index d4a78f265ca95e5c88c0d33a68afa798afd20995..81e017f12792a048eb4095bd7e7f32007bc5ace3 100644 (file)
#include "desktop.h"
#include "../document.h"
+#include "prefs-utils.h"
#include "canvas-grid.h"
#include "canvas-axonomgrid.h"
namespace Inkscape {
-#define DEFAULTGRIDCOLOR 0x0000FF20
-#define DEFAULTGRIDEMPCOLOR 0x0000FF40
-
static gchar const *const grid_name[] = {
N_("Rectangular grid"),
N_("Axonometric grid")
if (!grid_canvasitem_type) {
GtkTypeInfo grid_canvasitem_info = {
- "GridCanvasItem",
+ (gchar *)"GridCanvasItem",
sizeof (GridCanvasItem),
sizeof (GridCanvasItemClass),
(GtkClassInitFunc) grid_canvasitem_class_init,
@@ -159,7 +157,7 @@ grid_canvasitem_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i
};
CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type)
- : namelabel("", Gtk::ALIGN_CENTER), visible(true), gridtype(type)
+ : visible(true), gridtype(type)
{
repr = in_repr;
doc = in_doc;
@@ -169,22 +167,6 @@ CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocume
namedview = nv;
canvasitems = NULL;
-
- Glib::ustring str("<b>");
- str += getName();
- str += "</b>";
- namelabel.set_markup(str);
- vbox.pack_start(namelabel, true, true);
-
- _rcb_visible.init ( _("_Visible"),
- _("Determines whether the grid is displayed or not. Objects are still snapped to invisible grids."),
- "visible", _wr, false, repr, doc);
- vbox.pack_start(*dynamic_cast<Gtk::Widget*>(_rcb_visible._button), true, true);
-
- _rcb_snap_enabled.init ( _("_Snapping enabled"),
- _("Determines whether to snap to this grid or not. Can be 'on' for invisible grids."),
- "snap_enabled", _wr, false, repr, doc);
- vbox.pack_start(*dynamic_cast<Gtk::Widget*>(_rcb_snap_enabled._button), true, true);
}
CanvasGrid::~CanvasGrid()
@@ -272,7 +254,7 @@ CanvasGrid::writeNewGridToRepr(Inkscape::XML::Node * repr, SPDocument * doc, Gri
newnode->setAttribute("type", getSVGName(gridtype));
repr->appendChild(newnode);
-// Inkscape::GC::release(repr); FIX THIS. THIS SHOULD BE HERE!!!
+ Inkscape::GC::release(newnode);
sp_document_done(doc, SP_VERB_DIALOG_NAMEDVIEW, _("Create new grid"));
}
return item;
}
+Gtk::Widget *
+CanvasGrid::newWidget()
+{
+ Gtk::VBox * vbox = Gtk::manage( new Gtk::VBox() );
+ Gtk::Label * namelabel = Gtk::manage(new Gtk::Label("", Gtk::ALIGN_CENTER) );
+
+ Glib::ustring str("<b>");
+ str += getName();
+ str += "</b>";
+ namelabel->set_markup(str);
+ vbox->pack_start(*namelabel, true, true);
+
+ Inkscape::UI::Widget::RegisteredCheckButton * _rcb_enabled = Gtk::manage(
+ new Inkscape::UI::Widget::RegisteredCheckButton( _("_Enabled"),
+ _("Determines whether to snap to this grid or not. Can be 'on' for invisible grids."),
+ "enabled", _wr, false, repr, doc) );
+ Inkscape::UI::Widget::RegisteredCheckButton * _rcb_visible = Gtk::manage(
+ new Inkscape::UI::Widget::RegisteredCheckButton( _("_Visible"),
+ _("Determines whether the grid is displayed or not. Objects are still snapped to invisible grids."),
+ "visible", _wr, true, repr, doc) );
+
+ vbox->pack_start(*_rcb_enabled, true, true);
+ vbox->pack_start(*_rcb_visible, true, true);
+ Gtk::Widget * gridwdg = newSpecificWidget();
+ vbox->pack_start(*gridwdg, true, true);
+
+ std::list<Gtk::Widget*> slaves;
+ slaves.push_back(_rcb_visible);
+ slaves.push_back(gridwdg);
+ _rcb_enabled->setSlaveWidgets(slaves);
+
+ // set widget values
+ _rcb_visible->setActive(visible);
+ if (snapper != NULL) {
+ _rcb_enabled->setActive(snapper->getEnabled());
+ }
+
+ return dynamic_cast<Gtk::Widget *> (vbox);
+}
+
void
CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gchar const *oldval, gchar const *newval, bool is_interactive, void *data)
{
@@ -336,7 +358,7 @@ CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gc
((CanvasGrid*) data)->onReprAttrChanged(repr, key, oldval, newval, is_interactive);
}
-bool CanvasGrid::isSnapEnabled()
+bool CanvasGrid::isEnabled()
{
if (snapper == NULL) {
return false;
@@ -391,74 +413,23 @@ attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int
}
CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc)
- : CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR), table(1, 1)
-{
- origin[NR::X] = origin[NR::Y] = 0.0;
- color = DEFAULTGRIDCOLOR;
- empcolor = DEFAULTGRIDEMPCOLOR;
- empspacing = 5;
- spacing[NR::X] = spacing[NR::Y] = 1.0;
- gridunit = &sp_unit_get_by_id(SP_UNIT_PX);
- render_dotted = false;
+ : CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR)
+{
+ gridunit = sp_unit_get_by_abbreviation( prefs_get_string_attribute("options.grids.xy", "units") );
+ if (!gridunit)
+ gridunit = &sp_unit_get_by_id(SP_UNIT_PX);
+ origin[NR::X] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.xy", "origin_x", 0.0), *(gridunit) );
+ origin[NR::Y] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.xy", "origin_y", 0.0), *(gridunit) );
+ color = prefs_get_int_attribute("options.grids.xy", "color", 0x0000ff20);
+ empcolor = prefs_get_int_attribute("options.grids.xy", "empcolor", 0x0000ff40);
+ empspacing = prefs_get_int_attribute("options.grids.xy", "empspacing", 5);
+ spacing[NR::X] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.xy", "spacing_x", 0.0), *(gridunit) );
+ spacing[NR::Y] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.xy", "spacing_y", 0.0), *(gridunit) );
+ render_dotted = prefs_get_int_attribute ("options.grids.xy", "dotted", 0) == 1;
snapper = new CanvasXYGridSnapper(this, namedview, 0);
- // initialize widgets:
- vbox.set_border_width(2);
- table.set_spacings(2);
- vbox.pack_start(table, false, false, 0);
-
- Inkscape::UI::Widget::ScalarUnit * sutemp;
- _rumg.init (_("Grid _units:"), "units", _wr, repr, doc);
- _rsu_ox.init (_("_Origin X:"), _("X coordinate of grid origin"),
- "originx", _rumg, _wr, repr, doc);
- sutemp = _rsu_ox.getSU();
- sutemp->setDigits(4);
- sutemp->setIncrements(0.1, 1.0);
- _rsu_oy.init (_("O_rigin Y:"), _("Y coordinate of grid origin"),
- "originy", _rumg, _wr, repr, doc);
- sutemp = _rsu_oy.getSU();
- sutemp->setDigits(4);
- sutemp->setIncrements(0.1, 1.0);
- _rsu_sx.init (_("Spacing _X:"), _("Distance between vertical grid lines"),
- "spacingx", _rumg, _wr, repr, doc);
- sutemp = _rsu_sx.getSU();
- sutemp->setDigits(4);
- sutemp->setIncrements(0.1, 1.0);
- _rsu_sy.init (_("Spacing _Y:"), _("Distance between horizontal grid lines"),
- "spacingy", _rumg, _wr, repr, doc);
- sutemp = _rsu_sy.getSU();
- sutemp->setDigits(4);
- sutemp->setIncrements(0.1, 1.0);
- _rcp_gcol.init (_("Grid line _color:"), _("Grid line color"),
- _("Color of grid lines"), "color", "opacity", _wr, repr, doc);
- _rcp_gmcol.init (_("Ma_jor grid line color:"), _("Major grid line color"),
- _("Color of the major (highlighted) grid lines"),
- "empcolor", "empopacity", _wr, repr, doc);
- _rsi.init (_("_Major grid line every:"), _("lines"), "empspacing", _wr, repr, doc);
- _rcb_dotted.init ( _("_Show dots instead of lines"),
- _("If set, displays dots at gridpoints instead of gridlines"),
- "dotted", _wr, false, repr, doc);
-
- Gtk::Widget const *const widget_array[] = {
- _rumg._label, _rumg._sel,
- 0, _rsu_ox.getSU(),
- 0, _rsu_oy.getSU(),
- 0, _rsu_sx.getSU(),
- 0, _rsu_sy.getSU(),
- _rcp_gcol._label, _rcp_gcol._cp,
- 0, 0,
- _rcp_gmcol._label, _rcp_gmcol._cp,
- _rsi._label, &_rsi._hbox,
- 0, _rcb_dotted._button,
- };
-
- attach_all (table, widget_array, sizeof(widget_array));
-
- vbox.show();
-
if (repr) readRepr();
- updateWidgets();
}
CanvasXYGrid::~CanvasXYGrid ()
@param widget Widget associated with the scalar.
*/
static void validateScalar(double oldVal,
- double* pTarget,
- Inkscape::UI::Widget::RegisteredScalarUnit& widget)
+ double* pTarget)
{
// Avoid nullness.
if ( pTarget == NULL )
// Reset the scalar and associated widget to the old value.
*pTarget = oldVal;
- widget.setValue( *pTarget);
} //if
} //validateScalar
@param widget Widget associated with the int.
*/
static void validateInt(gint oldVal,
- gint* pTarget,
- Inkscape::UI::Widget::RegisteredSuffixedInteger& widget)
+ gint* pTarget)
{
// Avoid nullness.
if ( pTarget == NULL )
// Reset the int and associated widget to the old value.
*pTarget = oldVal;
- widget.setValue( *pTarget);
} //if
} //validateInt
if ( (value = repr->attribute("spacingx")) ) {
double oldVal = spacing[NR::X];
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[NR::X], &gridunit);
- validateScalar( oldVal, &spacing[NR::X], _rsu_sx );
+ validateScalar( oldVal, &spacing[NR::X]);
spacing[NR::X] = sp_units_get_pixels(spacing[NR::X], *(gridunit));
}
if ( (value = repr->attribute("spacingy")) ) {
double oldVal = spacing[NR::Y];
sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[NR::Y], &gridunit);
- validateScalar( oldVal, &spacing[NR::Y], _rsu_sy );
+ validateScalar( oldVal, &spacing[NR::Y]);
spacing[NR::Y] = sp_units_get_pixels(spacing[NR::Y], *(gridunit));
}
if ( (value = repr->attribute("empspacing")) ) {
gint oldVal = empspacing;
empspacing = atoi(value);
- validateInt( oldVal, &empspacing, _rsi );
+ validateInt( oldVal, &empspacing);
}
if ( (value = repr->attribute("dotted")) ) {
visible = (strcmp(value,"true") == 0);
}
- if ( (value = repr->attribute("snap_enabled")) ) {
+ if ( (value = repr->attribute("enabled")) ) {
g_assert(snapper != NULL);
snapper->setEnabled(strcmp(value,"true") == 0);
}
@@ -680,10 +647,97 @@ CanvasXYGrid::onReprAttrChanged(Inkscape::XML::Node */*repr*/, gchar const */*ke
-Gtk::Widget &
-CanvasXYGrid::getWidget()
+Gtk::Widget *
+CanvasXYGrid::newSpecificWidget()
{
- return vbox;
+ Gtk::Table * table = Gtk::manage( new Gtk::Table(1,1) );
+
+ Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu(
+ _("Grid _units:"), "units", _wr, repr, doc) );
+ Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
+ _("_Origin X:"), _("X coordinate of grid origin"), "originx", *_rumg, _wr, repr, doc) );
+ Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
+ _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy", *_rumg, _wr, repr, doc) );
+ Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sx = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
+ _("Spacing _X:"), _("Distance between vertical grid lines"), "spacingx", *_rumg, _wr, repr, doc) );
+ 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::RegisteredColorPicker *_rcp_gcol = Gtk::manage(
+ new Inkscape::UI::Widget::RegisteredColorPicker(
+ _("Grid line _color:"), _("Grid line color"), _("Color of grid lines"),
+ "color", "opacity", _wr, repr, doc));
+
+ Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gmcol = Gtk::manage(
+ new Inkscape::UI::Widget::RegisteredColorPicker(
+ _("Ma_jor grid line color:"), _("Major grid line color"),
+ _("Color of the major (highlighted) grid lines"), "empcolor", "empopacity",
+ _wr, repr, doc));
+
+ Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = Gtk::manage( new Inkscape::UI::Widget::RegisteredSuffixedInteger(
+ _("_Major grid line every:"), "", _("lines"), "empspacing", _wr, repr, doc) );
+
+ table->set_spacings(2);
+
+_wr.setUpdating (true);
+
+ _rsu_ox->setDigits(4);
+ _rsu_ox->setIncrements(0.1, 1.0);
+
+ _rsu_oy->setDigits(4);
+ _rsu_oy->setIncrements(0.1, 1.0);
+
+ _rsu_sx->setDigits(4);
+ _rsu_sx->setIncrements(0.1, 1.0);
+
+ _rsu_sy->setDigits(4);
+ _rsu_sy->setIncrements(0.1, 1.0);
+
+ Inkscape::UI::Widget::RegisteredCheckButton * _rcb_dotted = Gtk::manage(
+ new Inkscape::UI::Widget::RegisteredCheckButton( _("_Show dots instead of lines"),
+ _("If set, displays dots at gridpoints instead of gridlines"),
+ "dotted", _wr, false, repr, doc) );
+_wr.setUpdating (false);
+
+ Gtk::Widget const *const widget_array[] = {
+ 0, _rumg,
+ 0, _rsu_ox,
+ 0, _rsu_oy,
+ 0, _rsu_sx,
+ 0, _rsu_sy,
+ _rcp_gcol->_label, _rcp_gcol,
+ 0, 0,
+ _rcp_gmcol->_label, _rcp_gmcol,
+ 0, _rsi,
+ 0, _rcb_dotted,
+ };
+
+ attach_all (*table, widget_array, sizeof(widget_array));
+
+ // set widget values
+ _rumg->setUnit (gridunit);
+
+ gdouble val;
+ val = origin[NR::X];
+ val = sp_pixels_get_units (val, *(gridunit));
+ _rsu_ox->setValue (val);
+ val = origin[NR::Y];
+ val = sp_pixels_get_units (val, *(gridunit));
+ _rsu_oy->setValue (val);
+ val = spacing[NR::X];
+ double gridx = sp_pixels_get_units (val, *(gridunit));
+ _rsu_sx->setValue (gridx);
+ val = spacing[NR::Y];
+ double gridy = sp_pixels_get_units (val, *(gridunit));
+ _rsu_sy->setValue (gridy);
+
+ _rcp_gcol->setRgba32 (color);
+ _rcp_gmcol->setRgba32 (empcolor);
+ _rsi->setValue (empspacing);
+
+ _rcb_dotted->setActive(render_dotted);
+
+ return table;
}
void
CanvasXYGrid::updateWidgets()
{
+/*
if (_wr.isUpdating()) return;
_wr.setUpdating (true);
_rcb_visible.setActive(visible);
if (snapper != NULL) {
- _rcb_snap_enabled.setActive(snapper->getEnabled());
+ _rcb_enabled.setActive(snapper->getEnabled());
}
_rumg.setUnit (gridunit);
_wr.setUpdating (false);
return;
+*/
}
a = NR_RGBA32_A (rgba);
x0 = MAX (buf->rect.x0, xs);
x1 = MIN (buf->rect.x1, xe + 1);
- p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x0 - buf->rect.x0) * 3;
+ p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x0 - buf->rect.x0) * 4;
for (x = x0; x < x1; x++) {
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
p[1] = NR_COMPOSEN11_1111 (g, a, p[1]);
p[2] = NR_COMPOSEN11_1111 (b, a, p[2]);
- p += 3;
+ p += 4;
}
}
}
a = NR_RGBA32_A (rgba);
y0 = MAX (buf->rect.y0, ys);
y1 = MIN (buf->rect.y1, ye + 1);
- p = buf->buf + (y0 - buf->rect.y0) * buf->buf_rowstride + (x - buf->rect.x0) * 3;
+ p = buf->buf + (y0 - buf->rect.y0) * buf->buf_rowstride + (x - buf->rect.x0) * 4;
for (y = y0; y < y1; y++) {
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
p[1] = NR_COMPOSEN11_1111 (g, a, p[1]);
g = NR_RGBA32_G (rgba);
b = NR_RGBA32_B (rgba);
a = NR_RGBA32_A (rgba);
- p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x - buf->rect.x0) * 3;
+ p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x - buf->rect.x0) * 4;
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
p[1] = NR_COMPOSEN11_1111 (g, a, p[1]);
p[2] = NR_COMPOSEN11_1111 (b, a, p[2]);
gdouble const syg = floor ((buf->rect.y0 - ow[NR::Y]) / sw[NR::Y]) * sw[NR::Y] + ow[NR::Y];
gint const ylinestart = (gint) Inkscape::round((syg - ow[NR::Y]) / sw[NR::Y]);
+ //set correct coloring, depending preference (when zoomed out, always major coloring or minor coloring)
+ guint32 _empcolor;
+ bool no_emp_when_zoomed_out = prefs_get_int_attribute ("options.grids", "no_emphasize_when_zoomedout", 0) == 1;
+ if( (scaled[NR::X] || scaled[NR::Y]) && no_emp_when_zoomed_out ) {
+ _empcolor = color;
+ } else {
+ _empcolor = empcolor;
+ }
+
if (!render_dotted) {
gint ylinenum;
gdouble y;
for (y = syg, ylinenum = ylinestart; y < buf->rect.y1; y += sw[NR::Y], ylinenum++) {
gint const y0 = (gint) Inkscape::round(y);
-
- if (!scaled[NR::Y] && (ylinenum % empspacing) == 0) {
- grid_hline (buf, y0, buf->rect.x0, buf->rect.x1 - 1, empcolor);
- } else {
+ if (!scaled[NR::Y] && (ylinenum % empspacing) != 0) {
grid_hline (buf, y0, buf->rect.x0, buf->rect.x1 - 1, color);
+ } else {
+ grid_hline (buf, y0, buf->rect.x0, buf->rect.x1 - 1, _empcolor);
}
}
gdouble x;
for (x = sxg, xlinenum = xlinestart; x < buf->rect.x1; x += sw[NR::X], xlinenum++) {
gint const ix = (gint) Inkscape::round(x);
- if (!scaled[NR::X] && (xlinenum % empspacing) == 0) {
- grid_vline (buf, ix, buf->rect.y0, buf->rect.y1, empcolor);
- } else {
+ if (!scaled[NR::X] && (xlinenum % empspacing) != 0) {
grid_vline (buf, ix, buf->rect.y0, buf->rect.y1, color);
+ } else {
+ grid_vline (buf, ix, buf->rect.y0, buf->rect.y1, _empcolor);
}
}
} else {
gdouble x;
for (x = sxg, xlinenum = xlinestart; x < buf->rect.x1; x += sw[NR::X], xlinenum++) {
gint const ix = (gint) Inkscape::round(x);
- if ( (!scaled[NR::X] && (xlinenum % empspacing) == 0)
- || (!scaled[NR::Y] && (ylinenum % empspacing) == 0) )
+ if ( (!scaled[NR::X] && (xlinenum % empspacing) != 0)
+ || (!scaled[NR::Y] && (ylinenum % empspacing) != 0)
+ || ((scaled[NR::X] || scaled[NR::Y]) && no_emp_when_zoomed_out) )
{
- grid_dot (buf, ix, iy, empcolor | (guint32)0x000000FF); // put alpha to max value
+ grid_dot (buf, ix, iy, color | (guint32)0x000000FF); // put alpha to max value
} else {
- grid_dot (buf, ix, iy, color | (guint32)0x000000FF); // put alpha to max value
+ gint const pitch = 1;
+ grid_dot (buf, ix-pitch, iy, _empcolor);
+ grid_dot (buf, ix+pitch, iy, _empcolor);
+
+ grid_dot (buf, ix, iy, _empcolor | (guint32)0x000000FF); // put alpha to max value
+
+ grid_dot (buf, ix, iy-pitch, _empcolor);
+ grid_dot (buf, ix, iy+pitch, _empcolor);
}
}
void CanvasXYGridSnapper::_addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, NR::Point const point_on_line) const
{
- SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, normal_to_line, point_on_line);
+ SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);
sc.grid_lines.push_back(dummy);
}