CubicSDR/src/visual/MeterCanvas.cpp

125 lines
3.3 KiB
C++
Raw Normal View History

2014-12-31 21:43:05 -05:00
#include "MeterCanvas.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(MeterCanvas, wxGLCanvas) EVT_PAINT(MeterCanvas::OnPaint)
EVT_IDLE(MeterCanvas::OnIdle)
EVT_MOTION(MeterCanvas::OnMouseMoved)
EVT_LEFT_DOWN(MeterCanvas::OnMouseDown)
EVT_LEFT_UP(MeterCanvas::OnMouseReleased)
EVT_LEAVE_WINDOW(MeterCanvas::OnMouseLeftWindow)
EVT_ENTER_WINDOW(MeterCanvas::OnMouseEnterWindow)
2014-12-31 21:43:05 -05:00
wxEND_EVENT_TABLE()
MeterCanvas::MeterCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), level(0), level_max(1), inputValue(0), userInputValue(0) {
2014-12-31 21:43:05 -05:00
glContext = new MeterContext(this, &wxGetApp().GetContext(this));
}
MeterCanvas::~MeterCanvas() {
}
void MeterCanvas::setLevel(float level_in) {
level = level_in;
}
float MeterCanvas::getLevel() {
return level;
}
void MeterCanvas::setMax(float max_in) {
level_max = max_in;
}
void MeterCanvas::setInputValue(float slider_in) {
2014-12-31 21:43:05 -05:00
userInputValue = inputValue = slider_in;
}
2014-12-31 21:43:05 -05:00
bool MeterCanvas::inputChanged() {
return (inputValue != userInputValue);
}
2014-12-31 21:43:05 -05:00
float MeterCanvas::getInputValue() {
inputValue = userInputValue;
return userInputValue;
}
void MeterCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this);
const wxSize ClientSize = GetClientSize();
glContext->SetCurrent(*this);
initGLExtensions();
2014-12-31 21:43:05 -05:00
glViewport(0, 0, ClientSize.x, ClientSize.y);
glContext->DrawBegin();
if (mouseTracker.mouseInView()) {
glContext->Draw(0.4, 0.4, 0.4, 0.5, mouseTracker.getMouseY());
2014-12-31 21:43:05 -05:00
}
glContext->Draw(ThemeMgr::mgr.currentTheme->meterLevel.r, ThemeMgr::mgr.currentTheme->meterLevel.g, ThemeMgr::mgr.currentTheme->meterLevel.b, 0.5, level / level_max);
glContext->Draw(ThemeMgr::mgr.currentTheme->meterValue.r, ThemeMgr::mgr.currentTheme->meterValue.g, ThemeMgr::mgr.currentTheme->meterValue.b, 0.5, userInputValue / level_max);
2014-12-31 21:43:05 -05:00
glContext->DrawEnd();
SwapBuffers();
}
void MeterCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false);
}
void MeterCanvas::OnMouseMoved(wxMouseEvent& event) {
InteractiveCanvas::OnMouseMoved(event);
if (mouseTracker.mouseDown()) {
userInputValue = mouseTracker.getMouseY() * level_max;
} else {
if (!helpTip.empty()) {
setStatusText(helpTip);
}
2014-12-31 21:43:05 -05:00
}
}
void MeterCanvas::OnMouseDown(wxMouseEvent& event) {
InteractiveCanvas::OnMouseDown(event);
userInputValue = mouseTracker.getMouseY() * level_max;
mouseTracker.setHorizDragLock(true);
2014-12-31 21:43:05 -05:00
}
void MeterCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
InteractiveCanvas::OnMouseWheelMoved(event);
2014-12-31 21:43:05 -05:00
}
void MeterCanvas::OnMouseReleased(wxMouseEvent& event) {
InteractiveCanvas::OnMouseReleased(event);
userInputValue = mouseTracker.getMouseY() * level_max;
2014-12-31 21:43:05 -05:00
}
void MeterCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseLeftWindow(event);
2014-12-31 21:43:05 -05:00
SetCursor(wxCURSOR_CROSS);
}
void MeterCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
InteractiveCanvas::mouseTracker.OnMouseEnterWindow(event);
2014-12-31 21:43:05 -05:00
SetCursor(wxCURSOR_CROSS);
}
void MeterCanvas::setHelpTip(std::string tip) {
helpTip = tip;
}