New IHM
Dependencies: Array_Matrix TS_DISCO_F746NG LCD_DISCO_F746NG BSP_DISCO_F746NG
Diff: SeekBar.cpp
- Revision:
- 10:5a2068884fd9
- Parent:
- 9:c379410bda15
- Child:
- 12:687ec6183385
--- a/SeekBar.cpp Sun Apr 24 11:49:42 2016 +0000 +++ b/SeekBar.cpp Wed Apr 27 00:24:18 2016 +0000 @@ -1,7 +1,7 @@ //----------------------------------------------------------- // SeekBar class // -// 2016/04/24, Copyright (c) 2016 MIKAMI, Naoki +// 2016/04/27, Copyright (c) 2016 MIKAMI, Naoki //----------------------------------------------------------- #include "SeekBar.hpp" @@ -101,12 +101,13 @@ // Draw seekbar void SeekBar::Draw(float value, bool fill) { + uint16_t sizeS = (uint16_t)(SIZE_*0.6f); // Erase previous seekbar lcd_.SetTextColor(BACK_COLOR_); if (ORIENT_ == Holizontal) - lcd_.FillRect(X_-SIZE_/2, Y_-SIZE_/2, L_+SIZE_+1, SIZE_+1); + lcd_.FillRect(X_-sizeS/2, Y_-SIZE_/2, L_+sizeS+1, SIZE_+1); else - lcd_.FillRect(X_-SIZE_/2, Y_-SIZE_/2, SIZE_+1, L_+SIZE_+1); + lcd_.FillRect(X_-SIZE_/2, Y_-sizeS/2, SIZE_+1, L_+sizeS+1); v_ = Saturate(value); // current value Point pt = ToPoint(v_); // Position of thumb @@ -130,18 +131,33 @@ // Draw thumb if (active_) lcd_.SetTextColor(CREATED_COLOR_); else lcd_.SetTextColor(INACTIVE_TEXT_COLOR_); + uint16_t width = SIZE_; + uint16_t height = SIZE_; + if (ORIENT_ == Holizontal) width = sizeS; + else height = sizeS; + uint16_t xPos = pt.x - width/2; + uint16_t yPos = pt.y - height/2; + if (fill) - lcd_.FillCircle(pt.x, pt.y, SIZE_/2); + lcd_.FillRect(xPos, yPos, width+1, height+1); else - lcd_.DrawCircle(pt.x, pt.y, SIZE_/2); + { + lcd_.DrawRect(xPos, yPos, width, height); + lcd_.DrawHLine(pt.x+width/2, pt.y+height/2, 1); + if (v_ == MAX_) lcd_.DrawHLine(xPos, yPos, width); // should not be necessary + if (ORIENT_ == Holizontal) + lcd_.DrawVLine(pt.x, yPos+3, SIZE_-5); + else + lcd_.DrawHLine(xPos+3, pt.y, SIZE_-5); + } } SeekBar::Point SeekBar::ToPoint(float value) { if (ORIENT_ == Holizontal) - return Point(X_ + L_*(value - MIN_)/(MAX_ - MIN_), Y_); + return Point(X_ + Round(L_*(value - MIN_)/(MAX_ - MIN_)), Y_); else - return Point(X_, Y_ + L_ - L_*(value - MIN_)/(MAX_ - MIN_)); + return Point(X_, Y_ + L_ - Round(L_*(value - MIN_)/(MAX_ - MIN_))); } float SeekBar::ToValue(Point pt)