Browse Source

Add Rectangle::draw() function, use it in colors example

gh-pages
falkTX 9 years ago
parent
commit
142c6ddebd
3 changed files with 39 additions and 39 deletions
  1. +2
    -0
      dgl/Geometry.hpp
  2. +27
    -0
      dgl/src/Geometry.cpp
  3. +10
    -39
      examples/color.cpp

+ 2
- 0
dgl/Geometry.hpp View File

@@ -128,6 +128,8 @@ public:
void setSize(const T& width, const T& height) noexcept;
void setSize(const Size<T>& size) noexcept;

void draw();

Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept;

private:


+ 27
- 0
dgl/src/Geometry.cpp View File

@@ -412,6 +412,30 @@ void Rectangle<T>::setSize(const Size<T>& size) noexcept
fSize = size;
}

template<typename T>
void Rectangle<T>::draw()
{
// TODO - use glVexter2 d/f/i/s according to T type

glBegin(GL_QUADS);

{
glTexCoord2f(0.0f, 0.0f);
glVertex2i(fPos.fX, fPos.fY);

glTexCoord2f(1.0f, 0.0f);
glVertex2i(fPos.fX+fSize.fWidth, fPos.fY);

glTexCoord2f(1.0f, 1.0f);
glVertex2i(fPos.fX+fSize.fWidth, fPos.fY+fSize.fHeight);

glTexCoord2f(0.0f, 1.0f);
glVertex2i(fPos.fX, fPos.fY+fSize.fHeight);
}

glEnd();
}

template<typename T>
Rectangle<T>& Rectangle<T>::operator=(const Rectangle<T>& rect) noexcept
{
@@ -423,16 +447,19 @@ Rectangle<T>& Rectangle<T>::operator=(const Rectangle<T>& rect) 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 Size<short>;
template class Size<int>;
template class Size<long>;
template class Size<float>;
template class Size<double>;

template class Rectangle<short>;
template class Rectangle<int>;
template class Rectangle<long>;
template class Rectangle<float>;


+ 10
- 39
examples/color.cpp View File

@@ -99,50 +99,13 @@ private:

void onDisplay() override
{
int x = 0;
int y = 0;
int width = getWidth();
int height = getHeight();

// paint bg color (in full size)
glColor3b(r, g, b);

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();

// centered 2/3 size
x = width/6;
y = height/6;
width = width*2/3;
height = height*2/3;
bgFull.draw();

// paint inverted color (in 2/3 size)
glColor3b(100-r, 100-g, 100-b);

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();
bgSmall.draw();
}

void onReshape(int width, int height) override
@@ -150,11 +113,19 @@ private:
// make widget same size as window
setSize(width, height);
Widget::onReshape(width, height);

// full bg
bgFull = Rectangle<int>(0, 0, width, height);

// small bg, centered 2/3 size
bgSmall = Rectangle<int>(width/6, height/6, width*2/3, height*2/3);
}

char cur;
bool reverse;
int r, g, b;

Rectangle<int> bgFull, bgSmall;
};

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


Loading…
Cancel
Save