File: FloorMakerMain.cpp

package info (click to toggle)
sludge 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,844 kB
  • ctags: 2,981
  • sloc: cpp: 31,952; sh: 1,259; xml: 874; makefile: 672
file content (320 lines) | stat: -rw-r--r-- 7,575 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/* -*- Mode: C++; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * FloorMakerMain.cpp - Part of the SLUDGE Floor Maker (GTK+ version)
 *
 * Copyright (C) 2010 Tobias Hansen <tobias.han@gmx.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <gtk/gtk.h>
#include <gtk/gtkgl.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <glib-object.h>
#include <glib.h>

#include <GLee.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>

#include <errno.h>
#include <sys/types.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <getopt.h>

#include "SludgeFloorMaker.h"
#include "Common.h"

SludgeFloorMaker *floorMaker;

#ifdef __cplusplus
extern "C" {
#endif

// SludgeApplication callbacks:

G_MODULE_EXPORT gboolean
on_window1_delete_event(GtkWidget *theWidget, GdkEvent *theEvent, gpointer theUser_data)
{
	return floorMaker->on_window1_delete_event();
}

G_MODULE_EXPORT void
on_new(GtkMenuItem *theItem, gpointer theUser_data)
{
	floorMaker->on_new();
}


G_MODULE_EXPORT void
on_open(GtkMenuItem *theItem, gpointer theUser_data)
{
	floorMaker->on_open();
}

G_MODULE_EXPORT void
on_save(GtkMenuItem *theItem, gpointer theUser_data)
{
	floorMaker->on_save();
}

G_MODULE_EXPORT void
on_save_as(GtkMenuItem *theItem, gpointer theUser_data)
{
	floorMaker->on_save_as();
}

G_MODULE_EXPORT void
on_about(GtkMenuItem *theItem, gpointer theUser_data)
{
	floorMaker->on_about();
}

// SludgeGLApplication callbacks:

G_MODULE_EXPORT void
on_drawingarea1_realize(GtkWidget *theWidget, gpointer theUser_data)
{
	floorMaker->on_drawingarea1_realize(theWidget);
}

G_MODULE_EXPORT gboolean
on_drawingarea1_configure_event(GtkWidget *theWidget, GdkEventConfigure *theEvent, gpointer theUser_data)
{
	return floorMaker->on_drawingarea1_configure_event(theWidget, theEvent);
}

G_MODULE_EXPORT gboolean
on_drawingarea1_expose_event(GtkWidget *theWidget, GdkEventExpose *theEvent, gpointer theUser_data)
{
	return floorMaker->on_drawingarea1_expose_event(theWidget, theEvent);
}

G_MODULE_EXPORT gboolean
render_timer_event(gpointer theUser_data)
{
	return floorMaker->render_timer_event(theUser_data);
}

G_MODULE_EXPORT gboolean
on_drawingarea1_scroll_event(GtkWidget *theWidget, GdkEventScroll *theEvent, gpointer theUser_data)
{
	return floorMaker->on_drawingarea1_scroll_event(theWidget, theEvent);
}

G_MODULE_EXPORT gboolean
on_drawingarea1_button_press_event(GtkWidget *theWidget, GdkEventButton *theEvent, gpointer theUser_data)
{
	return floorMaker->on_drawingarea1_button_press_event(theWidget, theEvent);
}

G_MODULE_EXPORT gboolean
on_drawingarea1_button_release_event(GtkWidget *theWidget, GdkEventButton *theEvent, gpointer theUser_data)
{
	return floorMaker->on_drawingarea1_button_release_event(theWidget, theEvent);
}

G_MODULE_EXPORT gboolean
on_drawingarea1_motion_notify_event(GtkWidget *theWidget, GdkEventMotion *theEvent, gpointer theUser_data)
{
	return floorMaker->on_drawingarea1_motion_notify_event(theWidget, theEvent);
}

G_MODULE_EXPORT gboolean
on_drawingarea1_leave_notify_event(GtkWidget *theWidget, GdkEventAny *theEvent, gpointer theUser_data)
{
	return floorMaker->on_drawingarea1_leave_notify_event(theWidget, theEvent);
}

G_MODULE_EXPORT void
on_zoom_100_realize(GtkToolButton *theButton, gpointer theUser_data)
{
	floorMaker->on_zoom_100_realize(theButton);
}

G_MODULE_EXPORT void
on_zoom_fit_realize(GtkToolButton *theButton, gpointer theUser_data)
{
	floorMaker->on_zoom_fit_realize(theButton);
}

G_MODULE_EXPORT void
on_zoom_100_clicked(GtkToolButton *theButton, gpointer theUser_data)
{
	floorMaker->on_zoom_100_clicked();
}

G_MODULE_EXPORT void
on_zoom_fit_clicked(GtkToolButton *theButton, gpointer theUser_data)
{
	floorMaker->on_zoom_fit_clicked();
}

// SludgeFloorMaker callbacks:

G_MODULE_EXPORT void
on_filechooserbutton_realize(GtkFileChooser *theChooser, gpointer theUser_data)
{	
	floorMaker->on_filechooserbutton_realize(theChooser);
}

G_MODULE_EXPORT void
on_filechooserbutton_file_set(GtkFileChooser *theChooser, gpointer theUser_data)
{	
	floorMaker->on_filechooserbutton_file_set(theChooser);
}

G_MODULE_EXPORT void
on_colorbutton_realize(GtkColorButton *theButton, gpointer theUser_data)
{	
	floorMaker->on_colorbutton_realize(theButton);
}

G_MODULE_EXPORT void
on_colorbutton_color_set(GtkColorButton *theButton, gpointer theUser_data)
{	
	floorMaker->on_colorbutton_color_set(theButton);
}

G_MODULE_EXPORT void
on_define_borders_toggled(GtkRadioToolButton *theButton, gpointer theUser_data)
{
	floorMaker->on_mode_changed(0);
}

G_MODULE_EXPORT void
on_move_vertices_toggled(GtkRadioToolButton *theButton, gpointer theUser_data)
{
	floorMaker->on_mode_changed(1);
}

G_MODULE_EXPORT void
on_delete_vertices_toggled(GtkRadioToolButton *theButton, gpointer theUser_data)
{
	floorMaker->on_mode_changed(2);
}

G_MODULE_EXPORT void
on_split_line_toggled(GtkRadioToolButton *theButton, gpointer theUser_data)
{
	floorMaker->on_mode_changed(4);
}

G_MODULE_EXPORT void
on_split_floor_toggled(GtkRadioToolButton *theButton, gpointer theUser_data)
{
	floorMaker->on_mode_changed(5);
}

#ifdef __cplusplus
}
#endif

void printCmdlineUsage() {
	fprintf(stdout, "SLUDGE Floor Maker, usage: sludge-floormaker <floor file>\n");
}

bool parseCmdlineParameters(int argc, char *argv[]) {
	int retval = true;
	while (1)
	{
		static struct option long_options[] =
		{
			{"help",	no_argument,	   0, 'h' },
			{0,0,0,0} /* This is a filler for -1 */
		};
		int option_index = 0;
		int c = getopt_long (argc, argv, "h", long_options, &option_index);
		if (c == -1) break;
			switch (c) {
		case 'h':
		default:
			retval = false;
			break;
		}
	}
	return retval;
}

