summaryrefslogtreecommitdiffstats
path: root/src/draw-context.cpp
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2012-05-03 02:06:15 +0000
committerJon A. Cruz <jon@joncruz.org>2012-05-03 02:06:15 +0000
commit3198928b491fb91cdd177505c051659f89aa4158 (patch)
tree8cf8b51a36ba7e865d3c41984746ae35a26c9e6a /src/draw-context.cpp
parentFind dialog: better user message (diff)
downloadinkscape-3198928b491fb91cdd177505c051659f89aa4158.tar.gz
inkscape-3198928b491fb91cdd177505c051659f89aa4158.zip
Adding base configurable sizing of controls/handles.
(bzr r11316)
Diffstat (limited to 'src/draw-context.cpp')
-rw-r--r--src/draw-context.cpp199
1 files changed, 83 insertions, 116 deletions
diff --git a/src/draw-context.cpp b/src/draw-context.cpp
index d8ce2729d..a5c182410 100644
--- a/src/draw-context.cpp
+++ b/src/draw-context.cpp
@@ -4,6 +4,7 @@
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* Abhishek Sharma
+ * Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2000 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
@@ -42,6 +43,7 @@
#include "sp-namedview.h"
#include "live_effects/lpe-powerstroke.h"
#include "style.h"
+#include "ui/control-manager.h"
#include <gdk/gdkkeysyms.h>
@@ -132,6 +134,12 @@ static void spdc_selection_modified(Inkscape::Selection *sel, guint flags, SPDra
static void spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection *sel);
+/**
+ * Flushes white curve(s) and additional curve into object.
+ *
+ * No cleaning of colored curves - this has to be done by caller
+ * No rereading of white data, so if you cannot rely on ::modified, do it in caller
+ */
static void spdc_flush_white(SPDrawContext *dc, SPCurve *gc);
static void spdc_reset_white(SPDrawContext *dc);
@@ -140,9 +148,7 @@ static void spdc_free_colors(SPDrawContext *dc);
static SPEventContextClass *draw_parent_class;
-
-GType
-sp_draw_context_get_type(void)
+GType sp_draw_context_get_type(void)
{
static GType type = 0;
if (!type) {
@@ -154,15 +160,14 @@ sp_draw_context_get_type(void)
sizeof(SPDrawContext),
4,
(GInstanceInitFunc) sp_draw_context_init,
- NULL, /* value_table */
+ NULL, // value_table
};
type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPDrawContext", &info, (GTypeFlags)0);
}
return type;
}
-static void
-sp_draw_context_class_init(SPDrawContextClass *klass)
+static void sp_draw_context_class_init(SPDrawContextClass *klass)
{
GObjectClass *object_class;
SPEventContextClass *ec_class;
@@ -180,8 +185,7 @@ sp_draw_context_class_init(SPDrawContextClass *klass)
ec_class->root_handler = sp_draw_context_root_handler;
}
-static void
-sp_draw_context_init(SPDrawContext *dc)
+static void sp_draw_context_init(SPDrawContext *dc)
{
dc->attach = FALSE;
@@ -214,8 +218,7 @@ sp_draw_context_init(SPDrawContext *dc)
new (&dc->sel_modified_connection) sigc::connection();
}
-static void
-sp_draw_context_dispose(GObject *object)
+static void sp_draw_context_dispose(GObject *object)
{
SPDrawContext *dc = SP_DRAW_CONTEXT(object);
@@ -236,8 +239,7 @@ sp_draw_context_dispose(GObject *object)
G_OBJECT_CLASS(draw_parent_class)->dispose(object);
}
-static void
-sp_draw_context_setup(SPEventContext *ec)
+static void sp_draw_context_setup(SPEventContext *ec)
{
SPDrawContext *dc = SP_DRAW_CONTEXT(ec);
SPDesktop *dt = ec->desktop;
@@ -248,7 +250,7 @@ sp_draw_context_setup(SPEventContext *ec)
dc->selection = sp_desktop_selection(dt);
- /* Connect signals to track selection changes */
+ // Connect signals to track selection changes
dc->sel_changed_connection = dc->selection->connectChanged(
sigc::bind(sigc::ptr_fun(&spdc_selection_changed), dc)
);
@@ -256,21 +258,24 @@ sp_draw_context_setup(SPEventContext *ec)
sigc::bind(sigc::ptr_fun(&spdc_selection_modified), dc)
);
- /* Create red bpath */
+ // Create red bpath
dc->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->red_bpath), dc->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
- /* Create red curve */
+
+ // Create red curve
dc->red_curve = new SPCurve();
- /* Create blue bpath */
+ // Create blue bpath
dc->blue_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->blue_bpath), dc->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
- /* Create blue curve */
+
+ // Create blue curve
dc->blue_curve = new SPCurve();
- /* Create green curve */
+ // Create green curve
dc->green_curve = new SPCurve();
- /* No green anchor by default */
+
+ // No green anchor by default
dc->green_anchor = NULL;
dc->green_closed = FALSE;
@@ -278,8 +283,7 @@ sp_draw_context_setup(SPEventContext *ec)
spdc_attach_selection(dc, dc->selection);
}
-static void
-sp_draw_context_finish(SPEventContext *ec)
+static void sp_draw_context_finish(SPEventContext *ec)
{
SPDrawContext *dc = SP_DRAW_CONTEXT(ec);
@@ -297,13 +301,11 @@ sp_draw_context_finish(SPEventContext *ec)
spdc_free_colors(dc);
}
-static void
-sp_draw_context_set(SPEventContext */*ec*/, Inkscape::Preferences::Entry */*val*/)
+static void sp_draw_context_set(SPEventContext */*ec*/, Inkscape::Preferences::Entry */*val*/)
{
}
-gint
-sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event)
+gint sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event)
{
gint ret = FALSE;
@@ -336,16 +338,14 @@ sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event)
return ret;
}
-static Glib::ustring const
-tool_name(SPDrawContext *dc)
+static Glib::ustring const tool_name(SPDrawContext *dc)
{
return ( SP_IS_PEN_CONTEXT(dc)
? "/tools/freehand/pen"
: "/tools/freehand/pencil" );
}
-static void
-spdc_paste_curve_as_freehand_shape(const SPCurve *c, SPDrawContext *dc, SPItem *item)
+static void spdc_paste_curve_as_freehand_shape(const SPCurve *c, SPDrawContext *dc, SPItem *item)
{
using namespace Inkscape::LivePathEffect;
@@ -357,8 +357,7 @@ spdc_paste_curve_as_freehand_shape(const SPCurve *c, SPDrawContext *dc, SPItem *
static_cast<LPEPatternAlongPath*>(lpe)->pattern.paste_param_path(svgd);
}
-static void
-spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points, SPDrawContext *dc, SPItem *item)
+static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points, SPDrawContext *dc, SPItem *item)
{
using namespace Inkscape::LivePathEffect;
@@ -375,12 +374,7 @@ spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points, SPDrawCont
lpe->getRepr()->setAttribute("interpolator_beta", "0.2");
}
-/*
- * If we have an item and a waiting LPE, apply the effect to the item
- * (spiro spline mode is treated separately)
- */
-void
-spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item, SPCurve *curve)
+void spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item, SPCurve *curve)
{
using namespace Inkscape::LivePathEffect;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -486,8 +480,7 @@ spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item, SPCurve *c
* Selection handlers
*/
-static void
-spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc)
+static void spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc)
{
if (dc->attach) {
spdc_attach_selection(dc, sel);
@@ -496,18 +489,16 @@ spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc)
/* fixme: We have to ensure this is not delayed (Lauris) */
-static void
-spdc_selection_modified(Inkscape::Selection *sel, guint /*flags*/, SPDrawContext *dc)
+static void spdc_selection_modified(Inkscape::Selection *sel, guint /*flags*/, SPDrawContext *dc)
{
if (dc->attach) {
spdc_attach_selection(dc, sel);
}
}
-static void
-spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/)
+static void spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/)
{
- /* We reset white and forget white/start/end anchors */
+ // We reset white and forget white/start/end anchors
spdc_reset_white(dc);
dc->sa = NULL;
dc->ea = NULL;
@@ -515,17 +506,19 @@ spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/)
SPItem *item = dc->selection ? dc->selection->singleItem() : NULL;
if ( item && SP_IS_PATH(item) ) {
- /* Create new white data */
- /* Item */
+ // Create new white data
+ // Item
dc->white_item = item;
- /* Curve list */
- /* We keep it in desktop coordinates to eliminate calculation errors */
+
+ // Curve list
+ // We keep it in desktop coordinates to eliminate calculation errors
SPCurve *norm = SP_PATH(item)->get_curve_for_edit();
norm->transform((dc->white_item)->i2dt_affine());
g_return_if_fail( norm != NULL );
dc->white_curves = g_slist_reverse(norm->split());
norm->unref();
- /* Anchor list */
+
+ // Anchor list
for (GSList *l = dc->white_curves; l != NULL; l = l->next) {
SPCurve *c;
c = static_cast<SPCurve*>(l->data);
@@ -540,20 +533,11 @@ spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/)
dc->white_anchors = g_slist_prepend(dc->white_anchors, a);
}
}
- /* fixme: recalculate active anchor? */
+ // fixme: recalculate active anchor?
}
}
-/**
- * Snaps node or handle to PI/rotationsnapsperpi degree increments.
- *
- * \param dc draw context
- * \param p cursor point (to be changed by snapping)
- * \param o origin point
- * \param state keyboard state to check if ctrl or shift was pressed
-*/
-
void spdc_endpoint_snap_rotation(SPEventContext const *const ec, Geom::Point &p, Geom::Point const &o,
guint state)
{
@@ -604,36 +588,31 @@ void spdc_endpoint_snap_free(SPEventContext const * const ec, Geom::Point& p, bo
m.unSetup();
}
-static SPCurve *
-reverse_then_unref(SPCurve *orig)
+static SPCurve *reverse_then_unref(SPCurve *orig)
{
SPCurve *ret = orig->create_reverse();
orig->unref();
return ret;
}
-/**
- * Concats red, blue and green.
- * If any anchors are defined, process these, optionally removing curves from white list
- * Invoke _flush_white to write result back to object.
- */
-void
-spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed)
+void spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed)
{
- /* Concat RBG */
+ // Concat RBG
SPCurve *c = dc->green_curve;
- /* Green */
+ // Green
dc->green_curve = new SPCurve();
while (dc->green_bpaths) {
gtk_object_destroy(GTK_OBJECT(dc->green_bpaths->data));
dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data);
}
- /* Blue */
+
+ // Blue
c->append_continuous(dc->blue_curve, 0.0625);
dc->blue_curve->reset();
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->blue_bpath), NULL);
- /* Red */
+
+ // Red
if (dc->red_curve_is_valid) {
c->append_continuous(dc->red_curve, 0.0625);
}
@@ -645,18 +624,18 @@ spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed)
return;
}
- /* Step A - test, whether we ended on green anchor */
+ // Step A - test, whether we ended on green anchor
if ( forceclosed || ( dc->green_anchor && dc->green_anchor->active ) ) {
// We hit green anchor, closing Green-Blue-Red
SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Path is closed."));
c->closepath_current();
- /* Closed path, just flush */
+ // Closed path, just flush
spdc_flush_white(dc, c);
c->unref();
return;
}
- /* Step B - both start and end anchored to same curve */
+ // Step B - both start and end anchored to same curve
if ( dc->sa && dc->ea
&& ( dc->sa->curve == dc->ea->curve )
&& ( ( dc->sa != dc->ea )
@@ -674,7 +653,7 @@ spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed)
return;
}
- /* Step C - test start */
+ // Step C - test start
if (dc->sa) {
SPCurve *s = dc->sa->curve;
dc->white_curves = g_slist_remove(dc->white_curves, s);
@@ -700,16 +679,7 @@ spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed)
c->unref();
}
-/*
- * Flushes white curve(s) and additional curve into object
- *
- * No cleaning of colored curves - this has to be done by caller
- * No rereading of white data, so if you cannot rely on ::modified, do it in caller
- *
- */
-
-static void
-spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
+static void spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
{
SPCurve *c;
@@ -728,7 +698,7 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
return;
}
- /* Now we have to go back to item coordinates at last */
+ // Now we have to go back to item coordinates at last
c->transform( dc->white_item
? (dc->white_item)->dt2i_affine()
: SP_EVENT_CONTEXT_DESKTOP(dc)->dt2doc() );
@@ -738,7 +708,7 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
Inkscape::XML::Document *xml_doc = doc->getReprDoc();
if ( c && !c->is_empty() ) {
- /* We actually have something to write */
+ // We actually have something to write
bool has_lpe = false;
Inkscape::XML::Node *repr;
@@ -747,7 +717,7 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
has_lpe = sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(dc->white_item));
} else {
repr = xml_doc->createElement("svg:path");
- /* Set style */
+ // Set style
sp_desktop_apply_style_tool(desktop, repr, tool_name(dc).data(), false);
}
@@ -760,7 +730,7 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
g_free(str);
if (!dc->white_item) {
- /* Attach repr */
+ // Attach repr
SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
// we finished the path; now apply any waiting LPEs or freehand shapes
@@ -785,19 +755,15 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
c->unref();
- /* Flush pending updates */
+ // Flush pending updates
doc->ensureUpToDate();
}
-/**
- * Returns FIRST active anchor (the activated one).
- */
-SPDrawAnchor *
-spdc_test_inside(SPDrawContext *dc, Geom::Point p)
+SPDrawAnchor *spdc_test_inside(SPDrawContext *dc, Geom::Point p)
{
SPDrawAnchor *active = NULL;
- /* Test green anchor */
+ // Test green anchor
if (dc->green_anchor) {
active = sp_draw_anchor_test(dc->green_anchor, p, TRUE);
}
@@ -812,11 +778,10 @@ spdc_test_inside(SPDrawContext *dc, Geom::Point p)
return active;
}
-static void
-spdc_reset_white(SPDrawContext *dc)
+static void spdc_reset_white(SPDrawContext *dc)
{
if (dc->white_item) {
- /* We do not hold refcount */
+ // We do not hold refcount
dc->white_item = NULL;
}
while (dc->white_curves) {
@@ -829,10 +794,9 @@ spdc_reset_white(SPDrawContext *dc)
}
}
-static void
-spdc_free_colors(SPDrawContext *dc)
+static void spdc_free_colors(SPDrawContext *dc)
{
- /* Red */
+ // Red
if (dc->red_bpath) {
gtk_object_destroy(GTK_OBJECT(dc->red_bpath));
dc->red_bpath = NULL;
@@ -840,7 +804,8 @@ spdc_free_colors(SPDrawContext *dc)
if (dc->red_curve) {
dc->red_curve = dc->red_curve->unref();
}
- /* Blue */
+
+ // Blue
if (dc->blue_bpath) {
gtk_object_destroy(GTK_OBJECT(dc->blue_bpath));
dc->blue_bpath = NULL;
@@ -848,7 +813,8 @@ spdc_free_colors(SPDrawContext *dc)
if (dc->blue_curve) {
dc->blue_curve = dc->blue_curve->unref();
}
- /* Green */
+
+ // Green
while (dc->green_bpaths) {
gtk_object_destroy(GTK_OBJECT(dc->green_bpaths->data));
dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data);
@@ -859,9 +825,10 @@ spdc_free_colors(SPDrawContext *dc)
if (dc->green_anchor) {
dc->green_anchor = sp_draw_anchor_destroy(dc->green_anchor);
}
- /* White */
+
+ // White
if (dc->white_item) {
- /* We do not hold refcount */
+ // We do not hold refcount
dc->white_item = NULL;
}
while (dc->white_curves) {
@@ -874,7 +841,6 @@ spdc_free_colors(SPDrawContext *dc)
}
}
-/* Create a single dot represented by a circle */
void spdc_create_single_dot(SPEventContext *ec, Geom::Point const &pt, char const *tool, guint event_state) {
g_return_if_fail(!strcmp(tool, "/tools/freehand/pen") || !strcmp(tool, "/tools/freehand/pencil"));
Glib::ustring tool_path = tool;
@@ -886,10 +852,10 @@ void spdc_create_single_dot(SPEventContext *ec, Geom::Point const &pt, char cons
SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
Inkscape::GC::release(repr);
- /* apply the tool's current style */
+ // 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??) */
+ // 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");
@@ -900,23 +866,24 @@ void spdc_create_single_dot(SPEventContext *ec, Geom::Point const &pt, char cons
style->stroke_width.computed = 0;
sp_style_unref(style);
}
- /* unset stroke and set fill color to former stroke color */
+
+ // 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 */
+ // 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
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
Geom::Affine const i2d (item->i2dt_affine ());
Geom::Point pp = pt;
double rad = 0.5 * prefs->getDouble(tool_path + "/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. */
+ // 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);
}