Mercurial > hg > tweakathon2ios
view UI code/ButtronSlider.mm @ 52:89944ab3e129 tip
fix oF linker errors ios8
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Tue, 03 Feb 2015 13:18:23 +0000 |
parents | a62e033117fa |
children |
line wrap: on
line source
// // ButtronSlider.cpp // emptyExample // // Created by Robert Tubb on 22/05/2013. // // #include "ButtronSlider.h" ButtronSlider::ButtronSlider(float ax, float ay, float awidth, float aheight, float athickness, float aradius, ofColor aforegroundHi, ofColor abackgroundHi, ofColor aforegroundLo, ofColor abackgroundLo, SliderType type) : Buttron(ax,ay,awidth,aheight,athickness,aradius,aforegroundHi,abackgroundHi,aforegroundLo,abackgroundLo), sliderType(type) { init(); } ButtronSlider::ButtronSlider(float ax, float ay, float awidth, float aheight, SliderType type, const UIProps& props) : Buttron(ax,ay,awidth,aheight,props), sliderType(type) { init(); } void ButtronSlider::init(){ myType = SLIDER; minVal = 0.; maxVal = 127.; value = 0.6; hintShowing = false; string fname = ofFilePath::getAbsolutePath(ofToDataPath("buttron.png")); defaultImage.loadImage(fname); setHandTexture(&defaultImage); showScoreForFrames = 0; hintPosAnimIncr = 0; posAnimIncr = 0; onlyOneTouchAllowed = true; indicatorShowing = true; } // //--------------------------------------------------------------------- void ButtronSlider::drawIndicator(double proportion){ if(!indicatorShowing) return; if(on){ ofSetColor(foregroundHi); }else{ ofSetColor(foregroundLo); } if(inactive){ ofSetColor(fgInactive); } if(showScoreForFrames > 0){ ofSetColor(flashColor); showScoreForFrames--; } if(sliderType == FILL){ double maxH = height - 2 * thickness; // double w = width - 2 * thickness;// double barheight = value*maxH; double top = y + height - thickness - barheight; ofRect(x+thickness, top, w, barheight); }else if(sliderType == TEXTURE_FILL){ double maxH = height - 2 * thickness; // double w = width - 2 * thickness;// double barheight = value*maxH; double top = y + height - thickness - barheight; //ofRect(x+thickness, top, w, barheight); ofSetColor(255,255, 255); (*handTextureRef).draw(x+thickness, top, w, barheight); }else if(sliderType == LINE){ double loc = y + thickness + (1 -value)*(height-3*thickness); ofRect(x+thickness,loc, width-2*thickness,thickness); } } void ButtronSlider::drawHintIndicator(){ //ofSetColor(hintColor); float hthick = 16; double loc = y + thickness + (1 - hintValue)*(height-3*thickness); //ofRect(x-thickness,loc, width+2*thickness,hthick); ofSetColor(255, 255, 255); (*handTextureRef).draw(x+thickness,loc-hthick/2, width-4*thickness,hthick); } void ButtronSlider::animateHintToNewValue(int newVal, float timeToTake){ hintTargVal = (newVal - minVal)/(maxVal - minVal); float amtPerFrame = 1000./(ofGetFrameRate() * timeToTake); hintPosAnimIncr = (hintTargVal - hintValue )*amtPerFrame; animating = true; } void ButtronSlider::animateToNewValue(int newVal, float timeToTake){ targVal = (newVal - minVal)/(maxVal - minVal); float amtPerFrame = 1000./(ofGetFrameRate() * timeToTake); posAnimIncr = (targVal - value )*amtPerFrame; animFrac = pow( 0.05, 1000./(ofGetFrameRate() * timeToTake)); animating = true; } void ButtronSlider::update(){ if (!animating) return; float mov = (1-animFrac)*(targVal - value); value += mov; //hintValue += hintPosAnimIncr; // when we've hit the target stop. if (abs(targVal - value) < 0.01){ animating = false; } if (abs(hintTargVal - hintValue) < 0.01){ animating = false; } } //--------------------------------------------------------------------- bool ButtronSlider::handleMyTouch(int tx, int ty, touchType ttype, int touchID){ double ly = ty - y - thickness - radius; double prop; prop = 1 - ly/(height - 2 * (thickness + radius)); if(prop > 1.) prop = 1.; if(prop < 0.) prop = 0.; setValue(prop); int scaleVal = int((maxVal - minVal)*prop + minVal); vector<int> pass; if(callback) callback(myParamID,scaleVal); return true; } //-------------------------------------------------------------------- void ButtronSlider::flashScore(int score, ofColor col, int howLong){ showScoreForFrames = howLong; flashColor = col; }