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.

Button.hpp 1.1KB

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