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