Template VisualTool on the type of draggable features to use

Originally committed to SVN as r4320.
This commit is contained in:
Thomas Goyne 2010-05-20 08:55:46 +00:00
parent 2ef8302a6d
commit a282393b47
12 changed files with 75 additions and 52 deletions

View file

@ -81,7 +81,6 @@ class SubtitlesProvider;
/// DOCME /// DOCME
class VideoContext : public wxEvtHandler { class VideoContext : public wxEvtHandler {
friend class AudioProvider; friend class AudioProvider;
friend class VisualTool;
private: private:
/// DOCME /// DOCME

View file

@ -46,7 +46,7 @@
class VideoSlider; class VideoSlider;
class VideoBox; class VideoBox;
class VideoOutGL; class VideoOutGL;
class VisualTool; class IVisualTool;
struct VideoState { struct VideoState {
int x; int x;
@ -132,7 +132,7 @@ class VideoDisplay: public wxGLCanvas {
std::auto_ptr<VideoOutGL> videoOut; std::auto_ptr<VideoOutGL> videoOut;
/// The active visual typesetting tool /// The active visual typesetting tool
std::auto_ptr<VisualTool> tool; std::auto_ptr<IVisualTool> tool;
/// The current tool's ID /// The current tool's ID
int activeMode; int activeMode;
/// The toolbar used by individual typesetting tools /// The toolbar used by individual typesetting tools

View file

@ -34,6 +34,8 @@
/// @ingroup visual_ts /// @ingroup visual_ts
/// ///
#pragma once
class OpenGLWrapper; class OpenGLWrapper;
class AssDialogue; class AssDialogue;

View file

@ -59,13 +59,15 @@
#include "video_context.h" #include "video_context.h"
#include "video_display.h" #include "video_display.h"
#include "video_provider_manager.h" #include "video_provider_manager.h"
#include "visual_feature.h"
#include "visual_tool.h" #include "visual_tool.h"
const wxColour VisualTool::colour[4] = {wxColour(106,32,19), wxColour(255,169,40), wxColour(255,253,185), wxColour(187,0,0)}; const wxColour IVisualTool::colour[4] = {wxColour(106,32,19), wxColour(255,169,40), wxColour(255,253,185), wxColour(187,0,0)};
/// @brief Constructor /// @brief Constructor
/// @param parent /// @param parent
VisualTool::VisualTool(VideoDisplay *parent, VideoState const& video) template<class FeatureType>
VisualTool<FeatureType>::VisualTool(VideoDisplay *parent, VideoState const& video)
: parent(parent) : parent(parent)
, holding(false) , holding(false)
, curDiag(NULL) , curDiag(NULL)
@ -83,12 +85,14 @@ VisualTool::VisualTool(VideoDisplay *parent, VideoState const& video)
} }
/// @brief Destructor /// @brief Destructor
VisualTool::~VisualTool() { template<class FeatureType>
VisualTool<FeatureType>::~VisualTool() {
} }
/// @brief Mouse event /// @brief Mouse event
/// @param event /// @param event
void VisualTool::OnMouseEvent (wxMouseEvent &event) { template<class FeatureType>
void VisualTool<FeatureType>::OnMouseEvent (wxMouseEvent &event) {
bool realTime = Options.AsBool(L"Video Visual Realtime"); bool realTime = Options.AsBool(L"Video Visual Realtime");
if (event.Leaving()) { if (event.Leaving()) {
@ -203,7 +207,8 @@ void VisualTool::OnMouseEvent (wxMouseEvent &event) {
/// @brief Commit /// @brief Commit
/// @param full /// @param full
void VisualTool::Commit(bool full) { template<class FeatureType>
void VisualTool<FeatureType>::Commit(bool full) {
SubtitlesGrid *grid = VideoContext::Get()->grid; SubtitlesGrid *grid = VideoContext::Get()->grid;
if (full) grid->ass->FlagAsModified(_("visual typesetting")); if (full) grid->ass->FlagAsModified(_("visual typesetting"));
grid->CommitChanges(false,!full); grid->CommitChanges(false,!full);
@ -212,7 +217,8 @@ void VisualTool::Commit(bool full) {
/// @brief Get active dialogue line /// @brief Get active dialogue line
/// @return /// @return
AssDialogue* VisualTool::GetActiveDialogueLine() { template<class FeatureType>
AssDialogue* VisualTool<FeatureType>::GetActiveDialogueLine() {
SubtitlesGrid *grid = VideoContext::Get()->grid; SubtitlesGrid *grid = VideoContext::Get()->grid;
AssDialogue *diag = grid->GetDialogue(grid->editBox->linen); AssDialogue *diag = grid->GetDialogue(grid->editBox->linen);
@ -229,7 +235,8 @@ AssDialogue* VisualTool::GetActiveDialogueLine() {
/// @brief Get feature under mouse /// @brief Get feature under mouse
/// @return /// @return
int VisualTool::GetHighlightedFeature() { template<class FeatureType>
int VisualTool<FeatureType>::GetHighlightedFeature() {
int highestLayerFound = INT_MIN; int highestLayerFound = INT_MIN;
int bestMatch = -1; int bestMatch = -1;
for (size_t i=0;i<features.size();i++) { for (size_t i=0;i<features.size();i++) {
@ -242,7 +249,8 @@ int VisualTool::GetHighlightedFeature() {
} }
/// @brief Draw all features /// @brief Draw all features
void VisualTool::DrawAllFeatures() { template<class FeatureType>
void VisualTool<FeatureType>::DrawAllFeatures() {
if (!dragListOK) { if (!dragListOK) {
PopulateFeatureList(); PopulateFeatureList();
dragListOK = true; dragListOK = true;
@ -259,7 +267,8 @@ void VisualTool::DrawAllFeatures() {
} }
/// @brief Refresh /// @brief Refresh
void VisualTool::Refresh() { template<class FeatureType>
void VisualTool<FeatureType>::Refresh() {
frame_n = VideoContext::Get()->GetFrameN(); frame_n = VideoContext::Get()->GetFrameN();
if (!dragging) dragListOK = false; if (!dragging) dragListOK = false;
DoRefresh(); DoRefresh();
@ -269,7 +278,8 @@ void VisualTool::Refresh() {
/// @param diag /// @param diag
/// @param x /// @param x
/// @param y /// @param y
void VisualTool::GetLinePosition(AssDialogue *diag,int &x, int &y) { template<class FeatureType>
void VisualTool<FeatureType>::GetLinePosition(AssDialogue *diag,int &x, int &y) {
int orgx=0,orgy=0; int orgx=0,orgy=0;
GetLinePosition(diag,x,y,orgx,orgy); GetLinePosition(diag,x,y,orgx,orgy);
} }
@ -280,7 +290,8 @@ void VisualTool::GetLinePosition(AssDialogue *diag,int &x, int &y) {
/// @param y /// @param y
/// @param orgx /// @param orgx
/// @param orgy /// @param orgy
void VisualTool::GetLinePosition(AssDialogue *diag,int &x, int &y, int &orgx, int &orgy) { template<class FeatureType>
void VisualTool<FeatureType>::GetLinePosition(AssDialogue *diag,int &x, int &y, int &orgx, int &orgy) {
if (!diag) { if (!diag) {
x = INT_MIN; x = INT_MIN;
y = INT_MIN; y = INT_MIN;
@ -399,7 +410,8 @@ void VisualTool::GetLinePosition(AssDialogue *diag,int &x, int &y, int &orgx, in
/// @param y2 /// @param y2
/// @param t1 /// @param t1
/// @param t2 /// @param t2
void VisualTool::GetLineMove(AssDialogue *diag,bool &hasMove,int &x1,int &y1,int &x2,int &y2,int &t1,int &t2) { template<class FeatureType>
void VisualTool<FeatureType>::GetLineMove(AssDialogue *diag,bool &hasMove,int &x1,int &y1,int &x2,int &y2,int &t1,int &t2) {
// Parse tags // Parse tags
hasMove = false; hasMove = false;
diag->ParseASSTags(); diag->ParseASSTags();
@ -443,7 +455,8 @@ void VisualTool::GetLineMove(AssDialogue *diag,bool &hasMove,int &x1,int &y1,int
/// @param rx /// @param rx
/// @param ry /// @param ry
/// @param rz /// @param rz
void VisualTool::GetLineRotation(AssDialogue *diag,float &rx,float &ry,float &rz) { template<class FeatureType>
void VisualTool<FeatureType>::GetLineRotation(AssDialogue *diag,float &rx,float &ry,float &rz) {
// Default values // Default values
rx = ry = rz = 0.0f; rx = ry = rz = 0.0f;
@ -483,7 +496,8 @@ void VisualTool::GetLineRotation(AssDialogue *diag,float &rx,float &ry,float &rz
/// @param diag /// @param diag
/// @param scalX /// @param scalX
/// @param scalY /// @param scalY
void VisualTool::GetLineScale(AssDialogue *diag,float &scalX,float &scalY) { template<class FeatureType>
void VisualTool<FeatureType>::GetLineScale(AssDialogue *diag,float &scalX,float &scalY) {
// Default values // Default values
scalX = scalY = 100.0f; scalX = scalY = 100.0f;
@ -520,7 +534,8 @@ void VisualTool::GetLineScale(AssDialogue *diag,float &scalX,float &scalY) {
/// @param x2 /// @param x2
/// @param y2 /// @param y2
/// @param inverse /// @param inverse
void VisualTool::GetLineClip(AssDialogue *diag,int &x1,int &y1,int &x2,int &y2,bool &inverse) { template<class FeatureType>
void VisualTool<FeatureType>::GetLineClip(AssDialogue *diag,int &x1,int &y1,int &x2,int &y2,bool &inverse) {
// Default values // Default values
x1 = y1 = 0; x1 = y1 = 0;
int sw,sh; int sw,sh;
@ -570,7 +585,8 @@ void VisualTool::GetLineClip(AssDialogue *diag,int &x1,int &y1,int &x2,int &y2,b
/// @param diag /// @param diag
/// @param scale /// @param scale
/// @param inverse /// @param inverse
wxString VisualTool::GetLineVectorClip(AssDialogue *diag,int &scale,bool &inverse) { template<class FeatureType>
wxString VisualTool<FeatureType>::GetLineVectorClip(AssDialogue *diag,int &scale,bool &inverse) {
// Prepare overrides // Prepare overrides
wxString result; wxString result;
scale = 1; scale = 1;
@ -615,7 +631,8 @@ wxString VisualTool::GetLineVectorClip(AssDialogue *diag,int &scale,bool &invers
/// @brief Set override /// @brief Set override
/// @param tag /// @param tag
/// @param value /// @param value
void VisualTool::SetOverride(AssDialogue* line, wxString tag, wxString value) { template<class FeatureType>
void VisualTool<FeatureType>::SetOverride(AssDialogue* line, wxString tag, wxString value) {
if (!line) return; if (!line) return;
wxString removeTag; wxString removeTag;
@ -658,3 +675,5 @@ void VisualTool::SetOverride(AssDialogue* line, wxString tag, wxString value) {
parent->SetFocus(); parent->SetFocus();
} }
template class VisualTool<VisualDraggableFeature>;

View file

@ -45,26 +45,36 @@
#endif #endif
#include "gl_wrap.h" #include "gl_wrap.h"
#include "visual_feature.h"
//////////////
// Prototypes
class VideoDisplay; class VideoDisplay;
class AssDialogue; class AssDialogue;
class VisualTool;
struct VideoState; struct VideoState;
/// DOCME /// First window id for visualsubtoolbar items
#define VISUAL_SUB_TOOL_START 1300 #define VISUAL_SUB_TOOL_START 1300
/// DOCME /// Last window id for visualsubtoolbar items
#define VISUAL_SUB_TOOL_END (VISUAL_SUB_TOOL_START+100) #define VISUAL_SUB_TOOL_END (VISUAL_SUB_TOOL_START+100)
class IVisualTool : public OpenGLWrapper {
protected:
/// DOCME
static const wxColour colour[4];
public:
virtual void OnMouseEvent(wxMouseEvent &event)=0;
virtual void OnSubTool(wxCommandEvent &)=0;
virtual void Update()=0;
virtual void Draw()=0;
virtual void Refresh()=0;
virtual ~IVisualTool() { };
};
/// DOCME /// DOCME
/// @class VisualTool /// @class VisualTool
/// @brief DOCME /// @brief DOCME
/// DOCME /// DOCME
class VisualTool : public OpenGLWrapper { template<class FeatureType>
class VisualTool : public IVisualTool {
private: private:
/// DOCME /// DOCME
@ -79,9 +89,6 @@ protected:
/// DOCME /// DOCME
VideoDisplay *parent; VideoDisplay *parent;
/// DOCME
static const wxColour colour[4];
/// DOCME /// DOCME
bool holding; bool holding;
@ -95,7 +102,7 @@ protected:
int curFeature; int curFeature;
/// DOCME /// DOCME
std::vector<VisualDraggableFeature> features; std::vector<FeatureType> features;
/// DOCME /// DOCME
bool dragListOK; bool dragListOK;
@ -153,17 +160,17 @@ protected:
/// @brief DOCME /// @brief DOCME
/// @param feature /// @param feature
/// ///
virtual bool InitializeDrag(VisualDraggableFeature &feature) { return true; } virtual bool InitializeDrag(FeatureType &feature) { return true; }
/// @brief DOCME /// @brief DOCME
/// @param feature /// @param feature
/// ///
virtual void UpdateDrag(VisualDraggableFeature &feature) {} virtual void UpdateDrag(FeatureType &feature) {}
/// @brief DOCME /// @brief DOCME
/// @param feature /// @param feature
/// ///
virtual void CommitDrag(VisualDraggableFeature &feature) {} virtual void CommitDrag(FeatureType &feature) {}
/// @brief DOCME /// @brief DOCME
/// ///

View file

@ -34,20 +34,15 @@
/// @ingroup visual_ts /// @ingroup visual_ts
/// ///
#include "visual_feature.h"
///////////
// Headers
#include "visual_tool.h" #include "visual_tool.h"
/// DOCME /// DOCME
/// @class VisualToolClip /// @class VisualToolClip
/// @brief DOCME /// @brief DOCME
/// ///
/// DOCME /// DOCME
class VisualToolClip : public VisualTool { class VisualToolClip : public VisualTool<VisualDraggableFeature> {
private: private:
/// DOCME /// DOCME

View file

@ -34,11 +34,7 @@
/// @ingroup visual_ts /// @ingroup visual_ts
/// ///
#include "visual_feature.h"
///////////
// Headers
#include "visual_tool.h" #include "visual_tool.h"
@ -47,7 +43,7 @@
/// @brief DOCME /// @brief DOCME
/// ///
/// DOCME /// DOCME
class VisualToolCross : public VisualTool { class VisualToolCross : public VisualTool<VisualDraggableFeature> {
public: public:
VisualToolCross(VideoDisplay *parent, VideoState const& video, wxToolBar *); VisualToolCross(VideoDisplay *parent, VideoState const& video, wxToolBar *);
~VisualToolCross(); ~VisualToolCross();

View file

@ -39,6 +39,7 @@
#include <wx/toolbar.h> #include <wx/toolbar.h>
#endif #endif
#include "visual_feature.h"
#include "visual_tool.h" #include "visual_tool.h"
@ -47,7 +48,7 @@
/// @brief DOCME /// @brief DOCME
/// ///
/// DOCME /// DOCME
class VisualToolDrag : public VisualTool { class VisualToolDrag : public VisualTool<VisualDraggableFeature> {
private: private:
/// DOCME /// DOCME
wxToolBar *toolBar; wxToolBar *toolBar;

View file

@ -34,12 +34,13 @@
/// @ingroup visual_ts /// @ingroup visual_ts
/// ///
#include "visual_feature.h"
#include "visual_tool.h" #include "visual_tool.h"
/// DOCME /// DOCME
/// @class VisualToolRotateXY /// @class VisualToolRotateXY
/// @brief DOCME /// @brief DOCME
class VisualToolRotateXY : public VisualTool { class VisualToolRotateXY : public VisualTool<VisualDraggableFeature> {
private: private:
/// DOCME /// DOCME

View file

@ -34,6 +34,7 @@
/// @ingroup visual_ts /// @ingroup visual_ts
/// ///
#include "visual_feature.h"
#include "visual_tool.h" #include "visual_tool.h"
@ -42,7 +43,7 @@
/// @brief DOCME /// @brief DOCME
/// ///
/// DOCME /// DOCME
class VisualToolRotateZ : public VisualTool { class VisualToolRotateZ : public VisualTool<VisualDraggableFeature> {
private: private:
/// DOCME /// DOCME

View file

@ -34,12 +34,13 @@
/// @ingroup visual_ts /// @ingroup visual_ts
/// ///
#include "visual_feature.h"
#include "visual_tool.h" #include "visual_tool.h"
/// DOCME /// DOCME
/// @class VisualToolScale /// @class VisualToolScale
/// @brief DOCME /// @brief DOCME
class VisualToolScale : public VisualTool { class VisualToolScale : public VisualTool<VisualDraggableFeature> {
private: private:
/// DOCME /// DOCME

View file

@ -34,6 +34,7 @@
/// @ingroup visual_ts /// @ingroup visual_ts
/// ///
#include "visual_feature.h"
#include "visual_tool.h" #include "visual_tool.h"
#include "spline.h" #include "spline.h"
@ -42,7 +43,7 @@ class wxToolBar;
/// DOCME /// DOCME
/// @class VisualToolVectorClip /// @class VisualToolVectorClip
/// @brief DOCME /// @brief DOCME
class VisualToolVectorClip : public VisualTool { class VisualToolVectorClip : public VisualTool<VisualDraggableFeature> {
private: private:
/// DOCME /// DOCME