diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-10-13 17:54:17 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-10-13 17:54:17 +0200 |
commit | b84e5f74e5513e4cd14fe62b03777be8ee9c2537 (patch) | |
tree | 9b746875e370b40267bb34a0e09397fbff2036f1 | |
parent | 2fa698c43039872015f1ac61b04ca8f228d5f394 (diff) |
Refactored LED class.
-rw-r--r-- | plugingui/led.cc | 117 | ||||
-rw-r--r-- | plugingui/led.h | 30 |
2 files changed, 68 insertions, 79 deletions
diff --git a/plugingui/led.cc b/plugingui/led.cc index d26a0de..f8c001c 100644 --- a/plugingui/led.cc +++ b/plugingui/led.cc @@ -28,79 +28,70 @@ #include "painter.h" -GUI::LED::LED(Widget *parent) - : GUI::Widget(parent) +namespace GUI { + +LED::LED(Widget *parent) + : Widget(parent) + , state(Off) { - state = off; } -void GUI::LED::setState(GUI::LED::state_t state) +void LED::setState(state_t state) { - if(this->state != state) { - this->state = state; - repaintEvent(NULL); - } + if(this->state != state) + { + this->state = state; + repaintEvent(nullptr); + } } -void GUI::LED::repaintEvent(GUI::RepaintEvent *e) +void LED::repaintEvent(RepaintEvent *e) { - size_t h = height() - 1; - size_t w = width() - 1; + size_t h = height() - 1; + size_t w = width() - 1; - Painter p(this); - float alpha = 0.9; - switch(state) { - case red: - p.setColour(Colour(1, 0, 0,alpha)); - break; - case green: - p.setColour(Colour(0, 1, 0, alpha)); - break; - case blue: - p.setColour(Colour(0, 0, 1, alpha)); - break; - case off: - p.setColour(Colour(0.2, 0.2, 0.2, alpha)); - break; - } + Painter p(this); + float alpha = 0.9; + switch(state) { + case Red: + p.setColour(Colour(1, 0, 0,alpha)); + break; + case Green: + p.setColour(Colour(0, 1, 0, alpha)); + break; + case Blue: + p.setColour(Colour(0, 0, 1, alpha)); + break; + case Off: + p.setColour(Colour(0.2, 0.2, 0.2, alpha)); + break; + } - size_t size = w / 2; - if(h / 2 < size) size = h / 2; - p.drawFilledCircle(w/2, h/2, size); + size_t size = w / 2; + if((h / 2) < size) + { + size = h / 2; + } + p.drawFilledCircle(w / 2, h / 2, size); - switch(state) { - case red: - p.setColour(Colour(0.4, 0, 0,alpha)); - break; - case green: - p.setColour(Colour(0, 0.4, 0, alpha)); - break; - case blue: - p.setColour(Colour(0, 0, 0.4, alpha)); - break; - case off: - p.setColour(Colour(0.1, 0.1, 0.1, alpha)); - break; - } - p.drawCircle(w/2, h/2, size); + switch(state) { + case Red: + p.setColour(Colour(0.4, 0, 0, alpha)); + break; + case Green: + p.setColour(Colour(0, 0.4, 0, alpha)); + break; + case Blue: + p.setColour(Colour(0, 0, 0.4, alpha)); + break; + case Off: + p.setColour(Colour(0.1, 0.1, 0.1, alpha)); + break; + } + p.drawCircle(w / 2, h / 2, size); - p.setColour(Colour(1,alpha)); - p.drawFilledCircle(w/3, h/3, size / 6); + p.setColour(Colour(1, alpha)); + p.drawFilledCircle(w / 3, h / 3, size / 6); } -#ifdef TEST_LED -//Additional dependency files -//deps: -//Required cflags (autoconf vars may be used) -//cflags: -//Required link options (autoconf vars may be used) -//libs: -#include "test.h" - -TEST_BEGIN; - -// TODO: Put some testcode here (see test.h for usable macros). - -TEST_END; - -#endif/*TEST_LED*/ +} // GUI:: diff --git a/plugingui/led.h b/plugingui/led.h index 7bbd59a..977dbb3 100644 --- a/plugingui/led.h +++ b/plugingui/led.h @@ -24,8 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef __DRUMGIZMO_LED_H__ -#define __DRUMGIZMO_LED_H__ +#pragma once #include "widget.h" @@ -33,24 +32,23 @@ namespace GUI { class LED : public Widget { public: - typedef enum { - red, - green, - blue, - off - } state_t; + typedef enum { + Red, + Green, + Blue, + Off + } state_t; - LED(Widget *parent); + LED(Widget *parent); - void setState(state_t state); + void setState(state_t state); - //protected: - void repaintEvent(RepaintEvent *e); +protected: + // From Widget: + void repaintEvent(RepaintEvent *e) override; private: - state_t state; + state_t state; }; -}; - -#endif/*__DRUMGIZMO_LED_H__*/ +} // GUI:: |