From 1bcbc728c88885b4f36d05a0c891403527b40923 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 13 Jan 2012 20:18:40 +0000 Subject: [PATCH] Mark the current visual tool as active in the toolbar Originally committed to SVN as r6285. --- aegisub/src/command/vis_tool.cpp | 62 ++++++++++++-------------------- aegisub/src/video_display.cpp | 4 +++ aegisub/src/video_display.h | 4 +++ 3 files changed, 30 insertions(+), 40 deletions(-) diff --git a/aegisub/src/command/vis_tool.cpp b/aegisub/src/command/vis_tool.cpp index d8b7eeedd..ce12ee24b 100644 --- a/aegisub/src/command/vis_tool.cpp +++ b/aegisub/src/command/vis_tool.cpp @@ -42,88 +42,70 @@ namespace { /// @defgroup cmd-visual Visual typesetting tools commands /// @{ - struct validator_video_loaded : public Command { - CMD_TYPE(COMMAND_VALIDATE) - bool Validate(const agi::Context *c) { - return c->videoController->IsLoaded(); + template + struct visual_tool_command : public Command { + CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO) + + bool Validate(const agi::Context *c) { + return c->videoController->IsLoaded(); + } + + bool IsActive(const agi::Context *c) { + return c->videoDisplay->ToolIsType(typeid(T)); + } + + void operator()(agi::Context *c) { + c->videoDisplay->SetTool(new T(c->videoDisplay, c)); } }; - struct visual_mode_cross : public validator_video_loaded { + struct visual_mode_cross : public visual_tool_command { CMD_NAME("video/tool/cross") STR_MENU("Standard") STR_DISP("Standard") STR_HELP("Standard mode, double click sets position.") - - void operator()(agi::Context *c) { - c->videoDisplay->SetTool(new VisualToolCross(c->videoDisplay, c)); - } }; - struct visual_mode_drag : public validator_video_loaded { + struct visual_mode_drag : public visual_tool_command { CMD_NAME("video/tool/drag") STR_MENU("Drag") STR_DISP("Drag") STR_HELP("Drag subtitles.") - - void operator()(agi::Context *c) { - c->videoDisplay->SetTool(new VisualToolDrag(c->videoDisplay, c)); - } }; - struct visual_mode_rotate_z : public validator_video_loaded { + struct visual_mode_rotate_z : public visual_tool_command { CMD_NAME("video/tool/rotate/z") STR_MENU("Rotate Z") STR_DISP("Rotate Z") STR_HELP("Rotate subtitles on their Z axis.") - - void operator()(agi::Context *c) { - c->videoDisplay->SetTool(new VisualToolRotateZ(c->videoDisplay, c)); - } }; - struct visual_mode_rotate_xy : public validator_video_loaded { + struct visual_mode_rotate_xy : public visual_tool_command { CMD_NAME("video/tool/rotate/xy") STR_MENU("Rotate XY") STR_DISP("Rotate XY") STR_HELP("Rotate subtitles on their X and Y axes.") - - void operator()(agi::Context *c) { - c->videoDisplay->SetTool(new VisualToolRotateXY(c->videoDisplay, c)); - } }; - struct visual_mode_scale : public validator_video_loaded { + struct visual_mode_scale : public visual_tool_command { CMD_NAME("video/tool/scale") STR_MENU("Scale") STR_DISP("Scale") STR_HELP("Scale subtitles on X and Y axes.") - - void operator()(agi::Context *c) { - c->videoDisplay->SetTool(new VisualToolScale(c->videoDisplay, c)); - } }; - struct visual_mode_clip : public validator_video_loaded { + struct visual_mode_clip : public visual_tool_command { CMD_NAME("video/tool/clip") STR_MENU("Clip") STR_DISP("Clip") STR_HELP("Clip subtitles to a rectangle.") - - void operator()(agi::Context *c) { - c->videoDisplay->SetTool(new VisualToolClip(c->videoDisplay, c)); - } }; - struct visual_mode_vector_clip : public validator_video_loaded { + struct visual_mode_vector_clip : public visual_tool_command { CMD_NAME("video/tool/vector_clip") STR_MENU("Vector Clip") STR_DISP("Vector Clip") - STR_HELP("Clip subtitles to a vectorial arean.") - - void operator()(agi::Context *c) { - c->videoDisplay->SetTool(new VisualToolVectorClip(c->videoDisplay, c)); - } + STR_HELP("Clip subtitles to a vectorial area.") }; } diff --git a/aegisub/src/video_display.cpp b/aegisub/src/video_display.cpp index 0c133d255..b9484d35e 100644 --- a/aegisub/src/video_display.cpp +++ b/aegisub/src/video_display.cpp @@ -421,6 +421,10 @@ void VideoDisplay::SetTool(VisualToolBase *new_tool) { UpdateSize(); } +bool VideoDisplay::ToolIsType(std::type_info const& type) const { + return typeid(*tool) == type; +} + Vector2D VideoDisplay::GetMousePosition() const { return mouse_pos ? tool->ToScriptCoords(mouse_pos) : mouse_pos; } diff --git a/aegisub/src/video_display.h b/aegisub/src/video_display.h index 3a5d5e684..8c152a07d 100644 --- a/aegisub/src/video_display.h +++ b/aegisub/src/video_display.h @@ -41,6 +41,8 @@ #include #endif +#include + #include #include @@ -166,4 +168,6 @@ public: Vector2D GetMousePosition() const; void SetTool(VisualToolBase *new_tool); + + bool ToolIsType(std::type_info const& type) const; };