Skip to content

Commit

Permalink
perspective tool, part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1t3cht committed Nov 11, 2022
1 parent b77bd97 commit 3aeca6d
Show file tree
Hide file tree
Showing 10 changed files with 457 additions and 125 deletions.
43 changes: 41 additions & 2 deletions src/command/vis_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,31 @@ namespace {
}

bool IsActive(const agi::Context *c) override {
return c->videoDisplay->ToolIsVectorClipTool(M);
return c->videoDisplay->ToolIsType(typeid(VisualToolVectorClip)) && c->videoDisplay->GetSubTool() == M;
}

void operator()(agi::Context *c) override {
c->videoDisplay->SetTool(agi::make_unique<VisualToolVectorClip>(c->videoDisplay, c));
c->videoDisplay->SetVectorClipTool(M);
c->videoDisplay->SetSubTool(M);
}
};

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));
}

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

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(c->videoDisplay->GetSubTool() ^ M);
}
};

Expand Down Expand Up @@ -133,6 +152,23 @@ namespace {
STR_HELP("Clip subtitles to a vectorial area")
};

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

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

// Vector clip tools

struct visual_mode_vclip_drag final : public visual_tool_vclip_command<VCLIP_DRAG> {
Expand Down Expand Up @@ -205,6 +241,9 @@ namespace cmd {
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_grid>());

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
13 changes: 0 additions & 13 deletions src/video_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,23 +530,10 @@ 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 {
return tool && typeid(*tool) == type;
}

bool VideoDisplay::ToolIsVectorClipTool(VisualToolVectorClipMode vcliptoolmode) const {
return ToolIsType(typeid(VisualToolVectorClip)) && static_cast<VisualToolVectorClip*>(tool.get());
}

Vector2D VideoDisplay::GetMousePosition() const {
return last_mouse_pos ? tool->ToScriptCoords(last_mouse_pos) : last_mouse_pos;
}
Expand Down
6 changes: 2 additions & 4 deletions src/video_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,11 @@ class VideoDisplay final : public wxGLCanvas {

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;
void SetSubTool(int subtool) const { tool->SetSubTool(subtool); };

bool ToolIsType(std::type_info const& type) const;

bool ToolIsVectorClipTool(VisualToolVectorClipMode vcliptoolmode) const;
int GetSubTool() const { return tool->GetSubTool(); };

/// Discard all OpenGL state
void Unload();
Expand Down
2 changes: 2 additions & 0 deletions src/visual_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class VisualToolBase {
virtual void SetClientSize(int w, int h);
virtual void SetDisplayArea(int x, int y, int w, int h);
virtual void SetToolbar(wxToolBar *) { }
virtual void SetSubTool(int subtool) { }
virtual int GetSubTool() { return 0; }
virtual ~VisualToolBase() = default;
};

Expand Down
Loading

0 comments on commit 3aeca6d

Please sign in to comment.