/*
 * The main function.
 */
int
main(int argc, char *argv[])
{
	char *openThisFile = argv[argc - 1];

	if (! parseCmdlineParameters(argc, argv) ) {
		printCmdlineUsage();
		return 0;
	}

	if (argc < 2) {
		openThisFile = NULL;
	} else if (! fileExists(openThisFile) ) {
		fprintf(stderr, "Floor file not found.\n");
		printCmdlineUsage();
		return -1;
	}

	// On Windows, change to the program directory to
	// make sure the necessary resource files are found:
	winChangeToProgramDir(argv[0]);

	if (!g_thread_supported ()){ g_thread_init (NULL); }
	gdk_threads_init ();
	gdk_threads_enter ();

	/*
	 * Init GTK+ and GtkGLExt.
	 */
	gtk_init (&argc, &argv);
	gtk_gl_init (&argc, &argv);

	floorMaker = new SludgeFloorMaker();

	/*
	 * Get the window manager to connect any assigned signals in the loaded Glade file to our coded functions.
	 */
	gtk_builder_connect_signals (floorMaker->theXml, NULL);

	/*
	 * Show the window.
	 */
	gtk_widget_show (floorMaker->theWindow);

	// Start the render timer.
	g_timeout_add (10000 / 60, render_timer_event, floorMaker->theDrawingarea);

	if (openThisFile != NULL) {
		floorMaker->open(openThisFile);
	}

	// Run the window manager loop.
	if (floorMaker->initSuccess)
		gtk_main ();

	delete floorMaker;

	gdk_threads_leave ();

	return 0;
}