@@ -37,95 +37,46 @@ 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
58
- virtual void activate () override {
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
51
+ void activate () override {
59
52
real_style_->activate ();
60
53
}
61
- virtual void deactivate () override {
54
+ void deactivate () override {
62
55
real_style_->deactivate ();
63
56
}
64
- virtual void run (BladeBase* blade) override ;
65
-
66
- bool NoOnOff () override {
67
- return real_style_-> NoOnOff ();
57
+ void run (BladeBase* blade) override {
58
+ if (blade == blade_) {
59
+ real_style_-> run ( this );
60
+ }
68
61
}
69
62
70
- virtual bool Charging () { return real_style_->Charging ();}
63
+ bool NoOnOff () override { return real_style_->NoOnOff (); }
64
+
65
+ bool Charging () override { return real_style_->Charging (); }
71
66
72
67
bool IsHandled (HandledFeature effect) override {
73
68
if (real_style_)
74
69
return real_style_->IsHandled (effect);
75
70
return false ;
76
71
}
77
72
78
- OverDriveColor getColor (int i) override {return real_style_->getColor (i);}
79
-
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.
73
+ OverDriveColor getColor (int i) override { return real_style_->getColor (i); }
106
74
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
- }
75
+ int get_max_arg (int arg) override { return real_style_->get_max_arg (arg); }
124
76
77
+ // BladeBase implementation
125
78
int num_leds () const override {
126
- int result = blade1_num_leds_;
127
- result += blade2_->num_leds ();
128
- return result;
79
+ return blade1_num_leds_ + blade2_->num_leds ();
129
80
}
130
81
void set (int led, Color16 c) override {
131
82
if (led < blade1_num_leds_) {
@@ -163,38 +114,30 @@ class ComboBladeWrapper : public BladeWrapper {
163
114
}
164
115
165
116
void SetStyle (BladeStyle* style) override {
166
- dummy_style_-> setRealStyle ( style) ;
167
- blade_->SetStyle (dummy_style_ );
168
- blade2_->SetStyle (dummy_style_ );
117
+ real_style_ = style;
118
+ blade_->SetStyle (this );
119
+ blade2_->SetStyle (this );
169
120
}
170
121
171
122
BladeStyle* UnSetStyle () override {
172
- if (dummy_style_)
173
- return dummy_style_->UnSetRealStyle ();
174
- else
175
- return nullptr ;
123
+ BladeStyle* result = real_style_;
124
+ real_style_ = nullptr ;
125
+ return result;
176
126
}
177
127
178
128
BladeStyle* current_style () const override {
179
- if (dummy_style_)
180
- return dummy_style_->GetRealStyle ();
181
- else
182
- return nullptr ;
129
+ return real_style_;
183
130
}
184
131
185
132
private:
186
133
int blade1_num_leds_;
187
134
BladeBase* blade2_;
188
- ComboBladeStyleWrapper* dummy_style_ ;
135
+ BladeStyle* real_style_ ;
189
136
};
190
137
191
- void ComboBladeStyleWrapper::run (BladeBase* blade) {
192
- if (blade == primary_blade_) {
193
- real_style_->run (comboBlade_);
194
- }
195
- }
196
138
BladeBase* ComboBlade (BladeBase* blade1, BladeBase* blade2)
197
139
{
198
140
return new ComboBladeWrapper (blade1, blade2);
199
141
}
142
+
200
143
#endif
0 commit comments