canvas-grid.cpp revision edf415bfa81ef3be799bb0d740a9ca54553ff091
919N/A * It does seem to work however. I intend to clean up and sort things out later, but that can take forever...
919N/A#include "sp-canvas-util.h"
919N/A#include "display-forward.h"
919N/A#include "desktop-handles.h"
919N/A#include "display/cairo-utils.h"
830N/A#include "display/canvas-axonomgrid.h"
830N/A#include "display/canvas-grid.h"
830N/A#include "display/display-forward.h"
830N/A#include "display/sp-canvas-util.h"
830N/A#include "display/sp-canvas-group.h"
830N/A#include "document.h"
830N/A#include "inkscape.h"
830N/A#include "preferences.h"
830N/A#include "sp-namedview.h"
830N/A#include "sp-object.h"
830N/A#include "svg/svg-color.h"
830N/A#include "xml/node-event-vector.h"
830N/Astatic void grid_canvasitem_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags);
grid_canvasitem_get_type (void)
if (!grid_canvasitem_type) {
sizeof (GridCanvasItemClass),
sizeof (GridCanvasItem),
grid_canvasitem_type = g_type_register_static (sp_canvas_item_get_type (), "GridCanvasItem", &grid_canvasitem_info, (GTypeFlags)0);
return grid_canvasitem_type;
CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type)
if (repr) {
if (repr) {
while (canvasitems) {
return gridtype;
gint t = 0;
for (t = GRID_MAXTYPENR; t >= 0; t--) { //this automatically defaults to grid0 which is rectangular grid
return (GridType) t;
gint t = 0;
for (t = GRID_MAXTYPENR; t >= 0; t--) { //this automatically defaults to grid0 which is rectangular grid
return (GridType) t;
if (!repr) return;
// first create the child xml node, then hook it to repr. This order is important, to not set off listeners to repr before the new node is complete.
CanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype)
if (!doc) {
return NULL;
switch (gridtype) {
case GRID_RECTANGULAR:
case GRID_AXONOMETRIC:
return NULL;
* creates a new grid canvasitem for the SPDesktop given as parameter. Keeps a link to this canvasitem in the canvasitems list.
return NULL;
GridCanvasItem * item = INKSCAPE_GRID_CANVASITEM( sp_canvas_item_new(sp_desktop_gridgroup(desktop), INKSCAPE_TYPE_GRID_CANVASITEM, NULL) );
gtk_object_ref(GTK_OBJECT(item)); // since we're keeping a link to this item, we need to bump up the ref count
return item;
_("When zoomed out, not all grid lines will be displayed. Only the visible ones will be snapped to"),
_("Determines whether the grid is displayed or not. Objects are still snapped to invisible grids."),
CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gchar const *oldval, gchar const *newval, bool is_interactive, void *data)
if (!data)
* A DIRECT COPY-PASTE FROM DOCUMENT-PROPERTIES.CPP TO QUICKLY GET RESULTS
} else if (arr[i]) {
if (!gridunit)
origin[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit);
origin[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit);
spacing[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit);
spacing[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit);
static gboolean
if (!str) {
return FALSE;
gchar *u;
return FALSE;
while (isspace(*u)) {
*val = v;
return TRUE;
*val = v;
return TRUE;
return FALSE;
*val = v;
return TRUE;
return FALSE;
if (!str) {
return FALSE;
gchar *u;
return FALSE;
return TRUE;
double* pTarget)
if ( *pTarget <= 0 ) {
if ( oldVal <= 0 )
if ( *pTarget <= 0 ) {
if ( oldVal <= 0 )
* Called when XML node attribute changed; updates dialog widgets if change was not done by widgets themselves.
CanvasXYGrid::onReprAttrChanged(Inkscape::XML::Node */*repr*/, gchar const */*key*/, gchar const */*oldval*/, gchar const */*newval*/, bool /*is_interactive*/)
readRepr();
Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu(
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sx = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
_("Spacing _Y:"), _("Distance between horizontal grid lines"), "spacingy", *_rumg, _wr, repr, doc) );
Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = Gtk::manage( new Inkscape::UI::Widget::RegisteredSuffixedInteger(
0, _rumg,
0, _rsu_ox,
0, _rsu_oy,
0, _rsu_sx,
0, _rsu_sy,
0, _rsi,
0, _rcb_dotted,
return table;
_wr.setUpdating (true);
_rcb_visible.setActive(visible);
_rcb_enabled.setActive(snapper->getEnabled());
_rumg.setUnit (gridunit);
_rsu_ox.setValue (val);
_rsu_oy.setValue (val);
_rsu_sx.setValue (gridx);
_rsu_sy.setValue (gridy);
_rcp_gcol.setRgba32 (color);
_rcp_gmcol.setRgba32 (empcolor);
_rsi.setValue (empspacing);
_rcb_dotted.setActive(render_dotted);
_wr.setUpdating (false);
gdouble const sxg = floor ((buf->rect.left() - ow[Geom::X]) / sw[Geom::X]) * sw[Geom::X] + ow[Geom::X];
gdouble const syg = floor ((buf->rect.top() - ow[Geom::Y]) / sw[Geom::Y]) * sw[Geom::Y] + ow[Geom::Y];
//set correct coloring, depending preference (when zoomed out, always major coloring or minor coloring)
if (!render_dotted) {
gdouble y;
gdouble x;
gdouble y;
gdouble x;
CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager *sm, Geom::Coord const d) : LineSnapper(sm, d)
* \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels
return _snapmanager->snapprefs.getGridTolerance() == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp
LineList s;
double spacing;
if (getSnapVisibleOnly()) {
if (dt) {
void CanvasXYGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source, long source_num, Geom::Point const normal_to_line, Geom::Point const point_on_line) const
SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, source, source_num, Inkscape::SNAPTARGET_GRID, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);
void CanvasXYGridSnapper::_addSnappedPoint(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const
SnappedPoint dummy = SnappedPoint(snapped_point, source, source_num, Inkscape::SNAPTARGET_GRID, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), constrained_snap, true);