diff UI code/ButtronSlider.mm @ 0:a223551fdc1f

First commit - copy from tweakathlon.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 10 Oct 2014 11:46:42 +0100
parents
children 5cf2b80909fc
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UI code/ButtronSlider.mm	Fri Oct 10 11:46:42 2014 +0100
@@ -0,0 +1,106 @@
+//
+//  ButtronSlider.cpp
+//  emptyExample
+//
+//  Created by Robert Tubb on 22/05/2013.
+//
+//
+
+#include "ButtronSlider.h"
+
+
+ButtronSlider::ButtronSlider(float ax,
+                             float ay,
+                             float awidth,
+                             float aheight,
+                             float athickness,
+                             float aradius,
+                             ofColor aforegroundHi,
+                             ofColor abackgroundHi,
+                             ofColor aforegroundLo,
+                             ofColor abackgroundLo,
+                             SliderType type) :
+Buttron(ax,ay,awidth,aheight,athickness,aradius,aforegroundHi,abackgroundHi,aforegroundLo,abackgroundLo),
+sliderType(type)
+
+{
+
+    init();
+}
+ButtronSlider::ButtronSlider(float ax,
+                             float ay,
+                             float awidth,
+                             float aheight,
+                             SliderType type,
+                             const UIProps& props) :
+Buttron(ax,ay,awidth,aheight,props),
+sliderType(type)
+
+{
+    init();
+}
+void  ButtronSlider::init(){
+    myType = SLIDER;
+    minVal = 0.;
+    maxVal = 127.;
+    value = 0.6;
+    hintShowing = false;
+}
+// 
+//---------------------------------------------------------------------
+void ButtronSlider::drawIndicator(double proportion){
+    if(on){
+        ofSetColor(foregroundHi);
+    }else{
+        ofSetColor(foregroundLo);
+        
+    }
+    if(inactive){
+        ofSetColor(fgInactive);
+    }
+    if(sliderType == FILL){
+
+        double maxH = height - 2 * thickness; //
+        double w = width - 2 * thickness;//
+        double barheight = value*maxH;
+        double top = y + height - thickness - barheight;
+        ofRect(x+thickness, top, w, barheight);
+        
+    }else if(sliderType == LINE){
+        double loc = y + thickness +  (1 -value)*(height-3*thickness);
+        ofRect(x+thickness,loc, width-2*thickness,thickness);
+    }
+    
+
+}
+
+void ButtronSlider::drawHintIndicator(){
+
+    ofSetColor(hintColor);
+    float hthick = 1;
+    double loc = y + hthick +  (1 - hintValue)*(height-3*hthick);
+    ofRect(x+thickness,loc, width-2*thickness,hthick);
+
+}
+
+//---------------------------------------------------------------------
+
+bool ButtronSlider::handleMyTouch(int tx, int ty, touchType ttype, int touchID){
+
+    double ly = ty - y - thickness - radius;
+    
+    double prop;
+    
+    prop = 1 - ly/(height - 2 * (thickness + radius));
+
+    if(prop > 1.) prop = 1.;                                                           
+    if(prop < 0.) prop = 0.;
+
+    setValue(prop);
+    int scaleVal = int((maxVal - minVal)*prop + minVal);
+
+    vector<int> pass;
+    if(callback) callback(myParamID,scaleVal);
+    
+    return true;
+}
\ No newline at end of file