1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | This program is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with this program; if not, write to the Free Software Foundation, |
---|
18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
19 | |
---|
20 | |
---|
21 | ### File Specific: |
---|
22 | main-programmer: Benjamin Grauer |
---|
23 | |
---|
24 | */ |
---|
25 | |
---|
26 | #include "orxonox_gui_exec.h" |
---|
27 | #include <iostream> |
---|
28 | #include <string> |
---|
29 | |
---|
30 | OrxonoxGuiExec::OrxonoxGuiExec (Window* orxonoxGUI) |
---|
31 | { |
---|
32 | configFile = (char*)malloc (512*sizeof (char)); |
---|
33 | |
---|
34 | execFrame = new Frame ("Execute-Tags:"); |
---|
35 | execBox = new Box ('v'); |
---|
36 | |
---|
37 | start = new Button ("Start"); |
---|
38 | start->connectSignal ("clicked", startOrxonox); |
---|
39 | execBox->fill (start); |
---|
40 | saveSettings = new CheckButton ("Save Settings"); |
---|
41 | saveSettings->value = 1; |
---|
42 | execBox->fill (saveSettings); |
---|
43 | verboseMode = new Menu ("verbose mode", "no output", "verbose", "debug", "lastItem"); |
---|
44 | verboseMode->setFlagName ("verbose", "v", 0); |
---|
45 | execBox->fill (verboseMode); |
---|
46 | alwaysShow = new CheckButton ("Always Show this Menu"); |
---|
47 | alwaysShow->setFlagName ("gui", "g", 0); |
---|
48 | execBox->fill (alwaysShow); |
---|
49 | quit = new Button ("Quit"); |
---|
50 | quit->connectSignal ("clicked", orxonoxGUI->orxonox_gui_quit); |
---|
51 | execBox->fill (quit); |
---|
52 | |
---|
53 | execFrame->fill (execBox); |
---|
54 | } |
---|
55 | |
---|
56 | Frame* OrxonoxGuiExec::getFrame () |
---|
57 | { |
---|
58 | return execFrame; |
---|
59 | } |
---|
60 | |
---|
61 | /* FILE HANDLING */ |
---|
62 | |
---|
63 | void OrxonoxGuiExec::setFilename (char* filename) |
---|
64 | { |
---|
65 | char* buffer = (char*) malloc (512*sizeof(buffer)); |
---|
66 | sprintf (buffer, "%s", filename); |
---|
67 | if (!strncmp (buffer, "~/", 2)) |
---|
68 | { |
---|
69 | #ifdef __WIN32__ |
---|
70 | sprintf (configFile, "%s/%s", getenv ("USERPROFILE"), buffer+2); |
---|
71 | #else |
---|
72 | sprintf (configFile, "%s/%s", getenv ("HOME"), buffer+2); |
---|
73 | #endif |
---|
74 | } |
---|
75 | else if (buffer) |
---|
76 | sprintf(configFile, "%s", buffer); |
---|
77 | delete buffer; |
---|
78 | } |
---|
79 | |
---|
80 | int OrxonoxGuiExec::shouldsave () |
---|
81 | { |
---|
82 | return ( static_cast<Option*>(saveSettings)->value); |
---|
83 | } |
---|
84 | |
---|
85 | void OrxonoxGuiExec::writeToFile (Widget* widget) |
---|
86 | { |
---|
87 | CONFIG_FILE = fopen (configFile, "w"); |
---|
88 | if (CONFIG_FILE) |
---|
89 | writeFileText (widget); |
---|
90 | fclose (CONFIG_FILE); |
---|
91 | } |
---|
92 | |
---|
93 | void OrxonoxGuiExec::writeFileText (Widget* widget) |
---|
94 | { |
---|
95 | if (widget->is_option >= 1) |
---|
96 | if (strcmp (static_cast<Option*>(widget)->flag_name, "") || strcmp (static_cast<Option*>(widget)->flag_name_short, "")) |
---|
97 | { |
---|
98 | char Buffer[256]; |
---|
99 | char* space2under; |
---|
100 | sprintf (Buffer, "%s", static_cast<Option*>(widget)->option_name); |
---|
101 | if (strchr (Buffer, '_')) |
---|
102 | cout << "Warning Optionname" << Buffer << " is not Valid for Saving, because it includes an underscore" << endl; |
---|
103 | while (space2under = strchr(Buffer, ' ')) |
---|
104 | { |
---|
105 | sprintf (space2under, "_%s", space2under+1); |
---|
106 | } |
---|
107 | fprintf (CONFIG_FILE, "%s = %i\n", Buffer, static_cast<Option*>(widget)->value); |
---|
108 | } |
---|
109 | switch (widget->is_option) |
---|
110 | { |
---|
111 | case -1: |
---|
112 | writeFileText (static_cast<Container*>(widget)->down); |
---|
113 | break; |
---|
114 | case -2: |
---|
115 | writeFileText (static_cast<Box*>(widget)->down); |
---|
116 | break; |
---|
117 | } |
---|
118 | |
---|
119 | if (widget->next != NULL) |
---|
120 | writeFileText (widget->next); |
---|
121 | } |
---|
122 | |
---|
123 | void OrxonoxGuiExec::readFromFile (Widget* widget) |
---|
124 | { |
---|
125 | CONFIG_FILE = fopen (configFile, "r"); |
---|
126 | if (CONFIG_FILE) |
---|
127 | { |
---|
128 | char Buffer[256] = ""; |
---|
129 | char Variable[256]= ""; |
---|
130 | int Value; |
---|
131 | while (fscanf (CONFIG_FILE, "%s", Buffer) != EOF) |
---|
132 | { |
---|
133 | if (!strcmp (Buffer, "=")) |
---|
134 | { |
---|
135 | char* under2space; |
---|
136 | while (under2space = strchr(Variable, '_')) |
---|
137 | { |
---|
138 | sprintf (under2space, " %s", under2space+1); |
---|
139 | } |
---|
140 | |
---|
141 | fscanf (CONFIG_FILE, "%s", Buffer); |
---|
142 | Value = atoi(Buffer); |
---|
143 | readFileText (widget, Variable, Value); |
---|
144 | sprintf (Variable, ""); |
---|
145 | } |
---|
146 | sprintf (Variable, "%s", Buffer); |
---|
147 | } |
---|
148 | widget->setOptions(); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | void OrxonoxGuiExec::readFileText (Widget* widget, char* variableName, int variableValue) |
---|
153 | { |
---|
154 | if (widget->is_option >= 1) |
---|
155 | if (!strcmp (static_cast<Option*>(widget)->option_name, variableName)) |
---|
156 | static_cast<Option*>(widget)->value = variableValue; |
---|
157 | |
---|
158 | switch (widget->is_option) |
---|
159 | { |
---|
160 | case -1: |
---|
161 | readFileText (static_cast<Container*>(widget)->down, variableName, variableValue); |
---|
162 | break; |
---|
163 | case -2: |
---|
164 | readFileText (static_cast<Box*>(widget)->down, variableName, variableValue); |
---|
165 | break; |
---|
166 | } |
---|
167 | |
---|
168 | if (widget->next != NULL) |
---|
169 | readFileText (widget->next, variableName, variableValue); |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | gint startOrxonox (GtkWidget *widget, Widget* data) |
---|
174 | { |
---|
175 | /** |
---|
176 | * Starts Orxonox. |
---|
177 | */ |
---|
178 | cout << "Starting Orxonox" <<endl; |
---|
179 | } |
---|