GUI parts for DISCO-F746NG. GuiBase, Button, ButtonGroup, Label, BlinkLabel, NumericLabel, SeekBar, SeekbarGroup
Dependents: F746_SD_GraphicEqualizer_ren0620
Fork of F746_GUI by
Button.cpp
00001 //----------------------------------------------------------- 00002 // Button class handling multi-touch 00003 // Multi-touch: Enabled (default) 00004 // 00005 // 2016/04/08, Copyright (c) 2016 MIKAMI, Naoki 00006 //----------------------------------------------------------- 00007 00008 #include "Button.hpp" 00009 00010 namespace Mikami 00011 { 00012 // Draw button 00013 void Button::Draw(uint32_t color, uint32_t textColor) 00014 { 00015 if (color == BACK_COLOR_) active_ = true; 00016 if (!active_) return; 00017 lcd_.SetTextColor(color); 00018 lcd_.FillRect(X_, Y_, W_, H_); 00019 00020 if (STR_.length() != 0) 00021 { 00022 lcd_.SetFont(FONTS_); 00023 lcd_.SetBackColor(color); 00024 lcd_.SetTextColor(textColor); 00025 uint16_t x0 = X_ + (W_ - FONTS_->Width*(STR_.length()))/2; 00026 uint16_t y0 = Y_ + (H_ - FONTS_->Height)/2 + 1; 00027 DrawString(x0, y0, STR_); 00028 lcd_.SetBackColor(BACK_COLOR_); // recover back color 00029 } 00030 } 00031 00032 // Check touch detected 00033 bool Button::Touched() 00034 { 00035 if (!active_) return false; 00036 if (!PanelTouched()) return false; 00037 if (!IsOnButton()) return false; 00038 Draw(TOUCHED_COLOR_, TEXT_COLOR_); 00039 return true; 00040 } 00041 00042 // If touched position is on the button, return true 00043 bool Button::IsOnButton() 00044 { 00045 int nTouch = multiTouch_ ? state_.touchDetected : 1; 00046 for (int n=0; n<nTouch; n++) 00047 { 00048 uint16_t x = state_.touchX[n]; 00049 uint16_t y = state_.touchY[n]; 00050 00051 if ( (X_ <= x) && (x <= X_+W_+X_expend) && 00052 (Y_ <= y) && (y <= Y_+H_) ) return true; 00053 } 00054 return false; 00055 } 00056 00057 void Button::Activate() 00058 { 00059 active_ = true; 00060 Draw(); 00061 } 00062 00063 void Button::Inactivate() 00064 { 00065 Draw(INACTIVE_COLOR_, INACTIVE_TEXT_COLOR_); 00066 active_ = false; 00067 } 00068 }
Generated on Fri Jul 22 2022 12:03:18 by 1.7.2