Mark the current visual tool as active in the toolbar

Originally committed to SVN as r6285.
This commit is contained in:
Thomas Goyne 2012-01-13 20:18:40 +00:00
parent 54ebe9b37a
commit 1bcbc728c8
3 changed files with 30 additions and 40 deletions

View file

@ -42,88 +42,70 @@ namespace {
/// @defgroup cmd-visual Visual typesetting tools commands /// @defgroup cmd-visual Visual typesetting tools commands
/// @{ /// @{
struct validator_video_loaded : public Command { template<class T>
CMD_TYPE(COMMAND_VALIDATE) struct visual_tool_command : public Command {
bool Validate(const agi::Context *c) { CMD_TYPE(COMMAND_VALIDATE | COMMAND_RADIO)
return c->videoController->IsLoaded();
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<VisualToolCross> {
CMD_NAME("video/tool/cross") CMD_NAME("video/tool/cross")
STR_MENU("Standard") STR_MENU("Standard")
STR_DISP("Standard") STR_DISP("Standard")
STR_HELP("Standard mode, double click sets position.") 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<VisualToolDrag> {
CMD_NAME("video/tool/drag") CMD_NAME("video/tool/drag")
STR_MENU("Drag") STR_MENU("Drag")
STR_DISP("Drag") STR_DISP("Drag")
STR_HELP("Drag subtitles.") 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<VisualToolRotateZ> {
CMD_NAME("video/tool/rotate/z") CMD_NAME("video/tool/rotate/z")
STR_MENU("Rotate Z") STR_MENU("Rotate Z")
STR_DISP("Rotate Z") STR_DISP("Rotate Z")
STR_HELP("Rotate subtitles on their Z axis.") 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<VisualToolRotateXY> {
CMD_NAME("video/tool/rotate/xy") CMD_NAME("video/tool/rotate/xy")
STR_MENU("Rotate XY") STR_MENU("Rotate XY")
STR_DISP("Rotate XY") STR_DISP("Rotate XY")
STR_HELP("Rotate subtitles on their X and Y axes.") 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<VisualToolScale> {
CMD_NAME("video/tool/scale") CMD_NAME("video/tool/scale")
STR_MENU("Scale") STR_MENU("Scale")
STR_DISP("Scale") STR_DISP("Scale")
STR_HELP("Scale subtitles on X and Y axes.") 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<VisualToolClip> {
CMD_NAME("video/tool/clip") CMD_NAME("video/tool/clip")
STR_MENU("Clip") STR_MENU("Clip")
STR_DISP("Clip") STR_DISP("Clip")
STR_HELP("Clip subtitles to a rectangle.") 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<VisualToolVectorClip> {
CMD_NAME("video/tool/vector_clip") CMD_NAME("video/tool/vector_clip")
STR_MENU("Vector Clip") STR_MENU("Vector Clip")
STR_DISP("Vector Clip") STR_DISP("Vector Clip")
STR_HELP("Clip subtitles to a vectorial arean.") STR_HELP("Clip subtitles to a vectorial area.")
void operator()(agi::Context *c) {
c->videoDisplay->SetTool(new VisualToolVectorClip(c->videoDisplay, c));
}
}; };
} }

View file

@ -421,6 +421,10 @@ void VideoDisplay::SetTool(VisualToolBase *new_tool) {
UpdateSize(); UpdateSize();
} }
bool VideoDisplay::ToolIsType(std::type_info const& type) const {
return typeid(*tool) == type;
}
Vector2D VideoDisplay::GetMousePosition() const { Vector2D VideoDisplay::GetMousePosition() const {
return mouse_pos ? tool->ToScriptCoords(mouse_pos) : mouse_pos; return mouse_pos ? tool->ToScriptCoords(mouse_pos) : mouse_pos;
} }

View file

@ -41,6 +41,8 @@
#include <wx/glcanvas.h> #include <wx/glcanvas.h>
#endif #endif
#include <typeinfo>
#include <libaegisub/scoped_ptr.h> #include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h> #include <libaegisub/signal.h>
@ -166,4 +168,6 @@ public:
Vector2D GetMousePosition() const; Vector2D GetMousePosition() const;
void SetTool(VisualToolBase *new_tool); void SetTool(VisualToolBase *new_tool);
bool ToolIsType(std::type_info const& type) const;
}; };