rt300@0: // rt300@0: // button.cpp rt300@0: // Wablet rt300@0: // rt300@0: // Created by Robert Tubb on 19/03/2012. rt300@0: // Copyright (c) 2012 __MyCompanyName__. All rights reserved. rt300@0: // rt300@0: // button on screen either side of mesh rt300@0: #include rt300@0: #include "button.h" rt300@0: #include "globalUI.h" rt300@0: #include "globalForces.h" rt300@3: #include "scanpath.h" rt300@3: rt300@0: extern GlobalUI globalUI; rt300@0: extern GlobalForces globalForces; rt300@3: extern ScanPath scanPath; rt300@0: rt300@0: ControlButton::ControlButton(int abuttonId, int awidth,int aheight,int axpos,int aypos, string aname, Mesh *atheMeshPtr, ofColor acolor){ rt300@0: width = awidth; rt300@0: height = aheight; rt300@0: xpos = axpos; rt300@0: ypos = aypos; rt300@0: name = aname; rt300@0: bcolor = acolor; rt300@0: bcolor.setSaturation(150); rt300@0: bcolor.setBrightness(150); rt300@0: hicolor = acolor; rt300@0: hicolor.setSaturation(230); rt300@0: bcolor.setBrightness(230); rt300@0: buttonId = abuttonId; rt300@0: pressed = 0; rt300@0: theMesh = atheMeshPtr; rt300@0: rt300@0: //callingApp = atestApp; rt300@0: rt300@0: } rt300@0: rt300@0: void ControlButton::draw(){ rt300@0: //cout << "button draw " << hicolor.r << " \n"; rt300@0: if(pressed){ rt300@0: ofSetColor(hicolor); rt300@0: }else{ rt300@0: ofSetColor(bcolor); rt300@0: } rt300@0: rt300@0: ofRect(xpos,ypos,width,height); rt300@0: rt300@0: ofSetLineWidth(2); rt300@0: ofSetColor(hicolor); rt300@0: ofLine(xpos,ypos,xpos+width,ypos); rt300@0: ofLine(xpos,ypos,xpos,ypos+height); rt300@0: ofLine(xpos+width,ypos,xpos+width,ypos+height); rt300@0: ofLine(xpos,ypos+height,xpos+width,ypos+height); rt300@0: rt300@0: ofSetColor(0, 0, 0); rt300@0: ofDrawBitmapString(name, xpos+10, ypos+20); rt300@0: rt300@0: } rt300@0: rt300@0: bool ControlButton::checkTouchArea(int axpos,int aypos){ rt300@0: if ( (axpos > xpos) && (axpos < xpos+width) && (aypos > ypos) && (aypos < ypos+height)){ rt300@0: return true; rt300@0: }else{ rt300@0: return false; rt300@0: } rt300@0: rt300@0: } rt300@0: rt300@0: void ControlButton::press(){ rt300@0: cout << name << " button has been pressed\n"; rt300@0: rt300@0: if (name == "still"){ rt300@0: globalForces.homingAmt = 0.15; rt300@0: } rt300@0: rt300@0: if (name == "drift"){ rt300@0: theMesh->toggleSpringForces(false); rt300@0: } rt300@0: if (name == "tighter"){ rt300@0: theMesh->increasePropagationSpeed(); rt300@0: } rt300@0: if (name == "slacker"){ rt300@0: theMesh->decreasePropagationSpeed(); rt300@0: } rt300@0: rt300@0: if (name == "reset"){ rt300@0: theMesh->resetAll(); rt300@0: } rt300@0: if (name=="stickedge"){ rt300@0: theMesh->constrain(.0,.0,Mesh::CONSTRAIN_EDGES); rt300@0: } rt300@0: rt300@0: if (name == "free"){ rt300@0: theMesh->unconstrain(); rt300@0: } rt300@0: rt300@0: if (name == "drawscan"){ rt300@0: theMesh->resetPositions(); rt300@0: theMesh->resetVelocities(); rt300@0: globalUI.touchMode = globalUI.INSCRIBE_PATH; rt300@0: theMesh->clearScanPath(); rt300@0: theMesh->update(); rt300@0: } rt300@0: if (name == "deleteMesh"){ rt300@0: // cant rt300@0: } rt300@0: rt300@0: if (name == "force"){ rt300@0: globalUI.touchMode = globalUI.FORCE_FIELD; rt300@0: } rt300@0: if (name == "stick"){ rt300@0: globalUI.touchMode = globalUI.CONSTRAIN; rt300@0: } rt300@0: if (name == "unstick"){ rt300@0: globalUI.touchMode = globalUI.UNCONSTRAIN; rt300@0: } rt300@0: if (name == "free"){ rt300@0: // nothing rt300@0: //globalUI.touchMode = globalUI.UNCONSTRAIN; rt300@0: } rt300@0: if (name == "grab"){ rt300@0: globalUI.touchMode = globalUI.GRAB; rt300@0: } rt300@0: if (name == "smooth"){ rt300@0: globalForces.avFilterAmt = 0.11; rt300@0: } rt300@0: if (name == "harmonic"){ rt300@0: globalUI.touchMode = globalUI.SPATIAL_HARMONIC; rt300@0: } rt300@0: if (name == "gravity"){ rt300@0: globalForces.gravityAmt = 4.0; rt300@0: } rt300@0: if(name == "scanmode"){ rt300@3: scanPath.scanMode = scanPath.SPEED; rt300@0: } rt300@0: pressed = true; rt300@0: } rt300@0: rt300@0: void ControlButton::release(){ rt300@0: rt300@0: if (name == "homing"){ rt300@0: globalForces.homingAmt = 0.0; rt300@0: } rt300@0: if (name == "drift"){ rt300@0: theMesh->toggleSpringForces(true); rt300@0: } rt300@0: if (name == "smooth"){ rt300@0: globalForces.avFilterAmt = 0.02; rt300@0: } rt300@0: if (name == "gravity"){ rt300@0: globalForces.gravityAmt = 0.0; rt300@0: } rt300@0: if(name == "scanmode"){ rt300@3: scanPath.scanMode = scanPath.DISPLACEMENT; rt300@0: } rt300@0: if (name == "freeAll"){ rt300@0: theMesh->constrain(.0,.0,Mesh::CONSTRAIN_EDGES); rt300@0: } rt300@0: pressed = false; rt300@0: rt300@0: rt300@0: }