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.

53 lines
937B

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