diff options
| author | MenTaLguY <mental@rydia.net> | 2006-01-16 02:36:01 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2006-01-16 02:36:01 +0000 |
| commit | 179fa413b047bede6e32109e2ce82437c5fb8d34 (patch) | |
| tree | a5a6ac2c1708bd02288fbd8edb2ff500ff2e0916 /src/draw-anchor.cpp | |
| download | inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.tar.gz inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.zip | |
moving trunk for module inkscape
(bzr r1)
Diffstat (limited to 'src/draw-anchor.cpp')
| -rw-r--r-- | src/draw-anchor.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/draw-anchor.cpp b/src/draw-anchor.cpp new file mode 100644 index 000000000..2a3279075 --- /dev/null +++ b/src/draw-anchor.cpp @@ -0,0 +1,99 @@ +/** \file + * Anchors implementation. + */ + +/* + * Authors: + * Copyright (C) 2000 Lauris Kaplinski + * Copyright (C) 2000-2001 Ximian, Inc. + * Copyright (C) 2002 Lauris Kaplinski + * Copyright (C) 2004 Monash University + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "draw-anchor.h" +#include "desktop.h" +#include "desktop-handles.h" +#include "event-context.h" +#include "display/sodipodi-ctrl.h" + +/** + * Creates an anchor object and initializes it. + */ +SPDrawAnchor * +sp_draw_anchor_new(SPDrawContext *dc, SPCurve *curve, gboolean start, NR::Point delta) +{ + SPDesktop *dt = SP_EVENT_CONTEXT_DESKTOP(dc); + + SPDrawAnchor *a = g_new(SPDrawAnchor, 1); + + a->dc = dc; + a->curve = curve; + a->start = start; + a->active = FALSE; + a->dp = delta; + a->ctrl = sp_canvas_item_new(SP_DT_CONTROLS(dt), SP_TYPE_CTRL, + "size", 6.0, + "filled", 0, + "fill_color", 0xff00007f, + "stroked", 1, + "stroke_color", 0x000000ff, + NULL); + + SP_CTRL(a->ctrl)->moveto(delta); + + return a; +} + +/** + * Destroys the anchor's canvas item and frees the anchor object. + */ +SPDrawAnchor * +sp_draw_anchor_destroy(SPDrawAnchor *anchor) +{ + if (anchor->ctrl) { + gtk_object_destroy(GTK_OBJECT(anchor->ctrl)); + } + g_free(anchor); + return NULL; +} + +#define A_SNAP 4.0 + +/** + * Test if point is near anchor, if so fill anchor on canvas and return + * pointer to it or NULL. + */ +SPDrawAnchor * +sp_draw_anchor_test(SPDrawAnchor *anchor, NR::Point w, gboolean activate) +{ + SPDesktop *dt = SP_EVENT_CONTEXT_DESKTOP(anchor->dc); + + if ( activate && ( NR::LInfty( w - dt->d2w(anchor->dp) ) <= A_SNAP ) ) { + if (!anchor->active) { + sp_canvas_item_set((GtkObject *) anchor->ctrl, "filled", TRUE, NULL); + anchor->active = TRUE; + } + return anchor; + } + + if (anchor->active) { + sp_canvas_item_set((GtkObject *) anchor->ctrl, "filled", FALSE, NULL); + anchor->active = FALSE; + } + return NULL; +} + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
