#include <stdio.h>
#include <gtk/gtk.h>
#include <uilib/uilib.h>
+#include "gtkutil/dialog.h"
#include "gtkutil/pointer.h"
#include "iscenegraph.h"
#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;
*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;
clr.blue = (guint16) (GetGValue(*c) * (65535 / 255));
clr.green = (guint16) (GetBValue(*c) * (65535 / 255));
- auto dlg = ui::Widget(gtk_color_selection_dialog_new( "Choose Color" ));
+ 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 );
GtkWidget *ok_button, *cancel_button;
g_object_get(dlg, "ok-button", &ok_button, "cancel-button", &cancel_button, nullptr);
- ui::Widget(ok_button).connect( "clicked", G_CALLBACK( dialog_button_callback ), GINT_TO_POINTER( IDOK ) );
- ui::Widget(cancel_button).connect( "clicked", G_CALLBACK( dialog_button_callback ), GINT_TO_POINTER( IDCANCEL ) );
+ ui::Widget::from(ok_button).connect( "clicked", G_CALLBACK( dialog_button_callback ), GINT_TO_POINTER( IDOK ) );
+ ui::Widget::from(cancel_button).connect( "clicked", G_CALLBACK( dialog_button_callback ), GINT_TO_POINTER( IDCANCEL ) );
g_object_set_data( G_OBJECT( dlg ), "loop", &loop );
g_object_set_data( G_OBJECT( dlg ), "ret", &ret );
return ret;
}
-static void Set2DText( GtkWidget* label ){
+static void Set2DText(ui::Widget label ){
char s[40];
sprintf( s, "Line Width = %6.3f", portals.width_2d * 0.5f );
gtk_label_set_text( GTK_LABEL( label ), s );
}
-static void Set3DText( GtkWidget* label ){
+static void Set3DText(ui::Widget label ){
char s[40];
sprintf( s, "Line Width = %6.3f", portals.width_3d * 0.5f );
gtk_label_set_text( GTK_LABEL( label ), s );
}
-static void Set3DTransText( GtkWidget* label ){
+static void Set3DTransText(ui::Widget label ){
char s[40];
sprintf( s, "Polygon transparency = %d%%", (int)portals.trans_3d );
gtk_label_set_text( GTK_LABEL( label ), s );
}
-static void SetClipText( GtkWidget* label ){
+static void SetClipText(ui::Widget label ){
char s[40];
sprintf( s, "Cubic clip range = %d", (int)portals.clip_range * 64 );
gtk_label_set_text( GTK_LABEL( label ), s );
}
-static void OnScroll2d( GtkAdjustment *adj, gpointer data ){
+static void OnScroll2d(ui::Adjustment adj, gpointer data ){
portals.width_2d = static_cast<float>( gtk_adjustment_get_value(adj) );
Set2DText( ui::Widget::from(data) );
SceneChangeNotify();
}
-static void OnScroll3d( GtkAdjustment *adj, gpointer data ){
+static void OnScroll3d(ui::Adjustment adj, gpointer data ){
portals.width_3d = static_cast<float>( gtk_adjustment_get_value(adj) );
Set3DText( ui::Widget::from( data ) );
SceneChangeNotify();
}
-static void OnScrollTrans( GtkAdjustment *adj, gpointer data ){
+static void OnScrollTrans(ui::Adjustment adj, gpointer data ){
portals.trans_3d = static_cast<float>( gtk_adjustment_get_value(adj) );
Set3DTransText( ui::Widget::from( data ) );
SceneChangeNotify();
}
-static void OnScrollClip( GtkAdjustment *adj, gpointer data ){
+static void OnScrollClip(ui::Adjustment adj, gpointer data ){
portals.clip_range = static_cast<float>( gtk_adjustment_get_value(adj) );
SetClipText( ui::Widget::from( data ) );
SceneChangeNotify();
}
-static void OnAntiAlias2d( GtkWidget *widget, gpointer data ){
+static void OnAntiAlias2d(ui::Widget widget, gpointer data ){
portals.aa_2d = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
Portals_shadersChanged();
SceneChangeNotify();
}
-static void OnConfig2d( GtkWidget *widget, gpointer data ){
+static void OnConfig2d(ui::Widget widget, gpointer data ){
portals.show_2d = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
SceneChangeNotify();
}
-static void OnColor2d( GtkWidget *widget, gpointer data ){
+static void OnColor2d(ui::Widget widget, gpointer data ){
if ( DoColor( &portals.color_2d ) == IDOK ) {
Portals_shadersChanged();
}
}
-static void OnConfig3d( GtkWidget *widget, gpointer data ){
+static void OnConfig3d(ui::Widget widget, gpointer data ){
portals.show_3d = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
SceneChangeNotify();
}
-static void OnAntiAlias3d( GtkWidget *widget, gpointer data ){
+static void OnAntiAlias3d(ui::Widget widget, gpointer data ){
portals.aa_3d = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
Portals_shadersChanged();
SceneChangeNotify();
}
-static void OnColor3d( GtkWidget *widget, gpointer data ){
+static void OnColor3d(ui::Widget widget, gpointer data ){
if ( DoColor( &portals.color_3d ) == IDOK ) {
Portals_shadersChanged();
}
}
-static void OnColorFog( GtkWidget *widget, gpointer data ){
+static void OnColorFog(ui::Widget widget, gpointer data ){
if ( DoColor( &portals.color_fog ) == IDOK ) {
Portals_shadersChanged();
}
}
-static void OnFog( GtkWidget *widget, gpointer data ){
+static void OnFog(ui::Widget widget, gpointer data ){
portals.fog = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
Portals_shadersChanged();
SceneChangeNotify();
}
-static void OnSelchangeZbuffer( GtkWidget *widget, gpointer data ){
+static void OnSelchangeZbuffer(ui::Widget widget, gpointer data ){
portals.zbuffer = gpointer_to_int( data );
Portals_shadersChanged();
SceneChangeNotify();
}
-static void OnPoly( GtkWidget *widget, gpointer data ){
+static void OnPoly(ui::Widget widget, gpointer data ){
portals.polygons = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) );
SceneChangeNotify();
}
-static void OnLines( GtkWidget *widget, gpointer data ){
+static void OnLines(ui::Widget widget, gpointer data ){
portals.lines = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) );
SceneChangeNotify();
}
-static void OnClip( GtkWidget *widget, gpointer data ){
+static void OnClip(ui::Widget widget, gpointer data ){
portals.clip = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( widget ) ) ? true : false;
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();
auto table = ui::Table( 2, 4, FALSE );
table.show();
vbox2.pack_start( table, TRUE, TRUE, 0 );
- gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
- gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
+ gtk_table_set_row_spacings(table, 5);
+ gtk_table_set_col_spacings(table, 5);
auto button = ui::Button( "Color" );
button.show();
- gtk_table_attach( GTK_TABLE( table ), button, 0, 1, 0, 1,
- (GtkAttachOptions) ( GTK_FILL ),
- (GtkAttachOptions) ( 0 ), 0, 0 );
+ table.attach(button, {0, 1, 0, 1}, {GTK_FILL, 0});
button.connect( "clicked", G_CALLBACK( OnColor3d ), NULL );
button = ui::Button( "Depth Color" );
button.show();
- gtk_table_attach( GTK_TABLE( table ), button, 0, 1, 1, 2,
- (GtkAttachOptions) ( GTK_FILL ),
- (GtkAttachOptions) ( 0 ), 0, 0 );
+ table.attach(button, {0, 1, 1, 2}, {GTK_FILL, 0});
button.connect( "clicked", G_CALLBACK( OnColorFog ), NULL );
auto aa3check = ui::CheckButton( "Anti-Alias (May not work on some video cards)" );
aa3check.show();
- gtk_table_attach( GTK_TABLE( table ), aa3check, 1, 4, 0, 1,
- (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
- (GtkAttachOptions) ( 0 ), 0, 0 );
+ table.attach(aa3check, {1, 4, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
aa3check.connect( "toggled", G_CALLBACK( OnAntiAlias3d ), NULL );
auto depthcheck = ui::CheckButton( "Depth Cue" );
depthcheck.show();
- gtk_table_attach( GTK_TABLE( table ), depthcheck, 1, 2, 1, 2,
- (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
- (GtkAttachOptions) ( 0 ), 0, 0 );
+ table.attach(depthcheck, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
depthcheck.connect( "toggled", G_CALLBACK( OnFog ), NULL );
auto linescheck = ui::CheckButton( "Lines" );
linescheck.show();
- gtk_table_attach( GTK_TABLE( table ), linescheck, 2, 3, 1, 2,
- (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
- (GtkAttachOptions) ( 0 ), 0, 0 );
+ table.attach(linescheck, {2, 3, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
linescheck.connect( "toggled", G_CALLBACK( OnLines ), NULL );
auto polyscheck = ui::CheckButton( "Polygons" );
polyscheck.show();
- gtk_table_attach( GTK_TABLE( table ), polyscheck, 3, 4, 1, 2,
- (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
- (GtkAttachOptions) ( 0 ), 0, 0 );
+ table.attach(polyscheck, {3, 4, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
polyscheck.connect( "toggled", G_CALLBACK( OnPoly ), NULL );
auto zlist = ui::ComboBoxText(ui::New);
table = ui::Table( 2, 2, FALSE );
table.show();
vbox2.pack_start( table, TRUE, TRUE, 0 );
- gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
- gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
+ gtk_table_set_row_spacings(table, 5);
+ gtk_table_set_col_spacings(table, 5);
adj = ui::Adjustment( portals.trans_3d, 0, 100, 1, 1, 0 );
auto transslider = ui::HScale( adj );
transslider.show();
- gtk_table_attach( GTK_TABLE( table ), transslider, 0, 1, 0, 1,
- (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
- (GtkAttachOptions) ( 0 ), 0, 0 );
+ table.attach(transslider, {0, 1, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
gtk_scale_set_draw_value( GTK_SCALE( transslider ), FALSE );
auto translabel = ui::Label( "" );
translabel.show();
- gtk_table_attach( GTK_TABLE( table ), translabel, 1, 2, 0, 1,
- (GtkAttachOptions) ( GTK_FILL ),
- (GtkAttachOptions) ( 0 ), 0, 0 );
+ table.attach(translabel, {1, 2, 0, 1}, {GTK_FILL, 0});
gtk_misc_set_alignment( GTK_MISC( translabel ), 0.0, 0.0 );
adj.connect( "value_changed", G_CALLBACK( OnScrollTrans ), translabel );
adj = ui::Adjustment( portals.clip_range, 1, 128, 1, 1, 0 );
auto clipslider = ui::HScale( adj );
clipslider.show();
- gtk_table_attach( GTK_TABLE( table ), clipslider, 0, 1, 1, 2,
- (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
- (GtkAttachOptions) ( 0 ), 0, 0 );
+ table.attach(clipslider, {0, 1, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
gtk_scale_set_draw_value( GTK_SCALE( clipslider ), FALSE );
auto cliplabel = ui::Label( "" );
cliplabel.show();
- gtk_table_attach( GTK_TABLE( table ), cliplabel, 1, 2, 1, 2,
- (GtkAttachOptions) ( GTK_FILL ),
- (GtkAttachOptions) ( 0 ), 0, 0 );
+ table.attach(cliplabel, {1, 2, 1, 2}, {GTK_FILL, 0});
gtk_misc_set_alignment( GTK_MISC( cliplabel ), 0.0, 0.0 );
adj.connect( "value_changed", G_CALLBACK( OnScrollClip ), cliplabel );
button.show();
hbox.pack_start( button, FALSE, FALSE, 0 );
button.connect( "clicked", G_CALLBACK( OnColor2d ), NULL );
- gtk_widget_set_size_request( button, 60, -1 );
+ button.dimensions(60, -1);
auto aa2check = ui::CheckButton( "Anti-Alias (May not work on some video cards)" );
aa2check.show();
hbox.pack_end(button, FALSE, FALSE, 0);
button.connect( "clicked",
G_CALLBACK( dialog_button_callback ), GINT_TO_POINTER( IDOK ) );
- gtk_widget_set_size_request( button, 60, -1 );
+ button.dimensions(60, -1);
// initialize dialog
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( show2check ), portals.show_2d );