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)
|
2015-01-03 17:07:39 -05:00
|
|
|
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) :
|
2015-01-04 13:20:31 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MeterCanvas::setInputValue(float slider_in) {
|
|
|
|
userInputValue = inputValue = slider_in;
|
|
|
|
}
|
2015-01-04 13:20:31 -05:00
|
|
|
|
2014-12-31 21:43:05 -05:00
|
|
|
bool MeterCanvas::inputChanged() {
|
|
|
|
return (inputValue != userInputValue);
|
|
|
|
}
|
2015-01-04 13:20:31 -05:00
|
|
|
|
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);
|
|
|
|
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
|
|
|
|
|
|
|
glContext->DrawBegin();
|
2015-01-04 13:20:31 -05:00
|
|
|
if (mouseTracker.mouseInView()) {
|
|
|
|
glContext->Draw(0.4, 0.4, 0.4, 0.5, mouseTracker.getMouseY());
|
2014-12-31 21:43:05 -05:00
|
|
|
}
|
2015-01-14 22:14:57 -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);
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void MeterCanvas::OnMouseMoved(wxMouseEvent& event) {
|
2015-01-04 13:20:31 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void MeterCanvas::OnMouseDown(wxMouseEvent& event) {
|
2015-01-04 13:20:31 -05:00
|
|
|
InteractiveCanvas::OnMouseDown(event);
|
|
|
|
userInputValue = mouseTracker.getMouseY() * level_max;
|
|
|
|
mouseTracker.setHorizDragLock(true);
|
2014-12-31 21:43:05 -05:00
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void MeterCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
|
2015-01-04 13:20:31 -05:00
|
|
|
InteractiveCanvas::OnMouseWheelMoved(event);
|
2014-12-31 21:43:05 -05:00
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void MeterCanvas::OnMouseReleased(wxMouseEvent& event) {
|
2015-01-04 13:20:31 -05:00
|
|
|
InteractiveCanvas::OnMouseReleased(event);
|
|
|
|
userInputValue = mouseTracker.getMouseY() * level_max;
|
2014-12-31 21:43:05 -05:00
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void MeterCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
|
2015-01-04 13:20:31 -05:00
|
|
|
InteractiveCanvas::OnMouseLeftWindow(event);
|
2014-12-31 21:43:05 -05:00
|
|
|
SetCursor(wxCURSOR_CROSS);
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void MeterCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
|
2015-01-04 13:20:31 -05:00
|
|
|
InteractiveCanvas::mouseTracker.OnMouseEnterWindow(event);
|
2014-12-31 21:43:05 -05:00
|
|
|
SetCursor(wxCURSOR_CROSS);
|
|
|
|
}
|
2015-01-04 13:20:31 -05:00
|
|
|
|
|
|
|
void MeterCanvas::setHelpTip(std::string tip) {
|
|
|
|
helpTip = tip;
|
|
|
|
}
|