From 81fe2250a70c892eeb195725117d566a042e5c93 Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 2 Dec 2019 15:32:42 +0100 Subject: add draft janet interface for livecoding --- src/ui/toolbar/livecode-toolbar.cpp | 5 +++-- src/ui/tools/livecode-tool.cpp | 19 ++++++++++++------- src/ui/tools/livecode-tool.h | 6 ++++-- 3 files changed, 19 insertions(+), 11 deletions(-) (limited to 'src/ui') diff --git a/src/ui/toolbar/livecode-toolbar.cpp b/src/ui/toolbar/livecode-toolbar.cpp index 81533fec7..ee3a8b3c0 100644 --- a/src/ui/toolbar/livecode-toolbar.cpp +++ b/src/ui/toolbar/livecode-toolbar.cpp @@ -46,7 +46,7 @@ static LivecodeTool *get_livecode_tool() static void update_script_list(GtkListStore *model_files) { gtk_list_store_clear(model_files); auto prefs = Inkscape::Preferences::get(); - Glib::ustring library_path= prefs->getString("/tools/livecode/library_dir"); + Glib::ustring const library_path = prefs->getString("/tools/livecode/library_dir"); Glib::RefPtr library_dir = Gio::File::create_for_path(library_path); auto enumerator = library_dir->enumerate_children(); @@ -72,6 +72,7 @@ namespace UI { namespace Toolbar { LivecodeToolbar::LivecodeToolbar(SPDesktop *desktop) : Toolbar(desktop) + , _freeze(false) { auto prefs = Inkscape::Preferences::get(); @@ -132,7 +133,7 @@ void LivecodeToolbar::active_script_value_changed() LivecodeTool *tool = get_livecode_tool(); if (tool) { - // tool->loadScript(path); + tool->load_script(path); } _freeze = false; diff --git a/src/ui/tools/livecode-tool.cpp b/src/ui/tools/livecode-tool.cpp index 0071f47b3..8b096dbf0 100644 --- a/src/ui/tools/livecode-tool.cpp +++ b/src/ui/tools/livecode-tool.cpp @@ -53,7 +53,7 @@ const std::string LivecodeTool::prefsPath = "/tools/livecode"; LivecodeTool::LivecodeTool() : ToolBase(nullptr, false) - , api(SP_ACTIVE_DESKTOP) + , context(SP_ACTIVE_DESKTOP) { } @@ -83,25 +83,30 @@ bool LivecodeTool::root_handler(GdkEvent* event) ret = ToolBase::root_handler(event); if (!ret) { - api.push_event(event); + context.push_event(event); } return ret; } +void LivecodeTool::load_script(Glib::ustring const &path) +{ + context.load_script(path); +} + static Geom::Point p(100, 100); static Geom::Point a(50, 100), b(120, 300); static Geom::Rect rect(Geom::Point(20, 200), Geom::Point(220, 20)); bool LivecodeTool::handle_tick(Glib::RefPtr const &frame_clock) { - api.setup_frame(); + context.setup_frame(); - api.input_point("p", &p); - api.input_arrow("a->b", &a, &b); - api.input_rect("rect", &rect); + context.input_point("p", &p); + context.input_arrow("a->b", &a, &b); + context.input_rect("rect", &rect); - api.finish_frame(); + context.finish_frame(); return true; } diff --git a/src/ui/tools/livecode-tool.h b/src/ui/tools/livecode-tool.h index fdeb61264..63d85c2e8 100644 --- a/src/ui/tools/livecode-tool.h +++ b/src/ui/tools/livecode-tool.h @@ -19,7 +19,7 @@ #include "display/canvas-text.h" #include "display/canvas-temporary-item.h" #include "ui/control-manager.h" -#include "livecode/api.h" +#include "livecode/context.h" #include #define SP_LIVECODE_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) @@ -43,11 +43,13 @@ public: bool root_handler(GdkEvent* event) override; const std::string& getPrefsPath() override; + void load_script(Glib::ustring const &path); + private: bool handle_tick(Glib::RefPtr const &frame_clock); guint tick_callback; - Livecode::API api; + Livecode::Context context; }; } -- cgit v1.2.3