Browse Source

Add AudioButton and MidiButton example. Make SvgButton trigger Action event when right-clicking.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
aee5e22ec2
4 changed files with 31 additions and 0 deletions
  1. +1
    -0
      include/app/SvgButton.hpp
  2. +16
    -0
      src/app/SvgButton.cpp
  3. +9
    -0
      src/core/AudioInterface.cpp
  4. +5
    -0
      src/core/MIDI_CV.cpp

+ 1
- 0
include/app/SvgButton.hpp View File

@@ -18,6 +18,7 @@ struct SvgButton : widget::OpaqueWidget {

SvgButton();
void addFrame(std::shared_ptr<Svg> svg);
void onButton(const ButtonEvent& e) override;
void onDragStart(const DragStartEvent& e) override;
void onDragEnd(const DragEndEvent& e) override;
void onDragDrop(const DragDropEvent& e) override;


+ 16
- 0
src/app/SvgButton.cpp View File

@@ -17,6 +17,19 @@ SvgButton::SvgButton() {
fb->addChild(sw);
}


void SvgButton::onButton(const ButtonEvent& e) {
OpaqueWidget::onButton(e);

// Accept left and right-click dragging.
if (e.action == GLFW_PRESS && (e.button == GLFW_MOUSE_BUTTON_LEFT || e.button == GLFW_MOUSE_BUTTON_RIGHT)) {
ActionEvent eAction;
onAction(eAction);
e.consume(this);
}
}


void SvgButton::addFrame(std::shared_ptr<Svg> svg) {
frames.push_back(svg);
// If this is our first frame, automatically set SVG and size
@@ -30,6 +43,7 @@ void SvgButton::addFrame(std::shared_ptr<Svg> svg) {
}
}


void SvgButton::onDragStart(const DragStartEvent& e) {
if (e.button != GLFW_MOUSE_BUTTON_LEFT)
return;
@@ -40,6 +54,7 @@ void SvgButton::onDragStart(const DragStartEvent& e) {
}
}


void SvgButton::onDragEnd(const DragEndEvent& e) {
if (frames.size() >= 1) {
sw->setSvg(frames[0]);
@@ -47,6 +62,7 @@ void SvgButton::onDragEnd(const DragEndEvent& e) {
}
}


void SvgButton::onDragDrop(const DragDropEvent& e) {
if (e.origin == this) {
ActionEvent eAction;


+ 9
- 0
src/core/AudioInterface.cpp View File

@@ -544,6 +544,15 @@ struct AudioInterfaceWidget : ModuleWidget {
// Adjust deviceChoice position
audioWidget->deviceChoice->textOffset = Vec(6, 14);
addChild(audioWidget);

// AudioButton example
// AudioButton* audioButton_ADAT = createWidget<AudioButton_ADAT>(Vec(0, 0));
// audioButton_ADAT->setAudioPort(module ? &module->port : NULL);
// addChild(audioButton_ADAT);

// AudioButton* audioButton_USB_B = createWidget<AudioButton_USB_B>(Vec(0, 40));
// audioButton_USB_B->setAudioPort(module ? &module->port : NULL);
// addChild(audioButton_USB_B);
}
}



+ 5
- 0
src/core/MIDI_CV.cpp View File

@@ -498,6 +498,11 @@ struct MIDI_CVWidget : ModuleWidget {
midiWidget->box.size = mm2px(Vec(33.840, 28));
midiWidget->setMidiPort(module ? &module->midiInput : NULL);
addChild(midiWidget);

// MidiButton example
// MidiButton* midiButton = createWidget<MidiButton_MIDI_DIN>(Vec(0, 0));
// midiButton->setMidiPort(module ? &module->midiInput : NULL);
// addChild(midiButton);
}

void appendContextMenu(Menu* menu) override {


Loading…
Cancel
Save