summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2008-09-01 15:45:39 +0000
committercilix42 <cilix42@users.sourceforge.net>2008-09-01 15:45:39 +0000
commit905801788180beeee0671ba4151cce6b8492a4be (patch)
treedb881574159216c10229aa00bc592ab708dcb0a8 /src
parentFixed missing return of value and misc return cleanup. Should be the proper f... (diff)
downloadinkscape-905801788180beeee0671ba4151cce6b8492a4be.tar.gz
inkscape-905801788180beeee0671ba4151cce6b8492a4be.zip
Move single-dot-creation function to a better location (and rename it accordingly)
(bzr r6746)
Diffstat (limited to 'src')
-rw-r--r--src/draw-context.cpp59
-rw-r--r--src/draw-context.h1
-rw-r--r--src/pen-context.cpp2
-rw-r--r--src/pencil-context.cpp2
-rw-r--r--src/sp-path.cpp60
-rw-r--r--src/sp-path.h2
6 files changed, 62 insertions, 64 deletions
diff --git a/src/draw-context.cpp b/src/draw-context.cpp
index 6b98c17e5..266c6a961 100644
--- a/src/draw-context.cpp
+++ b/src/draw-context.cpp
@@ -792,6 +792,65 @@ spdc_free_colors(SPDrawContext *dc)
}
}
+/* Create a single dot represented by a circle */
+void spdc_create_single_dot(SPEventContext *ec, NR::Point const &pt, char const *tool, guint event_state) {
+ g_return_if_fail(!strcmp(tool, "tools.freehand.pen") || !strcmp(tool, "tools.freehand.pencil"));
+
+ SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(ec);
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+ Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
+ repr->setAttribute("sodipodi:type", "arc");
+ SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
+ Inkscape::GC::release(repr);
+
+ /* apply the tool's current style */
+ sp_desktop_apply_style_tool(desktop, repr, tool, false);
+
+ /* find out stroke width (TODO: is there an easier way??) */
+ double stroke_width = 3.0;
+ gchar const *style_str = NULL;
+ style_str = repr->attribute("style");
+ if (style_str) {
+ SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT);
+ sp_style_merge_from_style_string(style, style_str);
+ stroke_width = style->stroke_width.computed;
+ style->stroke_width.computed = 0;
+ sp_style_unref(style);
+ }
+ /* unset stroke and set fill color to former stroke color */
+ gchar * str;
+ str = g_strdup_printf("fill:#%06x;stroke:none;", sp_desktop_get_color_tool(desktop, tool, false) >> 8);
+ repr->setAttribute("style", str);
+ g_free(str);
+
+ /* put the circle where the mouse click occurred and set the diameter to the
+ current stroke width, multiplied by the amount specified in the preferences */
+ NR::Matrix const i2d (sp_item_i2d_affine (item));
+ NR::Point pp = pt * i2d;
+ double rad = 0.5 * prefs_get_double_attribute(tool, "dot-size", 3.0);
+ if (event_state & GDK_MOD1_MASK) {
+ /* TODO: We vary the dot size between 0.5*rad and 1.5*rad, where rad is the dot size
+ as specified in prefs. Very simple, but it might be sufficient in practice. If not,
+ we need to devise something more sophisticated. */
+ double s = g_random_double_range(-0.5, 0.5);
+ rad *= (1 + s);
+ }
+ if (event_state & GDK_SHIFT_MASK) {
+ // double the point size
+ rad *= 2;
+ }
+
+ sp_repr_set_svg_double (repr, "sodipodi:cx", pp[NR::X]);
+ sp_repr_set_svg_double (repr, "sodipodi:cy", pp[NR::Y]);
+ sp_repr_set_svg_double (repr, "sodipodi:rx", rad * stroke_width);
+ sp_repr_set_svg_double (repr, "sodipodi:ry", rad * stroke_width);
+ item->updateRepr();
+
+ sp_desktop_selection(desktop)->set(item);
+
+ desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating single dot"));
+ sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, _("Create single dot"));
+}
/*
Local Variables:
diff --git a/src/draw-context.h b/src/draw-context.h
index 35f7659de..42b270b82 100644
--- a/src/draw-context.h
+++ b/src/draw-context.h
@@ -88,6 +88,7 @@ void spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed);
void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, NR::Point const &o, guint state);
void spdc_endpoint_snap_free(SPEventContext const *ec, NR::Point &p, guint state);
void spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item);
+void spdc_create_single_dot(SPEventContext *ec, NR::Point const &pt, char const *tool, guint event_state);
#endif
diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index 2d1a48d3a..12253632d 100644
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
@@ -465,7 +465,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
if (pc->npoints == 0) {
if (bevent.state & GDK_CONTROL_MASK) {
- freehand_create_single_dot(event_context, event_dt, "tools.freehand.pen", bevent.state);
+ spdc_create_single_dot(event_context, event_dt, "tools.freehand.pen", bevent.state);
ret = TRUE;
break;
}
diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp
index cb1039119..b6231f7cb 100644
--- a/src/pencil-context.cpp
+++ b/src/pencil-context.cpp
@@ -241,7 +241,7 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve
default:
/* Set first point of sequence */
if (bevent.state & GDK_CONTROL_MASK) {
- freehand_create_single_dot(event_context, from_2geom(p), "tools.freehand.pencil", bevent.state);
+ spdc_create_single_dot(event_context, from_2geom(p), "tools.freehand.pencil", bevent.state);
ret = true;
break;
}
diff --git a/src/sp-path.cpp b/src/sp-path.cpp
index 427a7d6cf..731ecce64 100644
--- a/src/sp-path.cpp
+++ b/src/sp-path.cpp
@@ -477,66 +477,6 @@ sp_path_get_curve_reference (SPPath *path)
}
}
-/* Create a single dot represented by a circle */
-void freehand_create_single_dot(SPEventContext *ec, NR::Point const &pt, char const *tool, guint event_state) {
- g_return_if_fail(!strcmp(tool, "tools.freehand.pen") || !strcmp(tool, "tools.freehand.pencil"));
-
- SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(ec);
- Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
- Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
- repr->setAttribute("sodipodi:type", "arc");
- SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
- Inkscape::GC::release(repr);
-
- /* apply the tool's current style */
- sp_desktop_apply_style_tool(desktop, repr, tool, false);
-
- /* find out stroke width (TODO: is there an easier way??) */
- double stroke_width = 3.0;
- gchar const *style_str = NULL;
- style_str = repr->attribute("style");
- if (style_str) {
- SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT);
- sp_style_merge_from_style_string(style, style_str);
- stroke_width = style->stroke_width.computed;
- style->stroke_width.computed = 0;
- sp_style_unref(style);
- }
- /* unset stroke and set fill color to former stroke color */
- gchar * str;
- str = g_strdup_printf("fill:#%06x;stroke:none;", sp_desktop_get_color_tool(desktop, tool, false) >> 8);
- repr->setAttribute("style", str);
- g_free(str);
-
- /* put the circle where the mouse click occurred and set the diameter to the
- current stroke width, multiplied by the amount specified in the preferences */
- NR::Matrix const i2d (sp_item_i2d_affine (item));
- NR::Point pp = pt * i2d;
- double rad = 0.5 * prefs_get_double_attribute(tool, "dot-size", 3.0);
- if (event_state & GDK_MOD1_MASK) {
- /* TODO: We vary the dot size between 0.5*rad and 1.5*rad, where rad is the dot size
- as specified in prefs. Very simple, but it might be sufficient in practice. If not,
- we need to devise something more sophisticated. */
- double s = g_random_double_range(-0.5, 0.5);
- rad *= (1 + s);
- }
- if (event_state & GDK_SHIFT_MASK) {
- // double the point size
- rad *= 2;
- }
-
- sp_repr_set_svg_double (repr, "sodipodi:cx", pp[NR::X]);
- sp_repr_set_svg_double (repr, "sodipodi:cy", pp[NR::Y]);
- sp_repr_set_svg_double (repr, "sodipodi:rx", rad * stroke_width);
- sp_repr_set_svg_double (repr, "sodipodi:ry", rad * stroke_width);
- item->updateRepr();
-
- sp_desktop_selection(desktop)->set(item);
-
- desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating single dot"));
- sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, _("Create single dot"));
-}
-
/*
Local Variables:
mode:c++
diff --git a/src/sp-path.h b/src/sp-path.h
index 27e09c704..bf294c37c 100644
--- a/src/sp-path.h
+++ b/src/sp-path.h
@@ -39,8 +39,6 @@ SPCurve* sp_path_get_original_curve (SPPath *path);
SPCurve* sp_path_get_curve_for_edit (SPPath *path);
const SPCurve* sp_path_get_curve_reference (SPPath *path);
-void freehand_create_single_dot(SPEventContext *ec, NR::Point const &pt, char const *tool, guint event_state);
-
#endif
/*