annotate button.mm @ 15:d5758530a039 tip

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