Mercurial > hg > tweakathon2ios
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a223551fdc1f |
---|---|
1 // | |
2 // UIElement.h | |
3 // emptyExample | |
4 // | |
5 // Created by Robert Tubb on 22/05/2013. | |
6 // | |
7 // literally just an area of the screen that is a ui element | |
8 | |
9 #ifndef __emptyExample__UIElement__ | |
10 #define __emptyExample__UIElement__ | |
11 #include "ofMain.h" | |
12 #include "globalVariables.h" | |
13 #include <iostream> | |
14 #include <string> | |
15 #include "boost/function.hpp" | |
16 #include "UIProperties.h" | |
17 | |
18 typedef boost::function<void(int, int)> UICallbackFunction; | |
19 | |
20 class MessageOrganiser; | |
21 | |
22 class UIElement{ | |
23 public: | |
24 | |
25 | |
26 UICallbackFunction callback; | |
27 | |
28 UIElement(); | |
29 virtual ~UIElement(){}; | |
30 // recommended | |
31 UIElement(float ax, | |
32 float ay, | |
33 float awidth, | |
34 float aheight, | |
35 const UIProps& props); | |
36 | |
37 UIElement(float ax, | |
38 float ay, | |
39 float awidth, | |
40 float aheight, | |
41 ofColor bg); | |
42 | |
43 virtual void setLabel(string label){ | |
44 labelName = label; | |
45 } | |
46 virtual void draw(); | |
47 void hide(){ | |
48 hidden = true; | |
49 on = false; | |
50 | |
51 }; | |
52 void show(){ | |
53 hidden = false; | |
54 on = true; | |
55 | |
56 }; | |
57 bool touch(int x, int y, touchType ttype, int touchID); | |
58 | |
59 virtual void addHandler(UICallbackFunction handlerFunction, int paramID) // virtual? | |
60 { | |
61 cout << "handler added to UIElement " << endl; | |
62 callback = handlerFunction; | |
63 myParamID = paramID; | |
64 }; | |
65 | |
66 virtual void setValue(float value){ | |
67 cout << "not valid to set value on this?" << endl; | |
68 }; | |
69 virtual void setHintValue(float value){ | |
70 cout << "not valid to set value on this?" << endl; | |
71 }; | |
72 virtual void showHint(bool value){ | |
73 cout << "not valid to set value on this?" << endl; | |
74 }; | |
75 virtual void setHintColor(ofColor c){ | |
76 cout << "not valid to set value on this?" << endl; | |
77 }; | |
78 controllerType getType() const { | |
79 return myType; | |
80 } | |
81 float getWidth() const {return width;}; | |
82 virtual void setHighlight(bool hion){ | |
83 // ? | |
84 on = hion; | |
85 }; | |
86 void setActive(bool isActive){ | |
87 inactive = !isActive; // thats logic right? | |
88 } | |
89 void setX(float ax){ | |
90 x = ax; | |
91 }; | |
92 void setY(float ay){ | |
93 y = ay; | |
94 }; | |
95 protected: | |
96 | |
97 float x; | |
98 float y; | |
99 float width; | |
100 float height; | |
101 bool on; | |
102 int myParamID; | |
103 list<int> myTouchIDs; | |
104 | |
105 ofColor background; | |
106 | |
107 string labelName; | |
108 ofTrueTypeFont verdana16; | |
109 ofTrueTypeFont bigFont; | |
110 ofTrueTypeFont smallFont; | |
111 controllerType myType; | |
112 | |
113 bool hidden; // don't draw dont touch | |
114 bool inactive; // dont touch, draw dimmed | |
115 | |
116 void init(); | |
117 | |
118 bool isExistingTouchID(int touchID){ | |
119 // is id in list | |
120 std::list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID); | |
121 if (findIter == myTouchIDs.end()){ | |
122 return false; | |
123 }else{ | |
124 return true; | |
125 } | |
126 }; | |
127 | |
128 void addTouchID(int touchID){ | |
129 //list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID); | |
130 //if(findIter == myTouchIDs.end()){ // checks for duplicates | |
131 myTouchIDs.insert(myTouchIDs.begin(), touchID); | |
132 //} | |
133 }; | |
134 void removeTouchID(int touchID){ | |
135 list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID); | |
136 if(findIter != myTouchIDs.end()){ | |
137 myTouchIDs.erase(findIter); | |
138 } | |
139 }; | |
140 static float sumWidth(float total, UIElement* element){ | |
141 return total + element->getWidth(); | |
142 } | |
143 bool isMyTouch(int x, int y, touchType ttype, int touchID); | |
144 bool touchIsInMyArea(int tx, int ty); | |
145 virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID) = 0; // subclass handles it | |
146 | |
147 bool isCoordInMyRegion(double x, double y); // not used | |
148 | |
149 | |
150 }; | |
151 #endif /* defined(__emptyExample__UIElement__) */ |