annotate UI code/UIElement.h @ 52:89944ab3e129 tip

fix oF linker errors ios8
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 03 Feb 2015 13:18:23 +0000
parents 2bd658b44c2d
children
rev   line source
rt300@0 1 //
rt300@0 2 // UIElement.h
rt300@0 3 // emptyExample
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 22/05/2013.
rt300@0 6 //
rt300@0 7 // literally just an area of the screen that is a ui element
rt300@0 8
rt300@0 9 #ifndef __emptyExample__UIElement__
rt300@0 10 #define __emptyExample__UIElement__
rt300@0 11 #include "ofMain.h"
rt300@0 12 #include "globalVariables.h"
rt300@0 13 #include <iostream>
rt300@0 14 #include <string>
rt300@0 15 #include "boost/function.hpp"
rt300@0 16 #include "UIProperties.h"
rt300@0 17
rt300@0 18 typedef boost::function<void(int, int)> UICallbackFunction;
rt300@0 19
rt300@0 20 class MessageOrganiser;
rt300@0 21
rt300@0 22 class UIElement{
rt300@0 23 public:
rt300@0 24
rt300@0 25
rt300@0 26 UICallbackFunction callback;
rt300@0 27
rt300@0 28 UIElement();
rt300@0 29 virtual ~UIElement(){};
rt300@12 30
rt300@12 31 UIElement(float ax,
rt300@12 32 float ay,
rt300@12 33 float awidth,
rt300@12 34 float aheight);
rt300@12 35
rt300@0 36 // recommended
rt300@0 37 UIElement(float ax,
rt300@0 38 float ay,
rt300@0 39 float awidth,
rt300@0 40 float aheight,
rt300@0 41 const UIProps& props);
rt300@0 42
rt300@0 43 UIElement(float ax,
rt300@0 44 float ay,
rt300@0 45 float awidth,
rt300@0 46 float aheight,
rt300@0 47 ofColor bg);
rt300@0 48
rt300@0 49 virtual void setLabel(string label){
rt300@0 50 labelName = label;
rt300@0 51 }
rt300@42 52 string getLabel(){
rt300@42 53 return labelName;
rt300@42 54 }
rt300@0 55 virtual void draw();
rt300@0 56 void hide(){
rt300@0 57 hidden = true;
rt300@0 58
rt300@0 59 };
rt300@0 60 void show(){
rt300@0 61 hidden = false;
rt300@0 62
rt300@0 63 };
rt300@25 64 bool isShowing(){
rt300@25 65 return !hidden;
rt300@25 66 }
rt300@0 67 bool touch(int x, int y, touchType ttype, int touchID);
rt300@0 68
rt300@0 69 virtual void addHandler(UICallbackFunction handlerFunction, int paramID) // virtual?
rt300@0 70 {
rt300@18 71 //cout << "handler added to UIElement " << endl;
rt300@0 72 callback = handlerFunction;
rt300@0 73 myParamID = paramID;
rt300@0 74 };
rt300@0 75
rt300@0 76 virtual void setValue(float value){
rt300@0 77 cout << "not valid to set value on this?" << endl;
rt300@0 78 };
rt300@0 79 virtual void setHintValue(float value){
rt300@0 80 cout << "not valid to set value on this?" << endl;
rt300@0 81 };
rt300@0 82 virtual void showHint(bool value){
rt300@0 83 cout << "not valid to set value on this?" << endl;
rt300@0 84 };
rt300@0 85 virtual void setHintColor(ofColor c){
rt300@0 86 cout << "not valid to set value on this?" << endl;
rt300@0 87 };
rt300@0 88 controllerType getType() const {
rt300@0 89 return myType;
rt300@0 90 }
rt300@0 91 float getWidth() const {return width;};
rt300@0 92 virtual void setHighlight(bool hion){
rt300@0 93 // ?
rt300@0 94 on = hion;
rt300@0 95 };
rt300@0 96 void setActive(bool isActive){
rt300@0 97 inactive = !isActive; // thats logic right?
rt300@0 98 }
rt300@0 99 void setX(float ax){
rt300@0 100 x = ax;
rt300@0 101 };
rt300@0 102 void setY(float ay){
rt300@0 103 y = ay;
rt300@0 104 };
rt300@14 105 void setColor(ofColor c){
rt300@14 106 background = c;
rt300@14 107 }
rt300@26 108 int getZLayer(){
rt300@26 109 return zLayer;
rt300@26 110
rt300@26 111 }
rt300@38 112 void setPosition(float ax, float ay){
rt300@38 113 x = ax;
rt300@38 114 y = ay;
rt300@38 115 }
rt300@38 116 void setXPosition(float ax){
rt300@38 117 x = ax;
rt300@38 118 }
rt300@26 119 void setZLayer(int z){
rt300@26 120 zLayer = z;
rt300@26 121 }
rt300@26 122 void bringToFrontOf(UIElement* e){
rt300@26 123
rt300@26 124 setZLayer(e->getZLayer() + 1);
rt300@26 125 }
rt300@28 126
rt300@28 127 virtual void update(){
rt300@28 128
rt300@28 129 }
rt300@42 130 void setOn(bool aon){
rt300@42 131 on = aon;
rt300@42 132 }
rt300@0 133 protected:
rt300@0 134
rt300@0 135 void init();
rt300@0 136
rt300@0 137 bool isExistingTouchID(int touchID){
rt300@0 138 // is id in list
rt300@0 139 std::list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID);
rt300@0 140 if (findIter == myTouchIDs.end()){
rt300@0 141 return false;
rt300@0 142 }else{
rt300@0 143 return true;
rt300@0 144 }
rt300@0 145 };
rt300@0 146
rt300@0 147 void addTouchID(int touchID){
rt300@0 148 //list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID);
rt300@0 149 //if(findIter == myTouchIDs.end()){ // checks for duplicates
rt300@0 150 myTouchIDs.insert(myTouchIDs.begin(), touchID);
rt300@0 151 //}
rt300@0 152 };
rt300@0 153 void removeTouchID(int touchID){
rt300@0 154 list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID);
rt300@0 155 if(findIter != myTouchIDs.end()){
rt300@0 156 myTouchIDs.erase(findIter);
rt300@0 157 }
rt300@0 158 };
rt300@0 159 static float sumWidth(float total, UIElement* element){
rt300@0 160 return total + element->getWidth();
rt300@0 161 }
rt300@0 162 bool isMyTouch(int x, int y, touchType ttype, int touchID);
rt300@0 163 bool touchIsInMyArea(int tx, int ty);
rt300@0 164 virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID) = 0; // subclass handles it
rt300@0 165
rt300@0 166 bool isCoordInMyRegion(double x, double y); // not used
rt300@41 167 bool atLeastOneTouchAlready();
rt300@26 168 int zLayer;
rt300@0 169
rt300@27 170 // protected members:
rt300@27 171
rt300@27 172 float x;
rt300@27 173 float y;
rt300@27 174 float width;
rt300@27 175 float height;
rt300@27 176 bool on;
rt300@27 177 int myParamID;
rt300@27 178 list<int> myTouchIDs;
rt300@27 179
rt300@27 180 ofColor background;
rt300@27 181
rt300@27 182 string labelName;
rt300@27 183 ofTrueTypeFont verdana16;
rt300@27 184 ofTrueTypeFont bigFont;
rt300@27 185 ofTrueTypeFont smallFont;
rt300@27 186 controllerType myType;
rt300@27 187
rt300@27 188 bool hidden; // don't draw dont touch
rt300@27 189 bool inactive; // dont touch, draw dimmed
rt300@27 190
rt300@41 191 bool onlyOneTouchAllowed;
rt300@0 192 };
rt300@0 193 #endif /* defined(__emptyExample__UIElement__) */