From 1ed822fb016bc35dbe5bd8601ed2bca74ff8cf60 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Thu, 29 Nov 2007 23:31:22 +0000 Subject: [PATCH] add visibility and snap_enabled checkbuttons for grids. visibility already works, snap_enabled not yet. --- src/display/canvas-axonomgrid.cpp | 12 +++++++++- src/display/canvas-axonomgrid.h | 3 --- src/display/canvas-grid.cpp | 39 +++++++++++++++++++++++++------ src/display/canvas-grid.h | 15 ++++++++---- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 654dcf903..55430bdaf 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -386,6 +386,14 @@ CanvasAxonomGrid::readRepr() empspacing = atoi(value); } + if ( (value = repr->attribute("visible")) ) { + visible = (strcmp(value,"true") == 0); + } + + if ( (value = repr->attribute("snap_enabled")) ) { + snap_enabled = (strcmp(value,"true") == 0); + } + for (GSList *l = canvasitems; l != NULL; l = l->next) { sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) ); } @@ -424,7 +432,9 @@ CanvasAxonomGrid::updateWidgets() _wr.setUpdating (true); - //_rrb_gridtype.setValue (nv->gridtype); + _rcb_visible.setActive(visible); + _rcb_snap_enabled.setActive(snap_enabled); + _rumg.setUnit (gridunit); gdouble val; diff --git a/src/display/canvas-axonomgrid.h b/src/display/canvas-axonomgrid.h index d099de492..2eaec9d6f 100644 --- a/src/display/canvas-axonomgrid.h +++ b/src/display/canvas-axonomgrid.h @@ -78,9 +78,6 @@ private: Inkscape::UI::Widget::RegisteredScalarUnit _rsu_ox, _rsu_oy, _rsu_sy, _rsu_ax, _rsu_az; Inkscape::UI::Widget::RegisteredColorPicker _rcp_gcol, _rcp_gmcol; Inkscape::UI::Widget::RegisteredSuffixedInteger _rsi; - - Inkscape::UI::Widget::Registry _wr; - }; diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 92e0c5096..de9afbfc1 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -7,6 +7,12 @@ * */ +/* As a general comment, I am not exactly proud of how things are done. + * (for example the 'enable' widget and readRepr things) + * It does seem to work however. I intend to clean up and sort things out later, but that can take forever... + * Don't be shy to correct things. + */ + #include "sp-canvas-util.h" #include "display-forward.h" @@ -112,9 +118,10 @@ grid_canvasitem_render (SPCanvasItem * item, SPCanvasBuf * buf) { GridCanvasItem *gridcanvasitem = INKSCAPE_GRID_CANVASITEM (item); - sp_canvas_prepare_buffer (buf); - - if (gridcanvasitem->grid) gridcanvasitem->grid->Render(buf); + if ( gridcanvasitem->grid && gridcanvasitem->grid->isVisible() ) { + sp_canvas_prepare_buffer (buf); + gridcanvasitem->grid->Render(buf); + } } static void @@ -151,7 +158,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_LEFT), gridtype(type) + : namelabel("", Gtk::ALIGN_LEFT), gridtype(type), visible(true), snap_enabled(true) { repr = in_repr; doc = in_doc; @@ -166,7 +173,17 @@ CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocume str += getName(); str += ""; namelabel.set_markup(str); - vbox.pack_start(namelabel,true,true); + 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(_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(_rcb_snap_enabled._button), true, true); } CanvasGrid::~CanvasGrid() @@ -319,7 +336,6 @@ CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gc } - // ########################################################## // CanvasXYGrid @@ -577,8 +593,8 @@ CanvasXYGrid::readRepr() if ( (value = repr->attribute("originx")) ) { sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[NR::X], &gridunit); origin[NR::X] = sp_units_get_pixels(origin[NR::X], *(gridunit)); - } + if ( (value = repr->attribute("originy")) ) { sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[NR::Y], &gridunit); origin[NR::Y] = sp_units_get_pixels(origin[NR::Y], *(gridunit)); @@ -624,6 +640,10 @@ CanvasXYGrid::readRepr() render_dotted = (strcmp(value,"true") == 0); } + if ( (value = repr->attribute("visible")) ) { + visible = (strcmp(value,"true") == 0); + } + for (GSList *l = canvasitems; l != NULL; l = l->next) { sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) ); } @@ -663,6 +683,9 @@ CanvasXYGrid::updateWidgets() _wr.setUpdating (true); + _rcb_visible.setActive(visible); + _rcb_snap_enabled.setActive(snap_enabled); + _rumg.setUnit (gridunit); gdouble val; @@ -683,6 +706,8 @@ CanvasXYGrid::updateWidgets() _rcp_gmcol.setRgba32 (empcolor); _rsi.setValue (empspacing); + _rcb_dotted.setActive(render_dotted); + _wr.setUpdating (false); return; diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index f05d3b5cb..07e27cb4a 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -86,8 +86,8 @@ public: virtual void Update (NR::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 void readRepr() = 0; + virtual void onReprAttrChanged (Inkscape::XML::Node * /*repr*/, const gchar */*key*/, const gchar */*oldval*/, const gchar */*newval*/, bool /*is_interactive*/) = 0; virtual Gtk::Widget & getWidget() = 0; @@ -98,6 +98,9 @@ public: 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 visible; }; + bool isSnapEnabled() { return snap_enabled; }; + protected: CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type); @@ -108,6 +111,12 @@ protected: Gtk::VBox vbox; Gtk::Label namelabel; + Inkscape::UI::Widget::Registry _wr; + Inkscape::UI::Widget::RegisteredCheckButton _rcb_visible; + bool visible; + Inkscape::UI::Widget::RegisteredCheckButton _rcb_snap_enabled; + bool snap_enabled; + GridType gridtype; private: @@ -155,8 +164,6 @@ private: Inkscape::UI::Widget::RegisteredSuffixedInteger _rsi; Inkscape::UI::Widget::RegisteredCheckButton _rcb_dotted; - Inkscape::UI::Widget::Registry _wr; - bool render_dotted; }; -- 2.30.2