CubicSDR/src/visual/ModeSelectorContext.cpp

75 lines
2.0 KiB
C++
Raw Normal View History

// Copyright (c) Charles J. Cliffe
// SPDX-License-Identifier: GPL-2.0+
2015-01-04 19:50:05 -05:00
#include "ModeSelectorContext.h"
#include "ModeSelectorCanvas.h"
2015-01-15 00:59:33 -05:00
#include "ColorTheme.h"
2015-01-04 19:50:05 -05:00
ModeSelectorContext::ModeSelectorContext(ModeSelectorCanvas *canvas, wxGLContext *sharedContext, wxGLContextAttrs *ctxAttrs) :
PrimaryGLContext(canvas, sharedContext, ctxAttrs) {
2015-01-04 19:50:05 -05:00
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
void ModeSelectorContext::DrawBegin() {
2015-01-15 00:59:33 -05:00
glClearColor(ThemeMgr::mgr.currentTheme->generalBackground.r, ThemeMgr::mgr.currentTheme->generalBackground.g, ThemeMgr::mgr.currentTheme->generalBackground.b,1.0);
2015-01-04 19:50:05 -05:00
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
}
2021-04-04 22:20:33 -04:00
void ModeSelectorContext::DrawSelector(const std::string& label, int c, int cMax, bool on, float r, float g, float b, float a, float px, float py) {
2015-01-05 19:12:16 -05:00
GLint vp[4];
glGetIntegerv( GL_VIEWPORT, vp);
float viewHeight = (float) vp[3];
float viewWidth = (float) vp[2];
int fontSize = 18;
2015-01-05 19:12:16 -05:00
if (viewWidth < 30 || viewHeight < 200) {
fontSize = 16;
2015-01-05 19:12:16 -05:00
}
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 = (px / viewWidth);
float padY = (py / viewHeight);
if (a < 1.0) {
glEnable(GL_BLEND);
}
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();
if (a < 1.0) {
glDisable(GL_BLEND);
}
2015-01-05 19:12:16 -05:00
if (on) {
2015-01-15 20:37:51 -05:00
glColor4f(0, 0, 0, a);
}
2015-01-05 19:12:16 -05:00
//Do not zoom the selectors
GLFont::getFont(fontSize).drawString(label, 0.0, y + height / 2.0, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
2015-01-04 19:50:05 -05:00
}
void ModeSelectorContext::DrawEnd() {
// glFlush();
2015-01-04 19:50:05 -05:00
// CheckGLError();
2015-01-04 19:50:05 -05:00
}