diff --git a/dgl/Geometry.hpp b/dgl/Geometry.hpp index 580bd318..6ad966e8 100644 --- a/dgl/Geometry.hpp +++ b/dgl/Geometry.hpp @@ -458,6 +458,11 @@ public: */ void draw(); + /** + Draw lines (outline of this rectangle) using the current OpenGL state. + */ + void drawOutline(); + Rectangle& operator=(const Rectangle& rect) noexcept; Rectangle& operator*=(const T& m) noexcept; Rectangle& operator/=(const T& d) noexcept; @@ -467,6 +472,8 @@ public: private: Point fPos; Size fSize; + + void _draw(const bool isOutline); }; // ----------------------------------------------------------------------- diff --git a/dgl/src/Geometry.cpp b/dgl/src/Geometry.cpp index c3954895..600685ac 100644 --- a/dgl/src/Geometry.cpp +++ b/dgl/src/Geometry.cpp @@ -621,46 +621,13 @@ bool Rectangle::containsY(const T& y) const noexcept template void Rectangle::draw() { -#if 0 - 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; - } -#endif - - 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); - } + _draw(false); +} - glEnd(); +template +void Rectangle::drawOutline() +{ + _draw(true); } template @@ -699,6 +666,28 @@ bool Rectangle::operator!=(const Rectangle& rect) const noexcept return !operator==(rect); } +template +void Rectangle::_draw(const bool isOutline) +{ + glBegin(isOutline ? GL_LINE_LOOP : 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(); +} + // ----------------------------------------------------------------------- // Possible template data types