2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <glib/gi18n.h>
24 #include <gdk/gdkkeysyms.h>
26 #include "surfdlg_plugin.h"
28 #include "surfaceflagsdialog_ufoai.h"
33 #define MAX_BUTTONS 32
35 GtkWidget *surface_buttons[MAX_BUTTONS];
36 GtkWidget *content_buttons[MAX_BUTTONS];
38 GtkWidget *value_entry;
39 gboolean setup_buttons = TRUE;
41 int working_surface_flags;
43 int working_content_flags;
47 inline void set_inconsistent(GtkWidget *toggle_button)
49 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON (toggle_button), TRUE);
52 inline void clear_inconsistent(GtkWidget *toggle_button)
54 if ( gtk_toggle_button_get_inconsistent(GTK_TOGGLE_BUTTON (toggle_button)) )
56 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON (toggle_button), FALSE);
60 void clear_all_inconsistent(void)
64 for (i = 0; i < MAX_BUTTONS; i++) {
65 clear_inconsistent( surface_buttons[i] );
66 clear_inconsistent( content_buttons[i] );
70 void clear_all_buttons_and_values()
74 for (i = 0; i < MAX_BUTTONS; i++) {
75 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON ( surface_buttons[i] ), FALSE);
76 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON ( content_buttons[i] ), FALSE);
79 gtk_entry_set_text( (GtkEntry *)value_entry, "");
82 void SetFlagButtons_UFOAI(texdef_to_face_t *texdef_face_list, bool b_isListEmpty)
87 int diff_contents = 0;
89 gboolean diff_value = FALSE;
92 texdef_to_face_t* temp_texdef_face_list;
96 working_surface_flags = 0;
98 working_content_flags = 0;
102 if (!b_isListEmpty) {
103 tmp_texdef = &texdef_face_list->texdef;
104 contents = tmp_texdef->contents;
105 flags = tmp_texdef->flags;
106 value = tmp_texdef->value;
108 Sys_Printf("Surface: %d\tContents: %d\tValue: %d\ttmp_texdef\n",tmp_texdef->flags,tmp_texdef->contents,tmp_texdef->value);
109 Sys_Printf("Surface: %d\tContents: %d\tValue: %d\n",flags,contents,value);
111 for (temp_texdef_face_list = texdef_face_list->next; temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
113 tmp_texdef = &temp_texdef_face_list->texdef;
114 diff_contents |= contents ^ tmp_texdef->contents; // Figure out which buttons are inconsistent
115 diff_flags |= flags ^ tmp_texdef->flags;
116 if (tmp_texdef->value != value)
119 Sys_Printf("Surface: %d\tContents: %d\tValue: %d\ttmp_texdef\n",tmp_texdef->flags,tmp_texdef->contents,tmp_texdef->value);
120 Sys_Printf("Surface: %d\tContents: %d\tValue: %d\n",flags,contents,value);
124 clear_all_inconsistent();
126 // If no faces/brushes are selected, clear everything and bail
128 clear_all_buttons_and_values();
129 setup_buttons = FALSE;
133 for (i = 0; i < MAX_BUTTONS; i++) {
134 // Set surface buttons to reflect brush/face flags, contents, and values
135 if(diff_flags & (1 << i))
136 set_inconsistent(surface_buttons[i]);
137 else if(flags & (1 << i))
138 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (surface_buttons[i]), TRUE);
140 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (surface_buttons[i]), FALSE);
142 if(diff_contents & (1 << i))
143 set_inconsistent(content_buttons[i]);
144 else if(contents & (1 << i))
145 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (content_buttons[i]), TRUE);
147 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (content_buttons[i]), FALSE);
152 gtk_entry_set_text( (GtkEntry *)value_entry, "");
154 working_value = value;
155 sprintf( tex_buff, "%d", value);
156 gtk_entry_set_text( (GtkEntry *)value_entry, tex_buff);
159 setup_buttons = FALSE;
162 void SetChangeInFlags_Face_UFOAI (texdef_to_face_t *texdef_face_list)
164 texdef_to_face_t *temp_texdef_face_list;
165 texdef_t *tmp_texdef;
167 for (temp_texdef_face_list = texdef_face_list; temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
169 tmp_texdef = &temp_texdef_face_list->texdef;
170 tmp_texdef->flags = (tmp_texdef->flags & ~surface_mask) | working_surface_flags;
171 tmp_texdef->contents = (tmp_texdef->contents & ~content_mask) | working_content_flags;
172 tmp_texdef->value = working_value;
173 Sys_Printf("content_flag: %d content_mask: %d\n",working_content_flags,content_mask);
174 Sys_Printf("content: %d\n",tmp_texdef->contents);
178 inline void change_surfaceflag (GtkWidget *togglebutton, int sur_flag, gboolean change_flag_to)
180 if (!setup_buttons) // If we're setting up the buttons, we really don't need to
181 { // set flags that are already set
182 if (gtk_toggle_button_get_inconsistent(GTK_TOGGLE_BUTTON (togglebutton))) // Clear out inconsistent, if set
183 clear_inconsistent(GTK_WIDGET (togglebutton));
185 surface_mask |= sur_flag;
188 working_surface_flags |= sur_flag;
190 working_surface_flags &= ~sur_flag;
194 inline void change_contentflag (GtkWidget *togglebutton, int content_flag, gboolean change_flag_to)
196 if ( (!setup_buttons) ) // If we're setting up the buttons, we really don't need to
197 { // set flags that are already set
198 if (gtk_toggle_button_get_inconsistent(GTK_TOGGLE_BUTTON (togglebutton)))
199 clear_inconsistent(togglebutton);
200 //if (g_ptrSelectedFaces.GetSize() == 0) // Only changing content flags on whole brushes, not faces.
202 content_mask |= content_flag;
205 working_content_flags |= content_flag;
207 working_content_flags &= ~content_flag;
209 Sys_Printf("content_flag: %d content_mask: %d\n",content_flag,content_mask);
213 // Surface Flags Callbacks
214 void on_surface_button_toggled (GtkToggleButton *togglebutton, gpointer user_data)
216 int flag = GPOINTER_TO_INT(user_data);
217 change_surfaceflag(GTK_WIDGET (togglebutton), flag, (GTK_TOGGLE_BUTTON (togglebutton)->active));
220 // Content Flags Callbacks
221 void on_content_button_toggled (GtkToggleButton *togglebutton, gpointer user_data)
223 int flag = GPOINTER_TO_INT(user_data);
224 change_contentflag(GTK_WIDGET (togglebutton), flag, (GTK_TOGGLE_BUTTON (togglebutton)->active));
227 // Value Entry Callback
228 void on_value_entry_changed (GtkEditable *editable, gpointer user_data)
230 if ( (!setup_buttons) ) // If we're setting up the buttons, don't change value
231 working_value = atoi( gtk_entry_get_text( (GtkEntry*)editable) );
234 void on_value_entry_insert_text (GtkEditable *editable, gchar *new_text, gint new_text_length, gint *position, gpointer user_data)
239 // Limit input to digits, throwing out anything else
240 // Modified from Gtk FAQ for text filtering of GtkEntry
241 result = g_new (gchar, new_text_length);
243 for (i=0; i < new_text_length; i++) {
244 if (!isdigit(new_text[i]))
246 result[count++] = new_text[i];
250 gtk_signal_handler_block_by_func (GTK_OBJECT (editable),
251 GTK_SIGNAL_FUNC (on_value_entry_insert_text),
253 gtk_editable_insert_text (editable, result, count, position);
254 gtk_signal_handler_unblock_by_func (GTK_OBJECT (editable),
255 GTK_SIGNAL_FUNC (on_value_entry_insert_text),
258 gtk_signal_emit_stop_by_name (GTK_OBJECT (editable), "insert_text");
263 void on_surfacebutton_clicked (GtkButton *button, gpointer user_data)
265 gtk_notebook_set_page (GTK_NOTEBOOK(notebook1), 0);
268 void on_contentbutton_clicked (GtkButton *button, gpointer user_data)
270 gtk_notebook_set_page (GTK_NOTEBOOK(notebook1), 1);
273 #define UFOAI_FLAG_BUTTON_BORDER 3
275 GtkWidget* Create_UFOAIFlagsDialog (GtkWidget* surfacedialog_widget)
285 GtkWidget *hseparator1;
286 GtkWidget *value_label;
291 const char *buttonLabel;
294 frame1 = gtk_frame_new ("Flags");
295 gtk_widget_show (frame1);
296 gtk_container_add (GTK_CONTAINER (surfacedialog_widget), frame1);
298 vbox1 = gtk_vbox_new (FALSE, 0);
299 gtk_widget_show (vbox1);
300 gtk_container_add (GTK_CONTAINER (frame1), vbox1);
302 notebook1 = gtk_notebook_new ();
303 gtk_widget_show (notebook1);
304 gtk_box_pack_start (GTK_BOX (vbox1), notebook1, TRUE, TRUE, 0);
305 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook1), TRUE);
306 gtk_container_set_border_width (GTK_CONTAINER (notebook1), 5);
308 vbox2 = gtk_vbox_new (FALSE, 0);
309 gtk_widget_show (vbox2);
310 gtk_container_add (GTK_CONTAINER (notebook1), vbox2);
312 table4 = gtk_table_new (8, 4, FALSE);
313 gtk_widget_show (table4);
314 gtk_box_pack_start (GTK_BOX (vbox2), table4, TRUE, TRUE, 0);
317 for (i = 0; i < MAX_BUTTONS; i++) {
321 snprintf(buffer, sizeof(buffer) - 1, "surf%i", i + 1);
322 buttonLabel = g_FuncTable.m_pfnReadProjectKey(buffer);
323 Sys_Printf("%s: %s\n", buffer, buttonLabel);
324 surface_buttons[i] = gtk_toggle_button_new_with_label (buttonLabel);
325 gtk_signal_connect(GTK_OBJECT (surface_buttons[i]), "toggled", GTK_SIGNAL_FUNC(on_surface_button_toggled), GINT_TO_POINTER(1 << i));
326 gtk_widget_show(surface_buttons[i]);
327 gtk_table_attach(GTK_TABLE (table4), surface_buttons[i], 0 + x, 1 + x, (0 + y), (1 + y),
328 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
329 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
330 gtk_container_set_border_width (GTK_CONTAINER (surface_buttons[i]), UFOAI_FLAG_BUTTON_BORDER);
333 hseparator1 = gtk_hseparator_new ();
334 gtk_widget_show (hseparator1);
335 gtk_box_pack_start (GTK_BOX (vbox2), hseparator1, FALSE, FALSE, 0);
336 gtk_widget_set_usize (hseparator1, -2, 5);
338 hbox2 = gtk_hbox_new (FALSE, 0);
339 gtk_widget_show (hbox2);
340 gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
342 hbox3 = gtk_hbox_new (FALSE, 0);
343 gtk_widget_show (hbox3);
344 gtk_box_pack_start (GTK_BOX (hbox2), hbox3, TRUE, TRUE, 0);
346 vbox4 = gtk_vbox_new (FALSE, 0);
347 gtk_widget_show (vbox4);
348 gtk_box_pack_start (GTK_BOX (hbox3), vbox4, TRUE, TRUE, 0);
350 value_label = gtk_label_new (" Value: ");
351 gtk_widget_show (value_label);
352 gtk_box_pack_start (GTK_BOX (hbox3), value_label, FALSE, FALSE, 0);
354 value_entry = gtk_entry_new ();
355 gtk_signal_connect (GTK_OBJECT (value_entry), "changed",
356 GTK_SIGNAL_FUNC (on_value_entry_changed),
358 gtk_signal_connect (GTK_OBJECT (value_entry), "insert_text",
359 GTK_SIGNAL_FUNC (on_value_entry_insert_text),
361 gtk_entry_set_max_length( (GtkEntry *)value_entry, 11);
362 gtk_widget_show (value_entry);
363 gtk_box_pack_start (GTK_BOX (hbox3), value_entry, TRUE, TRUE, 0);
365 vbox3 = gtk_vbox_new (FALSE, 0);
366 gtk_widget_show (vbox3);
367 gtk_box_pack_start (GTK_BOX (hbox3), vbox3, TRUE, TRUE, 0);
369 label5 = gtk_label_new ("Surface Flags");
370 gtk_widget_show (label5);
371 gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 0), label5);
373 table3 = gtk_table_new (8, 4, FALSE);
374 gtk_widget_show (table3);
375 gtk_container_add (GTK_CONTAINER (notebook1), table3);
378 for (i = 0; i < MAX_BUTTONS; i++) {
382 snprintf(buffer, sizeof(buffer) - 1, "cont%i", i + 1);
383 buttonLabel = g_FuncTable.m_pfnReadProjectKey(buffer);
384 content_buttons[i] = gtk_toggle_button_new_with_label(buttonLabel);
385 gtk_signal_connect(GTK_OBJECT (content_buttons[i]), "toggled", GTK_SIGNAL_FUNC (on_content_button_toggled), GINT_TO_POINTER(1 << i));
386 gtk_widget_show(content_buttons[i]);
387 gtk_table_attach(GTK_TABLE (table3), content_buttons[i], 0 + x, 1 + x, (0 + y), (1 + y),
388 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
389 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
390 gtk_container_set_border_width (GTK_CONTAINER (content_buttons[i]), UFOAI_FLAG_BUTTON_BORDER);
393 label6 = gtk_label_new ("Content Flags");
394 gtk_widget_show (label6);
395 gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 1), label6);