Same as original
button_group.cpp@2:682475aae171, 2015-11-23 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Nov 23 01:26:27 2015 +0000
- Revision:
- 2:682475aae171
- Parent:
- 1:57fe493e8db2
- Child:
- 3:d99d9c0324b7
3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:d3038879fed6 | 1 | //----------------------------------------------------------- |
MikamiUitOpen | 0:d3038879fed6 | 2 | // Button group class -- Header |
MikamiUitOpen | 0:d3038879fed6 | 3 | // |
MikamiUitOpen | 1:57fe493e8db2 | 4 | // 2015/11/23, 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 | 0:d3038879fed6 | 16 | uint16_t number, 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 | 0:d3038879fed6 | 53 | // Get touched number and redraw button if touched |
MikamiUitOpen | 1:57fe493e8db2 | 54 | bool ButtonGroup::GetTouchedNumber(int &num, uint32_t color) |
MikamiUitOpen | 0:d3038879fed6 | 55 | { |
MikamiUitOpen | 0:d3038879fed6 | 56 | if (GetTouchedNumber(num)) |
MikamiUitOpen | 0:d3038879fed6 | 57 | { |
MikamiUitOpen | 0:d3038879fed6 | 58 | for (int n=0; n<numberOfButtons_; n++) |
MikamiUitOpen | 0:d3038879fed6 | 59 | if (n == num) |
MikamiUitOpen | 1:57fe493e8db2 | 60 | buttons_[n]->Draw(color); |
MikamiUitOpen | 0:d3038879fed6 | 61 | else |
MikamiUitOpen | 1:57fe493e8db2 | 62 | buttons_[n]->Draw(buttons_[n]->GetColor()); |
MikamiUitOpen | 0:d3038879fed6 | 63 | return true; |
MikamiUitOpen | 0:d3038879fed6 | 64 | } |
MikamiUitOpen | 0:d3038879fed6 | 65 | else |
MikamiUitOpen | 0:d3038879fed6 | 66 | return false; |
MikamiUitOpen | 0:d3038879fed6 | 67 | } |
MikamiUitOpen | 0:d3038879fed6 | 68 | } |