From: Thomas Debesse Date: Sat, 4 Apr 2020 04:23:10 +0000 (+0200) Subject: contrib/prtview: center config window on main window X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=65a3391aa1e4b06a4783d801117a2920fddc706b;p=xonotic%2Fnetradiant.git contrib/prtview: center config window on main window also center color picker on config window --- diff --git a/contrib/prtview/ConfigDialog.cpp b/contrib/prtview/ConfigDialog.cpp index 1d7f2743..688a66b1 100644 --- a/contrib/prtview/ConfigDialog.cpp +++ b/contrib/prtview/ConfigDialog.cpp @@ -21,6 +21,7 @@ #include #include #include +#include "gtkutil/dialog.h" #include "gtkutil/pointer.h" #include "iscenegraph.h" @@ -28,6 +29,8 @@ #include "prtview.h" #include "portals.h" +ui::Window config_dialog{ui::null}; + static void dialog_button_callback( ui::Widget widget, gpointer data ){ int *loop, *ret; @@ -39,7 +42,7 @@ static void dialog_button_callback( ui::Widget widget, gpointer data ){ *ret = gpointer_to_int( data ); } -static gint dialog_delete_callback( ui::Widget widget, GdkEvent* event, gpointer data ){ +static gint custom_dialog_delete_callback( ui::Widget widget, GdkEvent* event, gpointer data ){ widget.hide(); int *loop = (int *) g_object_get_data(G_OBJECT(widget), "loop"); *loop = 0; @@ -58,6 +61,7 @@ static int DoColor( PackedColour *c ){ clr.green = (guint16) (GetBValue(*c) * (65535 / 255)); auto dlg = ui::Widget::from(gtk_color_selection_dialog_new( "Choose Color" )); + gtk_window_set_transient_for( GTK_WINDOW( dlg ), config_dialog ); gtk_color_selection_set_current_color( GTK_COLOR_SELECTION( gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dlg)) ), &clr ); dlg.connect( "delete_event", G_CALLBACK( dialog_delete_callback ), NULL ); dlg.connect( "destroy", G_CALLBACK( gtk_widget_destroy ), NULL ); @@ -233,17 +237,16 @@ static void OnClip(ui::Widget widget, gpointer data ){ SceneChangeNotify(); } -void DoConfigDialog(){ +void DoConfigDialog( ui::Window main_window ){ int loop = 1, ret = IDCANCEL; + ModalDialog dialog; - auto dlg = ui::Window( ui::window_type::TOP ); - gtk_window_set_title( dlg, "Portal Viewer Configuration" ); - dlg.connect( "delete_event", - G_CALLBACK( dialog_delete_callback ), NULL ); - dlg.connect( "destroy", - G_CALLBACK( gtk_widget_destroy ), NULL ); + auto dlg = main_window.create_dialog_window( "Portal Viewer Configuration", G_CALLBACK( custom_dialog_delete_callback ), &dialog ); + + dlg.connect( "destroy", G_CALLBACK( gtk_widget_destroy ), NULL ); g_object_set_data( G_OBJECT( dlg ), "loop", &loop ); g_object_set_data( G_OBJECT( dlg ), "ret", &ret ); + config_dialog = dlg; auto vbox = ui::VBox( FALSE, 5 ); vbox.show(); diff --git a/contrib/prtview/ConfigDialog.h b/contrib/prtview/ConfigDialog.h index a9725847..e17e4126 100644 --- a/contrib/prtview/ConfigDialog.h +++ b/contrib/prtview/ConfigDialog.h @@ -20,6 +20,8 @@ #if !defined( INCLUDED_CONFIGDIALOG_H ) #define INCLUDED_CONFIGDIALOG_H -void DoConfigDialog(); +#include + +void DoConfigDialog( ui::Window main_window ); #endif diff --git a/contrib/prtview/prtview.cpp b/contrib/prtview/prtview.cpp index 62aa2a9f..14aeec13 100644 --- a/contrib/prtview/prtview.cpp +++ b/contrib/prtview/prtview.cpp @@ -65,7 +65,7 @@ const char *TRANS_3D = "Transparency"; const char *CLIP_RANGE = "ClipRange"; const char *CLIP = "Clip"; -ui::Window main_window{ui::null}; +static ui::Window main_window{ui::null}; void PrtView_construct(){ StringOutputStream tmp( 64 ); @@ -282,7 +282,7 @@ void QERPlug_Dispatch( const char* p, float* vMin, float* vMax, bool bSingleBrus } } else if ( !strcmp( p,Q3R_CMD_OPTIONS ) ) { - DoConfigDialog(); + DoConfigDialog( main_window ); SaveConfig(); SceneChangeNotify();