summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2014-02-26 19:31:49 +0000
committerMarkus Engel <markus.engel@tum.de>2014-02-26 19:31:49 +0000
commit21fa74799d08edc54fa6506e3f78fab04215241a (patch)
tree6ee36562ac02167eba78b506e07a1e402fc05996 /src
parentMade constructors of tools use initializer lists. (diff)
downloadinkscape-21fa74799d08edc54fa6506e3f78fab04215241a.tar.gz
inkscape-21fa74799d08edc54fa6506e3f78fab04215241a.zip
Added template functions as a casting-macro replacement.
(bzr r13061)
Diffstat (limited to 'src')
-rw-r--r--src/ui/tools/tool-base.h24
-rw-r--r--src/widgets/pencil-toolbar.cpp12
2 files changed, 33 insertions, 3 deletions
diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h
index a4a27a06c..79bdfe89d 100644
--- a/src/ui/tools/tool-base.h
+++ b/src/ui/tools/tool-base.h
@@ -215,9 +215,31 @@ void sp_toggle_dropper(SPDesktop *dt);
bool sp_event_context_knot_mouseover(ToolBase *ec);
+} // namespace Tools
+
+//#include <type_traits>
+
+namespace Tool {
+
+template<class Derived, typename T>
+bool is_a(const T* t) {
+ //static_assert(std::is_base_of<Tools::ToolBase, Derived>(), "Destination type not derived from ToolBase.");
+ //static_assert(std::is_convertible<const Tools::ToolBase*, const T*>(), "Cannot cast passed pointer to ToolBase*.");
+
+ return dynamic_cast<const Derived*>(static_cast<const Tools::ToolBase*>(t)) != NULL;
}
+
+template<class Derived, typename T>
+Derived* to(T* t) {
+ //static_assert(std::is_base_of<Tools::ToolBase, Derived>(), "Destination type not derived from ToolBase.");
+ //static_assert(std::is_convertible<Tools::ToolBase*, T*>(), "Cannot cast passed pointer to ToolBase*.");
+
+ return dynamic_cast<Derived*>(static_cast<Tools::ToolBase*>(t));
}
-}
+
+} // namespace Tool
+} // namespace UI
+} // namespace Inkscape
#endif // SEEN_SP_EVENT_CONTEXT_H
diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp
index e8296f735..7ad23bbbd 100644
--- a/src/widgets/pencil-toolbar.cpp
+++ b/src/widgets/pencil-toolbar.cpp
@@ -102,8 +102,16 @@ static void freehand_mode_changed(EgeSelectOneAction* act, GObject* tbl)
// in pen tool we have more options than in pencil tool; if one of them was chosen, we do any
// preparatory work here
- if (SP_IS_PEN_CONTEXT(desktop->event_context)) {
- Inkscape::UI::Tools::PenTool *pc = SP_PEN_CONTEXT(desktop->event_context);
+ //if (SP_IS_PEN_CONTEXT(desktop->event_context)) {
+ // Inkscape::UI::Tools::PenTool *pc = SP_PEN_CONTEXT(desktop->event_context);
+ // sp_pen_context_set_polyline_mode(pc);
+ //}
+
+ using namespace Inkscape::UI;
+ using Inkscape::UI::Tools::PenTool;
+
+ if (Tool::is_a<PenTool>(desktop->event_context)) {
+ PenTool* pc = Tool::to<PenTool>(desktop->event_context);
sp_pen_context_set_polyline_mode(pc);
}
}