1 | #include "orxonox_gui.h" |
---|
2 | #include <iostream.h> |
---|
3 | |
---|
4 | |
---|
5 | int main( int argc, char *argv[] ) |
---|
6 | { |
---|
7 | gtk_init (&argc, &argv); |
---|
8 | Window* orxonoxGUI = new Window("Graphical Orxonox Launcher"); |
---|
9 | orxonoxGUI->connectSignal ("destroy", orxonoxGUI->orxonox_gui_quit); |
---|
10 | orxonoxGUI->connectSignal ("delete_event", orxonoxGUI->orxonox_gui_quit); |
---|
11 | |
---|
12 | Frame* Frametest = new Frame ("Test"); |
---|
13 | orxonoxGUI->fill((Frame*) Frametest); |
---|
14 | Box* box = new Box ('v'); |
---|
15 | Frametest->fill(box); |
---|
16 | |
---|
17 | CheckButton* button = new CheckButton("test"); |
---|
18 | button->connectSignal ("clicked", orxonoxGUI->orxonox_gui_quit); |
---|
19 | box->fill(button); |
---|
20 | Slider* slider = new Slider("testslider", 0, 100); |
---|
21 | slider->connectSignal ("value_changed", slider->OptionChange); |
---|
22 | box->fill(slider); |
---|
23 | |
---|
24 | orxonoxGUI->showall (); |
---|
25 | |
---|
26 | gtk_main(); |
---|
27 | return 0; |
---|
28 | } |
---|
29 | |
---|
30 | |
---|
31 | /* WIDGET */ |
---|
32 | void Widget::show() |
---|
33 | { |
---|
34 | /** |
---|
35 | * Function to Show any Widget |
---|
36 | */ |
---|
37 | gtk_widget_show (widget); |
---|
38 | } |
---|
39 | |
---|
40 | void Widget::connectSignal (char* event, gint ( *signal)( GtkWidget*, GdkEvent*, void *)) |
---|
41 | { |
---|
42 | /** |
---|
43 | * Connect any signal to any given Sub-widget |
---|
44 | */ |
---|
45 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL); |
---|
46 | } |
---|
47 | |
---|
48 | void Widget::connectSignal (char* event, gint ( *signal)( GtkWidget*, Widget *)) |
---|
49 | { |
---|
50 | /** |
---|
51 | * Connect a signal with additionally passing the whole Object |
---|
52 | */ |
---|
53 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this); |
---|
54 | } |
---|
55 | |
---|
56 | /* CONTAINERS*/ |
---|
57 | |
---|
58 | void Container::fill (Widget *lowerWidget) |
---|
59 | { |
---|
60 | /** |
---|
61 | * fill any given Container with a lowerwidet |
---|
62 | */ |
---|
63 | gtk_container_add (GTK_CONTAINER(this->widget), lowerWidget->widget); |
---|
64 | this->down = lowerWidget; |
---|
65 | } |
---|
66 | |
---|
67 | // gtk_container_set_border_width (GTK_CONTAINER (widget), 5); |
---|
68 | |
---|
69 | /* WINDOW */ |
---|
70 | |
---|
71 | Window::Window (void) |
---|
72 | { |
---|
73 | /** |
---|
74 | * Creating a Window |
---|
75 | */ |
---|
76 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
77 | gtk_window_set_policy(GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
78 | } |
---|
79 | |
---|
80 | Window::Window (char* windowName) |
---|
81 | { |
---|
82 | /** |
---|
83 | * Creating a Window with passing a name |
---|
84 | */ |
---|
85 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
86 | gtk_window_set_policy(GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
87 | this->setTitle(windowName); |
---|
88 | } |
---|
89 | |
---|
90 | Window::~Window () |
---|
91 | { |
---|
92 | /** |
---|
93 | * Destoying a Window (not implemented) |
---|
94 | */ |
---|
95 | } |
---|
96 | |
---|
97 | void Window::showall () |
---|
98 | { |
---|
99 | /** |
---|
100 | * Shows all Widgets that are included within this Widget |
---|
101 | */ |
---|
102 | gtk_widget_show_all (widget); |
---|
103 | } |
---|
104 | |
---|
105 | void Window::setTitle (char* title) |
---|
106 | { |
---|
107 | /** |
---|
108 | * Set The Window title to title |
---|
109 | */ |
---|
110 | gtk_window_set_title (GTK_WINDOW (widget), title); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | gint Window::orxonox_gui_quit ( GtkWidget *widget, GdkEvent *event, gpointer data) |
---|
115 | { |
---|
116 | /** |
---|
117 | * Quits the orxonox_GUI |
---|
118 | */ |
---|
119 | gtk_main_quit(); |
---|
120 | return FALSE; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | /* FRAME */ |
---|
125 | |
---|
126 | Frame::Frame (void) |
---|
127 | { |
---|
128 | /** |
---|
129 | * Creates a new Frame without a name |
---|
130 | */ |
---|
131 | widget = gtk_frame_new (""); |
---|
132 | } |
---|
133 | Frame::Frame (char* title) |
---|
134 | { |
---|
135 | /** |
---|
136 | * Creates a new Frame with name title |
---|
137 | */ |
---|
138 | widget = gtk_frame_new (title); |
---|
139 | } |
---|
140 | Frame::~Frame () |
---|
141 | { |
---|
142 | /** |
---|
143 | * Destroys given Frame (not implemented yet) |
---|
144 | */ |
---|
145 | } |
---|
146 | |
---|
147 | void Frame::setTitle (char* title) |
---|
148 | { |
---|
149 | /** |
---|
150 | * Sets the Frames name to title |
---|
151 | */ |
---|
152 | gtk_frame_set_label (GTK_FRAME (widget), title); |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | /* BOX */ |
---|
158 | |
---|
159 | Box::Box (void) |
---|
160 | { |
---|
161 | /** |
---|
162 | * Creates a new horizontal Box |
---|
163 | */ |
---|
164 | widget = gtk_hbox_new(FALSE, 0); |
---|
165 | } |
---|
166 | Box::Box (char boxtype) |
---|
167 | { |
---|
168 | /** |
---|
169 | * Creates a new Box if boxtype is 'v' it will be vertically, if 'h' it will be horizontally |
---|
170 | */ |
---|
171 | if (boxtype == 'v') |
---|
172 | { |
---|
173 | widget = gtk_vbox_new(FALSE, 0); |
---|
174 | } |
---|
175 | else |
---|
176 | { |
---|
177 | widget = gtk_hbox_new(FALSE, 0); |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | Box::~Box () |
---|
182 | { |
---|
183 | /** |
---|
184 | * Destroys given Frame (not implemented yet) |
---|
185 | */ |
---|
186 | } |
---|
187 | |
---|
188 | void Box::fill (Widget *lowerWidget) |
---|
189 | { |
---|
190 | /** |
---|
191 | * Fill a Box with its lowerwidgets |
---|
192 | */ |
---|
193 | gtk_box_pack_start (GTK_BOX(this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
194 | } |
---|
195 | |
---|
196 | |
---|
197 | /* OPTION */ |
---|
198 | |
---|
199 | /* BUTTON */ |
---|
200 | Button::Button(char* buttonname) |
---|
201 | { |
---|
202 | /** |
---|
203 | * Creates a new Button with name buttonname |
---|
204 | */ |
---|
205 | widget = gtk_button_new_with_label(buttonname); |
---|
206 | option_name = buttonname; |
---|
207 | } |
---|
208 | |
---|
209 | /* CHECKBUTTON */ |
---|
210 | CheckButton::CheckButton(char* buttonname) |
---|
211 | { |
---|
212 | /** |
---|
213 | * Creates a new CheckButton with name buttonname |
---|
214 | */ |
---|
215 | widget = gtk_check_button_new_with_label(buttonname); |
---|
216 | option_name = buttonname; |
---|
217 | } |
---|
218 | |
---|
219 | /* SLIDER */ |
---|
220 | Slider::Slider (char* slidername, int start, int end) |
---|
221 | { |
---|
222 | /** |
---|
223 | * Creates a new Slider with name slidername a beginning value of start and an end value of end. |
---|
224 | */ |
---|
225 | widget = gtk_hscale_new_with_range (start, end, 5); |
---|
226 | value = start; |
---|
227 | option_name = slidername; |
---|
228 | } |
---|
229 | |
---|
230 | gint Slider::OptionChange (GtkWidget *widget, Widget* slider) |
---|
231 | { |
---|
232 | /** |
---|
233 | * Writes value, if changed on the slider, to the object. |
---|
234 | */ |
---|
235 | static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE((Slider*)slider->widget)); |
---|
236 | cout << static_cast<Slider*>(slider)->value << endl; |
---|
237 | } |
---|