~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/display/sp-ctrlpoint.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define __INKSCAPE_CTRLPOINT_C__
 
2
 
 
3
/*
 
4
 * Simple point
 
5
 *
 
6
 * Author:
 
7
 *   Maximilian Albert <maximilian.albert@gmail.com>
 
8
 *
 
9
 * Copyright (C) 2008 Maximilian Albert
 
10
 *
 
11
 * Released under GNU GPL
 
12
 */
 
13
 
 
14
#include "display-forward.h"
 
15
#include "sp-canvas-util.h"
 
16
#include "sp-ctrlpoint.h"
 
17
 
 
18
#ifdef HAVE_CONFIG_H
 
19
# include "config.h"
 
20
#endif
 
21
#include <color.h>
 
22
#include "display/inkscape-cairo.h"
 
23
 
 
24
 
 
25
static void sp_ctrlpoint_class_init (SPCtrlPointClass *klass);
 
26
static void sp_ctrlpoint_init (SPCtrlPoint *ctrlpoint);
 
27
static void sp_ctrlpoint_destroy (GtkObject *object);
 
28
 
 
29
static void sp_ctrlpoint_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags);
 
30
static void sp_ctrlpoint_render (SPCanvasItem *item, SPCanvasBuf *buf);
 
31
 
 
32
static SPCanvasItemClass *parent_class;
 
33
 
 
34
GType
 
35
sp_ctrlpoint_get_type (void)
 
36
{
 
37
    static GType type = 0;
 
38
    if (!type) {
 
39
        GTypeInfo info = {
 
40
            sizeof(SPCtrlPointClass),
 
41
            NULL, NULL,
 
42
            (GClassInitFunc) sp_ctrlpoint_class_init,
 
43
            NULL, NULL,
 
44
            sizeof(SPCtrlPoint),
 
45
            0,
 
46
            (GInstanceInitFunc) sp_ctrlpoint_init,
 
47
            NULL
 
48
        };
 
49
        type = g_type_register_static(SP_TYPE_CANVAS_ITEM, "SPCtrlPoint", &info, (GTypeFlags)0);
 
50
    }
 
51
    return type;
 
52
}
 
53
 
 
54
static void
 
55
sp_ctrlpoint_class_init (SPCtrlPointClass *klass)
 
56
{
 
57
    GtkObjectClass *object_class = (GtkObjectClass *) klass;
 
58
    SPCanvasItemClass *item_class = (SPCanvasItemClass *) klass;
 
59
 
 
60
    parent_class = (SPCanvasItemClass*)gtk_type_class (SP_TYPE_CANVAS_ITEM);
 
61
 
 
62
    object_class->destroy = sp_ctrlpoint_destroy;
 
63
 
 
64
    item_class->update = sp_ctrlpoint_update;
 
65
    item_class->render = sp_ctrlpoint_render;
 
66
}
 
67
 
 
68
static void
 
69
sp_ctrlpoint_init (SPCtrlPoint *ctrlpoint)
 
70
{
 
71
    ctrlpoint->rgba = 0x0000ff7f;
 
72
    ctrlpoint->pt[Geom::X] = ctrlpoint->pt[Geom::Y] = 0.0;
 
73
    ctrlpoint->item=NULL;
 
74
    ctrlpoint->radius = 2;
 
75
}
 
76
 
 
77
static void
 
78
sp_ctrlpoint_destroy (GtkObject *object)
 
