SPKT
Button.hpp@0:4e245f4bc8ac, 2019-06-07 (annotated)
- Committer:
- phungductung
- Date:
- Fri Jun 07 05:06:42 2019 +0000
- Revision:
- 0:4e245f4bc8ac
spkt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phungductung | 0:4e245f4bc8ac | 1 | //----------------------------------------------------------- |
phungductung | 0:4e245f4bc8ac | 2 | // Button class handling multi-touch -- Header |
phungductung | 0:4e245f4bc8ac | 3 | // Multi-touch: Enabled (default) |
phungductung | 0:4e245f4bc8ac | 4 | // |
phungductung | 0:4e245f4bc8ac | 5 | // 2016/03/29, Copyright (c) 2016 MIKAMI, Naoki |
phungductung | 0:4e245f4bc8ac | 6 | //----------------------------------------------------------- |
phungductung | 0:4e245f4bc8ac | 7 | |
phungductung | 0:4e245f4bc8ac | 8 | #ifndef F746_BUTTON_HPP |
phungductung | 0:4e245f4bc8ac | 9 | #define F746_BUTTON_HPP |
phungductung | 0:4e245f4bc8ac | 10 | |
phungductung | 0:4e245f4bc8ac | 11 | #include "GuiBase.hpp" |
phungductung | 0:4e245f4bc8ac | 12 | |
phungductung | 0:4e245f4bc8ac | 13 | namespace Mikami |
phungductung | 0:4e245f4bc8ac | 14 | { |
phungductung | 0:4e245f4bc8ac | 15 | class Button : public GuiBase |
phungductung | 0:4e245f4bc8ac | 16 | { |
phungductung | 0:4e245f4bc8ac | 17 | public: |
phungductung | 0:4e245f4bc8ac | 18 | // Constructor |
phungductung | 0:4e245f4bc8ac | 19 | Button(uint16_t x, uint16_t y, |
phungductung | 0:4e245f4bc8ac | 20 | uint16_t width, uint16_t height, |
phungductung | 0:4e245f4bc8ac | 21 | const string str = "", sFONT &fonts = Font12, |
phungductung | 0:4e245f4bc8ac | 22 | uint32_t textColor = GuiBase::ENUM_TEXT, |
phungductung | 0:4e245f4bc8ac | 23 | uint32_t backColor = GuiBase::ENUM_BACK, |
phungductung | 0:4e245f4bc8ac | 24 | uint32_t createdColor = GuiBase::ENUM_CREATED, |
phungductung | 0:4e245f4bc8ac | 25 | uint32_t touchedColor = GuiBase::ENUM_TOUCHED, |
phungductung | 0:4e245f4bc8ac | 26 | uint32_t inactiveColor = GuiBase::ENUM_INACTIVE, |
phungductung | 0:4e245f4bc8ac | 27 | uint32_t inactiveTextColor = GuiBase::ENUM_INACTIVE_TEXT) |
phungductung | 0:4e245f4bc8ac | 28 | : GuiBase(x, y, fonts, |
phungductung | 0:4e245f4bc8ac | 29 | textColor, backColor, createdColor, |
phungductung | 0:4e245f4bc8ac | 30 | touchedColor, inactiveColor, |
phungductung | 0:4e245f4bc8ac | 31 | inactiveTextColor), |
phungductung | 0:4e245f4bc8ac | 32 | W_(width), H_(height), STR_(str), active_(true) |
phungductung | 0:4e245f4bc8ac | 33 | { Draw(); } |
phungductung | 0:4e245f4bc8ac | 34 | |
phungductung | 0:4e245f4bc8ac | 35 | // Draw button |
phungductung | 0:4e245f4bc8ac | 36 | void Draw(uint32_t color, uint32_t textColor); |
phungductung | 0:4e245f4bc8ac | 37 | void Draw(uint32_t color) { Draw(color, TEXT_COLOR_); } |
phungductung | 0:4e245f4bc8ac | 38 | void Draw() { Draw(CREATED_COLOR_, TEXT_COLOR_); } |
phungductung | 0:4e245f4bc8ac | 39 | |
phungductung | 0:4e245f4bc8ac | 40 | // Erase button |
phungductung | 0:4e245f4bc8ac | 41 | void Erase() { Draw(BACK_COLOR_, BACK_COLOR_); } |
phungductung | 0:4e245f4bc8ac | 42 | |
phungductung | 0:4e245f4bc8ac | 43 | // Check touch detected and redraw button |
phungductung | 0:4e245f4bc8ac | 44 | bool Touched(); |
phungductung | 0:4e245f4bc8ac | 45 | |
phungductung | 0:4e245f4bc8ac | 46 | bool IsOnButton(); |
phungductung | 0:4e245f4bc8ac | 47 | |
phungductung | 0:4e245f4bc8ac | 48 | void Activate(); |
phungductung | 0:4e245f4bc8ac | 49 | void Inactivate(); |
phungductung | 0:4e245f4bc8ac | 50 | bool IsActive() { return active_; } |
phungductung | 0:4e245f4bc8ac | 51 | |
phungductung | 0:4e245f4bc8ac | 52 | // Set or reset multi-touch |
phungductung | 0:4e245f4bc8ac | 53 | static void SetMultiTouch(bool tf) { multiTouch_ = tf; } |
phungductung | 0:4e245f4bc8ac | 54 | |
phungductung | 0:4e245f4bc8ac | 55 | private: |
phungductung | 0:4e245f4bc8ac | 56 | const uint16_t W_, H_; |
phungductung | 0:4e245f4bc8ac | 57 | const string STR_; |
phungductung | 0:4e245f4bc8ac | 58 | bool active_; |
phungductung | 0:4e245f4bc8ac | 59 | |
phungductung | 0:4e245f4bc8ac | 60 | // disallow copy constructor and assignment operator |
phungductung | 0:4e245f4bc8ac | 61 | Button(const Button&); |
phungductung | 0:4e245f4bc8ac | 62 | Button& operator=(const Button&); |
phungductung | 0:4e245f4bc8ac | 63 | }; |
phungductung | 0:4e245f4bc8ac | 64 | } |
phungductung | 0:4e245f4bc8ac | 65 | #endif // F746_BUTTON_HPP |