@@ -10,26 +10,36 @@ class LEDSwitch : public ISwitchControlBase
1010 * @param bounds The control's bounds
1111 * @param bitmap The bitmap resource for the control
1212 * @param paramIdx The parameter index to link this control to */
13- LEDSwitch (const IRECT& bounds, float hitboxScaleFactor, const std::initializer_list<ISVG>& svgs, int paramIdx = kNoParameter )
14- : ISwitchControlBase(bounds, paramIdx, nullptr , static_cast <int >(svgs.size()))
15- , mSVGs (svgs)
13+ LEDSwitch (const IRECT& bounds, float hitboxScaleFactor, const ISVG& svgOff, const ISVG& svgOn1, const ISVG& svgOn2, int paramIdx = kNoParameter )
14+ : ISwitchControlBase(bounds, paramIdx, nullptr , 3 )
15+ , mSVGOff (svgOff)
16+ , mSVGOn1 (svgOn1)
17+ , mSVGOn2 (svgOn2)
1618 {
1719 hitboxScale = hitboxScaleFactor;
18- // AttachIControl(this);
1920 }
2021
2122 virtual ~LEDSwitch () {}
22- void Draw (IGraphics& g) override { g.DrawSVG (mSVGs [ GetSelectedIdx ()] , mRECT , &mBlend ); }
23+ void Draw (IGraphics& g) override { g.DrawSVG (GetValue () >= 1 . ? (tank2 ? mSVGOn2 : mSVGOn1 ) : mSVGOff , mRECT , &mBlend ); }
2324 void OnMouseDown (float x, float y, const IMouseMod& mod) {
24- if (mSVGs .size () > 1 )
25- SetValue (GetValue () + 1.0 / static_cast <double >(mSVGs .size () - 1 ));
26- else
27- SetValue (GetValue () + 1.0 );
28-
29- if (GetValue () > 1.001 )
25+ // if (child) { // If this is a child, don't allow it to be toggled when the parent forces it on
26+ // if (linkedParent->GetValue() == 1.) {
27+ // return;
28+ // }
29+ // }
30+ SetValue (GetValue () + 1 .);
31+ if (GetValue () > 1 .) {
3032 SetValue (0 .);
31-
33+ }
34+ preferedState = GetValue () >= 1 .; // Set the state to return to when the parent turns back off
3235 SetDirty ();
36+ if (child && !preferedState) {
37+ linkedParent->SetValue (0 .);
38+ linkedParent->SetDirty ();
39+ }
40+ if (parent) {
41+ linkedChild->Update ();
42+ }
3343 };
3444
3545 bool IsHit (float x, float y) const override {
@@ -38,10 +48,47 @@ class LEDSwitch : public ISwitchControlBase
3848 return hitbox.Contains (x, y);
3949 }
4050
51+ void SelectTank (bool isTank2) {
52+ tank2 = isTank2;
53+ SetDirty ();
54+ }
55+
4156 float hitboxScale = 1 .0f ;
4257
58+ void SetChild (LEDSwitch* child) {
59+ linkedChild = child;
60+ parent = true ;
61+ child->SetParent (this );
62+ }
63+
64+ void Update () {
65+ if (child) {
66+ if (linkedParent->GetValue () >= 1 ) {
67+ SetValue (1 .);
68+ }
69+ else {
70+ SetValue (preferedState);
71+ }
72+ SetDirty ();
73+ }
74+ }
75+
4376protected:
44- std::vector<ISVG> mSVGs ;
77+ ISVG mSVGOff ;
78+ ISVG mSVGOn1 ;
79+ ISVG mSVGOn2 ;
80+ bool tank2 = false ;
81+ bool parent = false ;
82+ bool child = false ;
83+ LEDSwitch* linkedChild;
84+ LEDSwitch* linkedParent;
85+ bool preferedState = false ;
86+
87+ private:
88+ void SetParent (LEDSwitch* parent) {
89+ linkedParent = parent;
90+ child = true ;
91+ }
4592};
4693END_IGRAPHICS_NAMESPACE
4794END_IPLUG_NAMESPACE
0 commit comments