Mercurial > hg > tweakathon2ios
view UI code/UIElementContainer.h @ 45:80112c9349c4
demo mode.
FUCKING ORIENTATION SHIT
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Mon, 15 Dec 2014 18:54:00 +0000 |
parents | 2bd658b44c2d |
children | a62e033117fa |
line wrap: on
line source
// // UIElementContainer.h // emptyExample // // Created by Robert Tubb on 22/05/2013. // // // a meta button, with border. #ifndef __emptyExample__UIElementContainer__ #define __emptyExample__UIElementContainer__ #include <iostream> #include "globalVariables.h" #include "ofMain.h" #include "UIElement.h" #include "boost/bind.hpp" #include "boost/function.hpp" #include "timeController.h" // is a UI "panel" containing sub elements // helps control the focus of the touch event extern TimeController timeController; class UIElementContainer: public UIElement{ public: UIProps myProps; vector<UIElement *> subElements; UIElementContainer(); ~UIElementContainer(){ removeAllSubelements(); }; UIElementContainer(float ax, float ay, float awidth, float aheight, const UIProps& props); // constructor 1 : we add stuff later void addElement(UIElement *elm){ subElements.push_back(elm); }; void removeAllSubelements(); int getNumberOfControls(); UIElement* getElement(int idx){ if (idx < subElements.size()){ return subElements[idx]; }else{ cout << "ERROR ERROR: index too big for subelemens" << endl; } } void showBorder(bool s){ if(s){ cthickness = 1; } } virtual void draw(); bool handleMyTouch(int x, int y, touchType ttype, int touchID){ vector<UIElement *>::iterator UIitr; for(UIitr = subElements.begin(); UIitr < subElements.end(); UIitr++){ (*UIitr)->touch(x,y,ttype,touchID); } return true; } void setActive(bool isActive){ vector<UIElement *>::iterator UIitr; for(UIitr = subElements.begin(); UIitr < subElements.end(); UIitr++){ (*UIitr)->setActive(isActive); } } void autoArrangeRow(){ // goes thru subelements and sets x and y pos to something sensible // add up all element widths float sum = accumulate(subElements.begin(), subElements.end(), 0.0, &UIElement::sumWidth); float spaceLeft = width - sum; float spac = spaceLeft/(getNumberOfControls()+1); if (spac <= 0){ cout << "ERROR: not enough space for controls" << endl; } float pos = spac; vector<UIElement *>::iterator ei; for(ei = subElements.begin(); ei < subElements.end(); ei++){ (*ei)->setX(pos); pos = pos + (*ei)->getWidth() + spac; } // TODO y set to centred } void showHideElementWithName(string label, bool show){ for( auto eit = subElements.begin(); eit < subElements.end(); eit++){ if( (*eit)->getLabel() == label ){ if (show){ (*eit)->show(); }else{ (*eit)->hide(); } } } } void showOnlyElementNamed(string label){ for( auto eit = subElements.begin(); eit < subElements.end(); eit++){ if( (*eit)->getLabel() == label ){ (*eit)->show(); }else{ (*eit)->hide(); } } } void showAllElements(){ for( auto eit = subElements.begin(); eit < subElements.end(); eit++){ (*eit)->show(); } } private: void drawBorder(); double cthickness; bool flashing; }; #endif /* defined(__emptyExample__UIElementContainer__) */