@@ -37,95 +37,48 @@ is the only thing that counts as an entry in the blade array.
37
37
38
38
*/
39
39
40
- class ComboBladeWrapper ;
41
-
42
-
43
- /*
44
- This class is used by ComboBladeWrapper to allow intercepting the style run()
45
- calls sent from the blades inside the ComboBladeWrapper.
46
-
47
- The style of the wrapped blades will be set to an instance of this class, which
48
- will then call the real style with our ComboBladeWrapper instance as the
49
- active blade.
50
-
51
- Since the same style is being executed for both blades we only actually run
52
- the style calls sent by the primary blade.
53
-
54
- */
55
- class ComboBladeStyleWrapper : public BladeStyle {
40
+ class ComboBladeWrapper : public BladeWrapper , BladeStyle {
56
41
public:
57
- // Bladestyle implementation
42
+ ComboBladeWrapper (BladeBase* blade1, BladeBase* blade2):
43
+ blade1_num_leds_ (blade1->num_leds ()),
44
+ blade2_(blade2),
45
+ real_style_(nullptr )
46
+ {
47
+ blade_ = blade1;
48
+ }
49
+
50
+ // BladeStyle implementation
58
51
virtual void activate () override {
59
52
real_style_->activate ();
60
53
}
61
54
virtual void deactivate () override {
62
55
real_style_->deactivate ();
63
56
}
64
- virtual void run (BladeBase* blade) override ;
57
+ virtual void run (BladeBase* blade) override {
58
+ if (blade == blade_) {
59
+ real_style_->run (this );
60
+ }
61
+ }
65
62
66
63
bool NoOnOff () override {
67
64
return real_style_->NoOnOff ();
68
65
}
69
66
70
- virtual bool Charging () { return real_style_->Charging ();}
67
+ virtual bool Charging () { return real_style_->Charging (); }
71
68
72
69
bool IsHandled (HandledFeature effect) override {
73
70
if (real_style_)
74
71
return real_style_->IsHandled (effect);
75
72
return false ;
76
73
}
77
74
78
- OverDriveColor getColor (int i) override {return real_style_->getColor (i);}
75
+ OverDriveColor getColor (int i) override { return real_style_->getColor (i); }
79
76
80
- int get_max_arg (int arg) override { return real_style_->get_max_arg (arg);}
81
-
82
- void setRealStyle (BladeStyle* style){real_style_ = style;}
83
-
84
- BladeStyle* GetRealStyle (){return real_style_;}
85
-
86
- BladeStyle* UnSetRealStyle (){
87
- BladeStyle* result = real_style_;
88
- real_style_ = nullptr ;
89
- return result;
90
- }
91
-
92
- ComboBladeStyleWrapper (ComboBladeWrapper* comboBlade, BladeBase* primary_blade) :
93
- comboBlade_ (comboBlade),
94
- primary_blade_ (primary_blade),
95
- real_style_ (nullptr ){
96
- }
97
- protected:
98
- ComboBladeWrapper* comboBlade_;
99
- BladeBase* primary_blade_;
100
- BladeStyle* real_style_;
101
- };
102
-
103
- /*
104
- This class is used by ComboBladeWrapper to allow intercepting the style run()
105
- calls sent from the blades inside the ComboBladeWrapper.
106
-
107
- This class acts as our entry in the blade array. When activated, it will
108
- activate the loops of the two assigned blades, pointing them at an instance of
109
- ComboBladeStyleWrapper. This will then be used to intercept the style run()
110
- calls of the indivdual blades and instead run the style against the
111
- ComboBladeWrapper. The ComboBladeWrapper will then send the led set calls
112
- to the appropriate blade based on the led number.
113
-
114
- */
115
- class ComboBladeWrapper : public BladeWrapper {
116
- public:
117
- ComboBladeWrapper (BladeBase* blade1, BladeBase* blade2):
118
- blade1_num_leds_ (blade1->num_leds ()),
119
- blade2_(blade2)
120
- {
121
- blade_ = blade1;
122
- dummy_style_ = new ComboBladeStyleWrapper (this , blade1);
123
- }
77
+ int get_max_arg (int arg) override { return real_style_->get_max_arg (arg); }
124
78
79
+ // BladeBase implementation
125
80
int num_leds () const override {
126
- int result = blade1_num_leds_;
127
- result += blade2_->num_leds ();
128
- return result;
81
+ return blade1_num_leds_ + blade2_->num_leds ();
129
82
}
130
83
void set (int led, Color16 c) override {
131
84
if (led < blade1_num_leds_) {
@@ -163,38 +116,30 @@ class ComboBladeWrapper : public BladeWrapper {
163
116
}
164
117
165
118
void SetStyle (BladeStyle* style) override {
166
- dummy_style_-> setRealStyle ( style) ;
167
- blade_->SetStyle (dummy_style_ );
168
- blade2_->SetStyle (dummy_style_ );
119
+ real_style_ = style;
120
+ blade_->SetStyle (this );
121
+ blade2_->SetStyle (this );
169
122
}
170
123
171
124
BladeStyle* UnSetStyle () override {
172
- if (dummy_style_)
173
- return dummy_style_->UnSetRealStyle ();
174
- else
175
- return nullptr ;
125
+ BladeStyle* result = real_style_;
126
+ real_style_ = nullptr ;
127
+ return result;
176
128
}
177
129
178
130
BladeStyle* current_style () const override {
179
- if (dummy_style_)
180
- return dummy_style_->GetRealStyle ();
181
- else
182
- return nullptr ;
131
+ return real_style_;
183
132
}
184
133
185
134
private:
186
135
int blade1_num_leds_;
187
136
BladeBase* blade2_;
188
- ComboBladeStyleWrapper* dummy_style_ ;
137
+ BladeStyle* real_style_ ;
189
138
};
190
139
191
- void ComboBladeStyleWrapper::run (BladeBase* blade) {
192
- if (blade == primary_blade_) {
193
- real_style_->run (comboBlade_);
194
- }
195
- }
196
140
BladeBase* ComboBlade (BladeBase* blade1, BladeBase* blade2)
197
141
{
198
142
return new ComboBladeWrapper (blade1, blade2);
199
143
}
144
+
200
145
#endif
0 commit comments