X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fextension%2Finternal%2Fgrid.cpp;h=061035eace22f8e733b9b25606f33c372771a8cd;hb=e900b46f3a8707abddd24803da7f25eecf09a942;hp=f74c652aa20f7f870d39c453c7a41bbf3121f2f2;hpb=6b15695578f07a3f72c4c9475c1a261a3021472a;p=inkscape.git diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index f74c652aa..061035eac 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -4,10 +4,8 @@ A plug-in to add a grid creation effect into Inkscape. */ /* - * Authors: - * Ted Gould - * - * Copyright (C) 2004-2005 Authors + * Copyright (C) 2004-2005 Ted Gould + * Copyright (C) 2007 MenTaLguY * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -17,8 +15,12 @@ #include #include "desktop.h" +#include "desktop-handles.h" #include "selection.h" #include "sp-object.h" +#include "util/glib-list-iterators.h" + +#include "svg/path-string.h" #include "extension/effect.h" #include "extension/system.h" @@ -42,6 +44,30 @@ Grid::load (Inkscape::Extension::Extension *module) return TRUE; } +namespace { + +Glib::ustring build_lines(int axis, NR::Rect bounding_area, + float offset, float spacing) +{ + NR::Point point_offset(0.0, 0.0); + point_offset[axis] = offset; + + SVG::PathString path_data; + for (NR::Point start_point = bounding_area.min(); + start_point[axis] + offset <= (bounding_area.max())[axis]; + start_point[axis] += spacing) { + NR::Point end_point = start_point; + end_point[1-axis] = (bounding_area.max())[1-axis]; + + path_data.moveTo(start_point + point_offset) + .lineTo(end_point + point_offset); + } + + return path_data; +} + +} + /** \brief This actually draws the grid. \param module The effect that was called (unused) @@ -60,7 +86,10 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc NR::Point(sp_document_width(doc), sp_document_height(doc))); } else { - bounding_area = selection->bounds(); + NR::Maybe bounds = selection->bounds(); + if (bounds) { + bounding_area = *bounds; + } gdouble doc_height = sp_document_height(document->doc()); NR::Rect temprec = NR::Rect(NR::Point(bounding_area.min()[NR::X], doc_height - bounding_area.min()[NR::Y]), @@ -69,67 +98,21 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc bounding_area = temprec; } - - float xspacing = module->get_param_float("xspacing"); - float yspacing = module->get_param_float("yspacing"); + float spacings[2] = { module->get_param_float("xspacing"), + module->get_param_float("yspacing") }; float line_width = module->get_param_float("lineWidth"); - float xoffset = module->get_param_float("xoffset"); - float yoffset = module->get_param_float("yoffset"); - - // std::cout << "Spacing: " << spacing; - // std::cout << " Line Width: " << line_width; - // std::cout << " Offset: " << offset << std::endl; - - Glib::ustring path_data; + float offsets[2] = { module->get_param_float("xoffset"), + module->get_param_float("yoffset") }; - for (NR::Point start_point = bounding_area.min(); - start_point[NR::X] + xoffset <= (bounding_area.max())[NR::X]; - start_point[NR::X] += xspacing) { - NR::Point end_point = start_point; - end_point[NR::Y] = (bounding_area.max())[NR::Y]; - gchar floatstring[64]; - - path_data += "M "; - sprintf(floatstring, "%f", start_point[NR::X] + xoffset); - path_data += floatstring; - path_data += " "; - sprintf(floatstring, "%f", start_point[NR::Y]); - path_data += floatstring; - path_data += " L "; - sprintf(floatstring, "%f", end_point[NR::X] + xoffset); - path_data += floatstring; - path_data += " "; - sprintf(floatstring, "%f", end_point[NR::Y]); - path_data += floatstring; - path_data += " "; + Glib::ustring path_data(""); + for ( int axis = 0 ; axis < 2 ; ++axis ) { + path_data += build_lines(axis, bounding_area, + offsets[axis], spacings[axis]); } - for (NR::Point start_point = bounding_area.min(); - start_point[NR::Y] + yoffset <= (bounding_area.max())[NR::Y]; - start_point[NR::Y] += yspacing) { - NR::Point end_point = start_point; - end_point[NR::X] = (bounding_area.max())[NR::X]; - gchar floatstring[64]; - - path_data += "M "; - sprintf(floatstring, "%f", start_point[NR::X]); - path_data += floatstring; - path_data += " "; - sprintf(floatstring, "%f", start_point[NR::Y] + yoffset); - path_data += floatstring; - path_data += " L "; - sprintf(floatstring, "%f", end_point[NR::X]); - path_data += floatstring; - path_data += " "; - sprintf(floatstring, "%f", end_point[NR::Y] + yoffset); - path_data += floatstring; - path_data += " "; - } - - // std::cout << "Path Data: " << path_data << std::endl; - - Inkscape::XML::Node * current_layer = ((SPDesktop *)document)->currentLayer()->repr; - Inkscape::XML::Node * path = sp_repr_new("svg:path"); + Inkscape::XML::Document * xml_doc = sp_document_repr_doc(document->doc()); + Inkscape::XML::Node * current_layer = static_cast(document)->currentLayer()->repr; + Inkscape::XML::Node * path = xml_doc->createElement("svg:path"); path->setAttribute("d", path_data.c_str()); @@ -141,9 +124,6 @@ Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc style += "pt"; path->setAttribute("style", style.c_str()); - // Glib::ustring transform("scale(1.25 1.25)"); - // path->setAttribute("transform", transform.c_str()); - current_layer->appendChild(path); return; @@ -186,71 +166,42 @@ PrefAdjustment::val_changed (void) \param moudule Module which holds the params \param view Unused today - may get style information in the future. - This function builds a VBox, and puts it into a Gtk::Plug. This way - the native window pointer can be pulled out and returned up to be - stuck in a Gtk::Socket further up the call stack. In the Vbox there - are several Hboxes, each one being a spin button to adjust a particular - parameter. The names of the parameters and the labels are all - stored in the arrays in the middle of the function. This makes - the code very generic. This will probably have to change if someone - wants to make this dialog look nicer. + Uses AutoGUI for creating the GUI. */ Gtk::Widget * Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View * view) { - Gtk::VBox * vbox; - vbox = new Gtk::VBox(); - -#define NUM_PREFERENCES 5 - char * labels[NUM_PREFERENCES] = {N_("Line Width"), - N_("Horizontal Spacing"), - N_("Vertical Spacing"), - N_("Horizontal Offset"), - N_("Vertical Offset")}; - char * prefs[NUM_PREFERENCES] = {"lineWidth", - "xspacing", - "yspacing", - "xoffset", - "yoffset"}; + SPDocument * current_document = view->doc(); - for (int i = 0; i < NUM_PREFERENCES; i++) { - Gtk::HBox * hbox = new Gtk::HBox(); + using Inkscape::Util::GSListConstIterator; + GSListConstIterator selected = sp_desktop_selection((SPDesktop *)view)->itemList(); + Inkscape::XML::Node * first_select = NULL; + if (selected != NULL) + first_select = SP_OBJECT_REPR(*selected); - Gtk::Label * label = new Gtk::Label(_(labels[i]), Gtk::ALIGN_LEFT); - label->show(); - hbox->pack_start(*label, true, true); - - PrefAdjustment * pref = new PrefAdjustment(module, prefs[i]); - - Gtk::SpinButton * spin = new Gtk::SpinButton(*pref, 0.1, 1); - spin->show(); - hbox->pack_start(*spin, false, false); - - hbox->show(); - - vbox->pack_start(*hbox, true, true); - } -#undef NUM_PREFERENCES - - vbox->show(); - - return vbox; + return module->autogui(current_document, first_select); } +#include "clear-n_.h" + void Grid::init (void) { Inkscape::Extension::build_from_mem( "\n" - "Grid\n" + "" N_("Grid") "\n" "org.inkscape.effect.grid\n" - "1.0\n" - "10.0\n" - "10.0\n" - "5.0\n" - "5.0\n" + "1.0\n" + "10.0\n" + "10.0\n" + "5.0\n" + "5.0\n" "\n" "all\n" + "\n" + "\n" + "\n" + "" N_("Draw a path which is a grid") "\n" "\n" "\n", new Grid()); return;