Same as original
button.cpp
- Committer:
- MikamiUitOpen
- Date:
- 2015-11-23
- Revision:
- 2:682475aae171
- Parent:
- 1:57fe493e8db2
- Child:
- 4:543ec60c2814
File content as of revision 2:682475aae171:
//----------------------------------------------------------- // Button class // // 2015/11/23, Copyright (c) 2015 MIKAMI, Naoki //----------------------------------------------------------- #include "button.hpp" namespace Mikami { // Draw button void Button::Draw(uint32_t color, uint32_t textColor) { lcd_.SetTextColor(color); lcd_.FillRect(X_, Y_, W_, H_); if (STR_.length() != 0) { lcd_.SetFont(FONTS_); lcd_.SetBackColor(color); lcd_.SetTextColor(textColor); sFONT *font = lcd_.GetFont(); uint16_t x0 = X_ + (W_ - (font->Width)*(STR_.length()))/2; uint16_t y0 = Y_ + (H_ - font->Height)/2; lcd_.DisplayStringAt(x0, y0, (uint8_t *)STR_.c_str(), LEFT_MODE); lcd_.SetBackColor(BACK_COLOR_); // recover back color } } // Check touch detected bool Button::Touched() { TS_StateTypeDef state; ts_.GetState(&state); if (state.touchDetected) { uint16_t x = state.touchX[0]; uint16_t y = state.touchY[0]; return ( (X_ <= x) && (x <= X_+W_) && (Y_ <= y) && (y <= Y_+H_) ) ? true : false; } else return false; } // Check touch detected and redraw button bool Button::Touched(uint32_t color, uint32_t textColor) { bool rtn = Touched(); if (rtn) Draw(color, textColor); return rtn; } }