Mercurial > hg > tweakathon2ios
comparison UI code/UIElementContainer.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 | 2bd658b44c2d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a223551fdc1f |
---|---|
1 // | |
2 // UIElementContainer.h | |
3 // emptyExample | |
4 // | |
5 // Created by Robert Tubb on 22/05/2013. | |
6 // | |
7 // | |
8 | |
9 | |
10 // a meta button, with border. | |
11 | |
12 #ifndef __emptyExample__UIElementContainer__ | |
13 #define __emptyExample__UIElementContainer__ | |
14 | |
15 #include <iostream> | |
16 #include "globalVariables.h" | |
17 #include "ofMain.h" | |
18 #include "UIElement.h" | |
19 #include "boost/bind.hpp" | |
20 #include "boost/function.hpp" | |
21 #include "timeController.h" | |
22 // is a UI "panel" containing sub elements | |
23 // helps control the focus of the touch event | |
24 | |
25 | |
26 extern TimeController timeController; | |
27 | |
28 class UIElementContainer: public UIElement{ | |
29 public: | |
30 UIProps myProps; | |
31 vector<UIElement *> subElements; | |
32 UIElementContainer(); | |
33 ~UIElementContainer(){ | |
34 removeAllSubelements(); | |
35 }; | |
36 UIElementContainer(float ax, | |
37 float ay, | |
38 float awidth, | |
39 float aheight, | |
40 const UIProps& props); // constructor 1 : we add stuff later | |
41 | |
42 void addElement(UIElement *elm){ | |
43 subElements.push_back(elm); | |
44 | |
45 }; | |
46 void removeAllSubelements(); | |
47 | |
48 int getNumberOfControls(); | |
49 UIElement* getElement(int idx){ | |
50 if (idx < subElements.size()){ | |
51 return subElements[idx]; | |
52 }else{ | |
53 cout << "ERROR ERROR: index too big for subelemens" << endl; | |
54 } | |
55 | |
56 } | |
57 void showBorder(bool s){ | |
58 if(s){ | |
59 cthickness = 1; | |
60 | |
61 } | |
62 } | |
63 virtual void draw(); | |
64 bool handleMyTouch(int x, int y, touchType ttype, int touchID){ | |
65 vector<UIElement *>::iterator UIitr; | |
66 for(UIitr = subElements.begin(); UIitr < subElements.end(); UIitr++){ | |
67 (*UIitr)->touch(x,y,ttype,touchID); | |
68 } | |
69 return true; | |
70 } | |
71 | |
72 void setActive(bool isActive){ | |
73 vector<UIElement *>::iterator UIitr; | |
74 for(UIitr = subElements.begin(); UIitr < subElements.end(); UIitr++){ | |
75 (*UIitr)->setActive(isActive); | |
76 } | |
77 } | |
78 | |
79 void autoArrangeRow(){ | |
80 // goes thru subelements and sets x and y pos to something sensible | |
81 | |
82 // add up all element widths | |
83 float sum = accumulate(subElements.begin(), subElements.end(), 0.0, &UIElement::sumWidth); | |
84 | |
85 float spaceLeft = width - sum; | |
86 | |
87 float spac = spaceLeft/(getNumberOfControls()+1); | |
88 | |
89 if (spac <= 0){ | |
90 cout << "ERROR: not enough space for controls" << endl; | |
91 | |
92 } | |
93 float pos = spac; | |
94 vector<UIElement *>::iterator ei; | |
95 for(ei = subElements.begin(); ei < subElements.end(); ei++){ | |
96 (*ei)->setX(pos); | |
97 pos = pos + (*ei)->getWidth() + spac; | |
98 } | |
99 // TODO y set to centred | |
100 } | |
101 private: | |
102 void drawBorder(); | |
103 double cthickness; | |
104 bool flashing; | |
105 }; | |
106 | |
107 #endif /* defined(__emptyExample__UIElementContainer__) */ |