Mercurial > hg > tweakathon2ios
diff UI code/ButtronXY.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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI code/ButtronXY.h Fri Oct 10 11:46:42 2014 +0100 @@ -0,0 +1,109 @@ +// +// ButtronXY.h +// tweakathlon +// +// Created by Robert Tubb on 25/06/2013. +// +// + +#ifndef __tweakathlon__ButtronXY__ +#define __tweakathlon__ButtronXY__ + +#include <iostream> +#include "buttron.h" + +class ButtronXY: public Buttron { + +public: + + UICallbackFunction callback; + + double xvalue, yvalue; // [0. 1.] + ~ButtronXY(){}; + ButtronXY(float ax, + float ay, + const UIProps& props); + ButtronXY(float ax, + float ay, + float awidth, + float athickness, + float aradius, + ofColor aforegroundHi, + ofColor abackgroundHi, + ofColor aforegroundLo, + ofColor abackgroundLo); + + void draw(){ + if(hidden) return; + Buttron::draw(); + drawIndicator(); + drawLabels(); + } + void drawLabels(){ + // where? + ofColor fg,bg; + + if(on){ + fg = foregroundHi; + bg = backgroundHi; + }else{ + fg = foregroundLo; + bg = backgroundLo; + } + ofSetColor(fg); + verdana16.drawString(labelNamex, x + width/2, y + thickness*4); + verdana16.drawString(labelNamey, x + thickness*2, y + height/2+7); + } + void init(); + + void setValue(double axvalue, double ayvalue){ + xvalue = axvalue; + yvalue = ayvalue; + }; + void setValueAndScale(double axvalue, double ayvalue){ + xvalue = (axvalue - minVal)/(maxVal - minVal); + yvalue = (ayvalue - minVal)/(maxVal - minVal); + } + void setHintValue(double hvalx, double hvaly){ + hintValuex = (hvalx - minVal)/(maxVal - minVal); + hintValuey = (hvaly - minVal)/(maxVal - minVal); + + }; + void setHintColor(ofColor c){ + // TODO somehow set the fill ? + }; + void setLabel(string xlabel, string ylabel){ + labelNamex = xlabel; + labelNamey = ylabel; + } + + + void showHint(bool tf){ + hintShowing = tf; + }; + virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID); + + virtual void addHandler(UICallbackFunction handlerFunction, int paramIDX, int paramIDY) // virtual? + { + cout << "handler added to XYUIElement " << endl; + callback = handlerFunction; + myParamIDX = paramIDX; + myParamIDY = paramIDY; + }; + + +private: + void drawIndicator(); + void drawHintIndicator(); + float maxVal; + float minVal; + int myParamIDX; + int myParamIDY; + float hintValuex; + float hintValuey; + bool hintShowing; + string labelNamex; + string labelNamey; +}; + +#endif /* defined(__tweakathlon__ButtronXY__) */