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.cpp
- Revision:
- 12:687ec6183385
- Parent:
- 10:5a2068884fd9
- Child:
- 15:0511a08a3c09
diff -r 7debdaa7b503 -r 687ec6183385 SeekBar.cpp --- a/SeekBar.cpp Wed Apr 27 07:28:04 2016 +0000 +++ b/SeekBar.cpp Sat Apr 30 06:33:32 2016 +0000 @@ -1,7 +1,7 @@ //----------------------------------------------------------- // SeekBar class // -// 2016/04/27, Copyright (c) 2016 MIKAMI, Naoki +// 2016/04/30, Copyright (c) 2016 MIKAMI, Naoki //----------------------------------------------------------- #include "SeekBar.hpp" @@ -19,13 +19,24 @@ : GuiBase(x, y, Font12, GuiBase::ENUM_TEXT, backColor, thumbColor), L_(length), W_(width), SIZE_(thumbSize), COLOR_L_(colorL), COLOR_H_(colorH), - MIN_(min), MAX_(max), ORIENT_(Holizontal), - v_(initialValue), slided_(false), active_(true) + MIN_(min), MAX_(max), ORIENT_(Holizontal), v_(initialValue), + labelOn_(true), slided_(false), active_(true) { Draw(initialValue); - labelL = new Label(x, y-28, left, Label::CENTER); - labelC = new Label(x+length/2, y-28, center, Label::CENTER); - labelR = new Label(x+length, y-28, right, Label::CENTER); + labelLCR = new Label *[3]; + uint16_t y0 = y - thumbSize/2 - 13; + labelLCR[0] = new Label(x, y0, left, Label::CENTER); + labelLCR[1] = new Label(x+length/2, y0, center, Label::CENTER); + labelLCR[2] = new Label(x+length, y0, right, Label::CENTER); + } + + SeekBar::~SeekBar() + { + if (labelOn_) + { + for (int n=0; n<3; n++) delete labelLCR[n]; + delete[] labelLCR; + } } // Slide thumb @@ -43,13 +54,12 @@ uint16_t x, y; bool rtn = IsOnThumb(x, y); - if (rtn) + if (rtn || slided_) { - v_ = ToValue(Point(x, y)); - Draw(v_, true); - slided_ = true; + if (rtn) v_ = ToValue(Point(x, y)); + Draw(v_, rtn); + slided_ = rtn; } - return rtn; } @@ -57,24 +67,16 @@ { active_ = true; Draw(v_); - if (labelL != NULL) - { - labelL->Draw(TEXT_COLOR_); - labelC->Draw(TEXT_COLOR_); - labelR->Draw(TEXT_COLOR_); - } + if (labelOn_) + for (int n=0; n<3; n++) labelLCR[n]->Draw(TEXT_COLOR_); } void SeekBar::Inactivate() { active_ = false; Draw(v_); - if (labelL != NULL) - { - labelL->Draw(INACTIVE_TEXT_COLOR_); - labelC->Draw(INACTIVE_TEXT_COLOR_); - labelR->Draw(INACTIVE_TEXT_COLOR_); - } + if (labelOn_) + for (int n=0; n<3; n++) labelLCR[n]->Draw(INACTIVE_TEXT_COLOR_); } // If touched position is on the thumb, return true @@ -83,16 +85,17 @@ x = state_.touchX[0]; y = state_.touchY[0]; + uint16_t th = SIZE_/2; 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; + if ( (pt.x-th <= x) && (x <= pt.x+th) && + (pt.y-th <= y) && (y <= pt.y+th) ) return true; } else { - if ( (pt.x-SIZE_ <= x) && (x <= pt.x+SIZE_) && - (pt.y-SIZE_/5 <= y) && (y <= pt.y+SIZE_/5) ) return true; + if ( (pt.x-th <= x) && (x <= pt.x+th) && + (pt.y-th <= y) && (y <= pt.y+th) ) return true; } return false; @@ -115,9 +118,9 @@ // Draw upper line if (active_) lcd_.SetTextColor(COLOR_H_); else lcd_.SetTextColor(INACTIVE_TEXT_COLOR_-0x404040); - if (ORIENT_ == Holizontal) + if ((ORIENT_ == Holizontal) && ((X_+L_-pt.x) > 0)) lcd_.FillRect(pt.x, Y_-W_/4, X_+L_-pt.x, W_/2); - else + if ((ORIENT_ == Vertical) && ((pt.y-Y_) > 0)) lcd_.FillRect(X_-W_/4, Y_, W_/2, pt.y-Y_); // Draw lower line @@ -144,11 +147,12 @@ { 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 + lcd_.DrawRect(xPos+1, yPos+1, width-2, height-2); + lcd_.DrawHLine(pt.x+width/2-1, pt.y+height/2-1, 1); if (ORIENT_ == Holizontal) - lcd_.DrawVLine(pt.x, yPos+3, SIZE_-5); + lcd_.DrawVLine(pt.x, yPos+4, SIZE_-7); else - lcd_.DrawHLine(xPos+3, pt.y, SIZE_-5); + lcd_.DrawHLine(xPos+4, pt.y, SIZE_-7); } }