Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/gui/guicc/orxonox_gui.cc @ 1974

Last change on this file since 1974 was 1974, checked in by bensch, 21 years ago

orxonox/branches/gui/guicc: added OptionMenu

File size: 5.6 KB
Line 
1#include "orxonox_gui.h"
2#include <iostream.h>
3
4
5int 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  Menu* menu = new Menu("test1", "no output", "verbose", "debug", "lastItem");
24  menu->connectSignal ("changed", menu->OptionChange);
25  box->fill(menu);
26  orxonoxGUI->showall ();
27 
28  gtk_main();
29  return 0;
30}
31
32
33/* WIDGET */
34void Widget::show()
35{
36  /**
37   * Function to Show any Widget
38   */
39  gtk_widget_show (widget);
40}
41
42void Widget::connectSignal (char* event, gint ( *signal)( GtkWidget*, GdkEvent*, void *))
43{
44  /**
45   * Connect any signal to any given Sub-widget
46   */
47  g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL);
48}
49
50void Widget::connectSignal (char* event, gint ( *signal)( GtkWidget*, Widget *))
51{
52  /**
53   * Connect a signal with additionally passing the whole Object
54   */
55  g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this);
56}
57
58/* CONTAINERS*/
59
60void Container::fill (Widget *lowerWidget)
61{
62  /**
63   * fill any given Container with a lowerwidet
64   */
65  gtk_container_add (GTK_CONTAINER(this->widget), lowerWidget->widget);
66  this->down = lowerWidget;
67}
68
69// gtk_container_set_border_width (GTK_CONTAINER (widget), 5);
70
71/* WINDOW */
72
73Window::Window (void)
74{
75  /**
76   * Creating a Window
77   */
78  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
79  gtk_window_set_policy(GTK_WINDOW(widget), TRUE, TRUE, TRUE);
80}
81
82Window::Window (char* windowName)
83{
84  /**
85   * Creating a Window with passing a name
86   */
87  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
88  gtk_window_set_policy(GTK_WINDOW(widget), TRUE, TRUE, TRUE);
89  this->setTitle(windowName);
90}
91
92Window::~Window ()
93{
94  /**
95   * Destoying a Window (not implemented)
96   */
97}
98
99void Window::showall ()
100{
101  /**
102   * Shows all Widgets that are included within this Widget
103   */
104  gtk_widget_show_all  (widget);
105}
106
107void Window::setTitle (char* title)
108{
109  /**
110   * Set The Window title to title
111   */
112  gtk_window_set_title (GTK_WINDOW (widget), title);
113}
114
115
116gint Window::orxonox_gui_quit ( GtkWidget *widget, GdkEvent *event, gpointer data)
117{
118  /**
119   * Quits the orxonox_GUI
120   */
121  gtk_main_quit();
122  return FALSE;
123}
124
125
126/* FRAME */
127
128Frame::Frame (void)
129{
130  /**
131   * Creates a new Frame without a name
132   */
133  widget = gtk_frame_new ("");
134}
135Frame::Frame (char* title)
136{
137  /**
138   * Creates a new Frame with name title
139   */
140  widget = gtk_frame_new (title);
141}
142Frame::~Frame ()
143{
144  /**
145   * Destroys given Frame (not implemented yet)
146   */
147}
148
149void Frame::setTitle (char* title)
150{
151  /**
152   * Sets the Frames name to title
153   */
154  gtk_frame_set_label (GTK_FRAME (widget), title);
155}
156
157
158
159/* BOX */
160
161Box::Box (void)
162{
163  /**
164   * Creates a new horizontal Box
165   */
166  widget = gtk_hbox_new(FALSE, 0);
167}
168Box::Box (char boxtype)
169{
170  /**
171   * Creates a new Box if boxtype is 'v' it will be vertically, if 'h' it will be horizontally
172   */
173  if (boxtype == 'v')
174    {
175      widget = gtk_vbox_new(FALSE, 0);
176    }
177  else
178    {
179      widget = gtk_hbox_new(FALSE, 0);
180    }
181}
182
183Box::~Box ()
184{
185  /**
186   * Destroys given Frame (not implemented yet)
187   */
188}
189
190void Box::fill (Widget *lowerWidget)
191{
192  /**
193   * Fill a Box with its lowerwidgets
194   */
195  gtk_box_pack_start (GTK_BOX(this->widget), lowerWidget->widget, TRUE, TRUE, 0);
196}
197
198
199/* OPTION */
200
201/* BUTTON */
202Button::Button(char* buttonname)
203{
204  /**
205   * Creates a new Button with name buttonname
206   */
207  widget = gtk_button_new_with_label(buttonname);
208  option_name = buttonname;
209}
210
211/* CHECKBUTTON */
212CheckButton::CheckButton(char* buttonname)
213{
214  /**
215   * Creates a new CheckButton with name buttonname
216   */
217  widget = gtk_check_button_new_with_label(buttonname);
218  option_name = buttonname;
219}
220
221/* SLIDER */
222Slider::Slider (char* slidername, int start, int end)
223{
224  /**
225   * Creates a new Slider with name slidername a beginning value of start and an end value of end.
226   */
227  widget = gtk_hscale_new_with_range (start, end, 5);
228  value = start;
229  option_name = slidername;
230}
231
232gint Slider::OptionChange (GtkWidget *widget, Widget* slider)
233{
234  /**
235   * Writes value, if changed on the slider, to the object.
236   */
237  static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE((Slider*)slider->widget));
238  cout << static_cast<Slider*>(slider)->value << endl;
239}
240
241
242Menu::Menu(char* menuname, ...)
243{
244  /**
245   * Creates an Menu-Item-list out of multiple input. Consider, that the last input argument has to be "lastItem" for this to work.
246   */
247  char *tmp;
248  va_list itemlist;
249  widget = gtk_option_menu_new();
250  GtkWidget* menu = gtk_menu_new ();
251  GtkWidget* item;
252
253  va_start(itemlist, menuname);
254  while (strcmp(tmp = va_arg(itemlist, char*), "lastItem"))
255    {
256      item = gtk_menu_item_new_with_label (tmp);
257      gtk_menu_shell_append(GTK_MENU_SHELL (menu), item);
258    }
259  va_end(itemlist);
260
261  gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu);
262}
263
264gint Menu::OptionChange (GtkWidget *widget, Widget* menu)
265{
266  /**
267   * Writes value, if changed on the Menu, to the object.
268   */
269  static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU(menu->widget));
270  cout << static_cast<Menu*>(menu)->value << endl;
271}
Note: See TracBrowser for help on using the repository browser.