New IHM
Dependencies: Array_Matrix TS_DISCO_F746NG LCD_DISCO_F746NG BSP_DISCO_F746NG
Diff: SeekBar.cpp
- Revision:
- 9:c379410bda15
- Parent:
- 6:b8f197b0012c
- Child:
- 10:5a2068884fd9
--- a/SeekBar.cpp Thu Apr 21 01:12:59 2016 +0000 +++ b/SeekBar.cpp Sun Apr 24 11:49:42 2016 +0000 @@ -1,7 +1,7 @@ //----------------------------------------------------------- // SeekBar class // -// 2016/04/12, Copyright (c) 2016 MIKAMI, Naoki +// 2016/04/24, Copyright (c) 2016 MIKAMI, Naoki //----------------------------------------------------------- #include "SeekBar.hpp" @@ -20,7 +20,7 @@ L_(length), W_(width), SIZE_(thumbSize), COLOR_L_(colorL), COLOR_H_(colorH), MIN_(min), MAX_(max), ORIENT_(Holizontal), - v_(initialValue), active_(true) + v_(initialValue), slided_(false), active_(true) { Draw(initialValue); labelL = new Label(x, y-28, left, Label::CENTER); @@ -77,6 +77,27 @@ } } + // If touched position is on the thumb, return true + bool SeekBar::IsOnThumb(uint16_t &x, uint16_t &y) + { + x = state_.touchX[0]; + y = state_.touchY[0]; + + Point pt = ToPoint(v_); + if (ORIENT_ == Holizontal) + { + if ( (pt.x-SIZE_/5 <= x) && (x <= pt.x+SIZE_/5) && + (pt.y-SIZE_ <= y) && (y <= pt.y+SIZE_) ) return true; + } + else + { + if ( (pt.x-SIZE_ <= x) && (x <= pt.x+SIZE_) && + (pt.y-SIZE_/5 <= y) && (y <= pt.y+SIZE_/5) ) return true; + } + + return false; + } + // Draw seekbar void SeekBar::Draw(float value, bool fill) { @@ -87,7 +108,8 @@ else lcd_.FillRect(X_-SIZE_/2, Y_-SIZE_/2, SIZE_+1, L_+SIZE_+1); - Point pt = ToPoint(Saturate(value)); // Position of thumb + v_ = Saturate(value); // current value + Point pt = ToPoint(v_); // Position of thumb // Draw upper line if (active_) lcd_.SetTextColor(COLOR_H_); @@ -114,27 +136,6 @@ lcd_.DrawCircle(pt.x, pt.y, SIZE_/2); } - // If touched position is on the button, return true - bool SeekBar::IsOnThumb(uint16_t &x, uint16_t &y) - { - x = state_.touchX[0]; - y = state_.touchY[0]; - - Point pt = ToPoint(v_); - if (ORIENT_ == Holizontal) - { - if ( (pt.x-SIZE_/5 <= x) && (x <= pt.x+SIZE_/5) && - (pt.y-SIZE_ <= y) && (y <= pt.y+SIZE_) ) return true; - } - else - { - if ( (pt.x-SIZE_ <= x) && (x <= pt.x+SIZE_) && - (pt.y-SIZE_/5 <= y) && (y <= pt.y+SIZE_/5) ) return true; - } - - return false; - } - SeekBar::Point SeekBar::ToPoint(float value) { if (ORIENT_ == Holizontal)