From f2601edaa1a327fbfce04cb6b5869712d3958736 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 22 Jun 2015 22:07:46 -0400 Subject: [PATCH] Borders, mixed coordinate preparations --- src/ui/GLPanel.cpp | 122 +++++++++++++++++++++++++++++++-------- src/ui/GLPanel.h | 7 ++- src/ui/UITestContext.cpp | 3 + 3 files changed, 108 insertions(+), 24 deletions(-) diff --git a/src/ui/GLPanel.cpp b/src/ui/GLPanel.cpp index 5342e0e..e09217a 100644 --- a/src/ui/GLPanel.cpp +++ b/src/ui/GLPanel.cpp @@ -9,10 +9,24 @@ GLPanel::GLPanel() : fillType(GLPANEL_FILL_SOLID), coord(GLPANEL_Y_DOWN_ZERO_ONE size[1] = 1.0f; fill[0] = RGB(0.5,0.5,0.5); fill[1] = RGB(0.1,0.1,0.1); + borderColor = RGB(0.8, 0.8, 0.8); genArrays(); } void GLPanel::genArrays() { + + float min, mid, max; + + if (coord == GLPANEL_Y_DOWN || coord == GLPANEL_Y_UP) { + min = -1; + mid = 0; + max = 1; + } else { + min = 0; + mid = 0.5; + max = 1; + } + if (fillType == GLPANEL_FILL_SOLID || fillType == GLPANEL_FILL_GRAD_X || fillType == GLPANEL_FILL_GRAD_Y) { glPoints.reserve(2 * 4); glPoints.resize(2 * 4); @@ -20,10 +34,10 @@ void GLPanel::genArrays() { glColors.resize(3 * 4); float pts[2 * 4] = { - 0.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 1.0f, - 1.0f, 0.0f + min, min, + min, max, + max, max, + max, min }; RGB c[4]; @@ -57,15 +71,15 @@ void GLPanel::genArrays() { 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, + min, min, + min, max, + mid, max, + mid, min, - 0.5f, 0.0f, - 0.5f, 1.0f, - 1.0f, 1.0f, - 1.0f, 0.0f + mid, min, + mid, max, + max, max, + max, min }; glPoints.assign(pts, pts + (2 * 8)); @@ -77,15 +91,15 @@ void GLPanel::genArrays() { } 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, + min, min, + min, mid, + max, mid, + max, min, - 0.0f, 0.5f, - 0.0f, 1.0f, - 1.0f, 1.0f, - 1.0f, 0.5f + min, mid, + min, max, + max, max, + max, mid }; glPoints.assign(pts, pts + (2 * 8)); @@ -153,7 +167,6 @@ void GLPanel::setFillColor(RGB color1, RGB color2) { genArrays(); } - void GLPanel::setMargin(float marg) { margin.left = margin.right = margin.top = margin.bottom = marg; } @@ -165,6 +178,20 @@ void GLPanel::setMargin(float margl, float margr, float margt, float margb) { margin.bottom = margb; } +void GLPanel::setBorderColor(RGB clr) { + borderColor = clr; +} + +void GLPanel::setBorder(float bord) { + border.left = border.right = border.top = border.bottom = bord; +} + +void GLPanel::setBorder(float bordl, float bordr, float bordt, float bordb) { + border.left = bordl; + border.right = bordr; + border.top = bordt; + border.bottom = bordb; +} void GLPanel::addChild(GLPanel *childPanel) { children.push_back(childPanel); @@ -185,6 +212,18 @@ void GLPanel::drawPanelContents() { } void GLPanel::draw(GLPanel *parent) { + float min, mid, max; + + if (coord == GLPANEL_Y_DOWN || coord == GLPANEL_Y_UP) { + min = -1; + mid = 0; + max = 1; + } else { + min = 0; + mid = 0.5; + max = 1; + } + if (!parent) { if (coord == GLPANEL_Y_DOWN_ZERO_ONE) { glPushMatrix(); @@ -218,6 +257,45 @@ void GLPanel::draw(GLPanel *parent) { glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); + + if (border.left || border.right || border.top || border.bottom) { + glEnable(GL_LINE_SMOOTH); + glColor3f(borderColor.r, borderColor.g, borderColor.b); + + if (border.left) { + glLineWidth(border.left); + glBegin(GL_LINES); + glVertex2f(min, min); + glVertex2f(min, max); + glEnd(); + } + + if (border.right) { + glLineWidth(border.right); + glBegin(GL_LINES); + glVertex2f(max, min); + glVertex2f(max, max); + glEnd(); + } + + if (border.top) { + glLineWidth(border.top); + glBegin(GL_LINES); + glVertex2f(min, min); + glVertex2f(max, min); + glEnd(); + } + + if (border.bottom) { + glLineWidth(border.bottom); + glBegin(GL_LINES); + glVertex2f(min, max); + glVertex2f(max, max); + glEnd(); + } + + glDisable(GL_LINE_SMOOTH); + } } if (contentsVisible) { @@ -235,8 +313,6 @@ void GLPanel::draw(GLPanel *parent) { - - void GLTestPanel::drawPanelContents() { glColor3f(1.0,1.0,1.0); glBegin(GL_LINES); diff --git a/src/ui/GLPanel.h b/src/ui/GLPanel.h index 7654c04..4ec248d 100644 --- a/src/ui/GLPanel.h +++ b/src/ui/GLPanel.h @@ -40,6 +40,7 @@ public: GLPanelEdges margin; GLPanelEdges border; RGB fill[2]; + RGB borderColor; bool contentsVisible; std::vector children; @@ -57,7 +58,11 @@ public: void setFillColor(RGB color1, RGB color2); void setMargin(float marg); void setMargin(float margl, float margr, float margt, float margb); - + + void setBorderColor(RGB clr); + void setBorder(float bord); + void setBorder(float bordl, float bordr, float bordt, float bordb); + void addChild(GLPanel *childPanel); void drawChildren(); diff --git a/src/ui/UITestContext.cpp b/src/ui/UITestContext.cpp index aecd307..b1b48fb 100644 --- a/src/ui/UITestContext.cpp +++ b/src/ui/UITestContext.cpp @@ -16,12 +16,15 @@ PrimaryGLContext(canvas, sharedContext) { 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)); + testChildPanel.setBorder(1); 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)); + testChildPanel2.setBorderColor(RGB(1.0,0.0,0.0)); + testChildPanel2.setBorder(2,4,6,8); testPanel.addChild(&testChildPanel); testPanel.addChild(&testChildPanel2);