commit 142c6ddebd4f7bd8c8507591de7768d09792d588
parent d2e2770f19971c309b3dcdc50a06b1ecd09f8902
Author: falkTX <falktx@gmail.com>
Date: Tue, 6 May 2014 17:29:09 +0200
Add Rectangle::draw() function, use it in colors example
Diffstat:
3 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/dgl/Geometry.hpp b/dgl/Geometry.hpp
@@ -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:
diff --git a/dgl/src/Geometry.cpp b/dgl/src/Geometry.cpp
@@ -413,6 +413,30 @@ void Rectangle<T>::setSize(const Size<T>& size) noexcept
}
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
{
fPos = rect.fPos;
@@ -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>;
diff --git a/examples/color.cpp b/examples/color.cpp
@@ -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;
};
// ------------------------------------------------------