CubicSDR/src/visual/ModeSelectorContext.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

2015-01-04 19:50:05 -05:00
#include "ModeSelectorContext.h"
#include "ModeSelectorCanvas.h"
ModeSelectorContext::ModeSelectorContext(ModeSelectorCanvas *canvas, wxGLContext *sharedContext) :
PrimaryGLContext(canvas, sharedContext) {
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
void ModeSelectorContext::DrawBegin() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
}
2015-01-05 19:12:16 -05:00
void ModeSelectorContext::DrawSelector(std::string label, int c, int cMax, bool on, float r, float g, float b, float a) {
GLint vp[4];
glGetIntegerv( GL_VIEWPORT, vp);
float viewHeight = (float) vp[3];
float viewWidth = (float) vp[2];
PrimaryGLContext::GLFontSize fontSize = GLFONT_SIZE16;
int fontHeight = 16;
if (viewWidth < 30) {
fontSize = GLFONT_SIZE12;
fontHeight = 12;
}
2015-01-04 19:50:05 -05:00
glColor4f(r, g, b, a);
2015-01-05 19:12:16 -05:00
float y = 1.0 - ((float) (c+1) / (float) cMax * 2.0);
2015-01-05 19:12:16 -05:00
float height = (2.0 / (float) cMax);
float padX = (4.0 / viewWidth);
float padY = (4.0 / viewHeight);
glBegin(on?GL_QUADS:GL_LINE_LOOP);
2015-01-05 19:12:16 -05:00
glVertex2f(-1.0 + padX, y + padY);
glVertex2f(1.0 - padX, y + padY);
glVertex2f(1.0 - padX, y + height - padY);
glVertex2f(-1.0 + padX, y + height - padY);
2015-01-04 19:50:05 -05:00
glEnd();
2015-01-05 19:12:16 -05:00
if (on) {
glColor4f(1.0-r, 1.0-g, 1.0-b, a);
}
2015-01-05 19:12:16 -05:00
getFont(fontSize).drawString(label, 0.0, y + height / 2.0, fontHeight, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
2015-01-04 19:50:05 -05:00
}
void ModeSelectorContext::DrawEnd() {
glFlush();
CheckGLError();
}