Commit 17b00286 authored by Tavmjong Bah's avatar Tavmjong Bah
Browse files

A complete rewrite of SPCanvasItems (now Inkscape::CanvasItems) along with all...

A complete rewrite of SPCanvasItems (now Inkscape::CanvasItems) along with all the code they touched.

Canvas items were a mixture of semi-related structures and half-classes following the GObject model. This work replaces them with C++ classes, all derived from CanvasItem. It also standardizes how things such as geometry and style are handled.

No user visible changes should be seen except for a few knot/handle/node/etc. in a few LPE's which may use a differ shape.
parent 0741f45a
Pipeline #180936617 passed with stages
in 10 minutes and 41 seconds
......@@ -16,9 +16,9 @@
../src/context-fns.cpp
../src/desktop-events.cpp
../src/desktop.cpp
../src/display/canvas-axonomgrid.cpp
../src/display/canvas-grid.cpp
../src/display/snap-indicator.cpp
../src/display/control/canvas-axonomgrid.cpp
../src/display/control/canvas-grid.cpp
../src/display/control/snap-indicator.cpp
../src/document.cpp
../src/event-log.cpp
../src/extension/dependency.cpp
......
......@@ -16,7 +16,7 @@
#include "message-stack.h"
#include "snap.h"
#include "display/snap-indicator.h"
#include "display/control/snap-indicator.h"
#include "object/sp-namedview.h"
......
......@@ -37,9 +37,9 @@
#include "sp-cursor.h"
#include "verbs.h"
#include "display/canvas-grid.h"
#include "display/guideline.h"
#include "display/snap-indicator.h"
#include "display/control/snap-indicator.h"
#include "display/control/canvas-item.h" // NOT USED!!
#include "display/control/canvas-item-guideline.h"
#include "helper/action.h"
......@@ -64,9 +64,9 @@ using Inkscape::DocumentUndo;
static void snoop_extended(GdkEvent* event, SPDesktop *desktop);
static void init_extended();
/* Root item handler */
/* Root canvas item handler */
int sp_desktop_root_handler(SPCanvasItem */*item*/, GdkEvent *event, SPDesktop *desktop)
bool sp_desktop_root_handler(GdkEvent *event, SPDesktop *desktop)
{
static bool watch = false;
static bool first = true;
......@@ -84,7 +84,7 @@ int sp_desktop_root_handler(SPCanvasItem */*item*/, GdkEvent *event, SPDesktop *
snoop_extended(event, desktop);
}
return sp_event_context_root_handler(desktop->event_context, event);
return (bool)sp_event_context_root_handler(desktop->event_context, event);
}
......@@ -97,28 +97,28 @@ static SPGuideDragType drag_type = SP_DRAG_NONE;
// Min distance from anchor to initiate rotation, measured in screenpixels
#define tol 40.0
gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
bool sp_dt_guide_event(GdkEvent *event, Inkscape::CanvasItemGuideLine *guide_item, SPGuide *guide)
{
static bool moved = false;
gint ret = FALSE;
bool ret = false;
SPGuide *guide = SP_GUIDE(data);
SPDesktop *desktop = item->canvas->get_desktop();
SPDesktop *desktop = guide_item->get_canvas()->get_desktop();
if (!desktop) {
std::cerr << "sp_dt_guide_event: No desktop!" << std::endl;
}
switch (event->type) {
case GDK_2BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
if (event->button.button == 1) {
drag_type = SP_DRAG_NONE;
sp_event_context_discard_delayed_snap_event(desktop->event_context);
sp_canvas_item_ungrab(item);
guide_item->ungrab();
Inkscape::UI::Dialogs::GuidelinePropertiesDialog::showDialog(guide, desktop);
ret = TRUE;
ret = true;
}
break;
case GDK_BUTTON_PRESS:
case GDK_BUTTON_PRESS:
if (event->button.button == 1) {
Geom::Point const event_w(event->button.x, event->button.y);
Geom::Point const event_dt(desktop->w2d(event_w));
......@@ -142,23 +142,25 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
}
if (drag_type == SP_DRAG_ROTATE || drag_type == SP_DRAG_TRANSLATE) {
sp_canvas_item_grab(item,
( GDK_BUTTON_RELEASE_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK ),
nullptr,
event->button.time);
guide_item->grab((Gdk::BUTTON_RELEASE_MASK |
Gdk::BUTTON_PRESS_MASK |
Gdk::POINTER_MOTION_MASK |
Gdk::POINTER_MOTION_HINT_MASK ),
nullptr);
}
ret = TRUE;
ret = true;
}
break;
case GDK_MOTION_NOTIFY:
if (drag_type != SP_DRAG_NONE) {
Geom::Point const motion_w(event->motion.x,
event->motion.y);
Geom::Point motion_dt(desktop->w2d(motion_w));
sp_event_context_snap_delay_handler(desktop->event_context, (gpointer) item, data, (GdkEventMotion *)event, Inkscape::UI::Tools::DelayedSnapEvent::GUIDE_HANDLER);
sp_event_context_snap_delay_handler(
desktop->event_context, (void *) guide_item, (void *) guide, (GdkEventMotion *)event,
Inkscape::UI::Tools::DelayedSnapEvent::GUIDE_HANDLER);
// This is for snapping while dragging existing guidelines. New guidelines,
// which are dragged off the ruler, are being snapped in sp_dt_ruler_event
......@@ -231,10 +233,11 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
moved = true;
desktop->set_coordinate_status(motion_dt);
ret = TRUE;
ret = true;
}
break;
case GDK_BUTTON_RELEASE:
case GDK_BUTTON_RELEASE:
if (drag_type != SP_DRAG_NONE && event->button.button == 1) {
sp_event_context_discard_delayed_snap_event(desktop->event_context);
......@@ -242,7 +245,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
Geom::Point const event_w(event->button.x,
event->button.y);
Geom::Point event_dt(desktop->w2d(event_w));
std::cout << " event_w: " << event_w << ", event_dt: " << event_dt << std::endl;
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop, true, nullptr, nullptr, guide);
if (drag_type == SP_DRAG_MOVE_ORIGIN) {
......@@ -271,7 +274,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
}
m.unSetup();
if (item->canvas->world_point_inside_canvas(event_w)) {
if (guide_item->get_canvas()->world_point_inside_canvas(event_w)) {
switch (drag_type) {
case SP_DRAG_TRANSLATE:
{
......@@ -311,7 +314,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
break;
}
DocumentUndo::done(desktop->getDocument(), SP_VERB_NONE,
_("Move guide"));
_("Move guide"));
} else {
/* Undo movement of any attached shapes. */
guide->moveto(guide->getPoint(), false);
......@@ -320,20 +323,21 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
desktop->getCanvas()->get_window()->set_cursor(desktop->event_context->cursor);
DocumentUndo::done(desktop->getDocument(), SP_VERB_NONE,
_("Delete guide"));
_("Delete guide"));
}
moved = false;
desktop->set_coordinate_status(event_dt);
}
drag_type = SP_DRAG_NONE;
sp_canvas_item_ungrab(item);
ret=TRUE;
guide_item->ungrab();
ret = true;
}
break;
case GDK_ENTER_NOTIFY:
{
case GDK_ENTER_NOTIFY:
{
if (!guide->getLocked()) {
sp_guideline_set_color(SP_GUIDELINE(item), guide->getHiColor());
guide_item->set_stroke(guide->getHiColor());
}
// set move or rotate cursor
......@@ -359,15 +363,18 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
desktop->guidesMessageContext()->setF(Inkscape::NORMAL_MESSAGE, _("<b>Guideline</b>: %s"), guide_description);
g_free(guide_description);
break;
}
case GDK_LEAVE_NOTIFY:
sp_guideline_set_color(SP_GUIDELINE(item), guide->getColor());
}
case GDK_LEAVE_NOTIFY:
guide_item->set_stroke(guide->getColor());
// restore event context's cursor
desktop->getCanvas()->get_window()->set_cursor(desktop->event_context->cursor);
desktop->guidesMessageContext()->clear();
break;
case GDK_KEY_PRESS:
switch (Inkscape::UI::Tools::get_latin_keyval (&event->key)) {
case GDK_KEY_Delete:
......@@ -377,7 +384,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
SPDocument *doc = guide->document;
sp_guide_remove(guide);
DocumentUndo::done(doc, SP_VERB_NONE, _("Delete guide"));
ret = TRUE;
ret = true;
sp_event_context_discard_delayed_snap_event(desktop->event_context);
desktop->getCanvas()->get_window()->set_cursor(desktop->event_context->cursor);
break;
......@@ -388,7 +395,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
auto display = Gdk::Display::get_default();
auto guide_cursor = Gdk::Cursor::create(display, Gdk::EXCHANGE);
desktop->getCanvas()->get_window()->set_cursor(guide_cursor);
ret = TRUE;
ret = true;
break;
}
......@@ -397,6 +404,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
break;
}
break;
case GDK_KEY_RELEASE:
switch (Inkscape::UI::Tools::get_latin_keyval (&event->key)) {
case GDK_KEY_Shift_L:
......@@ -412,8 +420,9 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
break;
}
break;
default:
break;
default:
break;
}
return ret;
......
......@@ -18,7 +18,12 @@
class SPDesktop;
struct SPDesktopWidget;
struct SPCanvasItem;
class SPGuide;
namespace Inkscape {
class CanvasItem;
class CanvasItemGuideLine;
}
typedef union _GdkEvent GdkEvent;
typedef struct _GdkEventCrossing GdkEventCrossing;
......@@ -27,7 +32,7 @@ typedef struct _GtkWidget GtkWidget;
/* Item handlers */
int sp_desktop_root_handler (SPCanvasItem *item, GdkEvent *event, SPDesktop *desktop);
bool sp_desktop_root_handler (GdkEvent *event, SPDesktop *desktop);
/* Default handlers */
......@@ -37,7 +42,7 @@ gint sp_canvas_motion_notify (GtkWidget *widget,GdkEventMotion *motion, SPDeskto
/* Guides */
gint sp_dt_guide_event (SPCanvasItem *item, GdkEvent *event, gpointer data);
bool sp_dt_guide_event(GdkEvent *event, Inkscape::CanvasItemGuideLine *guide_item, SPGuide *guide);
#endif
......
This diff is collapsed.
......@@ -39,22 +39,16 @@
#include "ui/dialog/print.h"
#include "ui/view/view.h"
namespace Gtk
{
class Toolbar;
class Window;
}
// ------- Inkscape --------
class SPCSSAttr;
struct SPCanvasItem;
struct SPCanvasGroup;
class SPDesktopWidget;
struct DesktopPrefObserver;
namespace Inkscape {
namespace UI {
namespace Tools {
class ToolBase;
}
}
}
class SPItem;
class SPNamedView;
class SPObject;
......@@ -63,12 +57,6 @@ typedef struct _DocumentInterface DocumentInterface;//struct DocumentInterface;
class InkscapeWindow;
namespace Gtk
{
class Toolbar;
class Window;
}
typedef int sp_verb_t;
struct _GdkEventAny;
......@@ -79,26 +67,39 @@ typedef struct _GdkEventWindowState GdkEventWindowState;
struct InkscapeApplication;
namespace Inkscape {
class LayerModel;
class MessageContext;
class Selection;
class LayerManager;
class EventLog;
namespace UI {
namespace Dialog {
class DialogManager;
}
namespace Widget {
class Canvas;
class Dock;
}
}
namespace Display {
class TemporaryItemList;
class TemporaryItem;
class SnapIndicator;
}
class EventLog;
class LayerManager;
class LayerModel;
class MessageContext;
class Selection;
class CanvasItem;
class CanvasItemCatchall;
class CanvasItemDrawing;
class CanvasItemGroup;
class CanvasItemRect;
class CanvasItemRotate;
namespace UI {
namespace Dialog {
class DialogManager;
}
namespace Tools {
class ToolBase;
}
namespace Widget {
class Canvas;
class Dock;
}
}
namespace Display {
class TemporaryItemList;
class TemporaryItem;
class SnapIndicator;
}
}
#define SP_DESKTOP_ZOOM_MAX 256.0
......@@ -109,7 +110,7 @@ namespace Inkscape {
* canvas. It is extensively used by many UI controls that need certain
* visual representations of their own.
*
* SPDesktop provides a certain set of SPCanvasItems, serving as GUI
* SPDesktop provides a certain set of CanvasItems, serving as GUI
* layers of different control objects. The one containing the whole
* document is the drawing layer. In addition to it, there are grid,
* guide, sketch and control layers. The sketch layer is used for
......@@ -151,34 +152,46 @@ public:
/// Stored settings for print dialogue
Inkscape::UI::Dialog::PrinterSettings printer_settings;
Inkscape::UI::Tools::ToolBase* getEventContext() const;
Inkscape::Selection* getSelection() const;
SPDocument* getDocument() const;
Inkscape::UI::Widget::Canvas* getCanvas() const;
SPCanvasItem* getAcetate() const;
SPCanvasGroup* getMain() const;
SPCanvasGroup* getGridGroup() const;
SPCanvasGroup* getGuides() const;
SPCanvasItem* getDrawing() const;
SPCanvasGroup* getSketch() const;
SPCanvasGroup* getControls() const;
SPCanvasGroup* getTempGroup() const;
Inkscape::MessageStack* getMessageStack() const;
SPNamedView* getNamedView() const;
Inkscape::UI::Tools::ToolBase* getEventContext() const { return event_context; }
Inkscape::Selection* getSelection() const { return selection; }
SPDocument* getDocument() const { return doc(); }
Inkscape::UI::Widget::Canvas* getCanvas() const { return canvas; }
Inkscape::MessageStack* getMessageStack() const { return messageStack().get(); }
SPNamedView* getNamedView() const { return namedview; }
// ------- Canvas Items -------
Inkscape::UI::Widget::Canvas *canvas;
SPCanvasItem *acetate;
SPCanvasGroup *main;
SPCanvasGroup *gridgroup;
SPCanvasGroup *guides;
SPCanvasItem *drawing;
SPCanvasGroup *sketch;
SPCanvasGroup *controls;
SPCanvasGroup *tempgroup; ///< contains temporary canvas items
SPCanvasItem *page; ///< page background
SPCanvasItem *page_border; ///< page border
SPCanvasItem *canvas_rotate; ///< quickly show canvas rotation
SPCanvasItem *canvas_debug; ///< shows tiling
// Move these into UI::Widget::Canvas:
Inkscape::CanvasItemGroup *getCanvasControls() const { return canvas_group_controls; }
Inkscape::CanvasItemGroup *getCanvasGrids() const { return canvas_group_grids; }
Inkscape::CanvasItemGroup *getCanvasGuides() const { return canvas_group_guides; }
Inkscape::CanvasItemGroup *getCanvasSketch() const { return canvas_group_sketch; }
Inkscape::CanvasItemGroup *getCanvasTemp() const { return canvas_group_temp; }
Inkscape::CanvasItemCatchall *getCanvasCatchall() const { return canvas_catchall; }
Inkscape::CanvasItemRect *getCanvasPage() const { return canvas_page; }
Inkscape::CanvasItemRect *getCanvasShadow() const { return canvas_shadow; }
Inkscape::CanvasItemDrawing *getCanvasDrawing() const { return canvas_drawing; }
Inkscape::CanvasItemRotate *getCanvasRotate() const { return canvas_rotate; }
private:
// Groups
Inkscape::CanvasItemGroup *canvas_group_controls = nullptr; ///< Handles, knots, nodes, etc.
Inkscape::CanvasItemGroup *canvas_group_drawing = nullptr; ///< Drawing + border + shadow.
Inkscape::CanvasItemGroup *canvas_group_grids = nullptr; ///< Grids.
Inkscape::CanvasItemGroup *canvas_group_guides = nullptr; ///< Guide lines.
Inkscape::CanvasItemGroup *canvas_group_sketch = nullptr; ///< Temporary items before becoming permanent.
Inkscape::CanvasItemGroup *canvas_group_temp = nullptr; ///< Temporary items that self-destruct.
// Individual items
Inkscape::CanvasItemCatchall *canvas_catchall = nullptr; ///< The bottom item for unclaimed events.
Inkscape::CanvasItemRect *canvas_page = nullptr; ///< Page background
Inkscape::CanvasItemRect *canvas_shadow = nullptr; ///< Page shadow
Inkscape::CanvasItemDrawing *canvas_drawing = nullptr; ///< The actual SVG drawing (a.k.a. arena).
Inkscape::CanvasItemRotate *canvas_rotate = nullptr; ///< Quick preview of canvas rotation.
public:
SPCSSAttr *current; ///< current style
bool _focusMode; ///< Whether we're focused working or general working
......@@ -257,7 +270,7 @@ public:
return _guides_message_context.get();
}
Inkscape::Display::TemporaryItem * add_temporary_canvasitem (SPCanvasItem *item, guint lifetime, bool move_to_bottom = true);
Inkscape::Display::TemporaryItem * add_temporary_canvasitem (Inkscape::CanvasItem *item, guint lifetime, bool move_to_bottom = true);
void remove_temporary_canvasitem (Inkscape::Display::TemporaryItem * tempitem);
void redrawDesktop();
......@@ -588,7 +601,7 @@ private:
prefs->addObserver(*this);
}
private:
void notify(Inkscape::Preferences::Entry const &) override {
void notify(Inkscape::Preferences::Entry const &entry) override {
_desktop->redrawDesktop();
}
SPDesktop *_desktop;
......
......@@ -2,15 +2,6 @@
set(display_SRC
cairo-utils.cpp
canvas-arena.cpp
canvas-axonomgrid.cpp
canvas-bpath.cpp
canvas-debug.cpp
canvas-grid.cpp
canvas-rotate.cpp
canvas-temporary-item-list.cpp
canvas-temporary-item.cpp
canvas-text.cpp
curve.cpp
drawing-context.cpp
drawing-group.cpp
......@@ -21,9 +12,7 @@ set(display_SRC
drawing-surface.cpp
drawing-text.cpp
drawing.cpp
gnome-canvas-acetate.cpp
grayscale.cpp
guideline.cpp
nr-3dutils.cpp
nr-filter-blend.cpp
nr-filter-colormatrix.cpp
......@@ -49,30 +38,31 @@ set(display_SRC
nr-light.cpp
nr-style.cpp
nr-svgfonts.cpp
snap-indicator.cpp
sodipodi-ctrl.cpp
sodipodi-ctrlrect.cpp
sp-canvas-util.cpp
sp-canvas-group.cpp
sp-canvas-item.cpp
sp-ctrlcurve.cpp
sp-ctrlline.cpp
sp-ctrlquadr.cpp
control/canvas-axonomgrid.cpp
control/canvas-grid.cpp
control/canvas-temporary-item-list.cpp
control/canvas-temporary-item.cpp
control/snap-indicator.cpp
control/canvas-item.cpp
control/canvas-item-bpath.cpp
control/canvas-item-catchall.cpp
control/canvas-item-ctrl.cpp
control/canvas-item-curve.cpp
control/canvas-item-drawing.cpp
control/canvas-item-grid.cpp
control/canvas-item-group.cpp
control/canvas-item-guideline.cpp
control/canvas-item-quad.cpp
control/canvas-item-rect.cpp
control/canvas-item-rotate.cpp
control/canvas-item-text.cpp
# -------
# Headers
cairo-templates.h
cairo-utils.h
canvas-arena.h
canvas-axonomgrid.h
canvas-bpath.h
canvas-debug.h
canvas-grid.h
canvas-rotate.h
canvas-temporary-item-list.h
canvas-temporary-item.h
canvas-text.h
curve.h
drawing-context.h
drawing-group.h
......@@ -83,9 +73,7 @@ set(display_SRC
drawing-surface.h
drawing-text.h
drawing.h
gnome-canvas-acetate.h
grayscale.h
guideline.h
nr-3dutils.h
nr-filter-blend.h
nr-filter-colormatrix.h
......@@ -115,15 +103,28 @@ set(display_SRC
nr-style.h
nr-svgfonts.h
rendermode.h
snap-indicator.h
sodipodi-ctrl.h
sodipodi-ctrlrect.h
sp-canvas-group.h
sp-canvas-item.h
sp-canvas-util.h
sp-ctrlcurve.h
sp-ctrlline.h
sp-ctrlquadr.h
control/canvas-axonomgrid.h
control/canvas-grid.h
control/canvas-temporary-item-list.h
control/canvas-temporary-item.h
control/snap-indicator.h
control/canvas-item.h
control/canvas-item-bpath.h
control/canvas-item-buffer.h
control/canvas-item-catchall.h
control/canvas-item-ctrl.h
control/canvas-item-curve.h
control/canvas-item-drawing.h
control/canvas-item-enums.h
control/canvas-item-grid.h
control/canvas-item-group.h
control/canvas-item-guideline.h
control/canvas-item-quad.h
control/canvas-item-rect.h
control/canvas-item-rotate.h
control/canvas-item-text.h
)
# add_inkscape_lib(display_LIB "${display_SRC}")
......
......@@ -15,24 +15,12 @@ DrawingItem:
Item belonging to the drawing. These are rendered via the
CanvasArena canvas item.
ControlItem:
SPCanvasGroup: Group of Canvas items such as:
Sketch: Temporary objects before they are added to document.
Temp: Temporary control objects.
Controls: Knots, etc.
Grid: All grids.
Guides: All guide lines and guide-line knots.
SPCtrl: Knots, etc.
CtrlRect: Page, border, etc.
CtrlLine
BPath: Editable paths
CanvasRotate: Copy of canvas for quick display while rotating.
Acetate: Infinite surface to catch events not caught elsewhere.