![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fini
main.cpp@12:262492b42b04, 2016-05-30 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon May 30 14:35:25 2016 +0000
- Revision:
- 12:262492b42b04
- Parent:
- 11:0195d802ab3d
- Child:
- 13:270545d8d62e
13
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 1:b4bcb6fa2a1d | 1 | //-------------------------------------------------------------------------------- |
MikamiUitOpen | 0:629ff18592b9 | 2 | // GuiBase とその派生クラスのデモプログラム |
MikamiUitOpen | 0:629ff18592b9 | 3 | // Demo program for GuiBase class and its derivertive classes |
MikamiUitOpen | 1:b4bcb6fa2a1d | 4 | // |
MikamiUitOpen | 8:8a55f2e374da | 5 | // GuiBase, Button, ButtonGroup, Label, NumericLabel, BlinkLabel, |
MikamiUitOpen | 8:8a55f2e374da | 6 | // SeekBar, SeekbarGroup |
MikamiUitOpen | 0:629ff18592b9 | 7 | // |
MikamiUitOpen | 12:262492b42b04 | 8 | // 2016/05/30, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 1:b4bcb6fa2a1d | 9 | //-------------------------------------------------------------------------------- |
MikamiUitOpen | 0:629ff18592b9 | 10 | |
MikamiUitOpen | 0:629ff18592b9 | 11 | #include "NumericLabel.hpp" |
MikamiUitOpen | 1:b4bcb6fa2a1d | 12 | #include "BlinkLabel.hpp" |
MikamiUitOpen | 0:629ff18592b9 | 13 | #include "ButtonGroup.hpp" |
MikamiUitOpen | 10:f23cca92f446 | 14 | #include "SeekbarGroup.hpp" |
MikamiUitOpen | 0:629ff18592b9 | 15 | |
MikamiUitOpen | 0:629ff18592b9 | 16 | using namespace Mikami; |
MikamiUitOpen | 0:629ff18592b9 | 17 | |
MikamiUitOpen | 0:629ff18592b9 | 18 | int main() |
MikamiUitOpen | 0:629ff18592b9 | 19 | { |
MikamiUitOpen | 11:0195d802ab3d | 20 | Label obj10(240, 2, "Dome: GUI parts, 2016/04/30, 15:31", Label::CENTER, Font16); |
MikamiUitOpen | 11:0195d802ab3d | 21 | Label obj11(240, 20, "Button, ButtonGroup, Label, NumericLabel, BlinkLabel,", |
MikamiUitOpen | 11:0195d802ab3d | 22 | Label::CENTER); |
MikamiUitOpen | 11:0195d802ab3d | 23 | Label obj12(240, 32, "SeekBar, SeekbarGroup", |
MikamiUitOpen | 0:629ff18592b9 | 24 | Label::CENTER); |
MikamiUitOpen | 0:629ff18592b9 | 25 | |
MikamiUitOpen | 11:0195d802ab3d | 26 | Button button1(10, 52, 50, 40, "1"); |
MikamiUitOpen | 11:0195d802ab3d | 27 | Button button2(62, 52, 50, 40, "2"); |
MikamiUitOpen | 0:629ff18592b9 | 28 | |
MikamiUitOpen | 0:629ff18592b9 | 29 | const int NUMBER_BUTTONS = 4; |
MikamiUitOpen | 7:5788d0406bfd | 30 | const string STR1[NUMBER_BUTTONS] = {"Button1", "Button2", "Button3", "Activate"}; |
MikamiUitOpen | 11:0195d802ab3d | 31 | ButtonGroup bGroup1(160, 52, 66, 40, NUMBER_BUTTONS, STR1, 5, 5, 3, 1, |
MikamiUitOpen | 0:629ff18592b9 | 32 | Font12, LCD_COLOR_WHITE, 0xFF003538, 0xFFB70068, 0xFFFF7FFF); |
MikamiUitOpen | 11:0195d802ab3d | 33 | NumericLabel<int> bTouch(240, 112, Label::LEFT, Font12, LCD_COLOR_MAGENTA); |
MikamiUitOpen | 0:629ff18592b9 | 34 | |
MikamiUitOpen | 3:e92615be71c7 | 35 | // Control status of bGroup1 |
MikamiUitOpen | 0:629ff18592b9 | 36 | const string STR2[3] = {"0", "1", "2"}; |
MikamiUitOpen | 0:629ff18592b9 | 37 | ButtonGroup bGroup2(160, 150, 66, 40, 3, STR2, 5, 5, 3); |
MikamiUitOpen | 7:5788d0406bfd | 38 | bGroup2.InactivateAll(); |
MikamiUitOpen | 1:b4bcb6fa2a1d | 39 | |
MikamiUitOpen | 3:e92615be71c7 | 40 | // Switching buttons to control barH active or inactive |
MikamiUitOpen | 3:e92615be71c7 | 41 | const string STR3[3] = {"ON", "OFF"}; |
MikamiUitOpen | 3:e92615be71c7 | 42 | ButtonGroup bGroup3(10, 150, 66, 40, 2, STR3, 0, 0, 2); |
MikamiUitOpen | 3:e92615be71c7 | 43 | bGroup3.TouchedColor(0); |
MikamiUitOpen | 3:e92615be71c7 | 44 | |
MikamiUitOpen | 1:b4bcb6fa2a1d | 45 | Button doNotTouch(250, 220, 120, 40, "Don't Touch", Font12, |
MikamiUitOpen | 1:b4bcb6fa2a1d | 46 | GuiBase::ENUM_TEXT, GuiBase::ENUM_BACK, |
MikamiUitOpen | 1:b4bcb6fa2a1d | 47 | LCD_COLOR_DARKGREEN, LCD_COLOR_RED); |
MikamiUitOpen | 0:629ff18592b9 | 48 | |
MikamiUitOpen | 7:5788d0406bfd | 49 | // Using default value for argument (Horizontal) |
MikamiUitOpen | 4:4f73a3054a67 | 50 | SeekBar barH(20, 250, 200, -5, 5, 0, "-5", "", "5"); |
MikamiUitOpen | 4:4f73a3054a67 | 51 | NumericLabel<float> numLabel1(80, 205, "%5.1f", barH.GetValue()); |
MikamiUitOpen | 4:4f73a3054a67 | 52 | NumericLabel<int> numLabel2(130, 205, "%3d", (int)barH.GetValue()); |
MikamiUitOpen | 4:4f73a3054a67 | 53 | NumericLabel<int> numLabel3(160, 205); |
MikamiUitOpen | 0:629ff18592b9 | 54 | |
MikamiUitOpen | 8:8a55f2e374da | 55 | // SeekbarGroup (vertical) |
MikamiUitOpen | 12:262492b42b04 | 56 | SeekbarGroup barV(410, 130, 121, 2, 45, -6, 6, 2, |
MikamiUitOpen | 11:0195d802ab3d | 57 | SeekBar::Vertical, 0xFFA0FFC0); |
MikamiUitOpen | 8:8a55f2e374da | 58 | NumericLabel<float> **numLabel4; |
MikamiUitOpen | 8:8a55f2e374da | 59 | numLabel4 = new NumericLabel<float> *[2]; |
MikamiUitOpen | 8:8a55f2e374da | 60 | for (int n=0; n<2; n++) numLabel4[n] = |
MikamiUitOpen | 12:262492b42b04 | 61 | new NumericLabel<float>(410+n*45, 104, "%4.1f", barV.GetValue(n), Label::CENTER); |
MikamiUitOpen | 12:262492b42b04 | 62 | NumericLabel<int> numLabel5(455, 92, "%1d", barV.GetIntValue(0), Label::CENTER); |
MikamiUitOpen | 8:8a55f2e374da | 63 | |
MikamiUitOpen | 12:262492b42b04 | 64 | // Test of left-, cenrer-, and right-justified |
MikamiUitOpen | 11:0195d802ab3d | 65 | Label leftJustified(420, 52, "ABC", Label::LEFT); |
MikamiUitOpen | 11:0195d802ab3d | 66 | Label centerJustified(420, 62, "ABC", Label::CENTER); |
MikamiUitOpen | 11:0195d802ab3d | 67 | Label rightJustified1(420, 72, "ABC", Label::RIGHT); |
MikamiUitOpen | 0:629ff18592b9 | 68 | |
MikamiUitOpen | 0:629ff18592b9 | 69 | while (true) |
MikamiUitOpen | 0:629ff18592b9 | 70 | { |
MikamiUitOpen | 0:629ff18592b9 | 71 | if (button1.Touched()) button2.Draw(); |
MikamiUitOpen | 0:629ff18592b9 | 72 | if (button2.Touched()) button1.Draw(); |
MikamiUitOpen | 0:629ff18592b9 | 73 | |
MikamiUitOpen | 0:629ff18592b9 | 74 | int num; |
MikamiUitOpen | 0:629ff18592b9 | 75 | if (bGroup1.GetTouchedNumber(num)) |
MikamiUitOpen | 1:b4bcb6fa2a1d | 76 | bTouch.Draw("Button%d touched", num+1); |
MikamiUitOpen | 7:5788d0406bfd | 77 | if (num == 3) |
MikamiUitOpen | 7:5788d0406bfd | 78 | bGroup2.ActivateAll(); |
MikamiUitOpen | 0:629ff18592b9 | 79 | |
MikamiUitOpen | 1:b4bcb6fa2a1d | 80 | if (bGroup2.GetTouchedNumber(num)) |
MikamiUitOpen | 1:b4bcb6fa2a1d | 81 | switch (num) |
MikamiUitOpen | 0:629ff18592b9 | 82 | { |
MikamiUitOpen | 1:b4bcb6fa2a1d | 83 | case 0: button1.Activate(); |
MikamiUitOpen | 1:b4bcb6fa2a1d | 84 | bGroup1.Activate(1); |
MikamiUitOpen | 1:b4bcb6fa2a1d | 85 | bGroup1.DrawAll(); |
MikamiUitOpen | 1:b4bcb6fa2a1d | 86 | break; |
MikamiUitOpen | 1:b4bcb6fa2a1d | 87 | case 1: button1.Inactivate(); |
MikamiUitOpen | 1:b4bcb6fa2a1d | 88 | bGroup1.Inactivate(1); |
MikamiUitOpen | 1:b4bcb6fa2a1d | 89 | break; |
MikamiUitOpen | 1:b4bcb6fa2a1d | 90 | case 2: for (int n=0; n<4; n++) bGroup1.Erase(n); |
MikamiUitOpen | 8:8a55f2e374da | 91 | for (int n=0; n<2; n++) |
MikamiUitOpen | 8:8a55f2e374da | 92 | { |
MikamiUitOpen | 8:8a55f2e374da | 93 | barV.Draw(n, 0); // reset seekbar |
MikamiUitOpen | 8:8a55f2e374da | 94 | numLabel4[n]->Draw("%4.1f", barV.GetValue(n)); |
MikamiUitOpen | 8:8a55f2e374da | 95 | } |
MikamiUitOpen | 1:b4bcb6fa2a1d | 96 | break; |
MikamiUitOpen | 0:629ff18592b9 | 97 | } |
MikamiUitOpen | 0:629ff18592b9 | 98 | |
MikamiUitOpen | 3:e92615be71c7 | 99 | if (barH.Slide()) |
MikamiUitOpen | 0:629ff18592b9 | 100 | { |
MikamiUitOpen | 3:e92615be71c7 | 101 | numLabel1.Draw("%5.1f", barH.GetValue()); |
MikamiUitOpen | 3:e92615be71c7 | 102 | int8_t x = (int8_t)barH.GetValue(); |
MikamiUitOpen | 0:629ff18592b9 | 103 | numLabel2.Draw("%3d", x); |
MikamiUitOpen | 0:629ff18592b9 | 104 | |
MikamiUitOpen | 3:e92615be71c7 | 105 | numLabel3.Draw("%3d", barH.GetIntValue()); |
MikamiUitOpen | 0:629ff18592b9 | 106 | } |
MikamiUitOpen | 0:629ff18592b9 | 107 | |
MikamiUitOpen | 8:8a55f2e374da | 108 | int sbNum; |
MikamiUitOpen | 8:8a55f2e374da | 109 | if (barV.GetSlidedNumber(sbNum)) |
MikamiUitOpen | 12:262492b42b04 | 110 | { |
MikamiUitOpen | 12:262492b42b04 | 111 | if (sbNum == 0) numLabel4[sbNum]->Draw("%4.1f", barV.GetValue(sbNum)); |
MikamiUitOpen | 12:262492b42b04 | 112 | else numLabel4[sbNum]->Draw("%4.1f", barV.GetValue(sbNum)); |
MikamiUitOpen | 12:262492b42b04 | 113 | if (sbNum == 1) numLabel5.Draw("%1d", barV.GetIntValue(sbNum)); |
MikamiUitOpen | 12:262492b42b04 | 114 | } |
MikamiUitOpen | 1:b4bcb6fa2a1d | 115 | // If "doNotTouch" button touched, trapped into endless loop |
MikamiUitOpen | 1:b4bcb6fa2a1d | 116 | if (doNotTouch.Touched()) |
MikamiUitOpen | 1:b4bcb6fa2a1d | 117 | BlinkLabel warning(250, 200, "You must reset", Label::LEFT, Font16); |
MikamiUitOpen | 3:e92615be71c7 | 118 | |
MikamiUitOpen | 3:e92615be71c7 | 119 | // SeekBar active inactive switching |
MikamiUitOpen | 4:4f73a3054a67 | 120 | if (bGroup3.Touched(0)) |
MikamiUitOpen | 4:4f73a3054a67 | 121 | { |
MikamiUitOpen | 4:4f73a3054a67 | 122 | barH.Activate(); |
MikamiUitOpen | 8:8a55f2e374da | 123 | barV.ActivateAll(); |
MikamiUitOpen | 4:4f73a3054a67 | 124 | } |
MikamiUitOpen | 4:4f73a3054a67 | 125 | if (bGroup3.Touched(1)) |
MikamiUitOpen | 4:4f73a3054a67 | 126 | { |
MikamiUitOpen | 4:4f73a3054a67 | 127 | barH.Inactivate(); |
MikamiUitOpen | 8:8a55f2e374da | 128 | barV.InactivateAll(); |
MikamiUitOpen | 4:4f73a3054a67 | 129 | } |
MikamiUitOpen | 0:629ff18592b9 | 130 | |
MikamiUitOpen | 0:629ff18592b9 | 131 | wait(0.02f); |
MikamiUitOpen | 0:629ff18592b9 | 132 | } |
MikamiUitOpen | 0:629ff18592b9 | 133 | } |