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.

122 lines
3.2KB

  1. #include <app/LedDisplay.hpp>
  2. #include <asset.hpp>
  3. #include <window.hpp>
  4. #include <app.hpp>
  5. namespace rack {
  6. namespace app {
  7. void LedDisplay::draw(const DrawArgs& args) {
  8. nvgBeginPath(args.vg);
  9. nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, 5.0);
  10. nvgFillColor(args.vg, nvgRGB(0x00, 0x00, 0x00));
  11. nvgFill(args.vg);
  12. nvgScissor(args.vg, RECT_ARGS(args.clipBox));
  13. Widget::draw(args);
  14. nvgResetScissor(args.vg);
  15. }
  16. LedDisplaySeparator::LedDisplaySeparator() {
  17. box.size = math::Vec();
  18. }
  19. void LedDisplaySeparator::draw(const DrawArgs& args) {
  20. nvgBeginPath(args.vg);
  21. nvgMoveTo(args.vg, 0, 0);
  22. nvgLineTo(args.vg, box.size.x, box.size.y);
  23. nvgStrokeWidth(args.vg, 1.0);
  24. nvgStrokeColor(args.vg, nvgRGB(0x33, 0x33, 0x33));
  25. nvgStroke(args.vg);
  26. }
  27. LedDisplayChoice::LedDisplayChoice() {
  28. box.size = mm2px(math::Vec(0, 28.0 / 3));
  29. font = APP->window->loadFont(asset::system("res/fonts/ShareTechMono-Regular.ttf"));
  30. color = nvgRGB(0xff, 0xd7, 0x14);
  31. bgColor = nvgRGBAf(0, 0, 0, 0);
  32. textOffset = math::Vec(10, 18);
  33. }
  34. void LedDisplayChoice::draw(const DrawArgs& args) {
  35. nvgScissor(args.vg, RECT_ARGS(args.clipBox));
  36. if (bgColor.a > 0.0) {
  37. nvgBeginPath(args.vg);
  38. nvgRect(args.vg, 0, 0, box.size.x, box.size.y);
  39. nvgFillColor(args.vg, bgColor);
  40. nvgFill(args.vg);
  41. }
  42. if (font->handle >= 0) {
  43. nvgFillColor(args.vg, color);
  44. nvgFontFaceId(args.vg, font->handle);
  45. nvgTextLetterSpacing(args.vg, 0.0);
  46. nvgFontSize(args.vg, 12);
  47. nvgText(args.vg, textOffset.x, textOffset.y, text.c_str(), NULL);
  48. }
  49. nvgResetScissor(args.vg);
  50. }
  51. void LedDisplayChoice::onButton(const event::Button& e) {
  52. OpaqueWidget::onButton(e);
  53. if (e.action == GLFW_PRESS && (e.button == GLFW_MOUSE_BUTTON_LEFT || e.button == GLFW_MOUSE_BUTTON_RIGHT)) {
  54. event::Action eAction;
  55. onAction(eAction);
  56. e.consume(this);
  57. }
  58. }
  59. LedDisplayTextField::LedDisplayTextField() {
  60. font = APP->window->loadFont(asset::system("res/fonts/ShareTechMono-Regular.ttf"));
  61. color = nvgRGB(0xff, 0xd7, 0x14);
  62. textOffset = math::Vec(5, 5);
  63. }
  64. void LedDisplayTextField::draw(const DrawArgs& args) {
  65. nvgScissor(args.vg, RECT_ARGS(args.clipBox));
  66. // Background
  67. nvgBeginPath(args.vg);
  68. nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, 5.0);
  69. nvgFillColor(args.vg, nvgRGB(0x00, 0x00, 0x00));
  70. nvgFill(args.vg);
  71. // Text
  72. if (font->handle >= 0) {
  73. bndSetFont(font->handle);
  74. NVGcolor highlightColor = color;
  75. highlightColor.a = 0.5;
  76. int begin = std::min(cursor, selection);
  77. int end = (this == APP->event->selectedWidget) ? std::max(cursor, selection) : -1;
  78. bndIconLabelCaret(args.vg, textOffset.x, textOffset.y,
  79. box.size.x - 2 * textOffset.x, box.size.y - 2 * textOffset.y,
  80. -1, color, 12, text.c_str(), highlightColor, begin, end);
  81. bndSetFont(APP->window->uiFont->handle);
  82. }
  83. nvgResetScissor(args.vg);
  84. }
  85. int LedDisplayTextField::getTextPosition(math::Vec mousePos) {
  86. bndSetFont(font->handle);
  87. int textPos = bndIconLabelTextPosition(APP->window->vg, textOffset.x, textOffset.y,
  88. box.size.x - 2 * textOffset.x, box.size.y - 2 * textOffset.y,
  89. -1, 12, text.c_str(), mousePos.x, mousePos.y);
  90. bndSetFont(APP->window->uiFont->handle);
  91. return textPos;
  92. }
  93. } // namespace app
  94. } // namespace rack