Single click program loading (ref #49)

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

@ -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 )

@ -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();

Loading…
Cancel
Save