rt300@0: // rt300@0: // UIElement.h rt300@0: // emptyExample rt300@0: // rt300@0: // Created by Robert Tubb on 22/05/2013. rt300@0: // rt300@0: // literally just an area of the screen that is a ui element rt300@0: rt300@0: #ifndef __emptyExample__UIElement__ rt300@0: #define __emptyExample__UIElement__ rt300@0: #include "ofMain.h" rt300@0: #include "globalVariables.h" rt300@0: #include rt300@0: #include rt300@0: #include "boost/function.hpp" rt300@0: #include "UIProperties.h" rt300@0: rt300@0: typedef boost::function UICallbackFunction; rt300@0: rt300@0: class MessageOrganiser; rt300@0: rt300@0: class UIElement{ rt300@0: public: rt300@0: rt300@0: rt300@0: UICallbackFunction callback; rt300@0: rt300@0: UIElement(); rt300@0: virtual ~UIElement(){}; rt300@12: rt300@12: UIElement(float ax, rt300@12: float ay, rt300@12: float awidth, rt300@12: float aheight); rt300@12: rt300@0: // recommended rt300@0: UIElement(float ax, rt300@0: float ay, rt300@0: float awidth, rt300@0: float aheight, rt300@0: const UIProps& props); rt300@0: rt300@0: UIElement(float ax, rt300@0: float ay, rt300@0: float awidth, rt300@0: float aheight, rt300@0: ofColor bg); rt300@0: rt300@0: virtual void setLabel(string label){ rt300@0: labelName = label; rt300@0: } rt300@42: string getLabel(){ rt300@42: return labelName; rt300@42: } rt300@0: virtual void draw(); rt300@0: void hide(){ rt300@0: hidden = true; rt300@0: rt300@0: }; rt300@0: void show(){ rt300@0: hidden = false; rt300@0: rt300@0: }; rt300@25: bool isShowing(){ rt300@25: return !hidden; rt300@25: } rt300@0: bool touch(int x, int y, touchType ttype, int touchID); rt300@0: rt300@0: virtual void addHandler(UICallbackFunction handlerFunction, int paramID) // virtual? rt300@0: { rt300@18: //cout << "handler added to UIElement " << endl; rt300@0: callback = handlerFunction; rt300@0: myParamID = paramID; rt300@0: }; rt300@0: rt300@0: virtual void setValue(float value){ rt300@0: cout << "not valid to set value on this?" << endl; rt300@0: }; rt300@0: virtual void setHintValue(float value){ rt300@0: cout << "not valid to set value on this?" << endl; rt300@0: }; rt300@0: virtual void showHint(bool value){ rt300@0: cout << "not valid to set value on this?" << endl; rt300@0: }; rt300@0: virtual void setHintColor(ofColor c){ rt300@0: cout << "not valid to set value on this?" << endl; rt300@0: }; rt300@0: controllerType getType() const { rt300@0: return myType; rt300@0: } rt300@0: float getWidth() const {return width;}; rt300@0: virtual void setHighlight(bool hion){ rt300@0: // ? rt300@0: on = hion; rt300@0: }; rt300@0: void setActive(bool isActive){ rt300@0: inactive = !isActive; // thats logic right? rt300@0: } rt300@0: void setX(float ax){ rt300@0: x = ax; rt300@0: }; rt300@0: void setY(float ay){ rt300@0: y = ay; rt300@0: }; rt300@14: void setColor(ofColor c){ rt300@14: background = c; rt300@14: } rt300@26: int getZLayer(){ rt300@26: return zLayer; rt300@26: rt300@26: } rt300@38: void setPosition(float ax, float ay){ rt300@38: x = ax; rt300@38: y = ay; rt300@38: } rt300@38: void setXPosition(float ax){ rt300@38: x = ax; rt300@38: } rt300@26: void setZLayer(int z){ rt300@26: zLayer = z; rt300@26: } rt300@26: void bringToFrontOf(UIElement* e){ rt300@26: rt300@26: setZLayer(e->getZLayer() + 1); rt300@26: } rt300@28: rt300@28: virtual void update(){ rt300@28: rt300@28: } rt300@42: void setOn(bool aon){ rt300@42: on = aon; rt300@42: } rt300@0: protected: rt300@0: rt300@0: void init(); rt300@0: rt300@0: bool isExistingTouchID(int touchID){ rt300@0: // is id in list rt300@0: std::list::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID); rt300@0: if (findIter == myTouchIDs.end()){ rt300@0: return false; rt300@0: }else{ rt300@0: return true; rt300@0: } rt300@0: }; rt300@0: rt300@0: void addTouchID(int touchID){ rt300@0: //list::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID); rt300@0: //if(findIter == myTouchIDs.end()){ // checks for duplicates rt300@0: myTouchIDs.insert(myTouchIDs.begin(), touchID); rt300@0: //} rt300@0: }; rt300@0: void removeTouchID(int touchID){ rt300@0: list::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID); rt300@0: if(findIter != myTouchIDs.end()){ rt300@0: myTouchIDs.erase(findIter); rt300@0: } rt300@0: }; rt300@0: static float sumWidth(float total, UIElement* element){ rt300@0: return total + element->getWidth(); rt300@0: } rt300@0: bool isMyTouch(int x, int y, touchType ttype, int touchID); rt300@0: bool touchIsInMyArea(int tx, int ty); rt300@0: virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID) = 0; // subclass handles it rt300@0: rt300@0: bool isCoordInMyRegion(double x, double y); // not used rt300@41: bool atLeastOneTouchAlready(); rt300@26: int zLayer; rt300@0: rt300@27: // protected members: rt300@27: rt300@27: float x; rt300@27: float y; rt300@27: float width; rt300@27: float height; rt300@27: bool on; rt300@27: int myParamID; rt300@27: list myTouchIDs; rt300@27: rt300@27: ofColor background; rt300@27: rt300@27: string labelName; rt300@27: ofTrueTypeFont verdana16; rt300@27: ofTrueTypeFont bigFont; rt300@27: ofTrueTypeFont smallFont; rt300@27: controllerType myType; rt300@27: rt300@27: bool hidden; // don't draw dont touch rt300@27: bool inactive; // dont touch, draw dimmed rt300@27: rt300@41: bool onlyOneTouchAllowed; rt300@0: }; rt300@0: #endif /* defined(__emptyExample__UIElement__) */