// SPDX-License-Identifier: GPL-2.0-or-later #ifndef INK_LIVECODE_API_H #define INK_LIVECODE_API_H /* * Context for the livecoding script language * * Authors: * Sol Bekic * Copyright (C) 2019 Authors * * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ #include #include <2geom/point.h> #include <2geom/rect.h> #include #include #include #include #include "xml/repr.h" #include "desktop.h" #include "livecode/input.h" class SPDocument; class SPItem; namespace Inkscape { namespace Livecode { class Mouse; class Script { public: Script(JanetTable *env, std::string const &path); void frame(); void commit(); private: JanetTable *env; JanetFunction *function; Glib::RefPtr file; Glib::RefPtr monitor; void reload(); void file_changed(const Glib::RefPtr& file, const Glib::RefPtr& other_file, Gio::FileMonitorEvent event); }; class Context { public: Context(SPDesktop *desktop); ~Context(); Inkscape::XML::Node *make_rect(Geom::Rect const &rect, SPCSSAttr *css = nullptr); Inkscape::XML::Node *make_line(Geom::Point const &p1, Geom::Point const &p2, SPCSSAttr *css = nullptr); Inkscape::XML::Node *make_path(Glib::ustring d, Geom::Point const &pos = Geom::Point(), SPCSSAttr *css = nullptr); Inkscape::XML::Node *make_arrow(Geom::Point const &from, Geom::Point const &to, SPCSSAttr *css = nullptr); bool input_point(Glib::ustring const &id, Geom::Point *point); bool input_line(Glib::ustring const &id, Geom::Point *p1, Geom::Point *p2); bool input_arrow(Glib::ustring const &id, Geom::Point *from, Geom::Point *to); bool input_rect(Glib::ustring const &id, Geom::Rect *rect); void draw_doc(Glib::ustring const &id, Inkscape::XML::Node *item); void draw_ui(Glib::ustring const &id, Inkscape::XML::Node *item); void push_event(GdkEvent *event); void frame(); inline Geom::Affine ui2dt() const { return doc_root->i2doc_affine(); } inline Geom::Affine dt2ui() const { return ui2dt().inverse(); } inline Geom::Affine ui2doc() const { return desktop->w2d(); } inline Geom::Affine doc2ui() const { return ui2doc().inverse(); } inline Geom::Affine ui2doc_vec() const { return desktop->w2d().withoutTranslation(); } inline Geom::Affine doc2ui_vec() const { return ui2doc_vec().inverse(); } Mouse const &mouse(); void load_script(Glib::ustring const &path); private: void setup_frame(); void finish_frame(); SPDesktop *desktop; SPItem *doc_root, *ui_root; JanetTable *env; std::unique_ptr