Margin now specified in pixels

This commit is contained in:
Charles J. Cliffe 2015-06-27 01:26:07 -04:00
parent df978cef89
commit c770a0e20e
3 changed files with 57 additions and 53 deletions

View File

@ -172,30 +172,30 @@ void GLPanel::setFillColor(RGB color1, RGB color2) {
genArrays(); genArrays();
} }
void GLPanel::setMargin(float marg) { void GLPanel::setMarginPx(float marg) {
margin.left = margin.right = margin.top = margin.bottom = marg; marginPx.left = marginPx.right = marginPx.top = marginPx.bottom = marg;
} }
void GLPanel::setMargin(float margl, float margr, float margt, float margb) { void GLPanel::setMarginPx(float margl, float margr, float margt, float margb) {
margin.left = margl; marginPx.left = margl;
margin.right = margr; marginPx.right = margr;
margin.top = margt; marginPx.top = margt;
margin.bottom = margb; marginPx.bottom = margb;
} }
void GLPanel::setBorderColor(RGB clr) { void GLPanel::setBorderColor(RGB clr) {
borderColor = clr; borderColor = clr;
} }
void GLPanel::setBorder(float bord) { void GLPanel::setBorderPx(float bord) {
border.left = border.right = border.top = border.bottom = bord; borderPx.left = borderPx.right = borderPx.top = borderPx.bottom = bord;
} }
void GLPanel::setBorder(float bordl, float bordr, float bordt, float bordb) { void GLPanel::setBorderPx(float bordl, float bordr, float bordt, float bordb) {
border.left = bordl; borderPx.left = bordl;
border.right = bordr; borderPx.right = bordr;
border.top = bordt; borderPx.top = bordt;
border.bottom = bordb; borderPx.bottom = bordb;
} }
void GLPanel::addChild(GLPanel *childPanel) { void GLPanel::addChild(GLPanel *childPanel) {
@ -236,14 +236,10 @@ void GLPanel::draw(CubicVR::mat4 transform_in, GLPanel *parent) {
} }
// compute local transform // compute local transform
localTransform = mCoord * mat4::translate(pos[0]+margin.left, pos[1]+margin.top, 0) * localTransform = mCoord * (mat4::translate(pos[0], pos[1], 0) * mat4::scale(size[0], size[1], 0));
mat4::scale(size[0]-(margin.left+margin.right), size[1]-(margin.top+margin.bottom), 0);
// compute global transform // compute global transform
transform = transform_in * localTransform; transform = transform_in * localTransform;
glLoadMatrixf(transform);
// init view[] // init view[]
setViewport(); setViewport();
@ -254,16 +250,27 @@ void GLPanel::draw(CubicVR::mat4 transform_in, GLPanel *parent) {
// screen dimensions // 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 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); 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);
// unit dimensions // unit dimensions
vec2 umin = (vmin * 0.5) + vec2(1,1); vec2 umin = (vmin * 0.5) + vec2(1,1);
vec2 umax = (vmax * 0.5) + vec2(1,1); vec2 umax = (vmax * 0.5) + vec2(1,1);
vec2 ucenter = (umin + umax) * 0.5;
// pixel dimensions // pixel dimensions
vec2 pdim((umax.x - umin.x) * view[0], (umax.y - umin.y) * view[1]); 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);
std::cout << umin << " :: " << ucenter << " :: " << pdim << " :: " << pvec << std::endl;
if (marginPx.left || marginPx.right || marginPx.top || marginPx.bottom) {
localTransform *= mat4::translate(marginPx.left*pvec.x, marginPx.top*pvec.y, 0) *
mat4::scale(1.0-(marginPx.left+marginPx.right)*pvec.x, 1.0-(marginPx.top+marginPx.bottom)*pvec.y, 0);
transform = transform_in * localTransform;
}
glLoadMatrixf(transform);
std::cout << umin << " :: " << umax << " :: " << pdim << std::endl;
if (fillType != GLPANEL_FILL_NONE) { if (fillType != GLPANEL_FILL_NONE) {
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
@ -275,46 +282,43 @@ void GLPanel::draw(CubicVR::mat4 transform_in, GLPanel *parent) {
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);
if (border.left || border.right || border.top || border.bottom) { if (borderPx.left || borderPx.right || borderPx.top || borderPx.bottom) {
glLoadMatrixf(mat4::identity());
glEnable(GL_LINE_SMOOTH); glEnable(GL_LINE_SMOOTH);
glColor3f(borderColor.r, borderColor.g, borderColor.b); glColor3f(borderColor.r, borderColor.g, borderColor.b);
if (border.left) { if (borderPx.left) {
glLineWidth(border.left); glLineWidth(borderPx.left);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex2f(vmin.x, vmin.y); glVertex2f(min, min);
glVertex2f(vmin.x, vmax.y); glVertex2f(min, max);
glEnd(); glEnd();
} }
if (border.right) { if (borderPx.right) {
glLineWidth(border.right); glLineWidth(borderPx.right);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex2f(vmax.x, vmin.y); glVertex2f(max, min);
glVertex2f(vmax.x, vmax.y); glVertex2f(max, max);
glEnd(); glEnd();
} }
if (border.top) { if (borderPx.top) {
glLineWidth(border.top); glLineWidth(borderPx.top);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex2f(vmin.x, vmin.y); glVertex2f(min, min);
glVertex2f(vmax.x, vmin.y); glVertex2f(max, min);
glEnd(); glEnd();
} }
if (border.bottom) { if (borderPx.bottom) {
glLineWidth(border.bottom); glLineWidth(borderPx.bottom);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex2f(vmin.x, vmax.y); glVertex2f(min, max);
glVertex2f(vmax.x, vmax.y); glVertex2f(max, max);
glEnd(); glEnd();
} }
glDisable(GL_LINE_SMOOTH); glDisable(GL_LINE_SMOOTH);
glLoadMatrixf(transform);
} }
} }

View File

@ -39,8 +39,8 @@ public:
float view[2]; float view[2];
GLPanelFillType fillType; GLPanelFillType fillType;
GLPanelCoordinateSystem coord; GLPanelCoordinateSystem coord;
GLPanelEdges margin; GLPanelEdges marginPx;
GLPanelEdges border; GLPanelEdges borderPx;
RGB fill[2]; RGB fill[2];
RGB borderColor; RGB borderColor;
bool contentsVisible; bool contentsVisible;
@ -61,12 +61,12 @@ public:
void setFill(GLPanelFillType fill_mode); void setFill(GLPanelFillType fill_mode);
void setFillColor(RGB color1); void setFillColor(RGB color1);
void setFillColor(RGB color1, RGB color2); void setFillColor(RGB color1, RGB color2);
void setMargin(float marg); void setMarginPx(float marg);
void setMargin(float margl, float margr, float margt, float margb); void setMarginPx(float margl, float margr, float margt, float margb);
void setBorderColor(RGB clr); void setBorderColor(RGB clr);
void setBorder(float bord); void setBorderPx(float bord);
void setBorder(float bordl, float bordr, float bordt, float bordb); void setBorderPx(float bordl, float bordr, float bordt, float bordb);
void addChild(GLPanel *childPanel); void addChild(GLPanel *childPanel);

View File

@ -7,24 +7,24 @@ PrimaryGLContext(canvas, sharedContext) {
testPanel.setPosition(0.0, 0.0); testPanel.setPosition(0.0, 0.0);
testPanel.setSize(1.0, 1.0); testPanel.setSize(1.0, 1.0);
testPanel.setMargin(0.02, 0.02, 0.1, 0.1); testPanel.setMarginPx(10);
testPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_Y); testPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_Y);
testPanel.setFillColor(RGB(0.0,0.0,1.0), RGB(0.0,1.0,0.0)); testPanel.setFillColor(RGB(0.0,0.0,1.0), RGB(0.0,1.0,0.0));
testChildPanel.setPosition(0.0, 0.0); testChildPanel.setPosition(0.0, 0.0);
testChildPanel.setMargin(0.05); testChildPanel.setMarginPx(10);
testChildPanel.setSize(1.0, 0.3); testChildPanel.setSize(1.0, 0.3);
testChildPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); 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.setFillColor(RGB(0.0,0.0,1.0), RGB(0.0,1.0,0.0));
testChildPanel.setBorder(1); testChildPanel.setBorderPx(1);
testChildPanel2.setPosition(0.0, 0.3); testChildPanel2.setPosition(0.0, 0.3);
testChildPanel2.setSize(1.0, 0.3); testChildPanel2.setSize(1.0, 0.3);
testChildPanel2.setMargin(0.05); testChildPanel2.setMarginPx(10);
testChildPanel2.setFill(GLPanel::GLPANEL_FILL_GRAD_X); testChildPanel2.setFill(GLPanel::GLPANEL_FILL_GRAD_X);
testChildPanel2.setFillColor(RGB(0.0,0.0,1.0), RGB(0.0,1.0,0.0)); 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.setBorderColor(RGB(1.0,0.0,0.0));
testChildPanel2.setBorder(2,4,6,8); testChildPanel2.setBorderPx(2,4,6,8);
testPanel.addChild(&testChildPanel); testPanel.addChild(&testChildPanel);
testPanel.addChild(&testChildPanel2); testPanel.addChild(&testChildPanel2);