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