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@0: virtual void draw(); rt300@0: void hide(){ rt300@0: hidden = true; rt300@0: on = false; rt300@0: rt300@0: }; rt300@0: void show(){ rt300@0: hidden = false; rt300@0: on = true; rt300@0: rt300@0: }; 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@0: 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@0: protected: rt300@0: rt300@0: float x; rt300@0: float y; rt300@0: float width; rt300@0: float height; rt300@0: bool on; rt300@0: int myParamID; rt300@0: list myTouchIDs; rt300@0: rt300@0: ofColor background; rt300@0: rt300@0: string labelName; rt300@0: ofTrueTypeFont verdana16; rt300@0: ofTrueTypeFont bigFont; rt300@0: ofTrueTypeFont smallFont; rt300@0: controllerType myType; rt300@0: rt300@0: bool hidden; // don't draw dont touch rt300@0: bool inactive; // dont touch, draw dimmed 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@0: rt300@0: rt300@0: }; rt300@0: #endif /* defined(__emptyExample__UIElement__) */