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