X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fdisplay%2Fcanvas-grid.h;h=58cfbf735d63b9a5cdb9a32c9ca987fe02b863fd;hb=5baec7f2ec5b05a6781f10a30890c65112eef76e;hp=54a57d3d0dc2130dd0ec298613df3df9213dd682;hpb=115d424c293045ccb2bb23f6b2322a2dd6e13a7d;p=inkscape.git diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index 54a57d3d0..58cfbf735 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -1,39 +1,42 @@ -#ifndef INKSCAPE_CANVAS_GRID_H -#define INKSCAPE_CANVAS_GRID_H - -/* - * Inkscape::CXYGrid - * - * Generic (and quite unintelligent) grid item for gnome canvas - * - * Copyright (C) Johan Engelen 2006 +/** @file + * @brief Cartesian grid item for the Inkscape canvas + */ +/* Copyright (C) Johan Engelen 2006-2007 * Copyright (C) Lauris Kaplinski 2000 - * */ -#include -#include "xml/repr.h" -#include +#ifndef INKSCAPE_CANVAS_GRID_H +#define INKSCAPE_CANVAS_GRID_H +#include +#include +#include #include + +#include "display/sp-canvas.h" +#include "xml/repr.h" #include "ui/widget/color-picker.h" #include "ui/widget/scalar-unit.h" - #include "ui/widget/registered-widget.h" #include "ui/widget/registry.h" -#include "ui/widget/tolerance-slider.h" - #include "xml/node-event-vector.h" - #include "snapper.h" #include "line-snapper.h" struct SPDesktop; struct SPNamedView; +class SPDocument; namespace Inkscape { + +enum GridType { + GRID_RECTANGULAR = 0, + GRID_AXONOMETRIC = 1 +}; +#define GRID_MAXTYPENR 1 + #define INKSCAPE_TYPE_GRID_CANVASITEM (Inkscape::grid_canvasitem_get_type ()) #define INKSCAPE_GRID_CANVASITEM(obj) (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem)) #define INKSCAPE_GRID_CANVASITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem)) @@ -59,91 +62,95 @@ GtkType grid_canvasitem_get_type (void); class CanvasGrid { public: - CanvasGrid(SPDesktop *desktop, Inkscape::XML::Node * in_repr); virtual ~CanvasGrid(); - - static CanvasGrid* NewGrid(SPDesktop *desktop, Inkscape::XML::Node * in_repr, const char * gridtype); - static void writeNewGridToRepr(Inkscape::XML::Node * repr, const char * gridtype); - - virtual void Update (NR::Matrix const &affine, unsigned int flags) = 0; + + // TODO: see effect.h and effect.cpp from live_effects how to link enums to SVGname to typename properly. (johan) + const char * getName(); + const char * getSVGName(); + GridType getGridType(); + static const char * getName(GridType type); + static const char * getSVGName(GridType type); + static GridType getGridTypeFromSVGName(const char * typestr); + static GridType getGridTypeFromName(const char * typestr); + + static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument *doc, GridType gridtype); + static void writeNewGridToRepr(Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype); + + GridCanvasItem * createCanvasItem(SPDesktop * desktop); + + virtual void Update (Geom::Matrix const &affine, unsigned int flags) = 0; virtual void Render (SPCanvasBuf *buf) = 0; - - virtual void readRepr() {}; - virtual void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive) {}; - - virtual Gtk::Widget & getWidget() = 0; - - void hide(); - void show(); - void set_visibility(bool visible); - void toggle_visibility(); - void enable_snapping() { snapenabled = true; snapper->setEnabled(true); } ; - void disable_snapping() { snapenabled = false; snapper->setEnabled(false); } ; - void toggle_snapping() { snapenabled = !snapenabled; snapper->setEnabled(snapenabled);}; + + virtual void readRepr() = 0; + virtual void onReprAttrChanged (Inkscape::XML::Node * /*repr*/, const gchar */*key*/, const gchar */*oldval*/, const gchar */*newval*/, bool /*is_interactive*/) = 0; + + Gtk::Widget * newWidget(); + + Geom::Point origin; /**< Origin of the grid */ + guint32 color; /**< Color for normal lines */ + guint32 empcolor; /**< Color for emphasis lines */ + gint empspacing; /**< Spacing between emphasis lines */ + + SPUnit const* gridunit; Inkscape::XML::Node * repr; - + SPDocument *doc; + Inkscape::Snapper* snapper; static void on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data); + + bool isVisible() { return (isEnabled() &&visible); }; + bool isEnabled(); + protected: - GridCanvasItem * canvasitem; + CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type); + + virtual Gtk::Widget * newSpecificWidget() = 0; + + GSList * canvasitems; // list of created canvasitems SPNamedView * namedview; - - Gtk::VBox vbox; - bool snapenabled; + Inkscape::UI::Widget::Registry _wr; bool visible; + GridType gridtype; + private: CanvasGrid(const CanvasGrid&); CanvasGrid& operator=(const CanvasGrid&); - }; class CanvasXYGrid : public CanvasGrid { public: - CanvasXYGrid(SPDesktop *desktop, Inkscape::XML::Node * in_repr); - ~CanvasXYGrid(); + CanvasXYGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc); + virtual ~CanvasXYGrid(); - void Update (NR::Matrix const &affine, unsigned int flags); + void Update (Geom::Matrix const &affine, unsigned int flags); void Render (SPCanvasBuf *buf); - + void readRepr(); void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive); - - Gtk::Widget & getWidget(); - - NR::Point origin; - guint32 color; - guint32 empcolor; - gint empspacing; - SPUnit const* gridunit; - NR::Point spacing; /**< Spacing between elements of the grid */ + Geom::Point spacing; /**< Spacing between elements of the grid */ bool scaled[2]; /**< Whether the grid is in scaled mode, which can - be different in the X or Y direction, hense two + be different in the X or Y direction, hence two variables */ - NR::Point ow; /**< Transformed origin by the affine for the zoom */ - NR::Point sw; /**< Transformed spacing by the affine for the zoom */ + Geom::Point ow; /**< Transformed origin by the affine for the zoom */ + Geom::Point sw; /**< Transformed spacing by the affine for the zoom */ + +protected: + virtual Gtk::Widget * newSpecificWidget(); + private: CanvasXYGrid(const CanvasXYGrid&); CanvasXYGrid& operator=(const CanvasXYGrid&); - - void updateWidgets(); - Gtk::Table table; - - Inkscape::UI::Widget::RegisteredCheckButton _rcbgrid, _rcbsnbb, _rcbsnnod; - Inkscape::UI::Widget::RegisteredUnitMenu _rumg, _rums; - Inkscape::UI::Widget::RegisteredScalarUnit _rsu_ox, _rsu_oy, _rsu_sx, _rsu_sy; - Inkscape::UI::Widget::RegisteredColorPicker _rcp_gcol, _rcp_gmcol; - Inkscape::UI::Widget::RegisteredSuffixedInteger _rsi; - - Inkscape::UI::Widget::Registry _wr; + void updateWidgets(); + bool render_dotted; }; @@ -151,61 +158,19 @@ private: class CanvasXYGridSnapper : public LineSnapper { public: - CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d); - -private: - LineList _getSnapLines(NR::Point const &p) const; - - CanvasXYGrid *grid; -}; - - - - - - - - - - + CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager *sm, Geom::Coord const d); + bool ThisSnapperMightSnap() const; + Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) + bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance - - - - - - - -#define INKSCAPE_TYPE_CXYGRID (Inkscape::cxygrid_get_type ()) -#define INKSCAPE_CXYGRID(obj) (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_CXYGRID, CXYGrid)) -#define INKSCAPE_CXYGRID_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_CXYGRID, CXYGridClass)) -#define INKSCAPE_IS_CXYGRID(obj) (GTK_CHECK_TYPE ((obj), INKSCAPE_TYPE_CXYGRID)) -#define INKSCAPE_IS_CXYGRID_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), INKSCAPE_TYPE_CXYGRID)) - - -/** \brief All the variables that are tracked for a grid specific - canvas item. */ -struct CXYGrid : public SPCanvasItem{ - NR::Point origin; /**< Origin of the grid */ - NR::Point spacing; /**< Spacing between elements of the grid */ - guint32 color; /**< Color for normal lines */ - guint32 empcolor; /**< Color for emphisis lines */ - gint empspacing; /**< Spacing between emphisis lines */ - bool scaled[2]; /**< Whether the grid is in scaled mode, which can - be different in the X or Y direction, hense two - variables */ - NR::Point ow; /**< Transformed origin by the affine for the zoom */ - NR::Point sw; /**< Transformed spacing by the affine for the zoom */ -}; - -struct CXYGridClass { - SPCanvasItemClass parent_class; +private: + LineList _getSnapLines(Geom::Point const &p) const; + void _addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source, Geom::Point const normal_to_line, const Geom::Point point_on_line) const; + void _addSnappedPoint(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source) const; + CanvasXYGrid *grid; }; -/* Standard Gtk function */ -GtkType cxygrid_get_type (void); - }; /* namespace Inkscape */