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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. }
  21. void onEnter(event::Enter &e) override {
  22. state = BND_HOVER;
  23. }
  24. void onLeave(event::Leave &e) override {
  25. state = BND_DEFAULT;
  26. }
  27. void onDragStart(event::DragStart &e) override {
  28. state = BND_ACTIVE;
  29. if (quantity)
  30. quantity->setMax();
  31. }
  32. void onDragEnd(event::DragEnd &e) override {
  33. state = BND_HOVER;
  34. if (quantity)
  35. quantity->setMin();
  36. }
  37. void onDragDrop(event::DragDrop &e) override {
  38. if (e.origin == this) {
  39. event::Action eAction;
  40. onAction(eAction);
  41. }
  42. }
  43. };
  44. } // namespace rack