Mercurial > hg > tweakathon2ios
diff UI code/ButtronSlider.h @ 0:a223551fdc1f
First commit - copy from tweakathlon.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 10 Oct 2014 11:46:42 +0100 |
parents | |
children | 8124f46eda65 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI code/ButtronSlider.h Fri Oct 10 11:46:42 2014 +0100 @@ -0,0 +1,82 @@ +// +// ButtronSlider.h +// emptyExample +// +// Created by Robert Tubb on 22/05/2013. +// +// + +#ifndef __emptyExample__ButtronSlider__ +#define __emptyExample__ButtronSlider__ +#include "Buttron.h" +#include <iostream> + +class ButtronSlider : public Buttron{ +public: + + ~ButtronSlider(){}; + ButtronSlider(float ax, + float ay, + float awidth, + float aheight, + float athickness, + float aradius, + ofColor aforegroundHi, + ofColor abackgroundHi, + ofColor aforegroundLo, + ofColor abackgroundLo, + SliderType type); + + ButtronSlider(float ax, + float ay, + float awidth, + float aheight, + SliderType type, + const UIProps& props); + + void init(); + void draw(){ + Buttron::draw(); + drawIndicator(value); + if(hintShowing) drawHintIndicator(); + } + + void setHintValue(double hval){ + hintValue = (hval - minVal)/(maxVal - minVal); + }; + void setHintColor(ofColor c){ + hintColor = c; + }; + void showHint(bool tf){ + hintShowing = tf; + }; + void setValue(double avalue){ + // scale appropriately to 0-1 (maxVal - minVal)*prop + minVal + value = avalue; // (avalue - minVal)/(maxVal - minVal); + }; + + void setValueAndScale(double avalue){ + // scale appropriately to 0-1 (maxVal - minVal)*prop + minVal + value = (avalue - minVal)/(maxVal - minVal); + }; + + virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID); + + void setRange(float lo, float hi){ + minVal = lo; + maxVal = hi; + } + +private: + void drawIndicator(double proportion); + float minVal; + float maxVal; + void drawHintIndicator(); + SliderType sliderType; + float value; // [0. 1.] + float hintValue; + bool hintShowing; + ofColor hintColor; +}; + +#endif /* defined(__emptyExample__ButtronSlider__) */