| @@ -46,8 +46,8 @@ public: | |||
| GLenum getType() const noexcept; | |||
| void draw(); | |||
| void draw(int x, int y); | |||
| void draw(const Point<int>& pos); | |||
| void drawAt(int x, int y); | |||
| void drawAt(const Point<int>& pos); | |||
| Image& operator=(const Image& image) noexcept; | |||
| bool operator==(const Image& image) const noexcept; | |||
| @@ -59,8 +59,6 @@ private: | |||
| GLenum fFormat; | |||
| GLenum fType; | |||
| GLuint fTextureId; | |||
| DISTRHO_PREVENT_HEAP_ALLOCATION | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| @@ -443,22 +443,41 @@ bool Rectangle<T>::containsY(const T& y) const noexcept | |||
| template<typename T> | |||
| void Rectangle<T>::draw() | |||
| { | |||
| // TODO - use glVexter2 d/f/i/s according to T type | |||
| typedef void (*glVextex2Func)(T x, T y); | |||
| static bool needsSetup = true; | |||
| static glVextex2Func glVextex2fn = (glVextex2Func)glVertex2i; | |||
| if (needsSetup) | |||
| { | |||
| #if 0 | |||
| // TODO | |||
| if (0) | |||
| glVextex2fn = (glVextex2Func)glVertex2d; | |||
| else if (0) | |||
| glVextex2fn = (glVextex2Func)glVertex2f; | |||
| else if (0) | |||
| glVextex2fn = (glVextex2Func)glVertex2s; | |||
| #endif | |||
| needsSetup = false; | |||
| } | |||
| glBegin(GL_QUADS); | |||
| { | |||
| glTexCoord2f(0.0f, 0.0f); | |||
| glVertex2i(fPos.fX, fPos.fY); | |||
| glVextex2fn(fPos.fX, fPos.fY); | |||
| glTexCoord2f(1.0f, 0.0f); | |||
| glVertex2i(fPos.fX+fSize.fWidth, fPos.fY); | |||
| glVextex2fn(fPos.fX+fSize.fWidth, fPos.fY); | |||
| glTexCoord2f(1.0f, 1.0f); | |||
| glVertex2i(fPos.fX+fSize.fWidth, fPos.fY+fSize.fHeight); | |||
| glVextex2fn(fPos.fX+fSize.fWidth, fPos.fY+fSize.fHeight); | |||
| glTexCoord2f(0.0f, 1.0f); | |||
| glVertex2i(fPos.fX, fPos.fY+fSize.fHeight); | |||
| glVextex2fn(fPos.fX, fPos.fY+fSize.fHeight); | |||
| } | |||
| glEnd(); | |||
| @@ -503,23 +522,20 @@ bool Rectangle<T>::operator!=(const Rectangle<T>& rect) const noexcept | |||
| // ----------------------------------------------------------------------- | |||
| // Possible template data types | |||
| template class Point<short>; | |||
| template class Point<int>; | |||
| template class Point<long>; | |||
| template class Point<float>; | |||
| template class Point<double>; | |||
| template class Point<float>; | |||
| template class Point<int>; | |||
| template class Point<short>; | |||
| template class Size<short>; | |||
| template class Size<int>; | |||
| template class Size<long>; | |||
| template class Size<float>; | |||
| template class Size<double>; | |||
| template class Size<float>; | |||
| template class Size<int>; | |||
| template class Size<short>; | |||
| template class Rectangle<short>; | |||
| template class Rectangle<int>; | |||
| template class Rectangle<long>; | |||
| template class Rectangle<float>; | |||
| template class Rectangle<double>; | |||
| template class Rectangle<float>; | |||
| template class Rectangle<int>; | |||
| template class Rectangle<short>; | |||
| // ----------------------------------------------------------------------- | |||
| @@ -80,7 +80,7 @@ void Image::loadFromMemory(const char* rawData, const Size<int>& size, GLenum fo | |||
| bool Image::isValid() const noexcept | |||
| { | |||
| return (fRawData != nullptr && getWidth() > 0 && getHeight() > 0); | |||
| return (fRawData != nullptr && fSize.getWidth() > 0 && fSize.getHeight() > 0); | |||
| } | |||
| int Image::getWidth() const noexcept | |||
| @@ -115,63 +115,51 @@ GLenum Image::getType() const noexcept | |||
| void Image::draw() | |||
| { | |||
| draw(0, 0); | |||
| drawAt(0, 0); | |||
| } | |||
| void Image::draw(int x, int y) | |||
| void Image::drawAt(int x, int y) | |||
| { | |||
| drawAt(Point<int>(x, y)); | |||
| } | |||
| void Image::drawAt(const Point<int>& pos) | |||
| { | |||
| if (! isValid()) | |||
| return; | |||
| if (fTextureId == 0) | |||
| glGenTextures(1, &fTextureId); | |||
| if (fTextureId == 0) | |||
| { | |||
| // invalidate image | |||
| fSize = Size<int>(0, 0); | |||
| // TODO print GL error | |||
| return; | |||
| } | |||
| glEnable(GL_TEXTURE_2D); | |||
| glBindTexture(GL_TEXTURE_2D, fTextureId); | |||
| glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | |||
| glPixelStorei(GL_PACK_ALIGNMENT, 1); | |||
| glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWidth(), getHeight(), 0, fFormat, fType, fRawData); | |||
| glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | |||
| glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fSize.getWidth(), fSize.getHeight(), 0, fFormat, fType, fRawData); | |||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); | |||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | |||
| float trans[] = { 0.0f, 0.0f, 0.0f, 0.0f }; | |||
| static const float trans[] = { 0.0f, 0.0f, 0.0f, 0.0f }; | |||
| glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, trans); | |||
| const int width = getWidth(); | |||
| const int height = getHeight(); | |||
| glBegin(GL_QUADS); | |||
| glTexCoord2f(0.0f, 0.0f); | |||
| glVertex2i(x, y); | |||
| glTexCoord2f(1.0f, 0.0f); | |||
| glVertex2i(x+width, y); | |||
| glTexCoord2f(1.0f, 1.0f); | |||
| glVertex2i(x+width, y+height); | |||
| glTexCoord2f(0.0f, 1.0f); | |||
| glVertex2i(x, y+height); | |||
| glEnd(); | |||
| Rectangle<int>(pos, fSize).draw(); | |||
| glBindTexture(GL_TEXTURE_2D, 0); | |||
| glDisable(GL_TEXTURE_2D); | |||
| } | |||
| void Image::draw(const Point<int>& pos) | |||
| { | |||
| draw(pos.getX(), pos.getY()); | |||
| } | |||
| // ----------------------------------------------------------------------- | |||
| Image& Image::operator=(const Image& image) noexcept | |||
| @@ -185,12 +173,12 @@ Image& Image::operator=(const Image& image) noexcept | |||
| bool Image::operator==(const Image& image) const noexcept | |||
| { | |||
| return (fRawData == image.fRawData); | |||
| return (fRawData == image.fRawData && fSize == image.fSize); | |||
| } | |||
| bool Image::operator!=(const Image& image) const noexcept | |||
| { | |||
| return (fRawData != image.fRawData); | |||
| return !operator==(image); | |||
| } | |||
| // ----------------------------------------------------------------------- | |||
| @@ -93,7 +93,7 @@ void ImageButton::setCallback(Callback* callback) | |||
| void ImageButton::onDisplay() | |||
| { | |||
| fCurImage->draw(getPos()); | |||
| fCurImage->drawAt(getPos()); | |||
| } | |||
| bool ImageButton::onMouse(int button, bool press, int x, int y) | |||
| @@ -194,7 +194,7 @@ void ImageSlider::onDisplay() | |||
| y = fStartPos.getY() + static_cast<int>(normValue*static_cast<float>(fEndPos.getY()-fStartPos.getY())); | |||
| } | |||
| fImage.draw(x, y); | |||
| fImage.drawAt(x, y); | |||
| } | |||
| bool ImageSlider::onMouse(int button, bool press, int x, int y) | |||
| @@ -59,9 +59,7 @@ public: | |||
| fImg3rev(true), | |||
| fImg1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, GL_BGR), | |||
| fImg2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, GL_BGR), | |||
| fImg3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, GL_BGR) | |||
| { | |||
| } | |||
| fImg3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, GL_BGR) {} | |||
| private: | |||
| void idleCallback() override | |||
| @@ -131,39 +129,39 @@ private: | |||
| switch (fImgTop3rd) | |||
| { | |||
| case 1: | |||
| fImg1.draw(fImg1x, kImg1y); | |||
| fImg1.drawAt(fImg1x, kImg1y); | |||
| break; | |||
| case 2: | |||
| fImg2.draw(fImg2x, kImg2y); | |||
| fImg2.drawAt(fImg2x, kImg2y); | |||
| break; | |||
| case 3: | |||
| fImg3.draw(kImg3x, fImg3y); | |||
| fImg3.drawAt(kImg3x, fImg3y); | |||
| break; | |||
| }; | |||
| switch (fImgTop2nd) | |||
| { | |||
| case 1: | |||
| fImg1.draw(fImg1x, kImg1y); | |||
| fImg1.drawAt(fImg1x, kImg1y); | |||
| break; | |||
| case 2: | |||
| fImg2.draw(fImg2x, kImg2y); | |||
| fImg2.drawAt(fImg2x, kImg2y); | |||
| break; | |||
| case 3: | |||
| fImg3.draw(kImg3x, fImg3y); | |||
| fImg3.drawAt(kImg3x, fImg3y); | |||
| break; | |||
| }; | |||
| switch (fImgTop1st) | |||
| { | |||
| case 1: | |||
| fImg1.draw(fImg1x, kImg1y); | |||
| fImg1.drawAt(fImg1x, kImg1y); | |||
| break; | |||
| case 2: | |||
| fImg2.draw(fImg2x, kImg2y); | |||
| fImg2.drawAt(fImg2x, kImg2y); | |||
| break; | |||
| case 3: | |||
| fImg3.draw(kImg3x, fImg3y); | |||
| fImg3.drawAt(kImg3x, fImg3y); | |||
| break; | |||
| }; | |||
| } | |||
| @@ -75,7 +75,7 @@ public: | |||
| y += 12; | |||
| } | |||
| fCurImage->draw(x, y); | |||
| fCurImage->drawAt(x, y); | |||
| } | |||
| // returns true if needs repaint | |||