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