Factor out the idea of a pen bound to options to a utility class

Originally committed to SVN as r5759.
This commit is contained in:
Thomas Goyne 2011-10-19 04:19:01 +00:00
parent 62f37772a3
commit d4e17dde2e
10 changed files with 149 additions and 48 deletions

View file

@ -887,6 +887,14 @@
RelativePath="..\..\src\mythes.hxx"
>
</File>
<File
RelativePath="..\..\src\pen.cpp"
>
</File>
<File
RelativePath="..\..\src\pen.h"
>
</File>
<File
RelativePath="..\..\src\persist_location.cpp"
>

View file

@ -153,6 +153,7 @@
<ClInclude Include="$(SrcDir)mkv_wrap.h" />
<ClInclude Include="$(SrcDir)mythes.hxx" />
<ClInclude Include="$(SrcDir)persist_location.h" />
<ClInclude Include="$(SrcDir)pen.h" />
<ClInclude Include="$(SrcDir)plugin_manager.h" />
<ClInclude Include="$(SrcDir)preferences.h" />
<ClInclude Include="$(SrcDir)preferences_base.h" />
@ -344,6 +345,7 @@
<ClCompile Include="$(SrcDir)menu.cpp" />
<ClCompile Include="$(SrcDir)mkv_wrap.cpp" />
<ClCompile Include="$(SrcDir)mythes.cxx" />
<ClCompile Include="$(SrcDir)pen.cpp" />
<ClCompile Include="$(SrcDir)persist_location.cpp" />
<ClCompile Include="$(SrcDir)plugin_manager.cpp" />
<ClCompile Include="$(SrcDir)preferences.cpp" />

View file

@ -645,6 +645,9 @@
<ClInclude Include="$(SrcDir)preferences.h">
<Filter>Preferences</Filter>
</ClInclude>
<ClInclude Include="$(SrcDir)pen.h">
<Filter>Utilities\UI utilities</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(SrcDir)ass_dialogue.cpp">
@ -1193,6 +1196,9 @@
<ClCompile Include="$(SrcDir)command\video.cpp">
<Filter>Commands</Filter>
</ClCompile>
<ClCompile Include="$(SrcDir)pen.cpp">
<Filter>Utilities\UI utilities</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="$(SrcDir)res.rc">

View file

@ -198,6 +198,7 @@ SRC += \
md5.c \
mkv_wrap.cpp \
mythes.cxx \
pen.cpp \
persist_location.cpp \
plugin_manager.cpp \
preferences.cpp \

View file

