Skip to content

Commit c30ae69

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

File tree

1 file changed

+32
-89
lines changed

1 file changed

+32
-89
lines changed

blades/combo_blade.h

+32-89
Original file line numberDiff line numberDiff line change
@@ -37,95 +37,46 @@ 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
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 {
5952
real_style_->activate();
6053
}
61-
virtual void deactivate() override {
54+
void deactivate() override {
6255
real_style_->deactivate();
6356
}
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+
}
6861
}
6962

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(); }
7166

7267
bool IsHandled(HandledFeature effect) override {
7368
if (real_style_)
7469
return real_style_->IsHandled(effect);
7570
return false;
7671
}
7772

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

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

77+
// BladeBase implementation
12578
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();
12980
}
13081
void set(int led, Color16 c) override {
13182
if (led < blade1_num_leds_) {
@@ -163,38 +114,30 @@ class ComboBladeWrapper : public BladeWrapper {
163114
}
164115

165116
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);
169120
}
170121

171122
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;
176126
}
177127

178128
BladeStyle* current_style() const override {
179-
if (dummy_style_)
180-
return dummy_style_->GetRealStyle();
181-
else
182-
return nullptr;
129+
return real_style_;
183130
}
184131

185132
private:
186133
int blade1_num_leds_;
187134
BladeBase* blade2_;
188-
ComboBladeStyleWrapper* dummy_style_;
135+
BladeStyle* real_style_;
189136
};
190137

191-
void ComboBladeStyleWrapper::run(BladeBase* blade) {
192-
if (blade == primary_blade_) {
193-
real_style_->run(comboBlade_);
194-
}
195-
}
196138
BladeBase* ComboBlade(BladeBase* blade1, BladeBase* blade2)
197139
{
198140
return new ComboBladeWrapper(blade1, blade2);
199141
}
142+
200143
#endif

0 commit comments

Comments
 (0)