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.

71 lines
1.2KB

  1. #include <ui/MenuOverlay.hpp>
  2. namespace rack {
  3. namespace ui {
  4. MenuOverlay::MenuOverlay() {
  5. bgColor = nvgRGBA(0, 0, 0, 0);
  6. }
  7. void MenuOverlay::draw(const DrawArgs& args) {
  8. if (bgColor.a > 0.f) {
  9. nvgBeginPath(args.vg);
  10. nvgRect(args.vg, 0, 0, VEC_ARGS(box.size));
  11. nvgFillColor(args.vg, bgColor);
  12. nvgFill(args.vg);
  13. }
  14. OpaqueWidget::draw(args);
  15. }
  16. void MenuOverlay::step() {
  17. // Adopt parent's size
  18. box = parent->box.zeroPos();
  19. Widget::step();
  20. }
  21. void MenuOverlay::onButton(const ButtonEvent& e) {
  22. OpaqueWidget::onButton(e);
  23. if (e.isConsumed() && e.getTarget() != this)
  24. return;
  25. if (e.action == GLFW_PRESS) {
  26. ActionEvent eAction;
  27. onAction(eAction);
  28. }
  29. // Consume all buttons.
  30. e.consume(this);
  31. }
  32. void MenuOverlay::onHoverKey(const HoverKeyEvent& e) {
  33. OpaqueWidget::onHoverKey(e);
  34. if (e.isConsumed())
  35. return;
  36. if (e.action == GLFW_PRESS && e.key == GLFW_KEY_ESCAPE) {
  37. ActionEvent eAction;
  38. onAction(eAction);
  39. }
  40. // Consume all keys.
  41. // Unfortunately this prevents MIDI computer keyboard from playing while a menu is open, but that might be a good thing for safety.
  42. e.consume(this);
  43. }
  44. void MenuOverlay::onAction(const ActionEvent& e) {
  45. requestDelete();
  46. }
  47. } // namespace ui
  48. } // namespace rack