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.

156 lines
4.5KB

  1. #ifndef WIDGET_MULTISCOPE_HPP
  2. #define WIDGET_MULTISCOPE_HPP
  3. #include "global_pre.hpp"
  4. #include "Features.hpp"
  5. #include "global_ui.hpp"
  6. #if USE_NEW_SCOPE
  7. #include "rack.hpp"
  8. using namespace rack;
  9. #include <string.h>
  10. #include "trowaSoft.hpp"
  11. #include "trowaSoftComponents.hpp"
  12. #include "trowaSoftUtilities.hpp"
  13. #include "dsp/digital.hpp"
  14. #include "Module_multiScope.hpp"
  15. /// TODO: Widget/Module wide invert setting
  16. struct TSScopeModuleResizeHandle : Widget {
  17. float minWidth;
  18. bool right = false;
  19. float dragX;
  20. Rect originalBox;
  21. TS_PadSwitch* displayToggleBtn = NULL;
  22. ColorValueLight* displayToggleLED = NULL;
  23. TS_PadSwitch* colorDisplayToggleBtn = NULL;
  24. ColorValueLight* colorDisplayToggleLED = NULL;
  25. TSScopeModuleResizeHandle(float minWidth) {
  26. box.size = Vec(RACK_GRID_WIDTH * 1, RACK_GRID_HEIGHT);
  27. this->minWidth = minWidth;
  28. return;
  29. }
  30. TSScopeModuleResizeHandle(float minWidth, SVGPanel* bgPanel) : TSScopeModuleResizeHandle(minWidth)
  31. {
  32. addChild(bgPanel);
  33. return;
  34. }
  35. TSScopeModuleResizeHandle(float minWidth, SVGPanel* bgPanel, TS_PadSwitch* displayBtn, ColorValueLight* displayLED) : TSScopeModuleResizeHandle(minWidth, bgPanel)
  36. {
  37. this->displayToggleBtn = displayBtn;
  38. this->displayToggleLED = displayLED;
  39. return;
  40. }
  41. // Set positions of controls relative to our position (even though we don't own these).
  42. void setChildPositions()
  43. {
  44. if (displayToggleBtn)
  45. {
  46. float margin = (this->box.size.x - displayToggleBtn->box.size.x) / 2.0;
  47. if (margin < 0)
  48. margin = 0;
  49. displayToggleBtn->box.pos.x = this->box.pos.x + margin;
  50. }
  51. if (displayToggleLED)
  52. {
  53. float margin = (this->box.size.x - displayToggleLED->box.size.x) / 2.0;
  54. if (margin < 0)
  55. margin = 0;
  56. displayToggleLED->box.pos.x = this->box.pos.x + margin;
  57. }
  58. if (colorDisplayToggleBtn)
  59. {
  60. float margin = (this->box.size.x - colorDisplayToggleBtn->box.size.x) / 2.0;
  61. if (margin < 0)
  62. margin = 0;
  63. colorDisplayToggleBtn->box.pos.x = this->box.pos.x + margin;
  64. }
  65. if (colorDisplayToggleLED)
  66. {
  67. float margin = (this->box.size.x - colorDisplayToggleLED->box.size.x) / 2.0;
  68. if (margin < 0)
  69. margin = 0;
  70. colorDisplayToggleLED->box.pos.x = this->box.pos.x + margin;
  71. }
  72. return;
  73. }
  74. void onMouseDown(EventMouseDown &e) override {
  75. if (e.button == 0) {
  76. e.consumed = true;
  77. e.target = this;
  78. }
  79. }
  80. void onDragStart(EventDragStart &e) override {
  81. dragX = RACK_PLUGIN_UI_RACKWIDGET->lastMousePos.x;
  82. ModuleWidget *m = getAncestorOfType<ModuleWidget>();
  83. originalBox = m->box;
  84. }
  85. void onDragMove(EventDragMove &e) override {
  86. ModuleWidget *m = getAncestorOfType<ModuleWidget>();
  87. float newDragX = RACK_PLUGIN_UI_RACKWIDGET->lastMousePos.x;
  88. float deltaX = newDragX - dragX;
  89. Rect newBox = originalBox;
  90. if (right) {
  91. newBox.size.x += deltaX;
  92. newBox.size.x = fmaxf(newBox.size.x, minWidth);
  93. newBox.size.x = roundf(newBox.size.x / RACK_GRID_WIDTH) * RACK_GRID_WIDTH;
  94. }
  95. else {
  96. newBox.size.x -= deltaX;
  97. newBox.size.x = fmaxf(newBox.size.x, minWidth);
  98. newBox.size.x = roundf(newBox.size.x / RACK_GRID_WIDTH) * RACK_GRID_WIDTH;
  99. newBox.pos.x = originalBox.pos.x + originalBox.size.x - newBox.size.x;
  100. }
  101. RACK_PLUGIN_UI_RACKWIDGET->requestModuleBox(m, newBox);
  102. }
  103. };
  104. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  105. // multiScopeWidget
  106. // Widget for the scope.
  107. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  108. struct multiScopeWidget : ModuleWidget {
  109. Panel* panel;
  110. TSScopeModuleResizeHandle* rightHandle;
  111. TransparentWidget* display[TROWA_SCOPE_NUM_WAVEFORMS];
  112. TS_Panel* screenContainer;
  113. TS_ColorSlider* colorSliders[3];
  114. TSScopeDisplay* scopeInfoDisplay;
  115. // Keep screw references to move them.
  116. ScrewBlack* rhsScrews[2];
  117. int inputAreaWidth;
  118. bool plugLightsEnabled = true;
  119. // Keep references to our ports to disable lights or change the colors.
  120. TS_Port* inputPorts[multiScope::NUM_INPUTS];
  121. // Keep references to our scale knobs [0: x, 1: y]
  122. TS_TinyBlackKnob* scaleKnobs[TROWA_SCOPE_NUM_WAVEFORMS][2];
  123. ColorValueLight* fillColorLEDs[TROWA_SCOPE_NUM_WAVEFORMS];
  124. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  125. // multiScopeWidget()
  126. // Instantiate a multiScope widget. v0.60 must have module as param.
  127. // @scopeModule : (IN) Pointer to the multiScope module.
  128. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  129. multiScopeWidget(multiScope* scopeModule);
  130. void step() override;
  131. json_t *toJson() override;
  132. void fromJson(json_t *rootJ) override;
  133. //Menu *createContextMenu() override;
  134. };
  135. #endif // use new scope
  136. #endif // end if not defined