// Text Editor dialog
// master window widget
-static GtkWidget *text_editor = 0;
-static GtkWidget *text_widget; // slave, text widget from the gtk editor
+static ui::Window text_editor{ui::null};
+static ui::Widget text_widget{ui::null}; // slave, text widget from the gtk editor
+ static GtkTextBuffer* text_buffer_;
-static gint editor_delete( GtkWidget *widget, gpointer data ){
-/* if ( gtk_MessageBox( widget, "Close the shader editor ?", "Radiant", eMB_YESNO, eMB_ICONQUESTION ) == eIDNO ) {
+static gint editor_delete( ui::Widget widget, gpointer data ){
- if ( ui::alert( widget.window(), "Close the shader editor ?", "Radiant", ui::alert_type::YESNO, ui::alert_icon::Question ) == ui::alert_response::NO ) {
++/* if ( ui::alert( widget.window(), "Close the shader editor ?", "Radiant", ui::alert_type::YESNO, ui::alert_icon::Question ) == ui::alert_response::NO ) {
return TRUE;
}
-
+ */
- gtk_widget_hide( text_editor );
+ text_editor.hide();
return TRUE;
}
-static void editor_save( GtkWidget *widget, gpointer data ){
+static void editor_save( ui::Widget widget, gpointer data ){
FILE *f = fopen( (char*)g_object_get_data( G_OBJECT( data ), "filename" ), "w" );
- gpointer text = g_object_get_data( G_OBJECT( data ), "text" );
+ //gpointer text = g_object_get_data( G_OBJECT( data ), "text" );
if ( f == 0 ) {
- gtk_MessageBox( GTK_WIDGET( data ), "Error saving file !" );
+ ui::alert( ui::Widget::from(data).window(), "Error saving file !" );
return;
}
- char *str = gtk_editable_get_chars( GTK_EDITABLE( text ), 0, -1 );
+ /* Obtain iters for the start and end of points of the buffer */
+ GtkTextIter start;
+ GtkTextIter end;
+ gtk_text_buffer_get_start_iter (text_buffer_, &start);
+ gtk_text_buffer_get_end_iter (text_buffer_, &end);
+
+ /* Get the entire buffer text. */
+ char *str = gtk_text_buffer_get_text (text_buffer_, &start, &end, FALSE);
+
+ //char *str = gtk_editable_get_chars( GTK_EDITABLE( text ), 0, -1 );
fwrite( str, 1, strlen( str ), f );
fclose( f );
+ g_free (str);
}
-static void editor_close( GtkWidget *widget, gpointer data ){
-/* if ( gtk_MessageBox( text_editor, "Close the shader editor ?", "Radiant", eMB_YESNO, eMB_ICONQUESTION ) == eIDNO ) {
+static void editor_close( ui::Widget widget, gpointer data ){
- if ( ui::alert( text_editor.window(), "Close the shader editor ?", "Radiant", ui::alert_type::YESNO, ui::alert_icon::Question ) == ui::alert_response::NO ) {
++/* if ( ui::alert( text_editor.window(), "Close the shader editor ?", "Radiant", ui::alert_type::YESNO, ui::alert_icon::Question ) == ui::alert_response::NO ) {
return;
}
-
+ */
- gtk_widget_hide( text_editor );
+ text_editor.hide();
}
static void CreateGtkTextEditor(){
- GtkWidget *dlg;
- GtkWidget *vbox, *hbox, *button, *scr, *text;
+ auto dlg = ui::Window( ui::window_type::TOP );
- dlg = gtk_window_new( GTK_WINDOW_TOPLEVEL );
-
- g_signal_connect( G_OBJECT( dlg ), "delete_event",
+ dlg.connect( "delete_event",
G_CALLBACK( editor_delete ), 0 );
- gtk_window_set_default_size( dlg, 600, 300 );
- gtk_window_set_default_size( GTK_WINDOW( dlg ), 400, 600 );
++ gtk_window_set_default_size( dlg, 400, 300 );
- vbox = gtk_vbox_new( FALSE, 5 );
- gtk_widget_show( vbox );
- gtk_container_add( GTK_CONTAINER( dlg ), GTK_WIDGET( vbox ) );
+ auto vbox = ui::VBox( FALSE, 5 );
+ vbox.show();
+ dlg.add(vbox);
gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
- scr = gtk_scrolled_window_new( 0, 0 );
- gtk_widget_show( scr );
- gtk_box_pack_start( GTK_BOX( vbox ), scr, TRUE, TRUE, 0 );
+ auto scr = ui::ScrolledWindow(ui::New);
+ scr.show();
+ vbox.pack_start( scr, TRUE, TRUE, 0 );
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
rewind( f );
fread( buf, 1, len, f );
- gtk_window_set_title( GTK_WINDOW( text_editor ), filename );
+ gtk_window_set_title( text_editor, filename );
- GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( text_widget ) );
+ auto text_buffer = gtk_text_view_get_buffer(ui::TextView::from(text_widget));
- gtk_text_buffer_set_text( text_buffer, (char*)buf, len );
+ gtk_text_buffer_set_text( text_buffer, (char*)buf, length );
old_filename = g_object_get_data( G_OBJECT( text_editor ), "filename" );
if ( old_filename ) {
// character offset, not byte offset
gtk_text_buffer_get_iter_at_offset( text_buffer, &text_iter, cursorpos );
gtk_text_buffer_place_cursor( text_buffer, &text_iter );
+ gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW( text_widget ), &text_iter, 0, TRUE, 0, 0);
}
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
gtk_widget_queue_draw( text_widget );
#endif
#include <gdk/gdkwin32.h>
#endif
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
// use the file associations to open files instead of builtin Gtk editor
- bool g_TextEditor_useWin32Editor = true;
+ bool g_TextEditor_useWin32Editor = false;
#else
// custom shader editor
bool g_TextEditor_useCustomEditor = false;
CopiedString g_TextEditor_editorCommand( "" );
#endif
- void DoTextEditor( const char* filename, int cursorpos ){
+ void DoTextEditor( const char* filename, int cursorpos, int length ){
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
if ( g_TextEditor_useWin32Editor ) {
- globalOutputStream() << "opening file '" << filename << "' (line " << cursorpos << " info ignored)\n";
- ShellExecute( (HWND)GDK_WINDOW_HWND( gtk_widget_get_window( MainFrame_getWindow() ) ), "open", filename, 0, 0, SW_SHOW );
+ StringOutputStream path( 256 );
+ StringOutputStream modpath( 256 );
+ const char* gamename = GlobalRadiant().getGameName();
+ const char* basegame = GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
+ const char* enginePath = GlobalRadiant().getEnginePath();
+ path << enginePath << basegame << '/' << filename;
+ modpath << enginePath << gamename << '/' << filename;
+ if ( file_exists( modpath.c_str() ) ){
+ globalOutputStream() << "opening file '" << modpath.c_str() << "' (line " << cursorpos << " info ignored)\n";
- ShellExecute( (HWND)GDK_WINDOW_HWND( GTK_WIDGET( MainFrame_getWindow() )->window ), "open", modpath.c_str(), 0, 0, SW_SHOW );
++ ShellExecute( (HWND)GDK_WINDOW_HWND( gtk_widget_get_window( MainFrame_getWindow() ) ), "open", modpath.c_str(), 0, 0, SW_SHOW );
+ }
+ else if ( file_exists( path.c_str() ) ){
+ globalOutputStream() << "opening file '" << path.c_str() << "' (line " << cursorpos << " info ignored)\n";
- ShellExecute( (HWND)GDK_WINDOW_HWND( GTK_WIDGET( MainFrame_getWindow() )->window ), "open", path.c_str(), 0, 0, SW_SHOW );
++ ShellExecute( (HWND)GDK_WINDOW_HWND( gtk_widget_get_window( MainFrame_getWindow() ) ), "open", path.c_str(), 0, 0, SW_SHOW );
+ }
+ else{
+ globalOutputStream() << "Failed to open '" << filename << "\n";
+ }
+ return;
+ }
+ else{
+ StringOutputStream path( 256 );
+ StringOutputStream modpath( 256 );
+ const char* gamename = GlobalRadiant().getGameName();
+ const char* basegame = GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
+ const char* enginePath = GlobalRadiant().getEnginePath();
+ path << enginePath << basegame << '/' << filename;
+ modpath << enginePath << gamename << '/' << filename;
+ if ( file_exists( modpath.c_str() ) ){
+ globalOutputStream() << "opening file '" << modpath.c_str() << "' (line " << cursorpos << " info ignored)\n";
+ DoGtkTextEditor( modpath.c_str(), cursorpos, length );
+ }
+ else if ( file_exists( path.c_str() ) ){
+ globalOutputStream() << "opening file '" << path.c_str() << "' (line " << cursorpos << " info ignored)\n";
+ DoGtkTextEditor( path.c_str(), cursorpos, length );
+ }
+ else{
+ globalOutputStream() << "Failed to open '" << filename << "\n";
+ }
return;
}
#else
#include "string/string.h"
EMessageBoxReturn DoLightIntensityDlg( int *intensity );
-EMessageBoxReturn DoShaderTagDlg( CopiedString *tag, char* title );
-EMessageBoxReturn DoShaderInfoDlg( const char* name, const char* filename, char* title );
+EMessageBoxReturn DoShaderTagDlg( CopiedString *tag, const char* title );
+EMessageBoxReturn DoShaderInfoDlg( const char* name, const char* filename, const char* title );
EMessageBoxReturn DoTextureLayout( float *fx, float *fy );
- void DoTextEditor( const char* filename, int cursorpos );
+ void DoTextEditor( const char* filename, int cursorpos, int length );
void DoProjectSettings();
}
-LatchedInt g_Layout_viewStyle( 0, "Window Layout" );
-LatchedBool g_Layout_enableDetachableMenus( true, "Detachable Menus" );
-LatchedBool g_Layout_enablePatchToolbar( true, "Patch Toolbar" );
-LatchedBool g_Layout_enablePluginToolbar( true, "Plugin Toolbar" );
-LatchedBool g_Layout_enableFilterToolbar( true, "Filter Toolbar" );
-
+LatchedValue<int> g_Layout_viewStyle( 0, "Window Layout" );
+LatchedValue<bool> g_Layout_enableDetachableMenus( true, "Detachable Menus" );
+LatchedValue<bool> g_Layout_enablePatchToolbar( true, "Patch Toolbar" );
+LatchedValue<bool> g_Layout_enablePluginToolbar( true, "Plugin Toolbar" );
++LatchedValue<bool> g_Layout_enableFilterToolbar( true, "Filter Toolbar" );
-GtkMenuItem* create_file_menu(){
+ui::MenuItem create_file_menu(){
// File menu
- GtkMenuItem* file_menu_item = new_sub_menu_item_with_mnemonic( "_File" );
- GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( file_menu_item ) );
+ auto file_menu_item = new_sub_menu_item_with_mnemonic( "_File" );
+ auto menu = ui::Menu::from( gtk_menu_item_get_submenu( file_menu_item ) );
if ( g_Layout_enableDetachableMenus.m_value ) {
menu_tearoff( menu );
}
register_shortcuts();
- GtkMenuBar* main_menu = create_main_menu( CurrentStyle() );
- gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( main_menu ), FALSE, FALSE, 0 );
+ auto main_menu = create_main_menu( CurrentStyle() );
+ vbox.pack_start( main_menu, FALSE, FALSE, 0 );
- GtkToolbar* main_toolbar = create_main_toolbar( CurrentStyle() );
- gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( main_toolbar ), FALSE, FALSE, 0 );
+ auto main_toolbar = create_main_toolbar( CurrentStyle() );
+ vbox.pack_start( main_toolbar, FALSE, FALSE, 0 );
- GtkToolbar* plugin_toolbar = create_plugin_toolbar();
+ auto plugin_toolbar = create_plugin_toolbar();
if ( !g_Layout_enablePluginToolbar.m_value ) {
- gtk_widget_hide( GTK_WIDGET( plugin_toolbar ) );
+ plugin_toolbar.hide();
}
- gtk_toolbar_append_space( GTK_TOOLBAR( plugin_toolbar ) );
- gtk_toolbar_append_space( GTK_TOOLBAR( plugin_toolbar ) );
+
+ if ( g_Layout_enableFilterToolbar.m_value ) {
- toolbar_append_toggle_button( plugin_toolbar, "Patches (CTRL + P)", "patch_wireframe.bmp", "FilterPatches" );
- gtk_toolbar_append_space( GTK_TOOLBAR( plugin_toolbar ) );
++ auto space = [&]() {
++ auto btn = gtk_separator_tool_item_new();
++ gtk_widget_show(GTK_WIDGET(btn));
++ gtk_container_add(GTK_CONTAINER(plugin_toolbar), GTK_WIDGET(btn));
++ };
++
++ space();
+ toolbar_append_toggle_button( plugin_toolbar, "World (ALT + 1)", "f-world.bmp", "FilterWorldBrushes" );
+ toolbar_append_toggle_button( plugin_toolbar, "Details (CTRL + D)", "f-details.bmp", "FilterDetails" );
+ toolbar_append_toggle_button( plugin_toolbar, "Structural (CTRL + SHIFT + D)", "f-structural.bmp", "FilterStructural" );
- gtk_toolbar_append_space( GTK_TOOLBAR( plugin_toolbar ) );
++ toolbar_append_toggle_button( plugin_toolbar, "Patches (CTRL + P)", "patch_wireframe.png", "FilterPatches" );
++ space();
+ toolbar_append_toggle_button( plugin_toolbar, "Areaportals (ALT + 3)", "f-areaportal.bmp", "FilterAreaportals" );
+ toolbar_append_toggle_button( plugin_toolbar, "Translucent (ALT + 4)", "f-translucent.bmp", "FilterTranslucent" );
+ toolbar_append_toggle_button( plugin_toolbar, "Liquids (ALT + 5)", "f-liquids.bmp", "FilterLiquids" );
+ toolbar_append_toggle_button( plugin_toolbar, "Caulk (ALT + 6)", "f-caulk.bmp", "FilterCaulk" );
+ toolbar_append_toggle_button( plugin_toolbar, "Clips (ALT + 7)", "f-clip.bmp", "FilterClips" );
+ toolbar_append_toggle_button( plugin_toolbar, "HintsSkips (CTRL + H)", "f-hint.bmp", "FilterHintsSkips" );
+ //toolbar_append_toggle_button( plugin_toolbar, "Paths (ALT + 8)", "texture_lock.bmp", "FilterPaths" );
- toolbar_append_toggle_button( plugin_toolbar, "Lights (ALT + 0)", "lightinspector.bmp", "FilterLights" );
++ space();
+ toolbar_append_toggle_button( plugin_toolbar, "Entities (ALT + 2)", "f-entities.bmp", "FilterEntities" );
- gtk_toolbar_append_space( GTK_TOOLBAR( plugin_toolbar ) );
++ toolbar_append_toggle_button( plugin_toolbar, "Lights (ALT + 0)", "lightinspector.png", "FilterLights" );
+ toolbar_append_toggle_button( plugin_toolbar, "Models (SHIFT + M)", "f-models.bmp", "FilterModels" );
+ toolbar_append_toggle_button( plugin_toolbar, "Triggers (CTRL + SHIFT + T)", "f-triggers.bmp", "FilterTriggers" );
+ toolbar_append_toggle_button( plugin_toolbar, "Decals (SHIFT + D)", "f-decals.bmp", "FilterDecals" );
- gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( plugin_toolbar ), FALSE, FALSE, 0 );
++ space();
+ toolbar_append_button( plugin_toolbar, "InvertFilters", "f-invert.bmp", "InvertFilters" );
+ toolbar_append_button( plugin_toolbar, "ResetFilters", "f-reset.bmp", "ResetFilters" );
+ }
+ vbox.pack_start( plugin_toolbar, FALSE, FALSE, 0 );
- GtkWidget* main_statusbar = create_main_statusbar( m_pStatusLabel );
- gtk_box_pack_end( GTK_BOX( vbox ), main_statusbar, FALSE, TRUE, 2 );
+ ui::Widget main_statusbar = create_main_statusbar(reinterpret_cast<ui::Widget *>(m_pStatusLabel));
+ vbox.pack_end(main_statusbar, FALSE, TRUE, 2);
GroupDialog_constructWindow( window );
g_page_entity = GroupDialog_addPage( "Entities", EntityInspector_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Entities" ) );
}
page.appendCheckBox(
"", "Plugin Toolbar",
- LatchedBoolImportCaller( g_Layout_enablePluginToolbar ),
- BoolExportCaller( g_Layout_enablePluginToolbar.m_latched )
+ make_property( g_Layout_enablePluginToolbar )
);
- LatchedBoolImportCaller( g_Layout_enableFilterToolbar ),
- BoolExportCaller( g_Layout_enableFilterToolbar.m_latched )
+ page.appendCheckBox(
+ "", "Filter Toolbar",
++ make_property( g_Layout_enableFilterToolbar )
+ );
}
void Layout_constructPage( PreferenceGroup& group ){
Patch_registerCommands();
XYShow_registerCommands();
- typedef FreeCaller1<const Selectable&, ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
+ typedef FreeCaller<void(const Selectable&), ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
GlobalSelectionSystem().addSelectionChangeCallback( ComponentModeSelectionChangedCaller() );
- GlobalPreferenceSystem().registerPreference( "DetachableMenus", BoolImportStringCaller( g_Layout_enableDetachableMenus.m_latched ), BoolExportStringCaller( g_Layout_enableDetachableMenus.m_latched ) );
- GlobalPreferenceSystem().registerPreference( "PatchToolBar", BoolImportStringCaller( g_Layout_enablePatchToolbar.m_latched ), BoolExportStringCaller( g_Layout_enablePatchToolbar.m_latched ) );
- GlobalPreferenceSystem().registerPreference( "PluginToolBar", BoolImportStringCaller( g_Layout_enablePluginToolbar.m_latched ), BoolExportStringCaller( g_Layout_enablePluginToolbar.m_latched ) );
- GlobalPreferenceSystem().registerPreference( "FilterToolBar", BoolImportStringCaller( g_Layout_enableFilterToolbar.m_latched ), BoolExportStringCaller( g_Layout_enableFilterToolbar.m_latched ) );
- GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", IntImportStringCaller( g_Layout_viewStyle.m_latched ), IntExportStringCaller( g_Layout_viewStyle.m_latched ) );
- GlobalPreferenceSystem().registerPreference( "XYHeight", IntImportStringCaller( g_layout_globals.nXYHeight ), IntExportStringCaller( g_layout_globals.nXYHeight ) );
- GlobalPreferenceSystem().registerPreference( "XYWidth", IntImportStringCaller( g_layout_globals.nXYWidth ), IntExportStringCaller( g_layout_globals.nXYWidth ) );
- GlobalPreferenceSystem().registerPreference( "CamWidth", IntImportStringCaller( g_layout_globals.nCamWidth ), IntExportStringCaller( g_layout_globals.nCamWidth ) );
- GlobalPreferenceSystem().registerPreference( "CamHeight", IntImportStringCaller( g_layout_globals.nCamHeight ), IntExportStringCaller( g_layout_globals.nCamHeight ) );
-
- GlobalPreferenceSystem().registerPreference( "State", IntImportStringCaller( g_layout_globals.nState ), IntExportStringCaller( g_layout_globals.nState ) );
- GlobalPreferenceSystem().registerPreference( "PositionX", IntImportStringCaller( g_layout_globals.m_position.x ), IntExportStringCaller( g_layout_globals.m_position.x ) );
- GlobalPreferenceSystem().registerPreference( "PositionY", IntImportStringCaller( g_layout_globals.m_position.y ), IntExportStringCaller( g_layout_globals.m_position.y ) );
- GlobalPreferenceSystem().registerPreference( "Width", IntImportStringCaller( g_layout_globals.m_position.w ), IntExportStringCaller( g_layout_globals.m_position.w ) );
- GlobalPreferenceSystem().registerPreference( "Height", IntImportStringCaller( g_layout_globals.m_position.h ), IntExportStringCaller( g_layout_globals.m_position.h ) );
-
- GlobalPreferenceSystem().registerPreference( "CamWnd", WindowPositionTrackerImportStringCaller( g_posCamWnd ), WindowPositionTrackerExportStringCaller( g_posCamWnd ) );
- GlobalPreferenceSystem().registerPreference( "XYWnd", WindowPositionTrackerImportStringCaller( g_posXYWnd ), WindowPositionTrackerExportStringCaller( g_posXYWnd ) );
- GlobalPreferenceSystem().registerPreference( "YZWnd", WindowPositionTrackerImportStringCaller( g_posYZWnd ), WindowPositionTrackerExportStringCaller( g_posYZWnd ) );
- GlobalPreferenceSystem().registerPreference( "XZWnd", WindowPositionTrackerImportStringCaller( g_posXZWnd ), WindowPositionTrackerExportStringCaller( g_posXZWnd ) );
+ GlobalPreferenceSystem().registerPreference( "DetachableMenus", make_property_string( g_Layout_enableDetachableMenus.m_latched ) );
+ GlobalPreferenceSystem().registerPreference( "PatchToolBar", make_property_string( g_Layout_enablePatchToolbar.m_latched ) );
+ GlobalPreferenceSystem().registerPreference( "PluginToolBar", make_property_string( g_Layout_enablePluginToolbar.m_latched ) );
++ GlobalPreferenceSystem().registerPreference( "FilterToolBar", make_property_string( g_Layout_enableFilterToolbar.m_latched ) );
+ GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", make_property_string( g_Layout_viewStyle.m_latched ) );
+ GlobalPreferenceSystem().registerPreference( "XYHeight", make_property_string( g_layout_globals.nXYHeight ) );
+ GlobalPreferenceSystem().registerPreference( "XYWidth", make_property_string( g_layout_globals.nXYWidth ) );
+ GlobalPreferenceSystem().registerPreference( "CamWidth", make_property_string( g_layout_globals.nCamWidth ) );
+ GlobalPreferenceSystem().registerPreference( "CamHeight", make_property_string( g_layout_globals.nCamHeight ) );
+
+ GlobalPreferenceSystem().registerPreference( "State", make_property_string( g_layout_globals.nState ) );
+ GlobalPreferenceSystem().registerPreference( "PositionX", make_property_string( g_layout_globals.m_position.x ) );
+ GlobalPreferenceSystem().registerPreference( "PositionY", make_property_string( g_layout_globals.m_position.y ) );
+ GlobalPreferenceSystem().registerPreference( "Width", make_property_string( g_layout_globals.m_position.w ) );
+ GlobalPreferenceSystem().registerPreference( "Height", make_property_string( g_layout_globals.m_position.h ) );
+
+ GlobalPreferenceSystem().registerPreference( "CamWnd", make_property<WindowPositionTracker_String>(g_posCamWnd) );
+ GlobalPreferenceSystem().registerPreference( "XYWnd", make_property<WindowPositionTracker_String>(g_posXYWnd) );
+ GlobalPreferenceSystem().registerPreference( "YZWnd", make_property<WindowPositionTracker_String>(g_posYZWnd) );
+ GlobalPreferenceSystem().registerPreference( "XZWnd", make_property<WindowPositionTracker_String>(g_posXZWnd) );
{
const char* ENGINEPATH_ATTRIBUTE =
}
void Interface_constructPreferences( PreferencesPage& page ){
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
- page.appendCheckBox( "", "Default Text Editor", g_TextEditor_useWin32Editor );
+ page.appendCheckBox( "", "External Shader Editor", g_TextEditor_useWin32Editor );
#else
{
- GtkWidget* use_custom = page.appendCheckBox( "Text Editor", "Custom", g_TextEditor_useCustomEditor );
- GtkWidget* custom_editor = page.appendPathEntry( "Text Editor Command", g_TextEditor_editorCommand, true );
+ ui::CheckButton use_custom = page.appendCheckBox( "Text Editor", "Custom", g_TextEditor_useCustomEditor );
+ ui::Widget custom_editor = page.appendPathEntry( "Text Editor Command", g_TextEditor_editorCommand, true );
Widget_connectToggleDependency( custom_editor, use_custom );
}
#endif
}
-static void ExtrapolateTexcoords( const float *axyz, const float *ast, const float *bxyz, const float *bst, const float *cxyz, const float *cst, const float *axyz_new, float *ast_out, const float *bxyz_new, float *bst_out, const float *cxyz_new, float *cst_out ){
- vec4_t scoeffs, tcoeffs;
- float md;
- m4x4_t solvematrix;
-
- vec3_t norm;
- vec3_t dab, dac;
- VectorSubtract( bxyz, axyz, dab );
- VectorSubtract( cxyz, axyz, dac );
- CrossProduct( dab, dac, norm );
-
- // assume:
- // s = f(x, y, z)
- // s(v + norm) = s(v) when n ortho xyz
-
- // s(v) = DotProduct(v, scoeffs) + scoeffs[3]
-
- // solve:
- // scoeffs * (axyz, 1) == ast[0]
- // scoeffs * (bxyz, 1) == bst[0]
- // scoeffs * (cxyz, 1) == cst[0]
- // scoeffs * (norm, 0) == 0
- // scoeffs * [axyz, 1 | bxyz, 1 | cxyz, 1 | norm, 0] = [ast[0], bst[0], cst[0], 0]
- solvematrix[0] = axyz[0];
- solvematrix[4] = axyz[1];
- solvematrix[8] = axyz[2];
- solvematrix[12] = 1;
- solvematrix[1] = bxyz[0];
- solvematrix[5] = bxyz[1];
- solvematrix[9] = bxyz[2];
- solvematrix[13] = 1;
- solvematrix[2] = cxyz[0];
- solvematrix[6] = cxyz[1];
- solvematrix[10] = cxyz[2];
- solvematrix[14] = 1;
- solvematrix[3] = norm[0];
- solvematrix[7] = norm[1];
- solvematrix[11] = norm[2];
- solvematrix[15] = 0;
-
- md = m4_det( solvematrix );
- if ( md * md < 1e-10 ) {
- Sys_Printf( "Cannot invert some matrix, some texcoords aren't extrapolated!" );
- return;
+char *Q_strncpyz( char *dst, const char *src, size_t len ) {
+ if ( len == 0 ) {
+ abort();
}
- m4x4_invert( solvematrix );
-
- scoeffs[0] = ast[0];
- scoeffs[1] = bst[0];
- scoeffs[2] = cst[0];
- scoeffs[3] = 0;
- m4x4_transform_vec4( solvematrix, scoeffs );
- tcoeffs[0] = ast[1];
- tcoeffs[1] = bst[1];
- tcoeffs[2] = cst[1];
- tcoeffs[3] = 0;
- m4x4_transform_vec4( solvematrix, tcoeffs );
-
- ast_out[0] = scoeffs[0] * axyz_new[0] + scoeffs[1] * axyz_new[1] + scoeffs[2] * axyz_new[2] + scoeffs[3];
- ast_out[1] = tcoeffs[0] * axyz_new[0] + tcoeffs[1] * axyz_new[1] + tcoeffs[2] * axyz_new[2] + tcoeffs[3];
- bst_out[0] = scoeffs[0] * bxyz_new[0] + scoeffs[1] * bxyz_new[1] + scoeffs[2] * bxyz_new[2] + scoeffs[3];
- bst_out[1] = tcoeffs[0] * bxyz_new[0] + tcoeffs[1] * bxyz_new[1] + tcoeffs[2] * bxyz_new[2] + tcoeffs[3];
- cst_out[0] = scoeffs[0] * cxyz_new[0] + scoeffs[1] * cxyz_new[1] + scoeffs[2] * cxyz_new[2] + scoeffs[3];
- cst_out[1] = tcoeffs[0] * cxyz_new[0] + tcoeffs[1] * cxyz_new[1] + tcoeffs[2] * cxyz_new[2] + tcoeffs[3];
+ strncpy( dst, src, len );
+ dst[ len - 1 ] = '\0';
+ return dst;
}
-/*
- ScaleBSPMain()
- amaze and confuse your enemies with wierd scaled maps!
- */
-
-int ScaleBSPMain( int argc, char **argv ){
- int i, j;
- float f, a;
- vec3_t scale;
- vec3_t vec;
- char str[ 1024 ];
- int uniform, axis;
- qboolean texscale;
- float *old_xyzst = NULL;
- float spawn_ref = 0;
-
-
- /* arg checking */
- if ( argc < 3 ) {
- Sys_Printf( "Usage: q3map [-v] -scale [-tex] [-spawn_ref <value>] <value> <mapname>\n" );
- return 0;
- }
-
- texscale = qfalse;
- for ( i = 1; i < argc - 2; ++i )
- {
- if ( !strcmp( argv[i], "-tex" ) ) {
- texscale = qtrue;
- }
- else if ( !strcmp( argv[i], "-spawn_ref" ) ) {
- spawn_ref = atof( argv[i + 1] );
- ++i;
- }
- else{
- break;
- }
- }
-
- /* get scale */
- // if(argc-2 >= i) // always true
- scale[2] = scale[1] = scale[0] = atof( argv[ argc - 2 ] );
- if ( argc - 3 >= i ) {
- scale[1] = scale[0] = atof( argv[ argc - 3 ] );
- }
- if ( argc - 4 >= i ) {
- scale[0] = atof( argv[ argc - 4 ] );
- }
-
- uniform = ( ( scale[0] == scale[1] ) && ( scale[1] == scale[2] ) );
-
- if ( scale[0] == 0.0f || scale[1] == 0.0f || scale[2] == 0.0f ) {
- Sys_Printf( "Usage: q3map [-v] -scale [-tex] [-spawn_ref <value>] <value> <mapname>\n" );
- Sys_Printf( "Non-zero scale value required.\n" );
- return 0;
- }
-
- /* do some path mangling */
- strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
- StripExtension( source );
- DefaultExtension( source, ".bsp" );
-
- /* load the bsp */
- Sys_Printf( "Loading %s\n", source );
- LoadBSPFile( source );
- ParseEntities();
-
- /* note it */
- Sys_Printf( "--- ScaleBSP ---\n" );
- Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
-
- /* scale entity keys */
- for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
- {
- /* scale origin */
- GetVectorForKey( &entities[ i ], "origin", vec );
- if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) {
- if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
- vec[2] += spawn_ref;
- }
- vec[0] *= scale[0];
- vec[1] *= scale[1];
- vec[2] *= scale[2];
- if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
- vec[2] -= spawn_ref;
- }
- sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
- SetKeyValue( &entities[ i ], "origin", str );
- }
-
- a = FloatForKey( &entities[ i ], "angle" );
- if ( a == -1 || a == -2 ) { // z scale
- axis = 2;
- }
- else if ( fabs( sin( DEG2RAD( a ) ) ) < 0.707 ) {
- axis = 0;
- }
- else{
- axis = 1;
- }
-
- /* scale door lip */
- f = FloatForKey( &entities[ i ], "lip" );
- if ( f ) {
- f *= scale[axis];
- sprintf( str, "%f", f );
- SetKeyValue( &entities[ i ], "lip", str );
- }
- /* scale plat height */
- f = FloatForKey( &entities[ i ], "height" );
- if ( f ) {
- f *= scale[2];
- sprintf( str, "%f", f );
- SetKeyValue( &entities[ i ], "height", str );
- }
+char *Q_strcat( char *dst, size_t dlen, const char *src ) {
- size_t n = strlen( dst );
++ size_t n = strlen( dst );
- // TODO maybe allow a definition file for entities to specify which values are scaled how?
+ if ( n > dlen ) {
+ abort(); /* buffer overflow */
}
- /* scale models */
- for ( i = 0; i < numBSPModels; i++ )
- {
- bspModels[ i ].mins[0] *= scale[0];
- bspModels[ i ].mins[1] *= scale[1];
- bspModels[ i ].mins[2] *= scale[2];
- bspModels[ i ].maxs[0] *= scale[0];
- bspModels[ i ].maxs[1] *= scale[1];
- bspModels[ i ].maxs[2] *= scale[2];
- }
+ return Q_strncpyz( dst + n, src, dlen - n );
+}
- /* scale nodes */
- for ( i = 0; i < numBSPNodes; i++ )
- {
- bspNodes[ i ].mins[0] *= scale[0];
- bspNodes[ i ].mins[1] *= scale[1];
- bspNodes[ i ].mins[2] *= scale[2];
- bspNodes[ i ].maxs[0] *= scale[0];
- bspNodes[ i ].maxs[1] *= scale[1];
- bspNodes[ i ].maxs[2] *= scale[2];
- }
- /* scale leafs */
- for ( i = 0; i < numBSPLeafs; i++ )
- {
- bspLeafs[ i ].mins[0] *= scale[0];
- bspLeafs[ i ].mins[1] *= scale[1];
- bspLeafs[ i ].mins[2] *= scale[2];
- bspLeafs[ i ].maxs[0] *= scale[0];
- bspLeafs[ i ].maxs[1] *= scale[1];
- bspLeafs[ i ].maxs[2] *= scale[2];
- }
+char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
+ size_t n = strlen( dst );
- if ( texscale ) {
- Sys_Printf( "Using texture unlocking (and probably breaking texture alignment a lot)\n" );
- old_xyzst = safe_malloc( sizeof( *old_xyzst ) * numBSPDrawVerts * 5 );
- for ( i = 0; i < numBSPDrawVerts; i++ )
- {
- old_xyzst[5 * i + 0] = bspDrawVerts[i].xyz[0];
- old_xyzst[5 * i + 1] = bspDrawVerts[i].xyz[1];
- old_xyzst[5 * i + 2] = bspDrawVerts[i].xyz[2];
- old_xyzst[5 * i + 3] = bspDrawVerts[i].st[0];
- old_xyzst[5 * i + 4] = bspDrawVerts[i].st[1];
- }
+ if ( n > dlen ) {
+ abort(); /* buffer overflow */
}
- /* scale drawverts */
- for ( i = 0; i < numBSPDrawVerts; i++ )
- {
- bspDrawVerts[i].xyz[0] *= scale[0];
- bspDrawVerts[i].xyz[1] *= scale[1];
- bspDrawVerts[i].xyz[2] *= scale[2];
- bspDrawVerts[i].normal[0] /= scale[0];
- bspDrawVerts[i].normal[1] /= scale[1];
- bspDrawVerts[i].normal[2] /= scale[2];
- VectorNormalize( bspDrawVerts[i].normal, bspDrawVerts[i].normal );
- }
+ return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) );
+}
- if ( texscale ) {
- for ( i = 0; i < numBSPDrawSurfaces; i++ )
- {
- switch ( bspDrawSurfaces[i].surfaceType )
- {
- case SURFACE_FACE:
- case SURFACE_META:
- if ( bspDrawSurfaces[i].numIndexes % 3 ) {
- Error( "Not a triangulation!" );
- }
- for ( j = bspDrawSurfaces[i].firstIndex; j < bspDrawSurfaces[i].firstIndex + bspDrawSurfaces[i].numIndexes; j += 3 )
- {
- int ia = bspDrawIndexes[j] + bspDrawSurfaces[i].firstVert, ib = bspDrawIndexes[j + 1] + bspDrawSurfaces[i].firstVert, ic = bspDrawIndexes[j + 2] + bspDrawSurfaces[i].firstVert;
- bspDrawVert_t *a = &bspDrawVerts[ia], *b = &bspDrawVerts[ib], *c = &bspDrawVerts[ic];
- float *oa = &old_xyzst[ia * 5], *ob = &old_xyzst[ib * 5], *oc = &old_xyzst[ic * 5];
- // extrapolate:
- // a->xyz -> oa
- // b->xyz -> ob
- // c->xyz -> oc
- ExtrapolateTexcoords(
- &oa[0], &oa[3],
- &ob[0], &ob[3],
- &oc[0], &oc[3],
- a->xyz, a->st,
- b->xyz, b->st,
- c->xyz, c->st );
- }
- break;
- }
- }
- }
- /* scale planes */
- if ( uniform ) {
- for ( i = 0; i < numBSPPlanes; i++ )
- {
- bspPlanes[ i ].dist *= scale[0];
- }
- }
- else
- {
- for ( i = 0; i < numBSPPlanes; i++ )
- {
- bspPlanes[ i ].normal[0] /= scale[0];
- bspPlanes[ i ].normal[1] /= scale[1];
- bspPlanes[ i ].normal[2] /= scale[2];
- f = 1 / VectorLength( bspPlanes[i].normal );
- VectorScale( bspPlanes[i].normal, f, bspPlanes[i].normal );
- bspPlanes[ i ].dist *= f;
- }
- }
+/*
+ ExitQ3Map()
+ cleanup routine
+ */
- /* scale gridsize */
- GetVectorForKey( &entities[ 0 ], "gridsize", vec );
- if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) {
- VectorCopy( gridSize, vec );
+static void ExitQ3Map( void ){
+ BSPFilesCleanup();
+ if ( mapDrawSurfs != NULL ) {
+ free( mapDrawSurfs );
}
- vec[0] *= scale[0];
- vec[1] *= scale[1];
- vec[2] *= scale[2];
- sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
- SetKeyValue( &entities[ 0 ], "gridsize", str );
-
- /* inject command line parameters */
- InjectCommandLine( argv, 0, argc - 1 );
-
- /* write the bsp */
- UnparseEntities();
- StripExtension( source );
- DefaultExtension( source, "_s.bsp" );
- Sys_Printf( "Writing %s\n", source );
- WriteBSPFile( source );
-
- /* return to sender */
- return 0;
}