Browse Source

Minor API changes that make sense; Cleanup

gh-pages
falkTX 10 years ago
parent
commit
716be94bfc
7 changed files with 65 additions and 65 deletions
  1. +2
    -4
      dgl/Image.hpp
  2. +33
    -17
      dgl/src/Geometry.cpp
  3. +17
    -29
      dgl/src/Image.cpp
  4. +1
    -1
      dgl/src/ImageButton.cpp
  5. +1
    -1
      dgl/src/ImageSlider.cpp
  6. +10
    -12
      examples/images.cpp
  7. +1
    -1
      examples/nekobi-ui_src/NekoWidget.hpp

+ 2
- 4
dgl/Image.hpp View File

@@ -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
};

// -----------------------------------------------------------------------


+ 33
- 17
dgl/src/Geometry.cpp View File

@@ -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>;

// -----------------------------------------------------------------------



+ 17
- 29
dgl/src/Image.cpp View File

@@ -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);
}

// -----------------------------------------------------------------------


+ 1
- 1
dgl/src/ImageButton.cpp View File

@@ -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)


+ 1
- 1
dgl/src/ImageSlider.cpp View File

@@ -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)


+ 10
- 12
examples/images.cpp View File

@@ -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;
};
}


+ 1
- 1
examples/nekobi-ui_src/NekoWidget.hpp View File

@@ -75,7 +75,7 @@ public:
y += 12;
}

fCurImage->draw(x, y);
fCurImage->drawAt(x, y);
}

// returns true if needs repaint


Loading…
Cancel
Save