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 #include "ConfigDialog.h"
23 #include <uilib/uilib.h>
24 #include "gtkutil/pointer.h"
26 #include "iscenegraph.h"
31 static void dialog_button_callback( ui::Widget widget, gpointer data ){
34 auto parent = widget.window();
35 loop = (int*)g_object_get_data( G_OBJECT( parent ), "loop" );
36 ret = (int*)g_object_get_data( G_OBJECT( parent ), "ret" );
39 *ret = gpointer_to_int( data );
42 static gint dialog_delete_callback( ui::Widget widget, GdkEvent* event, gpointer data ){
44 int *loop = (int *) g_object_get_data(G_OBJECT(widget), "loop");
49 // =============================================================================
50 // Color selection dialog
52 static int DoColor( PackedColour *c ){
54 int loop = 1, ret = IDCANCEL;
56 clr.red = (guint16) (GetRValue(*c) * (65535 / 255));
57 clr.blue = (guint16) (GetGValue(*c) * (65535 / 255));
58 clr.green = (guint16) (GetBValue(*c) * (65535 / 255));
60 auto dlg = ui::Widget::from(gtk_color_selection_dialog_new( "Choose Color" ));
62 gtk_window_set_transient_for( GTK_WINDOW( dlg ), GTK_WINDOW( g_pRadiantWnd ) );
63 gtk_window_set_position( GTK_WINDOW( dlg ),GTK_WIN_POS_CENTER_ON_PARENT );
64 gtk_window_set_modal( GTK_WINDOW( dlg ), TRUE );
65 gtk_color_selection_set_current_color( GTK_COLOR_SELECTION( gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dlg)) ), &clr );
66 dlg.connect( "delete_event", G_CALLBACK( dialog_delete_callback ), NULL );
67 dlg.connect( "destroy", G_CALLBACK( gtk_widget_destroy ), NULL );
69 GtkWidget *ok_button, *cancel_button;
70 g_object_get(dlg, "ok-button", &ok_button, "cancel-button", &cancel_button, nullptr);
72 ui::Widget::from(ok_button).connect( "clicked", G_CALLBACK( dialog_button_callback ), GINT_TO_POINTER( IDOK ) );
73 ui::Widget::from(cancel_button).connect( "clicked", G_CALLBACK( dialog_button_callback ), GINT_TO_POINTER( IDCANCEL ) );
74 g_object_set_data( G_OBJECT( dlg ), "loop", &loop );
75 g_object_set_data( G_OBJECT( dlg ), "ret", &ret );
83 gtk_color_selection_get_current_color( GTK_COLOR_SELECTION( gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dlg)) ), &clr );
85 gtk_grab_remove( dlg );
89 *c = RGB( clr.red / (65535 / 255), clr.green / (65535 / 255), clr.blue / (65535 / 255));
95 static void Set2DText(ui::Widget label ){
98 sprintf( s, "Line Width = %6.3f", portals.width_2d * 0.5f );
100 gtk_label_set_text( GTK_LABEL( label ), s );
103 static void Set3DText(ui::Widget label ){
106 sprintf( s, "Line Width = %6.3f", portals.width_3d * 0.5f );
108 gtk_label_set_text( GTK_LABEL( label ), s );
111 static void Set3DTransText(ui::Widget label ){
114 sprintf( s, "Polygon transparency = %d%%", (int)portals.trans_3d );
116 gtk_label_set_text( GTK_LABEL( label ), s );
119 static void SetClipText(ui::Widget label ){
122 sprintf( s, "Cubic clip range = %d", (int)portals.clip_range * 64 );
124 gtk_label_set_text( GTK_LABEL( label ), s );
127 static void OnScroll2d(ui::Adjustment adj, gpointer data ){
128 portals.width_2d = static_cast<float>( gtk_adjustment_get_value(adj) );
129 Set2DText( ui::Widget::from(data) );
131 Portals_shadersChanged();
135 static void OnScroll3d(ui::Adjustment adj, gpointer data ){
136 portals.width_3d = static_cast<float>( gtk_adjustment_get_value(adj) );
137 Set3DText( ui::Widget::from( data ) );
142 static void OnScrollTrans(ui::Adjustment adj, gpointer data ){
143 portals.trans_3d = static_cast<float>( gtk_adjustment_get_value(adj) );
144 Set3DTransText( ui::Widget::from( data ) );
149 static void OnScrollClip(ui::Adjustment adj, gpointer data ){
150 portals.clip_range = static_cast<float>( gtk_adjustment_get_value(adj) );
151 SetClipText( ui::Widget::from( data ) );
156 static void OnAntiAlias2d(ui::Widget widget, gpointer data ){
157 portals.aa_2d = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
159 Portals_shadersChanged();
164 static void OnConfig2d(ui::Widget widget, gpointer data ){
165 portals.show_2d = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
170 static void OnColor2d(ui::Widget widget, gpointer data ){
171 if ( DoColor( &portals.color_2d ) == IDOK ) {
172 Portals_shadersChanged();
178 static void OnConfig3d(ui::Widget widget, gpointer data ){
179 portals.show_3d = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
185 static void OnAntiAlias3d(ui::Widget widget, gpointer data ){
186 portals.aa_3d = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
188 Portals_shadersChanged();
192 static void OnColor3d(ui::Widget widget, gpointer data ){
193 if ( DoColor( &portals.color_3d ) == IDOK ) {
194 Portals_shadersChanged();
200 static void OnColorFog(ui::Widget widget, gpointer data ){
201 if ( DoColor( &portals.color_fog ) == IDOK ) {
202 Portals_shadersChanged();
208 static void OnFog(ui::Widget widget, gpointer data ){
209 portals.fog = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
211 Portals_shadersChanged();
215 static void OnSelchangeZbuffer(ui::Widget widget, gpointer data ){
216 portals.zbuffer = gpointer_to_int( data );
218 Portals_shadersChanged();
222 static void OnPoly(ui::Widget widget, gpointer data ){
223 portals.polygons = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) );
228 static void OnLines(ui::Widget widget, gpointer data ){
229 portals.lines = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) );
234 static void OnClip(ui::Widget widget, gpointer data ){
235 portals.clip = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
240 void DoConfigDialog(){
241 int loop = 1, ret = IDCANCEL;
243 auto dlg = ui::Window( ui::window_type::TOP );
245 gtk_window_set_transient_for( GTK_WINDOW( dlg ), GTK_WINDOW( g_pRadiantWnd ) );
246 gtk_window_set_position( GTK_WINDOW( dlg ),GTK_WIN_POS_CENTER_ON_PARENT );
247 gtk_window_set_modal( GTK_WINDOW( dlg ), TRUE );
249 gtk_window_set_title( dlg, "Portal Viewer Configuration" );
250 dlg.connect( "delete_event",
251 G_CALLBACK( dialog_delete_callback ), NULL );
252 dlg.connect( "destroy",
253 G_CALLBACK( gtk_widget_destroy ), NULL );
254 g_object_set_data( G_OBJECT( dlg ), "loop", &loop );
255 g_object_set_data( G_OBJECT( dlg ), "ret", &ret );
257 auto vbox = ui::VBox( FALSE, 5 );
260 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
262 auto frame = ui::Frame( "3D View" );
264 vbox.pack_start( frame, TRUE, TRUE, 0 );
266 auto vbox2 = ui::VBox( FALSE, 5 );
269 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 5 );
271 auto hbox = ui::HBox( FALSE, 5 );
273 vbox2.pack_start( hbox, TRUE, TRUE, 0 );
275 auto adj = ui::Adjustment( portals.width_3d, 2, 40, 1, 1, 0 );
276 auto lw3slider = ui::HScale( adj );
278 hbox.pack_start( lw3slider, TRUE, TRUE, 0 );
279 gtk_scale_set_draw_value( GTK_SCALE( lw3slider ), FALSE );
281 auto lw3label = ui::Label( "" );
283 hbox.pack_start( lw3label, FALSE, TRUE, 0 );
284 adj.connect( "value_changed", G_CALLBACK( OnScroll3d ), lw3label );
286 auto table = ui::Table( 2, 4, FALSE );
288 vbox2.pack_start( table, TRUE, TRUE, 0 );
289 gtk_table_set_row_spacings(table, 5);
290 gtk_table_set_col_spacings(table, 5);
292 auto button = ui::Button( "Color" );
294 table.attach(button, {0, 1, 0, 1}, {GTK_FILL, 0});
295 button.connect( "clicked", G_CALLBACK( OnColor3d ), NULL );
297 button = ui::Button( "Depth Color" );
299 table.attach(button, {0, 1, 1, 2}, {GTK_FILL, 0});
300 button.connect( "clicked", G_CALLBACK( OnColorFog ), NULL );
302 auto aa3check = ui::CheckButton( "Anti-Alias (May not work on some video cards)" );
304 table.attach(aa3check, {1, 4, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
305 aa3check.connect( "toggled", G_CALLBACK( OnAntiAlias3d ), NULL );
307 auto depthcheck = ui::CheckButton( "Depth Cue" );
309 table.attach(depthcheck, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
310 depthcheck.connect( "toggled", G_CALLBACK( OnFog ), NULL );
312 auto linescheck = ui::CheckButton( "Lines" );
314 table.attach(linescheck, {2, 3, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
315 linescheck.connect( "toggled", G_CALLBACK( OnLines ), NULL );
317 auto polyscheck = ui::CheckButton( "Polygons" );
319 table.attach(polyscheck, {3, 4, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
320 polyscheck.connect( "toggled", G_CALLBACK( OnPoly ), NULL );
322 auto zlist = ui::ComboBoxText(ui::New);
324 vbox2.pack_start( zlist, TRUE, FALSE, 0 );
326 gtk_combo_box_text_append_text(zlist, "Z-Buffer Test and Write (recommended for solid or no polygons)");
327 gtk_combo_box_text_append_text(zlist, "Z-Buffer Test Only (recommended for transparent polygons)");
328 gtk_combo_box_text_append_text(zlist, "Z-Buffer Off");
330 zlist.connect("changed", G_CALLBACK(+[](ui::ComboBox self, void *) {
331 OnSelchangeZbuffer(self, GINT_TO_POINTER(gtk_combo_box_get_active(self)));
334 table = ui::Table( 2, 2, FALSE );
336 vbox2.pack_start( table, TRUE, TRUE, 0 );
337 gtk_table_set_row_spacings(table, 5);
338 gtk_table_set_col_spacings(table, 5);
340 adj = ui::Adjustment( portals.trans_3d, 0, 100, 1, 1, 0 );
341 auto transslider = ui::HScale( adj );
343 table.attach(transslider, {0, 1, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
344 gtk_scale_set_draw_value( GTK_SCALE( transslider ), FALSE );
346 auto translabel = ui::Label( "" );
348 table.attach(translabel, {1, 2, 0, 1}, {GTK_FILL, 0});
349 gtk_misc_set_alignment( GTK_MISC( translabel ), 0.0, 0.0 );
350 adj.connect( "value_changed", G_CALLBACK( OnScrollTrans ), translabel );
352 adj = ui::Adjustment( portals.clip_range, 1, 128, 1, 1, 0 );
353 auto clipslider = ui::HScale( adj );
355 table.attach(clipslider, {0, 1, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
356 gtk_scale_set_draw_value( GTK_SCALE( clipslider ), FALSE );
358 auto cliplabel = ui::Label( "" );
360 table.attach(cliplabel, {1, 2, 1, 2}, {GTK_FILL, 0});
361 gtk_misc_set_alignment( GTK_MISC( cliplabel ), 0.0, 0.0 );
362 adj.connect( "value_changed", G_CALLBACK( OnScrollClip ), cliplabel );
364 hbox = ui::HBox( TRUE, 5 );
366 vbox2.pack_start( hbox, TRUE, FALSE, 0 );
368 auto show3check = ui::CheckButton( "Show" );
370 hbox.pack_start( show3check, TRUE, TRUE, 0 );
371 show3check.connect( "toggled", G_CALLBACK( OnConfig3d ), NULL );
373 auto portalcheck = ui::CheckButton( "Portal cubic clipper" );
375 hbox.pack_start( portalcheck, TRUE, TRUE, 0 );
376 portalcheck.connect( "toggled", G_CALLBACK( OnClip ), NULL );
378 frame = ui::Frame( "2D View" );
380 vbox.pack_start( frame, TRUE, TRUE, 0 );
382 vbox2 = ui::VBox( FALSE, 5 );
385 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 5 );
387 hbox = ui::HBox( FALSE, 5 );
389 vbox2.pack_start( hbox, TRUE, FALSE, 0 );
391 adj = ui::Adjustment( portals.width_2d, 2, 40, 1, 1, 0 );
392 auto lw2slider = ui::HScale( adj );
394 hbox.pack_start( lw2slider, TRUE, TRUE, 0 );
395 gtk_scale_set_draw_value( GTK_SCALE( lw2slider ), FALSE );
397 auto lw2label = ui::Label( "" );
399 hbox.pack_start( lw2label, FALSE, TRUE, 0 );
400 adj.connect( "value_changed", G_CALLBACK( OnScroll2d ), lw2label );
402 hbox = ui::HBox( FALSE, 5 );
404 vbox2.pack_start( hbox, TRUE, FALSE, 0 );
406 button = ui::Button( "Color" );
408 hbox.pack_start( button, FALSE, FALSE, 0 );
409 button.connect( "clicked", G_CALLBACK( OnColor2d ), NULL );
410 button.dimensions(60, -1);
412 auto aa2check = ui::CheckButton( "Anti-Alias (May not work on some video cards)" );
414 hbox.pack_start( aa2check, TRUE, TRUE, 0 );
415 aa2check.connect( "toggled", G_CALLBACK( OnAntiAlias2d ), NULL );
417 hbox = ui::HBox( FALSE, 5 );
419 vbox2.pack_start( hbox, TRUE, FALSE, 0 );
421 auto show2check = ui::CheckButton( "Show" );
423 hbox.pack_start( show2check, FALSE, FALSE, 0 );
424 show2check.connect( "toggled", G_CALLBACK( OnConfig2d ), NULL );
426 hbox = ui::HBox( FALSE, 5 );
428 vbox.pack_start( hbox, FALSE, FALSE, 0 );
430 button = ui::Button( "OK" );
432 hbox.pack_end(button, FALSE, FALSE, 0);
433 button.connect( "clicked",
434 G_CALLBACK( dialog_button_callback ), GINT_TO_POINTER( IDOK ) );
435 button.dimensions(60, -1);
438 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( show2check ), portals.show_2d );
439 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( aa2check ), portals.aa_2d );
440 Set2DText( lw2label );
442 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( show3check ), portals.show_3d );
443 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( depthcheck ), portals.fog );
444 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( polyscheck ), portals.polygons );
445 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( linescheck ), portals.lines );
446 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( aa3check ), portals.aa_3d );
447 gtk_combo_box_set_active(zlist, portals.zbuffer);
448 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( portalcheck ), portals.clip );
450 Set3DText( lw3label );
451 Set3DTransText( translabel );
452 SetClipText( cliplabel );
458 gtk_main_iteration();
460 gtk_grab_remove( dlg );