mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-04-04 10:38:50 -04:00
Simple class for tracking wx mouse in unit 0..1
This commit is contained in:
parent
4900ce7f17
commit
f6966b1824
@ -95,6 +95,7 @@ SET (cubicsdr_sources
|
||||
src/audio/AudioThread.cpp
|
||||
src/util/Gradient.cpp
|
||||
src/util/Timer.cpp
|
||||
src/util/MouseTracker.cpp
|
||||
src/visual/PrimaryGLContext.cpp
|
||||
src/visual/ScopeCanvas.cpp
|
||||
src/visual/ScopeContext.cpp
|
||||
@ -115,6 +116,7 @@ SET (cubicsdr_headers
|
||||
src/util/Gradient.h
|
||||
src/util/Timer.h
|
||||
src/util/ThreadQueue.h
|
||||
src/util/MouseTracker.h
|
||||
src/visual/PrimaryGLContext.h
|
||||
src/visual/ScopeCanvas.h
|
||||
src/visual/ScopeContext.h
|
||||
|
73
src/util/MouseTracker.cpp
Normal file
73
src/util/MouseTracker.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#include "MouseTracker.h"
|
||||
|
||||
void MouseTracker::OnMouseMoved(wxMouseEvent& event) {
|
||||
if (isMouseDown) {
|
||||
const wxSize ClientSize = target->GetClientSize();
|
||||
float mouseX = (float) event.m_x / (float) ClientSize.x;
|
||||
float mouseY = (float) event.m_y / (float) ClientSize.y;
|
||||
|
||||
deltaMouseX = mouseX - lastMouseX;
|
||||
deltaMouseY = mouseY - lastMouseY;
|
||||
|
||||
lastMouseX = mouseX;
|
||||
|
||||
if (vertDragLock && mouseY != lastMouseY) {
|
||||
target->WarpPointer(event.m_x, lastMouseY * ClientSize.y);
|
||||
} else {
|
||||
lastMouseY = mouseY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MouseTracker::OnMouseDown(wxMouseEvent& event) {
|
||||
const wxSize ClientSize = target->GetClientSize();
|
||||
|
||||
lastMouseX = (float) event.m_x / (float) ClientSize.x;
|
||||
lastMouseY = (float) event.m_y / (float) ClientSize.y;
|
||||
|
||||
isMouseDown = true;
|
||||
}
|
||||
|
||||
void MouseTracker::OnMouseWheelMoved(wxMouseEvent& event) {
|
||||
// std::cout << "wheel?" << std::endl;
|
||||
}
|
||||
|
||||
void MouseTracker::OnMouseReleased(wxMouseEvent& event) {
|
||||
isMouseDown = false;
|
||||
}
|
||||
|
||||
void MouseTracker::OnMouseLeftWindow(wxMouseEvent& event) {
|
||||
isMouseDown = false;
|
||||
}
|
||||
|
||||
float MouseTracker::getDeltaMouseX() {
|
||||
return deltaMouseX;
|
||||
}
|
||||
|
||||
float MouseTracker::getDeltaMouseY() {
|
||||
return deltaMouseY;
|
||||
}
|
||||
|
||||
float MouseTracker::getLastMouseX() {
|
||||
return lastMouseX;
|
||||
}
|
||||
|
||||
float MouseTracker::getLastMouseY() {
|
||||
return lastMouseY;
|
||||
}
|
||||
|
||||
float MouseTracker::getMouseX() {
|
||||
return mouseX;
|
||||
}
|
||||
|
||||
float MouseTracker::getMouseY() {
|
||||
return mouseY;
|
||||
}
|
||||
|
||||
void MouseTracker::setVertDragLock(bool dragLock) {
|
||||
vertDragLock = dragLock;
|
||||
}
|
||||
|
||||
bool MouseTracker::mouseDown() {
|
||||
return isMouseDown;
|
||||
}
|
35
src/util/MouseTracker.h
Normal file
35
src/util/MouseTracker.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "wx/window.h"
|
||||
|
||||
class MouseTracker {
|
||||
public:
|
||||
MouseTracker(wxWindow *target) :
|
||||
target(target), mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), deltaMouseX(0), deltaMouseY(0), isMouseDown(false), vertDragLock(false) {
|
||||
|
||||
}
|
||||
|
||||
void OnMouseMoved(wxMouseEvent& event);
|
||||
void OnMouseDown(wxMouseEvent& event);
|
||||
void OnMouseWheelMoved(wxMouseEvent& event);
|
||||
void OnMouseReleased(wxMouseEvent& event);
|
||||
void OnMouseLeftWindow(wxMouseEvent& event);
|
||||
|
||||
float getDeltaMouseX();
|
||||
float getDeltaMouseY();
|
||||
float getLastMouseX();
|
||||
float getLastMouseY();
|
||||
float getMouseX();
|
||||
float getMouseY();
|
||||
|
||||
void setVertDragLock(bool dragLock);
|
||||
bool mouseDown();
|
||||
|
||||
private:
|
||||
float mouseX, mouseY;
|
||||
float lastMouseX, lastMouseY;
|
||||
float deltaMouseX, deltaMouseY;
|
||||
bool isMouseDown;
|
||||
bool vertDragLock;
|
||||
wxWindow *target;
|
||||
};
|
Loading…
Reference in New Issue
Block a user