From f79090407d28fb181bf42fa266b1d14fbe209f31 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 21 Nov 2020 07:37:47 -0500 Subject: [PATCH] Add ui::OptionButton. Replace ShowButton with OptionButton in tip window. Add a few tips. --- include/Quantity.hpp | 2 ++ include/ui/OptionButton.hpp | 23 +++++++++++++++++++++++ src/Quantity.cpp | 4 ++++ src/app/TipWindow.cpp | 30 ++++++++++++++++++------------ src/ui/OptionButton.cpp | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 include/ui/OptionButton.hpp create mode 100644 src/ui/OptionButton.cpp diff --git a/include/Quantity.hpp b/include/Quantity.hpp index 6aa2019d..02aeb194 100644 --- a/include/Quantity.hpp +++ b/include/Quantity.hpp @@ -88,6 +88,8 @@ struct Quantity { void setMin(); /** Sets the value to the max value. */ void setMax(); + /** Sets the value to max if the current value is min, otherwise sets the value to min. */ + void toggle(); /** Sets value from the range 0 to 1. */ void setScaledValue(float scaledValue); /** Returns the value rescaled to the range 0 to 1. */ diff --git a/include/ui/OptionButton.hpp b/include/ui/OptionButton.hpp new file mode 100644 index 00000000..8331806a --- /dev/null +++ b/include/ui/OptionButton.hpp @@ -0,0 +1,23 @@ +#pragma once +#include +#include +#include + + +namespace rack { +namespace ui { + + +struct OptionButton : widget::OpaqueWidget { + std::string text; + /** Not owned. Tracks the pressed state of the button.*/ + Quantity* quantity = NULL; + + OptionButton(); + void draw(const DrawArgs& args) override; + void onDragDrop(const event::DragDrop& e) override; +}; + + +} // namespace ui +} // namespace rack diff --git a/src/Quantity.cpp b/src/Quantity.cpp index 2a87cb02..6820a0c1 100644 --- a/src/Quantity.cpp +++ b/src/Quantity.cpp @@ -73,6 +73,10 @@ void Quantity::setMax() { setValue(getMaxValue()); } +void Quantity::toggle() { + setValue(isMin() ? getMaxValue() : getMinValue()); +} + void Quantity::setScaledValue(float scaledValue) { if (!isBounded()) setValue(scaledValue); diff --git a/src/app/TipWindow.cpp b/src/app/TipWindow.cpp index 740fa18e..c408b980 100644 --- a/src/app/TipWindow.cpp +++ b/src/app/TipWindow.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -51,19 +52,20 @@ struct TipInfo { }; +// Remember to use “smart quotes.” static std::vector tipInfos = { {"To add a module to the rack, right-click an empty rack space or press Enter. Click and drag a module from the Module Browser into the desired rack space.\n\nYou can force-move modules by holding " RACK_MOD_CTRL_NAME " while dragging it.", "", ""}, // reviewed {"Pan around the rack by using the scroll bars, dragging while holding the middle mouse button, or pressing the arrow keys. Arrow key panning speed can be modified by holding " RACK_MOD_CTRL_NAME ", " RACK_MOD_SHIFT_NAME ", or " RACK_MOD_CTRL_NAME "+" RACK_MOD_SHIFT_NAME ".\n\nZoom in and out using the View menu, " RACK_MOD_CTRL_NAME "+scroll, or " RACK_MOD_CTRL_NAME "+= / " RACK_MOD_CTRL_NAME "+-.", "", ""}, // reviewed // {"Want to use VCV Rack as a plugin in your DAW? VCV Rack for DAWs is available now as a 64-bit VST 2 plugin for Ableton Live, Cubase, FL Studio, Reason, Studio One, REAPER, Bitwig, and more. Other plugin formats coming soon.", "Learn more", "https://vcvrack.com/RackForDAWs"}, // reviewed - {"You can use Rack fullscreen by selecting View > Fullscreen or pressing F11.\n\nIn fullscreen mode, the menu bar and scroll bars are hidden. This is ideal for screen recording with VCV Recorder.", "Get VCV Recorder", "https://vcvrack.com/Recorder"}, // reviewed - {"You can browse over 2400 modules on the VCV Library.", "VCV Library", "https://library.vcvrack.com/"}, - {"Some plugin developers accept donations for their work. Right-click a module panel and select Info > Donate.\n\nYou can support VCV Rack by purchasing VCV plugins.", "VCV Library", "https://library.vcvrack.com/"}, // reviewed + {"You can use Rack in fullscreen mode by selecting “View > Fullscreen“ or pressing F11.\n\nIn fullscreen mode, the menu bar and scroll bars are hidden. This is ideal for screen recording with VCV Recorder.", "Get VCV Recorder", "https://vcvrack.com/Recorder"}, // reviewed + {"You can search over 2400 modules on the VCV Library website.\n\nRegister for a VCV account, log into Rack using the Library menu, and browse the VCV Library to add or purchase modules. Keep all plugins up to date by clicking “Library > Update all”.", "VCV Library", "https://library.vcvrack.com/"}, // reviewed + {"Some developers of free plugins accept donations for their work. Right-click a module panel and select “Info > Donate”.\n\nYou can support VCV Rack by purchasing VCV plugins.", "VCV Library", "https://library.vcvrack.com/"}, // reviewed {"You can learn more about VCV Rack by browsing the official Rack manual.", "VCV Rack manual", "https://vcvrack.com/manual/"}, {"Follow VCV Rack on Twitter for new modules, product announcements, and development news.", "Twitter @vcvrack", "https://twitter.com/vcvrack"}, // reviewed - {"Did you know that patch cables in Rack can carry up to 16 signals? You can use this to easily build polyphonic patches with modules with the \"Polyphonic\" tag. Cables carrying more than 1 signal appear thicker than normal cables. To try out polyphony, add the VCV MIDI-CV module to your patch, right-click its panel, and select your desired number of polyphonic channels.", "Learn more about polyphony in VCV Rack", "https://vcvrack.com/manual/Polyphony"}, // reviewed + {"Did you know that patch cables in Rack can carry up to 16 signals? You can use this to easily build polyphonic patches with modules with the “Polyphonic” tag. Cables carrying more than 1 signal appear thicker than normal cables. To try out polyphony, add the VCV MIDI-CV module to your patch, right-click its panel, and select your desired number of polyphonic channels.", "Learn more about polyphony in VCV Rack", "https://vcvrack.com/manual/Polyphony"}, // reviewed {"Know C++ programming and want to create your own modules for Rack? Developing Rack modules is a great way to learn digital signal processing and quickly test your ideas with an easy-to-learn platform.\n\nDownload the Rack SDK and follow the official tutorial to get started.", "Plugin Development Tutorial", "https://vcvrack.com/manual/PluginDevelopmentTutorial"}, // reviewed - {"Confused about how to use a particular module? Right-click its panel and choose Info > User manual.\n\nYou can also open the module's Info menu to view the module's tags, website, VCV Library entry, and changelog.", "", ""}, // reviewed - {"Did you know that ModularGrid is interconnected with the VCV Library? If a Eurorack version of a Rack module is available, right-click its panel and choose Info > ModularGrid, or click the \"ModularGrid\" link on its VCV Library page.\nOn ModularGrid.net, you can click the \"Available for VCV Rack\" link if a hardware module has a virtual Rack version.", "Example: Grayscale Permutation on ModularGrid", "https://www.modulargrid.net/e/grayscale-permutation-18hp"}, // reviewed + {"Confused about how to use a particular module? Right-click its panel and choose “Info > User manual”.\n\nYou can also open the module's Info menu to view the module's tags, website, VCV Library entry, and changelog.", "", ""}, // reviewed + {"Did you know that ModularGrid is interconnected with the VCV Library? If a Eurorack version of a Rack module is available, right-click its panel and choose “Info > ModularGrid”, or click the “ModularGrid” link on its VCV Library page.\nOn ModularGrid.net, search for the “Available for VCV Rack” link if a hardware module has a virtual Rack version.", "Example: Grayscale Permutation on ModularGrid", "https://www.modulargrid.net/e/grayscale-permutation-18hp"}, // reviewed // {"", "", ""}, }; @@ -106,15 +108,19 @@ struct TipWindow : widget::OpaqueWidget { buttonLayout->spacing = math::Vec(margin, margin); addChild(buttonLayout); - struct ShowButton : ui::Button { - void step() override { - text = settings::showTipsOnLaunch ? "Don't show at startup" : "Show tips at startup"; + struct ShowQuantity : Quantity { + void setValue(float value) override { + settings::showTipsOnLaunch = (value > 0.f); } - void onAction(const event::Action& e) override { - settings::showTipsOnLaunch ^= true; + float getValue() override { + return settings::showTipsOnLaunch ? 1.f : 0.f; } }; - ShowButton* showButton = new ShowButton; + static ShowQuantity showQuantity; + + ui::OptionButton* showButton = new ui::OptionButton; + showButton->text = "Show tips at startup"; + showButton->quantity = &showQuantity; showButton->box.size.x = buttonWidth * 2 + margin; buttonLayout->addChild(showButton); diff --git a/src/ui/OptionButton.cpp b/src/ui/OptionButton.cpp new file mode 100644 index 00000000..d90cc49f --- /dev/null +++ b/src/ui/OptionButton.cpp @@ -0,0 +1,33 @@ +#include + + +namespace rack { +namespace ui { + + +OptionButton::OptionButton() { + box.size.y = BND_WIDGET_HEIGHT; +} + +void OptionButton::draw(const DrawArgs& args) { + BNDwidgetState state = BND_DEFAULT; + if (quantity && !quantity->isMin()) + state = BND_ACTIVE; + + bndOptionButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, text.c_str()); +} + + +void OptionButton::onDragDrop(const event::DragDrop& e) { + if (e.origin == this) { + if (quantity) + quantity->toggle(); + + event::Action eAction; + onAction(eAction); + } +} + + +} // namespace ui +} // namespace rack