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.

127 lines
3.5KB

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