GUI parts for DISCO-F746NG. GuiBase, Button, ButtonGroup, ResetButton, Label, BlinkLabel, NumericLabel, SeekBar, SeekbarGroup
Dependencies: Array_Matrix BSP_DISCO_F746NG
Fork of F746_GUI by
Diff: SeekBar.hpp
- Revision:
- 0:a2686ef737c2
- Child:
- 5:9c3ea4d4bc6b
diff -r 000000000000 -r a2686ef737c2 SeekBar.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SeekBar.hpp Thu Mar 31 07:28:42 2016 +0000 @@ -0,0 +1,66 @@ +//----------------------------------------------------------- +// SeekBar class -- Header +// +// 2016/03/29, Copyright (c) 2016 MIKAMI, Naoki +//----------------------------------------------------------- + +#ifndef F746_SEEKBAR_HPP +#define F746_SEEKBAR_HPP + +#include "GuiBase.hpp" + +namespace Mikami +{ + class SeekBar : public GuiBase + { + public: + enum Orientation { Holizontal, Vertical }; + + // Constructor + SeekBar(uint16_t x, uint16_t y, uint16_t length, + float min, float max, float value, + Orientation hv = Holizontal, + uint32_t thumbColor = LCD_COLOR_WHITE, + uint16_t thumbSize = 30, uint16_t width = 4, + uint32_t colorL = LCD_COLOR_LIGHTGRAY, + uint32_t colorH = 0xFFB0B0B0, + uint32_t backColor = GuiBase::ENUM_BACK) + : GuiBase(x, y, Font12, 0, backColor, thumbColor), + L_(length), W_(width), + SIZE_(thumbSize), COLOR_L_(colorL), COLOR_H_(colorH), + MIN_(min), MAX_(max), ORIENT_(hv), v_(value) + { Draw(value); } + + bool Slide(); + float GetValue() { return v_; } + int GetIntValue() { return Round(v_); } + + private: + struct Point + { + uint16_t x, y; + Point(uint16_t x0 = 0, uint16_t y0 = 0) : x(x0), y(y0) {} + }; + + const uint16_t L_, W_; + const uint16_t SIZE_; // Size of thumb + const uint32_t COLOR_L_, COLOR_H_; + const float MIN_, MAX_; + const Orientation ORIENT_; + + float v_; // value of seekbar + bool slided_; + + void Draw(float value, bool fill = false); + bool IsOnThumb(uint16_t &x, uint16_t &y); + Point ToPoint(float value); + float ToValue(Point pt); + int Round(float x) { return x + 0.5f - (x < 0); } // Round up on 5 + float Saturate(float value); + + // disallow copy constructor and assignment operator + SeekBar(const SeekBar&); + SeekBar& operator=(const SeekBar&); + }; +} +#endif // F746_SEEKBAR_HPP