diff UI code/Buttron.mm @ 38:fea11c3d1d94

tweaking endlessly
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Thu, 04 Dec 2014 17:03:01 +0000
parents 8d7ae43b2edd
children d810aa9ca03a
line wrap: on
line diff
--- a/UI code/Buttron.mm	Wed Dec 03 11:38:26 2014 +0000
+++ b/UI code/Buttron.mm	Thu Dec 04 17:03:01 2014 +0000
@@ -16,50 +16,51 @@
 }
 //------------------------------------------------------------------
 Buttron::Buttron(
-        float ax,
-        float ay,
-        float awidth,
-        float aheight,
-        float athickness,
-        float aradius,
-        ofColor aforegroundHi,
-        ofColor abackgroundHi,
-        ofColor aforegroundLo,
-        ofColor abackgroundLo) :
-        UIElement(ax,ay,awidth,aheight,abackgroundLo),
-        thickness(athickness),
-        radius(aradius),
-        foregroundHi(aforegroundHi),
-        backgroundHi(abackgroundHi),
-        foregroundLo(aforegroundLo),
-        backgroundLo(abackgroundLo) {
+                 float ax,
+                 float ay,
+                 float awidth,
+                 float aheight,
+                 float athickness,
+                 float aradius,
+                 ofColor aforegroundHi,
+                 ofColor abackgroundHi,
+                 ofColor aforegroundLo,
+                 ofColor abackgroundLo) :
+UIElement(ax,ay,awidth,aheight,abackgroundLo),
+thickness(athickness),
+radius(aradius),
+foregroundHi(aforegroundHi),
+backgroundHi(abackgroundHi),
+foregroundLo(aforegroundLo),
+backgroundLo(abackgroundLo) {
     //cout << "phew, buttron big constructur\n";
+    behaviourMode = MOMENTARY;
     on = false;
 }
 //------------------------------------------------------------------
 Buttron::Buttron(float ax,
                  float ay,
                  const UIProps& props):
-        UIElement(ax,ay,props.buttonWidth,props.buttonHeight, props)
+UIElement(ax,ay,props.buttonWidth,props.buttonHeight, props)
 
 {
-
+    
     thickness = props.borderThickness;
     radius = props.cornerRadius;
     foregroundHi = props.buttonHi;
-    backgroundHi = props.generalBackground;
+    backgroundHi = props.backgroundHi;
     foregroundLo = props.buttonLo;
     backgroundLo = props.generalBackground;
-    
+    behaviourMode = MOMENTARY;
     on = false;
 }
 //------------------------------------------------------------------
 Buttron::Buttron(float ax,
-        float ay,
-        float awidth,
-        float aheight,
-        const UIProps& props):
-    UIElement(ax,ay,awidth,aheight, props)
+                 float ay,
+                 float awidth,
+                 float aheight,
+                 const UIProps& props):
+UIElement(ax,ay,awidth,aheight, props)
 
 {
     //cout << "slider (meh) recommended constructor\n";
@@ -67,12 +68,13 @@
     thickness = props.borderThickness;
     radius = props.cornerRadius;
     foregroundHi = props.buttonHi;
-    backgroundHi = props.generalBackground;
+    backgroundHi = props.backgroundHi;
     foregroundLo = props.buttonLo;
     backgroundLo = props.generalBackground;
     fgInactive = props.inactiveGreyedOut;
     
     on = false;
+    behaviourMode = MOMENTARY;
 }
 //------------------------------------------------------------------
 void Buttron::draw(){
@@ -138,28 +140,28 @@
     
     //tl
     ofCircle(x+cornerSize, y+cornerSize, cornerSize);
-
+    
     
     //tr
-
+    
     ofCircle(x+width-cornerSize, y+cornerSize, cornerSize);
-
+    
     //bl
-
+    
     ofCircle(x+cornerSize, y+height-cornerSize, cornerSize);
-
+    
     //br
-
+    
     ofCircle(x+width-cornerSize, y+height-cornerSize, cornerSize);
-
+    
     // draw corner inner bg circles
     ofSetColor(bg);
     ofCircle(x+cornerSize, y+cornerSize, radius);
-
+    
     ofCircle(x+width-cornerSize, y+cornerSize, radius);
-
+    
     ofCircle(x+cornerSize, y+height-cornerSize, radius);
-
+    
     ofCircle(x+width-cornerSize, y+height-cornerSize, radius);
     
     // fill in background
@@ -173,15 +175,22 @@
 bool Buttron::handleMyTouch(int tx, int ty, touchType ttype, int touchID){
     
     //cout << "buttron handling touch\n";
-    if(ttype == TOUCH_DOWN){
-        on = true;
-        if(callback) callback(myParamID,1);
-        
-    }else if(ttype == TOUCH_MOVED){
-        
-    }else if(ttype == TOUCH_UP){
-        on = false;
+    if(behaviourMode == MOMENTARY){
+        if(ttype == TOUCH_DOWN){
+            on = true;
+            if(callback) callback(myParamID,1);
+            
+        }else if(ttype == TOUCH_MOVED){
+            
+        }else if(ttype == TOUCH_UP){
+            on = false;
+        }
     }
+    if(behaviourMode == TOGGLE)
+        if(ttype == TOUCH_DOWN){
+            on = !on;
+            if(callback) callback(myParamID,1);
+        }
     return true; // necessary?
     
 }