@ -53,6 +53,7 @@
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "include/aegisub/context.h"
#include "pen.h"
#include "main.h"
#include "selection_controller.h"
#include "standard_paths.h"
@ -60,25 +61,18 @@
class AudioMarkerKeyframe : public AudioMarker {
int64_t position;
static wxPen style;
Pen *style;
public:
AudioMarkerKeyframe(int64_t position) : position(position) { }
AudioMarkerKeyframe(Pen *style, int64_t position) : style(style), position(position) { }
int64_t GetPosition() const { return position; }
FeetStyle GetFeet() const { return Feet_None; }
bool CanSnap() const { return true; }
wxPen GetStyle() const
{
if (!style.IsOk())
/// @todo Make this colour configurable
style = wxPen(wxColour(255,0,255), 1);
return style;
}
wxPen GetStyle() const { return *style; }
bool operator < (const AudioMarkerKeyframe &other) const { return position < other.position; }
operator int64_t() const { return position; }
};
bool operator < (int64_t a, const AudioMarkerKeyframe &b) { return a < b.GetPosition(); }
bool operator < (const AudioMarkerKeyframe &a, int64_t b) { return a.GetPosition() < b; }
wxPen AudioMarkerKeyframe::style;
class AudioMarkerProviderKeyframes : public AudioMarkerProvider {
VideoContext *vc;
@ -90,6 +84,8 @@ class AudioMarkerProviderKeyframes : public AudioMarkerProvider {
std::vector<AudioMarkerKeyframe> keyframe_samples;
AudioController *controller;
Pen style;
void Update()
{
std::vector<int> const& keyframes = vc->GetKeyFrames();
@ -110,7 +106,7 @@ class AudioMarkerProviderKeyframes : public AudioMarkerProvider {
keyframe_samples.reserve(keyframes.size());
for (size_t i = 0; i < keyframes.size(); ++i)
{
keyframe_samples.push_back(AudioMarkerKeyframe(
keyframe_samples.push_back(AudioMarkerKeyframe(&style,
controller->SamplesFromMilliseconds(timecodes.TimeAtFrame(keyframes[i]))));
}
AnnounceMarkerMoved();
@ -123,6 +119,7 @@ public:
, audio_open_slot(controller->AddAudioOpenListener(&AudioMarkerProviderKeyframes::Update, this))
, timecode_slot(vc->AddTimecodesListener(&AudioMarkerProviderKeyframes::Update, this))
, controller(controller)
, style("Colour/Audio Display/Keyframe")
{
Update();
}
@ -142,21 +139,14 @@ public:
};
class VideoPositionMarker : public AudioMarker {
agi::signal::Connection colour_changed;
int64_t position;
wxPen style;
Pen style;
void OnColourChanged(agi::OptionValue const& opt)
{
style = wxPen(lagi_wxColour(opt.GetColour()), 1);
}
public:
VideoPositionMarker()
: colour_changed(OPT_SUB("Colour/Audio Display/Play Cursor", &VideoPositionMarker::OnColourChanged, this))
: style("Colour/Audio Display/Play Cursor")
, position(-1)
{
OnColourChanged(*OPT_GET("Colour/Audio Display/Play Cursor"));
}
void SetPosition(int64_t new_pos)

View file

@ -46,6 +46,7 @@
#include "audio_timing.h"
#include "include/aegisub/context.h"
#include "main.h"
#include "pen.h"
#include "selection_controller.h"
#include "utils.h"
@ -66,6 +67,12 @@ class AudioMarkerDialogueTiming : public AudioMarker {
/// Foot style for the marker
FeetStyle feet;
/// Draw style for the left marker
Pen style_left;
/// Draw style for the right marker
Pen style_right;
public:
// AudioMarker interface
int64_t GetPosition() const { return position; }
@ -198,9 +205,6 @@ void AudioMarkerDialogueTiming::SetPosition(int64_t new_position)
if (other)
{
wxPen style_left(wxColour(OPT_GET("Colour/Audio Display/Line boundary Start")->GetColour()), 2);
wxPen style_right(wxColour(OPT_GET("Colour/Audio Display/Line boundary End")->GetColour()), 2);
if (position < other->position)
{
feet = Feet_Right;
@ -224,6 +228,8 @@ AudioMarkerDialogueTiming::AudioMarkerDialogueTiming()
, position(0)
, style(*wxTRANSPARENT_PEN)
, feet(Feet_None)
, style_left("Colour/Audio Display/Line boundary Start", "Audio/Line Boundaries Thickness")
, style_right("Colour/Audio Display/Line boundary End", "Audio/Line Boundaries Thickness")
{
// Nothing more to do
}

View file

@ -31,6 +31,7 @@
#include "audio_timing.h"
#include "include/aegisub/context.h"
#include "main.h"
#include "pen.h"
#include "utils.h"
#ifndef AGI_PRE
@ -41,7 +42,7 @@
/// @brief AudioMarker implementation for AudioTimingControllerKaraoke
class KaraokeMarker : public AudioMarker {
int64_t position;
wxPen *pen;
Pen *pen;
FeetStyle style;
public:
@ -52,7 +53,7 @@ public:
void Move(int64_t new_pos) { position = new_pos; }
KaraokeMarker(int64_t position, wxPen *pen, FeetStyle style)
KaraokeMarker(int64_t position, Pen *pen, FeetStyle style)
: position(position)
, pen(pen)
, style(style)
@ -82,11 +83,11 @@ class AudioTimingControllerKaraoke : public AudioTimingController {
size_t cur_syl; ///< Index of currently selected syllable in the line
/// Pen used for the mid-syllable markers
wxPen separator_pen;
Pen separator_pen;
/// Pen used for the start-of-line marker
wxPen start_pen;
Pen start_pen;
/// Pen used for the end-of-line marker
wxPen end_pen;
Pen end_pen;
/// Immobile marker for the beginning of the line
KaraokeMarker start_marker;
@ -105,9 +106,6 @@ class AudioTimingControllerKaraoke : public AudioTimingController {
void OnAutoCommitChange(agi::OptionValue const& opt);
void OnAutoNextChange(agi::OptionValue const& opt);
/// Reload all style options from the user preferences
void RegenStyles();
int64_t ToMS(int64_t samples) const { return c->audioController->MillisecondsFromSamples(samples); }
int64_t ToSamples(int64_t ms) const { return c->audioController->SamplesFromMilliseconds(ms); }
@ -144,6 +142,9 @@ AudioTimingControllerKaraoke::AudioTimingControllerKaraoke(agi::Context *c, AssK
, active_line(c->selectionController->GetActiveLine())
, kara(kara)
, cur_syl(0)
, separator_pen("Colour/Audio Display/Syllable Boundaries", "Audio/Line Boundaries Thickness", wxPENSTYLE_DOT)
, start_pen("Colour/Audio Display/Line boundary Start", "Audio/Line Boundaries Thickness")
, end_pen("Colour/Audio Display/Line boundary End", "Audio/Line Boundaries Thickness")
, start_marker(ToSamples(active_line->Start.GetMS()), &start_pen, AudioMarker::Feet_Right)
, end_marker(ToSamples(active_line->End.GetMS()), &end_pen, AudioMarker::Feet_Left)
, auto_commit(OPT_GET("Audio/Auto/Commit")->GetBool())
@ -153,23 +154,11 @@ AudioTimingControllerKaraoke::AudioTimingControllerKaraoke(agi::Context *c, AssK
slots.push_back(kara->AddSyllablesChangedListener(&AudioTimingControllerKaraoke::Revert, this));
slots.push_back(OPT_SUB("Audio/Auto/Commit", &AudioTimingControllerKaraoke::OnAutoCommitChange, this));
slots.push_back(OPT_SUB("Audio/Next Line on Commit", &AudioTimingControllerKaraoke::OnAutoNextChange, this));
slots.push_back(OPT_SUB("Audio/Line Boundaries Thickness", &AudioTimingControllerKaraoke::RegenStyles, this));
slots.push_back(OPT_SUB("Colour/Audio Display/Syllable Boundaries", &AudioTimingControllerKaraoke::RegenStyles, this));
slots.push_back(OPT_SUB("Colour/Audio Display/Line boundary Start", &AudioTimingControllerKaraoke::RegenStyles, this));
slots.push_back(OPT_SUB("Colour/Audio Display/Line boundary End", &AudioTimingControllerKaraoke::RegenStyles, this));
RegenStyles();
Revert();
}
void AudioTimingControllerKaraoke::RegenStyles() {
int width = OPT_GET("Audio/Line Boundaries Thickness")->GetInt();
separator_pen = wxPen(wxColour(OPT_GET("Colour/Audio Display/Syllable Boundaries")->GetColour()), 1, wxPENSTYLE_DOT);
start_pen = wxPen(wxColour(OPT_GET("Colour/Audio Display/Line boundary Start")->GetColour()), width);
end_pen = wxPen(wxColour(OPT_GET("Colour/Audio Display/Line boundary End")->GetColour()), width);
}
void AudioTimingControllerKaraoke::OnAutoCommitChange(agi::OptionValue const& opt) {
auto_commit = opt.GetBool();
}

View file

@ -98,6 +98,7 @@
"Selection" : "rgb(64, 64, 64)",
"Selection Modified" : "rgb(92, 0, 0)"
},
"Keyframe" : "rgb(255,0,255)",
"Line Boundary Inactive Line" : "rgb(190,190,190)",
"Line boundary End" : "rgb(0, 0, 216)",
"Line boundary Start" : "rgb(216, 0, 0)",

45
aegisub/src/pen.cpp Normal file
View file

@ -0,0 +1,45 @@
// Copyright (c) 2011, Thomas Goyne <plorkyeran@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.
//
// Aegisub Project http://www.aegisub.org/
//
// $Id$
#include "config.h"
#include "pen.h"
#include "compat.h"
#include "main.h"
void Pen::OnColourChanged(agi::OptionValue const& opt) {
impl.SetColour(lagi_wxColour(opt.GetColour()));
}
void Pen::OnWidthChanged(agi::OptionValue const& opt) {
impl.SetWidth(opt.GetInt());
}
Pen::Pen(const char *colour_opt, const char *width_opt, wxPenStyle style)
: impl(lagi_wxColour(OPT_GET(colour_opt)->GetColour()), OPT_GET(width_opt)->GetInt(), style)
, colour_con(OPT_SUB(colour_opt, &Pen::OnColourChanged, this))
, width_con(OPT_SUB(width_opt, &Pen::OnWidthChanged, this))
{
}
Pen::Pen(const char *colour_opt, int width, wxPenStyle style)
: impl(lagi_wxColour(OPT_GET(colour_opt)->GetColour()), width, style)
, colour_con(OPT_SUB(colour_opt, &Pen::OnColourChanged, this))
{
}

53
aegisub/src/pen.h Normal file
View file

@ -0,0 +1,53 @@
// Copyright (c) 2011, Thomas Goyne <plorkyeran@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.
//
// Aegisub Project http://www.aegisub.org/
//
// $Id$
#ifndef AGI_PRE
#include <wx/pen.h>
#endif
#include <libaegisub/signal.h>
namespace agi { class OptionValue; }
/// @class Pen
/// @brief A simple wrapper around wxPen to bind the colour and width to the
/// value of an option
class Pen {
wxPen impl;
agi::signal::Connection colour_con;
agi::signal::Connection width_con;
void OnColourChanged(agi::OptionValue const& opt);
void OnWidthChanged(agi::OptionValue const& opt);
public:
/// Constructor
/// @param colour_opt Option name to get the colour from
/// @param width_opt Option name to get the width from
/// @param style Pen style
Pen(const char *colour_opt, const char *width_opt, wxPenStyle style = wxPENSTYLE_SOLID);
/// Constructor
/// @param colour_opt Option name to get the colour from
/// @param width Pen width
/// @param style Pen style
Pen(const char *colour_opt, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID);
/// Implicit conversion to wxPen
operator wxPen const&() const { return impl; }
};