~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/display/canvas-grid.cpp

  • Committer: cilix42
  • Date: 2008-09-18 17:48:42 UTC
  • Revision ID: cilix42@users.sourceforge.net-20080918174842-1ad33a7d7gqhv2hq
Next roud of NR ==> Geom conversion

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
static void grid_canvasitem_init (GridCanvasItem *grid);
53
53
static void grid_canvasitem_destroy (GtkObject *object);
54
54
 
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);
57
57
 
58
58
static SPCanvasItemClass * parent_class;
124
124
}
125
125
 
126
126
static void
127
 
grid_canvasitem_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
 
127
grid_canvasitem_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
128
128
{
129
129
    GridCanvasItem *gridcanvasitem = INKSCAPE_GRID_CANVASITEM (item);
130
130
 
419
419
    gridunit = sp_unit_get_by_abbreviation( prefs->getString("options.grids.xy", "units").data() );
420
420
    if (!gridunit)
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);
430
430
 
431
431
    snapper = new CanvasXYGridSnapper(this, &namedview->snap_manager, 0);
568
568
{
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));
573
573
    }
574
574
 
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));
578
578
    }
579
579
 
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));
585
585
 
586
586
    }
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));
592
592
 
593
593
    }
594
594
 
719
719
    _rumg->setUnit (gridunit);
720
720
 
721
721
    gdouble val;
722
 
    val = origin[NR::X];
 
722
    val = origin[Geom::X];
723
723
    val = sp_pixels_get_units (val, *(gridunit));
724
724
    _rsu_ox->setValue (val);
725
 
    val = origin[NR::Y];
 
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);
734
734
 
761
761
    _rumg.setUnit (gridunit);
762
762
 
763
763
    gdouble val;
764
 
    val = origin[NR::X];
 
764
    val = origin[Geom::X];
765
765
    val = sp_pixels_get_units (val, *(gridunit));
766
766
    _rsu_ox.setValue (val);
767
 
    val = origin[NR::Y];
 
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);
776
776
 
789
789
 
790
790
 
791
791
void
792
 
CanvasXYGrid::Update (NR::Matrix const &affine, unsigned int /*flags*/)
 
792
CanvasXYGrid::Update (Geom::Matrix const &affine, unsigned int /*flags*/)
793
793
{
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]);
797
797
 
798
798
    for(int dim = 0; dim < 2; dim++) {
799
799
        gint scaling_factor = empspacing;
881
881
void
882
882
CanvasXYGrid::Render (SPCanvasBuf *buf)
883
883
{
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]);
888
888
 
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;
895
895
    } else {
896
896
        _empcolor = empcolor;
899
899
    if (!render_dotted) {
900
900
        gint ylinenum;
901
901
        gdouble y;
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);
906
906
            } else {
907
907
                grid_hline (buf, y0, buf->rect.x0, buf->rect.x1 - 1, _empcolor);
910
910
 
911
911
        gint xlinenum;
912
912
        gdouble x;
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);
917
917
            } else {
918
918
                grid_vline (buf, ix, buf->rect.y0, buf->rect.y1, _empcolor);
921
921
    } else {
922
922
        gint ylinenum;
923
923
        gdouble y;
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);
926
926
 
927
927
            gint xlinenum;
928
928
            gdouble x;
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) )
934
934
                {
935
935
                    grid_dot (buf, ix, iy, color | (guint32)0x000000FF); // put alpha to max value
936
936
                } else {
949
949
    }
950
950
}
951
951
 
952
 
CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager const *sm, NR::Coord const d) : LineSnapper(sm, d)
 
952
CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager const *sm, Geom::Coord const d) : LineSnapper(sm, d)
953
953
{
954
954
    this->grid = grid;
955
955
}