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.

56 lines
987B

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