Same as original
button_group.cpp@6:d268555e2f50, 2015-12-09 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Wed Dec 09 01:55:25 2015 +0000
- Revision:
- 6:d268555e2f50
- Parent:
- 5:2cc388e91bde
- Child:
- 7:6913aebb3905
7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:d3038879fed6 | 1 | //----------------------------------------------------------- |
MikamiUitOpen | 5:2cc388e91bde | 2 | // Button group class |
MikamiUitOpen | 0:d3038879fed6 | 3 | // |
MikamiUitOpen | 6:d268555e2f50 | 4 | // 2015/12/09, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 0:d3038879fed6 | 5 | //----------------------------------------------------------- |
MikamiUitOpen | 0:d3038879fed6 | 6 | |
MikamiUitOpen | 0:d3038879fed6 | 7 | #include "button_group.hpp" |
MikamiUitOpen | 0:d3038879fed6 | 8 | |
MikamiUitOpen | 0:d3038879fed6 | 9 | namespace Mikami |
MikamiUitOpen | 0:d3038879fed6 | 10 | { |
MikamiUitOpen | 0:d3038879fed6 | 11 | // Constructor |
MikamiUitOpen | 0:d3038879fed6 | 12 | ButtonGroup::ButtonGroup(LCD_DISCO_F746NG &lcd, TS_DISCO_F746NG &ts, |
MikamiUitOpen | 0:d3038879fed6 | 13 | uint16_t x0, uint16_t y0, |
MikamiUitOpen | 0:d3038879fed6 | 14 | uint16_t width, uint16_t height, |
MikamiUitOpen | 0:d3038879fed6 | 15 | uint32_t color, uint32_t backColor, |
MikamiUitOpen | 3:d99d9c0324b7 | 16 | uint16_t number, const string str[], |
MikamiUitOpen | 0:d3038879fed6 | 17 | uint16_t spaceX, uint16_t spaceY, |
MikamiUitOpen | 0:d3038879fed6 | 18 | uint16_t column, |
MikamiUitOpen | 0:d3038879fed6 | 19 | sFONT &fonts, uint32_t textColor) |
MikamiUitOpen | 0:d3038879fed6 | 20 | : numberOfButtons_(number) |
MikamiUitOpen | 0:d3038879fed6 | 21 | { |
MikamiUitOpen | 0:d3038879fed6 | 22 | buttons_ = new Button *[number]; |
MikamiUitOpen | 0:d3038879fed6 | 23 | for (int n=0; n<number; n++) |
MikamiUitOpen | 0:d3038879fed6 | 24 | { |
MikamiUitOpen | 0:d3038879fed6 | 25 | div_t u1 = div(n, column); |
MikamiUitOpen | 0:d3038879fed6 | 26 | uint16_t x = x0 + u1.rem*(width + spaceX); |
MikamiUitOpen | 0:d3038879fed6 | 27 | uint16_t y = y0 + u1.quot*(height + spaceY); |
MikamiUitOpen | 0:d3038879fed6 | 28 | buttons_[n] = new Button(lcd, ts, x, y, width, height, |
MikamiUitOpen | 0:d3038879fed6 | 29 | color, backColor, |
MikamiUitOpen | 0:d3038879fed6 | 30 | str[n], fonts, textColor); |
MikamiUitOpen | 0:d3038879fed6 | 31 | } |
MikamiUitOpen | 0:d3038879fed6 | 32 | } |
MikamiUitOpen | 0:d3038879fed6 | 33 | |
MikamiUitOpen | 0:d3038879fed6 | 34 | // Destructor |
MikamiUitOpen | 0:d3038879fed6 | 35 | ButtonGroup::~ButtonGroup() |
MikamiUitOpen | 0:d3038879fed6 | 36 | { |
MikamiUitOpen | 0:d3038879fed6 | 37 | for (int n=0; n<numberOfButtons_; n++) delete buttons_[n]; |
MikamiUitOpen | 0:d3038879fed6 | 38 | delete[] *buttons_; |
MikamiUitOpen | 0:d3038879fed6 | 39 | } |
MikamiUitOpen | 0:d3038879fed6 | 40 | |
MikamiUitOpen | 0:d3038879fed6 | 41 | // Get touched number |
MikamiUitOpen | 0:d3038879fed6 | 42 | bool ButtonGroup::GetTouchedNumber(int &num) |
MikamiUitOpen | 0:d3038879fed6 | 43 | { |
MikamiUitOpen | 0:d3038879fed6 | 44 | for (int n=0; n<numberOfButtons_; n++) |
MikamiUitOpen | 0:d3038879fed6 | 45 | if (buttons_[n]->Touched()) |
MikamiUitOpen | 0:d3038879fed6 | 46 | { |
MikamiUitOpen | 0:d3038879fed6 | 47 | num = n; |
MikamiUitOpen | 0:d3038879fed6 | 48 | return true; |
MikamiUitOpen | 0:d3038879fed6 | 49 | } |
MikamiUitOpen | 0:d3038879fed6 | 50 | return false; |
MikamiUitOpen | 0:d3038879fed6 | 51 | } |
MikamiUitOpen | 0:d3038879fed6 | 52 | |
MikamiUitOpen | 6:d268555e2f50 | 53 | // Check touch detected for specified button and redraw |
MikamiUitOpen | 6:d268555e2f50 | 54 | bool ButtonGroup::Touched(int num, uint32_t color, |
MikamiUitOpen | 6:d268555e2f50 | 55 | uint32_t textColor) |
MikamiUitOpen | 6:d268555e2f50 | 56 | { |
MikamiUitOpen | 6:d268555e2f50 | 57 | if (buttons_[num]->Touched(color, textColor)) |
MikamiUitOpen | 6:d268555e2f50 | 58 | { |
MikamiUitOpen | 6:d268555e2f50 | 59 | for (int n=0; n<numberOfButtons_; n++) |
MikamiUitOpen | 6:d268555e2f50 | 60 | if (n != num) buttons_[n]->Redraw(); |
MikamiUitOpen | 6:d268555e2f50 | 61 | return true; |
MikamiUitOpen | 6:d268555e2f50 | 62 | } |
MikamiUitOpen | 6:d268555e2f50 | 63 | else |
MikamiUitOpen | 6:d268555e2f50 | 64 | return false; |
MikamiUitOpen | 6:d268555e2f50 | 65 | } |
MikamiUitOpen | 6:d268555e2f50 | 66 | |
MikamiUitOpen | 0:d3038879fed6 | 67 | // Get touched number and redraw button if touched |
MikamiUitOpen | 1:57fe493e8db2 | 68 | bool ButtonGroup::GetTouchedNumber(int &num, uint32_t color) |
MikamiUitOpen | 0:d3038879fed6 | 69 | { |
MikamiUitOpen | 0:d3038879fed6 | 70 | if (GetTouchedNumber(num)) |
MikamiUitOpen | 0:d3038879fed6 | 71 | { |
MikamiUitOpen | 0:d3038879fed6 | 72 | for (int n=0; n<numberOfButtons_; n++) |
MikamiUitOpen | 0:d3038879fed6 | 73 | if (n == num) |
MikamiUitOpen | 1:57fe493e8db2 | 74 | buttons_[n]->Draw(color); |
MikamiUitOpen | 0:d3038879fed6 | 75 | else |
MikamiUitOpen | 6:d268555e2f50 | 76 | buttons_[n]->Redraw(); |
MikamiUitOpen | 0:d3038879fed6 | 77 | return true; |
MikamiUitOpen | 0:d3038879fed6 | 78 | } |
MikamiUitOpen | 0:d3038879fed6 | 79 | else |
MikamiUitOpen | 0:d3038879fed6 | 80 | return false; |
MikamiUitOpen | 0:d3038879fed6 | 81 | } |
MikamiUitOpen | 0:d3038879fed6 | 82 | } |