*/
#include "sunplug.h"
+#include "globaldefs.h"
#include "debugging/debugging.h"
#include <gtk/gtk.h> // to display something with gtk (windows, buttons etc.), the whole package might not be necessary
+#define CMD_ABOUT "About..."
+
void about_plugin_window();
void MapCoordinator();
-#ifndef _WIN32
+#if !GDEF_OS_WINDOWS
// linux itoa implementation
char* itoa( int value, char* result, int base ){
// check that the base if valid
#endif
typedef struct _mapcoord_setting_packet {
- GtkSpinButton *spinner1, *spinner2, *spinner3, *spinner4;
+ ui::SpinButton spinner1{ui::null}, spinner2{ui::null}, spinner3{ui::null}, spinner4{ui::null};
Entity* worldspawn;
} mapcoord_setting_packet;
// ** GTK callback functions **
// **************************
-static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ){
+static gboolean delete_event(ui::Widget widget, GdkEvent *event, gpointer data ){
/* If you return FALSE in the "delete_event" signal handler,
* GTK will emit the "destroy" signal. Returning TRUE means
* you don't want the window to be destroyed.
}
// destroy widget if destroy signal is passed to widget
-static void destroy( GtkWidget *widget, gpointer data ){
- gtk_widget_destroy( widget );
+static void destroy( ui::Widget widget, gpointer data ){
+ widget.destroy();
}
// function for close button to destroy the toplevel widget
-static void close_window( GtkWidget *widget, gpointer data ){
- gtk_widget_destroy( gtk_widget_get_toplevel( widget ) );
+static void close_window( ui::Widget widget, gpointer data ){
+ widget.window().destroy();
}
// callback function to assign the optimal mapcoords to the spinboxes
-static void input_optimal( GtkWidget *widget, gpointer data ){
+static void input_optimal(ui::Widget widget, gpointer data ){
gtk_spin_button_set_value( msp.spinner1, minX );
gtk_spin_button_set_value( msp.spinner2, maxY );
gtk_spin_button_set_value( msp.spinner3, maxX );
}
// Spinner return value function
-gint grab_int_value( GtkSpinButton *a_spinner, gpointer user_data ) {
+gint grab_int_value(ui::SpinButton a_spinner, gpointer user_data ) {
return gtk_spin_button_get_value_as_int( a_spinner );
}
// write the values of the Spinner-Boxes to the worldspawn
-static void set_coordinates( GtkWidget *widget, gpointer data ){
+static void set_coordinates( ui::Widget widget, gpointer data ){
//Str str_min, str_max;
char buffer[10], str_min[20], str_max[20];
char MenuList[100] = "";
const char* init( void* hApp, void* pMainWidget ){
- main_window = ui::Window(GTK_WINDOW( pMainWidget ));
- return "Initializing SunPlug for GTKRadiant";
+ main_window = ui::Window::from(pMainWidget);
+ return "Initializing " PLUGIN_NAME " for " RADIANT_NAME;
}
const char* getName(){
- return "SunPlug"; // name that is shown in the menue
+ return PLUGIN_NAME; // name that is shown in the menue
}
const char* getCommandList(){
- const char about[] = "About...";
+ const char about[] = CMD_ABOUT;
const char etMapCoordinator[] = ";ET-MapCoordinator";
strcat( MenuList, about );
return "";
}
void dispatch( const char* command, float* vMin, float* vMax, bool bSingleBrush ){ // message processing
- if ( string_equal( command, "About..." ) ) {
+ if ( string_equal( command, CMD_ABOUT ) ) {
about_plugin_window();
}
if ( string_equal( command, "ET-MapCoordinator" ) ) {
_QERPluginTable m_plugin;
public:
typedef _QERPluginTable Type;
-STRING_CONSTANT( Name, "SunPlug" );
+STRING_CONSTANT( Name, PLUGIN_NAME );
SunPlugModule(){
m_plugin.m_pfnQERPlug_Init = &SunPlug::init;
// About dialog
void about_plugin_window(){
- GtkWidget *label, *button;
-
auto window = ui::Window( ui::window_type::TOP ); // create a window
- gtk_window_set_transient_for( GTK_WINDOW( window ), SunPlug::main_window ); // make the window to stay in front of the main window
+ gtk_window_set_transient_for( window, SunPlug::main_window ); // make the window to stay in front of the main window
window.connect( "delete_event", G_CALLBACK( delete_event ), NULL ); // connect the delete event
window.connect( "destroy", G_CALLBACK( destroy ), NULL ); // connect the destroy event for the window
- gtk_window_set_title( GTK_WINDOW( window ), "About SunPlug" ); // set the title of the window for the window
- gtk_window_set_resizable( GTK_WINDOW( window ), FALSE ); // don't let the user resize the window
- gtk_window_set_modal( GTK_WINDOW( window ), TRUE ); // force the user not to do something with the other windows
+ gtk_window_set_title( window, "About " PLUGIN_NAME ); // set the title of the window for the window
+ gtk_window_set_resizable( window, FALSE ); // don't let the user resize the window
+ gtk_window_set_modal( window, TRUE ); // force the user not to do something with the other windows
gtk_container_set_border_width( GTK_CONTAINER( window ), 10 ); // set the border of the window
auto vbox = ui::VBox( FALSE, 10 ); // create a box to arrange new objects vertically
window.add(vbox);
- label = ui::Label( "SunPlug v1.0 for NetRadiant 1.5\nby Topsun" ); // create a label
+ char const *label_text =
+ PLUGIN_NAME " " PLUGIN_VERSION " for "
+ RADIANT_NAME " " RADIANT_VERSION "\n\n"
+ "Written by Topsun\n\n"
+ "Built against "
+ RADIANT_NAME " " RADIANT_VERSION_STRING "\n"
+ __DATE__;
+
+ auto label = ui::Label( label_text ); // create a label
gtk_label_set_justify( GTK_LABEL( label ), GTK_JUSTIFY_LEFT ); // text align left
- gtk_box_pack_start( GTK_BOX( vbox ), label, FALSE, FALSE, 2 ); // insert the label in the box
+ vbox.pack_start( label, FALSE, FALSE, 2 ); // insert the label in the box
- button = ui::Button( "OK" ); // create a button with text
- g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( gtk_widget_destroy ), window ); // connect the click event to close the window
- gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 2 ); // insert the button in the box
+ auto button = ui::Button( "OK" ); // create a button with text
+ g_signal_connect_swapped( G_OBJECT( button ), "clicked", G_CALLBACK( gtk_widget_destroy ), (void *) window ); // connect the click event to close the window
+ vbox.pack_start( button, FALSE, FALSE, 2 ); // insert the button in the box
- gtk_window_set_position( GTK_WINDOW( window ), GTK_WIN_POS_CENTER ); // center the window on screen
+ gtk_window_set_position( window, GTK_WIN_POS_CENTER ); // center the window on screen
gtk_widget_show_all( window ); // show the window and all subelements
}
// MapCoordinator dialog window
void MapCoordinator(){
- GtkWidget *table, *label, *spinnerMinX, *spinnerMinY, *spinnerMaxX, *spinnerMaxY;
Entity *theWorldspawn = NULL;
const char *buffer;
char line[20];
// in any case we need a window to show the user what to do
auto window = ui::Window( ui::window_type::TOP ); // create the window
- gtk_window_set_transient_for( GTK_WINDOW( window ), SunPlug::main_window ); // make the window to stay in front of the main window
+ gtk_window_set_transient_for( window, SunPlug::main_window ); // make the window to stay in front of the main window
window.connect( "delete_event", G_CALLBACK( delete_event ), NULL ); // connect the delete event for the window
window.connect( "destroy", G_CALLBACK( destroy ), NULL ); // connect the destroy event for the window
- gtk_window_set_title( GTK_WINDOW( window ), "ET-MapCoordinator" ); // set the title of the window for the window
- gtk_window_set_resizable( GTK_WINDOW( window ), FALSE ); // don't let the user resize the window
- gtk_window_set_modal( GTK_WINDOW( window ), TRUE ); // force the user not to do something with the other windows
+ gtk_window_set_title( window, "ET-MapCoordinator" ); // set the title of the window for the window
+ gtk_window_set_resizable( window, FALSE ); // don't let the user resize the window
+ gtk_window_set_modal( window, TRUE ); // force the user not to do something with the other windows
gtk_container_set_border_width( GTK_CONTAINER( window ), 10 ); // set the border of the window
auto vbox = ui::VBox( FALSE, 10 ); // create a box to arrange new objects vertically
auto button = ui::Button( "Get optimal mapcoords" ); // create button with text
button.connect( "clicked", G_CALLBACK( input_optimal ), NULL ); // connect button with callback function
- gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 2 ); // insert button into vbox
+ vbox.pack_start( button, FALSE, FALSE, 2 ); // insert button into vbox
- gtk_box_pack_start( GTK_BOX( vbox ), gtk_hseparator_new(), FALSE, FALSE, 2 ); // insert separator into vbox
+ vbox.pack_start( ui::Widget::from(gtk_hseparator_new()), FALSE, FALSE, 2 ); // insert separator into vbox
- table = ui::Table( 4, 3, TRUE ); // create table
- gtk_table_set_row_spacings( GTK_TABLE( table ), 8 ); // set row spacings
- gtk_table_set_col_spacings( GTK_TABLE( table ), 8 ); // set column spacings
- gtk_box_pack_start( GTK_BOX( vbox ), table, FALSE, FALSE, 2 ); // insert table into vbox
+ auto table = ui::Table( 4, 3, TRUE ); // create table
+ gtk_table_set_row_spacings(table, 8); // set row spacings
+ gtk_table_set_col_spacings(table, 8); // set column spacings
+ vbox.pack_start( table, FALSE, FALSE, 2 ); // insert table into vbox
- label = ui::Label( "x" ); // create label
+ auto label = ui::Label( "x" ); // create label
gtk_label_set_justify( GTK_LABEL( label ), GTK_JUSTIFY_LEFT ); // align text to the left side
- gtk_table_attach_defaults( GTK_TABLE( table ), label, 1, 2, 0, 1 ); // insert label into table
+ table.attach(label, {1, 2, 0, 1}); // insert label into table
label = ui::Label( "y" ); // create label
gtk_label_set_justify( GTK_LABEL( label ), GTK_JUSTIFY_LEFT ); // align text to the left side
- gtk_table_attach_defaults( GTK_TABLE( table ), label, 2, 3, 0, 1 ); // insert label into table
+ table.attach(label, {2, 3, 0, 1}); // insert label into table
label = ui::Label( "mapcoordsmins" ); // create label
gtk_label_set_justify( GTK_LABEL( label ), GTK_JUSTIFY_LEFT ); // align text to the left side
- gtk_table_attach_defaults( GTK_TABLE( table ), label, 0, 1, 1, 2 ); // insert label into table
+ table.attach(label, {0, 1, 1, 2}); // insert label into table
- spinnerMinX = ui::SpinButton( spinner_adj_MinX, 1.0, 0 ); // create textbox wiht value spin, value and value range
- gtk_table_attach_defaults( GTK_TABLE( table ), spinnerMinX, 1, 2, 1, 2 ); // insert spinbox into table
+ auto spinnerMinX = ui::SpinButton(spinner_adj_MinX, 1.0, 0); // create textbox wiht value spin, value and value range
+ table.attach(spinnerMinX, {1, 2, 1, 2}); // insert spinbox into table
- spinnerMinY = ui::SpinButton( spinner_adj_MinY, 1.0, 0 ); // create textbox wiht value spin, value and value range
- gtk_table_attach_defaults( GTK_TABLE( table ), spinnerMinY, 2, 3, 1, 2 ); // insert spinbox into table
+ auto spinnerMinY = ui::SpinButton(spinner_adj_MinY, 1.0, 0); // create textbox wiht value spin, value and value range
+ table.attach(spinnerMinY, {2, 3, 1, 2}); // insert spinbox into table
label = ui::Label( "mapcoordsmaxs" ); // create label
gtk_label_set_justify( GTK_LABEL( label ), GTK_JUSTIFY_LEFT ); // align text to the left side
- gtk_table_attach_defaults( GTK_TABLE( table ), label, 0, 1, 2, 3 ); // insert label into table
+ table.attach(label, {0, 1, 2, 3}); // insert label into table
- spinnerMaxX = ui::SpinButton( spinner_adj_MaxX, 1.0, 0 ); // create textbox wiht value spin, value and value range
- gtk_table_attach_defaults( GTK_TABLE( table ), spinnerMaxX, 1, 2, 2, 3 ); // insert spinbox into table
+ auto spinnerMaxX = ui::SpinButton(spinner_adj_MaxX, 1.0, 0); // create textbox wiht value spin, value and value range
+ table.attach(spinnerMaxX, {1, 2, 2, 3}); // insert spinbox into table
- spinnerMaxY = ui::SpinButton( spinner_adj_MaxY, 1.0, 0 ); // create textbox wiht value spin, value and value range
- gtk_table_attach_defaults( GTK_TABLE( table ), spinnerMaxY, 2, 3, 2, 3 ); // insert spinbox into table
+ auto spinnerMaxY = ui::SpinButton(spinner_adj_MaxY, 1.0, 0); // create textbox wiht value spin, value and value range
+ table.attach(spinnerMaxY, {2, 3, 2, 3}); // insert spinbox into table
// put the references to the spinboxes and the worldspawn into the global exchange
- msp.spinner1 = GTK_SPIN_BUTTON( spinnerMinX );
- msp.spinner2 = GTK_SPIN_BUTTON( spinnerMinY );
- msp.spinner3 = GTK_SPIN_BUTTON( spinnerMaxX );
- msp.spinner4 = GTK_SPIN_BUTTON( spinnerMaxY );
+ msp.spinner1 = spinnerMinX;
+ msp.spinner2 = spinnerMinY;
+ msp.spinner3 = spinnerMaxX;
+ msp.spinner4 = spinnerMaxY;
msp.worldspawn = theWorldspawn;
button = ui::Button( "Set" ); // create button with text
button.connect( "clicked", G_CALLBACK( set_coordinates ), NULL ); // connect button with callback function
- gtk_table_attach_defaults( GTK_TABLE( table ), button, 1, 2, 3, 4 ); // insert button into table
+ table.attach(button, {1, 2, 3, 4}); // insert button into table
button = ui::Button( "Cancel" ); // create button with text
button.connect( "clicked", G_CALLBACK( close_window ), NULL ); // connect button with callback function
- gtk_table_attach_defaults( GTK_TABLE( table ), button, 2, 3, 3, 4 ); // insert button into table
+ table.attach(button, {2, 3, 3, 4}); // insert button into table
}
else {
globalOutputStream() << "SunPlug: no worldspawn found!\n"; // output error to console
- label = ui::Label( "ERROR: No worldspawn was found in the map!\nIn order to use this tool the map must have at least one brush in the worldspawn. " ); // create a label
+ auto label = ui::Label( "ERROR: No worldspawn was found in the map!\nIn order to use this tool the map must have at least one brush in the worldspawn. " ); // create a label
gtk_label_set_justify( GTK_LABEL( label ), GTK_JUSTIFY_LEFT ); // text align left
- gtk_box_pack_start( GTK_BOX( vbox ), label, FALSE, FALSE, 2 ); // insert the label in the box
+ vbox.pack_start( label, FALSE, FALSE, 2 ); // insert the label in the box
auto button = ui::Button( "OK" ); // create a button with text
button.connect( "clicked", G_CALLBACK( close_window ), NULL ); // connect the click event to close the window
- gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 2 ); // insert the button in the box
+ vbox.pack_start( button, FALSE, FALSE, 2 ); // insert the button in the box
}
- gtk_window_set_position( GTK_WINDOW( window ), GTK_WIN_POS_CENTER ); // center the window
+ gtk_window_set_position( window, GTK_WIN_POS_CENTER ); // center the window
gtk_widget_show_all( window ); // show the window and all subelements
}