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.

110 lines
2.6KB

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