Skip to content

Commit

Permalink
visual tools: Add perspective tool
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1t3cht committed Jan 25, 2023
1 parent 4c2b47d commit 36e5275
Show file tree
Hide file tree
Showing 56 changed files with 1,582 additions and 6 deletions.
21 changes: 21 additions & 0 deletions docs/art-sources/buttons/visual_perspective.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions docs/art-sources/buttons/visual_perspective_grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions docs/art-sources/buttons/visual_perspective_lock_outer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions docs/art-sources/buttons/visual_perspective_orgmode_center.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions docs/art-sources/buttons/visual_perspective_orgmode_keep.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions docs/art-sources/buttons/visual_perspective_orgmode_nofax.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions docs/art-sources/buttons/visual_perspective_plane.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_grid_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_grid_24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_grid_32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_grid_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_grid_64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bitmaps/button/visual_perspective_plane_16.png
Binary file added src/bitmaps/button/visual_perspective_plane_24.png
35 changes: 35 additions & 0 deletions src/bitmaps/manifest.respack
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,41 @@ button/visual_move_conv_pos_24.png
button/visual_move_conv_pos_32.png
button/visual_move_conv_pos_48.png
button/visual_move_conv_pos_64.png
button/visual_perspective_16.png
button/visual_perspective_24.png
button/visual_perspective_32.png
button/visual_perspective_48.png
button/visual_perspective_64.png
button/visual_perspective_grid_16.png
button/visual_perspective_grid_24.png
button/visual_perspective_grid_32.png
button/visual_perspective_grid_48.png
button/visual_perspective_grid_64.png
button/visual_perspective_lock_outer_16.png
button/visual_perspective_lock_outer_24.png
button/visual_perspective_lock_outer_32.png
button/visual_perspective_lock_outer_48.png
button/visual_perspective_lock_outer_64.png
button/visual_perspective_orgmode_center_16.png
button/visual_perspective_orgmode_center_24.png
button/visual_perspective_orgmode_center_32.png
button/visual_perspective_orgmode_center_48.png
button/visual_perspective_orgmode_center_64.png
button/visual_perspective_orgmode_keep_16.png
button/visual_perspective_orgmode_keep_24.png
button/visual_perspective_orgmode_keep_32.png
button/visual_perspective_orgmode_keep_48.png
button/visual_perspective_orgmode_keep_64.png
button/visual_perspective_orgmode_nofax_16.png
button/visual_perspective_orgmode_nofax_24.png
button/visual_perspective_orgmode_nofax_32.png
button/visual_perspective_orgmode_nofax_48.png
button/visual_perspective_orgmode_nofax_64.png
button/visual_perspective_plane_16.png
button/visual_perspective_plane_24.png
button/visual_perspective_plane_32.png
button/visual_perspective_plane_48.png
button/visual_perspective_plane_64.png
button/visual_rotatexy_16.png
button/visual_rotatexy_24.png
button/visual_rotatexy_32.png
Expand Down
152 changes: 152 additions & 0 deletions src/command/vis_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "../visual_tool_clip.h"
#include "../visual_tool_cross.h"
#include "../visual_tool_drag.h"
#include "../visual_tool_perspective.h"
#include "../visual_tool_rotatexy.h"
#include "../visual_tool_rotatez.h"
#include "../visual_tool_scale.h"
Expand Down Expand Up @@ -68,6 +69,33 @@ namespace {
}
};

template<VisualToolPerspectiveSetting M>
struct visual_tool_persp_setting : public Command {
CMD_TYPE(COMMAND_VALIDATE | COMMAND_TOGGLE)

bool Validate(const agi::Context *c) override {
return c->videoDisplay->ToolIsType(typeid(VisualToolPerspective));
}

virtual const bool CheckActive(int subtool) {
return subtool & M;
}

virtual const int UpdateSubTool(int subtool) {
return subtool ^ M;
}

bool IsActive(const agi::Context *c) override {
return Validate(c) && CheckActive(c->videoDisplay->GetSubTool());
}

void operator()(agi::Context *c) override {
if (!c->videoDisplay->ToolIsType(typeid(VisualToolPerspective)))
c->videoDisplay->SetTool(agi::make_unique<VisualToolPerspective>(c->videoDisplay, c));
c->videoDisplay->SetSubTool(UpdateSubTool(c->videoDisplay->GetSubTool()));
}
};

