diff --git a/src/ui/GLPanel.cpp b/src/ui/GLPanel.cpp index 79f9ac8..5342e0e 100644 --- a/src/ui/GLPanel.cpp +++ b/src/ui/GLPanel.cpp @@ -2,16 +2,115 @@ #include "GLPanel.h" - -GLPanel::GLPanel() : fill(GLPANEL_FILL_SOLID), coord(GLPANEL_Y_DOWN_ZERO_ONE), contentsVisible(true) { +GLPanel::GLPanel() : fillType(GLPANEL_FILL_SOLID), coord(GLPANEL_Y_DOWN_ZERO_ONE), contentsVisible(true) { pos[0] = 0.0f; pos[1] = 0.0f; size[0] = 1.0f; size[1] = 1.0f; - + fill[0] = RGB(0.5,0.5,0.5); + fill[1] = RGB(0.1,0.1,0.1); genArrays(); } +void GLPanel::genArrays() { + if (fillType == GLPANEL_FILL_SOLID || fillType == GLPANEL_FILL_GRAD_X || fillType == GLPANEL_FILL_GRAD_Y) { + glPoints.reserve(2 * 4); + glPoints.resize(2 * 4); + glColors.reserve(3 * 4); + glColors.resize(3 * 4); + + float pts[2 * 4] = { + 0.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + 1.0f, 0.0f + }; + + RGB c[4]; + + if (fillType == GLPANEL_FILL_SOLID) { + c[0] = c[1] = c[2] = c[3] = fill[0]; + } else if (fillType == GLPANEL_FILL_GRAD_X) { + c[0] = c[1] = fill[0]; + c[2] = c[3] = fill[1]; + } else if (fillType == GLPANEL_FILL_GRAD_Y) { + c[0] = c[3] = fill[0]; + c[1] = c[2] = fill[1]; + } + + float clr[3 * 4] = { + c[0].r, c[0].g, c[0].b, + c[1].r, c[1].g, c[1].b, + c[2].r, c[2].g, c[2].b, + c[3].r, c[3].g, c[3].b + }; + + glPoints.assign(pts, pts + (2 * 4)); + glColors.assign(clr, clr + (3 * 4)); + } else { + glPoints.reserve(2 * 8); + glPoints.resize(2 * 8); + glColors.reserve(3 * 8); + glColors.resize(3 * 8); + + RGB c[8]; + + if (fillType == GLPANEL_FILL_GRAD_BAR_X) { + float pts[2 * 8] = { + 0.0f, 0.0f, + 0.0f, 1.0f, + 0.5f, 1.0f, + 0.5f, 0.0f, + + 0.5f, 0.0f, + 0.5f, 1.0f, + 1.0f, 1.0f, + 1.0f, 0.0f + }; + glPoints.assign(pts, pts + (2 * 8)); + + c[0] = c[1] = fill[0]; + c[2] = c[3] = fill[1]; + + c[4] = c[5] = fill[1]; + c[6] = c[7] = fill[0]; + + } else if (fillType == GLPANEL_FILL_GRAD_BAR_Y) { + float pts[2 * 8] = { + 0.0f, 0.0f, + 0.0f, 0.5f, + 1.0f, 0.5f, + 1.0f, 0.0f, + + 0.0f, 0.5f, + 0.0f, 1.0f, + 1.0f, 1.0f, + 1.0f, 0.5f + }; + glPoints.assign(pts, pts + (2 * 8)); + + c[0] = c[3] = fill[0]; + c[1] = c[2] = fill[1]; + + c[4] = c[7] = fill[1]; + c[5] = c[6] = fill[0]; + } + + float clr[3 * 8] = { + c[0].r, c[0].g, c[0].b, + c[1].r, c[1].g, c[1].b, + c[2].r, c[2].g, c[2].b, + c[3].r, c[3].g, c[3].b, + c[4].r, c[4].g, c[4].b, + c[5].r, c[5].g, c[5].b, + c[6].r, c[6].g, c[6].b, + c[7].r, c[7].g, c[7].b + }; + + glColors.assign(clr, clr + (3 * 8)); + } +} + void GLPanel::setViewport() { GLint vp[4]; glGetIntegerv(GL_VIEWPORT, vp); @@ -39,9 +138,22 @@ float GLPanel::getHeightPx() { } void GLPanel::setFill(GLPanelFillType fill_mode) { - fill = fill_mode; + fillType = fill_mode; + genArrays(); } +void GLPanel::setFillColor(RGB color1) { + fill[0] = color1; + genArrays(); +} + +void GLPanel::setFillColor(RGB color1, RGB color2) { + fill[0] = color1; + fill[1] = color2; + genArrays(); +} + + void GLPanel::setMargin(float marg) { margin.left = margin.right = margin.top = margin.bottom = marg; } @@ -96,7 +208,7 @@ void GLPanel::draw(GLPanel *parent) { glTranslatef(pos[0]+margin.left, pos[1]+margin.top, 0); glScalef(size[0]-(margin.left+margin.right), size[1]-(margin.top+margin.bottom), 0); - if (fill != GLPANEL_FILL_NONE) { + if (fillType != GLPANEL_FILL_NONE) { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(2, GL_FLOAT, 0, &glPoints[0]); @@ -119,3 +231,29 @@ void GLPanel::draw(GLPanel *parent) { glPopMatrix(); } } + + + + + + +void GLTestPanel::drawPanelContents() { + glColor3f(1.0,1.0,1.0); + glBegin(GL_LINES); + glVertex2f(0, 0.5); + glVertex2f(1, 0.5); + glVertex2f(0.5, 0); + glVertex2f(0.5, 1); + + glVertex2f(0.5, 1); + glVertex2f(0.48, 0.80); + glVertex2f(0.5, 1); + glVertex2f(0.52, 0.80); + + glVertex2f(1, 0.5); + glVertex2f(0.90, 0.25); + glVertex2f(1, 0.5); + glVertex2f(0.90, 0.75); + + glEnd(); +} diff --git a/src/ui/GLPanel.h b/src/ui/GLPanel.h index 9532cbd..7654c04 100644 --- a/src/ui/GLPanel.h +++ b/src/ui/GLPanel.h @@ -2,6 +2,7 @@ #include #include "GLExt.h" +#include "ColorTheme.h" class GLPanelEdges { public: @@ -26,31 +27,7 @@ private: std::vector glPoints; std::vector glColors; - void genArrays() { - if (!glPoints.size()) { - glPoints.resize(2 * 4); - glColors.resize(3 * 4); - } - - float pts[2 * 4] = { - 0.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 1.0f, - 1.0f, 0.0f - }; - - float clr[3 * 4] = { - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0, - 1.0, 1.0, 1.0 - }; - - glPoints.reserve(2 * 4); - glColors.reserve(3 * 4); - glPoints.assign(pts, pts + (2 * 4)); - glColors.assign(clr, clr + (3 * 4)); - } + void genArrays(); public: typedef enum GLPanelFillType { GLPANEL_FILL_NONE, GLPANEL_FILL_SOLID, GLPANEL_FILL_GRAD_X, GLPANEL_FILL_GRAD_Y, GLPANEL_FILL_GRAD_BAR_X, GLPANEL_FILL_GRAD_BAR_Y } GLPanelFillType; @@ -58,10 +35,11 @@ public: float pos[2]; float size[2]; float view[2]; - GLPanelFillType fill; + GLPanelFillType fillType; GLPanelCoordinateSystem coord; GLPanelEdges margin; GLPanelEdges border; + RGB fill[2]; bool contentsVisible; std::vector children; @@ -75,6 +53,8 @@ public: float getHeightPx(); void setFill(GLPanelFillType fill_mode); + void setFillColor(RGB color1); + void setFillColor(RGB color1, RGB color2); void setMargin(float marg); void setMargin(float margl, float margr, float margt, float margb); @@ -92,18 +72,5 @@ public: } - void drawPanelContents() { - glColor3f(1.0,1.0,1.0); - glBegin(GL_LINES); - glVertex2f(0, 0.5); - glVertex2f(1, 0.5); - glVertex2f(0.5, 0); - glVertex2f(0.5, 1); - - glVertex2f(0.5, 1); - glVertex2f(0.48, 0.80); - glVertex2f(0.5, 1); - glVertex2f(0.52, 0.80); - glEnd(); - } + void drawPanelContents(); }; diff --git a/src/ui/UITestContext.cpp b/src/ui/UITestContext.cpp index f7c5e2a..aecd307 100644 --- a/src/ui/UITestContext.cpp +++ b/src/ui/UITestContext.cpp @@ -4,15 +4,25 @@ UITestContext::UITestContext(UITestCanvas *canvas, wxGLContext *sharedContext) : PrimaryGLContext(canvas, sharedContext) { + testPanel.setPosition(0.0, 0.0); testPanel.setSize(1.0, 1.0); testPanel.setMargin(0.02, 0.02, 0.1, 0.1); + testPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_Y); + testPanel.setFillColor(RGB(0.0,0.0,1.0), RGB(0.0,1.0,0.0)); + testChildPanel.setPosition(0.0, 0.0); testChildPanel.setMargin(0.05); testChildPanel.setSize(1.0, 0.3); + testChildPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); + testChildPanel.setFillColor(RGB(0.0,0.0,1.0), RGB(0.0,1.0,0.0)); + testChildPanel2.setPosition(0.0, 0.3); testChildPanel2.setSize(1.0, 0.3); testChildPanel2.setMargin(0.05); + testChildPanel2.setFill(GLPanel::GLPANEL_FILL_GRAD_X); + testChildPanel2.setFillColor(RGB(0.0,0.0,1.0), RGB(0.0,1.0,0.0)); + testPanel.addChild(&testChildPanel); testPanel.addChild(&testChildPanel2); }