Same as original
button.cpp
- Committer:
- MikamiUitOpen
- Date:
- 2015-12-08
- Revision:
- 5:2cc388e91bde
- Parent:
- 4:543ec60c2814
- Child:
- 10:5ca60e724a76
File content as of revision 5:2cc388e91bde:
//----------------------------------------------------------- // Button class // // 2015/12/08, Copyright (c) 2015 MIKAMI, Naoki //----------------------------------------------------------- #include "button.hpp" namespace Mikami { // Draw button void Button::Draw(uint32_t color, uint32_t textColor) { lcd_.SetTextColor(color); currentColor_ = color; lcd_.FillRect(X_, Y_, W_, H_); if (STR_.length() != 0) { lcd_.SetFont(FONTS_); lcd_.SetBackColor(color); lcd_.SetTextColor(textColor); uint16_t x0 = X_ + (W_ - FONT_WIDTH_*(STR_.length()))/2; uint16_t y0 = Y_ + (H_ - FONT_HEIGHT_)/2 + 1; 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; } }