root / ofxArgosUI / src / ofxArgosUI_View.cpp @ 66

View | Annotate | Download (5.9 KB)

1
/***********************************************************************
2
 
3
 Copyright (c) 2009, 2010 Dimitri Diakopoulos, http://www.dimitridiakopoulos.com/
4
5
 Portions Copyright (c) 2008, 2009 Memo Aktens, http://www.memo.tv/
6
 -> Based on ofxSimpleGuiToo
7
 
8
 Portions Copyright (c) 2008 Todd Vanderlin, http://toddvanderlin.com/
9
 -> Inspired by ofxSimpleGui API
10
11
        Redistribution and use in source and binary forms, with or without modification, 
12
        are permitted provided that the following conditions are met:
13
14
        1. Redistributions of source code must retain the above copyright notice, 
15
        this list of conditions and the following disclaimer.
16
17
        2. Redistributions in binary form must reproduce the above copyright notice, 
18
        this list of conditions and the following disclaimer in the documentation and/or 
19
        other materials provided with the distribution.
20
21
        3. The name of the author may not be used to endorse or promote products derived 
22
        from this software without specific prior written permission.
23
24
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
25
        ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
26
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
27
        ARE DISCLAIMED. IN NOEVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
28
        INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
29
        (INCLUDING, BUT NOT LIMITED TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
30
        LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
31
        AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
33
        OF THE USE OF THIS SOFTWARE,EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
34
35
*************************************************************************/ 
36
37
#include "ofxArgosUI_View.h"
38
39
ofxArgosUI_View::ofxArgosUI_View(string name) : ofxArgosUI_Control(name) {
40
        disableAllEvents();
41
}
42
43
ofxArgosUI_View::~ofxArgosUI_View() {
44
}
45
46
void ofxArgosUI_View::loadFromXML(ofxXmlSettings &XML) {
47
        for(int i=0; i < controls.size(); i++) {
48
                controls[i]->loadFromXML(XML);
49
        }
50
}
51
52
void ofxArgosUI_View::saveToXML(ofxXmlSettings &XML) {
53
        for(int i=0; i < controls.size(); i++) {
54
                controls[i]->saveToXML(XML);
55
        }
56
}
57
58
void ofxArgosUI_View::update(ofEventArgs &e) {
59
        for(int i = 0; i<controls.size(); i++){
60
                controls[i]->update();
61
        }
62
}
63
64
void ofxArgosUI_View::draw(float x, float y) {
65
66
        setPos(0,0);
67
        setSize(ofGetWidth(), ofGetHeight()); 
68
        
69
        ofSetRectMode(OF_RECTMODE_CORNER);
70
71
        for (int i = 0; i<systemcontrols.size(); i++){
72
                //systemcontrols[i]->draw(systemcontrols[i]->x, systemcontrols[i]->y);
73
        }
74
75
        if (stateManager::editing){
76
77
                for(int i = 0; i<controls.size(); i++) {
78
                        controls[i]->disableAllInput(); 
79
                        controls[i]->draw(controls[i]->x, controls[i]->y);
80
                }
81
        }
82
83
        else {
84
                focus.clear(); 
85
                for(int i = 0; i<controls.size(); i++) {
86
                        controls[i]->enableAllInput(); 
87
                        controls[i]->draw(controls[i]->x, controls[i]->y);
88
                }
89
        }
90
91
}
92
93
ofxArgosUI_Control *ofxArgosUI_View::addSystemControl(ofxArgosUI_Control* control) {
94
        systemcontrols.push_back(control);
95
        return control;
96
}
97
98
ofxArgosUI_Panel *ofxArgosUI_View::addSystemPanel(string name, int x, int y, int width, int height) {
99
        return (ofxArgosUI_Panel *)addSystemControl(new ofxArgosUI_Panel(name, x, y, width, height));
100
}
101
102
ofxArgosUI_Control *ofxArgosUI_View::addControl(ofxArgosUI_Control* control) {
103
        controls.push_back(control);
104
        return control;
105
}
106
107
ofxArgosUI_Panel *ofxArgosUI_View::addPanel(string name, int x, int y, int width, int height) {
108
        return (ofxArgosUI_Panel *)addControl(new ofxArgosUI_Panel(name, x, y, width, height));
109
}
110
111
ofxArgosUI_Button *ofxArgosUI_View::addButton(string name, int x, int y, int width, int height, bool *value) {
112
        return (ofxArgosUI_Button *)addControl(new ofxArgosUI_Button(name, x, y, width, height, value));
113
}
114
115
ofxArgosUI_FPSCounter *ofxArgosUI_View::addFPSCounter(int x, int y, int width, int height) {
116
        return (ofxArgosUI_FPSCounter *)addControl(new ofxArgosUI_FPSCounter(x, y, width, height));
117
}
118
119
ofxArgosUI_SliderInt *ofxArgosUI_View::addSlider(string name, int x, int y, int width, int height, int *value, int min, int max) {
120
        return (ofxArgosUI_SliderInt *)addControl(new ofxArgosUI_SliderInt(name, x, y, width, height, value, min, max, 0));
121
}
122
123
ofxArgosUI_SliderFloat *ofxArgosUI_View::addSlider(string name, int x, int y, int width, int height, float *value, float min, float max, float smoothing) {
124
        return (ofxArgosUI_SliderFloat *)addControl(new ofxArgosUI_SliderFloat(name, x, y, width, height, value, min, max, smoothing));
125
}
126
127
ofxArgosUI_XYPad *ofxArgosUI_View::addXYPad(string name, int x, int y, int width, int height, ofPoint* value, float xmin, float xmax, float ymin, float ymax) {
128
        return (ofxArgosUI_XYPad *)addControl(new ofxArgosUI_XYPad(name, x, y, width, height, value, xmin, xmax, ymin, ymax));
129
}
130
131
ofxArgosUI_TextField *ofxArgosUI_View::addTextField(string name, int x, int y, int width, int height, string *value) {
132
        return (ofxArgosUI_TextField *)addControl(new ofxArgosUI_TextField(name, x, y, width, height, value));
133
}
134
135
ofxArgosUI_Title *ofxArgosUI_View::addTitle(string name, bool *value) {
136
        return (ofxArgosUI_Title *)addControl(new ofxArgosUI_Title(name, value));
137
}
138
139
ofxArgosUI_Toggle *ofxArgosUI_View::addToggle(string name, int x, int y, int width, int height, bool *value) {
140
        return (ofxArgosUI_Toggle *)addControl(new ofxArgosUI_Toggle(name, x, y, width, height, value));
141
}
142
143
ofxArgosUI_Knob        *ofxArgosUI_View::addKnob(string name, int x, int y, int radius, float *value, float min, float max, float smoothing){
144
        return (ofxArgosUI_Knob *)addControl(new ofxArgosUI_Knob(name, x, y, radius, value, min, max, smoothing));
145
}
146
147
ofxArgosUI_Icon        *ofxArgosUI_View::addIcon(int x, int y, int width, int height){
148
        return (ofxArgosUI_Icon *)addControl(new ofxArgosUI_Icon(x, y, width, height));
149
}