| @@ -115,7 +115,7 @@ public: | |||
| protected: | |||
| /** @internal */ | |||
| void _drawAt(const Point<int>& pos, const GraphicsContext& gc) override; | |||
| void _drawAt(const Point<int>& pos) override; | |||
| private: | |||
| GLenum fFormat; | |||
| @@ -144,13 +144,18 @@ public: | |||
| @note If @takeReference is true, this increments the reference counter | |||
| of the cairo surface. | |||
| */ | |||
| ImageCairo(cairo_surface_t* surface, bool takeReference) noexcept; | |||
| ImageCairo(cairo_surface_t* surface, bool takeReference, const GraphicsContext* gc) noexcept; | |||
| /** | |||
| Constructor using another image data. | |||
| */ | |||
| ImageCairo(const ImageCairo& image) noexcept; | |||
| /** | |||
| Constructor using another image data, transferring to a different graphics context. | |||
| */ | |||
| ImageCairo(const ImageCairo& image, const GraphicsContext* gc) noexcept; | |||
| /** | |||
| Destructor. | |||
| @note Decrements the reference counter of the cairo surface. | |||
| @@ -161,7 +166,7 @@ public: | |||
| Load image data from memory. | |||
| @note @a rawData must remain valid for the lifetime of this Image. | |||
| */ | |||
| void loadFromPng(const char* const pngData, const uint pngSize) noexcept; | |||
| void loadFromPng(const char* const pngData, const uint pngSize, const GraphicsContext* gc) noexcept; | |||
| /** | |||
| Extract a part of the image bounded by the given rectangle. | |||
| @@ -191,10 +196,11 @@ public: | |||
| protected: | |||
| /** @internal */ | |||
| void _drawAt(const Point<int>& pos, const GraphicsContext& gc) override; | |||
| void _drawAt(const Point<int>& pos) override; | |||
| private: | |||
| cairo_surface_t* fSurface; | |||
| const GraphicsContext* fGc; | |||
| }; | |||
| #endif // DGL_CAIRO | |||
| @@ -91,34 +91,17 @@ public: | |||
| /** | |||
| Draw this image at (0, 0) point. | |||
| */ | |||
| void draw(const GraphicsContext& gc); | |||
| void draw(); | |||
| /** | |||
| Draw this image at (x, y) point. | |||
| */ | |||
| void drawAt(const int x, const int y, const GraphicsContext& gc); | |||
| void drawAt(const int x, const int y); | |||
| /** | |||
| Draw this image at position @a pos. | |||
| */ | |||
| void drawAt(const Point<int>& pos, const GraphicsContext& gc); | |||
| #ifdef DGL_OPENGL | |||
| /** | |||
| Draw this image at (0, 0) point. | |||
| */ | |||
| DISTRHO_DEPRECATED void draw(); | |||
| /** | |||
| Draw this image at (x, y) point. | |||
| */ | |||
| DISTRHO_DEPRECATED void drawAt(const int x, const int y); | |||
| /** | |||
| Draw this image at position @a pos. | |||
| */ | |||
| DISTRHO_DEPRECATED void drawAt(const Point<int>& pos); | |||
| #endif | |||
| void drawAt(const Point<int>& pos); | |||
| /** | |||
| TODO document this. | |||
| @@ -129,7 +112,7 @@ public: | |||
| protected: | |||
| /** @internal */ | |||
| virtual void _drawAt(const Point<int>& pos, const GraphicsContext& gc) = 0; | |||
| virtual void _drawAt(const Point<int>& pos) = 0; | |||
| const char* fRawData; | |||
| Size<uint> fSize; | |||
| @@ -115,7 +115,7 @@ ImageOpenGL& ImageOpenGL::operator=(const Image& image) noexcept | |||
| return *this; | |||
| } | |||
| void ImageOpenGL::_drawAt(const Point<int>& pos, const GraphicsContext& gc) | |||
| void ImageOpenGL::_drawAt(const Point<int>& pos) | |||
| { | |||
| if (fTextureId == 0 || ! isValid()) | |||
| return; | |||
| @@ -146,9 +146,6 @@ void ImageOpenGL::_drawAt(const Point<int>& pos, const GraphicsContext& gc) | |||
| glBindTexture(GL_TEXTURE_2D, 0); | |||
| glDisable(GL_TEXTURE_2D); | |||
| // unused | |||
| (void)gc; | |||
| } | |||
| #endif // DGL_OPENGL | |||
| @@ -159,12 +156,14 @@ void ImageOpenGL::_drawAt(const Point<int>& pos, const GraphicsContext& gc) | |||
| ImageCairo::ImageCairo() noexcept | |||
| : ImageBase(), | |||
| fSurface(nullptr) | |||
| fSurface(nullptr), | |||
| fGc(nullptr) | |||
| { | |||
| } | |||
| ImageCairo::ImageCairo(cairo_surface_t* surface, bool takeReference) noexcept | |||
| : fSurface(surface) | |||
| ImageCairo::ImageCairo(cairo_surface_t* surface, bool takeReference, const GraphicsContext* gc) noexcept | |||
| : fSurface(surface), | |||
| fGc(gc) | |||
| { | |||
| if (takeReference) | |||
| cairo_surface_reference(surface); | |||
| @@ -176,7 +175,19 @@ ImageCairo::ImageCairo(cairo_surface_t* surface, bool takeReference) noexcept | |||
| ImageCairo::ImageCairo(const ImageCairo& image) noexcept | |||
| : ImageBase(*this), | |||
| fSurface(cairo_surface_reference(image.fSurface)) | |||
| fSurface(cairo_surface_reference(image.fSurface)), | |||
| fGc(image.fGc) | |||
| { | |||
| cairo_surface_t* surface = fSurface; | |||
| fRawData = (const char*)cairo_image_surface_get_data(surface); | |||
| fSize.setWidth(cairo_image_surface_get_width(surface)); | |||
| fSize.setHeight(cairo_image_surface_get_height(surface)); | |||
| } | |||
| ImageCairo::ImageCairo(const ImageCairo& image, const GraphicsContext* gc) noexcept | |||
| : ImageBase(*this), | |||
| fSurface(cairo_surface_reference(image.fSurface)), | |||
| fGc(gc) | |||
| { | |||
| cairo_surface_t* surface = fSurface; | |||
| fRawData = (const char*)cairo_image_surface_get_data(surface); | |||
| @@ -210,7 +221,7 @@ static cairo_status_t readSomePngData(void *closure, | |||
| return CAIRO_STATUS_SUCCESS; | |||
| } | |||
| void ImageCairo::loadFromPng(const char* const pngData, const uint pngSize) noexcept | |||
| void ImageCairo::loadFromPng(const char* const pngData, const uint pngSize, const GraphicsContext* gc) noexcept | |||
| { | |||
| PngReaderData readerData; | |||
| readerData.dataPtr = pngData; | |||
| @@ -219,6 +230,7 @@ void ImageCairo::loadFromPng(const char* const pngData, const uint pngSize) noex | |||
| cairo_surface_t* surface = cairo_image_surface_create_from_png_stream(&readSomePngData, &readerData); | |||
| cairo_surface_destroy(fSurface); | |||
| fSurface = surface; | |||
| fGc = gc; | |||
| fRawData = (const char*)cairo_image_surface_get_data(surface); | |||
| fSize.setWidth(cairo_image_surface_get_width(surface)); | |||
| @@ -270,7 +282,7 @@ Image ImageCairo::getRegion(uint x, uint y, uint width, uint height) const noexc | |||
| const uint stride = cairo_image_surface_get_stride(surface); | |||
| unsigned char* data = fullData + x * bpp + y * stride; | |||
| return Image(cairo_image_surface_create_for_data(data, format, width, height, stride), false); | |||
| return Image(cairo_image_surface_create_for_data(data, format, width, height, stride), false, fGc); | |||
| } | |||
| cairo_surface_t* ImageCairo::getSurface() const noexcept | |||
| @@ -293,6 +305,7 @@ ImageCairo& ImageCairo::operator=(const ImageCairo& image) noexcept | |||
| cairo_surface_t* surface = cairo_surface_reference(image.fSurface); | |||
| cairo_surface_destroy(fSurface); | |||
| fSurface = surface; | |||
| fGc = image.fGc; | |||
| fRawData = (const char*)cairo_image_surface_get_data(surface); | |||
| fSize.setWidth(cairo_image_surface_get_width(surface)); | |||
| @@ -300,9 +313,12 @@ ImageCairo& ImageCairo::operator=(const ImageCairo& image) noexcept | |||
| return *this; | |||
| } | |||
| void ImageCairo::_drawAt(const Point<int>& pos, const GraphicsContext& gc) | |||
| void ImageCairo::_drawAt(const Point<int>& pos) | |||
| { | |||
| cairo_t* cr = gc.cairo; | |||
| const GraphicsContext* gc = fGc; | |||
| DISTRHO_SAFE_ASSERT_RETURN(gc,) | |||
| cairo_t* cr = gc->cairo; | |||
| cairo_surface_t* surface = fSurface; | |||
| if (!fSurface) | |||
| @@ -67,40 +67,20 @@ const char* ImageBase::getRawData() const noexcept | |||
| // ----------------------------------------------------------------------- | |||
| void ImageBase::draw(const GraphicsContext& gc) | |||
| { | |||
| _drawAt(Point<int>(), gc); | |||
| } | |||
| void ImageBase::drawAt(const int x, const int y, const GraphicsContext& gc) | |||
| { | |||
| _drawAt(Point<int>(x, y), gc); | |||
| } | |||
| void ImageBase::drawAt(const Point<int>& pos, const GraphicsContext& gc) | |||
| { | |||
| _drawAt(pos, gc); | |||
| } | |||
| #ifdef DGL_OPENGL | |||
| void ImageBase::draw() | |||
| { | |||
| GraphicsContext gc; | |||
| _drawAt(Point<int>(), gc); | |||
| _drawAt(Point<int>()); | |||
| } | |||
| void ImageBase::drawAt(const int x, const int y) | |||
| { | |||
| GraphicsContext gc; | |||
| _drawAt(Point<int>(x, y), gc); | |||
| _drawAt(Point<int>(x, y)); | |||
| } | |||
| void ImageBase::drawAt(const Point<int>& pos) | |||
| { | |||
| GraphicsContext gc; | |||
| _drawAt(pos, gc); | |||
| _drawAt(pos); | |||
| } | |||
| #endif | |||
| // ----------------------------------------------------------------------- | |||
| @@ -61,9 +61,7 @@ void ImageAboutWindow::setImage(const Image& image) | |||
| void ImageAboutWindow::onDisplay() | |||
| { | |||
| const GraphicsContext& gc = getParentWindow().getGraphicsContext(); | |||
| fImgBackground.draw(gc); | |||
| fImgBackground.draw(); | |||
| } | |||
| bool ImageAboutWindow::onKeyboard(const KeyboardEvent& ev) | |||
| @@ -175,18 +173,16 @@ void ImageButton::setCallback(Callback* callback) noexcept | |||
| void ImageButton::onDisplay() | |||
| { | |||
| const GraphicsContext& gc = getParentWindow().getGraphicsContext(); | |||
| switch (pData->impl.state) | |||
| { | |||
| case ButtonImpl::kStateDown: | |||
| pData->imageDown.draw(gc); | |||
| pData->imageDown.draw(); | |||
| break; | |||
| case ButtonImpl::kStateHover: | |||
| pData->imageHover.draw(gc); | |||
| pData->imageHover.draw(); | |||
| break; | |||
| default: | |||
| pData->imageNormal.draw(gc); | |||
| pData->imageNormal.draw(); | |||
| break; | |||
| } | |||
| } | |||
| @@ -539,6 +535,7 @@ void ImageKnob::onDisplay() | |||
| #ifdef DGL_CAIRO | |||
| void ImageKnob::onDisplay() | |||
| { | |||
| const GraphicsContext& gc = getParentWindow().getGraphicsContext(); | |||
| Image& displayImage = fDisplayImage; | |||
| const int angle = fRotationAngle; | |||
| const float normValue = ((fUsingLog ? _invlogscale(fValue) : fValue) - fMinimum) / (fMaximum - fMinimum); | |||
| @@ -559,7 +556,7 @@ void ImageKnob::onDisplay() | |||
| if (angle != 0) | |||
| { | |||
| Image rotated(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, layerW, layerH), false); | |||
| Image rotated(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, layerW, layerH), false, &gc); | |||
| cairo_t* cr = cairo_create(rotated.getSurface()); | |||
| cairo_translate(cr, 0.5 * layerW, 0.5 * layerH); | |||
| cairo_rotate(cr, normValue * angle * (float)(M_PI / 180)); | |||
| @@ -572,8 +569,7 @@ void ImageKnob::onDisplay() | |||
| fIsReady = true; | |||
| } | |||
| const GraphicsContext& gc = getParentWindow().getGraphicsContext(); | |||
| displayImage.draw(gc); | |||
| displayImage.draw(); | |||
| } | |||
| #endif // DGL_CAIRO | |||
| @@ -873,8 +869,6 @@ void ImageSlider::setCallback(Callback* callback) noexcept | |||
| void ImageSlider::onDisplay() | |||
| { | |||
| const GraphicsContext& gc = getParentWindow().getGraphicsContext(); | |||
| #if 0 // DEBUG, paints slider area | |||
| glColor3f(0.4f, 0.5f, 0.1f); | |||
| glRecti(fSliderArea.getX(), fSliderArea.getY(), fSliderArea.getX()+fSliderArea.getWidth(), fSliderArea.getY()+fSliderArea.getHeight()); | |||
| @@ -906,7 +900,7 @@ void ImageSlider::onDisplay() | |||
| y = fStartPos.getY() + static_cast<int>(normValue*static_cast<float>(fEndPos.getY()-fStartPos.getY())); | |||
| } | |||
| fImage.drawAt(x, y, gc); | |||
| fImage.drawAt(x, y); | |||
| } | |||
| bool ImageSlider::onMouse(const MouseEvent& ev) | |||
| @@ -1145,12 +1139,10 @@ void ImageSwitch::setCallback(Callback* callback) noexcept | |||
| void ImageSwitch::onDisplay() | |||
| { | |||
| const GraphicsContext& gc = getParentWindow().getGraphicsContext(); | |||
| if (fIsDown) | |||
| fImageDown.draw(gc); | |||
| fImageDown.draw(); | |||
| else | |||
| fImageNormal.draw(gc); | |||
| fImageNormal.draw(); | |||
| } | |||
| bool ImageSwitch::onMouse(const MouseEvent& ev) | |||
| @@ -29,6 +29,8 @@ public: | |||
| CairoExampleUI() | |||
| : UI(200, 200) | |||
| { | |||
| const GraphicsContext& gc = getParentWindow().getGraphicsContext(); | |||
| DemoWidgetClickable* widgetClickable = new DemoWidgetClickable(this); | |||
| fWidgetClickable = widgetClickable; | |||
| widgetClickable->setSize(50, 50); | |||
| @@ -40,7 +42,7 @@ public: | |||
| widgetBanner->setAbsolutePos(10, 10); | |||
| Image knobSkin; | |||
| knobSkin.loadFromPng(Artwork::knobData, Artwork::knobDataSize); | |||
| knobSkin.loadFromPng(Artwork::knobData, Artwork::knobDataSize, &gc); | |||
| ImageKnob* knob = new ImageKnob(this, knobSkin); | |||
| fKnob = knob; | |||
| @@ -49,8 +51,8 @@ public: | |||
| // knob->setRotationAngle(270); | |||
| Image buttonOn, buttonOff; | |||
| buttonOn.loadFromPng(Artwork::buttonOnData, Artwork::buttonOnDataSize); | |||
| buttonOff.loadFromPng(Artwork::buttonOffData, Artwork::buttonOffDataSize); | |||
| buttonOn.loadFromPng(Artwork::buttonOnData, Artwork::buttonOnDataSize, &gc); | |||
| buttonOff.loadFromPng(Artwork::buttonOffData, Artwork::buttonOffDataSize, &gc); | |||
| ImageButton* button = new ImageButton(this, buttonOff, buttonOn); | |||
| fButton = button; | |||