diff UI code/UIElement.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 af71bf84660f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UI code/UIElement.h	Fri Oct 10 11:46:42 2014 +0100
@@ -0,0 +1,151 @@
+//
+//  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(){};
+    // 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;
+    };
+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__) */