2015-06-20 20:19:52 -04:00
|
|
|
|
|
|
|
#include "GLPanel.h"
|
2015-06-26 22:04:16 -04:00
|
|
|
#include "cubic_math.h"
|
2015-08-18 18:43:55 -04:00
|
|
|
#include <algorithm>
|
2015-06-20 20:19:52 -04:00
|
|
|
|
2015-07-05 19:10:48 -04:00
|
|
|
using namespace CubicVR;
|
|
|
|
|
2015-10-27 01:56:49 -04:00
|
|
|
GLPanel::GLPanel() : fillType(GLPANEL_FILL_SOLID), contentsVisible(true), visible(true), transform(mat4::identity()) {
|
2015-06-20 20:19:52 -04:00
|
|
|
pos[0] = 0.0f;
|
|
|
|
pos[1] = 0.0f;
|
2015-08-19 23:22:46 -04:00
|
|
|
rot[0] = 0.0f;
|
|
|
|
rot[1] = 0.0f;
|
|
|
|
rot[2] = 0.0f;
|
2015-06-20 20:19:52 -04:00
|
|
|
size[0] = 1.0f;
|
|
|
|
size[1] = 1.0f;
|
2016-06-01 19:42:34 -04:00
|
|
|
fill[0] = RGBA4f(0.5f,0.5f,0.5f);
|
|
|
|
fill[1] = RGBA4f(0.1f,0.1f,0.1f);
|
|
|
|
borderColor = RGBA4f(0.8f, 0.8f, 0.8f);
|
2015-07-05 18:54:46 -04:00
|
|
|
setCoordinateSystem(GLPANEL_Y_UP);
|
2015-08-09 23:00:51 -04:00
|
|
|
setMarginPx(0);
|
|
|
|
setBorderPx(0);
|
2015-10-27 01:56:49 -04:00
|
|
|
srcBlend = GL_SRC_ALPHA;
|
|
|
|
dstBlend = GL_ONE_MINUS_SRC_ALPHA;
|
2015-06-20 20:19:52 -04:00
|
|
|
}
|
|
|
|
|
2015-06-21 11:58:14 -04:00
|
|
|
void GLPanel::genArrays() {
|
2015-07-05 18:54:46 -04:00
|
|
|
float min = -1.0, mid = 0, max = 1.0;
|
|
|
|
|
2015-06-21 11:58:14 -04:00
|
|
|
if (fillType == GLPANEL_FILL_SOLID || fillType == GLPANEL_FILL_GRAD_X || fillType == GLPANEL_FILL_GRAD_Y) {
|
|
|
|
glPoints.reserve(2 * 4);
|
|
|
|
glPoints.resize(2 * 4);
|
2015-08-17 21:52:38 -04:00
|
|
|
glColors.reserve(4 * 4);
|
|
|
|
glColors.resize(4 * 4);
|
2015-06-21 11:58:14 -04:00
|
|
|
|
|
|
|
float pts[2 * 4] = {
|
2015-06-22 22:07:46 -04:00
|
|
|
min, min,
|
|
|
|
min, max,
|
|
|
|
max, max,
|
|
|
|
max, min
|
2015-06-21 11:58:14 -04:00
|
|
|
};
|
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
RGBA4f c[4];
|
2015-06-21 11:58:14 -04:00
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
float clr[4 * 4] = {
|
|
|
|
c[0].r, c[0].g, c[0].b, c[0].a,
|
|
|
|
c[1].r, c[1].g, c[1].b, c[1].a,
|
|
|
|
c[2].r, c[2].g, c[2].b, c[2].a,
|
|
|
|
c[3].r, c[3].g, c[3].b, c[3].a
|
|
|
|
};
|
2015-06-21 11:58:14 -04:00
|
|
|
|
|
|
|
glPoints.assign(pts, pts + (2 * 4));
|
2015-08-17 21:52:38 -04:00
|
|
|
glColors.assign(clr, clr + (4 * 4));
|
2015-06-21 11:58:14 -04:00
|
|
|
} else {
|
|
|
|
glPoints.reserve(2 * 8);
|
|
|
|
glPoints.resize(2 * 8);
|
2015-08-17 21:52:38 -04:00
|
|
|
glColors.reserve(4 * 8);
|
|
|
|
glColors.resize(4 * 8);
|
2015-06-21 11:58:14 -04:00
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
RGBA4f c[8];
|
2015-06-21 11:58:14 -04:00
|
|
|
|
|
|
|
if (fillType == GLPANEL_FILL_GRAD_BAR_X) {
|
|
|
|
float pts[2 * 8] = {
|
2015-06-22 22:07:46 -04:00
|
|
|
min, min,
|
|
|
|
min, max,
|
|
|
|
mid, max,
|
|
|
|
mid, min,
|
2015-06-21 11:58:14 -04:00
|
|
|
|
2015-06-22 22:07:46 -04:00
|
|
|
mid, min,
|
|
|
|
mid, max,
|
|
|
|
max, max,
|
|
|
|
max, min
|
2015-06-21 11:58:14 -04:00
|
|
|
};
|
|
|
|
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] = {
|
2015-06-22 22:07:46 -04:00
|
|
|
min, min,
|
|
|
|
min, mid,
|
|
|
|
max, mid,
|
|
|
|
max, min,
|
2015-06-21 11:58:14 -04:00
|
|
|
|
2015-06-22 22:07:46 -04:00
|
|
|
min, mid,
|
|
|
|
min, max,
|
|
|
|
max, max,
|
|
|
|
max, mid
|
2015-06-21 11:58:14 -04:00
|
|
|
};
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
float clr[4 * 8] = {
|
|
|
|
c[0].r, c[0].g, c[0].b, c[0].a,
|
|
|
|
c[1].r, c[1].g, c[1].b, c[1].a,
|
|
|
|
c[2].r, c[2].g, c[2].b, c[2].a,
|
|
|
|
c[3].r, c[3].g, c[3].b, c[3].a,
|
|
|
|
c[4].r, c[4].g, c[4].b, c[4].a,
|
|
|
|
c[5].r, c[5].g, c[5].b, c[5].a,
|
|
|
|
c[6].r, c[6].g, c[6].b, c[6].a,
|
|
|
|
c[7].r, c[7].g, c[7].b, c[7].a
|
2015-06-21 11:58:14 -04:00
|
|
|
};
|
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
glColors.assign(clr, clr + (4 * 8));
|
2015-06-21 11:58:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 22:04:16 -04:00
|
|
|
|
2015-06-20 20:19:52 -04:00
|
|
|
void GLPanel::setViewport() {
|
|
|
|
GLint vp[4];
|
|
|
|
glGetIntegerv(GL_VIEWPORT, vp);
|
|
|
|
|
|
|
|
view[0] = vp[2];
|
|
|
|
view[1] = vp[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLPanel::setPosition(float x, float y) {
|
|
|
|
pos[0] = x;
|
|
|
|
pos[1] = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLPanel::setSize(float w, float h) {
|
|
|
|
size[0] = w;
|
|
|
|
size[1] = h;
|
|
|
|
}
|
|
|
|
|
2015-07-05 21:09:00 -04:00
|
|
|
float GLPanel::getWidth() {
|
|
|
|
return size[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
float GLPanel::getHeight() {
|
|
|
|
return size[1];
|
|
|
|
}
|
|
|
|
|
2015-06-20 20:19:52 -04:00
|
|
|
float GLPanel::getWidthPx() {
|
2015-07-05 21:09:00 -04:00
|
|
|
return pdim.x;
|
2015-06-20 20:19:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
float GLPanel::getHeightPx() {
|
2015-07-05 21:09:00 -04:00
|
|
|
return pdim.y;
|
2015-06-20 20:19:52 -04:00
|
|
|
}
|
|
|
|
|
2015-06-26 22:04:16 -04:00
|
|
|
|
|
|
|
void GLPanel::setCoordinateSystem(GLPanelCoordinateSystem coord_in) {
|
|
|
|
coord = coord_in;
|
|
|
|
|
|
|
|
if (coord == GLPANEL_Y_DOWN || coord == GLPANEL_Y_UP) {
|
|
|
|
min = -1;
|
|
|
|
mid = 0;
|
|
|
|
max = 1;
|
|
|
|
} else {
|
|
|
|
min = 0;
|
|
|
|
mid = 0.5;
|
|
|
|
max = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
genArrays();
|
|
|
|
}
|
|
|
|
|
2015-10-27 01:56:49 -04:00
|
|
|
bool GLPanel::hitTest(CubicVR::vec2 pos, CubicVR::vec2 &result) {
|
|
|
|
CubicVR::vec4 hitPos = CubicVR::mat4::vec4_multiply(CubicVR::vec4(pos.x, pos.y, 0.0, 1.0), transformInverse);
|
|
|
|
|
|
|
|
if (hitPos.x >= -1.0 && hitPos.x <= 1.0 && hitPos.y >= -1.0 && hitPos.y <= 1.0) {
|
|
|
|
result.x = hitPos.x;
|
|
|
|
result.y = hitPos.y;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-20 20:19:52 -04:00
|
|
|
void GLPanel::setFill(GLPanelFillType fill_mode) {
|
2015-06-21 11:58:14 -04:00
|
|
|
fillType = fill_mode;
|
|
|
|
genArrays();
|
|
|
|
}
|
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
void GLPanel::setFillColor(RGBA4f color1) {
|
2015-06-21 11:58:14 -04:00
|
|
|
fill[0] = color1;
|
|
|
|
genArrays();
|
2015-06-20 20:19:52 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
void GLPanel::setFillColor(RGBA4f color1, RGBA4f color2) {
|
2015-06-21 11:58:14 -04:00
|
|
|
fill[0] = color1;
|
|
|
|
fill[1] = color2;
|
|
|
|
genArrays();
|
|
|
|
}
|
|
|
|
|
2015-06-27 01:26:07 -04:00
|
|
|
void GLPanel::setMarginPx(float marg) {
|
2015-07-05 18:54:46 -04:00
|
|
|
marginPx = marg;
|
2015-06-20 20:19:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
void GLPanel::setBorderColor(RGBA4f clr) {
|
2015-06-22 22:07:46 -04:00
|
|
|
borderColor = clr;
|
|
|
|
}
|
|
|
|
|
2015-06-27 01:26:07 -04:00
|
|
|
void GLPanel::setBorderPx(float bord) {
|
|
|
|
borderPx.left = borderPx.right = borderPx.top = borderPx.bottom = bord;
|
2015-06-22 22:07:46 -04:00
|
|
|
}
|
|
|
|
|
2015-06-27 01:26:07 -04:00
|
|
|
void GLPanel::setBorderPx(float bordl, float bordr, float bordt, float bordb) {
|
|
|
|
borderPx.left = bordl;
|
|
|
|
borderPx.right = bordr;
|
|
|
|
borderPx.top = bordt;
|
|
|
|
borderPx.bottom = bordb;
|
2015-06-22 22:07:46 -04:00
|
|
|
}
|
2015-06-20 20:19:52 -04:00
|
|
|
|
2015-10-27 01:56:49 -04:00
|
|
|
void GLPanel::setBlend(GLuint src, GLuint dst) {
|
|
|
|
srcBlend = src;
|
|
|
|
dstBlend = dst;
|
|
|
|
}
|
|
|
|
|
2015-06-20 20:19:52 -04:00
|
|
|
void GLPanel::addChild(GLPanel *childPanel) {
|
2015-08-17 21:52:38 -04:00
|
|
|
std::vector<GLPanel *>::iterator i = std::find(children.begin(), children.end(), childPanel);
|
2015-08-18 18:43:55 -04:00
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
if (i == children.end()) {
|
|
|
|
children.push_back(childPanel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLPanel::removeChild(GLPanel *childPanel) {
|
|
|
|
std::vector<GLPanel *>::iterator i = std::find(children.begin(), children.end(), childPanel);
|
2015-08-18 18:43:55 -04:00
|
|
|
|
2015-08-17 21:52:38 -04:00
|
|
|
if (i != children.end()) {
|
|
|
|
children.erase(i);
|
|
|
|
}
|
2015-06-20 20:19:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLPanel::drawChildren() {
|
|
|
|
if (children.size()) {
|
|
|
|
std::vector<GLPanel *>::iterator panel_i;
|
|
|
|
|
|
|
|
for (panel_i = children.begin(); panel_i != children.end(); panel_i++) {
|
2015-07-05 19:10:48 -04:00
|
|
|
(*panel_i)->calcTransform(transform);
|
|
|
|
(*panel_i)->draw();
|
2015-06-20 20:19:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLPanel::drawPanelContents() {
|
|
|
|
drawChildren();
|
|
|
|
}
|
|
|
|
|
2015-07-05 19:10:48 -04:00
|
|
|
void GLPanel::calcTransform(mat4 transform_in) {
|
2015-06-26 22:04:16 -04:00
|
|
|
// compute local transform
|
2015-08-09 12:51:01 -04:00
|
|
|
localTransform = mat4::translate(pos[0], pos[1], 0) * mat4::scale(size[0], size[1], 1);
|
2015-08-19 23:22:46 -04:00
|
|
|
|
|
|
|
if (rot[0] || rot[1] || rot[2]) {
|
|
|
|
localTransform *= mat4::rotate(rot[0], rot[1], rot[2]);
|
|
|
|
}
|
|
|
|
|
2015-06-26 22:04:16 -04:00
|
|
|
// compute global transform
|
|
|
|
transform = transform_in * localTransform;
|
|
|
|
|
|
|
|
// init view[]
|
|
|
|
setViewport();
|
|
|
|
|
|
|
|
// get min/max transform
|
|
|
|
vec4 vmin_t = mat4::vec4_multiply(vec4(min, min, 0, 1), transform);
|
|
|
|
vec4 vmax_t = mat4::vec4_multiply(vec4(max, max, 0, 1), transform);
|
|
|
|
|
|
|
|
// screen dimensions
|
2015-07-01 00:34:32 -04:00
|
|
|
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);
|
2015-06-27 01:26:07 -04:00
|
|
|
|
2015-06-26 22:04:16 -04:00
|
|
|
// unit dimensions
|
2015-07-01 00:34:32 -04:00
|
|
|
umin = (vmin * 0.5) + vec2(1,1);
|
|
|
|
umax = (vmax * 0.5) + vec2(1,1);
|
2015-06-26 22:04:16 -04:00
|
|
|
|
2015-07-01 00:34:32 -04:00
|
|
|
ucenter = vec2((umin + umax) * 0.5);
|
2015-06-27 01:26:07 -04:00
|
|
|
|
2015-06-26 22:04:16 -04:00
|
|
|
// pixel dimensions
|
2015-07-05 18:54:46 -04:00
|
|
|
pdim = vec2((vmax.x - vmin.x) / 2.0 * view[0], (vmax.y - vmin.y) / 2.0 * view[1]);
|
|
|
|
pvec = vec2(((vmax.x - vmin.x) / 2.0) / pdim.x, ((vmax.y - vmin.y) / 2.0) / pdim.y);
|
2015-06-27 01:26:07 -04:00
|
|
|
|
2015-08-09 12:51:01 -04:00
|
|
|
// std::cout << umin << " :: " << ucenter << " :: " << pdim << " :: " << pvec << std::endl;
|
2015-06-27 01:26:07 -04:00
|
|
|
|
2015-07-05 18:54:46 -04:00
|
|
|
if (marginPx) {
|
2015-08-09 12:51:01 -04:00
|
|
|
transform *= mat4::scale(1.0 - marginPx * 2.0 * pvec.x / size[0], 1.0 - marginPx * 2.0 * pvec.y / size[1], 1);
|
2015-06-27 01:26:07 -04:00
|
|
|
}
|
2015-10-27 01:56:49 -04:00
|
|
|
|
|
|
|
transformInverse = CubicVR::mat4::inverse(transform);
|
2015-07-05 19:10:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLPanel::draw() {
|
2015-07-06 23:05:49 -04:00
|
|
|
float min = -1.0, max = 1.0;
|
|
|
|
|
2015-06-27 01:26:07 -04:00
|
|
|
glLoadMatrixf(transform);
|
2015-06-26 22:04:16 -04:00
|
|
|
|
2015-10-27 01:56:49 -04:00
|
|
|
if (fillType != GLPANEL_FILL_NONE && visible) {
|
2015-08-17 21:52:38 -04:00
|
|
|
glEnable(GL_BLEND);
|
2015-10-27 01:56:49 -04:00
|
|
|
glBlendFunc(srcBlend, dstBlend);
|
2015-06-20 20:19:52 -04:00
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
glVertexPointer(2, GL_FLOAT, 0, &glPoints[0]);
|
2015-08-17 21:52:38 -04:00
|
|
|
glColorPointer(4, GL_FLOAT, 0, &glColors[0]);
|
2015-06-20 20:19:52 -04:00
|
|
|
|
|
|
|
glDrawArrays(GL_QUADS, 0, glPoints.size() / 2);
|
|
|
|
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glDisableClientState(GL_COLOR_ARRAY);
|
2015-06-22 22:07:46 -04:00
|
|
|
|
2015-06-27 01:26:07 -04:00
|
|
|
if (borderPx.left || borderPx.right || borderPx.top || borderPx.bottom) {
|
2015-06-22 22:07:46 -04:00
|
|
|
glEnable(GL_LINE_SMOOTH);
|
2015-08-17 21:52:38 -04:00
|
|
|
glColor4f(borderColor.r, borderColor.g, borderColor.b, borderColor.a);
|
2015-06-22 22:07:46 -04:00
|
|
|
|
2015-06-27 01:26:07 -04:00
|
|
|
if (borderPx.left) {
|
|
|
|
glLineWidth(borderPx.left);
|
2015-06-22 22:07:46 -04:00
|
|
|
glBegin(GL_LINES);
|
2015-06-27 01:26:07 -04:00
|
|
|
glVertex2f(min, min);
|
|
|
|
glVertex2f(min, max);
|
2015-06-22 22:07:46 -04:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2015-06-27 01:26:07 -04:00
|
|
|
if (borderPx.right) {
|
|
|
|
glLineWidth(borderPx.right);
|
2015-06-22 22:07:46 -04:00
|
|
|
glBegin(GL_LINES);
|
2015-06-27 01:26:07 -04:00
|
|
|
glVertex2f(max, min);
|
|
|
|
glVertex2f(max, max);
|
2015-06-22 22:07:46 -04:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2015-06-27 01:26:07 -04:00
|
|
|
if (borderPx.top) {
|
|
|
|
glLineWidth(borderPx.top);
|
2015-06-22 22:07:46 -04:00
|
|
|
glBegin(GL_LINES);
|
2015-06-27 01:26:07 -04:00
|
|
|
glVertex2f(min, min);
|
|
|
|
glVertex2f(max, min);
|
2015-06-22 22:07:46 -04:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2015-06-27 01:26:07 -04:00
|
|
|
if (borderPx.bottom) {
|
|
|
|
glLineWidth(borderPx.bottom);
|
2015-06-22 22:07:46 -04:00
|
|
|
glBegin(GL_LINES);
|
2015-06-27 01:26:07 -04:00
|
|
|
glVertex2f(min, max);
|
|
|
|
glVertex2f(max, max);
|
2015-06-22 22:07:46 -04:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_LINE_SMOOTH);
|
|
|
|
}
|
2015-08-17 21:52:38 -04:00
|
|
|
glDisable(GL_BLEND);
|
2015-06-20 20:19:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (contentsVisible) {
|
2015-07-05 18:54:46 -04:00
|
|
|
mat4 mCoord = mat4::identity();
|
|
|
|
|
|
|
|
if (coord == GLPANEL_Y_DOWN_ZERO_ONE) {
|
|
|
|
mCoord *= mat4::translate(-1.0f, 1.0f, 0.0f) * mat4::scale(2.0f, -2.0f, 2.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(1.0f, -1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
// if (coord == GLPANEL_Y_UP) {
|
|
|
|
// }
|
|
|
|
glLoadMatrixf(transform * mCoord);
|
2015-06-20 20:19:52 -04:00
|
|
|
drawPanelContents();
|
|
|
|
}
|
|
|
|
}
|
2015-06-21 11:58:14 -04:00
|
|
|
|
|
|
|
|
2015-07-01 00:34:32 -04:00
|
|
|
GLTextPanel::GLTextPanel() : GLPanel() {
|
2015-07-05 18:54:46 -04:00
|
|
|
coord = GLPANEL_Y_UP;
|
2015-08-17 21:52:38 -04:00
|
|
|
horizAlign = GLFont::GLFONT_ALIGN_CENTER;
|
|
|
|
vertAlign = GLFont::GLFONT_ALIGN_CENTER;
|
2016-06-22 15:21:32 -04:00
|
|
|
useNativeFont = true;
|
2015-07-01 00:34:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLTextPanel::drawPanelContents() {
|
|
|
|
glColor4f(1, 1, 1, 1.0);
|
2016-06-23 15:17:02 -04:00
|
|
|
|
2015-07-05 21:09:00 -04:00
|
|
|
|
|
|
|
|
2016-06-22 15:21:32 -04:00
|
|
|
float pdimy = pdim.y;
|
2016-06-23 15:17:02 -04:00
|
|
|
|
|
|
|
double appliedScaleFactor = GLFont::getScaleFactor();
|
2016-06-22 15:21:32 -04:00
|
|
|
|
2016-06-23 15:17:02 -04:00
|
|
|
if (useNativeFont) {
|
|
|
|
appliedScaleFactor = 1.0;
|
2016-06-22 15:21:32 -04:00
|
|
|
}
|
2016-06-22 13:04:59 -04:00
|
|
|
|
2016-06-23 15:17:02 -04:00
|
|
|
//pdimy is considered un-scaled
|
|
|
|
pdimy = round(pdimy / appliedScaleFactor);
|
|
|
|
|
|
|
|
//target font size: a bit smaller than pdimy:
|
|
|
|
int sz = 12;
|
2016-06-22 13:04:59 -04:00
|
|
|
|
2016-06-23 15:17:02 -04:00
|
|
|
if (pdimy > 14) {
|
|
|
|
//make the font a little smaller that the TextPanel
|
|
|
|
sz = pdimy - 2;
|
2016-06-22 13:04:59 -04:00
|
|
|
|
2016-06-23 15:17:02 -04:00
|
|
|
}
|
2016-06-21 13:13:48 -04:00
|
|
|
|
2016-06-23 15:17:02 -04:00
|
|
|
GLFont::getFont(sz, appliedScaleFactor).drawString(textVal, mid, mid, horizAlign, vertAlign, (int)pdim.x, (int)pdim.y);
|
2015-07-01 00:34:32 -04:00
|
|
|
}
|
|
|
|
|
2016-06-22 15:21:32 -04:00
|
|
|
void GLTextPanel::setText(std::string text, GLFont::Align hAlign, GLFont::Align vAlign, bool useNative) {
|
2015-07-01 00:34:32 -04:00
|
|
|
textVal = text;
|
2015-08-17 21:52:38 -04:00
|
|
|
horizAlign = hAlign;
|
|
|
|
vertAlign = vAlign;
|
2016-06-22 15:21:32 -04:00
|
|
|
useNativeFont = useNative;
|
2015-07-01 00:34:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string GLTextPanel::getText() {
|
|
|
|
return textVal;
|
|
|
|
}
|
|
|
|
|
2015-06-21 11:58:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
void GLTestPanel::drawPanelContents() {
|
|
|
|
glColor3f(1.0,1.0,1.0);
|
|
|
|
glBegin(GL_LINES);
|
2015-07-05 18:54:46 -04:00
|
|
|
glVertex2f(min, mid);
|
|
|
|
glVertex2f(max, mid);
|
|
|
|
glVertex2f(mid, min);
|
|
|
|
glVertex2f(mid, max);
|
2015-06-21 11:58:14 -04:00
|
|
|
|
2015-07-05 18:54:46 -04:00
|
|
|
glVertex2f(mid, max);
|
|
|
|
glVertex2f(mid - 0.02, max - 0.2);
|
|
|
|
glVertex2f(mid, 1);
|
|
|
|
glVertex2f(mid + 0.02, max - 0.2);
|
2015-06-21 11:58:14 -04:00
|
|
|
|
2015-07-05 18:54:46 -04:00
|
|
|
glVertex2f(max, mid);
|
|
|
|
glVertex2f(max - 0.1, mid + max * 0.25);
|
|
|
|
glVertex2f(max, mid);
|
|
|
|
glVertex2f(max - 0.1, mid - max * 0.25);
|
2015-06-21 11:58:14 -04:00
|
|
|
|
|
|
|
glEnd();
|
|
|
|
}
|