From 663f563af20cc0438e13deebe24fdbd391ee0c28 Mon Sep 17 00:00:00 2001 From: asb2m10 Date: Sat, 5 Mar 2016 23:51:13 -0500 Subject: [PATCH] Single click program loading (ref #49) --- Source/ProgramListBox.cpp | 32 ++++++++++++++++++++------------ Source/ProgramListBox.h | 3 ++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Source/ProgramListBox.cpp b/Source/ProgramListBox.cpp index db1b122..bd5202c 100644 --- a/Source/ProgramListBox.cpp +++ b/Source/ProgramListBox.cpp @@ -29,6 +29,7 @@ ProgramListBox::ProgramListBox(const String name, int numCols) : Component(name) selectedPgm = -1; hasContent = false; dragCandidate = -1; + pgmCandidate = -1; readOnly = false; programNames.clear(); } @@ -101,29 +102,36 @@ int ProgramListBox::programPosition(int x, int y) { return (y / cellHeight) + ((x / cellWidth) * rows); } -void ProgramListBox::mouseDoubleClick(const MouseEvent &event) { +void ProgramListBox::mouseDown(const MouseEvent &event) { + pgmCandidate = -1; + if ( ! hasContent ) return; - if ( ! event.mods.isLeftButtonDown() ) - return; - int pos = programPosition(event.getMouseDownX(), event.getMouseDownY()); - if ( listener != nullptr ) - listener->programSelected(this, pos); + if ( event.mods.isRightButtonDown() ) { + int pos = programPosition(event.getMouseDownX(), event.getMouseDownY()); + if ( listener != nullptr ) + listener->programRightClicked(this, pos); + return; + } + + pgmCandidate = programPosition(event.getMouseDownX(), event.getMouseDownY()); } -void ProgramListBox::mouseDown(const MouseEvent &event) { - if ( ! hasContent ) - return; - if ( ! event.mods.isRightButtonDown() ) +void ProgramListBox::mouseUp(const MouseEvent &event) { + if ( pgmCandidate == -1 ) return; int pos = programPosition(event.getMouseDownX(), event.getMouseDownY()); - if ( listener != nullptr ) - listener->programRightClicked(this, pos); + if ( pgmCandidate == pos) { + if ( listener != nullptr ) + listener->programSelected(this, pgmCandidate); + pgmCandidate = -1; + } } void ProgramListBox::mouseDrag(const MouseEvent &event) { + pgmCandidate = -1; if ( ! hasContent ) return; if ( dragCandidate != -1 ) diff --git a/Source/ProgramListBox.h b/Source/ProgramListBox.h index e9b592a..9df3578 100644 --- a/Source/ProgramListBox.h +++ b/Source/ProgramListBox.h @@ -45,6 +45,7 @@ class ProgramListBox : public Component, public DragAndDropTarget { Cartridge cartContent; int dragCandidate; + int pgmCandidate; public: StringArray programNames; @@ -54,9 +55,9 @@ public: void addListener(ProgramListBoxListener *listener); void paint(Graphics &g) override; void resized() override; - void mouseDoubleClick(const MouseEvent &event) override; void mouseDown(const MouseEvent &event) override; void mouseDrag(const MouseEvent &event) override; + void mouseUp(const MouseEvent &event) override; void setSelected(int idx); Cartridge &getCurrentCart();