From fea0d2e6575b21945c4800805d66e43a2247ded5 Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 3 Jan 2018 13:39:43 +1100 Subject: [PATCH] Introduce Property to simplify preferences system --- include/ientity.h | 2 +- include/preferencesystem.cpp | 10 +- include/preferencesystem.h | 25 +++- libs/CMakeLists.txt | 1 + libs/generic/callback.h | 144 ++++++++++++--------- libs/gtkutil/accelerator.h | 5 +- libs/gtkutil/widget.cpp | 2 +- libs/gtkutil/widget.h | 15 +-- libs/gtkutil/window.cpp | 16 +-- libs/gtkutil/window.h | 20 ++- libs/property.h | 167 ++++++++++++++++++++++++ libs/stringio.h | 222 +++++++++----------------------- plugins/entity/entity.cpp | 10 +- radiant/autosave.cpp | 6 +- radiant/brushmanip.cpp | 2 +- radiant/brushmodule.cpp | 32 ++--- radiant/build.cpp | 2 +- radiant/camwindow.cpp | 174 ++++++++++++------------- radiant/commands.cpp | 2 +- radiant/commands.h | 2 +- radiant/dialog.cpp | 224 +++++++++++++++------------------ radiant/dialog.h | 102 ++++----------- radiant/entity.cpp | 27 ++-- radiant/entityinspector.cpp | 4 +- radiant/entitylist.cpp | 2 +- radiant/filters.cpp | 6 +- radiant/grid.cpp | 6 +- radiant/groupdialog.cpp | 6 +- radiant/groupdialog.h | 7 +- radiant/mainframe.cpp | 112 +++++++++-------- radiant/map.cpp | 8 +- radiant/mru.cpp | 4 +- radiant/multimon.cpp | 4 +- radiant/patchdialog.cpp | 12 +- radiant/patchmanip.cpp | 2 +- radiant/preferencedictionary.h | 19 ++- radiant/preferences.cpp | 84 +++++++------ radiant/preferences.h | 51 ++++---- radiant/surfacedialog.cpp | 18 ++- radiant/textures.cpp | 216 ++++++++++++++++--------------- radiant/texwindow.cpp | 212 +++++++++++++++---------------- radiant/texwindow.h | 5 +- radiant/undo.cpp | 28 ++--- radiant/watchbsp.cpp | 8 +- radiant/xywindow.cpp | 111 ++++++++-------- 45 files changed, 1081 insertions(+), 1056 deletions(-) create mode 100644 libs/property.h diff --git a/include/ientity.h b/include/ientity.h index 0ea6e25d..dd3f253c 100644 --- a/include/ientity.h +++ b/include/ientity.h @@ -124,7 +124,7 @@ virtual void setCounter( Counter* counter ) = 0; virtual void connectEntities( const scene::Path& e1, const scene::Path& e2, int index ) = 0; virtual void setLightRadii( bool lightRadii ) = 0; -virtual bool getLightRadii() = 0; +virtual bool getLightRadii() const = 0; virtual void setShowNames( bool showNames ) = 0; virtual bool getShowNames() = 0; virtual void setShowAngles( bool showAngles ) = 0; diff --git a/include/preferencesystem.cpp b/include/preferencesystem.cpp index 5476f9d6..5796d76f 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( ImportExportCallback::Import_t& importer ){ +void exportString( Callback& importer ){ importer( m_string.c_str() ); } -typedef MemberCaller::Import_t&), &StringPreference::exportString> ExportStringCaller; +typedef MemberCaller&), &StringPreference::exportString> ExportStringCaller; }; -inline void int_export( int i, ImportExportCallback::Import_t& importer ){ +inline void int_export( int i, Callback& 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( ImportExportCallback::Import_t& importer ){ +void exportString( Callback& importer ){ int_export( m_int, importer ); } -typedef MemberCaller::Import_t&), &IntPreference::exportString> ExportStringCaller; +typedef MemberCaller&), &IntPreference::exportString> ExportStringCaller; }; class IntPreferenceImporter diff --git a/include/preferencesystem.h b/include/preferencesystem.h index a82676ec..6479ec91 100644 --- a/include/preferencesystem.h +++ b/include/preferencesystem.h @@ -24,16 +24,31 @@ #include "generic/constant.h" #include "generic/callback.h" +#include "property.h" -class PreferenceSystem -{ +class PreferenceSystem { public: -INTEGER_CONSTANT( Version, 1 ); -STRING_CONSTANT( Name, "preferences" ); + INTEGER_CONSTANT(Version, 1); + STRING_CONSTANT(Name, "preferences"); -virtual void registerPreference( const char* name, const ImportExportCallback::Import_t& importer, const ImportExportCallback::Export_t& exporter ) = 0; + virtual void registerPreference(const char *name, const Property &cb) = 0; }; +template +Property make_property_string(Self &it) { + return make_property>(it); +} + +template +Property make_property_string(Self &it) { + return make_property_chain, const char *>, I>(it); +} + +template +Property make_property_string() { + return make_property_chain, const char *>, I>(); +} + #include "modulesystem.h" template diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 9094354e..9f5f834c 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -39,6 +39,7 @@ add_library(libs fs_path.h globaldefs.h imagelib.h + property.h instancelib.h maplib.h moduleobservers.h diff --git a/libs/generic/callback.h b/libs/generic/callback.h index 26772880..577dd9d9 100644 --- a/libs/generic/callback.h +++ b/libs/generic/callback.h @@ -69,65 +69,92 @@ namespace detail { namespace detail { - template - inline void *convertToOpaque(Type *t) { - return t; - } + template + struct ConvertFromOpaque { + }; - template - inline void *convertToOpaque(const Type *t) { - return const_cast( t ); - } + // reference - template - inline void *convertToOpaque(Type &t) { + template + inline const void *convertToOpaque(const T &t) { return &t; } - template - inline void *convertToOpaque(const Type &t) { - return const_cast( &t ); - } - - - template - class ConvertFromOpaque { + template + struct ConvertFromOpaque { + static T const &apply(void *p) { + return *static_cast(p); + } }; - template - class ConvertFromOpaque { - public: - static Type &apply(void *p) { - return *static_cast( p ); + template + inline void *convertToOpaque(T &t) { + return &t; + } + + template + struct ConvertFromOpaque { + static T &apply(void *p) { + return *static_cast( p ); } }; - template - class ConvertFromOpaque { - public: - static const Type &apply(void *p) { - return *static_cast( p ); + // pointer + + template + inline const void *convertToOpaque(const T *t) { + return t; + } + + template + struct ConvertFromOpaque { + static const T *apply(void *p) { + return static_cast(p); } }; + template + inline void *convertToOpaque(T *t) { + return t; + } - template - class ConvertFromOpaque { - public: - static Type *apply(void *p) { - // illegal cast - return reinterpret_cast( p ); + template + struct ConvertFromOpaque { + static T *apply(void *p) { + return static_cast(p); } }; - template - class ConvertFromOpaque { - public: - static const Type *apply(void *p) { - return static_cast( p ); + // function pointer + + template + inline const void *convertToOpaque(R(*const &t)(Ts...)) { + return &t; + } + + template + struct ConvertFromOpaque { + using Type = R(*)(Ts...); + + static Type const &apply(void *p) { + return *static_cast(p); } }; + template + inline void *convertToOpaque(R(*&t)(Ts...)) { + return &t; + } + + template + struct ConvertFromOpaque { + using Type = R(*)(Ts...); + + static Type &apply(void *p) { + return *static_cast(p); + } + }; + template class BindFirstOpaqueN; @@ -147,11 +174,15 @@ namespace detail { } static R thunk(void *environment, Ts... args) { - return Caller::call(detail::ConvertFromOpaque::apply(environment), args...); + return thunk_(detail::ConvertFromOpaque::apply(environment), args...); + } + + static R thunk_(FirstBound environment, Ts... args) { + return Caller::call(environment, args...); } void *getEnvironment() const { - return detail::convertToOpaque(firstBound); + return const_cast(detail::convertToOpaque(firstBound)); } }; @@ -291,15 +322,16 @@ namespace detail { } }; - template - struct freecallwrapper; + template + struct FreeCallerWrapper; + + template + struct FreeCallerWrapper { + using func = R(void *, Ts...); - template - struct freecallwrapper { - using func = R(R(Ts...), Ts...); - static R call(R(*f)(Ts...), Ts... args) { + static R call(void *f, Ts... args) { // ideally, we'd get the implementation of the function type directly. Instead, it's passed in - return f(args...); + return reinterpret_cast(f)(args...); } }; } @@ -308,18 +340,10 @@ namespace detail { template using FreeCaller = detail::FreeCaller, F>; -template -inline Callback makeCallbackF(F *func) { - // illegal cast - return Callback(reinterpret_cast(func), BindFirstOpaque>::thunk); +template +inline Callback makeCallbackF(R(*func)(Ts...)) { + void *pVoid = reinterpret_cast(func); + return BindFirstOpaque>(pVoid); } -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 f2be1821..528dd6bb 100644 --- a/libs/gtkutil/accelerator.h +++ b/libs/gtkutil/accelerator.h @@ -26,6 +26,7 @@ #include #include "generic/callback.h" +#include "property.h" // ignore numlock #define ALLOWED_MODIFIERS ( ~( GDK_MOD2_MASK | GDK_LOCK_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK ) ) @@ -111,8 +112,8 @@ class Toggle { public: Command m_command; -ImportExportCallback::Export_t m_exportCallback; -Toggle( const Callback& callback, const Accelerator& accelerator, const ImportExportCallback::Export_t& exportCallback ) : m_command( callback, accelerator ), m_exportCallback( exportCallback ){ +Callback &)> m_exportCallback; +Toggle( const Callback& callback, const Accelerator& accelerator, const Callback &)>& exportCallback ) : m_command( callback, accelerator ), m_exportCallback( exportCallback ){ } }; diff --git a/libs/gtkutil/widget.cpp b/libs/gtkutil/widget.cpp index db429083..9d9c1a8d 100644 --- a/libs/gtkutil/widget.cpp +++ b/libs/gtkutil/widget.cpp @@ -39,7 +39,7 @@ bool ToggleShown::active() const } } -void ToggleShown::exportActive(const ImportExportCallback::Import_t &importCallback) +void ToggleShown::exportActive(const Callback &importCallback) { importCallback(active()); } diff --git a/libs/gtkutil/widget.h b/libs/gtkutil/widget.h index 0cc8da3f..52b7d9c4 100644 --- a/libs/gtkutil/widget.h +++ b/libs/gtkutil/widget.h @@ -28,13 +28,14 @@ #include "generic/callback.h" #include "warnings.h" #include "debugging/debugging.h" +#include "property.h" class ToggleItem { - ImportExportCallback::Export_t m_exportCallback; - typedef std::list::Import_t> ImportCallbacks; + Callback &)> m_exportCallback; + typedef std::list> ImportCallbacks; ImportCallbacks m_importCallbacks; public: - ToggleItem(const ImportExportCallback::Export_t &exportCallback) : m_exportCallback(exportCallback) + ToggleItem(const Callback &)> &exportCallback) : m_exportCallback(exportCallback) { } @@ -45,13 +46,13 @@ public: } } - void addCallback(const ImportExportCallback::Import_t &callback) + void addCallback(const Callback &callback) { m_importCallbacks.push_back(callback); m_exportCallback(callback); } - typedef MemberCaller::Import_t &), &ToggleItem::addCallback> AddCallbackCaller; + typedef MemberCaller &), &ToggleItem::addCallback> AddCallbackCaller; }; class ToggleShown { @@ -77,9 +78,9 @@ public: bool active() const; - void exportActive(const ImportExportCallback::Import_t &importCallback); + void exportActive(const Callback &importCallback); - typedef MemberCaller::Import_t &), &ToggleShown::exportActive> ActiveCaller; + typedef MemberCaller &), &ToggleShown::exportActive> ActiveCaller; void set(bool shown); diff --git a/libs/gtkutil/window.cpp b/libs/gtkutil/window.cpp index e2d7ec39..11b6efeb 100644 --- a/libs/gtkutil/window.cpp +++ b/libs/gtkutil/window.cpp @@ -183,30 +183,30 @@ void window_set_position(ui::Window window, const WindowPosition &position) gtk_window_set_default_size( window, position.w, position.h ); } -void WindowPosition_Parse(WindowPosition &position, const char *value) +void WindowPosition_String::Import(WindowPosition &position, const char *value) { if ( sscanf( value, "%d %d %d %d", &position.x, &position.y, &position.w, &position.h ) != 4 ) { position = WindowPosition( c_default_window_pos ); // ensure sane default value for window position } } -void WindowPosition_Write(const WindowPosition &position, const ImportExportCallback::Import_t &importCallback) +void WindowPosition_String::Export(const WindowPosition &self, const Callback &returnz) { char buffer[64]; - sprintf( buffer, "%d %d %d %d", position.x, position.y, position.w, position.h ); - importCallback( buffer ); + sprintf( buffer, "%d %d %d %d", self.x, self.y, self.w, self.h ); + returnz( buffer ); } -void WindowPositionTracker_importString(WindowPositionTracker &self, const char *value) +void WindowPositionTracker_String::Import(WindowPositionTracker &self, const char *value) { WindowPosition position; - WindowPosition_Parse( position, value ); + WindowPosition_String::Import( position, value ); self.setPosition( position ); } -void WindowPositionTracker_exportString(const WindowPositionTracker &self, const ImportExportCallback::Import_t &importer) +void WindowPositionTracker_String::Export(const WindowPositionTracker &self, const Callback &returnz) { - WindowPosition_Write( self.getPosition(), importer ); + WindowPosition_String::Export( self.getPosition(), returnz ); } gboolean WindowPositionTracker::configure(ui::Widget widget, GdkEventConfigure *event, WindowPositionTracker *self) diff --git a/libs/gtkutil/window.h b/libs/gtkutil/window.h index 83b4c00b..69135f83 100644 --- a/libs/gtkutil/window.h +++ b/libs/gtkutil/window.h @@ -66,14 +66,13 @@ void window_get_position(ui::Window window, WindowPosition &position); void window_set_position(ui::Window window, const WindowPosition &position); -void WindowPosition_Parse(WindowPosition &position, const char *value); +struct WindowPosition_String { -typedef ReferenceCaller WindowPositionImportStringCaller; + static void Export(const WindowPosition &self, const Callback &returnz); -void WindowPosition_Write(const WindowPosition &position, const ImportExportCallback::Import_t &importCallback); - -typedef ConstReferenceCaller::Import_t &), WindowPosition_Write> WindowPositionExportStringCaller; + static void Import(WindowPosition &self, const char *value); +}; class WindowPositionTracker { WindowPosition m_position; @@ -97,13 +96,10 @@ public: }; -void WindowPositionTracker_importString(WindowPositionTracker &self, const char *value); - -typedef ReferenceCaller WindowPositionTrackerImportStringCaller; - -void WindowPositionTracker_exportString(const WindowPositionTracker &self, const ImportExportCallback::Import_t &importer); - -typedef ConstReferenceCaller::Import_t &), WindowPositionTracker_exportString> WindowPositionTrackerExportStringCaller; +struct WindowPositionTracker_String { + static void Export(const WindowPositionTracker &self, const Callback &returnz); + static void Import(WindowPositionTracker &self, const char *value); +}; #endif diff --git a/libs/property.h b/libs/property.h new file mode 100644 index 00000000..abdb32f4 --- /dev/null +++ b/libs/property.h @@ -0,0 +1,167 @@ +#ifndef INCLUDED_IMPORTEXPORT_H +#define INCLUDED_IMPORTEXPORT_H + +#include "generic/callback.h" +#include "string/string.h" + +template +struct Property { + // todo: just return T, don't use continuation passing style + Callback &returnz)> get; + Callback set; +}; + +// implementation + +template +struct PropertyImpl { + static void Export(const Self &self, const Callback &returnz) { + returnz(self); + } + + static void Import(Self &self, T value) { + self = value; + } +}; + +namespace detail { + + template + using propertyimpl_self = typename std::remove_reference>::type; + + template + using propertyimpl_other = get_argument; + + template + using propertyimpl_other_free = get_argument; + +} + +// adaptor + +template< + class Self, + class T = Self, + class I = PropertyImpl +> +struct PropertyAdaptor { + using Type = Self; + using Other = T; + + using Get = ConstReferenceCaller &), I::Export>; + using Set = ReferenceCaller; +}; + +template< + class T, + class I +> +struct PropertyAdaptorFree { + using Other = T; + + using Get = FreeCaller &), I::Export>; + using Set = FreeCaller; +}; + +// explicit full + +template +Property make_property(typename A::Type &self) { + return {typename A::Get(self), typename A::Set(self)}; +} + +template +Property make_property() { + return {typename A::Get(), typename A::Set()}; +} + +// explicit impl + +template, class T = detail::propertyimpl_other> +using property_impl = PropertyAdaptor; + +template> +Property make_property(Self &self) { + return make_property>(self); +} + +template> +using property_impl_free = PropertyAdaptorFree; + +template> +Property make_property() { + return make_property>(); +} + +// implicit + +template +Property make_property(Self &self) { + return make_property>(self); +} + +// chain + +template +Property> make_property_chain(detail::propertyimpl_self &it) { + using DST = detail::propertyimpl_other; + using SRC = detail::propertyimpl_self; + using X = detail::propertyimpl_self; + + using A = property_impl; + struct I { + static void ExportThunk(const Callback &self, SRC value) { + PropertyImpl::Export(value, self); + } + + static void Export(const X &self, const Callback &returnz) { + A::Get::thunk_(self, ConstReferenceCaller, void(SRC), ExportThunk>(returnz)); + } + + static void Import(X &self, DST value) { + SRC out; + PropertyImpl::Import(out, value); + A::Set::thunk_(self, out); + } + }; + return make_property>(it); +} + +template +Property> make_property_chain() { + using DST = detail::propertyimpl_other; + using SRC = detail::propertyimpl_self; + + using A = property_impl_free; + struct I { + static void ExportThunk(const Callback &self, SRC value) { + PropertyImpl::Export(value, self); + } + + static void Export(const Callback &returnz) { + A::Get::thunk_(nullptr, ConstReferenceCaller, void(SRC), ExportThunk>(returnz)); + } + + static void Import(DST value) { + SRC out; + PropertyImpl::Import(out, value); + A::Set::thunk_(nullptr, out); + } + }; + return make_property>(); +} + +// specializations + +template<> +struct PropertyImpl { + static void Export(const CopiedString &self, const Callback &returnz) { + returnz(self.c_str()); + } + + static void Import(CopiedString &self, const char *value) { + self = value; + } +}; + +#endif diff --git a/libs/stringio.h b/libs/stringio.h index 0eb5d337..47772ee4 100644 --- a/libs/stringio.h +++ b/libs/stringio.h @@ -29,6 +29,7 @@ #include "iscriplib.h" #include "string/string.h" #include "generic/callback.h" +#include "property.h" inline float string_read_float( const char* string ){ return static_cast( atof( string ) ); @@ -287,183 +288,78 @@ inline TextOutputStreamType& ostream_write( TextOutputStreamType& outputStream, } - - -inline void CopiedString_importString( CopiedString& self, const char* string ){ - self = string; -} -typedef ReferenceCaller CopiedStringImportStringCaller; -inline void CopiedString_exportString( const CopiedString& self, const ImportExportCallback::Import_t& importer ){ - importer( self.c_str() ); -} -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 ImportExportCallback::Import_t& importer ){ - importer( self ? "true" : "false" ); -} -typedef ConstReferenceCaller::Import_t&), Bool_exportString> BoolExportStringCaller; - -inline void Int_importString( int& self, const char* string ){ - if ( !string_parse_int( string, self ) ) { - self = 0; - } -} -typedef ReferenceCaller IntImportStringCaller; -inline void Int_exportString( const int& self, const ImportExportCallback::Import_t& importer ){ - char buffer[16]; - sprintf( buffer, "%d", self ); - importer( buffer ); -} -typedef ConstReferenceCaller::Import_t&), Int_exportString> IntExportStringCaller; - -inline void Size_importString( std::size_t& self, const char* string ){ - int i; - if ( string_parse_int( string, i ) && i >= 0 ) { - self = i; - } - else - { - self = 0; +template<> +struct PropertyImpl { + static void Export(const bool &self, const Callback &returnz) { + returnz(self ? "true" : "false"); } -} -typedef ReferenceCaller SizeImportStringCaller; -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::Import_t&), Size_exportString> SizeExportStringCaller; -inline void Float_importString( float& self, const char* string ){ - if ( !string_parse_float( string, self ) ) { - self = 0; - } -} -typedef ReferenceCaller FloatImportStringCaller; -inline void Float_exportString( const float& self, const ImportExportCallback::Import_t& importer ){ - char buffer[16]; - sprintf( buffer, "%g", self ); - importer( buffer ); -} -typedef ConstReferenceCaller::Import_t&), Float_exportString> FloatExportStringCaller; + static void Import(bool &self, const char *value) { + self = string_equal(value, "true"); + } +}; -inline void Vector3_importString( Vector3& self, const char* string ){ - if ( !string_parse_vector3( string, self ) ) { - self = Vector3( 0, 0, 0 ); +template<> +struct PropertyImpl { + static void Export(const int &self, const Callback &returnz) { + char buffer[16]; + sprintf(buffer, "%d", self); + returnz(buffer); } -} -typedef ReferenceCaller Vector3ImportStringCaller; -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::Import_t&), Vector3_exportString> Vector3ExportStringCaller; - - -template -class ImportConvert1 -{ -public: -static void thunk( void* environment, FirstArgument firstArgument ){ - Caller::thunk( environment, FirstConversion( firstArgument ) ); -} + static void Import(int &self, const char *value) { + if (!string_parse_int(value, self)) { + self = 0; + } + } }; +template<> +struct PropertyImpl { + static void Export(const std::size_t &self, const Callback &returnz) { + char buffer[16]; + sprintf(buffer, "%u", Unsigned(self)); + returnz(buffer); + } -class BoolFromString -{ -bool m_value; -public: -BoolFromString( const char* string ){ - Bool_importString( m_value, string ); -} -operator bool() const -{ - return m_value; -} + static void Import(std::size_t &self, const char *value) { + int i; + if (string_parse_int(value, i) && i >= 0) { + self = i; + } else { + self = 0; + } + } }; -inline void Bool_toString( const ImportExportCallback::Import_t& self, bool value ){ - Bool_exportString( value, self ); -} -typedef ConstReferenceCaller::Import_t, void(bool), Bool_toString> BoolToString; - - -template -inline ImportExportCallback::Import_t makeBoolStringImportCallback( const Caller& caller ){ - return ImportExportCallback::Import_t( caller.getEnvironment(), ImportConvert1::Import_t, 0>, Caller, BoolFromString>::thunk ); -} - -template -inline ImportExportCallback::Export_t makeBoolStringExportCallback( const Caller& caller ){ - return ImportExportCallback::Export_t( caller.getEnvironment(), ImportConvert1::Export_t, 0>, Caller, BoolToString>::thunk ); -} - +template<> +struct PropertyImpl { + static void Export(const float &self, const Callback &returnz) { + char buffer[16]; + sprintf(buffer, "%g", self); + returnz(buffer); + } -class IntFromString -{ -int m_value; -public: -IntFromString( const char* string ){ - Int_importString( m_value, string ); -} -operator int() const -{ - return m_value; -} + static void Import(float &self, const char *value) { + if (!string_parse_float(value, self)) { + self = 0; + } + } }; -inline void Int_toString( const ImportExportCallback::Import_t& self, int value ){ - Int_exportString( value, self ); -} -typedef ConstReferenceCaller::Import_t, void(int), Int_toString> IntToString; - - -template -inline ImportExportCallback::Import_t makeIntStringImportCallback( const Caller& caller ){ - return ImportExportCallback::Import_t( caller.getEnvironment(), ImportConvert1::Import_t, 0>, Caller, IntFromString>::thunk ); -} - -template -inline ImportExportCallback::Export_t makeIntStringExportCallback( const Caller& caller ){ - return ImportExportCallback::Export_t( caller.getEnvironment(), ImportConvert1::Export_t, 0>, Caller, IntToString>::thunk ); -} - - +template<> +struct PropertyImpl { + static void Export(const Vector3 &self, const Callback &returnz) { + char buffer[64]; + sprintf(buffer, "%g %g %g", self[0], self[1], self[2]); + returnz(buffer); + } -class SizeFromString -{ -std::size_t m_value; -public: -SizeFromString( const char* string ){ - Size_importString( m_value, string ); -} -operator std::size_t() const -{ - return m_value; -} + static void Import(Vector3 &self, const char *value) { + if (!string_parse_vector3(value, self)) { + self = Vector3(0, 0, 0); + } + } }; -inline void Size_toString( const ImportExportCallback::Import_t& self, std::size_t value ){ - Size_exportString( value, self ); -} -typedef ConstReferenceCaller::Import_t, void(std::size_t), Size_toString> SizeToString; - - -template -inline ImportExportCallback::Import_t makeSizeStringImportCallback( const Caller& caller ){ - return ImportExportCallback::Import_t( caller.getEnvironment(), ImportConvert1::Import_t, 0>, Caller, SizeFromString>::thunk ); -} - -template -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/plugins/entity/entity.cpp b/plugins/entity/entity.cpp index 1f286e05..dfd2a640 100644 --- a/plugins/entity/entity.cpp +++ b/plugins/entity/entity.cpp @@ -229,7 +229,7 @@ void connectEntities( const scene::Path& path, const scene::Path& targetPath, in void setLightRadii( bool lightRadii ){ g_lightRadii = lightRadii; } -bool getLightRadii(){ +bool getLightRadii() const { return g_lightRadii; } void setShowNames( bool showNames ){ @@ -330,10 +330,10 @@ void Entity_Construct( EGameType gameType ){ Static::instance().m_nameKey = "targetname"; } - GlobalPreferenceSystem().registerPreference( "SI_ShowNames", BoolImportStringCaller( g_showNames ), BoolExportStringCaller( g_showNames ) ); - GlobalPreferenceSystem().registerPreference( "SI_ShowAngles", BoolImportStringCaller( g_showAngles ), BoolExportStringCaller( g_showAngles ) ); - GlobalPreferenceSystem().registerPreference( "NewLightStyle", BoolImportStringCaller( g_newLightDraw ), BoolExportStringCaller( g_newLightDraw ) ); - GlobalPreferenceSystem().registerPreference( "LightRadiuses", BoolImportStringCaller( g_lightRadii ), BoolExportStringCaller( g_lightRadii ) ); + GlobalPreferenceSystem().registerPreference( "SI_ShowNames", make_property_string( g_showNames ) ); + GlobalPreferenceSystem().registerPreference( "SI_ShowAngles", make_property_string( g_showAngles ) ); + GlobalPreferenceSystem().registerPreference( "NewLightStyle", make_property_string( g_newLightDraw ) ); + GlobalPreferenceSystem().registerPreference( "LightRadiuses", make_property_string( g_lightRadii ) ); Entity_InitFilters(); LightType lightType = LIGHTTYPE_DEFAULT; diff --git a/radiant/autosave.cpp b/radiant/autosave.cpp index effb111e..c3eaf766 100644 --- a/radiant/autosave.cpp +++ b/radiant/autosave.cpp @@ -194,9 +194,9 @@ void Autosave_registerPreferencesPage(){ #include "stringio.h" void Autosave_Construct(){ - GlobalPreferenceSystem().registerPreference( "Autosave", BoolImportStringCaller( g_AutoSave_Enabled ), BoolExportStringCaller( g_AutoSave_Enabled ) ); - GlobalPreferenceSystem().registerPreference( "AutosaveMinutes", IntImportStringCaller( m_AutoSave_Frequency ), IntExportStringCaller( m_AutoSave_Frequency ) ); - GlobalPreferenceSystem().registerPreference( "Snapshots", BoolImportStringCaller( g_SnapShots_Enabled ), BoolExportStringCaller( g_SnapShots_Enabled ) ); + GlobalPreferenceSystem().registerPreference( "Autosave", make_property_string( g_AutoSave_Enabled ) ); + GlobalPreferenceSystem().registerPreference( "AutosaveMinutes", make_property_string( m_AutoSave_Frequency ) ); + GlobalPreferenceSystem().registerPreference( "Snapshots", make_property_string( g_SnapShots_Enabled ) ); Autosave_registerPreferencesPage(); } diff --git a/radiant/brushmanip.cpp b/radiant/brushmanip.cpp index 0e190e6c..abee96d0 100644 --- a/radiant/brushmanip.cpp +++ b/radiant/brushmanip.cpp @@ -1202,7 +1202,7 @@ void FlipClipper(){ Callback g_texture_lock_status_changed; -BoolExportCaller g_texdef_movelock_caller( g_brush_texturelock_enabled ); +ConstReferenceCaller &), PropertyImpl::Export> g_texdef_movelock_caller( g_brush_texturelock_enabled ); ToggleItem g_texdef_movelock_item( g_texdef_movelock_caller ); void Texdef_ToggleMoveLock(){ diff --git a/radiant/brushmodule.cpp b/radiant/brushmodule.cpp index fb67b498..2ab573e5 100644 --- a/radiant/brushmodule.cpp +++ b/radiant/brushmodule.cpp @@ -42,19 +42,20 @@ bool getTextureLockEnabled(){ return g_brush_texturelock_enabled; } -void Face_importSnapPlanes( bool value ){ - Face::m_quantise = value ? quantiseInteger : quantiseFloating; -} +struct Face_SnapPlanes { + static void Export(const QuantiseFunc &self, const Callback &returnz) { + returnz(self == quantiseInteger); + } -void Face_exportSnapPlanes( const ImportExportCallback::Import_t& importer ){ - importer( Face::m_quantise == quantiseInteger ); -} + static void Import(QuantiseFunc &self, bool value) { + self = value ? quantiseInteger : quantiseFloating; + } +}; void Brush_constructPreferences( PreferencesPage& page ){ page.appendCheckBox( "", "Snap planes to integer grid", - {makeCallbackF(Face_importSnapPlanes), - makeCallbackF(Face_exportSnapPlanes)} + make_property(Face::m_quantise) ); page.appendEntry( "Default texture scale", @@ -63,7 +64,7 @@ void Brush_constructPreferences( PreferencesPage& page ){ if ( g_showAlternativeTextureProjectionOption ) { page.appendCheckBox( "", "Use alternative texture-projection (\"brush primitives\")", - mkImportExportCallback(g_useAlternativeTextureProjection) + make_property(g_useAlternativeTextureProjection) ); } // d1223m @@ -110,8 +111,7 @@ void Brush_Construct( EBrushType type ){ GlobalPreferenceSystem().registerPreference( "AlternativeTextureProjection", - BoolImportStringCaller( g_useAlternativeTextureProjection.m_latched ), - BoolExportStringCaller( g_useAlternativeTextureProjection.m_latched ) + make_property_string( g_useAlternativeTextureProjection.m_latched ) ); g_useAlternativeTextureProjection.useLatched(); @@ -122,8 +122,8 @@ void Brush_Construct( EBrushType type ){ // d1223m GlobalPreferenceSystem().registerPreference( "BrushAlwaysCaulk", - BoolImportStringCaller( g_brush_always_caulk ), - BoolExportStringCaller( g_brush_always_caulk ) ); + make_property_string( g_brush_always_caulk ) + ); } Brush_registerCommands(); @@ -151,9 +151,9 @@ 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::Import_t&), Face_exportSnapPlanes>() ) ); - GlobalPreferenceSystem().registerPreference( "TexdefDefaultScale", FloatImportStringCaller( g_texdef_default_scale ), FloatExportStringCaller( g_texdef_default_scale ) ); + GlobalPreferenceSystem().registerPreference( "TextureLock", make_property_string( g_brush_texturelock_enabled ) ); + GlobalPreferenceSystem().registerPreference("BrushSnapPlanes", make_property_string(Face::m_quantise)); + GlobalPreferenceSystem().registerPreference( "TexdefDefaultScale", make_property_string( g_texdef_default_scale ) ); GridStatus_getTextureLockEnabled = getTextureLockEnabled; g_texture_lock_status_changed = makeCallbackF(GridStatus_onTextureLockEnabledChanged); diff --git a/radiant/build.cpp b/radiant/build.cpp index a1eab6c3..47d8fff4 100644 --- a/radiant/build.cpp +++ b/radiant/build.cpp @@ -1026,7 +1026,7 @@ void SaveBuildMenu(){ #include "stringio.h" void BuildMenu_Construct(){ - GlobalPreferenceSystem().registerPreference( "BuildMenu", CopiedStringImportStringCaller( g_buildMenu ), CopiedStringExportStringCaller( g_buildMenu ) ); + GlobalPreferenceSystem().registerPreference( "BuildMenu", make_property_string( g_buildMenu ) ); LoadBuildMenu(); } void BuildMenu_Destroy(){ diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index 11ea6b23..04110ee7 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -1039,36 +1039,35 @@ void CamWnd_Move_Discrete_Disable( CamWnd& camwnd ){ command_disconnect_accelerator( "CameraAngleDown" ); } -void CamWnd_Move_Discrete_Import( CamWnd& camwnd, bool value ){ - if ( g_camwindow_globals_private.m_bCamDiscrete ) { - CamWnd_Move_Discrete_Disable( camwnd ); +struct CamWnd_Move_Discrete { + static void Export(const Callback &returnz) { + returnz(g_camwindow_globals_private.m_bCamDiscrete); } - else - { - CamWnd_Move_Disable( camwnd ); - } - - g_camwindow_globals_private.m_bCamDiscrete = value; - if ( g_camwindow_globals_private.m_bCamDiscrete ) { - CamWnd_Move_Discrete_Enable( camwnd ); - } - else - { - CamWnd_Move_Enable( camwnd ); + static void Import(bool value) { + if (g_camwnd) { + Import_(*g_camwnd, value); + } else { + g_camwindow_globals_private.m_bCamDiscrete = value; + } } -} -void CamWnd_Move_Discrete_Import( bool value ){ - if ( g_camwnd != 0 ) { - CamWnd_Move_Discrete_Import( *g_camwnd, value ); - } - else - { + static void Import_(CamWnd &camwnd, bool value) { + if (g_camwindow_globals_private.m_bCamDiscrete) { + CamWnd_Move_Discrete_Disable(camwnd); + } else { + CamWnd_Move_Disable(camwnd); + } + g_camwindow_globals_private.m_bCamDiscrete = value; - } -} + if (g_camwindow_globals_private.m_bCamDiscrete) { + CamWnd_Move_Discrete_Enable(camwnd); + } else { + CamWnd_Move_Enable(camwnd); + } + } +}; void CamWnd_Add_Handlers_Move( CamWnd& camwnd ){ @@ -1392,12 +1391,12 @@ void ShowStatsToggle(){ g_camwindow_globals_private.m_showStats ^= 1; } -void ShowStatsExport( const ImportExportCallback::Import_t& importer ){ +void ShowStatsExport( const Callback &importer ){ importer( g_camwindow_globals_private.m_showStats ); } -FreeCaller::Import_t&), ShowStatsExport> g_show_stats_caller; -ImportExportCallback::Export_t g_show_stats_callback( g_show_stats_caller ); +FreeCaller&), ShowStatsExport> g_show_stats_caller; +Callback &)> g_show_stats_callback( g_show_stats_caller ); ToggleItem g_show_stats( g_show_stats_callback ); void CamWnd::Cam_Draw(){ @@ -1640,7 +1639,7 @@ bool Camera_GetFarClip(){ return g_camwindow_globals_private.m_bCubicClipping; } -BoolExportCaller g_getfarclip_caller( g_camwindow_globals_private.m_bCubicClipping ); +ConstReferenceCaller &), PropertyImpl::Export> g_getfarclip_caller( g_camwindow_globals_private.m_bCubicClipping ); ToggleItem g_getfarclip_item( g_getfarclip_caller ); void Camera_SetFarClip( bool value ){ @@ -1651,6 +1650,16 @@ void Camera_SetFarClip( bool value ){ CamWnd_Update( camwnd ); } +struct Camera_FarClip { + static void Export(const Callback &returnz) { + returnz(g_camwindow_globals_private.m_bCubicClipping); + } + + static void Import(bool value) { + Camera_SetFarClip(value); + } +}; + void Camera_ToggleFarClip(){ Camera_SetFarClip( !Camera_GetFarClip() ); } @@ -1745,46 +1754,43 @@ void GlobalCamera_LookThroughCamera(){ CamWnd_LookThroughCamera( *g_camwnd ); } - -void RenderModeImport( int value ){ - switch ( value ) - { - case 0: - CamWnd_SetMode( cd_wire ); - break; - case 1: - CamWnd_SetMode( cd_solid ); - break; - case 2: - CamWnd_SetMode( cd_texture ); - break; - case 3: - CamWnd_SetMode( cd_lighting ); - break; - default: - CamWnd_SetMode( cd_texture ); +struct RenderMode { + static void Export(const Callback &returnz) { + switch (CamWnd_GetMode()) { + case cd_wire: + returnz(0); + break; + case cd_solid: + returnz(1); + break; + case cd_texture: + returnz(2); + break; + case cd_lighting: + returnz(3); + break; + } } -} -typedef FreeCaller RenderModeImportCaller; -void RenderModeExport( const ImportExportCallback::Import_t& importer ){ - switch ( CamWnd_GetMode() ) - { - case cd_wire: - importer( 0 ); - break; - case cd_solid: - importer( 1 ); - break; - case cd_texture: - importer( 2 ); - break; - case cd_lighting: - importer( 3 ); - break; + static void Import(int value) { + switch (value) { + case 0: + CamWnd_SetMode(cd_wire); + break; + case 1: + CamWnd_SetMode(cd_solid); + break; + case 2: + CamWnd_SetMode(cd_texture); + break; + case 3: + CamWnd_SetMode(cd_lighting); + break; + default: + CamWnd_SetMode(cd_texture); + } } -} -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 +1799,11 @@ 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 )} + make_property() ); page.appendCheckBox( "", "Enable far-clip plane", - {FreeCaller(), - BoolExportCaller( g_camwindow_globals_private.m_bCubicClipping )} + make_property() ); if ( g_pGameDescription->mGameType == "doom3" ) { @@ -1808,8 +1812,7 @@ void Camera_constructPreferences( PreferencesPage& page ){ page.appendCombo( "Render Mode", STRING_ARRAY_RANGE( render_mode ), - {ImportExportCallback::Import_t( RenderModeImportCaller() ), - ImportExportCallback::Export_t( RenderModeExportCaller() )} + make_property() ); } else @@ -1819,8 +1822,7 @@ void Camera_constructPreferences( PreferencesPage& page ){ page.appendCombo( "Render Mode", STRING_ARRAY_RANGE( render_mode ), - {ImportExportCallback::Import_t( RenderModeImportCaller() ), - ImportExportCallback::Export_t( RenderModeExportCaller() )} + make_property() ); } @@ -1844,8 +1846,6 @@ void Camera_registerPreferencesPage(){ #include "stringio.h" #include "dialog.h" -typedef FreeCaller CamWndMoveDiscreteImportCaller; - void CameraSpeed_increase(){ if ( g_camwindow_globals_private.m_nMoveSpeed <= ( MAX_CAM_SPEED - CAM_SPEED_STEP - 10 ) ) { g_camwindow_globals_private.m_nMoveSpeed += CAM_SPEED_STEP; @@ -1905,18 +1905,18 @@ void CamWnd_Construct(){ GlobalToggles_insert( "ShowStats", makeCallbackF(ShowStatsToggle), ToggleItem::AddCallbackCaller( g_show_stats ) ); - GlobalPreferenceSystem().registerPreference( "ShowStats", BoolImportStringCaller( g_camwindow_globals_private.m_showStats ), BoolExportStringCaller( g_camwindow_globals_private.m_showStats ) ); - GlobalPreferenceSystem().registerPreference( "MoveSpeed", IntImportStringCaller( g_camwindow_globals_private.m_nMoveSpeed ), IntExportStringCaller( g_camwindow_globals_private.m_nMoveSpeed ) ); - GlobalPreferenceSystem().registerPreference( "CamLinkSpeed", BoolImportStringCaller( g_camwindow_globals_private.m_bCamLinkSpeed ), BoolExportStringCaller( g_camwindow_globals_private.m_bCamLinkSpeed ) ); - GlobalPreferenceSystem().registerPreference( "AngleSpeed", IntImportStringCaller( g_camwindow_globals_private.m_nAngleSpeed ), IntExportStringCaller( g_camwindow_globals_private.m_nAngleSpeed ) ); - GlobalPreferenceSystem().registerPreference( "CamInverseMouse", BoolImportStringCaller( g_camwindow_globals_private.m_bCamInverseMouse ), BoolExportStringCaller( g_camwindow_globals_private.m_bCamInverseMouse ) ); - GlobalPreferenceSystem().registerPreference( "CamDiscrete", makeBoolStringImportCallback( CamWndMoveDiscreteImportCaller() ), BoolExportStringCaller( g_camwindow_globals_private.m_bCamDiscrete ) ); - GlobalPreferenceSystem().registerPreference( "CubicClipping", BoolImportStringCaller( g_camwindow_globals_private.m_bCubicClipping ), BoolExportStringCaller( g_camwindow_globals_private.m_bCubicClipping ) ); - GlobalPreferenceSystem().registerPreference( "CubicScale", IntImportStringCaller( g_camwindow_globals.m_nCubicScale ), IntExportStringCaller( g_camwindow_globals.m_nCubicScale ) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors4", Vector3ImportStringCaller( g_camwindow_globals.color_cameraback ), Vector3ExportStringCaller( g_camwindow_globals.color_cameraback ) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors12", Vector3ImportStringCaller( g_camwindow_globals.color_selbrushes3d ), Vector3ExportStringCaller( g_camwindow_globals.color_selbrushes3d ) ); - GlobalPreferenceSystem().registerPreference( "CameraRenderMode", makeIntStringImportCallback( RenderModeImportCaller() ), makeIntStringExportCallback( RenderModeExportCaller() ) ); - GlobalPreferenceSystem().registerPreference( "StrafeMode", IntImportStringCaller( g_camwindow_globals_private.m_nStrafeMode ), IntExportStringCaller( g_camwindow_globals_private.m_nStrafeMode ) ); + GlobalPreferenceSystem().registerPreference( "ShowStats", make_property_string( g_camwindow_globals_private.m_showStats ) ); + GlobalPreferenceSystem().registerPreference( "MoveSpeed", make_property_string( g_camwindow_globals_private.m_nMoveSpeed ) ); + GlobalPreferenceSystem().registerPreference( "CamLinkSpeed", make_property_string( g_camwindow_globals_private.m_bCamLinkSpeed ) ); + GlobalPreferenceSystem().registerPreference( "AngleSpeed", make_property_string( g_camwindow_globals_private.m_nAngleSpeed ) ); + GlobalPreferenceSystem().registerPreference( "CamInverseMouse", make_property_string( g_camwindow_globals_private.m_bCamInverseMouse ) ); + GlobalPreferenceSystem().registerPreference( "CamDiscrete", make_property_string()); + GlobalPreferenceSystem().registerPreference( "CubicClipping", make_property_string( g_camwindow_globals_private.m_bCubicClipping ) ); + GlobalPreferenceSystem().registerPreference( "CubicScale", make_property_string( g_camwindow_globals.m_nCubicScale ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors4", make_property_string( g_camwindow_globals.color_cameraback ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors12", make_property_string( g_camwindow_globals.color_selbrushes3d ) ); + GlobalPreferenceSystem().registerPreference( "CameraRenderMode", make_property_string() ); + GlobalPreferenceSystem().registerPreference( "StrafeMode", make_property_string( g_camwindow_globals_private.m_nStrafeMode ) ); CamWnd_constructStatic(); diff --git a/radiant/commands.cpp b/radiant/commands.cpp index 299958dc..93823894 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 ImportExportCallback::Export_t& exportCallback, const Accelerator& accelerator ){ +void GlobalToggles_insert( const char* name, const Callback& callback, const Callback &)>& 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 53f61ad1..8c6b9f19 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 ImportExportCallback::Export_t& exportCallback, const Accelerator& accelerator = accelerator_null() ); +void GlobalToggles_insert( const char* name, const Callback& callback, const Callback &)>& 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 9de0a333..ff215079 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -107,164 +107,141 @@ DialogSpinnerRow DialogSpinnerRow_new( const char* name, double value, double lo } -template< - typename Type_, - typename Other_ = Type_, - class T = impexp -> -class ImportExport { -public: - using Type = Type_; - using Other = Other_; - - using ImportCaller = ReferenceCaller; - using ExportCaller = ReferenceCaller &), T::Export>; -}; - - -using BoolImportExport = ImportExport; - struct BoolToggle { - static void Import(GtkToggleButton &widget, bool value) { - gtk_toggle_button_set_active(&widget, value); + static void Export(const GtkToggleButton &self, const Callback &returnz) { + returnz(gtk_toggle_button_get_active(const_cast(&self)) != FALSE); } - static void Export(GtkToggleButton &widget, const ImportExportCallback::Import_t &importCallback) { - importCallback(gtk_toggle_button_get_active(&widget) != FALSE); + static void Import(GtkToggleButton &self, bool value) { + gtk_toggle_button_set_active(&self, value); } }; -using BoolToggleImportExport = ImportExport; - -using IntImportExport = ImportExport; +using BoolToggleImportExport = PropertyAdaptor; struct IntEntry { - static void Import(GtkEntry &widget, int value) { - entry_set_int(ui::Entry(&widget), value); + static void Export(const GtkEntry &self, const Callback &returnz) { + returnz(atoi(gtk_entry_get_text(const_cast(&self)))); } - static void Export(GtkEntry &widget, const ImportExportCallback::Import_t &importCallback) { - importCallback(atoi(gtk_entry_get_text(&widget))); + static void Import(GtkEntry &self, int value) { + entry_set_int(ui::Entry(&self), value); } }; -using IntEntryImportExport = ImportExport; +using IntEntryImportExport = PropertyAdaptor; struct IntRadio { - static void Import(GtkRadioButton &widget, int index) { - radio_button_set_active(ui::RadioButton(&widget), index); + static void Export(const GtkRadioButton &self, const Callback &returnz) { + returnz(radio_button_get_active(ui::RadioButton(const_cast(&self)))); } - static void Export(GtkRadioButton &widget, const ImportExportCallback::Import_t &importCallback) { - importCallback(radio_button_get_active(ui::RadioButton(&widget))); + static void Import(GtkRadioButton &self, int value) { + radio_button_set_active(ui::RadioButton(&self), value); } }; -using IntRadioImportExport = ImportExport; +using IntRadioImportExport = PropertyAdaptor; struct IntCombo { - static void Import(GtkComboBox &widget, int value) { - gtk_combo_box_set_active(&widget, value); + static void Export(const GtkComboBox &self, const Callback &returnz) { + returnz(gtk_combo_box_get_active(const_cast(&self))); } - static void Export(GtkComboBox &widget, const ImportExportCallback::Import_t &importCallback) { - importCallback(gtk_combo_box_get_active(&widget)); + static void Import(GtkComboBox &self, int value) { + gtk_combo_box_set_active(&self, value); } }; -using IntComboImportExport = ImportExport; +using IntComboImportExport = PropertyAdaptor; struct IntAdjustment { - static void Import(GtkAdjustment &widget, int value) { - gtk_adjustment_set_value(&widget, value); + static void Export(const GtkAdjustment &self, const Callback &returnz) { + returnz((int) gtk_adjustment_get_value(const_cast(&self))); } - static void Export(GtkAdjustment &widget, const ImportExportCallback::Import_t &importCallback) { - importCallback((int) gtk_adjustment_get_value(&widget)); + static void Import(GtkAdjustment &self, int value) { + gtk_adjustment_set_value(&self, value); } }; -using IntAdjustmentImportExport = ImportExport; +using IntAdjustmentImportExport = PropertyAdaptor; struct IntSpinner { - static void Import(GtkSpinButton &widget, int value) { - gtk_spin_button_set_value(&widget, value); + static void Export(const GtkSpinButton &self, const Callback &returnz) { + returnz(gtk_spin_button_get_value_as_int(const_cast(&self))); } - static void Export(GtkSpinButton &widget, const ImportExportCallback::Import_t &importCallback) { - importCallback(gtk_spin_button_get_value_as_int(&widget)); + static void Import(GtkSpinButton &self, int value) { + gtk_spin_button_set_value(&self, value); } }; -using IntSpinnerImportExport = ImportExport; +using IntSpinnerImportExport = PropertyAdaptor; -using StringImportExport = ImportExport; +using StringImportExport = PropertyAdaptor; struct TextEntry { - static void Import(GtkEntry &widget, const char *text) { - ui::Entry(&widget).text(text); + static void Export(const GtkEntry &self, const Callback &returnz) { + returnz(gtk_entry_get_text(const_cast(&self))); } - static void Export(GtkEntry &widget, const ImportExportCallback::Import_t &importCallback) { - importCallback(gtk_entry_get_text(&widget)); + static void Import(GtkEntry &self, const char *value) { + ui::Entry(&self).text(value); } }; -using TextEntryImportExport = ImportExport; - -using SizeImportExport = ImportExport; +using TextEntryImportExport = PropertyAdaptor; 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)); + static void Export(const GtkEntry &self, const Callback &returnz) { + int value = atoi(gtk_entry_get_text(const_cast(&self))); if (value < 0) { value = 0; } - importCallback(value); + returnz(value); } -}; -using SizeEntryImportExport = ImportExport; + static void Import(GtkEntry &self, std::size_t value) { + entry_set_int(ui::Entry(&self), int(value)); + } +}; -using FloatImportExport = ImportExport; +using SizeEntryImportExport = PropertyAdaptor; struct FloatEntry { - static void Import(GtkEntry &widget, float value) { - entry_set_float(ui::Entry(&widget), value); + static void Export(const GtkEntry &self, const Callback &returnz) { + returnz((float) atof(gtk_entry_get_text(const_cast(&self)))); } - static void Export(GtkEntry &widget, const ImportExportCallback::Import_t &importCallback) { - importCallback((float) atof(gtk_entry_get_text(&widget))); + static void Import(GtkEntry &self, float value) { + entry_set_float(ui::Entry(&self), value); } }; -using FloatEntryImportExport = ImportExport; +using FloatEntryImportExport = PropertyAdaptor; struct FloatSpinner { - static void Import(GtkSpinButton &widget, float value) { - gtk_spin_button_set_value(&widget, value); + static void Export(const GtkSpinButton &self, const Callback &returnz) { + returnz(float(gtk_spin_button_get_value(const_cast(&self)))); } - static void Export(GtkSpinButton &widget, const ImportExportCallback::Import_t &importCallback) { - importCallback(float(gtk_spin_button_get_value(&widget))); + static void Import(GtkSpinButton &self, float value) { + gtk_spin_button_set_value(&self, value); } }; -using FloatSpinnerImportExport = ImportExport; +using FloatSpinnerImportExport = PropertyAdaptor; template class CallbackDialogData : public DLG_DATA { - ImportExportCallback m_cbWidget; - ImportExportCallback m_cbViewer; + Property m_cbWidget; + Property m_cbViewer; public: - CallbackDialogData(const ImportExportCallback &cbWidget, const ImportExportCallback &cbViewer) + CallbackDialogData(const Property &cbWidget, const Property &cbViewer) : m_cbWidget(cbWidget), m_cbViewer(cbViewer) { } @@ -273,11 +250,11 @@ public: } void importData() const { - m_cbViewer.Export(m_cbWidget.Import); + m_cbViewer.get(m_cbWidget.set); } void exportData() const { - m_cbWidget.Export(m_cbViewer.Import); + m_cbWidget.get(m_cbViewer.set); } }; @@ -285,10 +262,8 @@ template 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)} + make_property(widget), + make_property(viewer) ) ); } @@ -297,12 +272,11 @@ template void AddCustomData( DialogDataList &data, typename Widget::Type &widget, - ImportExportCallback const &cbViewer + Property const &cbViewer ) { data.push_back( new CallbackDialogData( - {typename Widget::ImportCaller(widget), - typename Widget::ExportCaller(widget)}, + make_property(widget), cbViewer ) ); @@ -356,76 +330,76 @@ void Dialog::Destroy(){ } -void Dialog::AddBoolToggleData( GtkToggleButton& widget, ImportExportCallback const &cb ){ +void Dialog::AddBoolToggleData( GtkToggleButton& widget, Property const &cb ){ AddCustomData( m_data, widget, cb ); } -void Dialog::AddIntRadioData( GtkRadioButton& widget, ImportExportCallback const &cb ){ +void Dialog::AddIntRadioData( GtkRadioButton& widget, Property const &cb ){ AddCustomData( m_data, widget, cb ); } -void Dialog::AddTextEntryData( GtkEntry& widget, ImportExportCallback const &cb ){ +void Dialog::AddTextEntryData( GtkEntry& widget, Property const &cb ){ AddCustomData( m_data, widget, cb ); } -void Dialog::AddIntEntryData( GtkEntry& widget, ImportExportCallback const &cb ){ +void Dialog::AddIntEntryData( GtkEntry& widget, Property const &cb ){ AddCustomData( m_data, widget, cb ); } -void Dialog::AddSizeEntryData( GtkEntry& widget, ImportExportCallback const &cb ){ +void Dialog::AddSizeEntryData( GtkEntry& widget, Property const &cb ){ AddCustomData( m_data, widget, cb ); } -void Dialog::AddFloatEntryData( GtkEntry& widget, ImportExportCallback const &cb ){ +void Dialog::AddFloatEntryData( GtkEntry& widget, Property const &cb ){ AddCustomData( m_data, widget, cb ); } -void Dialog::AddFloatSpinnerData( GtkSpinButton& widget, ImportExportCallback const &cb ){ +void Dialog::AddFloatSpinnerData( GtkSpinButton& widget, Property const &cb ){ AddCustomData( m_data, widget, cb ); } -void Dialog::AddIntSpinnerData( GtkSpinButton& widget, ImportExportCallback const &cb ){ +void Dialog::AddIntSpinnerData( GtkSpinButton& widget, Property const &cb ){ AddCustomData( m_data, widget, cb ); } -void Dialog::AddIntAdjustmentData( GtkAdjustment& widget, ImportExportCallback const &cb ){ +void Dialog::AddIntAdjustmentData( GtkAdjustment& widget, Property const &cb ){ AddCustomData( m_data, widget, cb ); } -void Dialog::AddIntComboData( GtkComboBox& widget, ImportExportCallback const &cb ){ +void Dialog::AddIntComboData( GtkComboBox& widget, Property const &cb ){ AddCustomData( m_data, widget, cb ); } void Dialog::AddDialogData( GtkToggleButton& widget, bool& data ){ - AddData( m_data, widget, data ); + AddData>( m_data, widget, data ); } void Dialog::AddDialogData( GtkRadioButton& widget, int& data ){ - AddData( m_data, widget, data ); + AddData>( m_data, widget, data ); } void Dialog::AddDialogData( GtkEntry& widget, CopiedString& data ){ AddData( m_data, widget, data ); } void Dialog::AddDialogData( GtkEntry& widget, int& data ){ - AddData( m_data, widget, data ); + AddData>( m_data, widget, data ); } void Dialog::AddDialogData( GtkEntry& widget, std::size_t& data ){ - AddData( m_data, widget, data ); + AddData>( m_data, widget, data ); } void Dialog::AddDialogData( GtkEntry& widget, float& data ){ - AddData( m_data, widget, data ); + AddData>( m_data, widget, data ); } void Dialog::AddDialogData( GtkSpinButton& widget, float& data ){ - AddData( m_data, widget, data ); + AddData>( m_data, widget, data ); } void Dialog::AddDialogData( GtkSpinButton& widget, int& data ){ - AddData( m_data, widget, data ); + AddData>( m_data, widget, data ); } void Dialog::AddDialogData( GtkAdjustment& widget, int& data ){ - AddData( m_data, widget, data ); + AddData>( m_data, widget, data ); } void Dialog::AddDialogData( GtkComboBox& widget, int& data ){ - AddData( m_data, widget, data ); + AddData>( m_data, widget, data ); } void Dialog::exportData(){ @@ -466,7 +440,7 @@ EMessageBoxReturn Dialog::DoModal(){ } -ui::CheckButton Dialog::addCheckBox( ui::VBox vbox, const char* name, const char* flag, ImportExportCallback const &cb ){ +ui::CheckButton Dialog::addCheckBox( ui::VBox vbox, const char* name, const char* flag, Property const &cb ){ auto check = ui::CheckButton( flag ); check.show(); AddBoolToggleData( *GTK_TOGGLE_BUTTON( check ), cb ); @@ -476,10 +450,10 @@ ui::CheckButton Dialog::addCheckBox( ui::VBox vbox, const char* name, const char } ui::CheckButton Dialog::addCheckBox( ui::VBox vbox, const char* name, const char* flag, bool& data ){ - return addCheckBox(vbox, name, flag, mkImportExportCallback(data)); + return addCheckBox(vbox, name, flag, make_property(data)); } -void Dialog::addCombo( ui::VBox vbox, const char* name, StringArrayRange values, ImportExportCallback const &cb ){ +void Dialog::addCombo( ui::VBox vbox, const char* name, StringArrayRange values, Property const &cb ){ auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 ); alignment.show(); { @@ -501,7 +475,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, mkImportExportCallback(data)); + addCombo(vbox, name, values, make_property(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 ){ @@ -525,7 +499,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), mkImportExportCallback(data)); + AddIntAdjustmentData(*GTK_ADJUSTMENT(adj), make_property(data)); // scale auto alignment = ui::Alignment( 0.0, 0.5, 1.0, 0.0 ); @@ -543,7 +517,7 @@ 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, ImportExportCallback const &cb ){ +void Dialog::addRadio( ui::VBox vbox, const char* name, StringArrayRange names, Property const &cb ){ auto alignment = ui::Alignment( 0.0, 0.5, 0.0, 0.0 ); alignment.show();; { @@ -557,10 +531,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, mkImportExportCallback(data)); + addRadio(vbox, name, names, make_property(data)); } -void Dialog::addRadioIcons( ui::VBox vbox, const char* name, StringArrayRange icons, ImportExportCallback const &cb ){ +void Dialog::addRadioIcons( ui::VBox vbox, const char* name, StringArrayRange icons, Property const &cb ){ auto table = ui::Table(2, icons.last - icons.first, FALSE); table.show(); @@ -589,31 +563,31 @@ void Dialog::addRadioIcons( ui::VBox vbox, const char* name, StringArrayRange ic } void Dialog::addRadioIcons( ui::VBox vbox, const char* name, int& data, StringArrayRange icons ){ - addRadioIcons(vbox, name, icons, mkImportExportCallback(data)); + addRadioIcons(vbox, name, icons, make_property(data)); } -ui::Widget Dialog::addIntEntry( ui::VBox vbox, const char* name, ImportExportCallback const &cb ){ +ui::Widget Dialog::addIntEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); 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, ImportExportCallback const &cb ){ +ui::Widget Dialog::addSizeEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); 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, ImportExportCallback const &cb ){ +ui::Widget Dialog::addFloatEntry( ui::VBox vbox, const char* name, Property const &cb ){ DialogEntryRow row( DialogEntryRow_new( name ) ); 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, ImportExportCallback const &cb ){ +ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, bool browse_directory, Property 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 ); @@ -626,10 +600,10 @@ ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, bool browse_di } ui::Widget Dialog::addPathEntry( ui::VBox vbox, const char* name, CopiedString& data, bool browse_directory ){ - return addPathEntry(vbox, name, browse_directory, mkImportExportCallback(data)); + return addPathEntry(vbox, name, browse_directory, make_property(data)); } -ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, ImportExportCallback const &cb ){ +ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, Property const &cb ){ DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 1 ) ); AddIntSpinnerData( *GTK_SPIN_BUTTON(row.m_spin), cb ); DialogVBox_packRow( vbox, row.m_row ); @@ -637,10 +611,10 @@ ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value } 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, mkImportExportCallback(data)); + return addSpinner(vbox, name, value, lower, upper, make_property(data)); } -ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, ImportExportCallback const &cb ){ +ui::SpinButton Dialog::addSpinner( ui::VBox vbox, const char* name, double value, double lower, double upper, Property const &cb ){ DialogSpinnerRow row( DialogSpinnerRow_new( name, value, lower, upper, 10 ) ); AddFloatSpinnerData( *GTK_SPIN_BUTTON(row.m_spin), cb ); DialogVBox_packRow( vbox, row.m_row ); diff --git a/radiant/dialog.h b/radiant/dialog.h index cf2b2362..0147eb2c 100644 --- a/radiant/dialog.h +++ b/radiant/dialog.h @@ -24,67 +24,13 @@ #include #include +#include "property.h" #include "generic/callback.h" #include "gtkutil/dialog.h" #include "generic/callback.h" #include "string/string.h" -template -struct impexp { - static void Import(Self &self, T value) { - self = value; - } - - static void Export(Self &self, const Callback &importCallback) { - importCallback(self); - } -}; - -template -ImportExportCallback mkImportExportCallback(Self &self) { - return { - ReferenceCaller::Import>(self), - ReferenceCaller &), impexp::Export>(self) - }; -} - -#define BoolImport impexp::Import -#define BoolExport impexp::Export - -typedef ReferenceCaller &), BoolExport> BoolExportCaller; - -#define IntImport impexp::Import -#define IntExport impexp::Export - -typedef ReferenceCaller &), IntExport> IntExportCaller; - -#define SizeImport impexp::Import -#define SizeExport impexp::Export - - -#define FloatImport impexp::Import -#define FloatExport impexp::Export - -typedef ReferenceCaller &), FloatExport> FloatExportCaller; - -#define StringImport impexp::Import -#define StringExport impexp::Export - -template<> -struct impexp { - static void Import(CopiedString &self, const char *value) { - self = value; - } - - static void Export(CopiedString &self, const Callback &importCallback) { - importCallback(self.c_str()); - } -}; - -typedef ReferenceCaller &), StringExport> StringExportCaller; - - struct DLG_DATA { virtual ~DLG_DATA() = default; @@ -132,66 +78,66 @@ const ui::Window GetWidget() const { return m_window; } - 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, Property 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, ImportExportCallback const &cb); + void addCombo(ui::VBox vbox, const char *name, StringArrayRange values, Property 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, ImportExportCallback const &cb); + void addRadio(ui::VBox vbox, const char *name, StringArrayRange names, Property const &cb); void addRadio( ui::VBox vbox, const char* name, int& data, StringArrayRange names ); - void addRadioIcons(ui::VBox vbox, const char *name, StringArrayRange icons, ImportExportCallback const &cb); + void addRadioIcons(ui::VBox vbox, const char *name, StringArrayRange icons, Property const &cb); void addRadioIcons( ui::VBox vbox, const char* name, int& data, StringArrayRange icons ); - ui::Widget addIntEntry(ui::VBox vbox, const char *name, ImportExportCallback const &cb); + ui::Widget addIntEntry(ui::VBox vbox, const char *name, Property const &cb); ui::Widget addEntry( ui::VBox vbox, const char* name, int& data ){ - return addIntEntry(vbox, name, mkImportExportCallback(data)); + return addIntEntry(vbox, name, make_property(data)); } - ui::Widget addSizeEntry(ui::VBox vbox, const char *name, ImportExportCallback const &cb); + ui::Widget addSizeEntry(ui::VBox vbox, const char *name, Property const &cb); ui::Widget addEntry( ui::VBox vbox, const char* name, std::size_t& data ){ - return addSizeEntry(vbox, name, mkImportExportCallback(data)); + return addSizeEntry(vbox, name, make_property(data)); } - ui::Widget addFloatEntry(ui::VBox vbox, const char *name, ImportExportCallback const &cb); + ui::Widget addFloatEntry(ui::VBox vbox, const char *name, Property const &cb); ui::Widget addEntry( ui::VBox vbox, const char* name, float& data ){ - return addFloatEntry(vbox, name, mkImportExportCallback(data)); + return addFloatEntry(vbox, name, make_property(data)); } ui::Widget - addPathEntry(ui::VBox vbox, const char *name, bool browse_directory, ImportExportCallback const &cb); + addPathEntry(ui::VBox vbox, const char *name, bool browse_directory, Property 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, ImportExportCallback const &cb); + addSpinner(ui::VBox vbox, const char *name, double value, double lower, double upper, Property const &cb); ui::SpinButton addSpinner(ui::VBox vbox, const char *name, double value, double lower, double upper, - ImportExportCallback const &cb); + Property const &cb); protected: - void AddBoolToggleData(struct _GtkToggleButton &object, ImportExportCallback const &cb); + void AddBoolToggleData(struct _GtkToggleButton &object, Property const &cb); - void AddIntRadioData(struct _GtkRadioButton &object, ImportExportCallback const &cb); + void AddIntRadioData(struct _GtkRadioButton &object, Property const &cb); - void AddTextEntryData(struct _GtkEntry &object, ImportExportCallback const &cb); + void AddTextEntryData(struct _GtkEntry &object, Property const &cb); - void AddIntEntryData(struct _GtkEntry &object, ImportExportCallback const &cb); + void AddIntEntryData(struct _GtkEntry &object, Property const &cb); - void AddSizeEntryData(struct _GtkEntry &object, ImportExportCallback const &cb); + void AddSizeEntryData(struct _GtkEntry &object, Property const &cb); - void AddFloatEntryData(struct _GtkEntry &object, ImportExportCallback const &cb); + void AddFloatEntryData(struct _GtkEntry &object, Property const &cb); - void AddFloatSpinnerData(struct _GtkSpinButton &object, ImportExportCallback const &cb); + void AddFloatSpinnerData(struct _GtkSpinButton &object, Property const &cb); - void AddIntSpinnerData(struct _GtkSpinButton &object, ImportExportCallback const &cb); + void AddIntSpinnerData(struct _GtkSpinButton &object, Property const &cb); - void AddIntAdjustmentData(struct _GtkAdjustment &object, ImportExportCallback const &cb); + void AddIntAdjustmentData(struct _GtkAdjustment &object, Property const &cb); - void AddIntComboData(struct _GtkComboBox &object, ImportExportCallback const &cb); + void AddIntComboData(struct _GtkComboBox &object, Property 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 1c02828e..2952684d 100644 --- a/radiant/entity.cpp +++ b/radiant/entity.cpp @@ -542,22 +542,21 @@ const char* misc_model_dialog( ui::Widget parent ){ return 0; } -void LightRadiiImport( EntityCreator& self, bool value ){ - self.setLightRadii( value ); -} -typedef ReferenceCaller LightRadiiImportCaller; +struct LightRadii { + static void Export(const EntityCreator &self, const Callback &returnz) { + returnz(self.getLightRadii()); + } -void LightRadiiExport( EntityCreator& self, const ImportExportCallback::Import_t& importer ){ - importer( self.getLightRadii() ); -} -typedef ReferenceCaller::Import_t&), LightRadiiExport> LightRadiiExportCaller; + static void Import(EntityCreator &self, bool value) { + self.setLightRadii(value); + } +}; void Entity_constructPreferences( PreferencesPage& page ){ page.appendCheckBox( - "Show", "Light Radii", - {LightRadiiImportCaller( GlobalEntityCreator() ), - LightRadiiExportCaller( GlobalEntityCreator() )} - ); + "Show", "Light Radii", + make_property(GlobalEntityCreator()) + ); } void Entity_constructPage( PreferenceGroup& group ){ PreferencesPage page( group.createPage( "Entities", "Entity Display Preferences" ) ); @@ -591,8 +590,8 @@ void Entity_Construct(){ GlobalCommands_insert( "GroupSelection", makeCallbackF(Entity_groupSelected) ); GlobalCommands_insert( "UngroupSelection", makeCallbackF(Entity_ungroupSelected) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors5", Vector3ImportStringCaller( g_entity_globals.color_entity ), Vector3ExportStringCaller( g_entity_globals.color_entity ) ); - GlobalPreferenceSystem().registerPreference( "LastLightIntensity", IntImportStringCaller( g_iLastLightIntensity ), IntExportStringCaller( g_iLastLightIntensity ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors5", make_property_string( g_entity_globals.color_entity ) ); + GlobalPreferenceSystem().registerPreference( "LastLightIntensity", make_property_string( g_iLastLightIntensity ) ); Entity_registerPreferencesPage(); } diff --git a/radiant/entityinspector.cpp b/radiant/entityinspector.cpp index 39f61093..65b69327 100644 --- a/radiant/entityinspector.cpp +++ b/radiant/entityinspector.cpp @@ -1574,8 +1574,8 @@ EntityInspector g_EntityInspector; void EntityInspector_construct(){ GlobalEntityClassManager().attach( g_EntityInspector ); - GlobalPreferenceSystem().registerPreference( "EntitySplit1", IntImportStringCaller( g_entitysplit1_position ), IntExportStringCaller( g_entitysplit1_position ) ); - GlobalPreferenceSystem().registerPreference( "EntitySplit2", IntImportStringCaller( g_entitysplit2_position ), IntExportStringCaller( g_entitysplit2_position ) ); + GlobalPreferenceSystem().registerPreference( "EntitySplit1", make_property_string( g_entitysplit1_position ) ); + GlobalPreferenceSystem().registerPreference( "EntitySplit2", make_property_string( g_entitysplit2_position ) ); } diff --git a/radiant/entitylist.cpp b/radiant/entitylist.cpp index 9218027d..877eba23 100644 --- a/radiant/entitylist.cpp +++ b/radiant/entitylist.cpp @@ -375,7 +375,7 @@ void EntityList_Construct(){ getEntityList().m_positionTracker.setPosition( c_default_window_pos ); - GlobalPreferenceSystem().registerPreference( "EntityInfoDlg", WindowPositionTrackerImportStringCaller( getEntityList().m_positionTracker ), WindowPositionTrackerExportStringCaller( getEntityList().m_positionTracker ) ); + GlobalPreferenceSystem().registerPreference( "EntityInfoDlg", make_property( getEntityList().m_positionTracker ) ); typedef FreeCaller EntityListSelectionChangedCaller; GlobalSelectionSystem().addSelectionChangeCallback( EntityListSelectionChangedCaller() ); diff --git a/radiant/filters.cpp b/radiant/filters.cpp index 9764f4af..3957af62 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 ImportExportCallback::Import_t& importCallback ){ +void active( const Callback &importCallback ){ importCallback( ( g_filters_globals.exclude & m_mask ) != 0 ); } -typedef MemberCaller::Import_t&), &ToggleFilterFlag::active> ActiveCaller; +typedef MemberCaller&), &ToggleFilterFlag::active> ActiveCaller; void toggle(){ g_filters_globals.exclude ^= m_mask; m_item.update(); @@ -216,7 +216,7 @@ void Filters_constructMenu( ui::Menu menu_in_menu ){ #include "stringio.h" void ConstructFilters(){ - GlobalPreferenceSystem().registerPreference( "SI_Exclude", SizeImportStringCaller( g_filters_globals.exclude ), SizeExportStringCaller( g_filters_globals.exclude ) ); + GlobalPreferenceSystem().registerPreference( "SI_Exclude", make_property_string( g_filters_globals.exclude ) ); GlobalCommands_insert( "InvertFilters", makeCallbackF(InvertFilters) ); GlobalCommands_insert( "ResetFilters", makeCallbackF(ResetFilters) ); diff --git a/radiant/grid.cpp b/radiant/grid.cpp index be267002..df1e1c1a 100644 --- a/radiant/grid.cpp +++ b/radiant/grid.cpp @@ -134,10 +134,10 @@ void set(){ setGridPower( m_id ); } typedef MemberCaller SetCaller; -void active( const ImportExportCallback::Import_t& importCallback ){ +void active( const Callback &importCallback ){ importCallback( g_grid_power == m_id ); } -typedef MemberCaller::Import_t&), &GridMenuItem::active> ExportCaller; +typedef MemberCaller&), &GridMenuItem::active> ExportCaller; }; GridMenuItem g_gridMenu0125( GRIDPOWER_0125 ); @@ -254,7 +254,7 @@ void Grid_construct(){ g_grid_default = GridDefault_forGridPower( GRIDPOWER_8 ); - GlobalPreferenceSystem().registerPreference( "GridDefault", IntImportStringCaller( g_grid_default ), IntExportStringCaller( g_grid_default ) ); + GlobalPreferenceSystem().registerPreference( "GridDefault", make_property_string( g_grid_default ) ); g_grid_power = GridPower_forGridDefault( g_grid_default ); g_gridsize = GridSize_forGridPower( g_grid_power ); diff --git a/radiant/groupdialog.cpp b/radiant/groupdialog.cpp index 28098897..f6847dd9 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::Export_t> g_pages; +std::vector &)>> 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 ImportExportCallback::Export_t& title ){ +ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const Callback &)>& 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 ) )); @@ -195,7 +195,7 @@ void GroupDialog_updatePageTitle( ui::Widget page ){ #include "preferencesystem.h" void GroupDialog_Construct(){ - GlobalPreferenceSystem().registerPreference( "EntityWnd", WindowPositionTrackerImportStringCaller( g_GroupDlg.m_position_tracker ), WindowPositionTrackerExportStringCaller( g_GroupDlg.m_position_tracker ) ); + GlobalPreferenceSystem().registerPreference( "EntityWnd", make_property( g_GroupDlg.m_position_tracker ) ); GlobalCommands_insert( "ViewEntityInfo", makeCallbackF(GroupDialog_ToggleShow), Accelerator( 'N' ) ); } diff --git a/radiant/groupdialog.h b/radiant/groupdialog.h index 8f1a31ee..f136f382 100644 --- a/radiant/groupdialog.h +++ b/radiant/groupdialog.h @@ -23,6 +23,7 @@ #define INCLUDED_GROUPDIALOG_H #include +#include "property.h" #include "generic/callback.h" void GroupDialog_Construct(); @@ -33,11 +34,11 @@ void GroupDialog_destroyWindow(); ui::Window GroupDialog_getWindow(); void GroupDialog_show(); -inline void RawStringExport( const char* string, const ImportExportCallback::Import_t& importer ){ +inline void RawStringExport( const char* string, const Callback &importer ){ importer( string ); } -typedef ConstPointerCaller::Import_t&), RawStringExport> RawStringExportCaller; -ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const ImportExportCallback::Export_t& title ); +typedef ConstPointerCaller &), RawStringExport> RawStringExportCaller; +ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const Callback &)>& title ); void GroupDialog_showPage( ui::Widget page ); void GroupDialog_updatePageTitle( ui::Widget page ); diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index c4d2f40d..a569ea75 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -414,16 +414,18 @@ const char* GameToolsPath_get(){ return g_strGameToolsPath.c_str(); } -void EnginePathImport( CopiedString& self, const char* value ){ - setEnginePath( value ); -} -typedef ReferenceCaller EnginePathImportCaller; +struct EnginePath { + static void Export(const CopiedString &self, const Callback &returnz) { + returnz(self.c_str()); + } + + static void Import(CopiedString &self, const char *value) { + setEnginePath(value); + } +}; void Paths_constructPreferences( PreferencesPage& page ){ - page.appendPathEntry( "Engine Path", true, - {ImportExportCallback::Import_t( EnginePathImportCaller( g_strEnginePath ) ), - ImportExportCallback::Export_t( StringExportCaller( g_strEnginePath ) )} - ); + page.appendPathEntry( "Engine Path", true, make_property(g_strEnginePath) ); } void Paths_constructPage( PreferenceGroup& group ){ PreferencesPage page( group.createPage( "Paths", "Path Settings" ) ); @@ -999,24 +1001,24 @@ template class BoolFunctionExport { public: -static void apply( const ImportExportCallback::Import_t& importCallback ){ +static void apply( const Callback & importCallback ){ importCallback( BoolFunction() ); } }; -typedef FreeCaller::Import_t&), &BoolFunctionExport::apply> EdgeModeApplyCaller; +typedef FreeCaller &), &BoolFunctionExport::apply> EdgeModeApplyCaller; EdgeModeApplyCaller g_edgeMode_button_caller; -ImportExportCallback::Export_t g_edgeMode_button_callback( g_edgeMode_button_caller ); +Callback &)> g_edgeMode_button_callback( g_edgeMode_button_caller ); ToggleItem g_edgeMode_button( g_edgeMode_button_callback ); -typedef FreeCaller::Import_t&), &BoolFunctionExport::apply> VertexModeApplyCaller; +typedef FreeCaller &), &BoolFunctionExport::apply> VertexModeApplyCaller; VertexModeApplyCaller g_vertexMode_button_caller; -ImportExportCallback::Export_t g_vertexMode_button_callback( g_vertexMode_button_caller ); +Callback &)> g_vertexMode_button_callback( g_vertexMode_button_caller ); ToggleItem g_vertexMode_button( g_vertexMode_button_callback ); -typedef FreeCaller::Import_t&), &BoolFunctionExport::apply> FaceModeApplyCaller; +typedef FreeCaller &), &BoolFunctionExport::apply> FaceModeApplyCaller; FaceModeApplyCaller g_faceMode_button_caller; -ImportExportCallback::Export_t g_faceMode_button_callback( g_faceMode_button_caller ); +Callback &)> g_faceMode_button_callback( g_faceMode_button_caller ); ToggleItem g_faceMode_button( g_faceMode_button_callback ); void ComponentModeChanged(){ @@ -1290,44 +1292,44 @@ void Selection_NudgeRight(){ } -void TranslateToolExport( const ImportExportCallback::Import_t& importCallback ){ +void TranslateToolExport( const Callback & importCallback ){ importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate ); } -void RotateToolExport( const ImportExportCallback::Import_t& importCallback ){ +void RotateToolExport( const Callback & importCallback ){ importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate ); } -void ScaleToolExport( const ImportExportCallback::Import_t& importCallback ){ +void ScaleToolExport( const Callback & importCallback ){ importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale ); } -void DragToolExport( const ImportExportCallback::Import_t& importCallback ){ +void DragToolExport( const Callback & importCallback ){ importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag ); } -void ClipperToolExport( const ImportExportCallback::Import_t& importCallback ){ +void ClipperToolExport( const Callback & importCallback ){ importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip ); } -FreeCaller::Import_t&), TranslateToolExport> g_translatemode_button_caller; -ImportExportCallback::Export_t g_translatemode_button_callback( g_translatemode_button_caller ); +FreeCaller &), TranslateToolExport> g_translatemode_button_caller; +Callback &)> g_translatemode_button_callback( g_translatemode_button_caller ); ToggleItem g_translatemode_button( g_translatemode_button_callback ); -FreeCaller::Import_t&), RotateToolExport> g_rotatemode_button_caller; -ImportExportCallback::Export_t g_rotatemode_button_callback( g_rotatemode_button_caller ); +FreeCaller &), RotateToolExport> g_rotatemode_button_caller; +Callback &)> g_rotatemode_button_callback( g_rotatemode_button_caller ); ToggleItem g_rotatemode_button( g_rotatemode_button_callback ); -FreeCaller::Import_t&), ScaleToolExport> g_scalemode_button_caller; -ImportExportCallback::Export_t g_scalemode_button_callback( g_scalemode_button_caller ); +FreeCaller &), ScaleToolExport> g_scalemode_button_caller; +Callback &)> g_scalemode_button_callback( g_scalemode_button_caller ); ToggleItem g_scalemode_button( g_scalemode_button_callback ); -FreeCaller::Import_t&), DragToolExport> g_dragmode_button_caller; -ImportExportCallback::Export_t g_dragmode_button_callback( g_dragmode_button_caller ); +FreeCaller &), DragToolExport> g_dragmode_button_caller; +Callback &)> g_dragmode_button_callback( g_dragmode_button_caller ); ToggleItem g_dragmode_button( g_dragmode_button_callback ); -FreeCaller::Import_t&), ClipperToolExport> g_clipper_button_caller; -ImportExportCallback::Export_t g_clipper_button_callback( g_clipper_button_caller ); +FreeCaller &), ClipperToolExport> g_clipper_button_caller; +Callback &)> g_clipper_button_callback( g_clipper_button_caller ); ToggleItem g_clipper_button( g_clipper_button_callback ); void ToolChanged(){ @@ -3126,22 +3128,22 @@ void Layout_constructPreferences( PreferencesPage& page ){ page.appendRadioIcons( "Window Layout", STRING_ARRAY_RANGE( layouts ), - mkImportExportCallback( g_Layout_viewStyle ) + make_property( g_Layout_viewStyle ) ); } page.appendCheckBox( "", "Detachable Menus", - mkImportExportCallback( g_Layout_enableDetachableMenus ) + make_property( g_Layout_enableDetachableMenus ) ); if ( !string_empty( g_pGameDescription->getKeyValue( "no_patch" ) ) ) { page.appendCheckBox( "", "Patch Toolbar", - mkImportExportCallback( g_Layout_enablePatchToolbar ) + make_property( g_Layout_enablePatchToolbar ) ); } page.appendCheckBox( "", "Plugin Toolbar", - mkImportExportCallback( g_Layout_enablePluginToolbar ) + make_property( g_Layout_enablePluginToolbar ) ); } @@ -3279,25 +3281,25 @@ void MainFrame_Construct(){ typedef FreeCaller ComponentModeSelectionChangedCaller; GlobalSelectionSystem().addSelectionChangeCallback( ComponentModeSelectionChangedCaller() ); - GlobalPreferenceSystem().registerPreference( "DetachableMenus", BoolImportStringCaller( g_Layout_enableDetachableMenus.m_latched ), BoolExportStringCaller( g_Layout_enableDetachableMenus.m_latched ) ); - GlobalPreferenceSystem().registerPreference( "PatchToolBar", BoolImportStringCaller( g_Layout_enablePatchToolbar.m_latched ), BoolExportStringCaller( g_Layout_enablePatchToolbar.m_latched ) ); - GlobalPreferenceSystem().registerPreference( "PluginToolBar", BoolImportStringCaller( g_Layout_enablePluginToolbar.m_latched ), BoolExportStringCaller( g_Layout_enablePluginToolbar.m_latched ) ); - GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", IntImportStringCaller( g_Layout_viewStyle.m_latched ), IntExportStringCaller( g_Layout_viewStyle.m_latched ) ); - GlobalPreferenceSystem().registerPreference( "XYHeight", IntImportStringCaller( g_layout_globals.nXYHeight ), IntExportStringCaller( g_layout_globals.nXYHeight ) ); - GlobalPreferenceSystem().registerPreference( "XYWidth", IntImportStringCaller( g_layout_globals.nXYWidth ), IntExportStringCaller( g_layout_globals.nXYWidth ) ); - GlobalPreferenceSystem().registerPreference( "CamWidth", IntImportStringCaller( g_layout_globals.nCamWidth ), IntExportStringCaller( g_layout_globals.nCamWidth ) ); - GlobalPreferenceSystem().registerPreference( "CamHeight", IntImportStringCaller( g_layout_globals.nCamHeight ), IntExportStringCaller( g_layout_globals.nCamHeight ) ); - - GlobalPreferenceSystem().registerPreference( "State", IntImportStringCaller( g_layout_globals.nState ), IntExportStringCaller( g_layout_globals.nState ) ); - GlobalPreferenceSystem().registerPreference( "PositionX", IntImportStringCaller( g_layout_globals.m_position.x ), IntExportStringCaller( g_layout_globals.m_position.x ) ); - GlobalPreferenceSystem().registerPreference( "PositionY", IntImportStringCaller( g_layout_globals.m_position.y ), IntExportStringCaller( g_layout_globals.m_position.y ) ); - GlobalPreferenceSystem().registerPreference( "Width", IntImportStringCaller( g_layout_globals.m_position.w ), IntExportStringCaller( g_layout_globals.m_position.w ) ); - GlobalPreferenceSystem().registerPreference( "Height", IntImportStringCaller( g_layout_globals.m_position.h ), IntExportStringCaller( g_layout_globals.m_position.h ) ); - - GlobalPreferenceSystem().registerPreference( "CamWnd", WindowPositionTrackerImportStringCaller( g_posCamWnd ), WindowPositionTrackerExportStringCaller( g_posCamWnd ) ); - GlobalPreferenceSystem().registerPreference( "XYWnd", WindowPositionTrackerImportStringCaller( g_posXYWnd ), WindowPositionTrackerExportStringCaller( g_posXYWnd ) ); - GlobalPreferenceSystem().registerPreference( "YZWnd", WindowPositionTrackerImportStringCaller( g_posYZWnd ), WindowPositionTrackerExportStringCaller( g_posYZWnd ) ); - GlobalPreferenceSystem().registerPreference( "XZWnd", WindowPositionTrackerImportStringCaller( g_posXZWnd ), WindowPositionTrackerExportStringCaller( g_posXZWnd ) ); + GlobalPreferenceSystem().registerPreference( "DetachableMenus", make_property_string( g_Layout_enableDetachableMenus.m_latched ) ); + GlobalPreferenceSystem().registerPreference( "PatchToolBar", make_property_string( g_Layout_enablePatchToolbar.m_latched ) ); + GlobalPreferenceSystem().registerPreference( "PluginToolBar", make_property_string( g_Layout_enablePluginToolbar.m_latched ) ); + GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", make_property_string( g_Layout_viewStyle.m_latched ) ); + GlobalPreferenceSystem().registerPreference( "XYHeight", make_property_string( g_layout_globals.nXYHeight ) ); + GlobalPreferenceSystem().registerPreference( "XYWidth", make_property_string( g_layout_globals.nXYWidth ) ); + GlobalPreferenceSystem().registerPreference( "CamWidth", make_property_string( g_layout_globals.nCamWidth ) ); + GlobalPreferenceSystem().registerPreference( "CamHeight", make_property_string( g_layout_globals.nCamHeight ) ); + + GlobalPreferenceSystem().registerPreference( "State", make_property_string( g_layout_globals.nState ) ); + GlobalPreferenceSystem().registerPreference( "PositionX", make_property_string( g_layout_globals.m_position.x ) ); + GlobalPreferenceSystem().registerPreference( "PositionY", make_property_string( g_layout_globals.m_position.y ) ); + GlobalPreferenceSystem().registerPreference( "Width", make_property_string( g_layout_globals.m_position.w ) ); + GlobalPreferenceSystem().registerPreference( "Height", make_property_string( g_layout_globals.m_position.h ) ); + + GlobalPreferenceSystem().registerPreference( "CamWnd", make_property(g_posCamWnd) ); + GlobalPreferenceSystem().registerPreference( "XYWnd", make_property(g_posXYWnd) ); + GlobalPreferenceSystem().registerPreference( "YZWnd", make_property(g_posYZWnd) ); + GlobalPreferenceSystem().registerPreference( "XZWnd", make_property(g_posXZWnd) ); { const char* ENGINEPATH_ATTRIBUTE = @@ -3316,7 +3318,7 @@ void MainFrame_Construct(){ g_strEnginePath = path.c_str(); } - GlobalPreferenceSystem().registerPreference( "EnginePath", CopiedStringImportStringCaller( g_strEnginePath ), CopiedStringExportStringCaller( g_strEnginePath ) ); + GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) ); g_Layout_viewStyle.useLatched(); g_Layout_enableDetachableMenus.useLatched(); @@ -3346,7 +3348,7 @@ void MainFrame_Destroy(){ void GLWindow_Construct(){ - GlobalPreferenceSystem().registerPreference( "MouseButtons", IntImportStringCaller( g_glwindow_globals.m_nMouseType ), IntExportStringCaller( g_glwindow_globals.m_nMouseType ) ); + GlobalPreferenceSystem().registerPreference( "MouseButtons", make_property_string( g_glwindow_globals.m_nMouseType ) ); } void GLWindow_Destroy(){ diff --git a/radiant/map.cpp b/radiant/map.cpp index a6833a6c..3275184b 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -1788,7 +1788,7 @@ const char* getMapsPath(){ const char* getLastFolderPath(){ if (g_strLastFolder.empty()) { - GlobalPreferenceSystem().registerPreference( "LastFolder", CopiedStringImportStringCaller( g_strLastFolder ), CopiedStringExportStringCaller( g_strLastFolder ) ); + GlobalPreferenceSystem().registerPreference( "LastFolder", make_property_string( g_strLastFolder ) ); if (g_strLastFolder.empty()) { g_strLastFolder = g_qeglobals.m_userGamePath; } @@ -2166,9 +2166,9 @@ void Map_Construct(){ GlobalCommands_insert( "RegionSetBrush", makeCallbackF(RegionBrush) ); GlobalCommands_insert( "RegionSetSelection", makeCallbackF(RegionSelected), Accelerator( 'R', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); - GlobalPreferenceSystem().registerPreference( "LastMap", CopiedStringImportStringCaller( g_strLastMap ), CopiedStringExportStringCaller( g_strLastMap ) ); - GlobalPreferenceSystem().registerPreference( "LoadLastMap", BoolImportStringCaller( g_bLoadLastMap ), BoolExportStringCaller( g_bLoadLastMap ) ); - GlobalPreferenceSystem().registerPreference( "MapInfoDlg", WindowPositionImportStringCaller( g_posMapInfoWnd ), WindowPositionExportStringCaller( g_posMapInfoWnd ) ); + GlobalPreferenceSystem().registerPreference( "LastMap", make_property_string( g_strLastMap ) ); + GlobalPreferenceSystem().registerPreference( "LoadLastMap", make_property_string( g_bLoadLastMap ) ); + GlobalPreferenceSystem().registerPreference( "MapInfoDlg", make_property( g_posMapInfoWnd ) ); PreferencesDialog_addSettingsPreferences( makeCallbackF(Map_constructPreferences) ); diff --git a/radiant/mru.cpp b/radiant/mru.cpp index aef04cbc..9a4a1d75 100644 --- a/radiant/mru.cpp +++ b/radiant/mru.cpp @@ -219,11 +219,11 @@ void MRU_constructMenu( ui::Menu menu ){ #include "stringio.h" void MRU_Construct(){ - GlobalPreferenceSystem().registerPreference( "Count", SizeImportStringCaller( MRU_used ), SizeExportStringCaller( MRU_used ) ); + GlobalPreferenceSystem().registerPreference( "Count", make_property_string( MRU_used ) ); for ( std::size_t i = 0; i != MRU_MAX; ++i ) { - GlobalPreferenceSystem().registerPreference( MRU_keys[i], CopiedStringImportStringCaller( MRU_filenames[i] ), CopiedStringExportStringCaller( MRU_filenames[i] ) ); + GlobalPreferenceSystem().registerPreference( MRU_keys[i], make_property_string( MRU_filenames[i] ) ); } MRU_Init(); diff --git a/radiant/multimon.cpp b/radiant/multimon.cpp index b626f435..38ed3f30 100644 --- a/radiant/multimon.cpp +++ b/radiant/multimon.cpp @@ -86,8 +86,8 @@ void MultiMon_Construct(){ g_multimon_globals.m_bStartOnPrimMon = true; } - GlobalPreferenceSystem().registerPreference( "StartOnPrimMon", BoolImportStringCaller( g_multimon_globals.m_bStartOnPrimMon ), BoolExportStringCaller( g_multimon_globals.m_bStartOnPrimMon ) ); - GlobalPreferenceSystem().registerPreference( "NoSysMenuPopups", BoolImportStringCaller( g_Multimon_enableSysMenuPopups.m_latched ), BoolExportStringCaller( g_Multimon_enableSysMenuPopups.m_latched ) ); + GlobalPreferenceSystem().registerPreference( "StartOnPrimMon", make_property_string( g_multimon_globals.m_bStartOnPrimMon ) ); + GlobalPreferenceSystem().registerPreference( "NoSysMenuPopups", make_property_string( g_Multimon_enableSysMenuPopups.m_latched ) ); g_Multimon_enableSysMenuPopups.useLatched(); diff --git a/radiant/patchdialog.cpp b/radiant/patchdialog.cpp index b6650f50..83037832 100644 --- a/radiant/patchdialog.cpp +++ b/radiant/patchdialog.cpp @@ -1035,12 +1035,12 @@ void PatchInspector_SelectionChanged( const Selectable& selectable ){ void PatchInspector_Construct(){ GlobalCommands_insert( "PatchInspector", makeCallbackF(PatchInspector_toggleShown), Accelerator( 'S', (GdkModifierType)GDK_SHIFT_MASK ) ); - GlobalPreferenceSystem().registerPreference( "PatchWnd", WindowPositionTrackerImportStringCaller( g_PatchInspector.m_position_tracker ), WindowPositionTrackerExportStringCaller( g_PatchInspector.m_position_tracker ) ); - GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale1", FloatImportStringCaller( g_pi_globals.scale[0] ), FloatExportStringCaller( g_pi_globals.scale[0] ) ); - GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale2", FloatImportStringCaller( g_pi_globals.scale[1] ), FloatExportStringCaller( g_pi_globals.scale[1] ) ); - GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift1", FloatImportStringCaller( g_pi_globals.shift[0] ), FloatExportStringCaller( g_pi_globals.shift[0] ) ); - GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift2", FloatImportStringCaller( g_pi_globals.shift[1] ), FloatExportStringCaller( g_pi_globals.shift[1] ) ); - GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Rotate", FloatImportStringCaller( g_pi_globals.rotate ), FloatExportStringCaller( g_pi_globals.rotate ) ); + GlobalPreferenceSystem().registerPreference( "PatchWnd", make_property( g_PatchInspector.m_position_tracker ) ); + GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale1", make_property_string( g_pi_globals.scale[0] ) ); + GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale2", make_property_string( g_pi_globals.scale[1] ) ); + GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift1", make_property_string( g_pi_globals.shift[0] ) ); + GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift2", make_property_string( g_pi_globals.shift[1] ) ); + GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Rotate", make_property_string( g_pi_globals.rotate ) ); typedef FreeCaller PatchInspectorSelectionChangedCaller; GlobalSelectionSystem().addSelectionChangeCallback( PatchInspectorSelectionChangedCaller() ); diff --git a/radiant/patchmanip.cpp b/radiant/patchmanip.cpp index a7e993ef..60ee490f 100644 --- a/radiant/patchmanip.cpp +++ b/radiant/patchmanip.cpp @@ -607,7 +607,7 @@ void Patch_registerPreferencesPage(){ #include "preferencesystem.h" void PatchPreferences_construct(){ - GlobalPreferenceSystem().registerPreference( "Subdivisions", IntImportStringCaller( g_PatchSubdivideThreshold ), IntExportStringCaller( g_PatchSubdivideThreshold ) ); + GlobalPreferenceSystem().registerPreference( "Subdivisions", make_property_string( g_PatchSubdivideThreshold ) ); } diff --git a/radiant/preferencedictionary.h b/radiant/preferencedictionary.h index eed7b1c9..382271ee 100644 --- a/radiant/preferencedictionary.h +++ b/radiant/preferencedictionary.h @@ -33,17 +33,16 @@ class PreferenceDictionary : public PreferenceSystem { class PreferenceEntry { -ImportExportCallback::Import_t m_importer; -ImportExportCallback::Export_t m_exporter; +Property m_cb; public: -PreferenceEntry( const ImportExportCallback::Import_t& importer, const ImportExportCallback::Export_t& exporter ) - : m_importer( importer ), m_exporter( exporter ){ +PreferenceEntry( const Property& cb ) + : m_cb( cb ){ } void importString( const char* string ){ - m_importer( string ); + m_cb.set( string ); } -void exportString( const ImportExportCallback::Import_t& importer ){ - m_exporter( importer ); +void exportString( const Callback & importer ){ + m_cb.get( importer ); } }; @@ -66,11 +65,11 @@ iterator find( const char* name ){ return m_preferences.find( name ); } -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 ) ) ); +void registerPreference( const char* name, const Property& cb ){ + m_preferences.insert( PreferenceEntries::value_type( name, PreferenceEntry( cb ) ) ); PreferenceCache::iterator i = m_cache.find( name ); if ( i != m_cache.end() ) { - importer( ( *i ).second.c_str() ); + cb.set( i->second.c_str() ); m_cache.erase( i ); } } diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index ea3dbe44..ea993de5 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -216,18 +216,22 @@ bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filen } +struct LogConsole { + static void Export(const Callback &returnz) { + returnz(g_Console_enableLogging); + } -void LogConsole_importString( const char* string ){ - g_Console_enableLogging = string_equal( string, "true" ); - Sys_LogFile( g_Console_enableLogging ); -} -typedef FreeCaller LogConsoleImportStringCaller; + static void Import(bool value) { + g_Console_enableLogging = value; + Sys_LogFile(g_Console_enableLogging); + } +}; void RegisterGlobalPreferences( PreferenceSystem& preferences ){ - preferences.registerPreference( "gamefile", CopiedStringImportStringCaller( g_GamesDialog.m_sGameFile ), CopiedStringExportStringCaller( g_GamesDialog.m_sGameFile ) ); - preferences.registerPreference( "gamePrompt", BoolImportStringCaller( g_GamesDialog.m_bGamePrompt ), BoolExportStringCaller( g_GamesDialog.m_bGamePrompt ) ); - preferences.registerPreference( "log console", LogConsoleImportStringCaller(), BoolExportStringCaller( g_Console_enableLogging ) ); + preferences.registerPreference( "gamefile", make_property_string( g_GamesDialog.m_sGameFile ) ); + preferences.registerPreference( "gamePrompt", make_property_string( g_GamesDialog.m_bGamePrompt ) ); + preferences.registerPreference( "log console", make_property_string() ); } @@ -280,7 +284,7 @@ void CGameDialog::GameFileImport( int value ){ m_sGameFile = ( *iGame )->mGameFile; } -void CGameDialog::GameFileExport( const ImportExportCallback::Import_t& importCallback ) const { +void CGameDialog::GameFileExport( const Callback & importCallback ) const { // use m_sGameFile to set value std::list::const_iterator iGame; int i = 0; @@ -295,13 +299,15 @@ void CGameDialog::GameFileExport( const ImportExportCallback::Import_t& imp importCallback( m_nComboSelect ); } -void CGameDialog_GameFileImport( CGameDialog& self, int value ){ - self.GameFileImport( value ); -} +struct CGameDialog_GameFile { + static void Export(const CGameDialog &self, const Callback &returnz) { + self.GameFileExport(returnz); + } -void CGameDialog_GameFileExport( CGameDialog& self, const ImportExportCallback::Import_t& importCallback ){ - self.GameFileExport( importCallback ); -} + static void Import(CGameDialog &self, int value) { + self.GameFileImport(value); + } +}; void CGameDialog::CreateGlobalFrame( PreferencesPage& page ){ std::vector games; @@ -313,8 +319,7 @@ void CGameDialog::CreateGlobalFrame( PreferencesPage& page ){ page.appendCombo( "Select the game", StringArrayRange( &( *games.begin() ), &( *games.end() ) ), - {ReferenceCaller( *this ), - ReferenceCaller::Import_t&), CGameDialog_GameFileExport>( *this )} + make_property(*this) ); page.appendCheckBox( "Startup", "Show Global Preferences", m_bGamePrompt ); } @@ -914,39 +919,36 @@ void PreferencesDialog_showDialog(){ } } +struct GameName { + static void Export(const Callback &returnz) { + returnz(gamename_get()); + } + static void Import(const char *value) { + gamename_set(value); + } +}; +struct GameMode { + static void Export(const Callback &returnz) { + returnz(gamemode_get()); + } - -void GameName_importString( const char* value ){ - gamename_set( value ); -} -typedef FreeCaller GameNameImportStringCaller; -void GameName_exportString( const ImportExportCallback::Import_t& importer ){ - importer( gamename_get() ); -} -typedef FreeCaller::Import_t&), GameName_exportString> GameNameExportStringCaller; - -void GameMode_importString( const char* value ){ - gamemode_set( value ); -} -typedef FreeCaller GameModeImportStringCaller; -void GameMode_exportString( const ImportExportCallback::Import_t& importer ){ - importer( gamemode_get() ); -} -typedef FreeCaller::Import_t&), GameMode_exportString> GameModeExportStringCaller; - + static void Import(const char *value) { + gamemode_set(value); + } +}; void RegisterPreferences( PreferenceSystem& preferences ){ #if GDEF_OS_WINDOWS - preferences.registerPreference( "UseCustomShaderEditor", BoolImportStringCaller( g_TextEditor_useWin32Editor ), BoolExportStringCaller( g_TextEditor_useWin32Editor ) ); + preferences.registerPreference( "UseCustomShaderEditor", make_property_string( g_TextEditor_useWin32Editor ) ); #else - preferences.registerPreference( "UseCustomShaderEditor", BoolImportStringCaller( g_TextEditor_useCustomEditor ), BoolExportStringCaller( g_TextEditor_useCustomEditor ) ); - preferences.registerPreference( "CustomShaderEditorCommand", CopiedStringImportStringCaller( g_TextEditor_editorCommand ), CopiedStringExportStringCaller( g_TextEditor_editorCommand ) ); + preferences.registerPreference( "UseCustomShaderEditor", make_property_string( g_TextEditor_useCustomEditor ) ); + preferences.registerPreference( "CustomShaderEditorCommand", make_property_string( g_TextEditor_editorCommand ) ); #endif - preferences.registerPreference( "GameName", GameNameImportStringCaller(), GameNameExportStringCaller() ); - preferences.registerPreference( "GameMode", GameModeImportStringCaller(), GameModeExportStringCaller() ); + preferences.registerPreference( "GameName", make_property() ); + preferences.registerPreference( "GameMode", make_property() ); } void Preferences_Init(){ diff --git a/radiant/preferences.h b/radiant/preferences.h index 8d7f93ae..59dd60da 100644 --- a/radiant/preferences.h +++ b/radiant/preferences.h @@ -33,6 +33,7 @@ #include "dialog.h" #include #include +#include "property.h" void Widget_connectToggleDependency( ui::Widget self, ui::Widget toggleButton ); @@ -46,10 +47,10 @@ 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, ImportExportCallback const &cb ){ +ui::CheckButton appendCheckBox( const char* name, const char* flag, Property const &cb ){ return m_dialog.addCheckBox( m_vbox, name, flag, cb ); } -void appendCombo( const char* name, StringArrayRange values, ImportExportCallback const &cb ){ +void appendCombo( const char* name, StringArrayRange values, Property const &cb ){ m_dialog.addCombo( m_vbox, name, values, cb ); } void appendCombo( const char* name, int& data, StringArrayRange values ){ @@ -58,37 +59,37 @@ 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, ImportExportCallback const &cb ){ +void appendRadio( const char* name, StringArrayRange names, Property 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, ImportExportCallback const &cb ){ +void appendRadioIcons( const char* name, StringArrayRange icons, Property 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, ImportExportCallback const &cb ){ +ui::Widget appendEntry( const char* name, Property 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, ImportExportCallback const &cb){ +ui::Widget appendEntry( const char* name, Property 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, ImportExportCallback const &cb ){ +ui::Widget appendEntry( const char* name, Property 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, ImportExportCallback const &cb ){ +ui::Widget appendPathEntry( const char* name, bool browse_directory, Property const &cb ){ return m_dialog.addPathEntry( m_vbox, name, browse_directory, cb ); } ui::Widget appendPathEntry( const char* name, CopiedString& data, bool directory ){ @@ -97,10 +98,10 @@ 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, ImportExportCallback const &cb ){ +ui::SpinButton appendSpinner( const char* name, double value, double lower, double upper, Property 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, ImportExportCallback const &cb ){ +ui::SpinButton appendSpinner( const char* name, double value, double lower, double upper, Property const &cb ){ return m_dialog.addSpinner( m_vbox, name, value, lower, upper, cb ); } }; @@ -137,21 +138,25 @@ public: void useLatched() { m_value = m_latched; } +}; - void import(Value value) { - m_latched = value; - if (m_latched != m_value) { - PreferencesDialog_restartRequired(m_description); - } - } +template +struct PropertyImpl, T> { + static void Export(const LatchedValue &self, const Callback &returnz) { + returnz(self.m_latched); + } + + static void Import(LatchedValue &self, T value) { + self.m_latched = value; + if (value != self.m_value) { + PreferencesDialog_restartRequired(self.m_description); + } + } }; -template -ImportExportCallback mkImportExportCallback(LatchedValue &self) { - return { - MemberCaller, void(T), &LatchedValue::import>(self), - ReferenceCaller &), impexp::Export>(self.m_latched) - }; +template +Property make_property(LatchedValue &self) { + return make_property, T>(self); } /*! @@ -275,7 +280,7 @@ void DoGameDialog(); ui::Window BuildDialog(); void GameFileImport( int value ); -void GameFileExport( const ImportExportCallback::Import_t& importCallback ) const; +void GameFileExport( const Callback & importCallback ) const; /*! construction of the dialog frame diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp index 57007112..89df8a77 100644 --- a/radiant/surfacedialog.cpp +++ b/radiant/surfacedialog.cpp @@ -162,8 +162,6 @@ NonModalEntry m_valueEntry; ui::Entry m_valueEntryWidget{ui::null}; public: WindowPositionTracker m_positionTracker; -WindowPositionTrackerImportStringCaller m_importPosition; -WindowPositionTrackerExportStringCaller m_exportPosition; // Dialog Data float m_fitHorizontal; @@ -190,8 +188,6 @@ SurfaceInspector() : m_rotateEntry( Increment::ApplyCaller( m_rotateIncrement ), Increment::CancelCaller( m_rotateIncrement ) ), m_idleDraw( UpdateCaller( *this ) ), m_valueEntry( ApplyFlagsCaller( *this ), UpdateCaller( *this ) ), - m_importPosition( m_positionTracker ), - m_exportPosition( m_positionTracker ), m_hshiftIncrement( g_si_globals.shift[0] ), m_vshiftIncrement( g_si_globals.shift[1] ), m_hscaleIncrement( g_si_globals.scale[0] ), @@ -1415,13 +1411,13 @@ void SurfaceInspector_Construct(){ FaceTextureClipboard_setDefault(); - GlobalPreferenceSystem().registerPreference( "SurfaceWnd", getSurfaceInspector().m_importPosition, getSurfaceInspector().m_exportPosition ); - GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Scale1", FloatImportStringCaller( g_si_globals.scale[0] ), FloatExportStringCaller( g_si_globals.scale[0] ) ); - GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Scale2", FloatImportStringCaller( g_si_globals.scale[1] ), FloatExportStringCaller( g_si_globals.scale[1] ) ); - GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Shift1", FloatImportStringCaller( g_si_globals.shift[0] ), FloatExportStringCaller( g_si_globals.shift[0] ) ); - GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Shift2", FloatImportStringCaller( g_si_globals.shift[1] ), FloatExportStringCaller( g_si_globals.shift[1] ) ); - GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Rotate", FloatImportStringCaller( g_si_globals.rotate ), FloatExportStringCaller( g_si_globals.rotate ) ); - GlobalPreferenceSystem().registerPreference( "SnapTToGrid", BoolImportStringCaller( g_si_globals.m_bSnapTToGrid ), BoolExportStringCaller( g_si_globals.m_bSnapTToGrid ) ); + GlobalPreferenceSystem().registerPreference( "SurfaceWnd", make_property( getSurfaceInspector().m_positionTracker) ); + GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Scale1", make_property_string( g_si_globals.scale[0] ) ); + GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Scale2", make_property_string( g_si_globals.scale[1] ) ); + GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Shift1", make_property_string( g_si_globals.shift[0] ) ); + GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Shift2", make_property_string( g_si_globals.shift[1] ) ); + GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Rotate", make_property_string( g_si_globals.rotate ) ); + GlobalPreferenceSystem().registerPreference( "SnapTToGrid", make_property_string( g_si_globals.m_bSnapTToGrid ) ); typedef FreeCaller SurfaceInspectorSelectionChangedCaller; GlobalSelectionSystem().addSelectionChangeCallback( SurfaceInspectorSelectionChangedCaller() ); diff --git a/radiant/textures.cpp b/radiant/textures.cpp index eb989846..02f706b9 100644 --- a/radiant/textures.cpp +++ b/radiant/textures.cpp @@ -621,99 +621,106 @@ void Textures_UpdateTextureCompressionFormat(){ Textures_setTextureComponents( texture_components ); } -void TextureCompressionImport( TextureCompressionFormat& self, int value ){ - if ( !g_texture_globals.m_bOpenGLCompressionSupported - && g_texture_globals.m_bS3CompressionSupported - && value >= 1 ) { - ++value; - } - switch ( value ) - { - case 0: - self = TEXTURECOMPRESSION_NONE; - break; - case 1: - self = TEXTURECOMPRESSION_RGBA; - break; - case 2: - self = TEXTURECOMPRESSION_RGBA_S3TC_DXT1; - break; - case 3: - self = TEXTURECOMPRESSION_RGBA_S3TC_DXT3; - break; - case 4: - self = TEXTURECOMPRESSION_RGBA_S3TC_DXT5; - break; - } - Textures_UpdateTextureCompressionFormat(); -} -typedef ReferenceCaller TextureCompressionImportCaller; +struct TextureCompression { + static void Export(const TextureCompressionFormat &self, const Callback &returnz) { + returnz(self); + } + + static void Import(TextureCompressionFormat &self, int value) { + if (!g_texture_globals.m_bOpenGLCompressionSupported + && g_texture_globals.m_bS3CompressionSupported + && value >= 1) { + ++value; + } + switch (value) { + case 0: + self = TEXTURECOMPRESSION_NONE; + break; + case 1: + self = TEXTURECOMPRESSION_RGBA; + break; + case 2: + self = TEXTURECOMPRESSION_RGBA_S3TC_DXT1; + break; + case 3: + self = TEXTURECOMPRESSION_RGBA_S3TC_DXT3; + break; + case 4: + self = TEXTURECOMPRESSION_RGBA_S3TC_DXT5; + break; + } + Textures_UpdateTextureCompressionFormat(); + } +}; -void TextureGammaImport( float& self, float value ){ - if ( self != value ) { - Textures_Unrealise(); - self = value; - Textures_Realise(); +struct TextureGamma { + static void Export(const float &self, const Callback &returnz) { + returnz(self); } -} -typedef ReferenceCaller TextureGammaImportCaller; -void TextureModeImport( ETexturesMode& self, int value ){ - switch ( value ) - { - case 0: - Textures_SetMode( eTextures_NEAREST ); - break; - case 1: - Textures_SetMode( eTextures_NEAREST_MIPMAP_NEAREST ); - break; - case 2: - Textures_SetMode( eTextures_LINEAR ); - break; - case 3: - Textures_SetMode( eTextures_NEAREST_MIPMAP_LINEAR ); - break; - case 4: - Textures_SetMode( eTextures_LINEAR_MIPMAP_NEAREST ); - break; - case 5: - Textures_SetMode( eTextures_LINEAR_MIPMAP_LINEAR ); - break; - case 6: - Textures_SetMode( eTextures_MAX_ANISOTROPY ); + static void Import(float &self, float value) { + if (value != self) { + Textures_Unrealise(); + self = value; + Textures_Realise(); + } } -} -typedef ReferenceCaller TextureModeImportCaller; +}; -void TextureModeExport( ETexturesMode& self, const ImportExportCallback::Import_t& importer ){ - switch ( self ) - { - case eTextures_NEAREST: - importer( 0 ); - break; - case eTextures_NEAREST_MIPMAP_NEAREST: - importer( 1 ); - break; - case eTextures_LINEAR: - importer( 2 ); - break; - case eTextures_NEAREST_MIPMAP_LINEAR: - importer( 3 ); - break; - case eTextures_LINEAR_MIPMAP_NEAREST: - importer( 4 ); - break; - case eTextures_LINEAR_MIPMAP_LINEAR: - importer( 5 ); - break; - case eTextures_MAX_ANISOTROPY: - importer( 6 ); - break; - default: - importer( 4 ); - } -} -typedef ReferenceCaller::Import_t&), TextureModeExport> TextureModeExportCaller; +struct TextureMode { + static void Export(const ETexturesMode &self, const Callback &returnz) { + switch (self) { + case eTextures_NEAREST: + returnz(0); + break; + case eTextures_NEAREST_MIPMAP_NEAREST: + returnz(1); + break; + case eTextures_LINEAR: + returnz(2); + break; + case eTextures_NEAREST_MIPMAP_LINEAR: + returnz(3); + break; + case eTextures_LINEAR_MIPMAP_NEAREST: + returnz(4); + break; + case eTextures_LINEAR_MIPMAP_LINEAR: + returnz(5); + break; + case eTextures_MAX_ANISOTROPY: + returnz(6); + break; + default: + returnz(4); + } + } + + static void Import(ETexturesMode &self, int value) { + switch (value) { + case 0: + Textures_SetMode(eTextures_NEAREST); + break; + case 1: + Textures_SetMode(eTextures_NEAREST_MIPMAP_NEAREST); + break; + case 2: + Textures_SetMode(eTextures_LINEAR); + break; + case 3: + Textures_SetMode(eTextures_NEAREST_MIPMAP_LINEAR); + break; + case 4: + Textures_SetMode(eTextures_LINEAR_MIPMAP_NEAREST); + break; + case 5: + Textures_SetMode(eTextures_LINEAR_MIPMAP_LINEAR); + break; + case 6: + Textures_SetMode(eTextures_MAX_ANISOTROPY); + } + } +}; void Textures_constructPreferences( PreferencesPage& page ){ { @@ -721,7 +728,7 @@ void Textures_constructPreferences( PreferencesPage& page ){ page.appendRadio( "Texture Quality", STRING_ARRAY_RANGE( percentages ), - mkImportExportCallback( g_Textures_textureQuality ) + make_property( g_Textures_textureQuality ) ); } page.appendSpinner( @@ -729,16 +736,14 @@ void Textures_constructPreferences( PreferencesPage& page ){ 1.0, 0.0, 1.0, - {ImportExportCallback::Import_t( TextureGammaImportCaller( g_texture_globals.fGamma ) ), - ImportExportCallback::Export_t( FloatExportCaller( g_texture_globals.fGamma ) )} + make_property(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 ), - {ImportExportCallback::Import_t( TextureModeImportCaller( g_texture_mode ) ), - ImportExportCallback::Export_t( TextureModeExportCaller( g_texture_mode ) )} + make_property(g_texture_mode) ); } { @@ -758,8 +763,7 @@ 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 ) )} + make_property(g_texture_globals.m_nTextureCompressionFormat) ); } } @@ -771,20 +775,24 @@ void Textures_registerPreferencesPage(){ PreferencesDialog_addDisplayPage( makeCallbackF(Textures_constructPage) ); } -void TextureCompression_importString( const char* string ){ - g_texture_globals.m_nTextureCompressionFormat = static_cast( atoi( string ) ); - Textures_UpdateTextureCompressionFormat(); -} -typedef FreeCaller TextureCompressionImportStringCaller; +struct TextureCompressionPreference { + static void Export(const Callback &returnz) { + returnz(g_texture_globals.m_nTextureCompressionFormat); + } + static void Import(int value) { + g_texture_globals.m_nTextureCompressionFormat = static_cast( value ); + Textures_UpdateTextureCompressionFormat(); + } +}; void Textures_Construct(){ g_texturesmap = new TexturesMap; - GlobalPreferenceSystem().registerPreference( "TextureCompressionFormat", TextureCompressionImportStringCaller(), IntExportStringCaller( reinterpret_cast( g_texture_globals.m_nTextureCompressionFormat ) ) ); - GlobalPreferenceSystem().registerPreference( "TextureFiltering", IntImportStringCaller( reinterpret_cast( g_texture_mode ) ), IntExportStringCaller( reinterpret_cast( g_texture_mode ) ) ); - GlobalPreferenceSystem().registerPreference( "TextureQuality", IntImportStringCaller( g_Textures_textureQuality.m_latched ), IntExportStringCaller( g_Textures_textureQuality.m_latched ) ); - GlobalPreferenceSystem().registerPreference( "SI_Gamma", FloatImportStringCaller( g_texture_globals.fGamma ), FloatExportStringCaller( g_texture_globals.fGamma ) ); + GlobalPreferenceSystem().registerPreference( "TextureCompressionFormat", make_property_string() ); + GlobalPreferenceSystem().registerPreference( "TextureFiltering", make_property_string( reinterpret_cast( g_texture_mode ) ) ); + GlobalPreferenceSystem().registerPreference( "TextureQuality", make_property_string( g_Textures_textureQuality.m_latched ) ); + GlobalPreferenceSystem().registerPreference( "SI_Gamma", make_property_string( g_texture_globals.fGamma ) ); g_Textures_textureQuality.useLatched(); diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index a86575bf..8a760e03 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -226,26 +226,26 @@ enum StartupShaders STARTUPSHADERS_COMMON, }; -void TextureBrowser_hideUnusedExport( const ImportExportCallback::Import_t& importer ); -typedef FreeCaller::Import_t&), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport; +void TextureBrowser_hideUnusedExport( const Callback & importer ); +typedef FreeCaller &), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport; -void TextureBrowser_showShadersExport( const ImportExportCallback::Import_t& importer ); -typedef FreeCaller::Import_t&), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport; +void TextureBrowser_showShadersExport( const Callback & importer ); +typedef FreeCaller &), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport; -void TextureBrowser_showShaderlistOnly( const ImportExportCallback::Import_t& importer ); -typedef FreeCaller::Import_t&), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport; +void TextureBrowser_showShaderlistOnly( const Callback & importer ); +typedef FreeCaller &), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport; -void TextureBrowser_fixedSize( const ImportExportCallback::Import_t& importer ); -typedef FreeCaller::Import_t&), TextureBrowser_fixedSize> TextureBrowserFixedSizeExport; +void TextureBrowser_fixedSize( const Callback & importer ); +typedef FreeCaller &), TextureBrowser_fixedSize> TextureBrowserFixedSizeExport; -void TextureBrowser_filterMissing( const ImportExportCallback::Import_t& importer ); -typedef FreeCaller::Import_t&), TextureBrowser_filterMissing> TextureBrowserFilterMissingExport; +void TextureBrowser_filterMissing( const Callback & importer ); +typedef FreeCaller &), TextureBrowser_filterMissing> TextureBrowserFilterMissingExport; -void TextureBrowser_filterFallback( const ImportExportCallback::Import_t& importer ); -typedef FreeCaller::Import_t&), TextureBrowser_filterFallback> TextureBrowserFilterFallbackExport; +void TextureBrowser_filterFallback( const Callback & importer ); +typedef FreeCaller &), TextureBrowser_filterFallback> TextureBrowserFilterFallbackExport; -void TextureBrowser_enableAlpha( const ImportExportCallback::Import_t& importer ); -typedef FreeCaller::Import_t&), TextureBrowser_enableAlpha> TextureBrowserEnableAlphaExport; +void TextureBrowser_enableAlpha( const Callback & importer ); +typedef FreeCaller &), TextureBrowser_enableAlpha> TextureBrowserEnableAlphaExport; class TextureBrowser { @@ -671,14 +671,19 @@ void TextureBrowser_activeShadersChanged( TextureBrowser& textureBrowser ){ g_activeShadersChangedCallbacks(); } -void TextureBrowser_importShowScrollbar( TextureBrowser& textureBrowser, bool value ){ - textureBrowser.m_showTextureScrollbar = value; - if ( textureBrowser.m_texture_scroll != 0 ) { - textureBrowser.m_texture_scroll.visible(textureBrowser.m_showTextureScrollbar); - TextureBrowser_updateScroll( textureBrowser ); +struct TextureBrowser_ShowScrollbar { + static void Export(const TextureBrowser &self, const Callback &returnz) { + returnz(self.m_showTextureScrollbar); } -} -typedef ReferenceCaller TextureBrowserImportShowScrollbarCaller; + + static void Import(TextureBrowser &self, bool value) { + self.m_showTextureScrollbar = value; + if (self.m_texture_scroll) { + self.m_texture_scroll.visible(self.m_showTextureScrollbar); + TextureBrowser_updateScroll(self); + } + } +}; /* @@ -863,40 +868,40 @@ void TextureBrowser_ShowTagSearchResult( TextureBrowser& textureBrowser, const c bool TextureBrowser_hideUnused(); -void TextureBrowser_hideUnusedExport( const ImportExportCallback::Import_t& importer ){ +void TextureBrowser_hideUnusedExport( const Callback & importer ){ importer( TextureBrowser_hideUnused() ); } -typedef FreeCaller::Import_t&), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport; +typedef FreeCaller &), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport; -void TextureBrowser_showShadersExport( const ImportExportCallback::Import_t& importer ){ +void TextureBrowser_showShadersExport( const Callback & importer ){ importer( GlobalTextureBrowser().m_showShaders ); } -typedef FreeCaller::Import_t&), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport; +typedef FreeCaller &), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport; -void TextureBrowser_showShaderlistOnly( const ImportExportCallback::Import_t& importer ){ +void TextureBrowser_showShaderlistOnly( const Callback & importer ){ importer( g_TextureBrowser_shaderlistOnly ); } -typedef FreeCaller::Import_t&), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport; +typedef FreeCaller &), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport; -void TextureBrowser_fixedSize( const ImportExportCallback::Import_t& importer ){ +void TextureBrowser_fixedSize( const Callback & importer ){ importer( g_TextureBrowser_fixedSize ); } -typedef FreeCaller::Import_t&), TextureBrowser_fixedSize> TextureBrowser_FixedSizeExport; +typedef FreeCaller &), TextureBrowser_fixedSize> TextureBrowser_FixedSizeExport; -void TextureBrowser_filterMissing( const ImportExportCallback::Import_t& importer ){ +void TextureBrowser_filterMissing( const Callback & importer ){ importer( g_TextureBrowser_filterMissing ); } -typedef FreeCaller::Import_t&), TextureBrowser_filterMissing> TextureBrowser_filterMissingExport; +typedef FreeCaller &), TextureBrowser_filterMissing> TextureBrowser_filterMissingExport; -void TextureBrowser_filterFallback( const ImportExportCallback::Import_t& importer ){ +void TextureBrowser_filterFallback( const Callback & importer ){ importer( g_TextureBrowser_filterFallback ); } -typedef FreeCaller::Import_t&), TextureBrowser_filterFallback> TextureBrowser_filterFallbackExport; +typedef FreeCaller &), TextureBrowser_filterFallback> TextureBrowser_filterFallbackExport; -void TextureBrowser_enableAlpha( const ImportExportCallback::Import_t& importer ){ +void TextureBrowser_enableAlpha( const Callback & importer ){ importer( g_TextureBrowser_enableAlpha ); } -typedef FreeCaller::Import_t&), TextureBrowser_enableAlpha> TextureBrowser_enableAlphaExport; +typedef FreeCaller &), TextureBrowser_enableAlpha> TextureBrowser_enableAlphaExport; void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused ){ if ( hideUnused ) { @@ -2500,7 +2505,7 @@ void TextureBrowser_EnableAlpha(){ TextureBrowser_activeShadersChanged( GlobalTextureBrowser() ); } -void TextureBrowser_exportTitle( const ImportExportCallback::Import_t& importer ){ +void TextureBrowser_exportTitle( const Callback & importer ){ StringOutputStream buffer( 64 ); buffer << "Textures: "; if ( !string_empty( g_TextureBrowser_currentDirectory.c_str() ) ) { @@ -2513,72 +2518,70 @@ void TextureBrowser_exportTitle( const ImportExportCallback::Impor importer( buffer.c_str() ); } - -void TextureScaleImport( TextureBrowser& textureBrowser, int value ){ - switch ( value ) - { - case 0: - TextureBrowser_setScale( textureBrowser, 10 ); - break; - case 1: - TextureBrowser_setScale( textureBrowser, 25 ); - break; - case 2: - TextureBrowser_setScale( textureBrowser, 50 ); - break; - case 3: - TextureBrowser_setScale( textureBrowser, 100 ); - break; - case 4: - TextureBrowser_setScale( textureBrowser, 200 ); - break; - } -} -typedef ReferenceCaller TextureScaleImportCaller; - -void TextureScaleExport( TextureBrowser& textureBrowser, const ImportExportCallback::Import_t& importer ){ - switch ( textureBrowser.m_textureScale ) - { - case 10: - importer( 0 ); - break; - case 25: - importer( 1 ); - break; - case 50: - importer( 2 ); - break; - case 100: - importer( 3 ); - break; - case 200: - importer( 4 ); - break; +struct TextureScale { + static void Export(const TextureBrowser &self, const Callback &returnz) { + switch (self.m_textureScale) { + case 10: + returnz(0); + break; + case 25: + returnz(1); + break; + case 50: + returnz(2); + break; + case 100: + returnz(3); + break; + case 200: + returnz(4); + break; + } } -} -typedef ReferenceCaller::Import_t&), TextureScaleExport> TextureScaleExportCaller; + static void Import(TextureBrowser &self, int value) { + switch (value) { + case 0: + TextureBrowser_setScale(self, 10); + break; + case 1: + TextureBrowser_setScale(self, 25); + break; + case 2: + TextureBrowser_setScale(self, 50); + break; + case 3: + TextureBrowser_setScale(self, 100); + break; + case 4: + TextureBrowser_setScale(self, 200); + break; + } + } +}; -void UniformTextureSizeImport( TextureBrowser& textureBrowser, int value ){ +struct UniformTextureSize { + static void Export(const TextureBrowser &self, const Callback &returnz) { + returnz(g_TextureBrowser.m_uniformTextureSize); + } - if ( value > 16 ) - TextureBrowser_setUniformSize( textureBrowser, value ); -} -typedef ReferenceCaller UniformTextureSizeImportCaller; + static void Import(TextureBrowser &self, int value) { + if (value > 16) + TextureBrowser_setUniformSize(self, value); + } +}; void TextureBrowser_constructPreferences( PreferencesPage& page ){ page.appendCheckBox( "", "Texture scrollbar", - {TextureBrowserImportShowScrollbarCaller( GlobalTextureBrowser() ), - BoolExportCaller( GlobalTextureBrowser().m_showTextureScrollbar )} + make_property(GlobalTextureBrowser()) ); { const char* texture_scale[] = { "10%", "25%", "50%", "100%", "200%" }; page.appendCombo( "Texture Thumbnail Scale", STRING_ARRAY_RANGE( texture_scale ), - {ImportExportCallback::Import_t( TextureScaleImportCaller( GlobalTextureBrowser() ) ), - ImportExportCallback::Export_t( TextureScaleExportCaller( GlobalTextureBrowser() ) )} + make_property(GlobalTextureBrowser()) ); } page.appendSpinner( @@ -2605,9 +2608,6 @@ void TextureBrowser_registerPreferencesPage(){ #include "preferencesystem.h" #include "stringio.h" -typedef ReferenceCaller TextureBrowserSetScaleCaller; - - void TextureClipboard_textureSelected( const char* shader ); @@ -2630,25 +2630,17 @@ void TextureBrowser_Construct(){ GlobalToggles_insert( "FilterFallback", makeCallbackF(TextureBrowser_FilterFallback), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_hidenotex_item ) ); GlobalToggles_insert( "EnableAlpha", makeCallbackF(TextureBrowser_EnableAlpha), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_enablealpha_item ) ); - GlobalPreferenceSystem().registerPreference( "TextureScale", - makeSizeStringImportCallback( TextureBrowserSetScaleCaller( g_TextureBrowser ) ), - SizeExportStringCaller( g_TextureBrowser.m_textureScale ) - ); - GlobalPreferenceSystem().registerPreference( "UniformTextureSize", - makeIntStringImportCallback(UniformTextureSizeImportCaller(g_TextureBrowser)), - IntExportStringCaller(g_TextureBrowser.m_uniformTextureSize) ); - GlobalPreferenceSystem().registerPreference( "TextureScrollbar", - makeBoolStringImportCallback( TextureBrowserImportShowScrollbarCaller( g_TextureBrowser ) ), - BoolExportStringCaller( GlobalTextureBrowser().m_showTextureScrollbar ) - ); - GlobalPreferenceSystem().registerPreference( "ShowShaders", BoolImportStringCaller( GlobalTextureBrowser().m_showShaders ), BoolExportStringCaller( GlobalTextureBrowser().m_showShaders ) ); - GlobalPreferenceSystem().registerPreference( "ShowShaderlistOnly", BoolImportStringCaller( g_TextureBrowser_shaderlistOnly ), BoolExportStringCaller( g_TextureBrowser_shaderlistOnly ) ); - GlobalPreferenceSystem().registerPreference( "FixedSize", BoolImportStringCaller( g_TextureBrowser_fixedSize ), BoolExportStringCaller( g_TextureBrowser_fixedSize ) ); - GlobalPreferenceSystem().registerPreference( "FilterMissing", BoolImportStringCaller( g_TextureBrowser_filterMissing ), BoolExportStringCaller( g_TextureBrowser_filterMissing ) ); - GlobalPreferenceSystem().registerPreference( "EnableAlpha", BoolImportStringCaller( g_TextureBrowser_enableAlpha ), BoolExportStringCaller( g_TextureBrowser_enableAlpha ) ); - GlobalPreferenceSystem().registerPreference( "LoadShaders", IntImportStringCaller( reinterpret_cast( GlobalTextureBrowser().m_startupShaders ) ), IntExportStringCaller( reinterpret_cast( GlobalTextureBrowser().m_startupShaders ) ) ); - GlobalPreferenceSystem().registerPreference( "WheelMouseInc", SizeImportStringCaller( GlobalTextureBrowser().m_mouseWheelScrollIncrement ), SizeExportStringCaller( GlobalTextureBrowser().m_mouseWheelScrollIncrement ) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors0", Vector3ImportStringCaller( GlobalTextureBrowser().color_textureback ), Vector3ExportStringCaller( GlobalTextureBrowser().color_textureback ) ); + GlobalPreferenceSystem().registerPreference( "TextureScale", make_property_string(g_TextureBrowser) ); + GlobalPreferenceSystem().registerPreference( "UniformTextureSize", make_property_string(g_TextureBrowser) ); + GlobalPreferenceSystem().registerPreference( "TextureScrollbar", make_property_string(GlobalTextureBrowser())); + GlobalPreferenceSystem().registerPreference( "ShowShaders", make_property_string( GlobalTextureBrowser().m_showShaders ) ); + GlobalPreferenceSystem().registerPreference( "ShowShaderlistOnly", make_property_string( g_TextureBrowser_shaderlistOnly ) ); + GlobalPreferenceSystem().registerPreference( "FixedSize", make_property_string( g_TextureBrowser_fixedSize ) ); + GlobalPreferenceSystem().registerPreference( "FilterMissing", make_property_string( g_TextureBrowser_filterMissing ) ); + GlobalPreferenceSystem().registerPreference( "EnableAlpha", make_property_string( g_TextureBrowser_enableAlpha ) ); + GlobalPreferenceSystem().registerPreference( "LoadShaders", make_property_string( reinterpret_cast( GlobalTextureBrowser().m_startupShaders ) ) ); + GlobalPreferenceSystem().registerPreference( "WheelMouseInc", make_property_string( GlobalTextureBrowser().m_mouseWheelScrollIncrement ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors0", make_property_string( GlobalTextureBrowser().color_textureback ) ); g_TextureBrowser.shader = texdef_name_default(); diff --git a/radiant/texwindow.h b/radiant/texwindow.h index 31cd4d41..2d5125e4 100644 --- a/radiant/texwindow.h +++ b/radiant/texwindow.h @@ -23,6 +23,7 @@ #define INCLUDED_TEXWINDOW_H #include +#include "property.h" #include "math/vector.h" #include "generic/callback.h" #include "signal/signalfwd.h" @@ -44,8 +45,8 @@ void TextureBrowser_Construct(); void TextureBrowser_Destroy(); extern ui::Widget g_page_textures; -void TextureBrowser_exportTitle( const ImportExportCallback::Import_t& importer ); -typedef FreeCaller::Import_t&), TextureBrowser_exportTitle> TextureBrowserExportTitleCaller; +void TextureBrowser_exportTitle( const Callback & importer ); +typedef FreeCaller &), 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 b5507c5c..fb741abd 100644 --- a/radiant/undo.cpp +++ b/radiant/undo.cpp @@ -377,29 +377,29 @@ void trackersRedo() const { void UndoLevels_importString( RadiantUndoSystem& undo, const char* value ){ int levels; - Int_importString( levels, value ); + PropertyImpl::Import( levels, value ); undo.setLevels( levels ); } typedef ReferenceCaller UndoLevelsImportStringCaller; -void UndoLevels_exportString( const RadiantUndoSystem& undo, const ImportExportCallback::Import_t& importer ){ - Int_exportString( static_cast( undo.getLevels() ), importer ); +void UndoLevels_exportString( const RadiantUndoSystem& undo, const Callback & importer ){ + PropertyImpl::Export( static_cast( undo.getLevels() ), importer ); } -typedef ConstReferenceCaller::Import_t&), UndoLevels_exportString> UndoLevelsExportStringCaller; +typedef ConstReferenceCaller &), UndoLevels_exportString> UndoLevelsExportStringCaller; #include "generic/callback.h" -void UndoLevelsImport( RadiantUndoSystem& self, int value ){ - self.setLevels( value ); -} -typedef ReferenceCaller UndoLevelsImportCaller; -void UndoLevelsExport( const RadiantUndoSystem& self, const ImportExportCallback::Import_t& importCallback ){ - importCallback( static_cast( self.getLevels() ) ); -} -typedef ConstReferenceCaller::Import_t&), UndoLevelsExport> UndoLevelsExportCaller; +struct UndoLevels { + static void Export(const RadiantUndoSystem &self, const Callback &returnz) { + returnz(static_cast(self.getLevels())); + } + static void Import(RadiantUndoSystem &self, int value) { + self.setLevels(value); + } +}; void Undo_constructPreferences( RadiantUndoSystem& undo, PreferencesPage& page ){ - page.appendSpinner( "Undo Queue Size", 64, 0, 1024, {ImportExportCallback::Import_t( UndoLevelsImportCaller( undo ) ), ImportExportCallback::Export_t( UndoLevelsExportCaller( undo ) )} ); + page.appendSpinner("Undo Queue Size", 64, 0, 1024, make_property(undo)); } void Undo_constructPage( RadiantUndoSystem& undo, PreferenceGroup& group ){ PreferencesPage page( group.createPage( "Undo", "Undo Queue Settings" ) ); @@ -421,7 +421,7 @@ typedef UndoSystem Type; STRING_CONSTANT( Name, "*" ); UndoSystemAPI(){ - GlobalPreferenceSystem().registerPreference( "UndoLevels", makeIntStringImportCallback( UndoLevelsImportCaller( m_undosystem ) ), makeIntStringExportCallback( UndoLevelsExportCaller( m_undosystem ) ) ); + GlobalPreferenceSystem().registerPreference("UndoLevels", make_property_string(m_undosystem)); Undo_registerPreferencesPage( m_undosystem ); } diff --git a/radiant/watchbsp.cpp b/radiant/watchbsp.cpp index d5f6eb7c..8cc81fb1 100644 --- a/radiant/watchbsp.cpp +++ b/radiant/watchbsp.cpp @@ -201,10 +201,10 @@ void BuildMonitor_Construct(){ g_WatchBSP_Enabled = !string_equal( g_pGameDescription->getKeyValue( "no_bsp_monitor" ), "1" ); - GlobalPreferenceSystem().registerPreference( "WatchBSP", BoolImportStringCaller( g_WatchBSP_Enabled ), BoolExportStringCaller( g_WatchBSP_Enabled ) ); - GlobalPreferenceSystem().registerPreference( "RunQuake2Run", BoolImportStringCaller( g_WatchBSP_RunQuake ), BoolExportStringCaller( g_WatchBSP_RunQuake ) ); - GlobalPreferenceSystem().registerPreference( "LeakStop", BoolImportStringCaller( g_WatchBSP_LeakStop ), BoolExportStringCaller( g_WatchBSP_LeakStop ) ); - GlobalPreferenceSystem().registerPreference( "SleepMode", BoolImportStringCaller( g_WatchBSP_DoSleep ), BoolExportStringCaller( g_WatchBSP_DoSleep ) ); + GlobalPreferenceSystem().registerPreference( "WatchBSP", make_property_string( g_WatchBSP_Enabled ) ); + GlobalPreferenceSystem().registerPreference( "RunQuake2Run", make_property_string( g_WatchBSP_RunQuake ) ); + GlobalPreferenceSystem().registerPreference( "LeakStop", make_property_string( g_WatchBSP_LeakStop ) ); + GlobalPreferenceSystem().registerPreference( "SleepMode", make_property_string( g_WatchBSP_DoSleep ) ); Build_registerPreferencesPage(); } diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 7897df07..582d7105 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -2587,97 +2587,97 @@ void ShowNamesToggle(){ XY_UpdateAllWindows(); } typedef FreeCaller ShowNamesToggleCaller; -void ShowNamesExport( const ImportExportCallback::Import_t& importer ){ +void ShowNamesExport( const Callback & importer ){ importer( GlobalEntityCreator().getShowNames() ); } -typedef FreeCaller::Import_t&), ShowNamesExport> ShowNamesExportCaller; +typedef FreeCaller &), ShowNamesExport> ShowNamesExportCaller; void ShowAnglesToggle(){ GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() ); XY_UpdateAllWindows(); } typedef FreeCaller ShowAnglesToggleCaller; -void ShowAnglesExport( const ImportExportCallback::Import_t& importer ){ +void ShowAnglesExport( const Callback & importer ){ importer( GlobalEntityCreator().getShowAngles() ); } -typedef FreeCaller::Import_t&), ShowAnglesExport> ShowAnglesExportCaller; +typedef FreeCaller &), ShowAnglesExport> ShowAnglesExportCaller; void ShowBlocksToggle(){ g_xywindow_globals_private.show_blocks ^= 1; XY_UpdateAllWindows(); } typedef FreeCaller ShowBlocksToggleCaller; -void ShowBlocksExport( const ImportExportCallback::Import_t& importer ){ +void ShowBlocksExport( const Callback & importer ){ importer( g_xywindow_globals_private.show_blocks ); } -typedef FreeCaller::Import_t&), ShowBlocksExport> ShowBlocksExportCaller; +typedef FreeCaller &), ShowBlocksExport> ShowBlocksExportCaller; void ShowCoordinatesToggle(){ g_xywindow_globals_private.show_coordinates ^= 1; XY_UpdateAllWindows(); } typedef FreeCaller ShowCoordinatesToggleCaller; -void ShowCoordinatesExport( const ImportExportCallback::Import_t& importer ){ +void ShowCoordinatesExport( const Callback & importer ){ importer( g_xywindow_globals_private.show_coordinates ); } -typedef FreeCaller::Import_t&), ShowCoordinatesExport> ShowCoordinatesExportCaller; +typedef FreeCaller &), ShowCoordinatesExport> ShowCoordinatesExportCaller; void ShowOutlineToggle(){ g_xywindow_globals_private.show_outline ^= 1; XY_UpdateAllWindows(); } typedef FreeCaller ShowOutlineToggleCaller; -void ShowOutlineExport( const ImportExportCallback::Import_t& importer ){ +void ShowOutlineExport( const Callback & importer ){ importer( g_xywindow_globals_private.show_outline ); } -typedef FreeCaller::Import_t&), ShowOutlineExport> ShowOutlineExportCaller; +typedef FreeCaller &), ShowOutlineExport> ShowOutlineExportCaller; void ShowAxesToggle(){ g_xywindow_globals_private.show_axis ^= 1; XY_UpdateAllWindows(); } typedef FreeCaller ShowAxesToggleCaller; -void ShowAxesExport( const ImportExportCallback::Import_t& importer ){ +void ShowAxesExport( const Callback & importer ){ importer( g_xywindow_globals_private.show_axis ); } -typedef FreeCaller::Import_t&), ShowAxesExport> ShowAxesExportCaller; +typedef FreeCaller &), ShowAxesExport> ShowAxesExportCaller; void ShowWorkzoneToggle(){ g_xywindow_globals_private.d_show_work ^= 1; XY_UpdateAllWindows(); } typedef FreeCaller ShowWorkzoneToggleCaller; -void ShowWorkzoneExport( const ImportExportCallback::Import_t& importer ){ +void ShowWorkzoneExport( const Callback & importer ){ importer( g_xywindow_globals_private.d_show_work ); } -typedef FreeCaller::Import_t&), ShowWorkzoneExport> ShowWorkzoneExportCaller; +typedef FreeCaller &), ShowWorkzoneExport> ShowWorkzoneExportCaller; ShowNamesExportCaller g_show_names_caller; -ImportExportCallback::Export_t g_show_names_callback( g_show_names_caller ); +Callback &)> g_show_names_callback( g_show_names_caller ); ToggleItem g_show_names( g_show_names_callback ); ShowAnglesExportCaller g_show_angles_caller; -ImportExportCallback::Export_t g_show_angles_callback( g_show_angles_caller ); +Callback &)> g_show_angles_callback( g_show_angles_caller ); ToggleItem g_show_angles( g_show_angles_callback ); ShowBlocksExportCaller g_show_blocks_caller; -ImportExportCallback::Export_t g_show_blocks_callback( g_show_blocks_caller ); +Callback &)> g_show_blocks_callback( g_show_blocks_caller ); ToggleItem g_show_blocks( g_show_blocks_callback ); ShowCoordinatesExportCaller g_show_coordinates_caller; -ImportExportCallback::Export_t g_show_coordinates_callback( g_show_coordinates_caller ); +Callback &)> g_show_coordinates_callback( g_show_coordinates_caller ); ToggleItem g_show_coordinates( g_show_coordinates_callback ); ShowOutlineExportCaller g_show_outline_caller; -ImportExportCallback::Export_t g_show_outline_callback( g_show_outline_caller ); +Callback &)> g_show_outline_callback( g_show_outline_caller ); ToggleItem g_show_outline( g_show_outline_callback ); ShowAxesExportCaller g_show_axes_caller; -ImportExportCallback::Export_t g_show_axes_callback( g_show_axes_caller ); +Callback &)> g_show_axes_callback( g_show_axes_caller ); ToggleItem g_show_axes( g_show_axes_callback ); ShowWorkzoneExportCaller g_show_workzone_caller; -ImportExportCallback::Export_t g_show_workzone_callback( g_show_workzone_caller ); +Callback &)> g_show_workzone_callback( g_show_workzone_caller ); ToggleItem g_show_workzone( g_show_workzone_callback ); void XYShow_registerCommands(){ @@ -2727,16 +2727,15 @@ void Clipper_registerPreferencesPage(){ #include "stringio.h" +struct ToggleShown_Bool { + static void Export(const ToggleShown &self, const Callback &returnz) { + returnz(self.active()); + } - -void ToggleShown_importBool( ToggleShown& self, bool value ){ - self.set( value ); -} -typedef ReferenceCaller ToggleShownImportBoolCaller; -void ToggleShown_exportBool( const ToggleShown& self, const ImportExportCallback::Import_t& importer ){ - importer( self.active() ); -} -typedef ConstReferenceCaller::Import_t&), ToggleShown_exportBool> ToggleShownExportBoolCaller; + static void Import(ToggleShown &self, bool value) { + self.set(value); + } +}; void XYWindow_Construct(){ @@ -2756,32 +2755,32 @@ void XYWindow_Construct(){ GlobalCommands_insert( "Zoom100", makeCallbackF(XY_Zoom100) ); GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Focus), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); - GlobalPreferenceSystem().registerPreference( "ClipCaulk", BoolImportStringCaller( g_clip_useCaulk ), BoolExportStringCaller( g_clip_useCaulk ) ); - - GlobalPreferenceSystem().registerPreference( "NewRightClick", BoolImportStringCaller( g_xywindow_globals.m_bRightClick ), BoolExportStringCaller( g_xywindow_globals.m_bRightClick ) ); - GlobalPreferenceSystem().registerPreference( "ChaseMouse", BoolImportStringCaller( g_xywindow_globals_private.m_bChaseMouse ), BoolExportStringCaller( g_xywindow_globals_private.m_bChaseMouse ) ); - GlobalPreferenceSystem().registerPreference( "SizePainting", BoolImportStringCaller( g_xywindow_globals_private.m_bSizePaint ), BoolExportStringCaller( g_xywindow_globals_private.m_bSizePaint ) ); - GlobalPreferenceSystem().registerPreference( "NoStipple", BoolImportStringCaller( g_xywindow_globals.m_bNoStipple ), BoolExportStringCaller( g_xywindow_globals.m_bNoStipple ) ); - GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", BoolImportStringCaller( g_xywindow_globals_private.show_coordinates ), BoolExportStringCaller( g_xywindow_globals_private.show_coordinates ) ); - GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", BoolImportStringCaller( g_xywindow_globals_private.show_outline ), BoolExportStringCaller( g_xywindow_globals_private.show_outline ) ); - GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", BoolImportStringCaller( g_xywindow_globals_private.show_axis ), BoolExportStringCaller( g_xywindow_globals_private.show_axis ) ); - GlobalPreferenceSystem().registerPreference( "CamXYUpdate", BoolImportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ), BoolExportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ) ); - GlobalPreferenceSystem().registerPreference( "ShowWorkzone", BoolImportStringCaller( g_xywindow_globals_private.d_show_work ), BoolExportStringCaller( g_xywindow_globals_private.d_show_work ) ); - - GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", Vector3ImportStringCaller( g_xywindow_globals.AxisColorX ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorX ) ); - GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", Vector3ImportStringCaller( g_xywindow_globals.AxisColorY ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorY ) ); - GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", Vector3ImportStringCaller( g_xywindow_globals.AxisColorZ ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorZ ) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors1", Vector3ImportStringCaller( g_xywindow_globals.color_gridback ), Vector3ExportStringCaller( g_xywindow_globals.color_gridback ) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors2", Vector3ImportStringCaller( g_xywindow_globals.color_gridminor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridminor ) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors3", Vector3ImportStringCaller( g_xywindow_globals.color_gridmajor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridmajor ) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors6", Vector3ImportStringCaller( g_xywindow_globals.color_gridblock ), Vector3ExportStringCaller( g_xywindow_globals.color_gridblock ) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors7", Vector3ImportStringCaller( g_xywindow_globals.color_gridtext ), Vector3ExportStringCaller( g_xywindow_globals.color_gridtext ) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors8", Vector3ImportStringCaller( g_xywindow_globals.color_brushes ), Vector3ExportStringCaller( g_xywindow_globals.color_brushes ) ); - GlobalPreferenceSystem().registerPreference( "SI_Colors14", Vector3ImportStringCaller( g_xywindow_globals.color_gridmajor_alt ), Vector3ExportStringCaller( g_xywindow_globals.color_gridmajor_alt ) ); - - - GlobalPreferenceSystem().registerPreference( "XZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_xz_front_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_xz_front_shown ) ) ); - GlobalPreferenceSystem().registerPreference( "YZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_yz_side_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_yz_side_shown ) ) ); + GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) ); + + GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) ); + GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) ); + GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) ); + GlobalPreferenceSystem().registerPreference( "NoStipple", make_property_string( g_xywindow_globals.m_bNoStipple ) ); + GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", make_property_string( g_xywindow_globals_private.show_coordinates ) ); + GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", make_property_string( g_xywindow_globals_private.show_outline ) ); + GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", make_property_string( g_xywindow_globals_private.show_axis ) ); + GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) ); + GlobalPreferenceSystem().registerPreference( "ShowWorkzone", make_property_string( g_xywindow_globals_private.d_show_work ) ); + + GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", make_property_string( g_xywindow_globals.AxisColorX ) ); + GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", make_property_string( g_xywindow_globals.AxisColorY ) ); + GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", make_property_string( g_xywindow_globals.AxisColorZ ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors1", make_property_string( g_xywindow_globals.color_gridback ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors2", make_property_string( g_xywindow_globals.color_gridminor ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors3", make_property_string( g_xywindow_globals.color_gridmajor ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors6", make_property_string( g_xywindow_globals.color_gridblock ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors7", make_property_string( g_xywindow_globals.color_gridtext ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors8", make_property_string( g_xywindow_globals.color_brushes ) ); + GlobalPreferenceSystem().registerPreference( "SI_Colors14", make_property_string( g_xywindow_globals.color_gridmajor_alt ) ); + + + GlobalPreferenceSystem().registerPreference( "XZVIS", make_property_string( g_xz_front_shown ) ); + GlobalPreferenceSystem().registerPreference( "YZVIS", make_property_string( g_yz_side_shown ) ); Orthographic_registerPreferencesPage(); Clipper_registerPreferencesPage(); -- 2.39.2