diff --git a/src/command/vis_tool.cpp b/src/command/vis_tool.cpp index 168f427ee..c898d87f3 100644 --- a/src/command/vis_tool.cpp +++ b/src/command/vis_tool.cpp @@ -50,6 +50,25 @@ namespace { } }; + template + 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 vclip = agi::make_unique(c->videoDisplay, c); + c->videoDisplay->SetTool(std::move(vclip)); + c->videoDisplay->SetVectorClipTool(M); + } + }; + struct visual_mode_cross final : public visual_tool_command { CMD_NAME("video/tool/cross") CMD_ICON(visual_standard) @@ -105,6 +124,66 @@ namespace { STR_DISP("Vector Clip") STR_HELP("Clip subtitles to a vectorial area") }; + + // Vector clip tools + + struct visual_mode_vclip_drag final : public visual_tool_vclip_command { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { @@ -116,5 +195,14 @@ namespace cmd { reg(agi::make_unique()); reg(agi::make_unique()); reg(agi::make_unique()); + + reg(agi::make_unique()); + reg(agi::make_unique()); + reg(agi::make_unique()); + reg(agi::make_unique()); + reg(agi::make_unique()); + reg(agi::make_unique()); + reg(agi::make_unique()); + reg(agi::make_unique()); } } diff --git a/src/spline_curve.h b/src/spline_curve.h index c6c3c0b35..4630a64d2 100644 --- a/src/spline_curve.h +++ b/src/spline_curve.h @@ -32,6 +32,8 @@ /// @ingroup visual_ts /// +#pragma once + #include "vector2d.h" #include diff --git a/src/video_display.cpp b/src/video_display.cpp index 8d85311a6..8669b366b 100644 --- a/src/video_display.cpp +++ b/src/video_display.cpp @@ -428,10 +428,23 @@ void VideoDisplay::SetTool(std::unique_ptr new_tool) { } } +bool VideoDisplay::SetVectorClipTool(VisualToolVectorClipMode vcliptoolmode) const { + if (ToolIsType(typeid(VisualToolVectorClip))) { + static_cast(tool.get())->SetMode(vcliptoolmode); + return true; + } else { + return false; + } +} + bool VideoDisplay::ToolIsType(std::type_info const& type) const { return tool && typeid(*tool) == type; } +bool VideoDisplay::ToolIsVectorClipTool(VisualToolVectorClipMode vcliptoolmode) const { + return ToolIsType(typeid(VisualToolVectorClip)) && static_cast(tool.get()); +} + Vector2D VideoDisplay::GetMousePosition() const { return last_mouse_pos ? tool->ToScriptCoords(last_mouse_pos) : last_mouse_pos; } diff --git a/src/video_display.h b/src/video_display.h index f0d65edb6..799dc2441 100644 --- a/src/video_display.h +++ b/src/video_display.h @@ -35,6 +35,7 @@ #include #include "vector2d.h" +#include "visual_tool_vector_clip.h" #include #include @@ -165,8 +166,14 @@ public: void SetTool(std::unique_ptr 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 ToolIsVectorClipTool(VisualToolVectorClipMode vcliptoolmode) const; + /// Discard all OpenGL state void Unload(); }; diff --git a/src/visual_tool_vector_clip.cpp b/src/visual_tool_vector_clip.cpp index 25bffe4cb..8cae6b513 100644 --- a/src/visual_tool_vector_clip.cpp +++ b/src/visual_tool_vector_clip.cpp @@ -65,6 +65,9 @@ void VisualToolVectorClip::SetToolbar(wxToolBar *toolBar) { } 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 // rather than one per group for (int i = 0; i < VCLIP_LAST; i++) @@ -73,6 +76,10 @@ void VisualToolVectorClip::SetMode(VisualToolVectorClipMode new_mode) { mode = new_mode; } +VisualToolVectorClipMode VisualToolVectorClip::GetMode() { + return mode; +} + void VisualToolVectorClip::Draw() { if (!active_line) return; if (spline.empty()) return; diff --git a/src/visual_tool_vector_clip.h b/src/visual_tool_vector_clip.h index b9d2fdc14..4f0c8d0be 100644 --- a/src/visual_tool_vector_clip.h +++ b/src/visual_tool_vector_clip.h @@ -14,6 +14,8 @@ // // Aegisub Project http://www.aegisub.org/ +#pragma once + #include "visual_feature.h" #include "visual_tool.h" #include "spline.h" @@ -51,10 +53,6 @@ class VisualToolVectorClip final : public VisualTool box_added; - /// @brief Set the mode - /// @param mode 0-7 - void SetMode(VisualToolVectorClipMode mode); - void Save(); void Commit(wxString message="") override; @@ -73,4 +71,10 @@ class VisualToolVectorClip final : public VisualTool