annotate 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
rev   line source
rt300@0 1 //
rt300@0 2 // buttron.cpp
rt300@0 3 // emptyExample
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 30/04/2013.
rt300@0 6 //
rt300@0 7 //
rt300@0 8
rt300@0 9 #include "buttron.h"
rt300@0 10
rt300@0 11 //------------------------------------------------------------------
rt300@0 12
rt300@0 13 Buttron::Buttron(){
rt300@0 14 //
rt300@0 15 //cout << " buttron default constructur\n";
rt300@0 16 }
rt300@0 17 //------------------------------------------------------------------
rt300@0 18 Buttron::Buttron(
rt300@38 19 float ax,
rt300@38 20 float ay,
rt300@38 21 float awidth,
rt300@38 22 float aheight,
rt300@38 23 float athickness,
rt300@38 24 float aradius,
rt300@38 25 ofColor aforegroundHi,
rt300@38 26 ofColor abackgroundHi,
rt300@38 27 ofColor aforegroundLo,
rt300@38 28 ofColor abackgroundLo) :
rt300@38 29 UIElement(ax,ay,awidth,aheight,abackgroundLo),
rt300@38 30 thickness(athickness),
rt300@38 31 radius(aradius),
rt300@38 32 foregroundHi(aforegroundHi),
rt300@38 33 backgroundHi(abackgroundHi),
rt300@38 34 foregroundLo(aforegroundLo),
rt300@38 35 backgroundLo(abackgroundLo) {
rt300@0 36 //cout << "phew, buttron big constructur\n";
rt300@38 37 behaviourMode = MOMENTARY;
rt300@0 38 on = false;
rt300@0 39 }
rt300@0 40 //------------------------------------------------------------------
rt300@0 41 Buttron::Buttron(float ax,
rt300@0 42 float ay,
rt300@0 43 const UIProps& props):
rt300@38 44 UIElement(ax,ay,props.buttonWidth,props.buttonHeight, props)
rt300@0 45
rt300@0 46 {
rt300@38 47
rt300@0 48 thickness = props.borderThickness;
rt300@0 49 radius = props.cornerRadius;
rt300@0 50 foregroundHi = props.buttonHi;
rt300@38 51 backgroundHi = props.backgroundHi;
rt300@0 52 foregroundLo = props.buttonLo;
rt300@0 53 backgroundLo = props.generalBackground;
rt300@38 54 behaviourMode = MOMENTARY;
rt300@0 55 on = false;
rt300@0 56 }
rt300@0 57 //------------------------------------------------------------------
rt300@0 58 Buttron::Buttron(float ax,
rt300@38 59 float ay,
rt300@38 60 float awidth,
rt300@38 61 float aheight,
rt300@38 62 const UIProps& props):
rt300@38 63 UIElement(ax,ay,awidth,aheight, props)
rt300@0 64
rt300@0 65 {
rt300@0 66 //cout << "slider (meh) recommended constructor\n";
rt300@0 67
rt300@0 68 thickness = props.borderThickness;
rt300@0 69 radius = props.cornerRadius;
rt300@0 70 foregroundHi = props.buttonHi;
rt300@38 71 backgroundHi = props.backgroundHi;
rt300@0 72 foregroundLo = props.buttonLo;
rt300@0 73 backgroundLo = props.generalBackground;
rt300@0 74 fgInactive = props.inactiveGreyedOut;
rt300@0 75
rt300@0 76 on = false;
rt300@38 77 behaviourMode = MOMENTARY;
rt300@0 78 }
rt300@0 79 //------------------------------------------------------------------
rt300@0 80 void Buttron::draw(){
rt300@0 81 if(hidden) return;
rt300@26 82
rt300@26 83 ofDisableDepthTest();
rt300@0 84 //cout << "drawing button" << endl;
rt300@0 85 ofFill();
rt300@0 86 UIElement::draw(); // should do background
rt300@0 87 drawOutline();
rt300@0 88 drawTextLabel();
rt300@26 89
rt300@26 90 ofEnableDepthTest();
rt300@0 91 }
rt300@0 92 //------------------------------------------------------------------
rt300@0 93 void Buttron::drawTextLabel(){
rt300@0 94 ofColor fg,bg;
rt300@0 95
rt300@0 96 if(on){
rt300@0 97 fg = foregroundHi;
rt300@0 98 bg = backgroundHi;
rt300@0 99 }else{
rt300@0 100 fg = foregroundLo;
rt300@0 101 bg = backgroundLo;
rt300@0 102 }
rt300@0 103 if(inactive){
rt300@0 104 fg = fgInactive;
rt300@0 105 }
rt300@0 106 ofSetColor(fg);
rt300@0 107 verdana16.drawString(labelName, x + thickness*2, y + 35);
rt300@0 108
rt300@26 109
rt300@0 110 }
rt300@0 111 //------------------------------------------------------------------
rt300@0 112 void Buttron::drawOutline(){
rt300@0 113
rt300@0 114 // draw bars
rt300@0 115 ofColor fg,bg;
rt300@0 116
rt300@0 117 if(on){
rt300@0 118 fg = foregroundHi;
rt300@0 119 bg = backgroundHi;
rt300@0 120 }else{
rt300@0 121 fg = foregroundLo;
rt300@0 122 bg = backgroundLo;
rt300@0 123 }
rt300@22 124 if(inactive){
rt300@22 125 ofSetColor(fgInactive);
rt300@22 126 }
rt300@0 127 ofSetColor(fg);
rt300@0 128
rt300@0 129 float cornerSize = thickness + radius;
rt300@0 130 // left
rt300@0 131 ofRect(x, y+cornerSize, thickness, height - 2*(cornerSize));
rt300@0 132 //right
rt300@0 133 ofRect(x + width - thickness, y+cornerSize, thickness, height - 2*(cornerSize));
rt300@0 134 // top
rt300@0 135 ofRect(x+cornerSize, y, width-2*(cornerSize), thickness);
rt300@0 136 // bottom
rt300@0 137 ofRect(x+cornerSize, y+height-thickness, width-2*(cornerSize), thickness);
rt300@0 138
rt300@0 139 // draw corner foreground circles
rt300@0 140
rt300@0 141 //tl
rt300@0 142 ofCircle(x+cornerSize, y+cornerSize, cornerSize);
rt300@38 143
rt300@0 144
rt300@0 145 //tr
rt300@38 146
rt300@0 147 ofCircle(x+width-cornerSize, y+cornerSize, cornerSize);
rt300@38 148
rt300@0 149 //bl
rt300@38 150
rt300@0 151 ofCircle(x+cornerSize, y+height-cornerSize, cornerSize);
rt300@38 152
rt300@0 153 //br
rt300@38 154
rt300@0 155 ofCircle(x+width-cornerSize, y+height-cornerSize, cornerSize);
rt300@38 156
rt300@0 157 // draw corner inner bg circles
rt300@0 158 ofSetColor(bg);
rt300@0 159 ofCircle(x+cornerSize, y+cornerSize, radius);
rt300@38 160
rt300@0 161 ofCircle(x+width-cornerSize, y+cornerSize, radius);
rt300@38 162
rt300@0 163 ofCircle(x+cornerSize, y+height-cornerSize, radius);
rt300@38 164
rt300@0 165 ofCircle(x+width-cornerSize, y+height-cornerSize, radius);
rt300@0 166
rt300@0 167 // fill in background
rt300@0 168 ofRect(x+cornerSize,y+thickness,width-2*cornerSize,height-2*thickness);
rt300@0 169 ofRect(x+thickness, y+cornerSize, radius, height-2*cornerSize);
rt300@0 170 ofRect(x+width-cornerSize, y+cornerSize, radius, height-2*cornerSize);
rt300@26 171
rt300@26 172
rt300@0 173 }
rt300@0 174 //------------------------------------------------------------------------------
rt300@0 175 bool Buttron::handleMyTouch(int tx, int ty, touchType ttype, int touchID){
rt300@0 176
rt300@0 177 //cout << "buttron handling touch\n";
rt300@38 178 if(behaviourMode == MOMENTARY){
rt300@38 179 if(ttype == TOUCH_DOWN){
rt300@38 180 on = true;
rt300@38 181 if(callback) callback(myParamID,1);
rt300@38 182
rt300@38 183 }else if(ttype == TOUCH_MOVED){
rt300@38 184
rt300@38 185 }else if(ttype == TOUCH_UP){
rt300@38 186 on = false;
rt300@38 187 }
rt300@0 188 }
rt300@38 189 if(behaviourMode == TOGGLE)
rt300@38 190 if(ttype == TOUCH_DOWN){
rt300@38 191 on = !on;
rt300@38 192 if(callback) callback(myParamID,1);
rt300@38 193 }
rt300@0 194 return true; // necessary?
rt300@0 195
rt300@0 196 }
rt300@0 197
rt300@0 198 //------------------------------------------------------------------------------