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

  1. #include "app.hpp"
  2. #include "asset.hpp"
  3. #include "window.hpp"
  4. namespace rack {
  5. void LedDisplay::draw(NVGcontext *vg) {
  6. nvgBeginPath(vg);
  7. nvgRoundedRect(vg, 0, 0, box.size.x, box.size.y, 5.0);
  8. nvgFillColor(vg, nvgRGB(0x00, 0x00, 0x00));
  9. nvgFill(vg);
  10. Widget::draw(vg);
  11. }
  12. LedDisplaySeparator::LedDisplaySeparator() {
  13. box.size = Vec();
  14. }
  15. void LedDisplaySeparator::draw(NVGcontext *vg) {
  16. nvgBeginPath(vg);
  17. nvgMoveTo(vg, 0, 0);
  18. nvgLineTo(vg, box.size.x, box.size.y);
  19. nvgStrokeWidth(vg, 1.0);
  20. nvgStrokeColor(vg, nvgRGB(0x33, 0x33, 0x33));
  21. nvgStroke(vg);
  22. }
  23. LedDisplayChoice::LedDisplayChoice() {
  24. box.size = mm2px(Vec(0, 28.0 / 3));
  25. font = Font::load(assetGlobal("res/fonts/ShareTechMono-Regular.ttf"));
  26. color = nvgRGB(0xff, 0xd7, 0x14);
  27. textOffset = Vec(10, 18);
  28. }
  29. void LedDisplayChoice::draw(NVGcontext *vg) {
  30. nvgScissor(vg, 0, 0, box.size.x, box.size.y);
  31. if (font->handle >= 0) {
  32. nvgFillColor(vg, color);
  33. nvgFontFaceId(vg, font->handle);
  34. nvgTextLetterSpacing(vg, 0.0);
  35. nvgFontSize(vg, 12);
  36. nvgText(vg, textOffset.x, textOffset.y, text.c_str(), NULL);
  37. }
  38. nvgResetScissor(vg);
  39. }
  40. void LedDisplayChoice::onMouseDown(EventMouseDown &e) {
  41. if (e.button == 0 || e.button == 1) {
  42. EventAction eAction;
  43. onAction(eAction);
  44. e.consumed = true;
  45. e.target = this;
  46. }
  47. }
  48. LedDisplayTextField::LedDisplayTextField() {
  49. font = Font::load(assetGlobal("res/fonts/ShareTechMono-Regular.ttf"));
  50. color = nvgRGB(0xff, 0xd7, 0x14);
  51. textOffset = 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 = min(cursor, selection);
  66. int end = (this == gFocusedWidget) ? 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(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