rt300@0: // rt300@0: // ButtronSlider.h rt300@0: // emptyExample rt300@0: // rt300@0: // Created by Robert Tubb on 22/05/2013. rt300@0: // rt300@0: // rt300@0: rt300@0: #ifndef __emptyExample__ButtronSlider__ rt300@0: #define __emptyExample__ButtronSlider__ rt300@0: #include "Buttron.h" rt300@0: #include rt300@0: rt300@0: class ButtronSlider : public Buttron{ rt300@0: public: rt300@0: rt300@0: ~ButtronSlider(){}; rt300@0: ButtronSlider(float ax, rt300@0: float ay, rt300@0: float awidth, rt300@0: float aheight, rt300@0: float athickness, rt300@0: float aradius, rt300@0: ofColor aforegroundHi, rt300@0: ofColor abackgroundHi, rt300@0: ofColor aforegroundLo, rt300@0: ofColor abackgroundLo, rt300@0: SliderType type); rt300@0: rt300@0: ButtronSlider(float ax, rt300@0: float ay, rt300@0: float awidth, rt300@0: float aheight, rt300@0: SliderType type, rt300@0: const UIProps& props); rt300@0: rt300@0: void init(); rt300@0: void draw(){ rt300@38: if(!isShowing()) return; rt300@0: Buttron::draw(); rt300@27: ofDisableDepthTest(); rt300@0: drawIndicator(value); rt300@0: if(hintShowing) drawHintIndicator(); rt300@37: rt300@27: ofEnableDepthTest(); rt300@0: } rt300@0: rt300@0: void setHintValue(double hval){ rt300@0: hintValue = (hval - minVal)/(maxVal - minVal); rt300@0: }; rt300@0: void setHintColor(ofColor c){ rt300@0: hintColor = c; rt300@0: }; rt300@22: void setColor(ofColor c){ rt300@22: foregroundHi = c; rt300@22: foregroundLo = c; rt300@22: } rt300@0: void showHint(bool tf){ rt300@0: hintShowing = tf; rt300@0: }; rt300@0: void setValue(double avalue){ rt300@0: // scale appropriately to 0-1 (maxVal - minVal)*prop + minVal rt300@0: value = avalue; // (avalue - minVal)/(maxVal - minVal); rt300@0: }; rt300@0: rt300@0: void setValueAndScale(double avalue){ rt300@0: // scale appropriately to 0-1 (maxVal - minVal)*prop + minVal rt300@0: value = (avalue - minVal)/(maxVal - minVal); rt300@38: if (value > 1.) value = 1.; rt300@38: if (value < 0.) value = 0.; rt300@0: }; rt300@27: void showValueIndicator(bool show){ rt300@27: indicatorShowing = show; rt300@27: } rt300@0: virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID); rt300@0: rt300@0: void setRange(float lo, float hi){ rt300@0: minVal = lo; rt300@0: maxVal = hi; rt300@0: } rt300@37: rt300@37: void setHandTexture(ofImage* img){ rt300@41: if(img != NULL){ rt300@41: handTextureRef = img; rt300@41: }else{ rt300@41: handTextureRef = &defaultImage; rt300@41: } rt300@37: rt300@37: } rt300@29: void animateHintToNewValue(int newVal, float timeToTake); rt300@31: void animateToNewValue(int newVal, float timeToTake); rt300@29: void update(); rt300@39: void flashScore(int score, ofColor col, int howLong); rt300@37: rt300@0: private: rt300@0: void drawIndicator(double proportion); rt300@0: float minVal; rt300@0: float maxVal; rt300@0: void drawHintIndicator(); rt300@0: SliderType sliderType; rt300@0: float value; // [0. 1.] rt300@0: float hintValue; rt300@31: rt300@31: float hintTargVal; rt300@31: float targVal; rt300@31: rt300@29: float posAnimIncr; rt300@47: float animFrac; rt300@31: float hintPosAnimIncr; rt300@0: bool hintShowing; rt300@27: bool indicatorShowing; rt300@0: ofColor hintColor; rt300@37: ofColor flashColor; rt300@29: bool animating; rt300@37: int showScoreForFrames; rt300@37: rt300@37: ofImage* handTextureRef; rt300@37: ofImage defaultImage; rt300@0: }; rt300@0: rt300@0: #endif /* defined(__emptyExample__ButtronSlider__) */