diff --git a/src/ui/GLPanel.cpp b/src/ui/GLPanel.cpp index 3f0f094..df0bdc8 100644 --- a/src/ui/GLPanel.cpp +++ b/src/ui/GLPanel.cpp @@ -233,6 +233,21 @@ void GLPanel::draw(CubicVR::mat4 transform_in, GLPanel *parent) { } // if (coord == GLPANEL_Y_UP) { // } + } else if (parent->coord != coord) { + if (parent->coord == GLPANEL_Y_DOWN_ZERO_ONE && coord == GLPANEL_Y_UP_ZERO_ONE) { + mCoord *= mat4::translate(0.0f, 1.0f, 0.0f) * mat4::scale(1.0f, -1.0f, 1.0f); + } + if (parent->coord == GLPANEL_Y_UP_ZERO_ONE && coord == GLPANEL_Y_DOWN_ZERO_ONE) { + mCoord *= mat4::translate(0.0f, -1.0f, 0.0f) * mat4::scale(1.0f, -1.0f, 1.0f); + } +// if (coord == GLPANEL_Y_UP_ZERO_ONE) { +// mCoord = mat4::translate(-1.0f, -1.0f, 0.0f) * mat4::scale(2.0f, 2.0f, 2.0f); +// } +// if (coord == GLPANEL_Y_DOWN) { +// mCoord = mat4::scale(2.0f, 2.0f, 2.0f); +// } + // if (coord == GLPANEL_Y_UP) { + // } } // compute local transform @@ -248,24 +263,24 @@ void GLPanel::draw(CubicVR::mat4 transform_in, GLPanel *parent) { vec4 vmax_t = mat4::vec4_multiply(vec4(max, max, 0, 1), transform); // screen dimensions - vec2 vmin((vmin_t.x>vmax_t.x)?vmax_t.x:vmin_t.x, (vmin_t.y>vmax_t.y)?vmax_t.y:vmin_t.y); - vec2 vmax((vmin_t.x>vmax_t.x)?vmin_t.x:vmax_t.x, (vmin_t.y>vmax_t.y)?vmin_t.y:vmax_t.y); + vmin = vec2((vmin_t.x > vmax_t.x)?vmax_t.x:vmin_t.x, (vmin_t.y > vmax_t.y)?vmax_t.y:vmin_t.y); + vmax = vec2((vmin_t.x > vmax_t.x)?vmin_t.x:vmax_t.x, (vmin_t.y > vmax_t.y)?vmin_t.y:vmax_t.y); // unit dimensions - vec2 umin = (vmin * 0.5) + vec2(1,1); - vec2 umax = (vmax * 0.5) + vec2(1,1); + umin = (vmin * 0.5) + vec2(1,1); + umax = (vmax * 0.5) + vec2(1,1); - vec2 ucenter = (umin + umax) * 0.5; + ucenter = vec2((umin + umax) * 0.5); // pixel dimensions - vec2 pdim((umax.x - umin.x) * view[0], (umax.y - umin.y) * view[1]); - vec2 pvec((vmax.x-vmin.x) / pdim.x, (vmax.y-vmin.y) / pdim.y); + pdim = vec2((umax.x - umin.x) * view[0], (umax.y - umin.y) * view[1]); + pvec = vec2((vmax.x - vmin.x) / pdim.x, (vmax.y - vmin.y) / pdim.y); std::cout << umin << " :: " << ucenter << " :: " << pdim << " :: " << pvec << std::endl; if (marginPx.left || marginPx.right || marginPx.top || marginPx.bottom) { - localTransform *= mat4::translate(marginPx.left*pvec.x/size[0], marginPx.top*pvec.y/size[1], 0) * - mat4::scale(1.0-(marginPx.left+marginPx.right)*pvec.x/size[0], 1.0-(marginPx.top+marginPx.bottom)*pvec.y/size[1], 0); + localTransform *= mat4::translate(marginPx.left * pvec.x / size[0], marginPx.top * pvec.y / size[1], 0) * + mat4::scale(1.0 - (marginPx.left + marginPx.right) * pvec.x / size[0], 1.0 - (marginPx.top + marginPx.bottom) * pvec.y / size[1], 0); transform = transform_in * localTransform; } @@ -330,6 +345,23 @@ void GLPanel::draw(CubicVR::mat4 transform_in, GLPanel *parent) { } +GLTextPanel::GLTextPanel() : GLPanel() { + coord = GLPANEL_Y_UP_ZERO_ONE; +} + +void GLTextPanel::drawPanelContents() { + glColor4f(1, 1, 1, 1.0); + GLFont::getFont(GLFont::GLFONT_SIZE48).drawString(textVal, mid, mid, 48, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, (int)pdim.x*2, (int)pdim.y*2); +} + +void GLTextPanel::setText(std::string text) { + textVal = text; +} + +std::string GLTextPanel::getText() { + return textVal; +} + void GLTestPanel::drawPanelContents() { diff --git a/src/ui/GLPanel.h b/src/ui/GLPanel.h index 86b8aa7..0d6175f 100644 --- a/src/ui/GLPanel.h +++ b/src/ui/GLPanel.h @@ -2,6 +2,7 @@ #include #include "GLExt.h" +#include "GLFont.h" #include "ColorTheme.h" #include "cubic_math.h" @@ -47,6 +48,12 @@ public: CubicVR::mat4 transform; CubicVR::mat4 localTransform; float min, mid, max; + // screen dimensions + CubicVR::vec2 vmin, vmax; + // unit dimensions + CubicVR::vec2 umin, umax, ucenter; + // pixel dimensions + CubicVR::vec2 pdim, pvec; std::vector children; @@ -76,6 +83,17 @@ public: }; +class GLTextPanel : public GLPanel { +private: + std::string textVal; +public: + GLTextPanel(); + + void drawPanelContents(); + void setText(std::string text); + std::string getText(); +}; + class GLTestPanel : public GLPanel { public: GLTestPanel() : GLPanel() { diff --git a/src/ui/UITestContext.cpp b/src/ui/UITestContext.cpp index b06cdb0..53a5e79 100644 --- a/src/ui/UITestContext.cpp +++ b/src/ui/UITestContext.cpp @@ -26,6 +26,10 @@ PrimaryGLContext(canvas, sharedContext) { testChildPanel2.setBorderColor(RGB(1.0,0.0,0.0)); testChildPanel2.setBorderPx(1); + testText1.setText("Testing 123.."); + testText1.setFill(GLPanel::GLPANEL_FILL_NONE); + testChildPanel2.addChild(&testText1); + testPanel.addChild(&testChildPanel); testPanel.addChild(&testChildPanel2); } diff --git a/src/ui/UITestContext.h b/src/ui/UITestContext.h index 9ac27bb..e84755a 100644 --- a/src/ui/UITestContext.h +++ b/src/ui/UITestContext.h @@ -17,4 +17,5 @@ private: GLPanel testPanel; GLTestPanel testChildPanel; GLPanel testChildPanel2; + GLTextPanel testText1; }; diff --git a/src/util/GLFont.cpp b/src/util/GLFont.cpp index 2edfda2..d922e33 100644 --- a/src/util/GLFont.cpp +++ b/src/util/GLFont.cpp @@ -397,16 +397,20 @@ float GLFont::getStringWidth(std::string str, float size, float viewAspect) { return width; } -void GLFont::drawString(std::string str, float xpos, float ypos, int pxHeight, Align hAlign, Align vAlign) { +void GLFont::drawString(std::string str, float xpos, float ypos, int pxHeight, Align hAlign, Align vAlign, int vpx, int vpy) { - GLint vp[4]; pxHeight *= 2; - glGetIntegerv( GL_VIEWPORT, vp); - - float size = (float) pxHeight / (float) vp[3]; - float viewAspect = (float) vp[2] / (float) vp[3]; + if (!vpx || !vpy) { + GLint vp[4]; + glGetIntegerv( GL_VIEWPORT, vp); + vpx = vp[2]; + vpy = vp[3]; + } + + float size = (float) pxHeight / (float) vpy; + float viewAspect = (float) vpx / (float) vpy; float msgWidth = getStringWidth(str, size, viewAspect); glPushMatrix(); diff --git a/src/util/GLFont.h b/src/util/GLFont.h index f369ef0..825459b 100644 --- a/src/util/GLFont.h +++ b/src/util/GLFont.h @@ -66,7 +66,7 @@ public: bool isLoaded(); float getStringWidth(std::string str, float size, float viewAspect); - void drawString(std::string str, float xpos, float ypos, int pxHeight, Align hAlign = GLFONT_ALIGN_LEFT, Align vAlign = GLFONT_ALIGN_TOP); + void drawString(std::string str, float xpos, float ypos, int pxHeight, Align hAlign = GLFONT_ALIGN_LEFT, Align vAlign = GLFONT_ALIGN_TOP, int vpx=0, int vpy=0); static GLFont fonts[GLFONT_MAX]; static GLFont &getFont(GLFontSize esize);