Same as original

Committer:
MikamiUitOpen
Date:
Sun Nov 22 10:07:55 2015 +0000
Revision:
0:d3038879fed6
Child:
1:57fe493e8db2
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:d3038879fed6 1 //-----------------------------------------------------------
MikamiUitOpen 0:d3038879fed6 2 // Button class
MikamiUitOpen 0:d3038879fed6 3 //
MikamiUitOpen 0:d3038879fed6 4 // 2015/11/22, Copyright (c) 2015 MIKAMI, Naoki
MikamiUitOpen 0:d3038879fed6 5 //-----------------------------------------------------------
MikamiUitOpen 0:d3038879fed6 6
MikamiUitOpen 0:d3038879fed6 7 #include "button.hpp"
MikamiUitOpen 0:d3038879fed6 8
MikamiUitOpen 0:d3038879fed6 9 namespace Mikami
MikamiUitOpen 0:d3038879fed6 10 {
MikamiUitOpen 0:d3038879fed6 11 // Draw button
MikamiUitOpen 0:d3038879fed6 12 void Button::Draw(uint32_t color, uint32_t textColor)
MikamiUitOpen 0:d3038879fed6 13 {
MikamiUitOpen 0:d3038879fed6 14 lcd_.SetTextColor(color);
MikamiUitOpen 0:d3038879fed6 15 lcd_.FillRect(X_, Y_, W_, H_);
MikamiUitOpen 0:d3038879fed6 16
MikamiUitOpen 0:d3038879fed6 17 if (STR_.length() != 0)
MikamiUitOpen 0:d3038879fed6 18 {
MikamiUitOpen 0:d3038879fed6 19 lcd_.SetFont(FONTS_);
MikamiUitOpen 0:d3038879fed6 20 lcd_.SetBackColor(color);
MikamiUitOpen 0:d3038879fed6 21 lcd_.SetTextColor(textColor);
MikamiUitOpen 0:d3038879fed6 22
MikamiUitOpen 0:d3038879fed6 23 sFONT *font = lcd_.GetFont();
MikamiUitOpen 0:d3038879fed6 24 uint16_t x0 = X_ + (W_ - (font->Width)*(STR_.length()))/2;
MikamiUitOpen 0:d3038879fed6 25 uint16_t y0 = Y_ + (H_ - font->Height)/2;
MikamiUitOpen 0:d3038879fed6 26
MikamiUitOpen 0:d3038879fed6 27 lcd_.DisplayStringAt(x0, y0, (uint8_t *)STR_.c_str(), LEFT_MODE);
MikamiUitOpen 0:d3038879fed6 28
MikamiUitOpen 0:d3038879fed6 29 lcd_.SetBackColor(BACK_COLOR_); // recover back color
MikamiUitOpen 0:d3038879fed6 30 }
MikamiUitOpen 0:d3038879fed6 31 }
MikamiUitOpen 0:d3038879fed6 32
MikamiUitOpen 0:d3038879fed6 33 // Check touch detected
MikamiUitOpen 0:d3038879fed6 34 bool Button::Touched()
MikamiUitOpen 0:d3038879fed6 35 {
MikamiUitOpen 0:d3038879fed6 36 TS_StateTypeDef state;
MikamiUitOpen 0:d3038879fed6 37 ts_.GetState(&state);
MikamiUitOpen 0:d3038879fed6 38
MikamiUitOpen 0:d3038879fed6 39 if (state.touchDetected)
MikamiUitOpen 0:d3038879fed6 40 {
MikamiUitOpen 0:d3038879fed6 41 uint16_t x = state.touchX[0];
MikamiUitOpen 0:d3038879fed6 42 uint16_t y = state.touchY[0];
MikamiUitOpen 0:d3038879fed6 43
MikamiUitOpen 0:d3038879fed6 44 return ( (X_ <= x) && (x <= X_+W_) &&
MikamiUitOpen 0:d3038879fed6 45 (Y_ <= y) && (y <= Y_+H_) ) ? true : false;
MikamiUitOpen 0:d3038879fed6 46 }
MikamiUitOpen 0:d3038879fed6 47 else
MikamiUitOpen 0:d3038879fed6 48 return false;
MikamiUitOpen 0:d3038879fed6 49 }
MikamiUitOpen 0:d3038879fed6 50
MikamiUitOpen 0:d3038879fed6 51 // Check touch detected and redraw button
MikamiUitOpen 0:d3038879fed6 52 bool Button::Touched(uint32_t color, uint32_t textColor)
MikamiUitOpen 0:d3038879fed6 53 {
MikamiUitOpen 0:d3038879fed6 54 bool rtn = Touched();
MikamiUitOpen 0:d3038879fed6 55 if (rtn) Draw(color, textColor);
MikamiUitOpen 0:d3038879fed6 56 return rtn;
MikamiUitOpen 0:d3038879fed6 57 }
MikamiUitOpen 0:d3038879fed6 58 }