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.

166 lines
4.6KB

  1. //***********************************************************************************************
  2. //Impromptu Modular: Modules for VCV Rack by Marc Boulé
  3. //
  4. //Based on code from Valley Rack Free by Dale Johnson
  5. //See ./LICENSE.txt for all licenses
  6. //***********************************************************************************************
  7. #ifndef IM_WIDGETS_HPP
  8. #define IM_WIDGETS_HPP
  9. #include "rack.hpp"
  10. #include "window.hpp"
  11. using namespace rack;
  12. // Dynamic SVGScrew
  13. // General Dynamic Screw creation
  14. template <class TWidget>
  15. TWidget* createDynamicScrew(Vec pos, int* mode) {
  16. TWidget *dynScrew = Widget::create<TWidget>(pos);
  17. dynScrew->mode = mode;
  18. return dynScrew;
  19. }
  20. struct ScrewCircle : TransparentWidget {
  21. float angle = 0.0f;
  22. float radius = 2.0f;
  23. ScrewCircle(float _angle);
  24. void draw(NVGcontext *vg) override;
  25. };
  26. struct DynamicSVGScrew : FramebufferWidget {
  27. int* mode;
  28. int oldMode;
  29. // for random rotated screw used in primary mode
  30. SVGWidget *sw;
  31. TransformWidget *tw;
  32. ScrewCircle *sc;
  33. // for fixed svg screw used in alternate mode
  34. SVGWidget* swAlt;
  35. DynamicSVGScrew();
  36. void addSVGalt(std::shared_ptr<SVG> svg);
  37. void step() override;
  38. };
  39. // Dynamic SVGPanel
  40. struct PanelBorderWidget_Impromptu : TransparentWidget { // from SVGPanel.cpp
  41. int** expWidth = nullptr;
  42. void draw(NVGcontext *vg) override;
  43. };
  44. struct DynamicSVGPanel : FramebufferWidget { // like SVGPanel (in app.hpp and SVGPanel.cpp) but with dynmically assignable panel
  45. int* mode;
  46. int oldMode;
  47. int* expWidth;
  48. std::vector<std::shared_ptr<SVG>> panels;
  49. SVGWidget* visiblePanel;
  50. PanelBorderWidget_Impromptu* border;
  51. DynamicSVGPanel();
  52. void addPanel(std::shared_ptr<SVG> svg);
  53. void step() override;
  54. };
  55. // ******** Dynamic Ports ********
  56. // General Dynamic Port creation
  57. template <class TDynamicPort>
  58. TDynamicPort* createDynamicPort(Vec pos, Port::PortType type, Module *module, int portId,
  59. int* mode) {
  60. TDynamicPort *dynPort = Port::create<TDynamicPort>(pos, type, module, portId);
  61. dynPort->mode = mode;
  62. return dynPort;
  63. }
  64. // Dynamic SVGPort (see SVGPort in app.hpp and SVGPort.cpp)
  65. struct DynamicSVGPort : SVGPort {
  66. int* mode;
  67. int oldMode;
  68. std::vector<std::shared_ptr<SVG>> frames;
  69. DynamicSVGPort();
  70. void addFrame(std::shared_ptr<SVG> svg);
  71. void step() override;
  72. };
  73. // ******** Dynamic Params ********
  74. // General Dynamic Param creation
  75. template <class TDynamicParam>
  76. TDynamicParam* createDynamicParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue,
  77. int* mode) {
  78. TDynamicParam *dynParam = ParamWidget::create<TDynamicParam>(pos, module, paramId, minValue, maxValue, defaultValue);
  79. dynParam->mode = mode;
  80. return dynParam;
  81. }
  82. // Dynamic SVGSwitch (see SVGSwitch in app.hpp and SVGSwitch.cpp)
  83. struct DynamicSVGSwitch : SVGSwitch {
  84. int* mode;
  85. int oldMode;
  86. std::vector<std::shared_ptr<SVG>> framesAll;
  87. DynamicSVGSwitch();
  88. void addFrameAll(std::shared_ptr<SVG> svg);
  89. void step() override;
  90. };
  91. // Dynamic SVGKnob (see SVGKnob in app.hpp and SVGKnob.cpp)
  92. struct DynamicSVGKnob : SVGKnob {
  93. int* mode;
  94. int oldMode;
  95. std::vector<std::shared_ptr<SVG>> framesAll;
  96. SVGWidget* effect;
  97. DynamicSVGKnob();
  98. void addFrameAll(std::shared_ptr<SVG> svg);
  99. void addEffect(std::shared_ptr<SVG> svg);// do this last
  100. void step() override;
  101. };
  102. // General Dynamic Param creation version two with float* instead of one int*
  103. template <class TDynamicParam>
  104. TDynamicParam* createDynamicParam2(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue,
  105. float* wider, float* paramReadRequest) {
  106. TDynamicParam *dynParam = ParamWidget::create<TDynamicParam>(pos, module, paramId, minValue, maxValue, defaultValue);
  107. dynParam->wider = wider;
  108. dynParam->paramReadRequest = paramReadRequest;
  109. return dynParam;
  110. }
  111. // Dynamic Tactile pad (see Knob in app.hpp and Knob.cpp, and see SVGSlider in SVGSlider.cpp and app.hpp)
  112. struct DynamicIMTactile : ParamWidget, FramebufferWidget {
  113. float* wider;// > 0.5f = true
  114. float* paramReadRequest;
  115. float oldWider;
  116. float dragY;
  117. float dragValue;
  118. bool snap;
  119. static const int padWidth = 45;
  120. static const int padHeight = 200;
  121. static const int padInterSpace = 18;
  122. static const int padWidthWide = padWidth * 2 + padInterSpace;
  123. DynamicIMTactile();
  124. void step() override;
  125. void onDragStart(EventDragStart &e) override;
  126. void onDragMove(EventDragMove &e) override;
  127. void onMouseDown(EventMouseDown &e) override;
  128. //void changeValue(float newVal);
  129. };
  130. #endif