mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-02-03 09:44:26 -05:00
Mode selector class framework
This commit is contained in:
parent
482ff41382
commit
137116da9c
@ -141,6 +141,8 @@ SET (cubicsdr_sources
|
||||
src/visual/MeterContext.cpp
|
||||
src/visual/TuningCanvas.cpp
|
||||
src/visual/TuningContext.cpp
|
||||
src/visual/ModeSelectorCanvas.cpp
|
||||
src/visual/ModeSelectorContext.cpp
|
||||
src/visual/ScopeCanvas.cpp
|
||||
src/visual/ScopeContext.cpp
|
||||
src/visual/SpectrumCanvas.cpp
|
||||
@ -175,6 +177,8 @@ SET (cubicsdr_headers
|
||||
src/visual/MeterContext.h
|
||||
src/visual/TuningCanvas.h
|
||||
src/visual/TuningContext.h
|
||||
src/visual/ModeSelectorCanvas.h
|
||||
src/visual/ModeSelectorContext.h
|
||||
src/visual/ScopeCanvas.h
|
||||
src/visual/ScopeContext.h
|
||||
src/visual/SpectrumCanvas.h
|
||||
|
89
src/visual/ModeSelectorCanvas.cpp
Normal file
89
src/visual/ModeSelectorCanvas.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#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) :
|
||||
InteractiveCanvas(parent, attribList), dragAccum(0) {
|
||||
|
||||
glContext = new ModeSelectorContext(this, &wxGetApp().GetContext(this));
|
||||
}
|
||||
|
||||
ModeSelectorCanvas::~ModeSelectorCanvas() {
|
||||
|
||||
}
|
||||
|
||||
void ModeSelectorCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
wxPaintDC dc(this);
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
|
||||
glContext->SetCurrent(*this);
|
||||
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
||||
|
||||
glContext->DrawBegin();
|
||||
|
||||
|
||||
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);
|
||||
SetCursor(wxCURSOR_ARROW);
|
||||
}
|
||||
|
||||
void ModeSelectorCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
|
||||
InteractiveCanvas::OnMouseLeftWindow(event);
|
||||
SetCursor(wxCURSOR_CROSS);
|
||||
}
|
||||
|
||||
void ModeSelectorCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
|
||||
InteractiveCanvas::mouseTracker.OnMouseEnterWindow(event);
|
||||
SetCursor(wxCURSOR_ARROW);
|
||||
}
|
||||
|
||||
void ModeSelectorCanvas::setHelpTip(std::string tip) {
|
||||
helpTip = tip;
|
||||
}
|
40
src/visual/ModeSelectorCanvas.h
Normal file
40
src/visual/ModeSelectorCanvas.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "wx/glcanvas.h"
|
||||
#include "wx/timer.h"
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
#include "InteractiveCanvas.h"
|
||||
#include "ModeSelectorContext.h"
|
||||
#include "MouseTracker.h"
|
||||
|
||||
#include "fftw3.h"
|
||||
#include "Timer.h"
|
||||
|
||||
class ModeSelectorCanvas: public InteractiveCanvas {
|
||||
public:
|
||||
ModeSelectorCanvas(wxWindow *parent, int *attribList = NULL);
|
||||
~ModeSelectorCanvas();
|
||||
|
||||
void setHelpTip(std::string tip);
|
||||
|
||||
private:
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnIdle(wxIdleEvent &event);
|
||||
|
||||
void OnMouseMoved(wxMouseEvent& event);
|
||||
void OnMouseDown(wxMouseEvent& event);
|
||||
void OnMouseWheelMoved(wxMouseEvent& event);
|
||||
void OnMouseReleased(wxMouseEvent& event);
|
||||
void OnMouseEnterWindow(wxMouseEvent& event);
|
||||
void OnMouseLeftWindow(wxMouseEvent& event);
|
||||
|
||||
ModeSelectorContext *glContext;
|
||||
|
||||
std::string helpTip;
|
||||
//
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
};
|
||||
|
40
src/visual/ModeSelectorContext.cpp
Normal file
40
src/visual/ModeSelectorContext.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
void ModeSelectorContext::Draw(float r, float g, float b, float a, float level) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glColor4f(r, g, b, a);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(1.0, -1.0 + 2.0 * level);
|
||||
glVertex2f(-1.0, -1.0 + 2.0 * level);
|
||||
glVertex2f(-1.0, -1.0);
|
||||
glVertex2f(1.0, -1.0);
|
||||
glEnd();
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void ModeSelectorContext::DrawEnd() {
|
||||
glFlush();
|
||||
|
||||
CheckGLError();
|
||||
}
|
||||
|
17
src/visual/ModeSelectorContext.h
Normal file
17
src/visual/ModeSelectorContext.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "PrimaryGLContext.h"
|
||||
#include "Gradient.h"
|
||||
|
||||
#define NUM_WATERFALL_LINES 512
|
||||
|
||||
class ModeSelectorCanvas;
|
||||
|
||||
class ModeSelectorContext: public PrimaryGLContext {
|
||||
public:
|
||||
ModeSelectorContext(ModeSelectorCanvas *canvas, wxGLContext *sharedContext);
|
||||
|
||||
void DrawBegin();
|
||||
void Draw(float r, float g, float b, float a, float level);
|
||||
void DrawEnd();
|
||||
};
|
Loading…
Reference in New Issue
Block a user