Class library: Button class and ButtonGroup class for DISCO-F746NG. クラスライブラリ: DISCO-F746NG 用の,Button クラス,ButtonGroup クラス.

Dependents:   F746_SpectralAnalysis_NoPhoto F746_Fourier_series_of_square_wave_01 F746_ButtonGroup_Demo F746_Mandelbrot ... more

Revision:
0:d3038879fed6
Child:
1:57fe493e8db2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/button.cpp	Sun Nov 22 10:07:55 2015 +0000
@@ -0,0 +1,58 @@
+//-----------------------------------------------------------
+//  Button class
+//
+//  2015/11/22, 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;
+    }
+}