SPKT
SeekBar.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 | // SeekBar class -- Header |
phungductung | 0:4e245f4bc8ac | 3 | // |
phungductung | 0:4e245f4bc8ac | 4 | // 2017/01/25, Copyright (c) 2017 MIKAMI, Naoki |
phungductung | 0:4e245f4bc8ac | 5 | //----------------------------------------------------------- |
phungductung | 0:4e245f4bc8ac | 6 | |
phungductung | 0:4e245f4bc8ac | 7 | #ifndef F746_SEEKBAR_HPP |
phungductung | 0:4e245f4bc8ac | 8 | #define F746_SEEKBAR_HPP |
phungductung | 0:4e245f4bc8ac | 9 | |
phungductung | 0:4e245f4bc8ac | 10 | #include "GuiBase.hpp" |
phungductung | 0:4e245f4bc8ac | 11 | #include "Label.hpp" |
phungductung | 0:4e245f4bc8ac | 12 | |
phungductung | 0:4e245f4bc8ac | 13 | namespace Mikami |
phungductung | 0:4e245f4bc8ac | 14 | { |
phungductung | 0:4e245f4bc8ac | 15 | class SeekBar : public GuiBase |
phungductung | 0:4e245f4bc8ac | 16 | { |
phungductung | 0:4e245f4bc8ac | 17 | public: |
phungductung | 0:4e245f4bc8ac | 18 | enum Orientation { Holizontal, Vertical }; |
phungductung | 0:4e245f4bc8ac | 19 | |
phungductung | 0:4e245f4bc8ac | 20 | struct Point |
phungductung | 0:4e245f4bc8ac | 21 | { |
phungductung | 0:4e245f4bc8ac | 22 | uint16_t x, y; |
phungductung | 0:4e245f4bc8ac | 23 | Point(uint16_t x0 = 0, uint16_t y0 = 0) : x(x0), y(y0) {} |
phungductung | 0:4e245f4bc8ac | 24 | }; |
phungductung | 0:4e245f4bc8ac | 25 | |
phungductung | 0:4e245f4bc8ac | 26 | // Constructor |
phungductung | 0:4e245f4bc8ac | 27 | SeekBar(uint16_t x, uint16_t y, uint16_t length, |
phungductung | 0:4e245f4bc8ac | 28 | float min, float max, float initialValue, |
phungductung | 0:4e245f4bc8ac | 29 | Orientation hv = Holizontal, |
phungductung | 0:4e245f4bc8ac | 30 | uint32_t thumbColor = 0xFFB0B0FF, |
phungductung | 0:4e245f4bc8ac | 31 | uint16_t thumbSize = 30, uint16_t width = 4, |
phungductung | 0:4e245f4bc8ac | 32 | uint32_t colorL = LCD_COLOR_LIGHTGRAY, |
phungductung | 0:4e245f4bc8ac | 33 | uint32_t colorH = 0xFFB0B0B0, |
phungductung | 0:4e245f4bc8ac | 34 | uint32_t backColor = GuiBase::ENUM_BACK) |
phungductung | 0:4e245f4bc8ac | 35 | : GuiBase(x, y, Font12, 0, backColor, thumbColor), |
phungductung | 0:4e245f4bc8ac | 36 | L_(length), W_(width), |
phungductung | 0:4e245f4bc8ac | 37 | SIZE_(thumbSize), COLOR_L_(colorL), COLOR_H_(colorH), |
phungductung | 0:4e245f4bc8ac | 38 | MIN_(min), MAX_(max), ORIENT_(hv), v_(initialValue), |
phungductung | 0:4e245f4bc8ac | 39 | labelOn_(false), slided_(false), active_(true) |
phungductung | 0:4e245f4bc8ac | 40 | { Draw(initialValue); } |
phungductung | 0:4e245f4bc8ac | 41 | |
phungductung | 0:4e245f4bc8ac | 42 | // Constructor with scale value (only horizontal) |
phungductung | 0:4e245f4bc8ac | 43 | SeekBar(uint16_t x, uint16_t y, uint16_t length, |
phungductung | 0:4e245f4bc8ac | 44 | float min, float max, float initialValue, |
phungductung | 0:4e245f4bc8ac | 45 | string left, string center, string right, |
phungductung | 0:4e245f4bc8ac | 46 | uint32_t thumbColor = 0xFFB0B0FF, |
phungductung | 0:4e245f4bc8ac | 47 | uint16_t thumbSize = 30, uint16_t width = 4, |
phungductung | 0:4e245f4bc8ac | 48 | uint32_t colorL = LCD_COLOR_LIGHTGRAY, |
phungductung | 0:4e245f4bc8ac | 49 | uint32_t colorH = 0xFFB0B0B0, |
phungductung | 0:4e245f4bc8ac | 50 | uint32_t backColor = GuiBase::ENUM_BACK); |
phungductung | 0:4e245f4bc8ac | 51 | |
phungductung | 0:4e245f4bc8ac | 52 | virtual ~SeekBar() |
phungductung | 0:4e245f4bc8ac | 53 | { for (int n=0; n<3; n++) delete labelLCR_[n]; } |
phungductung | 0:4e245f4bc8ac | 54 | |
phungductung | 0:4e245f4bc8ac | 55 | bool Slide(); |
phungductung | 0:4e245f4bc8ac | 56 | float GetValue() { return v_; } |
phungductung | 0:4e245f4bc8ac | 57 | int GetIntValue() { return Round(v_); } |
phungductung | 0:4e245f4bc8ac | 58 | |
phungductung | 0:4e245f4bc8ac | 59 | void Activate(); |
phungductung | 0:4e245f4bc8ac | 60 | void Inactivate(); |
phungductung | 0:4e245f4bc8ac | 61 | bool IsActive() { return active_; } |
phungductung | 0:4e245f4bc8ac | 62 | |
phungductung | 0:4e245f4bc8ac | 63 | bool IsOnThumb(uint16_t &x, uint16_t &y); |
phungductung | 0:4e245f4bc8ac | 64 | void Draw(float value, bool fill = false); |
phungductung | 0:4e245f4bc8ac | 65 | void Redraw(bool fill = false); |
phungductung | 0:4e245f4bc8ac | 66 | float ToValue(Point pt); |
phungductung | 0:4e245f4bc8ac | 67 | |
phungductung | 0:4e245f4bc8ac | 68 | void SetValue(float v) { v_ = v; } |
phungductung | 0:4e245f4bc8ac | 69 | void SetSlided(bool tf) { slided_ = tf; } |
phungductung | 0:4e245f4bc8ac | 70 | bool GetSlided() { return slided_; } |
phungductung | 0:4e245f4bc8ac | 71 | |
phungductung | 0:4e245f4bc8ac | 72 | private: |
phungductung | 0:4e245f4bc8ac | 73 | const uint16_t L_, W_; |
phungductung | 0:4e245f4bc8ac | 74 | const uint16_t SIZE_; // Size of thumb |
phungductung | 0:4e245f4bc8ac | 75 | const uint32_t COLOR_L_, COLOR_H_; |
phungductung | 0:4e245f4bc8ac | 76 | const float MIN_, MAX_; |
phungductung | 0:4e245f4bc8ac | 77 | const Orientation ORIENT_; |
phungductung | 0:4e245f4bc8ac | 78 | |
phungductung | 0:4e245f4bc8ac | 79 | Label *labelLCR_[3]; |
phungductung | 0:4e245f4bc8ac | 80 | float v_; // value of seekbar |
phungductung | 0:4e245f4bc8ac | 81 | bool labelOn_; |
phungductung | 0:4e245f4bc8ac | 82 | bool slided_; |
phungductung | 0:4e245f4bc8ac | 83 | bool active_; |
phungductung | 0:4e245f4bc8ac | 84 | |
phungductung | 0:4e245f4bc8ac | 85 | int Round(float x) { return x + 0.5f - (x < 0); } |
phungductung | 0:4e245f4bc8ac | 86 | Point ToPoint(float value); |
phungductung | 0:4e245f4bc8ac | 87 | float Saturate(float value); |
phungductung | 0:4e245f4bc8ac | 88 | |
phungductung | 0:4e245f4bc8ac | 89 | // disallow copy constructor and assignment operator |
phungductung | 0:4e245f4bc8ac | 90 | SeekBar(const SeekBar&); |
phungductung | 0:4e245f4bc8ac | 91 | SeekBar& operator=(const SeekBar&); |
phungductung | 0:4e245f4bc8ac | 92 | }; |
phungductung | 0:4e245f4bc8ac | 93 | } |
phungductung | 0:4e245f4bc8ac | 94 | #endif // F746_SEEKBAR_HPP |
phungductung | 0:4e245f4bc8ac | 95 |