Merge pull request #355 from cjcliffe/mousewheel_tweak

Mousewheel tweaks
- Fix wheel for windows 7
- Fix mousewheel ranges and movement
- Add gain mousewheel support
- Focus tweaks / fixes
This commit is contained in:
Charles J. Cliffe 2016-05-31 18:10:27 -04:00
commit a75faaf4f2
9 changed files with 91 additions and 22 deletions

View File

@ -6,7 +6,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
SET(CUBICSDR_VERSION_MAJOR "0")
SET(CUBICSDR_VERSION_MINOR "1")
SET(CUBICSDR_VERSION_PATCH "28")
SET(CUBICSDR_VERSION_PATCH "29")
SET(CUBICSDR_VERSION_REL "alpha")
SET(CUBICSDR_VERSION "${CUBICSDR_VERSION_MAJOR}.${CUBICSDR_VERSION_MINOR}.${CUBICSDR_VERSION_PATCH}-${CUBICSDR_VERSION_REL}")

View File

@ -1490,6 +1490,12 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
}
#endif
#ifdef _WIN32
if (scopeCanvas->HasFocus()) {
waterfallCanvas->SetFocus();
}
#endif
if (!this->IsActive()) {
std::this_thread::sleep_for(std::chrono::milliseconds(30));
} else {
@ -1779,6 +1785,11 @@ void AppFrame::refreshGainUI() {
gainCanvas->Refresh();
}
#ifdef _WIN32
bool AppFrame::canFocus() {
return (!wxGetApp().isDeviceSelectorOpen() && (!modemProps || !modemProps->isMouseInView()));
}
#endif
FrequencyDialog::FrequencyDialogTarget AppFrame::getFrequencyDialogTarget() {
FrequencyDialog::FrequencyDialogTarget target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_DEFAULT;

View File

@ -96,6 +96,10 @@ public:
FrequencyDialog::FrequencyDialogTarget getFrequencyDialogTarget();
void refreshGainUI();
#ifdef _WIN32
bool canFocus();
#endif
private:
void OnMenu(wxCommandEvent& event);
void OnClose(wxCloseEvent& event);

View File

@ -22,6 +22,7 @@ EVT_LEFT_DOWN(GainCanvas::OnMouseDown)
EVT_LEFT_UP(GainCanvas::OnMouseReleased)
EVT_LEAVE_WINDOW(GainCanvas::OnMouseLeftWindow)
EVT_ENTER_WINDOW(GainCanvas::OnMouseEnterWindow)
EVT_MOUSEWHEEL(GainCanvas::OnMouseWheelMoved)
wxEND_EVENT_TABLE()
GainCanvas::GainCanvas(wxWindow *parent, int *dispAttrs) :
@ -151,12 +152,31 @@ void GainCanvas::OnMouseDown(wxMouseEvent& event) {
void GainCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
InteractiveCanvas::OnMouseWheelMoved(event);
// Refresh();
CubicVR::vec2 hitResult;
int panelHit = GetPanelHit(hitResult);
if (panelHit >= 0) {
float movement = 3.0 * (float)event.GetWheelRotation();
GainInfo *gInfo;
gInfo = gainInfo[panelHit];
gInfo->current = gInfo->current + ((movement / 100.0) * ((gInfo->high - gInfo->low) / 100.0));
gInfo->changed = true;
float levelVal = float(gInfo->current-gInfo->low)/float(gInfo->high-gInfo->low);
gInfo->levelPanel.setSize(1.0, levelVal);
gInfo->levelPanel.setPosition(0.0, levelVal-1.0);
gInfo->valuePanel.setText(std::to_string(int(gInfo->current)));
}
}
void GainCanvas::OnMouseReleased(wxMouseEvent& event) {
InteractiveCanvas::OnMouseReleased(event);
// Refresh();
}
void GainCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
@ -174,7 +194,11 @@ void GainCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
void GainCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
InteractiveCanvas::mouseTracker.OnMouseEnterWindow(event);
SetCursor(wxCURSOR_CROSS);
// Refresh();
#ifdef _WIN32
if (wxGetApp().getAppFrame()->canFocus()) {
this->SetFocus();
}
#endif
}

View File

@ -126,31 +126,45 @@ void MeterCanvas::OnMouseDown(wxMouseEvent& event) {
InteractiveCanvas::OnMouseDown(event);
userInputValue = mouseTracker.getMouseY() * (level_max-level_min) + level_min;
mouseTracker.setHorizDragLock(true);
Refresh();
}
void MeterCanvas::OnMouseReleased(wxMouseEvent& event) {
InteractiveCanvas::OnMouseReleased(event);
userInputValue = mouseTracker.getMouseY() * (level_max-level_min) + level_min;
Refresh();
}
void MeterCanvas::OnMouseRightDown(wxMouseEvent& event) {
InteractiveCanvas::OnMouseRightDown(event);
Refresh();
}
void MeterCanvas::OnMouseRightReleased(wxMouseEvent& event) {
InteractiveCanvas::OnMouseRightReleased(event);
if (showUserInput) {
userInputValue = level - level * 0.02;
Refresh();
}
}
void MeterCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
InteractiveCanvas::OnMouseWheelMoved(event);
float movement = (float)event.GetWheelRotation() / (float)event.GetLinesPerAction();
userInputValue = userInputValue + movement / 1000;
Refresh();
float movement = 3.0 * (float)event.GetWheelRotation();
float currentValue = 0;
if (showUserInput) {
currentValue = userInputValue;
} else {
currentValue = level;
}
currentValue = currentValue + ((movement / 100.0) * ((level_max - level_min) / 100.0));
if (currentValue > level_max) {
currentValue = level_max;
}
if (currentValue < level_min) {
currentValue = level_min;
}
userInputValue = currentValue;
}
void MeterCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
@ -162,9 +176,12 @@ void MeterCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
void MeterCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
InteractiveCanvas::mouseTracker.OnMouseEnterWindow(event);
SetCursor(wxCURSOR_CROSS);
Refresh();
#ifdef _WIN32
if (wxGetApp().getAppFrame()->canFocus()) {
this->SetFocus();
}
#endif
}
void MeterCanvas::setHelpTip(std::string tip) {
helpTip = tip;

View File

@ -248,6 +248,9 @@ void SpectrumCanvas::OnMouseDown(wxMouseEvent& event) {
void SpectrumCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
InteractiveCanvas::OnMouseWheelMoved(event);
if (waterfallCanvas) {
waterfallCanvas->OnMouseWheelMoved(event);
}
}
void SpectrumCanvas::OnMouseReleased(wxMouseEvent& event) {
@ -259,9 +262,11 @@ void SpectrumCanvas::OnMouseReleased(wxMouseEvent& event) {
void SpectrumCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseEnterWindow(event);
SetCursor(wxCURSOR_SIZEWE);
if (waterfallCanvas) {
waterfallCanvas->SetFocus();
#ifdef _WIN32
if (wxGetApp().getAppFrame()->canFocus()) {
this->SetFocus();
}
#endif
}
void SpectrumCanvas::OnMouseLeftWindow(wxMouseEvent& event) {

View File

@ -410,8 +410,12 @@ void TuningCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
hoverIndex = 0;
hoverState = TUNING_HOVER_NONE;
lastPPM = currentPPM = wxGetApp().getPPM();
#ifdef _WIN32
if (wxGetApp().getAppFrame()->canFocus()) {
this->SetFocus();
}
#endif
}
void TuningCanvas::setHelpTip(std::string tip) {
helpTip = tip;

View File

@ -852,8 +852,12 @@ void WaterfallCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
void WaterfallCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseEnterWindow(event);
SetCursor(wxCURSOR_CROSS);
#ifdef _WIN32
if (wxGetApp().getAppFrame()->canFocus()) {
this->SetFocus();
}
#endif
}
void WaterfallCanvas::OnMouseRightDown(wxMouseEvent& event) {
InteractiveCanvas::OnMouseRightDown(event);

View File

@ -35,6 +35,7 @@ public:
void OnKeyDown(wxKeyEvent& event);
void OnKeyUp(wxKeyEvent& event);
void OnMouseWheelMoved(wxMouseEvent& event);
private:
void OnPaint(wxPaintEvent& event);
@ -43,7 +44,6 @@ private:
void updateHoverState();
void OnMouseMoved(wxMouseEvent& event);
void OnMouseWheelMoved(wxMouseEvent& event);
void OnMouseDown(wxMouseEvent& event);
void OnMouseReleased(wxMouseEvent& event);
void OnMouseRightDown(wxMouseEvent& event);