annotate button.mm @ 0:c667dfe12d47

OK. Ther real deal.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 19 Nov 2012 13:00:42 +0000
parents
children d346ddc50f70
rev   line source
rt300@0 1 //
rt300@0 2 // button.cpp
rt300@0 3 // Wablet
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 19/03/2012.
rt300@0 6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
rt300@0 7 //
rt300@0 8 // button on screen either side of mesh
rt300@0 9 #include <iostream>
rt300@0 10 #include "button.h"
rt300@0 11 #include "globalUI.h"
rt300@0 12 #include "globalForces.h"
rt300@0 13 extern GlobalUI globalUI;
rt300@0 14 extern GlobalForces globalForces;
rt300@0 15
rt300@0 16 ControlButton::ControlButton(int abuttonId, int awidth,int aheight,int axpos,int aypos, string aname, Mesh *atheMeshPtr, ofColor acolor){
rt300@0 17 width = awidth;
rt300@0 18 height = aheight;
rt300@0 19 xpos = axpos;
rt300@0 20 ypos = aypos;
rt300@0 21 name = aname;
rt300@0 22 bcolor = acolor;
rt300@0 23 bcolor.setSaturation(150);
rt300@0 24 bcolor.setBrightness(150);
rt300@0 25 hicolor = acolor;
rt300@0 26 hicolor.setSaturation(230);
rt300@0 27 bcolor.setBrightness(230);
rt300@0 28 buttonId = abuttonId;
rt300@0 29 pressed = 0;
rt300@0 30 theMesh = atheMeshPtr;
rt300@0 31
rt300@0 32 //callingApp = atestApp;
rt300@0 33
rt300@0 34 }
rt300@0 35
rt300@0 36 void ControlButton::draw(){
rt300@0 37 //cout << "button draw " << hicolor.r << " \n";
rt300@0 38 if(pressed){
rt300@0 39 ofSetColor(hicolor);
rt300@0 40 }else{
rt300@0 41 ofSetColor(bcolor);
rt300@0 42 }
rt300@0 43
rt300@0 44 ofRect(xpos,ypos,width,height);
rt300@0 45
rt300@0 46 ofSetLineWidth(2);
rt300@0 47 ofSetColor(hicolor);
rt300@0 48 ofLine(xpos,ypos,xpos+width,ypos);
rt300@0 49 ofLine(xpos,ypos,xpos,ypos+height);
rt300@0 50 ofLine(xpos+width,ypos,xpos+width,ypos+height);
rt300@0 51 ofLine(xpos,ypos+height,xpos+width,ypos+height);
rt300@0 52
rt300@0 53 ofSetColor(0, 0, 0);
rt300@0 54 ofDrawBitmapString(name, xpos+10, ypos+20);
rt300@0 55
rt300@0 56 }
rt300@0 57
rt300@0 58 bool ControlButton::checkTouchArea(int axpos,int aypos){
rt300@0 59 if ( (axpos > xpos) && (axpos < xpos+width) && (aypos > ypos) && (aypos < ypos+height)){
rt300@0 60 return true;
rt300@0 61 }else{
rt300@0 62 return false;
rt300@0 63 }
rt300@0 64
rt300@0 65 }
rt300@0 66
rt300@0 67 void ControlButton::press(){
rt300@0 68 cout << name << " button has been pressed\n";
rt300@0 69
rt300@0 70 if (name == "still"){
rt300@0 71 globalForces.homingAmt = 0.15;
rt300@0 72 }
rt300@0 73
rt300@0 74 if (name == "drift"){
rt300@0 75 theMesh->toggleSpringForces(false);
rt300@0 76 }
rt300@0 77 if (name == "tighter"){
rt300@0 78 theMesh->increasePropagationSpeed();
rt300@0 79 }
rt300@0 80 if (name == "slacker"){
rt300@0 81 theMesh->decreasePropagationSpeed();
rt300@0 82 }
rt300@0 83
rt300@0 84 if (name == "reset"){
rt300@0 85 theMesh->resetAll();
rt300@0 86 }
rt300@0 87 if (name=="stickedge"){
rt300@0 88 theMesh->constrain(.0,.0,Mesh::CONSTRAIN_EDGES);
rt300@0 89 }
rt300@0 90
rt300@0 91 if (name == "free"){
rt300@0 92 theMesh->unconstrain();
rt300@0 93 }
rt300@0 94
rt300@0 95 if (name == "drawscan"){
rt300@0 96 theMesh->resetPositions();
rt300@0 97 theMesh->resetVelocities();
rt300@0 98 globalUI.touchMode = globalUI.INSCRIBE_PATH;
rt300@0 99 theMesh->clearScanPath();
rt300@0 100 theMesh->update();
rt300@0 101 }
rt300@0 102 if (name == "deleteMesh"){
rt300@0 103 // cant
rt300@0 104 }
rt300@0 105
rt300@0 106 if (name == "force"){
rt300@0 107 globalUI.touchMode = globalUI.FORCE_FIELD;
rt300@0 108 }
rt300@0 109 if (name == "stick"){
rt300@0 110 globalUI.touchMode = globalUI.CONSTRAIN;
rt300@0 111 }
rt300@0 112 if (name == "unstick"){
rt300@0 113 globalUI.touchMode = globalUI.UNCONSTRAIN;
rt300@0 114 }
rt300@0 115 if (name == "free"){
rt300@0 116 // nothing
rt300@0 117 //globalUI.touchMode = globalUI.UNCONSTRAIN;
rt300@0 118 }
rt300@0 119 if (name == "grab"){
rt300@0 120 globalUI.touchMode = globalUI.GRAB;
rt300@0 121 }
rt300@0 122 if (name == "smooth"){
rt300@0 123 globalForces.avFilterAmt = 0.11;
rt300@0 124 }
rt300@0 125 if (name == "harmonic"){
rt300@0 126 globalUI.touchMode = globalUI.SPATIAL_HARMONIC;
rt300@0 127 }
rt300@0 128 if (name == "gravity"){
rt300@0 129 globalForces.gravityAmt = 4.0;
rt300@0 130 }
rt300@0 131 if(name == "scanmode"){
rt300@0 132 theMesh->scanPath->scanMode = theMesh->scanPath->SPEED;
rt300@0 133 }
rt300@0 134 pressed = true;
rt300@0 135 }
rt300@0 136
rt300@0 137 void ControlButton::release(){
rt300@0 138
rt300@0 139 if (name == "homing"){
rt300@0 140 globalForces.homingAmt = 0.0;
rt300@0 141 }
rt300@0 142 if (name == "drift"){
rt300@0 143 theMesh->toggleSpringForces(true);
rt300@0 144 }
rt300@0 145 if (name == "smooth"){
rt300@0 146 globalForces.avFilterAmt = 0.02;
rt300@0 147 }
rt300@0 148 if (name == "gravity"){
rt300@0 149 globalForces.gravityAmt = 0.0;
rt300@0 150 }
rt300@0 151 if(name == "scanmode"){
rt300@0 152 theMesh->scanPath->scanMode = theMesh->scanPath->DISPLACEMENT;
rt300@0 153 }
rt300@0 154 if (name == "freeAll"){
rt300@0 155 theMesh->constrain(.0,.0,Mesh::CONSTRAIN_EDGES);
rt300@0 156 }
rt300@0 157 pressed = false;
rt300@0 158
rt300@0 159
rt300@0 160 }