struct visual_mode_cross final : public visual_tool_command<VisualToolCross> {
CMD_NAME("video/tool/cross")
CMD_ICON(visual_standard)
Expand Down Expand Up @@ -100,6 +128,14 @@ namespace {
STR_HELP("Rotate subtitles on their X and Y axes")
};

struct visual_mode_perspective final : public visual_tool_command<VisualToolPerspective> {
CMD_NAME("video/tool/perspective")
CMD_ICON(visual_perspective)
STR_MENU("Apply 3D Perspective")
STR_DISP("Apply 3D Perspective")
STR_HELP("Rotate and shear subtitles to make them fit a given quad's perspective")
};

struct visual_mode_scale final : public visual_tool_command<VisualToolScale> {
CMD_NAME("video/tool/scale")
CMD_ICON(visual_scale)
Expand All @@ -124,6 +160,113 @@ namespace {
STR_HELP("Clip subtitles to a vectorial area")
};

// Perspective settings
struct visual_mode_perspective_plane final : public visual_tool_persp_setting<PERSP_OUTER> {
CMD_NAME("video/tool/perspective/plane")
CMD_ICON(visual_perspective_plane)
STR_MENU("Show Surrounding Plane")
STR_DISP("Show Surrounding Plane")
STR_HELP("Toggles showing a second quad for the ambient 3D plane.")
};

// Perspective settings
struct visual_mode_perspective_lock_inner final : public visual_tool_persp_setting<PERSP_LOCK_OUTER> {
CMD_NAME("video/tool/perspective/lock_outer")
CMD_ICON(visual_perspective_lock_outer)
STR_MENU("Lock Outer Quad")
STR_DISP("Lock Outer Quad")
STR_HELP("When the surrounding plane is also visible, switches which quad is locked. If inactive, the inner quad can only be resized without changing the perspective plane. If active, this holds for the outer quad instead.")

bool Validate(const agi::Context *c) override {
return c->videoDisplay->ToolIsType(typeid(VisualToolPerspective)) && c->videoDisplay->GetSubTool() | PERSP_OUTER;
}
};

struct visual_mode_perspective_grid final : public visual_tool_persp_setting<PERSP_GRID> {
CMD_NAME("video/tool/perspective/grid")
CMD_ICON(visual_perspective_grid)
STR_MENU("Show Grid")
STR_DISP("Show Grid")
STR_HELP("Toggles showing a 3D grid in the visual perspective tool")
};

struct visual_mode_perspective_orgmode_center : public visual_tool_persp_setting<PERSP_ORGMODE_CENTER> {
CMD_NAME("video/tool/perspective/orgmode/center")
CMD_ICON(visual_perspective_orgmode_center)
STR_MENU("\\org Mode: Center")
STR_DISP("\\org Mode: Center")
STR_HELP("Puts \\org at the center of the perspective quad")

const bool CheckActive(int subtool) override {
return (subtool & PERSP_ORGMODE) == PERSP_ORGMODE_CENTER;
}

const int UpdateSubTool(int subtool) override {
return (subtool & ~PERSP_ORGMODE) | PERSP_ORGMODE_CENTER;
}
};

struct visual_mode_perspective_orgmode_nofax : public visual_tool_persp_setting<PERSP_ORGMODE_NOFAX> {
CMD_NAME("video/tool/perspective/orgmode/nofax")
CMD_ICON(visual_perspective_orgmode_nofax)
STR_MENU("\\org Mode: No \\fax")
STR_DISP("\\org Mode: No \\fax")
STR_HELP("Finds a value for \\org where \\fax can be zero, if possible. Use this mode if your event contains line breaks.")

const bool CheckActive(int subtool) override {
return (subtool & PERSP_ORGMODE) == PERSP_ORGMODE_NOFAX;
}

const int UpdateSubTool(int subtool) override {
return (subtool & ~PERSP_ORGMODE) | PERSP_ORGMODE_NOFAX;
}
};

struct visual_mode_perspective_orgmode_keep : public visual_tool_persp_setting<PERSP_ORGMODE_KEEP> {
CMD_NAME("video/tool/perspective/orgmode/keep")
CMD_ICON(visual_perspective_orgmode_keep)
STR_MENU("\\org Mode: Keep")
STR_DISP("\\org Mode: Keep")
STR_HELP("Fixes the position of \\org")

const bool CheckActive(int subtool) override {
return (subtool & PERSP_ORGMODE) == PERSP_ORGMODE_KEEP;
}

const int UpdateSubTool(int subtool) override {
return (subtool & ~PERSP_ORGMODE) | PERSP_ORGMODE_KEEP;
}
};

struct visual_mode_perspective_orgmode_cycle : public visual_tool_persp_setting<PERSP_ORGMODE> {
CMD_NAME("video/tool/perspective/orgmode/cycle")
STR_MENU("Cycle \\org mode")
STR_DISP("Cycle \\org mode")
STR_HELP("Cycles through the three \\org modes")

const bool CheckActive(int subtool) override {
return false;
}

const int UpdateSubTool(int subtool) override {
int newtool = 0;
switch (subtool & PERSP_ORGMODE) {
case PERSP_ORGMODE_CENTER:
newtool = PERSP_ORGMODE_NOFAX;
break;
case PERSP_ORGMODE_NOFAX:
newtool = PERSP_ORGMODE_KEEP;
break;
case PERSP_ORGMODE_KEEP:
newtool = PERSP_ORGMODE_CENTER;
break;
default:
break;
}
return (subtool & ~PERSP_ORGMODE) | newtool;
}
};

// Vector clip tools

struct visual_mode_vclip_drag final : public visual_tool_vclip_command<VCLIP_DRAG> {
Expand Down Expand Up @@ -191,10 +334,19 @@ namespace cmd {
reg(agi::make_unique<visual_mode_drag>());
reg(agi::make_unique<visual_mode_rotate_z>());
reg(agi::make_unique<visual_mode_rotate_xy>());
reg(agi::make_unique<visual_mode_perspective>());
reg(agi::make_unique<visual_mode_scale>());
reg(agi::make_unique<visual_mode_clip>());
reg(agi::make_unique<visual_mode_vector_clip>());

reg(agi::make_unique<visual_mode_perspective_plane>());
reg(agi::make_unique<visual_mode_perspective_lock_inner>());
reg(agi::make_unique<visual_mode_perspective_grid>());
reg(agi::make_unique<visual_mode_perspective_orgmode_center>());
reg(agi::make_unique<visual_mode_perspective_orgmode_nofax>());
reg(agi::make_unique<visual_mode_perspective_orgmode_keep>());
reg(agi::make_unique<visual_mode_perspective_orgmode_cycle>());

reg(agi::make_unique<visual_mode_vclip_drag>());
reg(agi::make_unique<visual_mode_vclip_line>());
reg(agi::make_unique<visual_mode_vclip_bicubic>());
Expand Down
Loading

0 comments on commit 36e5275

Please sign in to comment.