Class library: Button class and ButtonGroup class for DISCO-F746NG. クラスライブラリ: DISCO-F746NG 用の,Button クラス,ButtonGroup クラス.
Dependents: F746_SpectralAnalysis_NoPhoto F746_Fourier_series_of_square_wave_01 F746_ButtonGroup_Demo F746_Mandelbrot ... more
Revision 4:543ec60c2814, committed 2015-12-05
- Comitter:
- MikamiUitOpen
- Date:
- Sat Dec 05 11:09:29 2015 +0000
- Parent:
- 3:d99d9c0324b7
- Child:
- 5:2cc388e91bde
- Commit message:
- 5
Changed in this revision
--- a/button.cpp Mon Nov 23 09:47:50 2015 +0000 +++ b/button.cpp Sat Dec 05 11:09:29 2015 +0000 @@ -1,7 +1,7 @@ //----------------------------------------------------------- // Button class // -// 2015/11/23, Copyright (c) 2015 MIKAMI, Naoki +// 2015/12/05, Copyright (c) 2015 MIKAMI, Naoki //----------------------------------------------------------- #include "button.hpp" @@ -12,6 +12,7 @@ void Button::Draw(uint32_t color, uint32_t textColor) { lcd_.SetTextColor(color); + currentColor_ = color; lcd_.FillRect(X_, Y_, W_, H_); if (STR_.length() != 0) @@ -56,3 +57,4 @@ return rtn; } } +
--- a/button.hpp Mon Nov 23 09:47:50 2015 +0000 +++ b/button.hpp Sat Dec 05 11:09:29 2015 +0000 @@ -1,7 +1,7 @@ //----------------------------------------------------------- // Button class -- Header // -// 2015/11/23, Copyright (c) 2015 MIKAMI, Naoki +// 2015/12/05, Copyright (c) 2015 MIKAMI, Naoki //----------------------------------------------------------- #ifndef F746_BUTTON_HPP @@ -24,7 +24,7 @@ const string str = "", sFONT &fonts = Font12, uint32_t textColor = LCD_COLOR_WHITE) : lcd_(lcd), ts_(ts), X_(x), Y_(y), W_(width), H_(height), - COLOR_(color), BACK_COLOR_(backColor), + ORIGINAL_COLOR_(color), BACK_COLOR_(backColor), STR_(str), FONTS_(&fonts) { Draw(color, textColor); } @@ -33,7 +33,7 @@ // Redraw button with original color void Redraw(uint32_t textColor = LCD_COLOR_WHITE) - { Draw(COLOR_, textColor); } + { Draw(ORIGINAL_COLOR_, textColor); } // Erase button with selected color void Erase() @@ -46,16 +46,21 @@ bool Touched(uint32_t color, uint32_t textColor = LCD_COLOR_WHITE); // Get original color - uint32_t GetColor() { return COLOR_; } + uint32_t GetOriginalColor() { return ORIGINAL_COLOR_; } + // Get current color + uint32_t GetCurrentColor() { return currentColor_; } + private: LCD_DISCO_F746NG &lcd_; TS_DISCO_F746NG &ts_; const uint16_t X_, Y_, W_, H_; - const uint32_t COLOR_; // original color + const uint32_t ORIGINAL_COLOR_; // original color const uint32_t BACK_COLOR_; // back color of screen const string STR_; sFONT *const FONTS_; + + uint32_t currentColor_; // disallow copy constructor and assignment operator Button(const Button&); @@ -64,3 +69,4 @@ } #endif // F746_BUTTON_HPP +
--- a/button_group.cpp Mon Nov 23 09:47:50 2015 +0000 +++ b/button_group.cpp Sat Dec 05 11:09:29 2015 +0000 @@ -1,7 +1,7 @@ //----------------------------------------------------------- // Button group class -- Header // -// 2015/11/23, Copyright (c) 2015 MIKAMI, Naoki +// 2015/12/05, Copyright (c) 2015 MIKAMI, Naoki //----------------------------------------------------------- #include "button_group.hpp" @@ -59,10 +59,11 @@ if (n == num) buttons_[n]->Draw(color); else - buttons_[n]->Draw(buttons_[n]->GetColor()); + buttons_[n]->Draw(buttons_[n]->GetOriginalColor()); return true; } else return false; } } +
--- a/button_group.hpp Mon Nov 23 09:47:50 2015 +0000 +++ b/button_group.hpp Sat Dec 05 11:09:29 2015 +0000 @@ -1,7 +1,7 @@ //----------------------------------------------------------- // Button group class -- Header // -// 2015/11/23, Copyright (c) 2015 MIKAMI, Naoki +// 2015/12/05, Copyright (c) 2015 MIKAMI, Naoki //----------------------------------------------------------- #ifndef F746_BUTTON_GROUP_HPP @@ -33,9 +33,16 @@ void Draw(int num, uint32_t color, uint32_t textColor = LCD_COLOR_WHITE) { buttons_[num]->Draw(color, textColor); } + // Draw all button + void DrawAll(uint32_t color, uint32_t textColor = LCD_COLOR_WHITE) + { + for (int n=0; n<numberOfButtons_; n++) + buttons_[n]->Draw(color, textColor); + } + // Redraw button with original color void Redraw(int num, uint32_t textColor = LCD_COLOR_WHITE) - { buttons_[num]->Draw(buttons_[num]->GetColor(), textColor); } + { buttons_[num]->Draw(buttons_[num]->GetOriginalColor(), textColor); } // Erase button with selected color void Erase(int num, uint32_t color) @@ -54,6 +61,10 @@ // Get touched number and redraw button if touched bool GetTouchedNumber(int &num, uint32_t color); + + // Get current color + uint32_t GetCurrentColor(int n) + { return buttons_[n]->GetCurrentColor(); } private: Button **buttons_;