Single click program loading (ref #49)

pull/1/head
asb2m10 9 years ago
parent 87ca47eabb
commit 663f563af2
  1. 26
      Source/ProgramListBox.cpp
  2. 3
      Source/ProgramListBox.h

@ -29,6 +29,7 @@ ProgramListBox::ProgramListBox(const String name, int numCols) : Component(name)
selectedPgm = -1; selectedPgm = -1;
hasContent = false; hasContent = false;
dragCandidate = -1; dragCandidate = -1;
pgmCandidate = -1;
readOnly = false; readOnly = false;
programNames.clear(); programNames.clear();
} }
@ -101,29 +102,36 @@ int ProgramListBox::programPosition(int x, int y) {
return (y / cellHeight) + ((x / cellWidth) * rows); return (y / cellHeight) + ((x / cellWidth) * rows);
} }
void ProgramListBox::mouseDoubleClick(const MouseEvent &event) { void ProgramListBox::mouseDown(const MouseEvent &event) {
pgmCandidate = -1;
if ( ! hasContent ) if ( ! hasContent )
return; return;
if ( ! event.mods.isLeftButtonDown() )
return;
if ( event.mods.isRightButtonDown() ) {
int pos = programPosition(event.getMouseDownX(), event.getMouseDownY()); int pos = programPosition(event.getMouseDownX(), event.getMouseDownY());
if ( listener != nullptr ) if ( listener != nullptr )
listener->programSelected(this, pos); listener->programRightClicked(this, pos);
return;
}
pgmCandidate = programPosition(event.getMouseDownX(), event.getMouseDownY());
} }
void ProgramListBox::mouseDown(const MouseEvent &event) { void ProgramListBox::mouseUp(const MouseEvent &event) {
if ( ! hasContent ) if ( pgmCandidate == -1 )
return;
if ( ! event.mods.isRightButtonDown() )
return; return;
int pos = programPosition(event.getMouseDownX(), event.getMouseDownY()); int pos = programPosition(event.getMouseDownX(), event.getMouseDownY());
if ( pgmCandidate == pos) {
if ( listener != nullptr ) if ( listener != nullptr )
listener->programRightClicked(this, pos); listener->programSelected(this, pgmCandidate);
pgmCandidate = -1;
}
} }
void ProgramListBox::mouseDrag(const MouseEvent &event) { void ProgramListBox::mouseDrag(const MouseEvent &event) {
pgmCandidate = -1;
if ( ! hasContent ) if ( ! hasContent )
return; return;
if ( dragCandidate != -1 ) if ( dragCandidate != -1 )

@ -45,6 +45,7 @@ class ProgramListBox : public Component, public DragAndDropTarget {
Cartridge cartContent; Cartridge cartContent;
int dragCandidate; int dragCandidate;
int pgmCandidate;
public: public:
StringArray programNames; StringArray programNames;
@ -54,9 +55,9 @@ public:
void addListener(ProgramListBoxListener *listener); void addListener(ProgramListBoxListener *listener);
void paint(Graphics &g) override; void paint(Graphics &g) override;
void resized() override; void resized() override;
void mouseDoubleClick(const MouseEvent &event) override;
void mouseDown(const MouseEvent &event) override; void mouseDown(const MouseEvent &event) override;
void mouseDrag(const MouseEvent &event) override; void mouseDrag(const MouseEvent &event) override;
void mouseUp(const MouseEvent &event) override;
void setSelected(int idx); void setSelected(int idx);
Cartridge &getCurrentCart(); Cartridge &getCurrentCart();

Loading…
Cancel
Save