New IHM
Dependencies: Array_Matrix TS_DISCO_F746NG LCD_DISCO_F746NG BSP_DISCO_F746NG
SeekBar.hpp@13:9ae055fac9cf, 2016-05-30 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon May 30 14:34:44 2016 +0000
- Revision:
- 13:9ae055fac9cf
- Parent:
- 12:687ec6183385
- Child:
- 15:0511a08a3c09
14
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:a2686ef737c2 | 1 | //----------------------------------------------------------- |
MikamiUitOpen | 0:a2686ef737c2 | 2 | // SeekBar class -- Header |
MikamiUitOpen | 0:a2686ef737c2 | 3 | // |
MikamiUitOpen | 13:9ae055fac9cf | 4 | // 2016/05/30, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:a2686ef737c2 | 5 | //----------------------------------------------------------- |
MikamiUitOpen | 0:a2686ef737c2 | 6 | |
MikamiUitOpen | 0:a2686ef737c2 | 7 | #ifndef F746_SEEKBAR_HPP |
MikamiUitOpen | 0:a2686ef737c2 | 8 | #define F746_SEEKBAR_HPP |
MikamiUitOpen | 0:a2686ef737c2 | 9 | |
MikamiUitOpen | 0:a2686ef737c2 | 10 | #include "GuiBase.hpp" |
MikamiUitOpen | 6:b8f197b0012c | 11 | #include "Label.hpp" |
MikamiUitOpen | 0:a2686ef737c2 | 12 | |
MikamiUitOpen | 0:a2686ef737c2 | 13 | namespace Mikami |
MikamiUitOpen | 0:a2686ef737c2 | 14 | { |
MikamiUitOpen | 0:a2686ef737c2 | 15 | class SeekBar : public GuiBase |
MikamiUitOpen | 0:a2686ef737c2 | 16 | { |
MikamiUitOpen | 0:a2686ef737c2 | 17 | public: |
MikamiUitOpen | 0:a2686ef737c2 | 18 | enum Orientation { Holizontal, Vertical }; |
MikamiUitOpen | 0:a2686ef737c2 | 19 | |
MikamiUitOpen | 9:c379410bda15 | 20 | struct Point |
MikamiUitOpen | 9:c379410bda15 | 21 | { |
MikamiUitOpen | 9:c379410bda15 | 22 | uint16_t x, y; |
MikamiUitOpen | 9:c379410bda15 | 23 | Point(uint16_t x0 = 0, uint16_t y0 = 0) : x(x0), y(y0) {} |
MikamiUitOpen | 9:c379410bda15 | 24 | }; |
MikamiUitOpen | 9:c379410bda15 | 25 | |
MikamiUitOpen | 0:a2686ef737c2 | 26 | // Constructor |
MikamiUitOpen | 0:a2686ef737c2 | 27 | SeekBar(uint16_t x, uint16_t y, uint16_t length, |
MikamiUitOpen | 6:b8f197b0012c | 28 | float min, float max, float initialValue, |
MikamiUitOpen | 0:a2686ef737c2 | 29 | Orientation hv = Holizontal, |
MikamiUitOpen | 12:687ec6183385 | 30 | uint32_t thumbColor = 0xFFB0B0FF, |
MikamiUitOpen | 0:a2686ef737c2 | 31 | uint16_t thumbSize = 30, uint16_t width = 4, |
MikamiUitOpen | 0:a2686ef737c2 | 32 | uint32_t colorL = LCD_COLOR_LIGHTGRAY, |
MikamiUitOpen | 0:a2686ef737c2 | 33 | uint32_t colorH = 0xFFB0B0B0, |
MikamiUitOpen | 0:a2686ef737c2 | 34 | uint32_t backColor = GuiBase::ENUM_BACK) |
MikamiUitOpen | 0:a2686ef737c2 | 35 | : GuiBase(x, y, Font12, 0, backColor, thumbColor), |
MikamiUitOpen | 0:a2686ef737c2 | 36 | L_(length), W_(width), |
MikamiUitOpen | 0:a2686ef737c2 | 37 | SIZE_(thumbSize), COLOR_L_(colorL), COLOR_H_(colorH), |
MikamiUitOpen | 12:687ec6183385 | 38 | MIN_(min), MAX_(max), ORIENT_(hv), v_(initialValue), |
MikamiUitOpen | 12:687ec6183385 | 39 | labelOn_(false), slided_(false), active_(true) |
MikamiUitOpen | 6:b8f197b0012c | 40 | { Draw(initialValue); } |
MikamiUitOpen | 6:b8f197b0012c | 41 | |
MikamiUitOpen | 6:b8f197b0012c | 42 | // Constructor with scale value (only horizontal) |
MikamiUitOpen | 6:b8f197b0012c | 43 | SeekBar(uint16_t x, uint16_t y, uint16_t length, |
MikamiUitOpen | 6:b8f197b0012c | 44 | float min, float max, float initialValue, |
MikamiUitOpen | 6:b8f197b0012c | 45 | string left, string center, string right, |
MikamiUitOpen | 12:687ec6183385 | 46 | uint32_t thumbColor = 0xFFB0B0FF, |
MikamiUitOpen | 6:b8f197b0012c | 47 | uint16_t thumbSize = 30, uint16_t width = 4, |
MikamiUitOpen | 6:b8f197b0012c | 48 | uint32_t colorL = LCD_COLOR_LIGHTGRAY, |
MikamiUitOpen | 6:b8f197b0012c | 49 | uint32_t colorH = 0xFFB0B0B0, |
MikamiUitOpen | 6:b8f197b0012c | 50 | uint32_t backColor = GuiBase::ENUM_BACK); |
MikamiUitOpen | 0:a2686ef737c2 | 51 | |
MikamiUitOpen | 12:687ec6183385 | 52 | ~SeekBar(); |
MikamiUitOpen | 12:687ec6183385 | 53 | |
MikamiUitOpen | 0:a2686ef737c2 | 54 | bool Slide(); |
MikamiUitOpen | 0:a2686ef737c2 | 55 | float GetValue() { return v_; } |
MikamiUitOpen | 0:a2686ef737c2 | 56 | int GetIntValue() { return Round(v_); } |
MikamiUitOpen | 9:c379410bda15 | 57 | |
MikamiUitOpen | 5:9c3ea4d4bc6b | 58 | void Activate(); |
MikamiUitOpen | 5:9c3ea4d4bc6b | 59 | void Inactivate(); |
MikamiUitOpen | 9:c379410bda15 | 60 | bool IsActive() { return active_; } |
MikamiUitOpen | 9:c379410bda15 | 61 | |
MikamiUitOpen | 9:c379410bda15 | 62 | bool IsOnThumb(uint16_t &x, uint16_t &y); |
MikamiUitOpen | 9:c379410bda15 | 63 | void Draw(float value, bool fill = false); |
MikamiUitOpen | 9:c379410bda15 | 64 | float ToValue(Point pt); |
MikamiUitOpen | 9:c379410bda15 | 65 | |
MikamiUitOpen | 9:c379410bda15 | 66 | void SetValue(float v) { v_ = v; } |
MikamiUitOpen | 9:c379410bda15 | 67 | void SetSlided(bool tf) { slided_ = tf; } |
MikamiUitOpen | 9:c379410bda15 | 68 | bool GetSlided() { return slided_; } |
MikamiUitOpen | 9:c379410bda15 | 69 | |
MikamiUitOpen | 0:a2686ef737c2 | 70 | private: |
MikamiUitOpen | 0:a2686ef737c2 | 71 | const uint16_t L_, W_; |
MikamiUitOpen | 0:a2686ef737c2 | 72 | const uint16_t SIZE_; // Size of thumb |
MikamiUitOpen | 0:a2686ef737c2 | 73 | const uint32_t COLOR_L_, COLOR_H_; |
MikamiUitOpen | 0:a2686ef737c2 | 74 | const float MIN_, MAX_; |
MikamiUitOpen | 0:a2686ef737c2 | 75 | const Orientation ORIENT_; |
MikamiUitOpen | 0:a2686ef737c2 | 76 | |
MikamiUitOpen | 12:687ec6183385 | 77 | Label **labelLCR; |
MikamiUitOpen | 0:a2686ef737c2 | 78 | float v_; // value of seekbar |
MikamiUitOpen | 12:687ec6183385 | 79 | bool labelOn_; |
MikamiUitOpen | 0:a2686ef737c2 | 80 | bool slided_; |
MikamiUitOpen | 5:9c3ea4d4bc6b | 81 | bool active_; |
MikamiUitOpen | 0:a2686ef737c2 | 82 | |
MikamiUitOpen | 13:9ae055fac9cf | 83 | int Round(float x) { return x + 0.5f - (x < 0); } |
MikamiUitOpen | 0:a2686ef737c2 | 84 | Point ToPoint(float value); |
MikamiUitOpen | 0:a2686ef737c2 | 85 | float Saturate(float value); |
MikamiUitOpen | 0:a2686ef737c2 | 86 | |
MikamiUitOpen | 0:a2686ef737c2 | 87 | // disallow copy constructor and assignment operator |
MikamiUitOpen | 0:a2686ef737c2 | 88 | SeekBar(const SeekBar&); |
MikamiUitOpen | 0:a2686ef737c2 | 89 | SeekBar& operator=(const SeekBar&); |
MikamiUitOpen | 0:a2686ef737c2 | 90 | }; |
MikamiUitOpen | 0:a2686ef737c2 | 91 | } |
MikamiUitOpen | 0:a2686ef737c2 | 92 | #endif // F746_SEEKBAR_HPP |
MikamiUitOpen | 13:9ae055fac9cf | 93 |