add GLTextPanel, initial work on nested coordinate systems

This commit is contained in:
Charles J. Cliffe 2015-07-01 00:34:32 -04:00
parent b28c8dbc3e
commit 48308145b7
6 changed files with 75 additions and 16 deletions

View File

@ -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() {

View File

@ -2,6 +2,7 @@
#include <vector>
#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<GLPanel *> 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() {

View File

@ -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);
}

View File

@ -17,4 +17,5 @@ private:
GLPanel testPanel;
GLTestPanel testChildPanel;
GLPanel testChildPanel2;
GLTextPanel testText1;
};

View File

@ -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();

View File

@ -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);