@@ -128,6 +128,8 @@ public: | |||||
void setSize(const T& width, const T& height) noexcept; | void setSize(const T& width, const T& height) noexcept; | ||||
void setSize(const Size<T>& size) noexcept; | void setSize(const Size<T>& size) noexcept; | ||||
void draw(); | |||||
Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept; | Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept; | ||||
private: | private: | ||||
@@ -412,6 +412,30 @@ void Rectangle<T>::setSize(const Size<T>& size) noexcept | |||||
fSize = size; | 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> | template<typename T> | ||||
Rectangle<T>& Rectangle<T>::operator=(const Rectangle<T>& rect) noexcept | 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 | // Possible template data types | ||||
template class Point<short>; | |||||
template class Point<int>; | template class Point<int>; | ||||
template class Point<long>; | template class Point<long>; | ||||
template class Point<float>; | template class Point<float>; | ||||
template class Point<double>; | template class Point<double>; | ||||
template class Size<short>; | |||||
template class Size<int>; | template class Size<int>; | ||||
template class Size<long>; | template class Size<long>; | ||||
template class Size<float>; | template class Size<float>; | ||||
template class Size<double>; | template class Size<double>; | ||||
template class Rectangle<short>; | |||||
template class Rectangle<int>; | template class Rectangle<int>; | ||||
template class Rectangle<long>; | template class Rectangle<long>; | ||||
template class Rectangle<float>; | template class Rectangle<float>; | ||||
@@ -99,50 +99,13 @@ private: | |||||
void onDisplay() override | void onDisplay() override | ||||
{ | { | ||||
int x = 0; | |||||
int y = 0; | |||||
int width = getWidth(); | |||||
int height = getHeight(); | |||||
// paint bg color (in full size) | // paint bg color (in full size) | ||||
glColor3b(r, g, b); | 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) | // paint inverted color (in 2/3 size) | ||||
glColor3b(100-r, 100-g, 100-b); | 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 | void onReshape(int width, int height) override | ||||
@@ -150,11 +113,19 @@ private: | |||||
// make widget same size as window | // make widget same size as window | ||||
setSize(width, height); | setSize(width, height); | ||||
Widget::onReshape(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; | char cur; | ||||
bool reverse; | bool reverse; | ||||
int r, g, b; | int r, g, b; | ||||
Rectangle<int> bgFull, bgSmall; | |||||
}; | }; | ||||
// ------------------------------------------------------ | // ------------------------------------------------------ | ||||