Code

noop: CodingStyle: const placement
[inkscape.git] / src / draw-anchor.cpp
1 /** \file
2  * Anchors implementation.
3  */
5 /*
6  * Authors:
7  * Copyright (C) 2000 Lauris Kaplinski
8  * Copyright (C) 2000-2001 Ximian, Inc.
9  * Copyright (C) 2002 Lauris Kaplinski
10  * Copyright (C) 2004 Monash University
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
16 #include "draw-anchor.h"
17 #include "desktop.h"
18 #include "desktop-handles.h"
19 #include "event-context.h"
20 #include "display/sodipodi-ctrl.h"
22 /**
23  * Creates an anchor object and initializes it.
24  */
25 SPDrawAnchor *
26 sp_draw_anchor_new(SPDrawContext *dc, SPCurve *curve, gboolean start, NR::Point delta)
27 {
28     SPDesktop *dt = SP_EVENT_CONTEXT_DESKTOP(dc);
30     SPDrawAnchor *a = g_new(SPDrawAnchor, 1);
32     a->dc = dc;
33     a->curve = curve;
34     a->start = start;
35     a->active = FALSE;
36     a->dp = delta;
37     a->ctrl = sp_canvas_item_new(sp_desktop_controls(dt), SP_TYPE_CTRL,
38                                  "size", 6.0,
39                                  "filled", 0,
40                                  "fill_color", 0xff00007f,
41                                  "stroked", 1,
42                                  "stroke_color", 0x000000ff,
43                                  NULL);
45     SP_CTRL(a->ctrl)->moveto(delta);
47     return a;
48 }
50 /**
51  * Destroys the anchor's canvas item and frees the anchor object.
52  */
53 SPDrawAnchor *
54 sp_draw_anchor_destroy(SPDrawAnchor *anchor)
55 {
56     if (anchor->ctrl) {
57         gtk_object_destroy(GTK_OBJECT(anchor->ctrl));
58     }
59     g_free(anchor);
60     return NULL;
61 }
63 #define A_SNAP 4.0
65 /**
66  * Test if point is near anchor, if so fill anchor on canvas and return
67  * pointer to it or NULL.
68  */
69 SPDrawAnchor *
70 sp_draw_anchor_test(SPDrawAnchor *anchor, NR::Point w, gboolean activate)
71 {
72     SPDesktop *dt = SP_EVENT_CONTEXT_DESKTOP(anchor->dc);
74     if ( activate && ( NR::LInfty( w - dt->d2w(anchor->dp) ) <= A_SNAP ) ) {
75         if (!anchor->active) {
76             sp_canvas_item_set((GtkObject *) anchor->ctrl, "filled", TRUE, NULL);
77             anchor->active = TRUE;
78         }
79         return anchor;
80     }
82     if (anchor->active) {
83         sp_canvas_item_set((GtkObject *) anchor->ctrl, "filled", FALSE, NULL);
84         anchor->active = FALSE;
85     }
86     return NULL;
87 }
90 /*
91   Local Variables:
92   mode:c++
93   c-file-style:"stroustrup"
94   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
95   indent-tabs-mode:nil
96   fill-column:99
97   End:
98 */
99 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :