You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.0KB

  1. #pragma once
  2. #include "widgets/OpaqueWidget.hpp"
  3. #include "ui/common.hpp"
  4. namespace rack {
  5. struct RadioButton : OpaqueWidget {
  6. BNDwidgetState state = BND_DEFAULT;
  7. Quantity *quantity = NULL;
  8. RadioButton() {
  9. box.size.y = BND_WIDGET_HEIGHT;
  10. }
  11. ~RadioButton() {
  12. if (quantity)
  13. delete quantity;
  14. }
  15. void draw(NVGcontext *vg) override {
  16. std::string label;
  17. if (quantity)
  18. label = quantity->getLabel();
  19. bndRadioButton(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, label.c_str());
  20. }
  21. void onEnter(event::Enter &e) override {
  22. if (state != BND_ACTIVE)
  23. state = BND_HOVER;
  24. }
  25. void onLeave(event::Leave &e) override {
  26. if (state != BND_ACTIVE)
  27. state = BND_DEFAULT;
  28. }
  29. void onDragDrop(event::DragDrop &e) override {
  30. if (e.origin == this) {
  31. if (state == BND_ACTIVE) {
  32. state = BND_HOVER;
  33. if (quantity)
  34. quantity->setMin();
  35. }
  36. else {
  37. state = BND_ACTIVE;
  38. if (quantity)
  39. quantity->setMax();
  40. }
  41. event::Action eAction;
  42. onAction(eAction);
  43. }
  44. }
  45. };
  46. } // namespace rack