Add bindable commands for visual vector clip tools

This commit is contained in:
arch1t3cht 2022-07-12 14:14:44 +02:00
parent 77af0c40dc
commit 10d233d3e2
6 changed files with 125 additions and 4 deletions

View file

@ -50,6 +50,25 @@ namespace {
} }
}; };
template<VisualToolVectorClipMode M>
struct visual_tool_vclip_command : public Command {
CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
bool Validate(const agi::Context *c) override {
return !!c->project->VideoProvider();
}
bool IsActive(const agi::Context *c) override {
return c->videoDisplay->ToolIsVectorClipTool(M);
}
void operator()(agi::Context *c) override {
std::unique_ptr<VisualToolVectorClip> vclip = agi::make_unique<VisualToolVectorClip>(c->videoDisplay, c);
c->videoDisplay->SetTool(std::move(vclip));
c->videoDisplay->SetVectorClipTool(M);
}
};
struct visual_mode_cross final : public visual_tool_command<VisualToolCross> { struct visual_mode_cross final : public visual_tool_command<VisualToolCross> {
CMD_NAME("video/tool/cross") CMD_NAME("video/tool/cross")
CMD_ICON(visual_standard) CMD_ICON(visual_standard)
@ -105,6 +124,66 @@ namespace {
STR_DISP("Vector Clip") STR_DISP("Vector Clip")
STR_HELP("Clip subtitles to a vectorial area") STR_HELP("Clip subtitles to a vectorial area")
}; };
// Vector clip tools
struct visual_mode_vclip_drag final : public visual_tool_vclip_command<VCLIP_DRAG> {
CMD_NAME("video/tool/vclip/drag")
CMD_ICON(visual_vector_clip_drag)
STR_MENU("Drag")
STR_DISP("Drag")
STR_HELP("Drag control points")
};
struct visual_mode_vclip_line final : public visual_tool_vclip_command<VCLIP_LINE> {
CMD_NAME("video/tool/vclip/line")
CMD_ICON(visual_vector_clip_line)
STR_MENU("Line")
STR_DISP("Line")
STR_HELP("Appends a line")
};
struct visual_mode_vclip_bicubic final : public visual_tool_vclip_command<VCLIP_BICUBIC> {
CMD_NAME("video/tool/vclip/bicubic")
CMD_ICON(visual_vector_clip_bicubic)
STR_MENU("Bicubic")
STR_DISP("Bicubic")
STR_HELP("Appends a bezier bicubic curve")
};
struct visual_mode_vclip_convert final : public visual_tool_vclip_command<VCLIP_CONVERT> {
CMD_NAME("video/tool/vclip/convert")
CMD_ICON(visual_vector_clip_convert)
STR_MENU("Convert")
STR_DISP("Convert")
STR_HELP("Converts a segment between line and bicubic")
};
struct visual_mode_vclip_insert final : public visual_tool_vclip_command<VCLIP_INSERT> {
CMD_NAME("video/tool/vclip/insert")
CMD_ICON(visual_vector_clip_insert)
STR_MENU("Insert")
STR_DISP("Insert")
STR_HELP("Inserts a control point")
};
struct visual_mode_vclip_remove final : public visual_tool_vclip_command<VCLIP_REMOVE> {
CMD_NAME("video/tool/vclip/remove")
CMD_ICON(visual_vector_clip_remove)
STR_MENU("Remove")
STR_DISP("Remove")
STR_HELP("Removes a control point")
};
struct visual_mode_vclip_freehand final : public visual_tool_vclip_command<VCLIP_FREEHAND> {
CMD_NAME("video/tool/vclip/freehand")
CMD_ICON(visual_vector_clip_freehand)
STR_MENU("Freehand")
STR_DISP("Freehand")
STR_HELP("Draws a freehand shape")
};
struct visual_mode_vclip_freehand_smooth final : public visual_tool_vclip_command<VCLIP_FREEHAND_SMOOTH> {
CMD_NAME("video/tool/vclip/freehand_smooth")
CMD_ICON(visual_vector_clip_freehand_smooth)
STR_MENU("Freehand smooth")
STR_DISP("Freehand smooth")
STR_HELP("Draws a smoothed freehand shape")
};
} }
namespace cmd { namespace cmd {
@ -116,5 +195,14 @@ namespace cmd {
reg(agi::make_unique<visual_mode_scale>()); reg(agi::make_unique<visual_mode_scale>());
reg(agi::make_unique<visual_mode_clip>()); reg(agi::make_unique<visual_mode_clip>());
reg(agi::make_unique<visual_mode_vector_clip>()); reg(agi::make_unique<visual_mode_vector_clip>());
reg(agi::make_unique<visual_mode_vclip_drag>());
reg(agi::make_unique<visual_mode_vclip_line>());
reg(agi::make_unique<visual_mode_vclip_bicubic>());
reg(agi::make_unique<visual_mode_vclip_convert>());
reg(agi::make_unique<visual_mode_vclip_insert>());
reg(agi::make_unique<visual_mode_vclip_remove>());
reg(agi::make_unique<visual_mode_vclip_freehand>());
reg(agi::make_unique<visual_mode_vclip_freehand_smooth>());
} }
} }

