Browse Source

Add Rectangle::drawOutline()

gh-pages
falkTX 9 years ago
parent
commit
fb9ff8db59
2 changed files with 35 additions and 39 deletions
  1. +7
    -0
      dgl/Geometry.hpp
  2. +28
    -39
      dgl/src/Geometry.cpp

+ 7
- 0
dgl/Geometry.hpp View File

@@ -458,6 +458,11 @@ public:
*/
void draw();

/**
Draw lines (outline of this rectangle) using the current OpenGL state.
*/
void drawOutline();

Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept;
Rectangle<T>& operator*=(const T& m) noexcept;
Rectangle<T>& operator/=(const T& d) noexcept;
@@ -467,6 +472,8 @@ public:
private:
Point<T> fPos;
Size<T> fSize;

void _draw(const bool isOutline);
};

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


+ 28
- 39
dgl/src/Geometry.cpp View File

@@ -621,46 +621,13 @@ bool Rectangle<T>::containsY(const T& y) const noexcept
template<typename T>
void Rectangle<T>::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<typename T>
void Rectangle<T>::drawOutline()
{
_draw(true);
}

template<typename T>
@@ -699,6 +666,28 @@ bool Rectangle<T>::operator!=(const Rectangle<T>& rect) const noexcept
return !operator==(rect);
}

template<typename T>
void Rectangle<T>::_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



Loading…
Cancel
Save