From: TimePath Date: Mon, 1 Jan 2018 10:34:55 +0000 (+1100) Subject: Group import/export callbacks X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2a1cfc426e60b77c7b212d827e2592de01041266;p=xonotic%2Fnetradiant.git Group import/export callbacks --- diff --git a/include/preferencesystem.cpp b/include/preferencesystem.cpp index 1786f50b..5476f9d6 100644 --- a/include/preferencesystem.cpp +++ b/include/preferencesystem.cpp @@ -76,13 +76,13 @@ void importString( const char* value ){ m_observer.onChanged(); } typedef MemberCaller ImportStringCaller; -void exportString( StringImportCallback& importer ){ +void exportString( ImportExportCallback::Import_t& importer ){ importer( m_string.c_str() ); } -typedef MemberCaller ExportStringCaller; +typedef MemberCaller::Import_t&), &StringPreference::exportString> ExportStringCaller; }; -inline void int_export( int i, StringImportCallback& importer ){ +inline void int_export( int i, ImportExportCallback::Import_t& importer ){ char buffer[16]; sprintf( buffer, "%d", i ); importer( buffer ); @@ -114,10 +114,10 @@ void importString( const char* value ){ m_observer.onChanged(); } typedef MemberCaller ImportStringCaller; -void exportString( StringImportCallback& importer ){ +void exportString( ImportExportCallback::Import_t& importer ){ int_export( m_int, importer ); } -typedef MemberCaller ExportStringCaller; +typedef MemberCaller::Import_t&), &IntPreference::exportString> ExportStringCaller; }; class IntPreferenceImporter diff --git a/include/preferencesystem.h b/include/preferencesystem.h index 4ecbfc85..a82676ec 100644 --- a/include/preferencesystem.h +++ b/include/preferencesystem.h @@ -25,16 +25,13 @@ #include "generic/constant.h" #include "generic/callback.h" -typedef Callback StringImportCallback; -typedef Callback StringExportCallback; - class PreferenceSystem { public: INTEGER_CONSTANT( Version, 1 ); STRING_CONSTANT( Name, "preferences" ); -virtual void registerPreference( const char* name, const StringImportCallback& importer, const StringExportCallback& exporter ) = 0; +virtual void registerPreference( const char* name, const ImportExportCallback::Import_t& importer, const ImportExportCallback::Export_t& exporter ) = 0; }; #include "modulesystem.h" diff --git a/libs/generic/callback.cpp b/libs/generic/callback.cpp index 423efcea..7022e8cf 100644 --- a/libs/generic/callback.cpp +++ b/libs/generic/callback.cpp @@ -207,7 +207,7 @@ void instantiate(){ Test test; const Test& testconst = test; { - Callback a = makeCallbackF(&test0free)(); + Callback a = makeCallbackF(&test0free); Callback b = Test::Test0Caller( test ); b = makeCallback( Test::Test0(), test ); Callback c = Test::Test0ConstCaller( testconst ); @@ -221,7 +221,7 @@ void instantiate(){ } { typedef Callback TestCallback1; - TestCallback1 a = makeCallbackF(&test1free)); + TestCallback1 a = makeCallbackF(&test1free); TestCallback1 b = Test::Test1Caller( test ); b = makeCallback( Test::Test1(), test ); TestCallback1 c = Test::Test1ConstCaller( testconst ); diff --git a/libs/generic/callback.h b/libs/generic/callback.h index 03689e83..26772880 100644 --- a/libs/generic/callback.h +++ b/libs/generic/callback.h @@ -314,21 +314,12 @@ inline Callback makeCallbackF(F *func) { return Callback(reinterpret_cast(func), BindFirstOpaque>::thunk); } -// todo: remove - -using BoolImportCallback = Callback; -using BoolExportCallback = Callback; - -using IntImportCallback = Callback; -using IntExportCallback = Callback; - -using FloatImportCallback = Callback; -using FloatExportCallback = Callback; - -using StringImportCallback = Callback; -using StringExportCallback = Callback; - -using SizeImportCallback = Callback; -using SizeExportCallback = Callback; +template +struct ImportExportCallback { + using Import_t = Callback; + Import_t Import; + using Export_t = Callback &)>; + Export_t Export; +}; #endif diff --git a/libs/gtkutil/accelerator.h b/libs/gtkutil/accelerator.h index 4cbc55f4..f2be1821 100644 --- a/libs/gtkutil/accelerator.h +++ b/libs/gtkutil/accelerator.h @@ -111,8 +111,8 @@ class Toggle { public: Command m_command; -BoolExportCallback m_exportCallback; -Toggle( const Callback& callback, const Accelerator& accelerator, const BoolExportCallback& exportCallback ) : m_command( callback, accelerator ), m_exportCallback( exportCallback ){ +ImportExportCallback::Export_t m_exportCallback; +Toggle( const Callback& callback, const Accelerator& accelerator, const ImportExportCallback::Export_t& exportCallback ) : m_command( callback, accelerator ), m_exportCallback( exportCallback ){ } }; diff --git a/libs/gtkutil/widget.cpp b/libs/gtkutil/widget.cpp index 162f992a..db429083 100644 --- a/libs/gtkutil/widget.cpp +++ b/libs/gtkutil/widget.cpp @@ -39,7 +39,7 @@ bool ToggleShown::active() const } } -void ToggleShown::exportActive(const BoolImportCallback &importCallback) +void ToggleShown::exportActive(const ImportExportCallback::Import_t &importCallback) { importCallback(active()); } diff --git a/libs/gtkutil/widget.h b/libs/gtkutil/widget.h index 9592b495..0cc8da3f 100644 --- a/libs/gtkutil/widget.h +++ b/libs/gtkutil/widget.h @@ -30,11 +30,11 @@ #include "debugging/debugging.h" class ToggleItem { - BoolExportCallback m_exportCallback; - typedef std::list ImportCallbacks; + ImportExportCallback::Export_t m_exportCallback; + typedef std::list::Import_t> ImportCallbacks; ImportCallbacks m_importCallbacks; public: - ToggleItem(const BoolExportCallback &exportCallback) : m_exportCallback(exportCallback) + ToggleItem(const ImportExportCallback::Export_t &exportCallback) : m_exportCallback(exportCallback) { } @@ -45,13 +45,13 @@ public: } } - void addCallback(const BoolImportCallback &callback) + void addCallback(const ImportExportCallback::Import_t &callback) { m_importCallbacks.push_back(callback); m_exportCallback(callback); } - typedef MemberCaller AddCallbackCaller; + typedef MemberCaller::Import_t &), &ToggleItem::addCallback> AddCallbackCaller; }; class ToggleShown { @@ -77,9 +77,9 @@ public: bool active() const; - void exportActive(const BoolImportCallback &importCallback); + void exportActive(const ImportExportCallback::Import_t &importCallback); - typedef MemberCaller ActiveCaller; + typedef MemberCaller::Import_t &), &ToggleShown::exportActive> ActiveCaller; void set(bool shown); diff --git a/libs/gtkutil/window.cpp b/libs/gtkutil/window.cpp index 9276ad2d..e2d7ec39 100644 --- a/libs/gtkutil/window.cpp +++ b/libs/gtkutil/window.cpp @@ -190,7 +190,7 @@ void WindowPosition_Parse(WindowPosition &position, const char *value) } } -void WindowPosition_Write(const WindowPosition &position, const StringImportCallback &importCallback) +void WindowPosition_Write(const WindowPosition &position, const ImportExportCallback::Import_t &importCallback) { char buffer[64]; sprintf( buffer, "%d %d %d %d", position.x, position.y, position.w, position.h ); @@ -204,7 +204,7 @@ void WindowPositionTracker_importString(WindowPositionTracker &self, const char self.setPosition( position ); } -void WindowPositionTracker_exportString(const WindowPositionTracker &self, const StringImportCallback &importer) +void WindowPositionTracker_exportString(const WindowPositionTracker &self, const ImportExportCallback::Import_t &importer) { WindowPosition_Write( self.getPosition(), importer ); } diff --git a/libs/gtkutil/window.h b/libs/gtkutil/window.h index cc2a7f62..83b4c00b 100644 --- a/libs/gtkutil/window.h +++ b/libs/gtkutil/window.h @@ -70,9 +70,9 @@ void WindowPosition_Parse(WindowPosition &position, const char *value); typedef ReferenceCaller WindowPositionImportStringCaller; -void WindowPosition_Write(const WindowPosition &position, const StringImportCallback &importCallback); +void WindowPosition_Write(const WindowPosition &position, const ImportExportCallback::Import_t &importCallback); -typedef ConstReferenceCaller WindowPositionExportStringCaller; +typedef ConstReferenceCaller::Import_t &), WindowPosition_Write> WindowPositionExportStringCaller; class WindowPositionTracker { @@ -101,9 +101,9 @@ void WindowPositionTracker_importString(WindowPositionTracker &self, const char typedef ReferenceCaller WindowPositionTrackerImportStringCaller; -void WindowPositionTracker_exportString(const WindowPositionTracker &self, const StringImportCallback &importer); +void WindowPositionTracker_exportString(const WindowPositionTracker &self, const ImportExportCallback::Import_t &importer); -typedef ConstReferenceCaller WindowPositionTrackerExportStringCaller; +typedef ConstReferenceCaller::Import_t &), WindowPositionTracker_exportString> WindowPositionTrackerExportStringCaller; #endif diff --git a/libs/stringio.h b/libs/stringio.h index caf93865..0eb5d337 100644 --- a/libs/stringio.h +++ b/libs/stringio.h @@ -293,19 +293,19 @@ inline void CopiedString_importString( CopiedString& self, const char* string ){ self = string; } typedef ReferenceCaller CopiedStringImportStringCaller; -inline void CopiedString_exportString( const CopiedString& self, const StringImportCallback& importer ){ +inline void CopiedString_exportString( const CopiedString& self, const ImportExportCallback::Import_t& importer ){ importer( self.c_str() ); } -typedef ConstReferenceCaller CopiedStringExportStringCaller; +typedef ConstReferenceCaller::Import_t&), CopiedString_exportString> CopiedStringExportStringCaller; inline void Bool_importString( bool& self, const char* string ){ self = string_equal( string, "true" ); } typedef ReferenceCaller BoolImportStringCaller; -inline void Bool_exportString( const bool& self, const StringImportCallback& importer ){ +inline void Bool_exportString( const bool& self, const ImportExportCallback::Import_t& importer ){ importer( self ? "true" : "false" ); } -typedef ConstReferenceCaller BoolExportStringCaller; +typedef ConstReferenceCaller::Import_t&), Bool_exportString> BoolExportStringCaller; inline void Int_importString( int& self, const char* string ){ if ( !string_parse_int( string, self ) ) { @@ -313,12 +313,12 @@ inline void Int_importString( int& self, const char* string ){ } } typedef ReferenceCaller IntImportStringCaller; -inline void Int_exportString( const int& self, const StringImportCallback& importer ){ +inline void Int_exportString( const int& self, const ImportExportCallback::Import_t& importer ){ char buffer[16]; sprintf( buffer, "%d", self ); importer( buffer ); } -typedef ConstReferenceCaller IntExportStringCaller; +typedef ConstReferenceCaller::Import_t&), Int_exportString> IntExportStringCaller; inline void Size_importString( std::size_t& self, const char* string ){ int i; @@ -331,12 +331,12 @@ inline void Size_importString( std::size_t& self, const char* string ){ } } typedef ReferenceCaller SizeImportStringCaller; -inline void Size_exportString( const std::size_t& self, const StringImportCallback& importer ){ +inline void Size_exportString( const std::size_t& self, const ImportExportCallback::Import_t& importer ){ char buffer[16]; sprintf( buffer, "%u", Unsigned( self ) ); importer( buffer ); } -typedef ConstReferenceCaller SizeExportStringCaller; +typedef ConstReferenceCaller::Import_t&), Size_exportString> SizeExportStringCaller; inline void Float_importString( float& self, const char* string ){ if ( !string_parse_float( string, self ) ) { @@ -344,12 +344,12 @@ inline void Float_importString( float& self, const char* string ){ } } typedef ReferenceCaller FloatImportStringCaller; -inline void Float_exportString( const float& self, const StringImportCallback& importer ){ +inline void Float_exportString( const float& self, const ImportExportCallback::Import_t& importer ){ char buffer[16]; sprintf( buffer, "%g", self ); importer( buffer ); } -typedef ConstReferenceCaller FloatExportStringCaller; +typedef ConstReferenceCaller::Import_t&), Float_exportString> FloatExportStringCaller; inline void Vector3_importString( Vector3& self, const char* string ){ if ( !string_parse_vector3( string, self ) ) { @@ -357,12 +357,12 @@ inline void Vector3_importString( Vector3& self, const char* string ){ } } typedef ReferenceCaller Vector3ImportStringCaller; -inline void Vector3_exportString( const Vector3& self, const StringImportCallback& importer ){ +inline void Vector3_exportString( const Vector3& self, const ImportExportCallback::Import_t& importer ){ char buffer[64]; sprintf( buffer, "%g %g %g", self[0], self[1], self[2] ); importer( buffer ); } -typedef ConstReferenceCaller Vector3ExportStringCaller; +typedef ConstReferenceCaller::Import_t&), Vector3_exportString> Vector3ExportStringCaller; @@ -389,20 +389,20 @@ operator bool() const } }; -inline void Bool_toString( const StringImportCallback& self, bool value ){ +inline void Bool_toString( const ImportExportCallback::Import_t& self, bool value ){ Bool_exportString( value, self ); } -typedef ConstReferenceCaller BoolToString; +typedef ConstReferenceCaller::Import_t, void(bool), Bool_toString> BoolToString; template -inline StringImportCallback makeBoolStringImportCallback( const Caller& caller ){ - return StringImportCallback( caller.getEnvironment(), ImportConvert1, Caller, BoolFromString>::thunk ); +inline ImportExportCallback::Import_t makeBoolStringImportCallback( const Caller& caller ){ + return ImportExportCallback::Import_t( caller.getEnvironment(), ImportConvert1::Import_t, 0>, Caller, BoolFromString>::thunk ); } template -inline StringExportCallback makeBoolStringExportCallback( const Caller& caller ){ - return StringExportCallback( caller.getEnvironment(), ImportConvert1, Caller, BoolToString>::thunk ); +inline ImportExportCallback::Export_t makeBoolStringExportCallback( const Caller& caller ){ + return ImportExportCallback::Export_t( caller.getEnvironment(), ImportConvert1::Export_t, 0>, Caller, BoolToString>::thunk ); } @@ -419,20 +419,20 @@ operator int() const } }; -inline void Int_toString( const StringImportCallback& self, int value ){ +inline void Int_toString( const ImportExportCallback::Import_t& self, int value ){ Int_exportString( value, self ); } -typedef ConstReferenceCaller IntToString; +typedef ConstReferenceCaller::Import_t, void(int), Int_toString> IntToString; template -inline StringImportCallback makeIntStringImportCallback( const Caller& caller ){ - return StringImportCallback( caller.getEnvironment(), ImportConvert1, Caller, IntFromString>::thunk ); +inline ImportExportCallback::Import_t makeIntStringImportCallback( const Caller& caller ){ + return ImportExportCallback::Import_t( caller.getEnvironment(), ImportConvert1::Import_t, 0>, Caller, IntFromString>::thunk ); } template -inline StringExportCallback makeIntStringExportCallback( const Caller& caller ){ - return StringExportCallback( caller.getEnvironment(), ImportConvert1, Caller, IntToString>::thunk ); +inline ImportExportCallback::Export_t makeIntStringExportCallback( const Caller& caller ){ + return ImportExportCallback::Export_t( caller.getEnvironment(), ImportConvert1::Export_t, 0>, Caller, IntToString>::thunk ); } @@ -450,20 +450,20 @@ operator std::size_t() const } }; -inline void Size_toString( const StringImportCallback& self, std::size_t value ){ +inline void Size_toString( const ImportExportCallback::Import_t& self, std::size_t value ){ Size_exportString( value, self ); } -typedef ConstReferenceCaller SizeToString; +typedef ConstReferenceCaller::Import_t, void(std::size_t), Size_toString> SizeToString; template -inline StringImportCallback makeSizeStringImportCallback( const Caller& caller ){ - return StringImportCallback( caller.getEnvironment(), ImportConvert1, Caller, SizeFromString>::thunk ); +inline ImportExportCallback::Import_t makeSizeStringImportCallback( const Caller& caller ){ + return ImportExportCallback::Import_t( caller.getEnvironment(), ImportConvert1::Import_t, 0>, Caller, SizeFromString>::thunk ); } template -inline StringExportCallback makeSizeStringExportCallback( const Caller& caller ){ - return StringExportCallback( caller.getEnvironment(), ImportConvert1, Caller, SizeToString>::thunk ); +inline ImportExportCallback::Export_t makeSizeStringExportCallback( const Caller& caller ){ + return ImportExportCallback::Export_t( caller.getEnvironment(), ImportConvert1::Export_t, 0>, Caller, SizeToString>::thunk ); } #endif diff --git a/radiant/brushmodule.cpp b/radiant/brushmodule.cpp index 02e54167..fb67b498 100644 --- a/radiant/brushmodule.cpp +++ b/radiant/brushmodule.cpp @@ -34,7 +34,7 @@ #include "mainframe.h" #include "preferences.h" -LatchedBool g_useAlternativeTextureProjection( false, "Use alternative texture-projection (\"brush primitives\")" ); +LatchedValue g_useAlternativeTextureProjection( false, "Use alternative texture-projection (\"brush primitives\")" ); bool g_showAlternativeTextureProjectionOption = false; bool g_brush_always_caulk; @@ -46,15 +46,15 @@ void Face_importSnapPlanes( bool value ){ Face::m_quantise = value ? quantiseInteger : quantiseFloating; } -void Face_exportSnapPlanes( const BoolImportCallback& importer ){ +void Face_exportSnapPlanes( const ImportExportCallback::Import_t& importer ){ importer( Face::m_quantise == quantiseInteger ); } void Brush_constructPreferences( PreferencesPage& page ){ page.appendCheckBox( "", "Snap planes to integer grid", - makeCallbackF(Face_importSnapPlanes), - makeCallbackF(Face_exportSnapPlanes) + {makeCallbackF(Face_importSnapPlanes), + makeCallbackF(Face_exportSnapPlanes)} ); page.appendEntry( "Default texture scale", @@ -63,8 +63,7 @@ void Brush_constructPreferences( PreferencesPage& page ){ if ( g_showAlternativeTextureProjectionOption ) { page.appendCheckBox( "", "Use alternative texture-projection (\"brush primitives\")", - LatchedBoolImportCaller( g_useAlternativeTextureProjection ), - BoolExportCaller( g_useAlternativeTextureProjection.m_latched ) + mkImportExportCallback(g_useAlternativeTextureProjection) ); } // d1223m @@ -153,7 +152,7 @@ void Brush_Construct( EBrushType type ){ } GlobalPreferenceSystem().registerPreference( "TextureLock", BoolImportStringCaller( g_brush_texturelock_enabled ), BoolExportStringCaller( g_brush_texturelock_enabled ) ); - GlobalPreferenceSystem().registerPreference( "BrushSnapPlanes", makeBoolStringImportCallback( FreeCaller() ), makeBoolStringExportCallback( FreeCaller() ) ); + GlobalPreferenceSystem().registerPreference( "BrushSnapPlanes", makeBoolStringImportCallback( FreeCaller() ), makeBoolStringExportCallback( FreeCaller::Import_t&), Face_exportSnapPlanes>() ) ); GlobalPreferenceSystem().registerPreference( "TexdefDefaultScale", FloatImportStringCaller( g_texdef_default_scale ), FloatExportStringCaller( g_texdef_default_scale ) ); GridStatus_getTextureLockEnabled = getTextureLockEnabled; diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index 273f2b01..11ea6b23 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -1392,12 +1392,12 @@ void ShowStatsToggle(){ g_camwindow_globals_private.m_showStats ^= 1; } -void ShowStatsExport( const BoolImportCallback& importer ){ +void ShowStatsExport( const ImportExportCallback::Import_t& importer ){ importer( g_camwindow_globals_private.m_showStats ); } -FreeCaller g_show_stats_caller; -BoolExportCallback g_show_stats_callback( g_show_stats_caller ); +FreeCaller::Import_t&), ShowStatsExport> g_show_stats_caller; +ImportExportCallback::Export_t g_show_stats_callback( g_show_stats_caller ); ToggleItem g_show_stats( g_show_stats_callback ); void CamWnd::Cam_Draw(){ @@ -1767,7 +1767,7 @@ void RenderModeImport( int value ){ } typedef FreeCaller RenderModeImportCaller; -void RenderModeExport( const IntImportCallback& importer ){ +void RenderModeExport( const ImportExportCallback::Import_t& importer ){ switch ( CamWnd_GetMode() ) { case cd_wire: @@ -1784,7 +1784,7 @@ void RenderModeExport( const IntImportCallback& importer ){ break; } } -typedef FreeCaller RenderModeExportCaller; +typedef FreeCaller::Import_t&), RenderModeExport> RenderModeExportCaller; void Camera_constructPreferences( PreferencesPage& page ){ page.appendSlider( "Movement Speed", g_camwindow_globals_private.m_nMoveSpeed, TRUE, 0, 0, 100, MIN_CAM_SPEED, MAX_CAM_SPEED, 1, 10 ); @@ -1793,13 +1793,13 @@ void Camera_constructPreferences( PreferencesPage& page ){ page.appendCheckBox( "", "Invert mouse vertical axis", g_camwindow_globals_private.m_bCamInverseMouse ); page.appendCheckBox( "", "Discrete movement", - FreeCaller(), - BoolExportCaller( g_camwindow_globals_private.m_bCamDiscrete ) + {FreeCaller(), + BoolExportCaller( g_camwindow_globals_private.m_bCamDiscrete )} ); page.appendCheckBox( "", "Enable far-clip plane", - FreeCaller(), - BoolExportCaller( g_camwindow_globals_private.m_bCubicClipping ) + {FreeCaller(), + BoolExportCaller( g_camwindow_globals_private.m_bCubicClipping )} ); if ( g_pGameDescription->mGameType == "doom3" ) { @@ -1808,8 +1808,8 @@ void Camera_constructPreferences( PreferencesPage& page ){ page.appendCombo( "Render Mode", STRING_ARRAY_RANGE( render_mode ), - IntImportCallback( RenderModeImportCaller() ), - IntExportCallback( RenderModeExportCaller() ) + {ImportExportCallback::Import_t( RenderModeImportCaller() ), + ImportExportCallback::Export_t( RenderModeExportCaller() )} ); } else @@ -1819,8 +1819,8 @@ void Camera_constructPreferences( PreferencesPage& page ){ page.appendCombo( "Render Mode", STRING_ARRAY_RANGE( render_mode ), - IntImportCallback( RenderModeImportCaller() ), - IntExportCallback( RenderModeExportCaller() ) + {ImportExportCallback::Import_t( RenderModeImportCaller() ), + ImportExportCallback::Export_t( RenderModeExportCaller() )} ); } diff --git a/radiant/commands.cpp b/radiant/commands.cpp index 1fab3bdc..299958dc 100644 --- a/radiant/commands.cpp +++ b/radiant/commands.cpp @@ -87,7 +87,7 @@ typedef std::map Toggles; Toggles g_toggles; -void GlobalToggles_insert( const char* name, const Callback& callback, const BoolExportCallback& exportCallback, const Accelerator& accelerator ){ +void GlobalToggles_insert( const char* name, const Callback& callback, const ImportExportCallback::Export_t& exportCallback, const Accelerator& accelerator ){ bool added = g_toggles.insert( Toggles::value_type( name, Toggle( callback, GlobalShortcuts_insert( name, accelerator ), exportCallback ) ) ).second; ASSERT_MESSAGE( added, "toggle already registered: " << makeQuoted( name ) ); } diff --git a/radiant/commands.h b/radiant/commands.h index ec10e1d8..53f61ad1 100644 --- a/radiant/commands.h +++ b/radiant/commands.h @@ -38,7 +38,7 @@ virtual void visit( const char* name, Accelerator& accelerator ) = 0; void GlobalCommands_insert( const char* name, const Callback& callback, const Accelerator& accelerator = accelerator_null() ); const Command& GlobalCommands_find( const char* name ); -void GlobalToggles_insert( const char* name, const Callback& callback, const BoolExportCallback& exportCallback, const Accelerator& accelerator = accelerator_null() ); +void GlobalToggles_insert( const char* name, const Callback& callback, const ImportExportCallback::Export_t& exportCallback, const Accelerator& accelerator = accelerator_null() ); const Toggle& GlobalToggles_find( const char* name ); void GlobalKeyEvents_insert( const char* name, const Accelerator& accelerator, const Callback& keyDown, const Callback& keyUp ); diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp index bb8705f2..9de0a333 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -107,193 +107,206 @@ DialogSpinnerRow DialogSpinnerRow_new( const char* name, double value, double lo } - template< - typename Type_, - typename Other_, - void( *Import ) ( Type_&, Other_ ), - void( *Export ) ( Type_&, const Callback& ) - > -class ImportExport -{ + typename Type_, + typename Other_ = Type_, + class T = impexp +> +class ImportExport { public: -typedef Type_ Type; -typedef Other_ Other; + using Type = Type_; + using Other = Other_; -typedef ReferenceCaller ImportCaller; -typedef ReferenceCaller&), Export> ExportCaller; + using ImportCaller = ReferenceCaller; + using ExportCaller = ReferenceCaller &), T::Export>; }; -typedef ImportExport BoolImportExport; -typedef ImportExport IntImportExport; -typedef ImportExport SizeImportExport; -typedef ImportExport FloatImportExport; -typedef ImportExport StringImportExport; +using BoolImportExport = ImportExport; +struct BoolToggle { + static void Import(GtkToggleButton &widget, bool value) { + gtk_toggle_button_set_active(&widget, value); + } -void BoolToggleImport( GtkToggleButton& widget, bool value ){ - gtk_toggle_button_set_active( &widget, value ); -} -void BoolToggleExport( GtkToggleButton& widget, const BoolImportCallback& importCallback ){ - importCallback( gtk_toggle_button_get_active( &widget ) != FALSE ); -} -typedef ImportExport BoolToggleImportExport; + static void Export(GtkToggleButton &widget, const ImportExportCallback::Import_t &importCallback) { + importCallback(gtk_toggle_button_get_active(&widget) != FALSE); + } +}; +using BoolToggleImportExport = ImportExport; -void IntRadioImport( GtkRadioButton& widget, int index ){ - radio_button_set_active( ui::RadioButton(&widget), index ); -} -void IntRadioExport( GtkRadioButton& widget, const IntImportCallback& importCallback ){ - importCallback( radio_button_get_active( ui::RadioButton(&widget) ) ); -} -typedef ImportExport IntRadioImportExport; +using IntImportExport = ImportExport; -void TextEntryImport( GtkEntry& widget, const char* text ){ - ui::Entry(&widget).text(text); -} -void TextEntryExport( GtkEntry& widget, const StringImportCallback& importCallback ){ - importCallback( gtk_entry_get_text( &widget ) ); -} -typedef ImportExport TextEntryImportExport; +struct IntEntry { + static void Import(GtkEntry &widget, int value) { + entry_set_int(ui::Entry(&widget), value); + } + static void Export(GtkEntry &widget, const ImportExportCallback::Import_t &importCallback) { + importCallback(atoi(gtk_entry_get_text(&widget))); + } +}; -void IntEntryImport( GtkEntry& widget, int value ){ - entry_set_int( ui::Entry(&widget), value ); -} -void IntEntryExport( GtkEntry& widget, const IntImportCallback& importCallback ){ - importCallback( atoi( gtk_entry_get_text( &widget ) ) ); -} -typedef ImportExport IntEntryImportExport; +using IntEntryImportExport = ImportExport; +struct IntRadio { + static void Import(GtkRadioButton &widget, int index) { + radio_button_set_active(ui::RadioButton(&widget), index); + } -void SizeEntryImport( GtkEntry& widget, std::size_t value ){ - entry_set_int( ui::Entry(&widget), int(value) ); -} -void SizeEntryExport( GtkEntry& widget, const SizeImportCallback& importCallback ){ - int value = atoi( gtk_entry_get_text( &widget ) ); - if ( value < 0 ) { - value = 0; + static void Export(GtkRadioButton &widget, const ImportExportCallback::Import_t &importCallback) { + importCallback(radio_button_get_active(ui::RadioButton(&widget))); } - importCallback( value ); -} -typedef ImportExport SizeEntryImportExport; +}; +using IntRadioImportExport = ImportExport; -void FloatEntryImport( GtkEntry& widget, float value ){ - entry_set_float( ui::Entry(&widget), value ); -} -void FloatEntryExport( GtkEntry& widget, const FloatImportCallback& importCallback ){ - importCallback( (float)atof( gtk_entry_get_text( &widget ) ) ); -} -typedef ImportExport FloatEntryImportExport; +struct IntCombo { + static void Import(GtkComboBox &widget, int value) { + gtk_combo_box_set_active(&widget, value); + } + static void Export(GtkComboBox &widget, const ImportExportCallback::Import_t &importCallback) { + importCallback(gtk_combo_box_get_active(&widget)); + } +}; -void FloatSpinnerImport( GtkSpinButton& widget, float value ){ - gtk_spin_button_set_value( &widget, value ); -} -void FloatSpinnerExport( GtkSpinButton& widget, const FloatImportCallback& importCallback ){ - importCallback( float(gtk_spin_button_get_value( &widget ) ) ); -} -typedef ImportExport FloatSpinnerImportExport; +using IntComboImportExport = ImportExport; +struct IntAdjustment { + static void Import(GtkAdjustment &widget, int value) { + gtk_adjustment_set_value(&widget, value); + } -void IntSpinnerImport( GtkSpinButton& widget, int value ){ - gtk_spin_button_set_value( &widget, value ); -} -void IntSpinnerExport( GtkSpinButton& widget, const IntImportCallback& importCallback ){ - importCallback( gtk_spin_button_get_value_as_int( &widget ) ); -} -typedef ImportExport IntSpinnerImportExport; + static void Export(GtkAdjustment &widget, const ImportExportCallback::Import_t &importCallback) { + importCallback((int) gtk_adjustment_get_value(&widget)); + } +}; +using IntAdjustmentImportExport = ImportExport; -void IntAdjustmentImport( GtkAdjustment& widget, int value ){ - gtk_adjustment_set_value( &widget, value ); -} -void IntAdjustmentExport( GtkAdjustment& widget, const IntImportCallback& importCallback ){ - importCallback( (int)gtk_adjustment_get_value( &widget ) ); -} -typedef ImportExport IntAdjustmentImportExport; +struct IntSpinner { + static void Import(GtkSpinButton &widget, int value) { + gtk_spin_button_set_value(&widget, value); + } + static void Export(GtkSpinButton &widget, const ImportExportCallback::Import_t &importCallback) { + importCallback(gtk_spin_button_get_value_as_int(&widget)); + } +}; -void IntComboImport( GtkComboBox& widget, int value ){ - gtk_combo_box_set_active( &widget, value ); -} -void IntComboExport( GtkComboBox& widget, const IntImportCallback& importCallback ){ - importCallback( gtk_combo_box_get_active( &widget ) ); -} -typedef ImportExport IntComboImportExport; +using IntSpinnerImportExport = ImportExport; +using StringImportExport = ImportExport; -template -class CallbackDialogData : public DLG_DATA -{ -public: -typedef Callback ImportCallback; -typedef Callback ExportCallback; +struct TextEntry { + static void Import(GtkEntry &widget, const char *text) { + ui::Entry(&widget).text(text); + } + + static void Export(GtkEntry &widget, const ImportExportCallback::Import_t &importCallback) { + importCallback(gtk_entry_get_text(&widget)); + } +}; + +using TextEntryImportExport = ImportExport; + +using SizeImportExport = ImportExport; + +struct SizeEntry { + static void Import(GtkEntry &widget, std::size_t value) { + entry_set_int(ui::Entry(&widget), int(value)); + } + + static void Export(GtkEntry &widget, const ImportExportCallback::Import_t &importCallback) { + int value = atoi(gtk_entry_get_text(&widget)); + if (value < 0) { + value = 0; + } + importCallback(value); + } +}; + +using SizeEntryImportExport = ImportExport; -private: -ImportCallback m_importWidget; -ExportCallback m_exportWidget; -ImportCallback m_importViewer; -ExportCallback m_exportViewer; +using FloatImportExport = ImportExport; + +struct FloatEntry { + static void Import(GtkEntry &widget, float value) { + entry_set_float(ui::Entry(&widget), value); + } + + static void Export(GtkEntry &widget, const ImportExportCallback::Import_t &importCallback) { + importCallback((float) atof(gtk_entry_get_text(&widget))); + } +}; + +using FloatEntryImportExport = ImportExport; + +struct FloatSpinner { + static void Import(GtkSpinButton &widget, float value) { + gtk_spin_button_set_value(&widget, value); + } + + static void Export(GtkSpinButton &widget, const ImportExportCallback::Import_t &importCallback) { + importCallback(float(gtk_spin_button_get_value(&widget))); + } +}; + +using FloatSpinnerImportExport = ImportExport; + + + +template +class CallbackDialogData : public DLG_DATA { + ImportExportCallback m_cbWidget; + ImportExportCallback m_cbViewer; public: -CallbackDialogData( const ImportCallback& importWidget, const ExportCallback& exportWidget, const ImportCallback& importViewer, const ExportCallback& exportViewer ) - : m_importWidget( importWidget ), m_exportWidget( exportWidget ), m_importViewer( importViewer ), m_exportViewer( exportViewer ){ -} -void release(){ - delete this; -} -void importData() const { - m_exportViewer( m_importWidget ); -} -void exportData() const { - m_exportWidget( m_importViewer ); -} + CallbackDialogData(const ImportExportCallback &cbWidget, const ImportExportCallback &cbViewer) + : m_cbWidget(cbWidget), m_cbViewer(cbViewer) { + } + + void release() { + delete this; + } + + void importData() const { + m_cbViewer.Export(m_cbWidget.Import); + } + + void exportData() const { + m_cbWidget.Export(m_cbViewer.Import); + } }; template -class AddData -{ -DialogDataList& m_data; -public: -AddData( DialogDataList& data ) : m_data( data ){ -} -void apply( typename Widget::Type& widget, typename Viewer::Type& viewer ) const { - m_data.push_back( - new CallbackDialogData( - typename Widget::ImportCaller( widget ), - typename Widget::ExportCaller( widget ), - typename Viewer::ImportCaller( viewer ), - typename Viewer::ExportCaller( viewer ) +void AddData(DialogDataList &data, typename Widget::Type &widget, typename Viewer::Type &viewer) { + data.push_back( + new CallbackDialogData( + {typename Widget::ImportCaller(widget), + typename Widget::ExportCaller(widget)}, + {typename Viewer::ImportCaller(viewer), + typename Viewer::ExportCaller(viewer)} ) - ); + ); } -}; template -class AddCustomData -{ -DialogDataList& m_data; -public: -AddCustomData( DialogDataList& data ) : m_data( data ){ -} -void apply( - typename Widget::Type& widget, - const Callback& importViewer, - const Callback&)>& exportViewer - ) const { - m_data.push_back( - new CallbackDialogData( - typename Widget::ImportCaller( widget ), - typename Widget::ExportCaller( widget ), - importViewer, - exportViewer +void AddCustomData( + DialogDataList &data, + typename Widget::Type &widget, + ImportExportCallback const &cbViewer +) { + data.push_back( + new CallbackDialogData( + {typename Widget::ImportCaller(widget), + typename Widget::ExportCaller(widget)}, + cbViewer ) - ); + ); } -}; // ============================================================================= // Dialog class @@ -343,76 +356,76 @@ void Dialog::Destroy(){ } -void Dialog::AddBoolToggleData( GtkToggleButton& widget, const BoolImportCallback& importViewer, const BoolExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddBoolToggleData( GtkToggleButton& widget, ImportExportCallback const &cb ){ + AddCustomData( m_data, widget, cb ); } -void Dialog::AddIntRadioData( GtkRadioButton& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddIntRadioData( GtkRadioButton& widget, ImportExportCallback const &cb ){ + AddCustomData( m_data, widget, cb ); } -void Dialog::AddTextEntryData( GtkEntry& widget, const StringImportCallback& importViewer, const StringExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddTextEntryData( GtkEntry& widget, ImportExportCallback const &cb ){ + AddCustomData( m_data, widget, cb ); } -void Dialog::AddIntEntryData( GtkEntry& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddIntEntryData( GtkEntry& widget, ImportExportCallback const &cb ){ + AddCustomData( m_data, widget, cb ); } -void Dialog::AddSizeEntryData( GtkEntry& widget, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddSizeEntryData( GtkEntry& widget, ImportExportCallback const &cb ){ + AddCustomData( m_data, widget, cb ); } -void Dialog::AddFloatEntryData( GtkEntry& widget, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddFloatEntryData( GtkEntry& widget, ImportExportCallback const &cb ){ + AddCustomData( m_data, widget, cb ); } -void Dialog::AddFloatSpinnerData( GtkSpinButton& widget, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddFloatSpinnerData( GtkSpinButton& widget, ImportExportCallback const &cb ){ + AddCustomData( m_data, widget, cb ); } -void Dialog::AddIntSpinnerData( GtkSpinButton& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddIntSpinnerData( GtkSpinButton& widget, ImportExportCallback const &cb ){ + AddCustomData( m_data, widget, cb ); } -void Dialog::AddIntAdjustmentData( GtkAdjustment& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddIntAdjustmentData( GtkAdjustment& widget, ImportExportCallback const &cb ){ + AddCustomData( m_data, widget, cb ); } -void Dialog::AddIntComboData( GtkComboBox& widget, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ - AddCustomData( m_data ).apply( widget, importViewer, exportViewer ); +void Dialog::AddIntComboData( GtkComboBox& widget, ImportExportCallback const &cb ){ + AddCustomData( m_data, widget, cb ); } void Dialog::AddDialogData( GtkToggleButton& widget, bool& data ){ - AddData( m_data ).apply( widget, data ); + AddData( m_data, widget, data ); } void Dialog::AddDialogData( GtkRadioButton& widget, int& data ){ - AddData( m_data ).apply( widget, data ); + AddData( m_data, widget, data ); } void Dialog::AddDialogData( GtkEntry& widget, CopiedString& data ){ - AddData( m_data ).apply( widget, data ); + AddData( m_data, widget, data ); } void Dialog::AddDialogData( GtkEntry& widget, int& data ){ - AddData( m_data ).apply( widget, data ); + AddData( m_data, widget, data ); } void Dialog::AddDialogData( GtkEntry& widget, std::size_t& data ){ - AddData( m_data ).apply( widget, data ); + AddData( m_data, widget, data ); } void Dialog::AddDialogData( GtkEntry& widget, float& data ){ - AddData( m_data ).apply( widget, data ); + AddData( m_data, widget, data ); } void Dialog::AddDialogData( GtkSpinButton& widget, float& data ){ - AddData( m_data ).apply( widget, data ); + AddData( m_data, widget, data ); } void Dialog::AddDialogData( GtkSpinButton& widget, int& data ){ - AddData( m_data ).apply( widget, data ); + AddData( m_data, widget, data ); } void Dialog::AddDialogData( GtkAdjustment& widget, int& data ){ - AddData( m_data ).apply( widget, data ); + AddData( m_data, widget, data ); } void Dialog::AddDialogData( GtkComboBox& widget, int& data ){ - AddData( m_data ).apply( widget, data ); + AddData( m_data, widget, data ); } void Dialog::exportData(){ @@ -453,20 +466,20 @@ EMessageBoxReturn Dialog::DoModal(){ } -ui::CheckButton Dialog::addCheckBox( ui::VBox vbox, const char* name, const char* flag, const BoolImportCallback& importViewer, const BoolExportCallback& exportViewer ){ +ui::CheckButton Dialog::addCheckBox( ui::VBox vbox, const char* name, const char* flag, ImportExportCallback const &cb ){ auto check = ui::CheckButton( flag ); check.show(); - AddBoolToggleData( *GTK_TOGGLE_BUTTON( check ), importViewer, exportViewer ); + AddBoolToggleData( *GTK_TOGGLE_BUTTON( check ), cb ); DialogVBox_packRow( vbox, ui::Widget(DialogRow_new( name, check ) )); return check; } ui::CheckButton Dialog::addCheckBox( ui::VBox vbox, const char* name, const char* flag, bool& data ){ - return addCheckBox( vbox, name, flag, BoolImportCaller( data ), BoolExportCaller( data ) ); + return addCheckBox(vbox, name, flag, mkImportExportCallback(data)); } -void Dialog::addCombo( ui::VBox vbox, const char* name, StringArrayRange values, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ +void Dialog::addCombo( ui::VBox vbox, const char* name, StringArrayRange values, ImportExportCallback const &cb ){ auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 ); alignment.show(); { @@ -477,7 +490,7 @@ void Dialog::addCombo( ui::VBox vbox, const char* name, StringArrayRange values, gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), *i ); } - AddIntComboData( *GTK_COMBO_BOX( combo ), importViewer, exportViewer ); + AddIntComboData( *GTK_COMBO_BOX( combo ), cb ); combo.show(); alignment.add(combo); @@ -488,7 +501,7 @@ void Dialog::addCombo( ui::VBox vbox, const char* name, StringArrayRange values, } void Dialog::addCombo( ui::VBox vbox, const char* name, int& data, StringArrayRange values ){ - addCombo( vbox, name, values, IntImportCaller( data ), IntExportCaller( data ) ); + addCombo(vbox, name, values, mkImportExportCallback(data)); } void Dialog::addSlider( ui::VBox vbox, const char* name, int& data, gboolean draw_value, const char* low, const char* high, double value, double lower, double upper, double step_increment, double page_increment ){ @@ -512,7 +525,7 @@ void Dialog::addSlider( ui::VBox vbox, const char* name, int& data, gboolean dra // adjustment auto adj = ui::Adjustment( value, lower, upper, step_increment, page_increment, 0 ); - AddIntAdjustmentData( *GTK_ADJUSTMENT(adj), IntImportCaller( data ), IntExportCaller( data ) ); + AddIntAdjustmentData(*GTK_ADJUSTMENT(adj), mkImportExportCallback(data)); // scale auto alignment = ui::Alignment( 0.0, 0.5, 1.0, 0.0 ); @@ -530,13 +543,13 @@ void Dialog::addSlider( ui::VBox vbox, const char* name, int& data, gboolean dra DialogVBox_packRow( vbox, row ); } -void Dialog::addRadio( ui::VBox vbox, const char* name, StringArrayRange names, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ +void Dialog::addRadio( ui::VBox vbox, const char* name, StringArrayRange names, ImportExportCallback const &cb ){ auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 ); alignment.show();; { RadioHBox radioBox = RadioHBox_new( names ); alignment.add(radioBox.m_hbox); - AddIntRadioData( *GTK_RADIO_BUTTON( radioBox.m_radio ), importViewer, exportViewer ); + AddIntRadioData( *GTK_RADIO_BUTTON( radioBox.m_radio ), cb ); } auto row = DialogRow_new( name, alignment ); @@ -544,10 +557,10 @@ void Dialog::addRadio( ui::VBox vbox, const char* name, StringArrayRange names, } void Dialog::addRadio( ui::VBox vbox, const char* name, int& data, StringArrayRange names ){ - addRadio( vbox, name, names, IntImportCaller( data ), IntExportCaller( data ) ); + addRadio(vbox, name, names, mkImportExportCallback(data)); } -void Dialog::addRadioIcons( ui::VBox vbox, const char* name, StringArrayRange icons, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ +void Dialog::addRadioIcons( ui::VBox vbox, const char* name, StringArrayRange icons, ImportExportCallback const &cb ){ auto table = ui::Table(2, icons.last - icons.first, FALSE); table.show(); @@ -570,66 +583,66 @@ void Dialog::addRadioIcons( ui::VBox vbox, const char* name, StringArrayRange ic group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( radio ) ); } - AddIntRadioData( *GTK_RADIO_BUTTON( radio ), importViewer, exportViewer ); + AddIntRadioData( *GTK_RADIO_BUTTON( radio ), cb ); DialogVBox_packRow( vbox, DialogRow_new( name, table ) ); } void Dialog::addRadioIcons( ui::VBox vbox, const char* name, int& data, StringArrayRange icons ){ - addRadioIcons( vbox, name, icons, IntImportCaller( data ), IntExportCaller( data ) ); + addRadioIcons(vbox, name, icons, mkImportExportCallback(data)); } -ui::Widget Dialog::addIntEntry( ui::VBox vbox, const char* name, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ +ui::Widget Dialog::addIntEntry( ui::VBox vbox, const char* name, ImportExportCallback const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddIntEntryData( *GTK_ENTRY(row.m_entry), importViewer, exportViewer ); + AddIntEntryData( *GTK_ENTRY(row.m_entry), cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } -ui::Widget Dialog::addSizeEntry( ui::VBox vbox, const char* name, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer ){ +ui::Widget Dialog::addSizeEntry( ui::VBox vbox, const char* name, ImportExportCallback const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddSizeEntryData( *GTK_ENTRY(row.m_entry), importViewer, exportViewer ); + AddSizeEntryData( *GTK_ENTRY(row.m_entry), cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } -ui::Widget Dialog::addFloatEntry( ui::VBox vbox, const char* name, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){ +ui::Widget Dialog::addFloatEntry( ui::VBox vbox, const char* name, ImportExportCallback const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); - AddFloatEntryData( *GTK_ENTRY(row.m_entry), importViewer, exportViewer ); + AddFloatEntryData( *GTK_ENTRY(row.m_entry), cb ); DialogVBox_packRow( vbox, row.m_row ); return row.m_row; } -ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, bool browse_directory, const StringImportCallback& importViewer, const StringExportCallback& exportViewer ){ +ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, bool browse_directory, ImportExportCallback const &cb ){ PathEntry pathEntry = PathEntry_new(); pathEntry.m_button.connect( "clicked", G_CALLBACK( browse_directory ? button_clicked_entry_browse_directory : button_clicked_entry_browse_file ), pathEntry.m_entry ); - AddTextEntryData( *GTK_ENTRY(pathEntry.m_entry), importViewer, exportViewer ); + AddTextEntryData( *GTK_ENTRY(pathEntry.m_entry), cb ); auto row = DialogRow_new( name, ui::Widget(pathEntry.m_frame ) ); DialogVBox_packRow( vbox, row ); - return ui::Widget(row ); + return row; } ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, CopiedString& data, bool browse_directory ){ - return addPathEntry( vbox, name, browse_directory, StringImportCallback( StringImportCaller( data ) ), StringExportCallback( StringExportCaller( data ) ) ); + return addPathEntry(vbox, name, browse_directory, mkImportExportCallback(data)); } -ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, const IntImportCallback& importViewer, const IntExportCallback& exportViewer ){ +ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, ImportExportCallback const &cb ){ DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 1 ) ); - AddIntSpinnerData( *GTK_SPIN_BUTTON(row.m_spin), importViewer, exportViewer ); + AddIntSpinnerData( *GTK_SPIN_BUTTON(row.m_spin), cb ); DialogVBox_packRow( vbox, row.m_row ); - return ui::SpinButton(row.m_spin); + return row.m_spin; } ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, int& data, double value, double lower, double upper ){ - return addSpinner( vbox, name, value, lower, upper, IntImportCallback( IntImportCaller( data ) ), IntExportCallback( IntExportCaller( data ) ) ); + return addSpinner(vbox, name, value, lower, upper, mkImportExportCallback(data)); } -ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer ){ +ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, ImportExportCallback const &cb ){ DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 10 ) ); - AddFloatSpinnerData( *GTK_SPIN_BUTTON(row.m_spin), importViewer, exportViewer ); + AddFloatSpinnerData( *GTK_SPIN_BUTTON(row.m_spin), cb ); DialogVBox_packRow( vbox, row.m_row ); - return ui::SpinButton(row.m_spin); + return row.m_spin; } diff --git a/radiant/dialog.h b/radiant/dialog.h index d9424809..cf2b2362 100644 --- a/radiant/dialog.h +++ b/radiant/dialog.h @@ -30,58 +30,59 @@ #include "generic/callback.h" #include "string/string.h" -inline void BoolImport( bool& self, bool value ){ - self = value; -} -typedef ReferenceCaller BoolImportCaller; +template +struct impexp { + static void Import(Self &self, T value) { + self = value; + } + + static void Export(Self &self, const Callback &importCallback) { + importCallback(self); + } +}; -inline void BoolExport( bool& self, const BoolImportCallback& importCallback ){ - importCallback( self ); +template +ImportExportCallback mkImportExportCallback(Self &self) { + return { + ReferenceCaller::Import>(self), + ReferenceCaller &), impexp::Export>(self) + }; } -typedef ReferenceCaller BoolExportCaller; +#define BoolImport impexp::Import +#define BoolExport impexp::Export -inline void IntImport( int& self, int value ){ - self = value; -} -typedef ReferenceCaller IntImportCaller; +typedef ReferenceCaller &), BoolExport> BoolExportCaller; -inline void IntExport( int& self, const IntImportCallback& importCallback ){ - importCallback( self ); -} -typedef ReferenceCaller IntExportCaller; +#define IntImport impexp::Import +#define IntExport impexp::Export +typedef ReferenceCaller &), IntExport> IntExportCaller; -inline void SizeImport( std::size_t& self, std::size_t value ){ - self = value; -} -typedef ReferenceCaller SizeImportCaller; +#define SizeImport impexp::Import +#define SizeExport impexp::Export -inline void SizeExport( std::size_t& self, const SizeImportCallback& importCallback ){ - importCallback( self ); -} -typedef ReferenceCaller SizeExportCaller; +#define FloatImport impexp::Import +#define FloatExport impexp::Export -inline void FloatImport( float& self, float value ){ - self = value; -} -typedef ReferenceCaller FloatImportCaller; +typedef ReferenceCaller &), FloatExport> FloatExportCaller; -inline void FloatExport( float& self, const FloatImportCallback& importCallback ){ - importCallback( self ); -} -typedef ReferenceCaller FloatExportCaller; +#define StringImport impexp::Import +#define StringExport impexp::Export +template<> +struct impexp { + static void Import(CopiedString &self, const char *value) { + self = value; + } -inline void StringImport( CopiedString& self, const char* value ){ - self = value; -} -typedef ReferenceCaller StringImportCaller; -inline void StringExport( CopiedString& self, const StringImportCallback& importCallback ){ - importCallback( self.c_str() ); -} -typedef ReferenceCaller StringExportCaller; + static void Export(CopiedString &self, const Callback &importCallback) { + importCallback(self.c_str()); + } +}; + +typedef ReferenceCaller &), StringExport> StringExportCaller; struct DLG_DATA @@ -131,45 +132,66 @@ const ui::Window GetWidget() const { return m_window; } -ui::CheckButton addCheckBox( ui::VBox vbox, const char* name, const char* flag, const BoolImportCallback& importCallback, const BoolExportCallback& exportCallback ); + ui::CheckButton addCheckBox(ui::VBox vbox, const char *name, const char *flag, ImportExportCallback const &cb); ui::CheckButton addCheckBox( ui::VBox vbox, const char* name, const char* flag, bool& data ); -void addCombo( ui::VBox vbox, const char* name, StringArrayRange values, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ); + + void addCombo(ui::VBox vbox, const char *name, StringArrayRange values, ImportExportCallback const &cb); void addCombo( ui::VBox vbox, const char* name, int& data, StringArrayRange values ); void addSlider( ui::VBox vbox, const char* name, int& data, gboolean draw_value, const char* low, const char* high, double value, double lower, double upper, double step_increment, double page_increment ); -void addRadio( ui::VBox vbox, const char* name, StringArrayRange names, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ); + + void addRadio(ui::VBox vbox, const char *name, StringArrayRange names, ImportExportCallback const &cb); void addRadio( ui::VBox vbox, const char* name, int& data, StringArrayRange names ); -void addRadioIcons( ui::VBox vbox, const char* name, StringArrayRange icons, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ); + + void addRadioIcons(ui::VBox vbox, const char *name, StringArrayRange icons, ImportExportCallback const &cb); void addRadioIcons( ui::VBox vbox, const char* name, int& data, StringArrayRange icons ); -ui::Widget addIntEntry( ui::VBox vbox, const char* name, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ); + + ui::Widget addIntEntry(ui::VBox vbox, const char *name, ImportExportCallback const &cb); ui::Widget addEntry( ui::VBox vbox, const char* name, int& data ){ - return addIntEntry( vbox, name, IntImportCaller( data ), IntExportCaller( data ) ); + return addIntEntry(vbox, name, mkImportExportCallback(data)); } -ui::Widget addSizeEntry( ui::VBox vbox, const char* name, const SizeImportCallback& importCallback, const SizeExportCallback& exportCallback ); + + ui::Widget addSizeEntry(ui::VBox vbox, const char *name, ImportExportCallback const &cb); ui::Widget addEntry( ui::VBox vbox, const char* name, std::size_t& data ){ - return addSizeEntry( vbox, name, SizeImportCaller( data ), SizeExportCaller( data ) ); + return addSizeEntry(vbox, name, mkImportExportCallback(data)); } -ui::Widget addFloatEntry( ui::VBox vbox, const char* name, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback ); + + ui::Widget addFloatEntry(ui::VBox vbox, const char *name, ImportExportCallback const &cb); ui::Widget addEntry( ui::VBox vbox, const char* name, float& data ){ - return addFloatEntry( vbox, name, FloatImportCaller( data ), FloatExportCaller( data ) ); + return addFloatEntry(vbox, name, mkImportExportCallback(data)); } -ui::Widget addPathEntry( ui::VBox vbox, const char* name, bool browse_directory, const StringImportCallback& importCallback, const StringExportCallback& exportCallback ); + + ui::Widget + addPathEntry(ui::VBox vbox, const char *name, bool browse_directory, ImportExportCallback const &cb); ui::Widget addPathEntry( ui::VBox vbox, const char* name, CopiedString& data, bool directory ); ui::SpinButton addSpinner( ui::VBox vbox, const char* name, int& data, double value, double lower, double upper ); -ui::SpinButton addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ); -ui::SpinButton addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback ); + + ui::SpinButton + addSpinner(ui::VBox vbox, const char *name, double value, double lower, double upper, ImportExportCallback const &cb); + + ui::SpinButton addSpinner(ui::VBox vbox, const char *name, double value, double lower, double upper, + ImportExportCallback const &cb); protected: -void AddBoolToggleData( struct _GtkToggleButton& object, const BoolImportCallback& importCallback, const BoolExportCallback& exportCallback ); -void AddIntRadioData( struct _GtkRadioButton& object, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ); -void AddTextEntryData( struct _GtkEntry& object, const StringImportCallback& importCallback, const StringExportCallback& exportCallback ); -void AddIntEntryData( struct _GtkEntry& object, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ); -void AddSizeEntryData( struct _GtkEntry& object, const SizeImportCallback& importCallback, const SizeExportCallback& exportCallback ); -void AddFloatEntryData( struct _GtkEntry& object, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback ); -void AddFloatSpinnerData( struct _GtkSpinButton& object, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback ); -void AddIntSpinnerData( struct _GtkSpinButton& object, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ); -void AddIntAdjustmentData( struct _GtkAdjustment& object, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ); -void AddIntComboData( struct _GtkComboBox& object, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ); + void AddBoolToggleData(struct _GtkToggleButton &object, ImportExportCallback const &cb); + + void AddIntRadioData(struct _GtkRadioButton &object, ImportExportCallback const &cb); + + void AddTextEntryData(struct _GtkEntry &object, ImportExportCallback const &cb); + + void AddIntEntryData(struct _GtkEntry &object, ImportExportCallback const &cb); + + void AddSizeEntryData(struct _GtkEntry &object, ImportExportCallback const &cb); + + void AddFloatEntryData(struct _GtkEntry &object, ImportExportCallback const &cb); + + void AddFloatSpinnerData(struct _GtkSpinButton &object, ImportExportCallback const &cb); + + void AddIntSpinnerData(struct _GtkSpinButton &object, ImportExportCallback const &cb); + + void AddIntAdjustmentData(struct _GtkAdjustment &object, ImportExportCallback const &cb); + + void AddIntComboData(struct _GtkComboBox &object, ImportExportCallback const &cb); void AddDialogData( struct _GtkToggleButton& object, bool& data ); void AddDialogData( struct _GtkRadioButton& object, int& data ); diff --git a/radiant/entity.cpp b/radiant/entity.cpp index feb08f6a..1c02828e 100644 --- a/radiant/entity.cpp +++ b/radiant/entity.cpp @@ -547,16 +547,16 @@ void LightRadiiImport( EntityCreator& self, bool value ){ } typedef ReferenceCaller LightRadiiImportCaller; -void LightRadiiExport( EntityCreator& self, const BoolImportCallback& importer ){ +void LightRadiiExport( EntityCreator& self, const ImportExportCallback::Import_t& importer ){ importer( self.getLightRadii() ); } -typedef ReferenceCaller LightRadiiExportCaller; +typedef ReferenceCaller::Import_t&), LightRadiiExport> LightRadiiExportCaller; void Entity_constructPreferences( PreferencesPage& page ){ page.appendCheckBox( "Show", "Light Radii", - LightRadiiImportCaller( GlobalEntityCreator() ), - LightRadiiExportCaller( GlobalEntityCreator() ) + {LightRadiiImportCaller( GlobalEntityCreator() ), + LightRadiiExportCaller( GlobalEntityCreator() )} ); } void Entity_constructPage( PreferenceGroup& group ){ diff --git a/radiant/filters.cpp b/radiant/filters.cpp index 65472334..9764f4af 100644 --- a/radiant/filters.cpp +++ b/radiant/filters.cpp @@ -127,10 +127,10 @@ ToggleFilterFlag( unsigned int mask ) : m_mask( mask ), m_item( ActiveCaller( *t } ToggleFilterFlag( const ToggleFilterFlag& other ) : m_mask( other.m_mask ), m_item( ActiveCaller( *this ) ){ } -void active( const BoolImportCallback& importCallback ){ +void active( const ImportExportCallback::Import_t& importCallback ){ importCallback( ( g_filters_globals.exclude & m_mask ) != 0 ); } -typedef MemberCaller ActiveCaller; +typedef MemberCaller::Import_t&), &ToggleFilterFlag::active> ActiveCaller; void toggle(){ g_filters_globals.exclude ^= m_mask; m_item.update(); diff --git a/radiant/grid.cpp b/radiant/grid.cpp index fa255b44..be267002 100644 --- a/radiant/grid.cpp +++ b/radiant/grid.cpp @@ -134,10 +134,10 @@ void set(){ setGridPower( m_id ); } typedef MemberCaller SetCaller; -void active( const BoolImportCallback& importCallback ){ +void active( const ImportExportCallback::Import_t& importCallback ){ importCallback( g_grid_power == m_id ); } -typedef MemberCaller ExportCaller; +typedef MemberCaller::Import_t&), &GridMenuItem::active> ExportCaller; }; GridMenuItem g_gridMenu0125( GRIDPOWER_0125 ); diff --git a/radiant/groupdialog.cpp b/radiant/groupdialog.cpp index a926d0fb..28098897 100644 --- a/radiant/groupdialog.cpp +++ b/radiant/groupdialog.cpp @@ -71,7 +71,7 @@ namespace GroupDlg g_GroupDlg; std::size_t g_current_page; -std::vector g_pages; +std::vector::Export_t> g_pages; } void GroupDialog_updatePageTitle( ui::Window window, std::size_t pageIndex ){ @@ -123,7 +123,7 @@ void GroupDlg::Create( ui::Window parent ){ } -ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const StringExportCallback& title ){ +ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const ImportExportCallback::Export_t& title ){ ui::Widget w = ui::Label( tabLabel ); w.show(); ui::Widget page = ui::Widget(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gtk_notebook_insert_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), widget, w, -1 ) )); diff --git a/radiant/groupdialog.h b/radiant/groupdialog.h index f1a2e86b..8f1a31ee 100644 --- a/radiant/groupdialog.h +++ b/radiant/groupdialog.h @@ -33,11 +33,11 @@ void GroupDialog_destroyWindow(); ui::Window GroupDialog_getWindow(); void GroupDialog_show(); -inline void RawStringExport( const char* string, const StringImportCallback& importer ){ +inline void RawStringExport( const char* string, const ImportExportCallback::Import_t& importer ){ importer( string ); } -typedef ConstPointerCaller RawStringExportCaller; -ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const StringExportCallback& title ); +typedef ConstPointerCaller::Import_t&), RawStringExport> RawStringExportCaller; +ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const ImportExportCallback::Export_t& title ); void GroupDialog_showPage( ui::Widget page ); void GroupDialog_updatePageTitle( ui::Widget page ); diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 6ae00e3d..c4d2f40d 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -421,8 +421,8 @@ typedef ReferenceCaller Engin void Paths_constructPreferences( PreferencesPage& page ){ page.appendPathEntry( "Engine Path", true, - StringImportCallback( EnginePathImportCaller( g_strEnginePath ) ), - StringExportCallback( StringExportCaller( g_strEnginePath ) ) + {ImportExportCallback::Import_t( EnginePathImportCaller( g_strEnginePath ) ), + ImportExportCallback::Export_t( StringExportCaller( g_strEnginePath ) )} ); } void Paths_constructPage( PreferenceGroup& group ){ @@ -999,24 +999,24 @@ template class BoolFunctionExport { public: -static void apply( const BoolImportCallback& importCallback ){ +static void apply( const ImportExportCallback::Import_t& importCallback ){ importCallback( BoolFunction() ); } }; -typedef FreeCaller::apply> EdgeModeApplyCaller; +typedef FreeCaller::Import_t&), &BoolFunctionExport::apply> EdgeModeApplyCaller; EdgeModeApplyCaller g_edgeMode_button_caller; -BoolExportCallback g_edgeMode_button_callback( g_edgeMode_button_caller ); +ImportExportCallback::Export_t g_edgeMode_button_callback( g_edgeMode_button_caller ); ToggleItem g_edgeMode_button( g_edgeMode_button_callback ); -typedef FreeCaller::apply> VertexModeApplyCaller; +typedef FreeCaller::Import_t&), &BoolFunctionExport::apply> VertexModeApplyCaller; VertexModeApplyCaller g_vertexMode_button_caller; -BoolExportCallback g_vertexMode_button_callback( g_vertexMode_button_caller ); +ImportExportCallback::Export_t g_vertexMode_button_callback( g_vertexMode_button_caller ); ToggleItem g_vertexMode_button( g_vertexMode_button_callback ); -typedef FreeCaller::apply> FaceModeApplyCaller; +typedef FreeCaller::Import_t&), &BoolFunctionExport::apply> FaceModeApplyCaller; FaceModeApplyCaller g_faceMode_button_caller; -BoolExportCallback g_faceMode_button_callback( g_faceMode_button_caller ); +ImportExportCallback::Export_t g_faceMode_button_callback( g_faceMode_button_caller ); ToggleItem g_faceMode_button( g_faceMode_button_callback ); void ComponentModeChanged(){ @@ -1290,44 +1290,44 @@ void Selection_NudgeRight(){ } -void TranslateToolExport( const BoolImportCallback& importCallback ){ +void TranslateToolExport( const ImportExportCallback::Import_t& importCallback ){ importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate ); } -void RotateToolExport( const BoolImportCallback& importCallback ){ +void RotateToolExport( const ImportExportCallback::Import_t& importCallback ){ importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate ); } -void ScaleToolExport( const BoolImportCallback& importCallback ){ +void ScaleToolExport( const ImportExportCallback::Import_t& importCallback ){ importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale ); } -void DragToolExport( const BoolImportCallback& importCallback ){ +void DragToolExport( const ImportExportCallback::Import_t& importCallback ){ importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag ); } -void ClipperToolExport( const BoolImportCallback& importCallback ){ +void ClipperToolExport( const ImportExportCallback::Import_t& importCallback ){ importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip ); } -FreeCaller g_translatemode_button_caller; -BoolExportCallback g_translatemode_button_callback( g_translatemode_button_caller ); +FreeCaller::Import_t&), TranslateToolExport> g_translatemode_button_caller; +ImportExportCallback::Export_t g_translatemode_button_callback( g_translatemode_button_caller ); ToggleItem g_translatemode_button( g_translatemode_button_callback ); -FreeCaller g_rotatemode_button_caller; -BoolExportCallback g_rotatemode_button_callback( g_rotatemode_button_caller ); +FreeCaller::Import_t&), RotateToolExport> g_rotatemode_button_caller; +ImportExportCallback::Export_t g_rotatemode_button_callback( g_rotatemode_button_caller ); ToggleItem g_rotatemode_button( g_rotatemode_button_callback ); -FreeCaller g_scalemode_button_caller; -BoolExportCallback g_scalemode_button_callback( g_scalemode_button_caller ); +FreeCaller::Import_t&), ScaleToolExport> g_scalemode_button_caller; +ImportExportCallback::Export_t g_scalemode_button_callback( g_scalemode_button_caller ); ToggleItem g_scalemode_button( g_scalemode_button_callback ); -FreeCaller g_dragmode_button_caller; -BoolExportCallback g_dragmode_button_callback( g_dragmode_button_caller ); +FreeCaller::Import_t&), DragToolExport> g_dragmode_button_caller; +ImportExportCallback::Export_t g_dragmode_button_callback( g_dragmode_button_caller ); ToggleItem g_dragmode_button( g_dragmode_button_callback ); -FreeCaller g_clipper_button_caller; -BoolExportCallback g_clipper_button_callback( g_clipper_button_caller ); +FreeCaller::Import_t&), ClipperToolExport> g_clipper_button_caller; +ImportExportCallback::Export_t g_clipper_button_callback( g_clipper_button_caller ); ToggleItem g_clipper_button( g_clipper_button_callback ); void ToolChanged(){ @@ -1770,10 +1770,10 @@ void ClipperChangeNotify(){ } -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" ); +LatchedValue g_Layout_viewStyle( 0, "Window Layout" ); +LatchedValue g_Layout_enableDetachableMenus( true, "Detachable Menus" ); +LatchedValue g_Layout_enablePatchToolbar( true, "Patch Toolbar" ); +LatchedValue g_Layout_enablePluginToolbar( true, "Plugin Toolbar" ); @@ -3126,26 +3126,22 @@ void Layout_constructPreferences( PreferencesPage& page ){ page.appendRadioIcons( "Window Layout", STRING_ARRAY_RANGE( layouts ), - LatchedIntImportCaller( g_Layout_viewStyle ), - IntExportCaller( g_Layout_viewStyle.m_latched ) + mkImportExportCallback( g_Layout_viewStyle ) ); } page.appendCheckBox( "", "Detachable Menus", - LatchedBoolImportCaller( g_Layout_enableDetachableMenus ), - BoolExportCaller( g_Layout_enableDetachableMenus.m_latched ) + mkImportExportCallback( g_Layout_enableDetachableMenus ) ); if ( !string_empty( g_pGameDescription->getKeyValue( "no_patch" ) ) ) { page.appendCheckBox( "", "Patch Toolbar", - LatchedBoolImportCaller( g_Layout_enablePatchToolbar ), - BoolExportCaller( g_Layout_enablePatchToolbar.m_latched ) + mkImportExportCallback( g_Layout_enablePatchToolbar ) ); } page.appendCheckBox( "", "Plugin Toolbar", - LatchedBoolImportCaller( g_Layout_enablePluginToolbar ), - BoolExportCaller( g_Layout_enablePluginToolbar.m_latched ) + mkImportExportCallback( g_Layout_enablePluginToolbar ) ); } diff --git a/radiant/mainframe.h b/radiant/mainframe.h index f271ad9e..944c7b8b 100644 --- a/radiant/mainframe.h +++ b/radiant/mainframe.h @@ -164,8 +164,7 @@ void GLWindow_Destroy(); extern glwindow_globals_t g_glwindow_globals; template class LatchedValue; -typedef LatchedValue LatchedBool; -extern LatchedBool g_Layout_enableDetachableMenus; +extern LatchedValue g_Layout_enableDetachableMenus; void deleteSelection(); diff --git a/radiant/multimon.cpp b/radiant/multimon.cpp index 8a569e0b..b626f435 100644 --- a/radiant/multimon.cpp +++ b/radiant/multimon.cpp @@ -29,14 +29,13 @@ multimon_globals_t g_multimon_globals; -LatchedBool g_Multimon_enableSysMenuPopups( false, "Floating windows sysmenu icons" ); +LatchedValue g_Multimon_enableSysMenuPopups( false, "Floating windows sysmenu icons" ); void MultiMonitor_constructPreferences( PreferencesPage& page ){ ui::CheckButton primary_monitor = page.appendCheckBox( "Multi Monitor", "Start on Primary Monitor", g_multimon_globals.m_bStartOnPrimMon ); ui::CheckButton popup = page.appendCheckBox( "", "Disable system menu on popup windows", - LatchedBoolImportCaller( g_Multimon_enableSysMenuPopups ), - BoolExportCaller( g_Multimon_enableSysMenuPopups.m_latched ) + mkImportExportCallback( g_Multimon_enableSysMenuPopups ) ); Widget_connectToggleDependency( popup, primary_monitor ); } diff --git a/radiant/preferencedictionary.h b/radiant/preferencedictionary.h index 5d2dbc07..eed7b1c9 100644 --- a/radiant/preferencedictionary.h +++ b/radiant/preferencedictionary.h @@ -33,16 +33,16 @@ class PreferenceDictionary : public PreferenceSystem { class PreferenceEntry { -StringImportCallback m_importer; -StringExportCallback m_exporter; +ImportExportCallback::Import_t m_importer; +ImportExportCallback::Export_t m_exporter; public: -PreferenceEntry( const StringImportCallback& importer, const StringExportCallback& exporter ) +PreferenceEntry( const ImportExportCallback::Import_t& importer, const ImportExportCallback::Export_t& exporter ) : m_importer( importer ), m_exporter( exporter ){ } void importString( const char* string ){ m_importer( string ); } -void exportString( const StringImportCallback& importer ){ +void exportString( const ImportExportCallback::Import_t& importer ){ m_exporter( importer ); } }; @@ -66,7 +66,7 @@ iterator find( const char* name ){ return m_preferences.find( name ); } -void registerPreference( const char* name, const StringImportCallback& importer, const StringExportCallback& exporter ){ +void registerPreference( const char* name, const ImportExportCallback::Import_t& importer, const ImportExportCallback::Export_t& exporter ){ m_preferences.insert( PreferenceEntries::value_type( name, PreferenceEntry( importer, exporter ) ) ); PreferenceCache::iterator i = m_cache.find( name ); if ( i != m_cache.end() ) { diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index 510a1cc1..ea3dbe44 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -280,7 +280,7 @@ void CGameDialog::GameFileImport( int value ){ m_sGameFile = ( *iGame )->mGameFile; } -void CGameDialog::GameFileExport( const IntImportCallback& importCallback ) const { +void CGameDialog::GameFileExport( const ImportExportCallback::Import_t& importCallback ) const { // use m_sGameFile to set value std::list::const_iterator iGame; int i = 0; @@ -299,7 +299,7 @@ void CGameDialog_GameFileImport( CGameDialog& self, int value ){ self.GameFileImport( value ); } -void CGameDialog_GameFileExport( CGameDialog& self, const IntImportCallback& importCallback ){ +void CGameDialog_GameFileExport( CGameDialog& self, const ImportExportCallback::Import_t& importCallback ){ self.GameFileExport( importCallback ); } @@ -313,8 +313,8 @@ void CGameDialog::CreateGlobalFrame( PreferencesPage& page ){ page.appendCombo( "Select the game", StringArrayRange( &( *games.begin() ), &( *games.end() ) ), - ReferenceCaller( *this ), - ReferenceCaller( *this ) + {ReferenceCaller( *this ), + ReferenceCaller::Import_t&), CGameDialog_GameFileExport>( *this )} ); page.appendCheckBox( "Startup", "Show Global Preferences", m_bGamePrompt ); } @@ -922,19 +922,19 @@ void GameName_importString( const char* value ){ gamename_set( value ); } typedef FreeCaller GameNameImportStringCaller; -void GameName_exportString( const StringImportCallback& importer ){ +void GameName_exportString( const ImportExportCallback::Import_t& importer ){ importer( gamename_get() ); } -typedef FreeCaller GameNameExportStringCaller; +typedef FreeCaller::Import_t&), GameName_exportString> GameNameExportStringCaller; void GameMode_importString( const char* value ){ gamemode_set( value ); } typedef FreeCaller GameModeImportStringCaller; -void GameMode_exportString( const StringImportCallback& importer ){ +void GameMode_exportString( const ImportExportCallback::Import_t& importer ){ importer( gamemode_get() ); } -typedef FreeCaller GameModeExportStringCaller; +typedef FreeCaller::Import_t&), GameMode_exportString> GameModeExportStringCaller; void RegisterPreferences( PreferenceSystem& preferences ){ diff --git a/radiant/preferences.h b/radiant/preferences.h index 0aae24c7..8d7f93ae 100644 --- a/radiant/preferences.h +++ b/radiant/preferences.h @@ -46,11 +46,11 @@ PreferencesPage( Dialog& dialog, ui::VBox vbox ) : m_dialog( dialog ), m_vbox( v ui::CheckButton appendCheckBox( const char* name, const char* flag, bool& data ){ return m_dialog.addCheckBox( m_vbox, name, flag, data ); } -ui::CheckButton appendCheckBox( const char* name, const char* flag, const BoolImportCallback& importCallback, const BoolExportCallback& exportCallback ){ - return m_dialog.addCheckBox( m_vbox, name, flag, importCallback, exportCallback ); +ui::CheckButton appendCheckBox( const char* name, const char* flag, ImportExportCallback const &cb ){ + return m_dialog.addCheckBox( m_vbox, name, flag, cb ); } -void appendCombo( const char* name, StringArrayRange values, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ){ - m_dialog.addCombo( m_vbox, name, values, importCallback, exportCallback ); +void appendCombo( const char* name, StringArrayRange values, ImportExportCallback const &cb ){ + m_dialog.addCombo( m_vbox, name, values, cb ); } void appendCombo( const char* name, int& data, StringArrayRange values ){ m_dialog.addCombo( m_vbox, name, data, values ); @@ -58,38 +58,38 @@ void appendCombo( const char* name, int& data, StringArrayRange values ){ void appendSlider( const char* name, int& data, gboolean draw_value, const char* low, const char* high, double value, double lower, double upper, double step_increment, double page_increment ){ m_dialog.addSlider( m_vbox, name, data, draw_value, low, high, value, lower, upper, step_increment, page_increment ); } -void appendRadio( const char* name, StringArrayRange names, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ){ - m_dialog.addRadio( m_vbox, name, names, importCallback, exportCallback ); +void appendRadio( const char* name, StringArrayRange names, ImportExportCallback const &cb ){ + m_dialog.addRadio( m_vbox, name, names, cb ); } void appendRadio( const char* name, int& data, StringArrayRange names ){ m_dialog.addRadio( m_vbox, name, data, names ); } -void appendRadioIcons( const char* name, StringArrayRange icons, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ){ - m_dialog.addRadioIcons( m_vbox, name, icons, importCallback, exportCallback ); +void appendRadioIcons( const char* name, StringArrayRange icons, ImportExportCallback const &cb ){ + m_dialog.addRadioIcons( m_vbox, name, icons, cb ); } void appendRadioIcons( const char* name, int& data, StringArrayRange icons ){ m_dialog.addRadioIcons( m_vbox, name, data, icons ); } -ui::Widget appendEntry( const char* name, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ){ - return m_dialog.addIntEntry( m_vbox, name, importCallback, exportCallback ); +ui::Widget appendEntry( const char* name, ImportExportCallback const &cb ){ + return m_dialog.addIntEntry( m_vbox, name, cb ); } ui::Widget appendEntry( const char* name, int& data ){ return m_dialog.addEntry( m_vbox, name, data ); } -ui::Widget appendEntry( const char* name, const SizeImportCallback& importCallback, const SizeExportCallback& exportCallback ){ - return m_dialog.addSizeEntry( m_vbox, name, importCallback, exportCallback ); +ui::Widget appendEntry( const char* name, ImportExportCallback const &cb){ + return m_dialog.addSizeEntry( m_vbox, name, cb ); } ui::Widget appendEntry( const char* name, std::size_t& data ){ return m_dialog.addEntry( m_vbox, name, data ); } -ui::Widget appendEntry( const char* name, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback ){ - return m_dialog.addFloatEntry( m_vbox, name, importCallback, exportCallback ); +ui::Widget appendEntry( const char* name, ImportExportCallback const &cb ){ + return m_dialog.addFloatEntry( m_vbox, name, cb ); } ui::Widget appendEntry( const char* name, float& data ){ return m_dialog.addEntry( m_vbox, name, data ); } -ui::Widget appendPathEntry( const char* name, bool browse_directory, const StringImportCallback& importCallback, const StringExportCallback& exportCallback ){ - return m_dialog.addPathEntry( m_vbox, name, browse_directory, importCallback, exportCallback ); +ui::Widget appendPathEntry( const char* name, bool browse_directory, ImportExportCallback const &cb ){ + return m_dialog.addPathEntry( m_vbox, name, browse_directory, cb ); } ui::Widget appendPathEntry( const char* name, CopiedString& data, bool directory ){ return m_dialog.addPathEntry( m_vbox, name, data, directory ); @@ -97,11 +97,11 @@ ui::Widget appendPathEntry( const char* name, CopiedString& data, bool directory ui::SpinButton appendSpinner( const char* name, int& data, double value, double lower, double upper ){ return m_dialog.addSpinner( m_vbox, name, data, value, lower, upper ); } -ui::SpinButton appendSpinner( const char* name, double value, double lower, double upper, const IntImportCallback& importCallback, const IntExportCallback& exportCallback ){ - return m_dialog.addSpinner( m_vbox, name, value, lower, upper, importCallback, exportCallback ); +ui::SpinButton appendSpinner( const char* name, double value, double lower, double upper, ImportExportCallback const &cb ){ + return m_dialog.addSpinner( m_vbox, name, value, lower, upper, cb ); } -ui::SpinButton appendSpinner( const char* name, double value, double lower, double upper, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback ){ - return m_dialog.addSpinner( m_vbox, name, value, lower, upper, importCallback, exportCallback ); +ui::SpinButton appendSpinner( const char* name, double value, double lower, double upper, ImportExportCallback const &cb ){ + return m_dialog.addSpinner( m_vbox, name, value, lower, upper, cb ); } }; @@ -125,31 +125,34 @@ void PreferencesDialog_addSettingsPage( const PreferenceGroupCallback& callback void PreferencesDialog_restartRequired( const char* staticName ); template -class LatchedValue -{ +class LatchedValue { public: -Value m_value; -Value m_latched; -const char* m_description; - -LatchedValue( Value value, const char* description ) : m_latched( value ), m_description( description ){ -} -void useLatched(){ - m_value = m_latched; -} -void import( Value value ){ - m_latched = value; - if ( m_latched != m_value ) { - PreferencesDialog_restartRequired( m_description ); - } -} + Value m_value; + Value m_latched; + const char *m_description; + + LatchedValue(Value value, const char *description) : m_latched(value), m_description(description) { + } + + void useLatched() { + m_value = m_latched; + } + + void import(Value value) { + m_latched = value; + if (m_latched != m_value) { + PreferencesDialog_restartRequired(m_description); + } + } }; -typedef LatchedValue LatchedBool; -typedef MemberCaller LatchedBoolImportCaller; - -typedef LatchedValue LatchedInt; -typedef MemberCaller LatchedIntImportCaller; +template +ImportExportCallback mkImportExportCallback(LatchedValue &self) { + return { + MemberCaller, void(T), &LatchedValue::import>(self), + ReferenceCaller &), impexp::Export>(self.m_latched) + }; +} /*! holds information for a given game @@ -272,7 +275,7 @@ void DoGameDialog(); ui::Window BuildDialog(); void GameFileImport( int value ); -void GameFileExport( const IntImportCallback& importCallback ) const; +void GameFileExport( const ImportExportCallback::Import_t& importCallback ) const; /*! construction of the dialog frame diff --git a/radiant/textures.cpp b/radiant/textures.cpp index b724c317..eb989846 100644 --- a/radiant/textures.cpp +++ b/radiant/textures.cpp @@ -166,7 +166,7 @@ inline const int& min_int( const int& left, const int& right ){ int max_tex_size = 0; const int max_texture_quality = 3; -LatchedInt g_Textures_textureQuality( 3, "Texture Quality" ); +LatchedValue g_Textures_textureQuality( 3, "Texture Quality" ); /// \brief This function does the actual processing of raw RGBA data into a GL texture. /// It will also resample to power-of-two dimensions, generate the mipmaps and adjust gamma. @@ -685,7 +685,7 @@ void TextureModeImport( ETexturesMode& self, int value ){ } typedef ReferenceCaller TextureModeImportCaller; -void TextureModeExport( ETexturesMode& self, const IntImportCallback& importer ){ +void TextureModeExport( ETexturesMode& self, const ImportExportCallback::Import_t& importer ){ switch ( self ) { case eTextures_NEAREST: @@ -713,7 +713,7 @@ void TextureModeExport( ETexturesMode& self, const IntImportCallback& importer ) importer( 4 ); } } -typedef ReferenceCaller TextureModeExportCaller; +typedef ReferenceCaller::Import_t&), TextureModeExport> TextureModeExportCaller; void Textures_constructPreferences( PreferencesPage& page ){ { @@ -721,8 +721,7 @@ void Textures_constructPreferences( PreferencesPage& page ){ page.appendRadio( "Texture Quality", STRING_ARRAY_RANGE( percentages ), - LatchedIntImportCaller( g_Textures_textureQuality ), - IntExportCaller( g_Textures_textureQuality.m_latched ) + mkImportExportCallback( g_Textures_textureQuality ) ); } page.appendSpinner( @@ -730,16 +729,16 @@ void Textures_constructPreferences( PreferencesPage& page ){ 1.0, 0.0, 1.0, - FloatImportCallback( TextureGammaImportCaller( g_texture_globals.fGamma ) ), - FloatExportCallback( FloatExportCaller( g_texture_globals.fGamma ) ) + {ImportExportCallback::Import_t( TextureGammaImportCaller( g_texture_globals.fGamma ) ), + ImportExportCallback::Export_t( FloatExportCaller( g_texture_globals.fGamma ) )} ); { const char* texture_mode[] = { "Nearest", "Nearest Mipmap", "Linear", "Bilinear", "Bilinear Mipmap", "Trilinear", "Anisotropy" }; page.appendCombo( "Texture Render Mode", STRING_ARRAY_RANGE( texture_mode ), - IntImportCallback( TextureModeImportCaller( g_texture_mode ) ), - IntExportCallback( TextureModeExportCaller( g_texture_mode ) ) + {ImportExportCallback::Import_t( TextureModeImportCaller( g_texture_mode ) ), + ImportExportCallback::Export_t( TextureModeExportCaller( g_texture_mode ) )} ); } { @@ -759,8 +758,8 @@ void Textures_constructPreferences( PreferencesPage& page ){ page.appendCombo( "Hardware Texture Compression", compression, - TextureCompressionImportCaller( g_texture_globals.m_nTextureCompressionFormat ), - IntExportCaller( reinterpret_cast( g_texture_globals.m_nTextureCompressionFormat ) ) + {TextureCompressionImportCaller( g_texture_globals.m_nTextureCompressionFormat ), + IntExportCaller( reinterpret_cast( g_texture_globals.m_nTextureCompressionFormat ) )} ); } } diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 0097d9be..a86575bf 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -226,26 +226,26 @@ enum StartupShaders STARTUPSHADERS_COMMON, }; -void TextureBrowser_hideUnusedExport( const BoolImportCallback& importer ); -typedef FreeCaller TextureBrowserHideUnusedExport; +void TextureBrowser_hideUnusedExport( const ImportExportCallback::Import_t& importer ); +typedef FreeCaller::Import_t&), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport; -void TextureBrowser_showShadersExport( const BoolImportCallback& importer ); -typedef FreeCaller TextureBrowserShowShadersExport; +void TextureBrowser_showShadersExport( const ImportExportCallback::Import_t& importer ); +typedef FreeCaller::Import_t&), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport; -void TextureBrowser_showShaderlistOnly( const BoolImportCallback& importer ); -typedef FreeCaller TextureBrowserShowShaderlistOnlyExport; +void TextureBrowser_showShaderlistOnly( const ImportExportCallback::Import_t& importer ); +typedef FreeCaller::Import_t&), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport; -void TextureBrowser_fixedSize( const BoolImportCallback& importer ); -typedef FreeCaller TextureBrowserFixedSizeExport; +void TextureBrowser_fixedSize( const ImportExportCallback::Import_t& importer ); +typedef FreeCaller::Import_t&), TextureBrowser_fixedSize> TextureBrowserFixedSizeExport; -void TextureBrowser_filterMissing( const BoolImportCallback& importer ); -typedef FreeCaller TextureBrowserFilterMissingExport; +void TextureBrowser_filterMissing( const ImportExportCallback::Import_t& importer ); +typedef FreeCaller::Import_t&), TextureBrowser_filterMissing> TextureBrowserFilterMissingExport; -void TextureBrowser_filterFallback( const BoolImportCallback& importer ); -typedef FreeCaller TextureBrowserFilterFallbackExport; +void TextureBrowser_filterFallback( const ImportExportCallback::Import_t& importer ); +typedef FreeCaller::Import_t&), TextureBrowser_filterFallback> TextureBrowserFilterFallbackExport; -void TextureBrowser_enableAlpha( const BoolImportCallback& importer ); -typedef FreeCaller TextureBrowserEnableAlphaExport; +void TextureBrowser_enableAlpha( const ImportExportCallback::Import_t& importer ); +typedef FreeCaller::Import_t&), TextureBrowser_enableAlpha> TextureBrowserEnableAlphaExport; class TextureBrowser { @@ -863,40 +863,40 @@ void TextureBrowser_ShowTagSearchResult( TextureBrowser& textureBrowser, const c bool TextureBrowser_hideUnused(); -void TextureBrowser_hideUnusedExport( const BoolImportCallback& importer ){ +void TextureBrowser_hideUnusedExport( const ImportExportCallback::Import_t& importer ){ importer( TextureBrowser_hideUnused() ); } -typedef FreeCaller TextureBrowserHideUnusedExport; +typedef FreeCaller::Import_t&), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport; -void TextureBrowser_showShadersExport( const BoolImportCallback& importer ){ +void TextureBrowser_showShadersExport( const ImportExportCallback::Import_t& importer ){ importer( GlobalTextureBrowser().m_showShaders ); } -typedef FreeCaller TextureBrowserShowShadersExport; +typedef FreeCaller::Import_t&), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport; -void TextureBrowser_showShaderlistOnly( const BoolImportCallback& importer ){ +void TextureBrowser_showShaderlistOnly( const ImportExportCallback::Import_t& importer ){ importer( g_TextureBrowser_shaderlistOnly ); } -typedef FreeCaller TextureBrowserShowShaderlistOnlyExport; +typedef FreeCaller::Import_t&), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport; -void TextureBrowser_fixedSize( const BoolImportCallback& importer ){ +void TextureBrowser_fixedSize( const ImportExportCallback::Import_t& importer ){ importer( g_TextureBrowser_fixedSize ); } -typedef FreeCaller TextureBrowser_FixedSizeExport; +typedef FreeCaller::Import_t&), TextureBrowser_fixedSize> TextureBrowser_FixedSizeExport; -void TextureBrowser_filterMissing( const BoolImportCallback& importer ){ +void TextureBrowser_filterMissing( const ImportExportCallback::Import_t& importer ){ importer( g_TextureBrowser_filterMissing ); } -typedef FreeCaller TextureBrowser_filterMissingExport; +typedef FreeCaller::Import_t&), TextureBrowser_filterMissing> TextureBrowser_filterMissingExport; -void TextureBrowser_filterFallback( const BoolImportCallback& importer ){ +void TextureBrowser_filterFallback( const ImportExportCallback::Import_t& importer ){ importer( g_TextureBrowser_filterFallback ); } -typedef FreeCaller TextureBrowser_filterFallbackExport; +typedef FreeCaller::Import_t&), TextureBrowser_filterFallback> TextureBrowser_filterFallbackExport; -void TextureBrowser_enableAlpha( const BoolImportCallback& importer ){ +void TextureBrowser_enableAlpha( const ImportExportCallback::Import_t& importer ){ importer( g_TextureBrowser_enableAlpha ); } -typedef FreeCaller TextureBrowser_enableAlphaExport; +typedef FreeCaller::Import_t&), TextureBrowser_enableAlpha> TextureBrowser_enableAlphaExport; void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused ){ if ( hideUnused ) { @@ -2500,7 +2500,7 @@ void TextureBrowser_EnableAlpha(){ TextureBrowser_activeShadersChanged( GlobalTextureBrowser() ); } -void TextureBrowser_exportTitle( const StringImportCallback& importer ){ +void TextureBrowser_exportTitle( const ImportExportCallback::Import_t& importer ){ StringOutputStream buffer( 64 ); buffer << "Textures: "; if ( !string_empty( g_TextureBrowser_currentDirectory.c_str() ) ) { @@ -2536,7 +2536,7 @@ void TextureScaleImport( TextureBrowser& textureBrowser, int value ){ } typedef ReferenceCaller TextureScaleImportCaller; -void TextureScaleExport( TextureBrowser& textureBrowser, const IntImportCallback& importer ){ +void TextureScaleExport( TextureBrowser& textureBrowser, const ImportExportCallback::Import_t& importer ){ switch ( textureBrowser.m_textureScale ) { case 10: @@ -2556,7 +2556,7 @@ void TextureScaleExport( TextureBrowser& textureBrowser, const IntImportCallback break; } } -typedef ReferenceCaller TextureScaleExportCaller; +typedef ReferenceCaller::Import_t&), TextureScaleExport> TextureScaleExportCaller; void UniformTextureSizeImport( TextureBrowser& textureBrowser, int value ){ @@ -2569,16 +2569,16 @@ typedef ReferenceCaller Uni void TextureBrowser_constructPreferences( PreferencesPage& page ){ page.appendCheckBox( "", "Texture scrollbar", - TextureBrowserImportShowScrollbarCaller( GlobalTextureBrowser() ), - BoolExportCaller( GlobalTextureBrowser().m_showTextureScrollbar ) + {TextureBrowserImportShowScrollbarCaller( GlobalTextureBrowser() ), + BoolExportCaller( GlobalTextureBrowser().m_showTextureScrollbar )} ); { const char* texture_scale[] = { "10%", "25%", "50%", "100%", "200%" }; page.appendCombo( "Texture Thumbnail Scale", STRING_ARRAY_RANGE( texture_scale ), - IntImportCallback( TextureScaleImportCaller( GlobalTextureBrowser() ) ), - IntExportCallback( TextureScaleExportCaller( GlobalTextureBrowser() ) ) + {ImportExportCallback::Import_t( TextureScaleImportCaller( GlobalTextureBrowser() ) ), + ImportExportCallback::Export_t( TextureScaleExportCaller( GlobalTextureBrowser() ) )} ); } page.appendSpinner( diff --git a/radiant/texwindow.h b/radiant/texwindow.h index 2debccea..31cd4d41 100644 --- a/radiant/texwindow.h +++ b/radiant/texwindow.h @@ -43,11 +43,9 @@ const char* TextureBrowser_GetSelectedShader( TextureBrowser& textureBrower ); void TextureBrowser_Construct(); void TextureBrowser_Destroy(); -typedef Callback StringImportCallback; - extern ui::Widget g_page_textures; -void TextureBrowser_exportTitle( const StringImportCallback& importer ); -typedef FreeCaller TextureBrowserExportTitleCaller; +void TextureBrowser_exportTitle( const ImportExportCallback::Import_t& importer ); +typedef FreeCaller::Import_t&), TextureBrowser_exportTitle> TextureBrowserExportTitleCaller; const Vector3& TextureBrowser_getBackgroundColour( TextureBrowser& textureBrowser ); void TextureBrowser_setBackgroundColour( TextureBrowser& textureBrowser, const Vector3& colour ); diff --git a/radiant/undo.cpp b/radiant/undo.cpp index 8277c70e..b5507c5c 100644 --- a/radiant/undo.cpp +++ b/radiant/undo.cpp @@ -381,10 +381,10 @@ void UndoLevels_importString( RadiantUndoSystem& undo, const char* value ){ undo.setLevels( levels ); } typedef ReferenceCaller UndoLevelsImportStringCaller; -void UndoLevels_exportString( const RadiantUndoSystem& undo, const StringImportCallback& importer ){ +void UndoLevels_exportString( const RadiantUndoSystem& undo, const ImportExportCallback::Import_t& importer ){ Int_exportString( static_cast( undo.getLevels() ), importer ); } -typedef ConstReferenceCaller UndoLevelsExportStringCaller; +typedef ConstReferenceCaller::Import_t&), UndoLevels_exportString> UndoLevelsExportStringCaller; #include "generic/callback.h" @@ -392,14 +392,14 @@ void UndoLevelsImport( RadiantUndoSystem& self, int value ){ self.setLevels( value ); } typedef ReferenceCaller UndoLevelsImportCaller; -void UndoLevelsExport( const RadiantUndoSystem& self, const IntImportCallback& importCallback ){ +void UndoLevelsExport( const RadiantUndoSystem& self, const ImportExportCallback::Import_t& importCallback ){ importCallback( static_cast( self.getLevels() ) ); } -typedef ConstReferenceCaller UndoLevelsExportCaller; +typedef ConstReferenceCaller::Import_t&), UndoLevelsExport> UndoLevelsExportCaller; void Undo_constructPreferences( RadiantUndoSystem& undo, PreferencesPage& page ){ - page.appendSpinner( "Undo Queue Size", 64, 0, 1024, IntImportCallback( UndoLevelsImportCaller( undo ) ), IntExportCallback( UndoLevelsExportCaller( undo ) ) ); + page.appendSpinner( "Undo Queue Size", 64, 0, 1024, {ImportExportCallback::Import_t( UndoLevelsImportCaller( undo ) ), ImportExportCallback::Export_t( UndoLevelsExportCaller( undo ) )} ); } void Undo_constructPage( RadiantUndoSystem& undo, PreferenceGroup& group ){ PreferencesPage page( group.createPage( "Undo", "Undo Queue Settings" ) ); diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index d6f22833..7897df07 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -2587,97 +2587,97 @@ void ShowNamesToggle(){ XY_UpdateAllWindows(); } typedef FreeCaller ShowNamesToggleCaller; -void ShowNamesExport( const BoolImportCallback& importer ){ +void ShowNamesExport( const ImportExportCallback::Import_t& importer ){ importer( GlobalEntityCreator().getShowNames() ); } -typedef FreeCaller ShowNamesExportCaller; +typedef FreeCaller::Import_t&), ShowNamesExport> ShowNamesExportCaller; void ShowAnglesToggle(){ GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() ); XY_UpdateAllWindows(); } typedef FreeCaller ShowAnglesToggleCaller; -void ShowAnglesExport( const BoolImportCallback& importer ){ +void ShowAnglesExport( const ImportExportCallback::Import_t& importer ){ importer( GlobalEntityCreator().getShowAngles() ); } -typedef FreeCaller ShowAnglesExportCaller; +typedef FreeCaller::Import_t&), ShowAnglesExport> ShowAnglesExportCaller; void ShowBlocksToggle(){ g_xywindow_globals_private.show_blocks ^= 1; XY_UpdateAllWindows(); } typedef FreeCaller ShowBlocksToggleCaller; -void ShowBlocksExport( const BoolImportCallback& importer ){ +void ShowBlocksExport( const ImportExportCallback::Import_t& importer ){ importer( g_xywindow_globals_private.show_blocks ); } -typedef FreeCaller ShowBlocksExportCaller; +typedef FreeCaller::Import_t&), ShowBlocksExport> ShowBlocksExportCaller; void ShowCoordinatesToggle(){ g_xywindow_globals_private.show_coordinates ^= 1; XY_UpdateAllWindows(); } typedef FreeCaller ShowCoordinatesToggleCaller; -void ShowCoordinatesExport( const BoolImportCallback& importer ){ +void ShowCoordinatesExport( const ImportExportCallback::Import_t& importer ){ importer( g_xywindow_globals_private.show_coordinates ); } -typedef FreeCaller ShowCoordinatesExportCaller; +typedef FreeCaller::Import_t&), ShowCoordinatesExport> ShowCoordinatesExportCaller; void ShowOutlineToggle(){ g_xywindow_globals_private.show_outline ^= 1; XY_UpdateAllWindows(); } typedef FreeCaller ShowOutlineToggleCaller; -void ShowOutlineExport( const BoolImportCallback& importer ){ +void ShowOutlineExport( const ImportExportCallback::Import_t& importer ){ importer( g_xywindow_globals_private.show_outline ); } -typedef FreeCaller ShowOutlineExportCaller; +typedef FreeCaller::Import_t&), ShowOutlineExport> ShowOutlineExportCaller; void ShowAxesToggle(){ g_xywindow_globals_private.show_axis ^= 1; XY_UpdateAllWindows(); } typedef FreeCaller ShowAxesToggleCaller; -void ShowAxesExport( const BoolImportCallback& importer ){ +void ShowAxesExport( const ImportExportCallback::Import_t& importer ){ importer( g_xywindow_globals_private.show_axis ); } -typedef FreeCaller ShowAxesExportCaller; +typedef FreeCaller::Import_t&), ShowAxesExport> ShowAxesExportCaller; void ShowWorkzoneToggle(){ g_xywindow_globals_private.d_show_work ^= 1; XY_UpdateAllWindows(); } typedef FreeCaller ShowWorkzoneToggleCaller; -void ShowWorkzoneExport( const BoolImportCallback& importer ){ +void ShowWorkzoneExport( const ImportExportCallback::Import_t& importer ){ importer( g_xywindow_globals_private.d_show_work ); } -typedef FreeCaller ShowWorkzoneExportCaller; +typedef FreeCaller::Import_t&), ShowWorkzoneExport> ShowWorkzoneExportCaller; ShowNamesExportCaller g_show_names_caller; -BoolExportCallback g_show_names_callback( g_show_names_caller ); +ImportExportCallback::Export_t g_show_names_callback( g_show_names_caller ); ToggleItem g_show_names( g_show_names_callback ); ShowAnglesExportCaller g_show_angles_caller; -BoolExportCallback g_show_angles_callback( g_show_angles_caller ); +ImportExportCallback::Export_t g_show_angles_callback( g_show_angles_caller ); ToggleItem g_show_angles( g_show_angles_callback ); ShowBlocksExportCaller g_show_blocks_caller; -BoolExportCallback g_show_blocks_callback( g_show_blocks_caller ); +ImportExportCallback::Export_t g_show_blocks_callback( g_show_blocks_caller ); ToggleItem g_show_blocks( g_show_blocks_callback ); ShowCoordinatesExportCaller g_show_coordinates_caller; -BoolExportCallback g_show_coordinates_callback( g_show_coordinates_caller ); +ImportExportCallback::Export_t g_show_coordinates_callback( g_show_coordinates_caller ); ToggleItem g_show_coordinates( g_show_coordinates_callback ); ShowOutlineExportCaller g_show_outline_caller; -BoolExportCallback g_show_outline_callback( g_show_outline_caller ); +ImportExportCallback::Export_t g_show_outline_callback( g_show_outline_caller ); ToggleItem g_show_outline( g_show_outline_callback ); ShowAxesExportCaller g_show_axes_caller; -BoolExportCallback g_show_axes_callback( g_show_axes_caller ); +ImportExportCallback::Export_t g_show_axes_callback( g_show_axes_caller ); ToggleItem g_show_axes( g_show_axes_callback ); ShowWorkzoneExportCaller g_show_workzone_caller; -BoolExportCallback g_show_workzone_callback( g_show_workzone_caller ); +ImportExportCallback::Export_t g_show_workzone_callback( g_show_workzone_caller ); ToggleItem g_show_workzone( g_show_workzone_callback ); void XYShow_registerCommands(){ @@ -2733,10 +2733,10 @@ void ToggleShown_importBool( ToggleShown& self, bool value ){ self.set( value ); } typedef ReferenceCaller ToggleShownImportBoolCaller; -void ToggleShown_exportBool( const ToggleShown& self, const BoolImportCallback& importer ){ +void ToggleShown_exportBool( const ToggleShown& self, const ImportExportCallback::Import_t& importer ){ importer( self.active() ); } -typedef ConstReferenceCaller ToggleShownExportBoolCaller; +typedef ConstReferenceCaller::Import_t&), ToggleShown_exportBool> ToggleShownExportBoolCaller; void XYWindow_Construct(){