GUI parts for DISCO-F746NG. GuiBase, Button, ButtonGroup, ResetButton, Label, BlinkLabel, NumericLabel, SeekBar, SeekbarGroup, NumericUpDown
Dependencies: Array_Matrix BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG
Dependents: F746_AudioOutQSPI F746_AudioPlayerSD DISCO-F746NG_test001 F746_SD_WavPlayer ... more
ButtonGroup.cpp
00001 //----------------------------------------------------------- 00002 // ButtonGroup class 00003 // 00004 // 2017/01/25, Copyright (c) 2017 MIKAMI, Naoki 00005 //----------------------------------------------------------- 00006 00007 #include "ButtonGroup.hpp" 00008 00009 namespace Mikami 00010 { 00011 // Constructor 00012 ButtonGroup::ButtonGroup( 00013 uint16_t x0, uint16_t y0, 00014 uint16_t width, uint16_t height, 00015 uint16_t number, const string str[], 00016 uint16_t spaceX, uint16_t spaceY, 00017 uint16_t column, int touched, 00018 sFONT &fonts, 00019 uint32_t textColor, uint32_t backColor, 00020 uint32_t createdColor, uint32_t touchedColor, 00021 uint32_t inactiveColor, uint32_t inactiveTextColor) 00022 : TEXT_COLOR_(textColor), CREATED_COLOR_(createdColor), 00023 TOUCHED_COLOR_(touchedColor), 00024 NUMBER_(number), prevNum_(touched) 00025 { 00026 buttons_.SetSize(number); 00027 for (int n=0; n<number; n++) 00028 { 00029 div_t u1 = div(n, column); 00030 uint16_t x = x0 + u1.rem*(width + spaceX); 00031 uint16_t y = y0 + u1.quot*(height + spaceY); 00032 buttons_[n] = 00033 new Button(x, y, width, height, str[n], fonts, 00034 textColor, backColor, 00035 createdColor, touchedColor, 00036 inactiveColor, inactiveTextColor); 00037 } 00038 // On created, set touched color as needed 00039 if (touched >= 0) TouchedColor(touched); 00040 } 00041 00042 // Draw button 00043 bool ButtonGroup::Draw(int num, uint32_t color, uint32_t textColor) 00044 { 00045 if (!Range(num)) return false; 00046 buttons_[num]->Draw(color, textColor); 00047 return true; 00048 } 00049 00050 // Change to touched color 00051 bool ButtonGroup::TouchedColor(int num) 00052 { 00053 if (prevNum_ != num) prevNum_ = num; 00054 return Draw(num, TOUCHED_COLOR_, TEXT_COLOR_); 00055 } 00056 00057 // Erase button 00058 bool ButtonGroup::Erase(int num) 00059 { 00060 if (!Range(num)) return false; 00061 buttons_[num]->Erase(); 00062 return true; 00063 } 00064 00065 // Check touch detected for specified button 00066 bool ButtonGroup::Touched(int num) 00067 { 00068 if (!Range(num)) return false; 00069 if (!buttons_[num]->IsActive()) return false; 00070 int touched; 00071 if (!GetTouchedNumber(touched)) return false; 00072 bool rtn = (touched == num) ? true : false; 00073 return rtn; 00074 } 00075 00076 // Get touched number, return value: true or false 00077 bool ButtonGroup::GetTouchedNumber(int &num) 00078 { 00079 bool rtn = false; 00080 if (GuiBase::PanelTouched()) 00081 { 00082 for (int n=0; n<NUMBER_; n++) 00083 if (buttons_[n]->IsOnButton() && 00084 buttons_[n]->IsActive()) 00085 { 00086 num = n; 00087 rtn = true; 00088 } 00089 00090 if (!rtn) return false; 00091 } 00092 else 00093 return false; 00094 00095 buttons_[num]->Draw(TOUCHED_COLOR_); 00096 if ((prevNum_ >= 0) && (prevNum_ != num)) 00097 buttons_[prevNum_]->Draw(); 00098 if (prevNum_ != num) prevNum_ = num; 00099 return true; 00100 } 00101 00102 // Get touched number, return value: touched number 00103 int ButtonGroup::GetTouchedNumber() 00104 { 00105 int num; 00106 if (GetTouchedNumber(num)) 00107 return num; 00108 else 00109 return -1; 00110 } 00111 00112 // Wait until touched and get touched number 00113 int ButtonGroup::WaitTouchedAndGet() 00114 { 00115 int num; 00116 while (!GetTouchedNumber(num)) {} 00117 return num; 00118 } 00119 00120 // Activate and inactivate button(s) 00121 bool ButtonGroup::Activate(int num) 00122 { 00123 if (!Range(num)) return false; 00124 buttons_[num]->Activate(); 00125 return true; 00126 } 00127 bool ButtonGroup::Inactivate(int num) 00128 { 00129 if (!Range(num)) return false; 00130 buttons_[num]->Inactivate(); 00131 return true; 00132 } 00133 } 00134
Generated on Wed Jul 13 2022 14:24:25 by 1.7.2