visual tools: Add general interface for setting subtools
This commit is contained in:
parent
af009c4ce7
commit
bfdf01df9a
6 changed files with 17 additions and 42 deletions
|
@ -59,12 +59,12 @@ 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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -428,23 +428,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;
|
||||
}
|
||||
|
|
|
@ -166,13 +166,11 @@ public:
|
|||
|
||||
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();
|
||||
|
|
|
@ -146,6 +146,8 @@ public:
|
|||
virtual void Draw()=0;
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -42,15 +42,7 @@ VisualToolVectorClip::VisualToolVectorClip(VideoDisplay *parent, agi::Context *c
|
|||
// as is done in toolbar.cpp feels like too big of a hack. At least this way the button's actions
|
||||
// are not purely controlled by the order they're added in.
|
||||
void VisualToolVectorClip::AddTool(std::string command_name, VisualToolVectorClipMode mode) {
|
||||
cmd::Command *command;
|
||||
try {
|
||||
command = cmd::get(command_name);
|
||||
}
|
||||
catch (cmd::CommandNotFound const&) {
|
||||
// Toolbar names are all hardcoded so this should never happen
|
||||
throw agi::InternalError("Toolbar named " + command_name + " not found.");
|
||||
}
|
||||
|
||||
cmd::Command *command = cmd::get(command_name);
|
||||
int icon_size = OPT_GET("App/Toolbar Icon Size")->GetInt();
|
||||
toolBar->AddTool(BUTTON_ID_BASE + mode, command->StrDisplay(c), command->Icon(icon_size), command->GetTooltip("Video"), wxITEM_CHECK);
|
||||
}
|
||||
|
@ -75,24 +67,23 @@ void VisualToolVectorClip::SetToolbar(wxToolBar *toolBar) {
|
|||
toolBar->ToggleTool(BUTTON_ID_BASE + VCLIP_DRAG, true);
|
||||
toolBar->Realize();
|
||||
toolBar->Show(true);
|
||||
toolBar->Bind(wxEVT_TOOL, [=](wxCommandEvent& e) { SetMode((VisualToolVectorClipMode) (e.GetId() - BUTTON_ID_BASE)); });
|
||||
SetMode(VCLIP_LINE);
|
||||
#undef ICON
|
||||
toolBar->Bind(wxEVT_TOOL, [=](wxCommandEvent& e) { SetSubTool(e.GetId() - BUTTON_ID_BASE); });
|
||||
SetSubTool(VCLIP_LINE);
|
||||
}
|
||||
|
||||
void VisualToolVectorClip::SetMode(VisualToolVectorClipMode new_mode) {
|
||||
void VisualToolVectorClip::SetSubTool(int subtool) {
|
||||
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++)
|
||||
toolBar->ToggleTool(BUTTON_ID_BASE + i, i == new_mode);
|
||||
toolBar->ToggleTool(BUTTON_ID_BASE + i, i == subtool);
|
||||
|
||||
mode = new_mode;
|
||||
mode = subtool;
|
||||
}
|
||||
|
||||
VisualToolVectorClipMode VisualToolVectorClip::GetMode() {
|
||||
int VisualToolVectorClip::GetSubTool() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
|
@ -452,7 +443,7 @@ void VisualToolVectorClip::UpdateHold() {
|
|||
|
||||
// End freedraw
|
||||
if (!holding && (mode == VCLIP_FREEHAND || mode == VCLIP_FREEHAND_SMOOTH)) {
|
||||
SetMode(VCLIP_DRAG);
|
||||
SetSubTool(VCLIP_DRAG);
|
||||
MakeFeatures();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ struct VisualToolVectorClipDraggableFeature final : public VisualDraggableFeatur
|
|||
class VisualToolVectorClip final : public VisualTool<VisualToolVectorClipDraggableFeature> {
|
||||
Spline spline; /// The current spline
|
||||
wxToolBar *toolBar = nullptr; /// The subtoolbar
|
||||
VisualToolVectorClipMode mode = VCLIP_DRAG; /// 0-7
|
||||
int mode = VCLIP_DRAG; /// 0-7
|
||||
bool inverse = false; /// is iclip?
|
||||
|
||||
std::set<Feature *> box_added;
|
||||
|
@ -75,9 +75,6 @@ public:
|
|||
VisualToolVectorClip(VideoDisplay *parent, agi::Context *context);
|
||||
void SetToolbar(wxToolBar *tb) override;
|
||||
|
||||
/// @brief Set the mode. Only valid if the tool is already active.
|
||||
/// @param mode
|
||||
void SetMode(VisualToolVectorClipMode mode);
|
||||
|
||||
VisualToolVectorClipMode GetMode();
|
||||
void SetSubTool(int subtool) override;
|
||||
int GetSubTool() override;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue