52
52
static void grid_canvasitem_init (GridCanvasItem *grid);
53
53
static void grid_canvasitem_destroy (GtkObject *object);
55
static void grid_canvasitem_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
55
static void grid_canvasitem_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags);
56
56
static void grid_canvasitem_render (SPCanvasItem *item, SPCanvasBuf *buf);
58
58
static SPCanvasItemClass * parent_class;
419
419
gridunit = sp_unit_get_by_abbreviation( prefs->getString("options.grids.xy", "units").data() );
421
421
gridunit = &sp_unit_get_by_id(SP_UNIT_PX);
422
origin[NR::X] = sp_units_get_pixels(prefs->getDouble("options.grids.xy", "origin_x", 0.0), *gridunit);
423
origin[NR::Y] = sp_units_get_pixels(prefs->getDouble("options.grids.xy", "origin_y", 0.0), *gridunit);
422
origin[Geom::X] = sp_units_get_pixels(prefs->getDouble("options.grids.xy", "origin_x", 0.0), *gridunit);
423
origin[Geom::Y] = sp_units_get_pixels(prefs->getDouble("options.grids.xy", "origin_y", 0.0), *gridunit);
424
424
color = prefs->getInt("options.grids.xy", "color", 0x0000ff20);
425
425
empcolor = prefs->getInt("options.grids.xy", "empcolor", 0x0000ff40);
426
426
empspacing = prefs->getInt("options.grids.xy", "empspacing", 5);
427
spacing[NR::X] = sp_units_get_pixels(prefs->getDouble("options.grids.xy", "spacing_x", 0.0), *gridunit);
428
spacing[NR::Y] = sp_units_get_pixels(prefs->getDouble("options.grids.xy", "spacing_y", 0.0), *gridunit);
427
spacing[Geom::X] = sp_units_get_pixels(prefs->getDouble("options.grids.xy", "spacing_x", 0.0), *gridunit);
428
spacing[Geom::Y] = sp_units_get_pixels(prefs->getDouble("options.grids.xy", "spacing_y", 0.0), *gridunit);
429
429
render_dotted = prefs->getBool("options.grids.xy", "dotted", false);
431
431
snapper = new CanvasXYGridSnapper(this, &namedview->snap_manager, 0);
569
569
gchar const *value;
570
570
if ( (value = repr->attribute("originx")) ) {
571
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[NR::X], &gridunit);
572
origin[NR::X] = sp_units_get_pixels(origin[NR::X], *(gridunit));
571
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::X], &gridunit);
572
origin[Geom::X] = sp_units_get_pixels(origin[Geom::X], *(gridunit));
575
575
if ( (value = repr->attribute("originy")) ) {
576
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[NR::Y], &gridunit);
577
origin[NR::Y] = sp_units_get_pixels(origin[NR::Y], *(gridunit));
576
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::Y], &gridunit);
577
origin[Geom::Y] = sp_units_get_pixels(origin[Geom::Y], *(gridunit));
580
580
if ( (value = repr->attribute("spacingx")) ) {
581
double oldVal = spacing[NR::X];
582
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[NR::X], &gridunit);
583
validateScalar( oldVal, &spacing[NR::X]);
584
spacing[NR::X] = sp_units_get_pixels(spacing[NR::X], *(gridunit));
581
double oldVal = spacing[Geom::X];
582
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[Geom::X], &gridunit);
583
validateScalar( oldVal, &spacing[Geom::X]);
584
spacing[Geom::X] = sp_units_get_pixels(spacing[Geom::X], *(gridunit));
587
587
if ( (value = repr->attribute("spacingy")) ) {
588
double oldVal = spacing[NR::Y];
589
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[NR::Y], &gridunit);
590
validateScalar( oldVal, &spacing[NR::Y]);
591
spacing[NR::Y] = sp_units_get_pixels(spacing[NR::Y], *(gridunit));
588
double oldVal = spacing[Geom::Y];
589
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[Geom::Y], &gridunit);
590
validateScalar( oldVal, &spacing[Geom::Y]);
591
spacing[Geom::Y] = sp_units_get_pixels(spacing[Geom::Y], *(gridunit));
719
719
_rumg->setUnit (gridunit);
722
val = origin[Geom::X];
723
723
val = sp_pixels_get_units (val, *(gridunit));
724
724
_rsu_ox->setValue (val);
725
val = origin[Geom::Y];
726
726
val = sp_pixels_get_units (val, *(gridunit));
727
727
_rsu_oy->setValue (val);
728
val = spacing[NR::X];
728
val = spacing[Geom::X];
729
729
double gridx = sp_pixels_get_units (val, *(gridunit));
730
730
_rsu_sx->setValue (gridx);
731
val = spacing[NR::Y];
731
val = spacing[Geom::Y];
732
732
double gridy = sp_pixels_get_units (val, *(gridunit));
733
733
_rsu_sy->setValue (gridy);
761
761
_rumg.setUnit (gridunit);
764
val = origin[Geom::X];
765
765
val = sp_pixels_get_units (val, *(gridunit));
766
766
_rsu_ox.setValue (val);
767
val = origin[Geom::Y];
768
768
val = sp_pixels_get_units (val, *(gridunit));
769
769
_rsu_oy.setValue (val);
770
val = spacing[NR::X];
770
val = spacing[Geom::X];
771
771
double gridx = sp_pixels_get_units (val, *(gridunit));
772
772
_rsu_sx.setValue (gridx);
773
val = spacing[NR::Y];
773
val = spacing[Geom::Y];
774
774
double gridy = sp_pixels_get_units (val, *(gridunit));
775
775
_rsu_sy.setValue (gridy);
792
CanvasXYGrid::Update (NR::Matrix const &affine, unsigned int /*flags*/)
792
CanvasXYGrid::Update (Geom::Matrix const &affine, unsigned int /*flags*/)
794
794
ow = origin * affine;
795
795
sw = spacing * affine;
796
sw -= NR::Point(affine[4], affine[5]);
796
sw -= Geom::Point(affine[4], affine[5]);
798
798
for(int dim = 0; dim < 2; dim++) {
799
799
gint scaling_factor = empspacing;
882
882
CanvasXYGrid::Render (SPCanvasBuf *buf)
884
gdouble const sxg = floor ((buf->rect.x0 - ow[NR::X]) / sw[NR::X]) * sw[NR::X] + ow[NR::X];
885
gint const xlinestart = (gint) Inkscape::round((sxg - ow[NR::X]) / sw[NR::X]);
886
gdouble const syg = floor ((buf->rect.y0 - ow[NR::Y]) / sw[NR::Y]) * sw[NR::Y] + ow[NR::Y];
887
gint const ylinestart = (gint) Inkscape::round((syg - ow[NR::Y]) / sw[NR::Y]);
884
gdouble const sxg = floor ((buf->rect.x0 - ow[Geom::X]) / sw[Geom::X]) * sw[Geom::X] + ow[Geom::X];
885
gint const xlinestart = (gint) Inkscape::round((sxg - ow[Geom::X]) / sw[Geom::X]);
886
gdouble const syg = floor ((buf->rect.y0 - ow[Geom::Y]) / sw[Geom::Y]) * sw[Geom::Y] + ow[Geom::Y];
887
gint const ylinestart = (gint) Inkscape::round((syg - ow[Geom::Y]) / sw[Geom::Y]);
889
889
//set correct coloring, depending preference (when zoomed out, always major coloring or minor coloring)
890
890
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
891
891
guint32 _empcolor;
892
892
bool no_emp_when_zoomed_out = prefs->getBool("options.grids", "no_emphasize_when_zoomedout", false);
893
if( (scaled[NR::X] || scaled[NR::Y]) && no_emp_when_zoomed_out ) {
893
if( (scaled[Geom::X] || scaled[Geom::Y]) && no_emp_when_zoomed_out ) {
894
894
_empcolor = color;
896
896
_empcolor = empcolor;
899
899
if (!render_dotted) {
902
for (y = syg, ylinenum = ylinestart; y < buf->rect.y1; y += sw[NR::Y], ylinenum++) {
902
for (y = syg, ylinenum = ylinestart; y < buf->rect.y1; y += sw[Geom::Y], ylinenum++) {
903
903
gint const y0 = (gint) Inkscape::round(y);
904
if (!scaled[NR::Y] && (ylinenum % empspacing) != 0) {
904
if (!scaled[Geom::Y] && (ylinenum % empspacing) != 0) {
905
905
grid_hline (buf, y0, buf->rect.x0, buf->rect.x1 - 1, color);
907
907
grid_hline (buf, y0, buf->rect.x0, buf->rect.x1 - 1, _empcolor);
913
for (x = sxg, xlinenum = xlinestart; x < buf->rect.x1; x += sw[NR::X], xlinenum++) {
913
for (x = sxg, xlinenum = xlinestart; x < buf->rect.x1; x += sw[Geom::X], xlinenum++) {
914
914
gint const ix = (gint) Inkscape::round(x);
915
if (!scaled[NR::X] && (xlinenum % empspacing) != 0) {
915
if (!scaled[Geom::X] && (xlinenum % empspacing) != 0) {
916
916
grid_vline (buf, ix, buf->rect.y0, buf->rect.y1, color);
918
918
grid_vline (buf, ix, buf->rect.y0, buf->rect.y1, _empcolor);
924
for (y = syg, ylinenum = ylinestart; y < buf->rect.y1; y += sw[NR::Y], ylinenum++) {
924
for (y = syg, ylinenum = ylinestart; y < buf->rect.y1; y += sw[Geom::Y], ylinenum++) {
925
925
gint const iy = (gint) Inkscape::round(y);
929
for (x = sxg, xlinenum = xlinestart; x < buf->rect.x1; x += sw[NR::X], xlinenum++) {
929
for (x = sxg, xlinenum = xlinestart; x < buf->rect.x1; x += sw[Geom::X], xlinenum++) {
930
930
gint const ix = (gint) Inkscape::round(x);
931
if ( (!scaled[NR::X] && (xlinenum % empspacing) != 0)
932
|| (!scaled[NR::Y] && (ylinenum % empspacing) != 0)
933
|| ((scaled[NR::X] || scaled[NR::Y]) && no_emp_when_zoomed_out) )
931
if ( (!scaled[Geom::X] && (xlinenum % empspacing) != 0)
932
|| (!scaled[Geom::Y] && (ylinenum % empspacing) != 0)
933
|| ((scaled[Geom::X] || scaled[Geom::Y]) && no_emp_when_zoomed_out) )
935
935
grid_dot (buf, ix, iy, color | (guint32)0x000000FF); // put alpha to max value