Skip to content

Commit d1638f4

Browse files
committed
Additional updates from PR
1 parent 200a0b4 commit d1638f4

File tree

1 file changed

+29
-84
lines changed

1 file changed

+29
-84
lines changed

blades/combo_blade.h

+29-84
Original file line numberDiff line numberDiff line change
@@ -37,95 +37,48 @@ is the only thing that counts as an entry in the blade array.
3737
3838
*/
3939

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 {
5641
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
5851
virtual void activate() override {
5952
real_style_->activate();
6053
}
6154
virtual void deactivate() override {
6255
real_style_->deactivate();
6356
}
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+
}
6562

6663
bool NoOnOff() override {
6764
return real_style_->NoOnOff();
6865
}
6966

70-
virtual bool Charging() { return real_style_->Charging();}
67+
virtual bool Charging() { return real_style_->Charging(); }
7168

7269
bool IsHandled(HandledFeature effect) override {
7370
if (real_style_)
7471
return real_style_->IsHandled(effect);
7572
return false;
7673
}
7774

78-
OverDriveColor getColor(int i) override {return real_style_->getColor(i);}
75+
OverDriveColor getColor(int i) override { return real_style_->getColor(i); }
7976

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); }
12478

79+
// BladeBase implementation
12580
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();
12982
}
13083
void set(int led, Color16 c) override {
13184
if (led < blade1_num_leds_) {
@@ -163,38 +116,30 @@ class ComboBladeWrapper : public BladeWrapper {
163116
}
164117

165118
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);
169122
}
170123

171124
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;
176128
}
177129

178130
BladeStyle* current_style() const override {
179-
if (dummy_style_)
180-
return dummy_style_->GetRealStyle();
181-
else
182-
return nullptr;
131+
return real_style_;
183132
}
184133

185134
private:
186135
int blade1_num_leds_;
187136
BladeBase* blade2_;
188-
ComboBladeStyleWrapper* dummy_style_;
137+
BladeStyle* real_style_;
189138
};
190139

191-
void ComboBladeStyleWrapper::run(BladeBase* blade) {
192-
if (blade == primary_blade_) {
193-
real_style_->run(comboBlade_);
194-
}
195-
}
196140
BladeBase* ComboBlade(BladeBase* blade1, BladeBase* blade2)
197141
{
198142
return new ComboBladeWrapper(blade1, blade2);
199143
}
144+
200145
#endif

0 commit comments

Comments
 (0)