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
ButtonGroup.cpp@3:fe6ff954824a, 2016-04-07 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Thu Apr 07 00:08:19 2016 +0000
- Revision:
- 3:fe6ff954824a
- Parent:
- 2:d2f882d98f0a
- Child:
- 14:b977160de2f3
4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:a2686ef737c2 | 1 | //----------------------------------------------------------- |
MikamiUitOpen | 0:a2686ef737c2 | 2 | // ButtonGroup class |
MikamiUitOpen | 0:a2686ef737c2 | 3 | // |
MikamiUitOpen | 3:fe6ff954824a | 4 | // 2016/04/07, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:a2686ef737c2 | 5 | //----------------------------------------------------------- |
MikamiUitOpen | 0:a2686ef737c2 | 6 | |
MikamiUitOpen | 0:a2686ef737c2 | 7 | #include "ButtonGroup.hpp" |
MikamiUitOpen | 0:a2686ef737c2 | 8 | |
MikamiUitOpen | 0:a2686ef737c2 | 9 | namespace Mikami |
MikamiUitOpen | 0:a2686ef737c2 | 10 | { |
MikamiUitOpen | 0:a2686ef737c2 | 11 | // Constructor |
MikamiUitOpen | 0:a2686ef737c2 | 12 | ButtonGroup::ButtonGroup( |
MikamiUitOpen | 0:a2686ef737c2 | 13 | uint16_t x0, uint16_t y0, |
MikamiUitOpen | 0:a2686ef737c2 | 14 | uint16_t width, uint16_t height, |
MikamiUitOpen | 0:a2686ef737c2 | 15 | uint16_t number, const string str[], |
MikamiUitOpen | 0:a2686ef737c2 | 16 | uint16_t spaceX, uint16_t spaceY, |
MikamiUitOpen | 0:a2686ef737c2 | 17 | uint16_t column, int touched, |
MikamiUitOpen | 0:a2686ef737c2 | 18 | sFONT &fonts, |
MikamiUitOpen | 0:a2686ef737c2 | 19 | uint32_t textColor, uint32_t backColor, |
MikamiUitOpen | 0:a2686ef737c2 | 20 | uint32_t createdColor, uint32_t touchedColor, |
MikamiUitOpen | 0:a2686ef737c2 | 21 | uint32_t inactiveColor, uint32_t inactiveTextColor) |
MikamiUitOpen | 0:a2686ef737c2 | 22 | : GuiBase(x0, y0, fonts, textColor, backColor, |
MikamiUitOpen | 0:a2686ef737c2 | 23 | createdColor, touchedColor, |
MikamiUitOpen | 0:a2686ef737c2 | 24 | inactiveColor, inactiveTextColor), |
MikamiUitOpen | 0:a2686ef737c2 | 25 | numberOfButtons_(number), prevNum_(touched) |
MikamiUitOpen | 0:a2686ef737c2 | 26 | { |
MikamiUitOpen | 0:a2686ef737c2 | 27 | buttons_ = new Button *[number]; |
MikamiUitOpen | 0:a2686ef737c2 | 28 | for (int n=0; n<number; n++) |
MikamiUitOpen | 0:a2686ef737c2 | 29 | { |
MikamiUitOpen | 0:a2686ef737c2 | 30 | div_t u1 = div(n, column); |
MikamiUitOpen | 0:a2686ef737c2 | 31 | uint16_t x = x0 + u1.rem*(width + spaceX); |
MikamiUitOpen | 0:a2686ef737c2 | 32 | uint16_t y = y0 + u1.quot*(height + spaceY); |
MikamiUitOpen | 0:a2686ef737c2 | 33 | buttons_[n] = |
MikamiUitOpen | 0:a2686ef737c2 | 34 | new Button(x, y, width, height, str[n], fonts, |
MikamiUitOpen | 0:a2686ef737c2 | 35 | TEXT_COLOR_, BACK_COLOR_, |
MikamiUitOpen | 0:a2686ef737c2 | 36 | CREATED_COLOR_, TOUCHED_COLOR_, |
MikamiUitOpen | 0:a2686ef737c2 | 37 | INACTIVE_COLOR_, INACTIVE_TEXT_COLOR_); |
MikamiUitOpen | 0:a2686ef737c2 | 38 | } |
MikamiUitOpen | 3:fe6ff954824a | 39 | // On created, set touched color as needed |
MikamiUitOpen | 3:fe6ff954824a | 40 | if (touched >= 0) TouchedColor(touched); |
MikamiUitOpen | 0:a2686ef737c2 | 41 | } |
MikamiUitOpen | 0:a2686ef737c2 | 42 | |
MikamiUitOpen | 0:a2686ef737c2 | 43 | // Destructor |
MikamiUitOpen | 0:a2686ef737c2 | 44 | ButtonGroup::~ButtonGroup() |
MikamiUitOpen | 0:a2686ef737c2 | 45 | { |
MikamiUitOpen | 0:a2686ef737c2 | 46 | for (int n=0; n<numberOfButtons_; n++) delete buttons_[n]; |
MikamiUitOpen | 0:a2686ef737c2 | 47 | delete[] *buttons_; |
MikamiUitOpen | 0:a2686ef737c2 | 48 | } |
MikamiUitOpen | 0:a2686ef737c2 | 49 | |
MikamiUitOpen | 0:a2686ef737c2 | 50 | // Draw button |
MikamiUitOpen | 0:a2686ef737c2 | 51 | bool ButtonGroup::Draw(int num, uint32_t color, uint32_t textColor) |
MikamiUitOpen | 0:a2686ef737c2 | 52 | { |
MikamiUitOpen | 0:a2686ef737c2 | 53 | if (!Range(num)) return false; |
MikamiUitOpen | 0:a2686ef737c2 | 54 | buttons_[num]->Draw(color, textColor); |
MikamiUitOpen | 0:a2686ef737c2 | 55 | return true; |
MikamiUitOpen | 0:a2686ef737c2 | 56 | } |
MikamiUitOpen | 0:a2686ef737c2 | 57 | |
MikamiUitOpen | 3:fe6ff954824a | 58 | // Change to touched color |
MikamiUitOpen | 3:fe6ff954824a | 59 | bool ButtonGroup::TouchedColor(int num) |
MikamiUitOpen | 3:fe6ff954824a | 60 | { |
MikamiUitOpen | 3:fe6ff954824a | 61 | if (prevNum_ != num) prevNum_ = num; |
MikamiUitOpen | 3:fe6ff954824a | 62 | return Draw(num, TOUCHED_COLOR_, TEXT_COLOR_); |
MikamiUitOpen | 3:fe6ff954824a | 63 | } |
MikamiUitOpen | 3:fe6ff954824a | 64 | |
MikamiUitOpen | 2:d2f882d98f0a | 65 | // Erase button |
MikamiUitOpen | 0:a2686ef737c2 | 66 | bool ButtonGroup::Erase(int num) |
MikamiUitOpen | 0:a2686ef737c2 | 67 | { |
MikamiUitOpen | 0:a2686ef737c2 | 68 | if (!Range(num)) return false; |
MikamiUitOpen | 0:a2686ef737c2 | 69 | buttons_[num]->Erase(); |
MikamiUitOpen | 0:a2686ef737c2 | 70 | return true; |
MikamiUitOpen | 0:a2686ef737c2 | 71 | } |
MikamiUitOpen | 0:a2686ef737c2 | 72 | |
MikamiUitOpen | 0:a2686ef737c2 | 73 | // Check touch detected for specified button |
MikamiUitOpen | 0:a2686ef737c2 | 74 | bool ButtonGroup::Touched(int num) |
MikamiUitOpen | 0:a2686ef737c2 | 75 | { |
MikamiUitOpen | 0:a2686ef737c2 | 76 | if (!Range(num)) return false; |
MikamiUitOpen | 0:a2686ef737c2 | 77 | if (!buttons_[num]->IsActive()) return false; |
MikamiUitOpen | 0:a2686ef737c2 | 78 | int touched; |
MikamiUitOpen | 0:a2686ef737c2 | 79 | if (!GetTouchedNumber(touched)) return false; |
MikamiUitOpen | 0:a2686ef737c2 | 80 | bool rtn = (touched == num) ? true : false; |
MikamiUitOpen | 0:a2686ef737c2 | 81 | return rtn; |
MikamiUitOpen | 0:a2686ef737c2 | 82 | } |
MikamiUitOpen | 0:a2686ef737c2 | 83 | |
MikamiUitOpen | 0:a2686ef737c2 | 84 | // Get touched number |
MikamiUitOpen | 0:a2686ef737c2 | 85 | bool ButtonGroup::GetTouchedNumber(int &num) |
MikamiUitOpen | 0:a2686ef737c2 | 86 | { |
MikamiUitOpen | 0:a2686ef737c2 | 87 | bool rtn = false; |
MikamiUitOpen | 0:a2686ef737c2 | 88 | if (PanelTouched()) |
MikamiUitOpen | 0:a2686ef737c2 | 89 | { |
MikamiUitOpen | 0:a2686ef737c2 | 90 | for (int n=0; n<numberOfButtons_; n++) |
MikamiUitOpen | 0:a2686ef737c2 | 91 | if (buttons_[n]->IsOnButton() && |
MikamiUitOpen | 0:a2686ef737c2 | 92 | buttons_[n]->IsActive()) |
MikamiUitOpen | 0:a2686ef737c2 | 93 | { |
MikamiUitOpen | 0:a2686ef737c2 | 94 | num = n; |
MikamiUitOpen | 0:a2686ef737c2 | 95 | rtn = true; |
MikamiUitOpen | 0:a2686ef737c2 | 96 | } |
MikamiUitOpen | 0:a2686ef737c2 | 97 | |
MikamiUitOpen | 0:a2686ef737c2 | 98 | if (!rtn) return false; |
MikamiUitOpen | 0:a2686ef737c2 | 99 | } |
MikamiUitOpen | 0:a2686ef737c2 | 100 | else |
MikamiUitOpen | 0:a2686ef737c2 | 101 | return false; |
MikamiUitOpen | 0:a2686ef737c2 | 102 | |
MikamiUitOpen | 0:a2686ef737c2 | 103 | buttons_[num]->Draw(TOUCHED_COLOR_); |
MikamiUitOpen | 0:a2686ef737c2 | 104 | if ((prevNum_ >= 0) && (prevNum_ != num)) |
MikamiUitOpen | 0:a2686ef737c2 | 105 | buttons_[prevNum_]->Draw(); |
MikamiUitOpen | 0:a2686ef737c2 | 106 | if (prevNum_ != num) prevNum_ = num; |
MikamiUitOpen | 0:a2686ef737c2 | 107 | return true; |
MikamiUitOpen | 0:a2686ef737c2 | 108 | } |
MikamiUitOpen | 0:a2686ef737c2 | 109 | |
MikamiUitOpen | 0:a2686ef737c2 | 110 | // Activate and inactivate |
MikamiUitOpen | 0:a2686ef737c2 | 111 | bool ButtonGroup::Activate(int num) |
MikamiUitOpen | 0:a2686ef737c2 | 112 | { |
MikamiUitOpen | 0:a2686ef737c2 | 113 | if (!Range(num)) return false; |
MikamiUitOpen | 0:a2686ef737c2 | 114 | buttons_[num]->Activate(); |
MikamiUitOpen | 0:a2686ef737c2 | 115 | return true; |
MikamiUitOpen | 0:a2686ef737c2 | 116 | } |
MikamiUitOpen | 0:a2686ef737c2 | 117 | bool ButtonGroup::Inactivate(int num) |
MikamiUitOpen | 0:a2686ef737c2 | 118 | { |
MikamiUitOpen | 0:a2686ef737c2 | 119 | if (!Range(num)) return false; |
MikamiUitOpen | 0:a2686ef737c2 | 120 | buttons_[num]->Inactivate(); |
MikamiUitOpen | 0:a2686ef737c2 | 121 | return true; |
MikamiUitOpen | 0:a2686ef737c2 | 122 | } |
MikamiUitOpen | 0:a2686ef737c2 | 123 | } |