79
{
 
80
    g_return_if_fail (object != NULL);
 
81
    g_return_if_fail (SP_IS_CTRLPOINT (object));
 
82
 
 
83
    SPCtrlPoint *ctrlpoint = SP_CTRLPOINT (object);
 
84
 
 
85
    ctrlpoint->item=NULL;
 
86
 
 
87
    if (GTK_OBJECT_CLASS (parent_class)->destroy)
 
88
        (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
 
89
}
 
90
 
 
91
static void
 
92
sp_ctrlpoint_render (SPCanvasItem *item, SPCanvasBuf *buf)
 
93
{
 
94
    SPCtrlPoint *cp = SP_CTRLPOINT (item);
 
95
 
 
96
    if (!buf->ct)
 
97
        return;
 
98
 
 
99
    sp_canvas_prepare_buffer (buf);
 
100
 
 
101
    guint32 rgba = cp->rgba;
 
102
    cairo_set_source_rgba(buf->ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba));
 
103
 
 
104
    cairo_set_line_width(buf->ct, 1);
 
105
    cairo_new_path(buf->ct);
 
106
 
 
107
    Geom::Point pt = cp->pt * cp->affine;
 
108
 
 
109
    cairo_arc(buf->ct, pt[Geom::X] - buf->rect.x0, pt[Geom::Y] - buf->rect.y0, cp->radius, 0.0, 2 * M_PI);
 
110
    cairo_stroke(buf->ct);
 
111
}
 
112
 
 
113
static void
 
114
sp_ctrlpoint_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
 
115
{
 
116
    SPCtrlPoint *cp = SP_CTRLPOINT (item);
 
117
 
 
118
    sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
 
119
 
 
120
    if (parent_class->update)
 
121
        (* parent_class->update) (item, affine, flags);
 
122
 
 
123
    sp_canvas_item_reset_bounds (item);
 
124
 
 
125
    cp->affine = affine;
 
126
 
 
127
    Geom::Point pt = cp->pt * affine;
 
128
 
 
129
    item->x1 = pt[Geom::X] - cp->radius;
 
130
    item->y1 = pt[Geom::Y] - cp->radius;
 
131
    item->x2 = pt[Geom::X] + cp->radius;
 
132
    item->y2 = pt[Geom::Y] + cp->radius;
 
133
 
 
134
    sp_canvas_request_redraw (item->canvas,
 
135
                              (int)item->x1 - 15, (int)item->y1 - 15,
 
136
                              (int)item->x1 + 15, (int)item->y1 + 15);
 
137
}
 
138
 
 
139
void
 
140
sp_ctrlpoint_set_color (SPCtrlPoint *cp, guint32 rgba)
 
141
{
 
142
    g_return_if_fail (cp != NULL);
 
143
    g_return_if_fail (SP_IS_CTRLPOINT (cp));
 
144
 
 
145
    if (rgba != cp->rgba) {
 
146
        SPCanvasItem *item;
 
147
        cp->rgba = rgba;
 
148
        item = SP_CANVAS_ITEM (cp);
 
149
        sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
 
150
    }
 
151
}
 
152
 
 
153
#define EPSILON 1e-6
 
154
#define DIFFER(a,b) (fabs ((a) - (b)) > EPSILON)
 
155
 
 
156
void
 
157
sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const gdouble x, const gdouble y)
 
158
{
 
159
    g_return_if_fail (cp != NULL);
 
160
    g_return_if_fail (SP_IS_CTRLPOINT (cp));
 
161
 
 
162
    if (DIFFER (x, cp->pt[Geom::X]) || DIFFER (y, cp->pt[Geom::Y])) {
 
163
        cp->pt[Geom::X] = x;
 
164
        cp->pt[Geom::Y] = y;
 
165
        sp_canvas_item_request_update (SP_CANVAS_ITEM (cp));
 
166
    }
 
167
}
 
168
 
 
169
void
 
170
sp_ctrlpoint_set_coords (SPCtrlPoint *cp, const Geom::Point pt)
 
171
{
 
172
    sp_ctrlpoint_set_coords(cp, pt[Geom::X], pt[Geom::Y]);
 
173
}
 
174
 
 
175
void
 
176
sp_ctrlpoint_set_radius (SPCtrlPoint *cp, const double r)
 
177
{
 
178
    cp->radius = r;
 
179
}
 
180
 
 
181
/*
 
182
  Local Variables:
 
183
  mode:c++
 
184
  c-file-style:"stroustrup"
 
185
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
186
  indent-tabs-mode:nil
 
187
  fill-column:99
 
188
  End:
 
189
*/
 
190
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :