From 6affce058142d8e21342b850594a5307bff76958 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 8 Nov 2010 05:08:24 +0000 Subject: [PATCH] Make OPT_GET return a const OptionValue* and add OPT_SUB/OPT_UNSUB for subscribing to option changes Originally committed to SVN as r4834. --- aegisub/src/base_grid.cpp | 30 +++++++++++++++--------------- aegisub/src/frame_main.cpp | 2 +- aegisub/src/main.h | 9 ++++++++- aegisub/src/preferences_base.cpp | 6 +++--- aegisub/src/subs_edit_ctrl.cpp | 26 +++++++++++++------------- aegisub/src/video_context.cpp | 18 +++++++++--------- aegisub/src/video_context.h | 2 +- aegisub/src/video_display.h | 2 +- aegisub/src/video_slider.cpp | 4 ++-- 9 files changed, 53 insertions(+), 46 deletions(-) diff --git a/aegisub/src/base_grid.cpp b/aegisub/src/base_grid.cpp index 62827b8a3..748908c6e 100644 --- a/aegisub/src/base_grid.cpp +++ b/aegisub/src/base_grid.cpp @@ -107,23 +107,23 @@ BaseGrid::BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wx UpdateStyle(); agi::OptionValue::ChangeListener UpdateStyle(std::tr1::bind(&BaseGrid::UpdateStyle, this)); - OPT_GET("Subtitle/Grid/Font Face")->Subscribe(this, UpdateStyle); - OPT_GET("Subtitle/Grid/Font Size")->Subscribe(this, UpdateStyle); + OPT_SUB("Subtitle/Grid/Font Face", this, UpdateStyle); + OPT_SUB("Subtitle/Grid/Font Size", this, UpdateStyle); agi::OptionValue::ChangeListener Refresh(std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL)); - OPT_GET("Colour/Subtitle Grid/Active Border")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Background/Background")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Background/Comment")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Background/Inframe")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Background/Selected Comment")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Background/Selection")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Collision")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Header")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Left Column")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Lines")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Selection")->Subscribe(this, Refresh); - OPT_GET("Colour/Subtitle Grid/Standard")->Subscribe(this, Refresh); - OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->Subscribe(this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Active Border", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Background/Background", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Background/Comment", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Background/Inframe", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Background/Selected Comment", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Background/Selection", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Collision", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Header", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Left Column", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Lines", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Selection", this, Refresh); + OPT_SUB("Colour/Subtitle Grid/Standard", this, Refresh); + OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", this, Refresh); } diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index 23e648223..69b83088f 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -167,7 +167,7 @@ FrameMain::FrameMain (wxArrayString args) if (time > 0) { AutoSave.Start(time*1000); } - OPT_GET("App/Auto/Save Every Seconds")->Subscribe(this, std::tr1::bind(autosave_timer_changed, std::tr1::ref(AutoSave), std::tr1::placeholders::_1)); + OPT_SUB("App/Auto/Save Every Seconds", this, std::tr1::bind(autosave_timer_changed, std::tr1::ref(AutoSave), std::tr1::placeholders::_1)); // Set accelerator keys StartupLog(_T("Install hotkeys")); diff --git a/aegisub/src/main.h b/aegisub/src/main.h index f9d14ee16..4f1816a0c 100644 --- a/aegisub/src/main.h +++ b/aegisub/src/main.h @@ -69,11 +69,18 @@ namespace config { namespace Automation4 { class AutoloadScriptManager; } /// Macro to get OptionValue object. -#define OPT_GET(x) config::opt->Get(x) +#define OPT_GET(x) const_cast(config::opt->Get(x)) /// Macro to set OptionValue object. #define OPT_SET(x) config::opt->Get(x) +/// Macro to subscribe to OptionValue changes +#define OPT_SUB(x, ...) config::opt->Get(x)->Subscribe(__VA_ARGS__) + +/// Macro to unsubscribe to OptionValue changes +#define OPT_UNSUB(x, ...) config::opt->Get(x)->Unsubscribe(__VA_ARGS__) + + /// DOCME /// @class AegisubApp /// @brief DOCME diff --git a/aegisub/src/preferences_base.cpp b/aegisub/src/preferences_base.cpp index 53e9035ac..75ffff755 100644 --- a/aegisub/src/preferences_base.cpp +++ b/aegisub/src/preferences_base.cpp @@ -108,7 +108,7 @@ void OptionPage::CellSkip(wxFlexGridSizer *&flex) { void OptionPage::OptionAdd(wxFlexGridSizer *&flex, const wxString &name, const char *opt_name, double min, double max, double inc) { - agi::OptionValue *opt = OPT_GET(opt_name); + const agi::OptionValue *opt = OPT_GET(opt_name); int type = opt->GetType(); @@ -162,7 +162,7 @@ void OptionPage::OptionAdd(wxFlexGridSizer *&flex, const wxString &name, const c void OptionPage::OptionChoice(wxFlexGridSizer *&flex, const wxString &name, const wxArrayString &choices, const char *opt_name) { - agi::OptionValue *opt = OPT_GET(opt_name); + const agi::OptionValue *opt = OPT_GET(opt_name); flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL); wxComboBox *cb = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, choices, wxCB_READONLY | wxCB_DROPDOWN); @@ -197,7 +197,7 @@ wxFlexGridSizer* OptionPage::PageSizer(wxString name) { void OptionPage::OptionBrowse(wxFlexGridSizer *&flex, const wxString &name, BrowseType browse_type, const char *opt_name) { - agi::OptionValue *opt = OPT_GET(opt_name); + const agi::OptionValue *opt = OPT_GET(opt_name); if (opt->GetType() != agi::OptionValue::Type_String) throw PreferenceIncorrectType("Option must be agi::OptionValue::Type_String for BrowseButton."); diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index 4595549fc..c05a2629d 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -183,21 +183,21 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, S agi::OptionValue::ChangeListener SetStyles = bind(&SubsTextEditCtrl::SetStyles, this); - OPT_GET("Subtitle/Edit Box/Font Face")->Subscribe(this, SetStyles); - OPT_GET("Subtitle/Edit Box/Font Size")->Subscribe(this, SetStyles); - OPT_GET("Colour/Subtitle/Syntax/Normal")->Subscribe(this, SetStyles); - OPT_GET("Colour/Subtitle/Syntax/Brackets")->Subscribe(this, SetStyles); - OPT_GET("Colour/Subtitle/Syntax/Slashes")->Subscribe(this, SetStyles); - OPT_GET("Colour/Subtitle/Syntax/Highlight Tags")->Subscribe(this, SetStyles); - OPT_GET("Colour/Subtitle/Syntax/Error")->Subscribe(this, SetStyles); - OPT_GET("Colour/Subtitle/Syntax/Background/Error")->Subscribe(this, SetStyles); - OPT_GET("Colour/Subtitle/Syntax/Parameters")->Subscribe(this, SetStyles); - OPT_GET("Colour/Subtitle/Syntax/Line Break")->Subscribe(this, SetStyles); - OPT_GET("Colour/Subtitle/Syntax/Karaoke Template")->Subscribe(this, SetStyles); + OPT_SUB("Subtitle/Edit Box/Font Face", this, SetStyles); + OPT_SUB("Subtitle/Edit Box/Font Size", this, SetStyles); + OPT_SUB("Colour/Subtitle/Syntax/Normal", this, SetStyles); + OPT_SUB("Colour/Subtitle/Syntax/Brackets", this, SetStyles); + OPT_SUB("Colour/Subtitle/Syntax/Slashes", this, SetStyles); + OPT_SUB("Colour/Subtitle/Syntax/Highlight Tags", this, SetStyles); + OPT_SUB("Colour/Subtitle/Syntax/Error", this, SetStyles); + OPT_SUB("Colour/Subtitle/Syntax/Background/Error", this, SetStyles); + OPT_SUB("Colour/Subtitle/Syntax/Parameters", this, SetStyles); + OPT_SUB("Colour/Subtitle/Syntax/Line Break", this, SetStyles); + OPT_SUB("Colour/Subtitle/Syntax/Karaoke Template", this, SetStyles); - OPT_GET("Subtitle/Highlight/Syntax")->Subscribe(this, bind(&SubsTextEditCtrl::UpdateStyle, this, 0, -1)); + OPT_SUB("Subtitle/Highlight/Syntax", this, bind(&SubsTextEditCtrl::UpdateStyle, this, 0, -1)); static wxStyledTextEvent evt; - OPT_GET("App/Call Tips")->Subscribe(this, bind(&SubsTextEditCtrl::UpdateCallTip, this, ref(evt))); + OPT_SUB("App/Call Tips", this, bind(&SubsTextEditCtrl::UpdateCallTip, this, ref(evt))); } diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index 2280481b8..d8b35a4ce 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -110,15 +110,15 @@ VideoContext::VideoContext() Bind(EVT_SUBTITLES_ERROR, &VideoContext::OnSubtitlesError, this); agi::OptionValue::ChangeListener providerChanged(std::tr1::bind(&VideoContext::Reload, this)); - OPT_GET("Subtitle/Provider")->Subscribe(this, providerChanged); - OPT_GET("Video/Provider")->Subscribe(this, providerChanged); + OPT_SUB("Subtitle/Provider", this, providerChanged); + OPT_SUB("Video/Provider", this, providerChanged); // It would be nice to find a way to move these to the individual providers - OPT_GET("Provider/Avisynth/Allow Ancient")->Subscribe(this, providerChanged); - OPT_GET("Provider/Avisynth/Memory Max")->Subscribe(this, providerChanged); + OPT_SUB("Provider/Avisynth/Allow Ancient", this, providerChanged); + OPT_SUB("Provider/Avisynth/Memory Max", this, providerChanged); - OPT_GET("Provider/Video/FFmpegSource/Decoding Threads")->Subscribe(this, providerChanged); - OPT_GET("Provider/Video/FFmpegSource/Unsafe Seeking")->Subscribe(this, providerChanged); + OPT_SUB("Provider/Video/FFmpegSource/Decoding Threads", this, providerChanged); + OPT_SUB("Provider/Video/FFmpegSource/Unsafe Seeking", this, providerChanged); } VideoContext::~VideoContext () { @@ -259,7 +259,7 @@ void VideoContext::UpdateDisplays(bool full, bool seek) { // Update audio display if (audio && audio->loaded && audio->IsShownOnScreen()) { - static agi::OptionValue* opt = OPT_GET("Audio/Display/Draw/Video Position"); + static const agi::OptionValue* opt = OPT_GET("Audio/Display/Draw/Video Position"); if (opt->GetBool()) { audio->UpdateImage(false); } @@ -283,7 +283,7 @@ void VideoContext::JumpToFrame(int n) { UpdateDisplays(false, true); - static agi::OptionValue* highlight = OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame"); + static const agi::OptionValue* highlight = OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame"); if (!isPlaying && highlight->GetBool()) grid->Refresh(false); } @@ -308,7 +308,7 @@ int VideoContext::GetHeight() const { void VideoContext::SaveSnapshot(bool raw) { // Get folder - static agi::OptionValue* ssPath = OPT_GET("Path/Screenshot"); + static const agi::OptionValue* ssPath = OPT_GET("Path/Screenshot"); wxString option = lagi_wxString(ssPath->GetString()); wxFileName videoFile(videoName); wxString basepath; diff --git a/aegisub/src/video_context.h b/aegisub/src/video_context.h index f3318982e..42576862d 100644 --- a/aegisub/src/video_context.h +++ b/aegisub/src/video_context.h @@ -138,7 +138,7 @@ private: wxString ovrTimecodeFile; - agi::OptionValue* playAudioOnStep; + const agi::OptionValue* playAudioOnStep; void OnPlayTimer(wxTimerEvent &event); diff --git a/aegisub/src/video_display.h b/aegisub/src/video_display.h index d72d34c12..8bae13aa4 100644 --- a/aegisub/src/video_display.h +++ b/aegisub/src/video_display.h @@ -64,7 +64,7 @@ struct VideoState { /// @class VideoDisplay /// @brief DOCME class VideoDisplay : public wxGLCanvas { - agi::OptionValue* alwaysShowTools; + const agi::OptionValue* alwaysShowTools; /// The unscaled size of the displayed video wxSize origSize; diff --git a/aegisub/src/video_slider.cpp b/aegisub/src/video_slider.cpp index 3cfe50164..673074bba 100644 --- a/aegisub/src/video_slider.cpp +++ b/aegisub/src/video_slider.cpp @@ -73,11 +73,11 @@ VideoSlider::VideoSlider (wxWindow* parent, wxWindowID id) SetMinSize(wxSize(20, 25)); locked = false; SetRange(0,1); - OPT_GET("Video/Slider/Show Keyframes")->Subscribe(this, std::tr1::bind(&wxWindow::Refresh, this, false, (wxRect*)NULL)); + OPT_SUB("Video/Slider/Show Keyframes", this, std::tr1::bind(&wxWindow::Refresh, this, false, (wxRect*)NULL)); } VideoSlider::~VideoSlider() { - OPT_GET("Video/Slider/Show Keyframes")->Unsubscribe(this); + OPT_UNSUB("Video/Slider/Show Keyframes", this); } /// @brief Set value