diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2019-11-28 22:32:59 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2019-11-28 22:32:59 +0000 |
| commit | e892be093dd86fbdabf7a21f9bfd333bcd0839b7 (patch) | |
| tree | 4123d5e6c9792a4f7a648acf2cb975c20e833520 /src/livecode/api.h | |
| parent | add livecoding tool to toolbar (diff) | |
| download | inkscape-e892be093dd86fbdabf7a21f9bfd333bcd0839b7.tar.gz inkscape-e892be093dd86fbdabf7a21f9bfd333bcd0839b7.zip | |
add api and input modules for the livecoding tool
Diffstat (limited to 'src/livecode/api.h')
| -rw-r--r-- | src/livecode/api.h | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/livecode/api.h b/src/livecode/api.h new file mode 100644 index 000000000..d2974a01d --- /dev/null +++ b/src/livecode/api.h @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_LIVECODE_API_H +#define INK_LIVECODE_API_H + +/* + * API for the livecoding script language + * + * Authors: + * Sol Bekic <s+inkscape@s-ol.nu> + * Copyright (C) 2019 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include <cstddef> +#include <2geom/point.h> +#include <2geom/rect.h> +#include <gdk/gdk.h> + +#include "xml/repr.h" +#include "desktop.h" +#include "livecode/input.h" + + +class SPDocument; +class SPItem; + +namespace Inkscape { +namespace Livecode { + +class Mouse; + +class API { +public: + API(SPDesktop *desktop); + ~API(); + + 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 setup_frame(); + void finish_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(); + +private: + SPDesktop *desktop; + SPItem *doc_root, *ui_root; + + Mouse _mouse; + + Glib::ustring hot, active; + std::vector<SPItem *> drawn_items; +}; + +} +} + +#endif // INK_LIVECODE_API_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
