Convert OptionValue over to agi::signal
Originally committed to SVN as r4899.
This commit is contained in:
parent
4fc1ff6ad6
commit
13f052317e
11 changed files with 48 additions and 127 deletions
|
@ -287,10 +287,6 @@
|
|||
RelativePath="..\..\libaegisub\common\option.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\libaegisub\common\option_value.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\libaegisub\common\option_visit.cpp"
|
||||
>
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (c) 2010, Niels M Hansen <nielsm@aegisub.org>
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
/// @file option_value.cpp
|
||||
/// @brief Container for holding an actual option value.
|
||||
/// @ingroup libaegisub
|
||||
|
||||
#ifndef LAGI_PRE
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#include "libaegisub/option_value.h"
|
||||
|
||||
namespace agi {
|
||||
|
||||
void OptionValue::NotifyChanged() {
|
||||
for (ChangeListenerSet::const_iterator nfcb = listeners.begin(); nfcb != listeners.end(); ++nfcb) {
|
||||
nfcb->second(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void OptionValue::Subscribe(void *key, ChangeListener listener) {
|
||||
assert(listeners.find(key) == listeners.end());
|
||||
listeners[key] = listener;
|
||||
}
|
||||
|
||||
void OptionValue::Unsubscribe(void *key) {
|
||||
assert(listeners.find(key) != listeners.end());
|
||||
listeners.erase(key);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,22 +18,17 @@
|
|||
/// @brief Container for holding an actual option value.
|
||||
/// @ingroup libaegisub
|
||||
|
||||
#ifndef LAGI_PRE
|
||||
#if !defined(AGI_PRE) && !defined(LAGI_PRE)
|
||||
#include <stdint.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <functional>
|
||||
#else
|
||||
#include <tr1/functional>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <libaegisub/exception.h>
|
||||
#include <libaegisub/colour.h>
|
||||
#include <libaegisub/exception.h>
|
||||
#include <libaegisub/signals.h>
|
||||
|
||||
namespace agi {
|
||||
|
||||
|
@ -49,15 +44,9 @@ class ConfigVisitor;
|
|||
/// @class OptionValue
|
||||
/// Holds an actual option.
|
||||
class OptionValue {
|
||||
public:
|
||||
typedef std::tr1::function<void (const OptionValue &)> ChangeListener;
|
||||
|
||||
private:
|
||||
typedef std::map<void*, ChangeListener> ChangeListenerSet;
|
||||
ChangeListenerSet listeners;
|
||||
|
||||
agi::signal::Signal<OptionValue const&> ValueChanged;
|
||||
protected:
|
||||
void NotifyChanged();
|
||||
void NotifyChanged() { ValueChanged(*this); }
|
||||
|
||||
OptionValueErrorInvalidType TypeError(std::string type, std::string op = " retrieve ") const {
|
||||
return OptionValueErrorInvalidType("Attempt to" + op + type + " with non-" + type + " value " + GetName());
|
||||
|
@ -129,8 +118,7 @@ public:
|
|||
virtual void GetDefaultListBool(std::vector<bool> &out) const { throw ListTypeError("string"); }
|
||||
|
||||
|
||||
void Subscribe(void *key, ChangeListener listener);
|
||||
void Unsubscribe(void *key);
|
||||
DEFINE_SIGNAL_ADDERS(ValueChanged, Subscribe);
|
||||
};
|
||||
|
||||
#define CONFIG_OPTIONVALUE(type_name, type) \
|
||||
|
|
|
@ -106,24 +106,23 @@ BaseGrid::BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wx
|
|||
// Set style
|
||||
UpdateStyle();
|
||||
|
||||
agi::OptionValue::ChangeListener UpdateStyle(std::tr1::bind(&BaseGrid::UpdateStyle, this));
|
||||
OPT_SUB("Subtitle/Grid/Font Face", this, UpdateStyle);
|
||||
OPT_SUB("Subtitle/Grid/Font Size", this, UpdateStyle);
|
||||
OPT_SUB("Subtitle/Grid/Font Face", &BaseGrid::UpdateStyle, this);
|
||||
OPT_SUB("Subtitle/Grid/Font Size", &BaseGrid::UpdateStyle, this);
|
||||
|
||||
agi::OptionValue::ChangeListener Refresh(std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL));
|
||||
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);
|
||||
std::tr1::function<void (agi::OptionValue const&)> Refresh(std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL));
|
||||
OPT_SUB("Colour/Subtitle Grid/Active Border", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Background/Background", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Background/Comment", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Background/Inframe", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Background/Selected Comment", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Background/Selection", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Collision", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Header", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Left Column", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Lines", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Selection", Refresh);
|
||||
OPT_SUB("Colour/Subtitle Grid/Standard", Refresh);
|
||||
OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", Refresh);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
#define StartupLog(a)
|
||||
#endif
|
||||
|
||||
static void autosave_timer_changed(wxTimer &timer, const agi::OptionValue &opt);
|
||||
static void autosave_timer_changed(wxTimer *timer, const agi::OptionValue &opt);
|
||||
|
||||
FrameMain::FrameMain (wxArrayString args)
|
||||
: wxFrame ((wxFrame*)NULL,-1,_T(""),wxDefaultPosition,wxSize(920,700),wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN)
|
||||
|
@ -167,7 +167,7 @@ FrameMain::FrameMain (wxArrayString args)
|
|||
if (time > 0) {
|
||||
AutoSave.Start(time*1000);
|
||||
}
|
||||
OPT_SUB("App/Auto/Save Every Seconds", this, std::tr1::bind(autosave_timer_changed, std::tr1::ref(AutoSave), std::tr1::placeholders::_1));
|
||||
OPT_SUB("App/Auto/Save Every Seconds", autosave_timer_changed, &AutoSave, agi::signal::_1);
|
||||
|
||||
// Set accelerator keys
|
||||
StartupLog(_T("Install hotkeys"));
|
||||
|
@ -1337,12 +1337,12 @@ bool FrameMain::HasASSDraw() {
|
|||
#endif
|
||||
}
|
||||
|
||||
static void autosave_timer_changed(wxTimer &timer, const agi::OptionValue &opt) {
|
||||
static void autosave_timer_changed(wxTimer *timer, const agi::OptionValue &opt) {
|
||||
int freq = opt.GetInt();
|
||||
if (freq <= 0) {
|
||||
timer.Stop();
|
||||
timer->Stop();
|
||||
}
|
||||
else {
|
||||
timer.Start(freq * 1000);
|
||||
timer->Start(freq * 1000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace config {
|
|||
namespace Automation4 { class AutoloadScriptManager; }
|
||||
|
||||
/// Macro to get OptionValue object.
|
||||
#define OPT_GET(x) const_cast<const agi::OptionValue *>(config::opt->Get(x))
|
||||
#define OPT_GET(x) const_cast<const agi::OptionValue*>(config::opt->Get(x))
|
||||
|
||||
/// Macro to set OptionValue object.
|
||||
#define OPT_SET(x) config::opt->Get(x)
|
||||
|
|
|
@ -181,23 +181,21 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, S
|
|||
|
||||
Bind(wxEVT_STC_STYLENEEDED, &SubsTextEditCtrl::UpdateCallTip, this);
|
||||
|
||||
agi::OptionValue::ChangeListener SetStyles = bind(&SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Subtitle/Edit Box/Font Face", &SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Subtitle/Edit Box/Font Size", &SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Colour/Subtitle/Syntax/Normal", &SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Colour/Subtitle/Syntax/Brackets", &SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Colour/Subtitle/Syntax/Slashes", &SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Colour/Subtitle/Syntax/Highlight Tags", &SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Colour/Subtitle/Syntax/Error", &SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Colour/Subtitle/Syntax/Background/Error", &SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Colour/Subtitle/Syntax/Parameters", &SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Colour/Subtitle/Syntax/Line Break", &SubsTextEditCtrl::SetStyles, this);
|
||||
OPT_SUB("Colour/Subtitle/Syntax/Karaoke Template", &SubsTextEditCtrl::SetStyles, this);
|
||||
|
||||
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_SUB("Subtitle/Highlight/Syntax", this, bind(&SubsTextEditCtrl::UpdateStyle, this, 0, -1));
|
||||
OPT_SUB("Subtitle/Highlight/Syntax", &SubsTextEditCtrl::UpdateStyle, this, 0, -1);
|
||||
static wxStyledTextEvent evt;
|
||||
OPT_SUB("App/Call Tips", this, bind(&SubsTextEditCtrl::UpdateCallTip, this, ref(evt)));
|
||||
OPT_SUB("App/Call Tips", &SubsTextEditCtrl::UpdateCallTip, this, ref(evt));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -109,16 +109,15 @@ VideoContext::VideoContext()
|
|||
Bind(EVT_VIDEO_ERROR, &VideoContext::OnVideoError, this);
|
||||
Bind(EVT_SUBTITLES_ERROR, &VideoContext::OnSubtitlesError, this);
|
||||
|
||||
agi::OptionValue::ChangeListener providerChanged(std::tr1::bind(&VideoContext::Reload, this));
|
||||
OPT_SUB("Subtitle/Provider", this, providerChanged);
|
||||
OPT_SUB("Video/Provider", this, providerChanged);
|
||||
OPT_SUB("Subtitle/Provider", &VideoContext::Reload, this);
|
||||
OPT_SUB("Video/Provider", &VideoContext::Reload, this);
|
||||
|
||||
// It would be nice to find a way to move these to the individual providers
|
||||
OPT_SUB("Provider/Avisynth/Allow Ancient", this, providerChanged);
|
||||
OPT_SUB("Provider/Avisynth/Memory Max", this, providerChanged);
|
||||
OPT_SUB("Provider/Avisynth/Allow Ancient", &VideoContext::Reload, this);
|
||||
OPT_SUB("Provider/Avisynth/Memory Max", &VideoContext::Reload, this);
|
||||
|
||||
OPT_SUB("Provider/Video/FFmpegSource/Decoding Threads", this, providerChanged);
|
||||
OPT_SUB("Provider/Video/FFmpegSource/Unsafe Seeking", this, providerChanged);
|
||||
OPT_SUB("Provider/Video/FFmpegSource/Decoding Threads", &VideoContext::Reload, this);
|
||||
OPT_SUB("Provider/Video/FFmpegSource/Unsafe Seeking", &VideoContext::Reload, this);
|
||||
}
|
||||
|
||||
VideoContext::~VideoContext () {
|
||||
|
@ -126,8 +125,6 @@ VideoContext::~VideoContext () {
|
|||
delete audio->provider;
|
||||
delete audio->player;
|
||||
}
|
||||
// Don't unsubscribe from option change notifications as the options object
|
||||
// might not even exist anymore
|
||||
}
|
||||
|
||||
VideoContext *VideoContext::Get() {
|
||||
|
|
|
@ -76,7 +76,6 @@ class VideoContext : public wxEvtHandler {
|
|||
friend class AudioProvider;
|
||||
friend class KeyFrameFile;
|
||||
|
||||
private:
|
||||
/// DOCME
|
||||
std::list<VideoDisplay*> displayList;
|
||||
|
||||
|
|
|
@ -73,11 +73,10 @@ VideoSlider::VideoSlider (wxWindow* parent, wxWindowID id)
|
|||
SetMinSize(wxSize(20, 25));
|
||||
locked = false;
|
||||
SetRange(0,1);
|
||||
OPT_SUB("Video/Slider/Show Keyframes", this, std::tr1::bind(&wxWindow::Refresh, this, false, (wxRect*)NULL));
|
||||
OPT_SUB("Video/Slider/Show Keyframes", &wxWindow::Refresh, this, false, (wxRect*)NULL);
|
||||
}
|
||||
|
||||
VideoSlider::~VideoSlider() {
|
||||
OPT_UNSUB("Video/Slider/Show Keyframes", this);
|
||||
}
|
||||
|
||||
/// @brief Set value
|
||||
|
|
|
@ -34,23 +34,13 @@
|
|||
/// @ingroup custom_control
|
||||
///
|
||||
|
||||
|
||||
|
||||
|
||||
////////////
|
||||
// Includes
|
||||
#ifndef AGI_PRE
|
||||
#include <wx/window.h>
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////
|
||||
// Class prototypes
|
||||
class VideoDisplay;
|
||||
class SubtitlesGrid;
|
||||
|
||||
|
||||
|
||||
/// DOCME
|
||||
/// @class VideoSlider
|
||||
/// @brief DOCME
|
||||
|
|
Loading…
Reference in a new issue