Same as original

Revision:
13:af578b53ff0e
Parent:
12:710078d50d9b
Child:
14:3076e383e6b0
diff -r 710078d50d9b -r af578b53ff0e button.cpp
--- a/button.cpp	Thu Feb 18 10:04:20 2016 +0000
+++ b/button.cpp	Mon Feb 22 13:39:32 2016 +0000
@@ -1,7 +1,8 @@
 //-----------------------------------------------------------
-//  Button class coping with multi-touch
+//  Button class handling multi-touch
+//      Multi-touch: Enabled (default)
 //
-//  2016/02/18, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/02/22, Copyright (c) 2016 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "button.hpp"
@@ -31,20 +32,9 @@
     // Check touch detected
     bool Button::Touched()
     {
-        bool rtn = false;
-        TS_StateTypeDef state;
-        ts_.GetState(&state);
-
-        for (int n=0; n<state.touchDetected; n++)
-        {
-            uint16_t x = state.touchX[n];
-            uint16_t y = state.touchY[n];
-
-            if ( (X_ <= x) && (x <= X_+W_) &&
-                 (Y_ <= y) && (y <= Y_+H_) ) rtn = true;
-            if (rtn) break;
-        }
-        return rtn;
+        ts_.GetState(&state_);
+        if (!state_.touchDetected) return false;
+        return IsOnButton();
     }
         
     // Check touch detected and redraw button
@@ -54,4 +44,29 @@
         if (rtn) Draw(color, textColor);
         return rtn;
     }
+    
+    // If panel touched, return true
+    bool Button::PanelTouched()
+    {
+        ts_.GetState(&state_);
+        return (bool)(state_.touchDetected);
+    }
+    
+    // If touched position is on the button, return true
+    bool Button::IsOnButton()
+    {
+        int nTouch = multiTouch ? state_.touchDetected : 1;
+        for (int n=0; n<nTouch; n++)
+        {
+            uint16_t x = state_.touchX[n];
+            uint16_t y = state_.touchY[n];
+
+            if ( (X_ <= x) && (x <= X_+W_) &&
+                 (Y_ <= y) && (y <= Y_+H_) ) return true;
+        }
+        return false;
+    }
+
+    TS_StateTypeDef Button::state_;
+    bool Button::multiTouch = true;
 }