annotate UI code/ButtronSlider.mm @ 13:ab3e0e980c82

Sequence conrtollrer FINALLY works.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 20 Oct 2014 19:36:39 +0100
parents a223551fdc1f
children 5cf2b80909fc
rev   line source
rt300@0 1 //
rt300@0 2 // ButtronSlider.cpp
rt300@0 3 // emptyExample
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 22/05/2013.
rt300@0 6 //
rt300@0 7 //
rt300@0 8
rt300@0 9 #include "ButtronSlider.h"
rt300@0 10
rt300@0 11
rt300@0 12 ButtronSlider::ButtronSlider(float ax,
rt300@0 13 float ay,
rt300@0 14 float awidth,
rt300@0 15 float aheight,
rt300@0 16 float athickness,
rt300@0 17 float aradius,
rt300@0 18 ofColor aforegroundHi,
rt300@0 19 ofColor abackgroundHi,
rt300@0 20 ofColor aforegroundLo,
rt300@0 21 ofColor abackgroundLo,
rt300@0 22 SliderType type) :
rt300@0 23 Buttron(ax,ay,awidth,aheight,athickness,aradius,aforegroundHi,abackgroundHi,aforegroundLo,abackgroundLo),
rt300@0 24 sliderType(type)
rt300@0 25
rt300@0 26 {
rt300@0 27
rt300@0 28 init();
rt300@0 29 }
rt300@0 30 ButtronSlider::ButtronSlider(float ax,
rt300@0 31 float ay,
rt300@0 32 float awidth,
rt300@0 33 float aheight,
rt300@0 34 SliderType type,
rt300@0 35 const UIProps& props) :
rt300@0 36 Buttron(ax,ay,awidth,aheight,props),
rt300@0 37 sliderType(type)
rt300@0 38
rt300@0 39 {
rt300@0 40 init();
rt300@0 41 }
rt300@0 42 void ButtronSlider::init(){
rt300@0 43 myType = SLIDER;
rt300@0 44 minVal = 0.;
rt300@0 45 maxVal = 127.;
rt300@0 46 value = 0.6;
rt300@0 47 hintShowing = false;
rt300@0 48 }
rt300@0 49 //
rt300@0 50 //---------------------------------------------------------------------
rt300@0 51 void ButtronSlider::drawIndicator(double proportion){
rt300@0 52 if(on){
rt300@0 53 ofSetColor(foregroundHi);
rt300@0 54 }else{
rt300@0 55 ofSetColor(foregroundLo);
rt300@0 56
rt300@0 57 }
rt300@0 58 if(inactive){
rt300@0 59 ofSetColor(fgInactive);
rt300@0 60 }
rt300@0 61 if(sliderType == FILL){
rt300@0 62
rt300@0 63 double maxH = height - 2 * thickness; //
rt300@0 64 double w = width - 2 * thickness;//
rt300@0 65 double barheight = value*maxH;
rt300@0 66 double top = y + height - thickness - barheight;
rt300@0 67 ofRect(x+thickness, top, w, barheight);
rt300@0 68
rt300@0 69 }else if(sliderType == LINE){
rt300@0 70 double loc = y + thickness + (1 -value)*(height-3*thickness);
rt300@0 71 ofRect(x+thickness,loc, width-2*thickness,thickness);
rt300@0 72 }
rt300@0 73
rt300@0 74
rt300@0 75 }
rt300@0 76
rt300@0 77 void ButtronSlider::drawHintIndicator(){
rt300@0 78
rt300@0 79 ofSetColor(hintColor);
rt300@0 80 float hthick = 1;
rt300@0 81 double loc = y + hthick + (1 - hintValue)*(height-3*hthick);
rt300@0 82 ofRect(x+thickness,loc, width-2*thickness,hthick);
rt300@0 83
rt300@0 84 }
rt300@0 85
rt300@0 86 //---------------------------------------------------------------------
rt300@0 87
rt300@0 88 bool ButtronSlider::handleMyTouch(int tx, int ty, touchType ttype, int touchID){
rt300@0 89
rt300@0 90 double ly = ty - y - thickness - radius;
rt300@0 91
rt300@0 92 double prop;
rt300@0 93
rt300@0 94 prop = 1 - ly/(height - 2 * (thickness + radius));
rt300@0 95
rt300@0 96 if(prop > 1.) prop = 1.;
rt300@0 97 if(prop < 0.) prop = 0.;
rt300@0 98
rt300@0 99 setValue(prop);
rt300@0 100 int scaleVal = int((maxVal - minVal)*prop + minVal);
rt300@0 101
rt300@0 102 vector<int> pass;
rt300@0 103 if(callback) callback(myParamID,scaleVal);
rt300@0 104
rt300@0 105 return true;
rt300@0 106 }