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.

111 lines
2.7KB

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