2015-01-04 19:50:05 -05:00
|
|
|
#include "ModeSelectorCanvas.h"
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "CubicSDR.h"
|
|
|
|
#include "CubicSDRDefs.h"
|
|
|
|
#include "AppFrame.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
wxBEGIN_EVENT_TABLE(ModeSelectorCanvas, wxGLCanvas) EVT_PAINT(ModeSelectorCanvas::OnPaint)
|
|
|
|
EVT_IDLE(ModeSelectorCanvas::OnIdle)
|
|
|
|
EVT_MOTION(ModeSelectorCanvas::OnMouseMoved)
|
|
|
|
EVT_LEFT_DOWN(ModeSelectorCanvas::OnMouseDown)
|
|
|
|
EVT_LEFT_UP(ModeSelectorCanvas::OnMouseReleased)
|
|
|
|
EVT_LEAVE_WINDOW(ModeSelectorCanvas::OnMouseLeftWindow)
|
|
|
|
EVT_ENTER_WINDOW(ModeSelectorCanvas::OnMouseEnterWindow)
|
|
|
|
wxEND_EVENT_TABLE()
|
|
|
|
|
|
|
|
ModeSelectorCanvas::ModeSelectorCanvas(wxWindow *parent, int *attribList) :
|
2015-07-30 19:30:46 -04:00
|
|
|
InteractiveCanvas(parent, attribList), numChoices(0), currentSelection(-1) {
|
2015-01-04 19:50:05 -05:00
|
|
|
|
|
|
|
glContext = new ModeSelectorContext(this, &wxGetApp().GetContext(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
ModeSelectorCanvas::~ModeSelectorCanvas() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-06 00:29:33 -05:00
|
|
|
int ModeSelectorCanvas::getHoveredSelection() {
|
|
|
|
if (!mouseTracker.mouseInView()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
float ypos = 1.0 - (mouseTracker.getMouseY() * 2.0);
|
|
|
|
float yval = (int) (((ypos + 1.0) / 2.0) * (float) numChoices);
|
|
|
|
|
|
|
|
return yval;
|
|
|
|
}
|
|
|
|
|
2015-01-04 19:50:05 -05:00
|
|
|
void ModeSelectorCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
|
|
|
wxPaintDC dc(this);
|
2015-02-10 23:49:34 -05:00
|
|
|
#ifdef __APPLE__ // force half-rate?
|
|
|
|
glFinish();
|
|
|
|
#endif
|
|
|
|
const wxSize ClientSize = GetClientSize();
|
2015-01-04 19:50:05 -05:00
|
|
|
|
|
|
|
glContext->SetCurrent(*this);
|
2015-02-09 20:49:21 -05:00
|
|
|
initGLExtensions();
|
|
|
|
|
2015-01-04 19:50:05 -05:00
|
|
|
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
|
|
|
|
|
|
|
glContext->DrawBegin();
|
|
|
|
|
2015-01-06 00:29:33 -05:00
|
|
|
int yval = getHoveredSelection();
|
|
|
|
|
|
|
|
for (int i = 0; i < numChoices; i++) {
|
2015-01-14 22:14:57 -05:00
|
|
|
if (yval == i) {
|
|
|
|
glContext->DrawSelector(selections[i].label, i, numChoices, true, ThemeMgr::mgr.currentTheme->buttonHighlight.r, ThemeMgr::mgr.currentTheme->buttonHighlight.g, ThemeMgr::mgr.currentTheme->buttonHighlight.b, 1.0);
|
|
|
|
} else {
|
|
|
|
glContext->DrawSelector(selections[i].label, i, numChoices, i == currentSelection, ThemeMgr::mgr.currentTheme->button.r, ThemeMgr::mgr.currentTheme->button.g, ThemeMgr::mgr.currentTheme->button.b, 1.0);
|
|
|
|
}
|
2015-01-06 00:29:33 -05:00
|
|
|
}
|
2015-01-04 19:50:05 -05:00
|
|
|
|
|
|
|
glContext->DrawEnd();
|
|
|
|
|
|
|
|
SwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModeSelectorCanvas::OnIdle(wxIdleEvent &event) {
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModeSelectorCanvas::OnMouseMoved(wxMouseEvent& event) {
|
|
|
|
InteractiveCanvas::OnMouseMoved(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModeSelectorCanvas::OnMouseDown(wxMouseEvent& event) {
|
|
|
|
InteractiveCanvas::OnMouseDown(event);
|
|
|
|
mouseTracker.setHorizDragLock(true);
|
|
|
|
mouseTracker.setVertDragLock(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModeSelectorCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
|
|
|
|
InteractiveCanvas::OnMouseWheelMoved(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModeSelectorCanvas::OnMouseReleased(wxMouseEvent& event) {
|
|
|
|
InteractiveCanvas::OnMouseReleased(event);
|
|
|
|
mouseTracker.setHorizDragLock(false);
|
|
|
|
mouseTracker.setVertDragLock(false);
|
2015-01-06 00:29:33 -05:00
|
|
|
|
|
|
|
const wxSize ClientSize = GetClientSize();
|
|
|
|
|
|
|
|
if (mouseTracker.getOriginDeltaMouseX() < 2.0 / ClientSize.y) {
|
|
|
|
currentSelection = getHoveredSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCursor (wxCURSOR_ARROW);
|
2015-01-04 19:50:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModeSelectorCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
|
|
|
|
InteractiveCanvas::OnMouseLeftWindow(event);
|
2015-01-06 00:29:33 -05:00
|
|
|
SetCursor (wxCURSOR_CROSS);
|
2015-01-04 19:50:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModeSelectorCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
|
|
|
|
InteractiveCanvas::mouseTracker.OnMouseEnterWindow(event);
|
2015-01-06 00:29:33 -05:00
|
|
|
SetCursor (wxCURSOR_ARROW);
|
2015-04-02 21:16:03 -04:00
|
|
|
if (!helpTip.empty()) {
|
|
|
|
setStatusText(helpTip);
|
|
|
|
}
|
2015-01-04 19:50:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModeSelectorCanvas::setHelpTip(std::string tip) {
|
|
|
|
helpTip = tip;
|
|
|
|
}
|
2015-01-06 00:29:33 -05:00
|
|
|
|
|
|
|
void ModeSelectorCanvas::setNumChoices(int numChoices_in) {
|
|
|
|
numChoices = numChoices_in;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModeSelectorCanvas::addChoice(int value, std::string label) {
|
|
|
|
selections.push_back(ModeSelectorMode(value, label));
|
|
|
|
numChoices = selections.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModeSelectorCanvas::setSelection(int value) {
|
|
|
|
for (int i = 0; i < numChoices; i++) {
|
|
|
|
if (selections[i].value == value) {
|
|
|
|
currentSelection = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentSelection = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModeSelectorCanvas::getSelection() {
|
|
|
|
if (currentSelection == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return selections[currentSelection].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|