2 PrtView plugin for GtkRadiant
3 Copyright (C) 2001 Geoffrey Dewan, Loki software and qeradiant.com
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // LoadPortalFileDialog.cpp : implementation file
23 #include "LoadPortalFileDialog.h"
26 #include <gtkutil/pointer.h>
27 #include "stream/stringstream.h"
29 #include "gtkutil/pointer.h"
31 #include "qerplugin.h"
36 static void dialog_button_callback(ui::Widget widget, gpointer data)
40 auto parent = widget.window();
41 loop = (int *) g_object_get_data(G_OBJECT(parent), "loop");
42 ret = (int *) g_object_get_data(G_OBJECT(parent), "ret");
45 *ret = gpointer_to_int(data);
48 static gint dialog_delete_callback(ui::Widget widget, GdkEvent *event, gpointer data)
51 int *loop = (int *) g_object_get_data(G_OBJECT(widget), "loop");
56 static void change_clicked(ui::Widget widget, gpointer data)
58 char *filename = NULL;
60 auto file_sel = ui::Widget::from(
61 gtk_file_chooser_dialog_new("Locate portal (.prt) file", nullptr, GTK_FILE_CHOOSER_ACTION_OPEN,
62 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
63 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
66 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(file_sel), portals.fn);
68 if (gtk_dialog_run(GTK_DIALOG (file_sel)) == GTK_RESPONSE_ACCEPT) {
69 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (file_sel));
71 ui::Widget(file_sel).destroy();
73 if (filename != NULL) {
74 strcpy(portals.fn, filename);
75 gtk_entry_set_text(GTK_ENTRY(data), filename);
80 int DoLoadPortalFileDialog()
82 int loop = 1, ret = IDCANCEL;
84 auto dlg = ui::Window(ui::window_type::TOP);
85 gtk_window_set_title(dlg, "Load .prt");
86 dlg.connect("delete_event",
87 G_CALLBACK(dialog_delete_callback), NULL);
88 dlg.connect("destroy",
89 G_CALLBACK(gtk_widget_destroy), NULL);
90 g_object_set_data(G_OBJECT(dlg), "loop", &loop);
91 g_object_set_data(G_OBJECT(dlg), "ret", &ret);
93 auto vbox = ui::VBox(FALSE, 5);
96 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
98 auto entry = ui::Entry(ui::New);
100 gtk_editable_set_editable(GTK_EDITABLE(entry), FALSE);
101 vbox.pack_start(entry, FALSE, FALSE, 0);
103 auto hbox = ui::HBox(FALSE, 5);
105 vbox.pack_start(hbox, FALSE, FALSE, 0);
107 auto check3d = ui::CheckButton("Show 3D");
109 hbox.pack_start(check3d, FALSE, FALSE, 0);
111 auto check2d = ui::CheckButton("Show 2D");
113 hbox.pack_start(check2d, FALSE, FALSE, 0);
115 auto button = ui::Button("Change");
117 hbox.pack_end(button, FALSE, FALSE, 0);
118 button.connect("clicked", G_CALLBACK(change_clicked), entry);
119 button.dimensions(60, -1);
121 hbox = ui::HBox(FALSE, 5);
123 vbox.pack_start(hbox, FALSE, FALSE, 0);
125 button = ui::Button("Cancel");
127 hbox.pack_end(button, FALSE, FALSE, 0);
128 button.connect("clicked",
129 G_CALLBACK(dialog_button_callback), GINT_TO_POINTER(IDCANCEL));
130 button.dimensions(60, -1);
132 button = ui::Button("OK");
134 hbox.pack_end(button, FALSE, FALSE, 0);
135 button.connect("clicked",
136 G_CALLBACK(dialog_button_callback), GINT_TO_POINTER(IDOK));
137 button.dimensions(60, -1);
139 strcpy(portals.fn, GlobalRadiant().getMapName());
140 char *fn = strrchr(portals.fn, '.');
145 StringOutputStream value(256);
147 gtk_entry_set_text(GTK_ENTRY(entry), value.c_str());
148 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check2d), portals.show_2d);
149 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check3d), portals.show_3d);
155 gtk_main_iteration();
161 portals.show_3d = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check3d)) ? true : false;
162 portals.show_2d = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check2d)) ? true : false;
165 gtk_grab_remove(dlg);