Mercurial > hg > tweakathon2ios
view UI code/UIElement.h @ 22:8124f46eda65
pretty much working.
ugly though.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Thu, 23 Oct 2014 18:15:46 +0100 |
parents | 36cdb73691da |
children | 8eb530e0601b |
line wrap: on
line source
// // UIElement.h // emptyExample // // Created by Robert Tubb on 22/05/2013. // // literally just an area of the screen that is a ui element #ifndef __emptyExample__UIElement__ #define __emptyExample__UIElement__ #include "ofMain.h" #include "globalVariables.h" #include <iostream> #include <string> #include "boost/function.hpp" #include "UIProperties.h" typedef boost::function<void(int, int)> UICallbackFunction; class MessageOrganiser; class UIElement{ public: UICallbackFunction callback; UIElement(); virtual ~UIElement(){}; UIElement(float ax, float ay, float awidth, float aheight); // recommended UIElement(float ax, float ay, float awidth, float aheight, const UIProps& props); UIElement(float ax, float ay, float awidth, float aheight, ofColor bg); virtual void setLabel(string label){ labelName = label; } virtual void draw(); void hide(){ hidden = true; on = false; }; void show(){ hidden = false; on = true; }; bool touch(int x, int y, touchType ttype, int touchID); virtual void addHandler(UICallbackFunction handlerFunction, int paramID) // virtual? { //cout << "handler added to UIElement " << endl; callback = handlerFunction; myParamID = paramID; }; virtual void setValue(float value){ cout << "not valid to set value on this?" << endl; }; virtual void setHintValue(float value){ cout << "not valid to set value on this?" << endl; }; virtual void showHint(bool value){ cout << "not valid to set value on this?" << endl; }; virtual void setHintColor(ofColor c){ cout << "not valid to set value on this?" << endl; }; controllerType getType() const { return myType; } float getWidth() const {return width;}; virtual void setHighlight(bool hion){ // ? on = hion; }; void setActive(bool isActive){ inactive = !isActive; // thats logic right? } void setX(float ax){ x = ax; }; void setY(float ay){ y = ay; }; void setColor(ofColor c){ background = c; } protected: float x; float y; float width; float height; bool on; int myParamID; list<int> myTouchIDs; ofColor background; string labelName; ofTrueTypeFont verdana16; ofTrueTypeFont bigFont; ofTrueTypeFont smallFont; controllerType myType; bool hidden; // don't draw dont touch bool inactive; // dont touch, draw dimmed void init(); bool isExistingTouchID(int touchID){ // is id in list std::list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID); if (findIter == myTouchIDs.end()){ return false; }else{ return true; } }; void addTouchID(int touchID){ //list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID); //if(findIter == myTouchIDs.end()){ // checks for duplicates myTouchIDs.insert(myTouchIDs.begin(), touchID); //} }; void removeTouchID(int touchID){ list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID); if(findIter != myTouchIDs.end()){ myTouchIDs.erase(findIter); } }; static float sumWidth(float total, UIElement* element){ return total + element->getWidth(); } bool isMyTouch(int x, int y, touchType ttype, int touchID); bool touchIsInMyArea(int tx, int ty); virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID) = 0; // subclass handles it bool isCoordInMyRegion(double x, double y); // not used }; #endif /* defined(__emptyExample__UIElement__) */