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@0
|
52 virtual void draw();
|
rt300@0
|
53 void hide(){
|
rt300@0
|
54 hidden = true;
|
rt300@0
|
55 on = false;
|
rt300@0
|
56
|
rt300@0
|
57 };
|
rt300@0
|
58 void show(){
|
rt300@0
|
59 hidden = false;
|
rt300@0
|
60 on = true;
|
rt300@0
|
61
|
rt300@0
|
62 };
|
rt300@0
|
63 bool touch(int x, int y, touchType ttype, int touchID);
|
rt300@0
|
64
|
rt300@0
|
65 virtual void addHandler(UICallbackFunction handlerFunction, int paramID) // virtual?
|
rt300@0
|
66 {
|
rt300@0
|
67 cout << "handler added to UIElement " << endl;
|
rt300@0
|
68 callback = handlerFunction;
|
rt300@0
|
69 myParamID = paramID;
|
rt300@0
|
70 };
|
rt300@0
|
71
|
rt300@0
|
72 virtual void setValue(float value){
|
rt300@0
|
73 cout << "not valid to set value on this?" << endl;
|
rt300@0
|
74 };
|
rt300@0
|
75 virtual void setHintValue(float value){
|
rt300@0
|
76 cout << "not valid to set value on this?" << endl;
|
rt300@0
|
77 };
|
rt300@0
|
78 virtual void showHint(bool value){
|
rt300@0
|
79 cout << "not valid to set value on this?" << endl;
|
rt300@0
|
80 };
|
rt300@0
|
81 virtual void setHintColor(ofColor c){
|
rt300@0
|
82 cout << "not valid to set value on this?" << endl;
|
rt300@0
|
83 };
|
rt300@0
|
84 controllerType getType() const {
|
rt300@0
|
85 return myType;
|
rt300@0
|
86 }
|
rt300@0
|
87 float getWidth() const {return width;};
|
rt300@0
|
88 virtual void setHighlight(bool hion){
|
rt300@0
|
89 // ?
|
rt300@0
|
90 on = hion;
|
rt300@0
|
91 };
|
rt300@0
|
92 void setActive(bool isActive){
|
rt300@0
|
93 inactive = !isActive; // thats logic right?
|
rt300@0
|
94 }
|
rt300@0
|
95 void setX(float ax){
|
rt300@0
|
96 x = ax;
|
rt300@0
|
97 };
|
rt300@0
|
98 void setY(float ay){
|
rt300@0
|
99 y = ay;
|
rt300@0
|
100 };
|
rt300@0
|
101 protected:
|
rt300@0
|
102
|
rt300@0
|
103 float x;
|
rt300@0
|
104 float y;
|
rt300@0
|
105 float width;
|
rt300@0
|
106 float height;
|
rt300@0
|
107 bool on;
|
rt300@0
|
108 int myParamID;
|
rt300@0
|
109 list<int> myTouchIDs;
|
rt300@0
|
110
|
rt300@0
|
111 ofColor background;
|
rt300@0
|
112
|
rt300@0
|
113 string labelName;
|
rt300@0
|
114 ofTrueTypeFont verdana16;
|
rt300@0
|
115 ofTrueTypeFont bigFont;
|
rt300@0
|
116 ofTrueTypeFont smallFont;
|
rt300@0
|
117 controllerType myType;
|
rt300@0
|
118
|
rt300@0
|
119 bool hidden; // don't draw dont touch
|
rt300@0
|
120 bool inactive; // dont touch, draw dimmed
|
rt300@0
|
121
|
rt300@0
|
122 void init();
|
rt300@0
|
123
|
rt300@0
|
124 bool isExistingTouchID(int touchID){
|
rt300@0
|
125 // is id in list
|
rt300@0
|
126 std::list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID);
|
rt300@0
|
127 if (findIter == myTouchIDs.end()){
|
rt300@0
|
128 return false;
|
rt300@0
|
129 }else{
|
rt300@0
|
130 return true;
|
rt300@0
|
131 }
|
rt300@0
|
132 };
|
rt300@0
|
133
|
rt300@0
|
134 void addTouchID(int touchID){
|
rt300@0
|
135 //list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID);
|
rt300@0
|
136 //if(findIter == myTouchIDs.end()){ // checks for duplicates
|
rt300@0
|
137 myTouchIDs.insert(myTouchIDs.begin(), touchID);
|
rt300@0
|
138 //}
|
rt300@0
|
139 };
|
rt300@0
|
140 void removeTouchID(int touchID){
|
rt300@0
|
141 list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID);
|
rt300@0
|
142 if(findIter != myTouchIDs.end()){
|
rt300@0
|
143 myTouchIDs.erase(findIter);
|
rt300@0
|
144 }
|
rt300@0
|
145 };
|
rt300@0
|
146 static float sumWidth(float total, UIElement* element){
|
rt300@0
|
147 return total + element->getWidth();
|
rt300@0
|
148 }
|
rt300@0
|
149 bool isMyTouch(int x, int y, touchType ttype, int touchID);
|
rt300@0
|
150 bool touchIsInMyArea(int tx, int ty);
|
rt300@0
|
151 virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID) = 0; // subclass handles it
|
rt300@0
|
152
|
rt300@0
|
153 bool isCoordInMyRegion(double x, double y); // not used
|
rt300@0
|
154
|
rt300@0
|
155
|
rt300@0
|
156 };
|
rt300@0
|
157 #endif /* defined(__emptyExample__UIElement__) */
|