View file

@ -32,6 +32,8 @@
/// @ingroup visual_ts /// @ingroup visual_ts
/// ///
#pragma once
#include "vector2d.h" #include "vector2d.h"
#include <vector> #include <vector>

View file

@ -428,10 +428,23 @@ void VideoDisplay::SetTool(std::unique_ptr<VisualToolBase> new_tool) {
} }
} }
bool VideoDisplay::SetVectorClipTool(VisualToolVectorClipMode vcliptoolmode) const {
if (ToolIsType(typeid(VisualToolVectorClip))) {
static_cast<VisualToolVectorClip*>(tool.get())->SetMode(vcliptoolmode);
return true;
} else {
return false;
}
}
bool VideoDisplay::ToolIsType(std::type_info const& type) const { bool VideoDisplay::ToolIsType(std::type_info const& type) const {
return tool && typeid(*tool) == type; return tool && typeid(*tool) == type;
} }
bool VideoDisplay::ToolIsVectorClipTool(VisualToolVectorClipMode vcliptoolmode) const {
return ToolIsType(typeid(VisualToolVectorClip)) && static_cast<VisualToolVectorClip*>(tool.get());
}
Vector2D VideoDisplay::GetMousePosition() const { Vector2D VideoDisplay::GetMousePosition() const {
return last_mouse_pos ? tool->ToScriptCoords(last_mouse_pos) : last_mouse_pos; return last_mouse_pos ? tool->ToScriptCoords(last_mouse_pos) : last_mouse_pos;
} }

View file

@ -35,6 +35,7 @@
#include <libaegisub/signal.h> #include <libaegisub/signal.h>
#include "vector2d.h" #include "vector2d.h"
#include "visual_tool_vector_clip.h"
#include <memory> #include <memory>
#include <typeinfo> #include <typeinfo>
@ -165,8 +166,14 @@ public:
void SetTool(std::unique_ptr<VisualToolBase> new_tool); void SetTool(std::unique_ptr<VisualToolBase> new_tool);
/// Will only set the vector clip mode if the vector clip tool is active already,
/// otherwise it just returns false.
bool SetVectorClipTool(VisualToolVectorClipMode vcliptoolmode) const;
bool ToolIsType(std::type_info const& type) const; bool ToolIsType(std::type_info const& type) const;
bool ToolIsVectorClipTool(VisualToolVectorClipMode vcliptoolmode) const;
/// Discard all OpenGL state /// Discard all OpenGL state
void Unload(); void Unload();
}; };

View file

@ -65,6 +65,9 @@ void VisualToolVectorClip::SetToolbar(wxToolBar *toolBar) {
} }
void VisualToolVectorClip::SetMode(VisualToolVectorClipMode new_mode) { void VisualToolVectorClip::SetMode(VisualToolVectorClipMode new_mode) {
if (toolBar == nullptr) {
throw agi::InternalError("Vector clip toolbar hasn't been set yet!");
}
// Manually enforce radio behavior as we want one selection in the bar // Manually enforce radio behavior as we want one selection in the bar
// rather than one per group // rather than one per group
for (int i = 0; i < VCLIP_LAST; i++) for (int i = 0; i < VCLIP_LAST; i++)
@ -73,6 +76,10 @@ void VisualToolVectorClip::SetMode(VisualToolVectorClipMode new_mode) {
mode = new_mode; mode = new_mode;
} }
VisualToolVectorClipMode VisualToolVectorClip::GetMode() {
return mode;
}
void VisualToolVectorClip::Draw() { void VisualToolVectorClip::Draw() {
if (!active_line) return; if (!active_line) return;
if (spline.empty()) return; if (spline.empty()) return;

View file

@ -14,6 +14,8 @@
// //
// Aegisub Project http://www.aegisub.org/ // Aegisub Project http://www.aegisub.org/
#pragma once
#include "visual_feature.h" #include "visual_feature.h"
#include "visual_tool.h" #include "visual_tool.h"
#include "spline.h" #include "spline.h"
@ -51,10 +53,6 @@ class VisualToolVectorClip final : public VisualTool<VisualToolVectorClipDraggab
std::set<Feature *> box_added; std::set<Feature *> box_added;
/// @brief Set the mode
/// @param mode 0-7
void SetMode(VisualToolVectorClipMode mode);
void Save(); void Save();
void Commit(wxString message="") override; void Commit(wxString message="") override;
@ -73,4 +71,10 @@ class VisualToolVectorClip final : public VisualTool<VisualToolVectorClipDraggab
public: public:
VisualToolVectorClip(VideoDisplay *parent, agi::Context *context); VisualToolVectorClip(VideoDisplay *parent, agi::Context *context);
void SetToolbar(wxToolBar *tb) override; void SetToolbar(wxToolBar *tb) override;
/// @brief Set the mode. Only valid if the tool is already active.
/// @param mode
void SetMode(VisualToolVectorClipMode mode);
VisualToolVectorClipMode GetMode();
}; };