~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/display/sp-ctrlline.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#ifdef HAVE_CONFIG_H
27
27
# include "config.h"
28
28
#endif
29
 
#include <livarot/Path.h>
30
29
#include <color.h>
 
30
#include "display/inkscape-cairo.h"
31
31
 
32
32
 
33
33
static void sp_ctrlline_class_init (SPCtrlLineClass *klass);
34
34
static void sp_ctrlline_init (SPCtrlLine *ctrlline);
35
35
static void sp_ctrlline_destroy (GtkObject *object);
36
36
 
37
 
static void sp_ctrlline_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
 
37
static void sp_ctrlline_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags);
38
38
static void sp_ctrlline_render (SPCanvasItem *item, SPCanvasBuf *buf);
39
39
 
40
40
static SPCanvasItemClass *parent_class;
41
41
 
42
 
GtkType
 
42
GType
43
43
sp_ctrlline_get_type (void)
44
44
{
45
 
    static GtkType type = 0;
46
 
 
 
45
    static GType type = 0;
47
46
    if (!type) {
48
 
        GtkTypeInfo info = {
49
 
            "SPCtrlLine",
50
 
            sizeof (SPCtrlLine),
51
 
            sizeof (SPCtrlLineClass),
52
 
            (GtkClassInitFunc) sp_ctrlline_class_init,
53
 
            (GtkObjectInitFunc) sp_ctrlline_init,
54
 
            NULL, NULL, NULL
 
47
        GTypeInfo info = {
 
48
            sizeof(SPCtrlLineClass),
 
49
            NULL, NULL,
 
50
            (GClassInitFunc) sp_ctrlline_class_init,
 
51
            NULL, NULL,
 
52
            sizeof(SPCtrlLine),
 
53
            0,
 
54
            (GInstanceInitFunc) sp_ctrlline_init,
 
55
            NULL
55
56
        };
56
 
        type = gtk_type_unique (SP_TYPE_CANVAS_ITEM, &info);
 
57
        type = g_type_register_static(SP_TYPE_CANVAS_ITEM, "SPCtrlLine", &info, (GTypeFlags)0);
57
58
    }
58
59
    return type;
59
60
}
76
77
sp_ctrlline_init (SPCtrlLine *ctrlline)
77
78
{
78
79
    ctrlline->rgba = 0x0000ff7f;
79
 
    ctrlline->s.x = ctrlline->s.y = ctrlline->e.x = ctrlline->e.y = 0.0;
80
 
    ctrlline->shp=NULL;
 
80
    ctrlline->s[Geom::X] = ctrlline->s[Geom::Y] = ctrlline->e[Geom::X] = ctrlline->e[Geom::Y] = 0.0;
81
81
    ctrlline->item=NULL;
82
82
}
83
83
 
89
89
 
90
90
    SPCtrlLine *ctrlline = SP_CTRLLINE (object);
91
91
 
92
 
    if (ctrlline->shp) {
93
 
        delete ctrlline->shp;
94
 
        ctrlline->shp = NULL;
95
 
    }
96
 
 
97
92
    ctrlline->item=NULL;
98
93
 
99
94
    if (GTK_OBJECT_CLASS (parent_class)->destroy)
103
98
static void
104
99
sp_ctrlline_render (SPCanvasItem *item, SPCanvasBuf *buf)
105
100
{
106
 
    SPCtrlLine *ctrlline = SP_CTRLLINE (item);
107
 
 
108
 
    NRRectL  area;
109
 
    area.x0=buf->rect.x0;
110
 
    area.x1=buf->rect.x1;
111
 
    area.y0=buf->rect.y0;
112
 
    area.y1=buf->rect.y1;
113
 
 
114
 
/*
115
 
// CAIRO FIXME: after SPCanvasBuf is switched to unpacked 32bit rgb, rendering can be done via cairo:
116
 
    cairo_surface_t* cst = cairo_image_surface_create_for_data (
117
 
        buf->buf,
118
 
        CAIRO_FORMAT_RGB24,
119
 
        buf->rect.x1 - buf->rect.x0,
120
 
        buf->rect.y1 - buf->rect.y0,
121
 
        buf->buf_rowstride
122
 
        );
123
 
    cairo_t *ct = cairo_create (cst);
124
 
 
125
 
    guint32 rgba = ctrlline->rgba;
126
 
    cairo_set_source_rgba(ct, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba), SP_RGBA32_A_F(rgba));
127
 
 
128
 
    cairo_set_line_width(ct, 0.5);
129
 
    cairo_new_path(ct);
130
 
 
131
 
    cairo_move_to (ct, ctrlline->s.x - buf->rect.x0, ctrlline->s.y - buf->rect.y0);
132
 
    cairo_line_to (ct, ctrlline->e.x - buf->rect.x0, ctrlline->e.y - buf->rect.y0);
133
 
 
134
 
    cairo_stroke(ct);
135
 
    cairo_destroy (ct);
136
 
    cairo_surface_finish (cst);
137
 
    cairo_surface_destroy (cst);
138
 
*/
139
 
 
140
 
// CAIRO FIXME: instead of this:
141
 
    if (ctrlline->shp) {
142
 
        sp_canvas_prepare_buffer (buf);
143
 
        nr_pixblock_render_ctrl_rgba (ctrlline->shp,ctrlline->rgba,area,(char*)buf->buf, buf->buf_rowstride);
144
 
    }
 
101
    SPCtrlLine *cl = SP_CTRLLINE (item);
 
102
 
 
103
    if (!buf->ct)
 
104
        return;
 
105
 
 
106
    if (cl->s == cl->e)
 
107
        return;
 
108
 
 
109
    sp_canvas_prepare_buffer (buf);
 
110
 
 
111
    guint32 rgba = cl->rgba;
 
112
    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));
 
113
 
 
114
    cairo_set_line_width(buf->ct, 1);
 
115
    cairo_new_path(buf->ct);
 
116
 
 
117
    Geom::Point s = cl->s * cl->affine;
 
118
    Geom::Point e = cl->e * cl->affine;
 
119
 
 
120
    cairo_move_to (buf->ct, s[Geom::X] - buf->rect.x0, s[Geom::Y] - buf->rect.y0);
 
121
    cairo_line_to (buf->ct, e[Geom::X] - buf->rect.x0, e[Geom::Y] - buf->rect.y0);
 
122
 
 
123
    cairo_stroke(buf->ct);
145
124
}
146
125
 
147
126
static void
148
 
sp_ctrlline_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
 
127
sp_ctrlline_update (SPCanvasItem *item, Geom::Matrix const &affine, unsigned int flags)
149
128
{
150
129
    SPCtrlLine *cl = SP_CTRLLINE (item);
151
130
 
156
135
 
157
136
    sp_canvas_item_reset_bounds (item);
158
137
 
159
 
/*
160
 
// CAIRO FIXME: all that is needed for update with cairo:
161
 
    NR::Point s = NR::Point(cl->s.x, cl->s.y) * affine;
162
 
    NR::Point e = NR::Point(cl->e.x, cl->e.y) * affine;
163
 
 
164
 
    cl->s.x = s[NR::X];
165
 
    cl->s.y = s[NR::Y];
166
 
    cl->e.x = e[NR::X];
167
 
    cl->e.y = e[NR::Y];
168
 
 
169
 
    item->x1 = (int)(MIN(s[NR::X], e[NR::X]) - 1);
170
 
    item->y1 = (int)(MIN(s[NR::Y], e[NR::Y]) - 1);
171
 
    item->x2 = (int)(MAX(s[NR::X], e[NR::X]) + 1);
172
 
    item->y2 = (int)(MAX(s[NR::Y], e[NR::Y]) + 1);
173
 
*/
174
 
 
175
 
// CAIRO FIXME: instead of:
176
 
    NRRect dbox;
177
 
    dbox.x0=dbox.x1=dbox.y0=dbox.y1=0;
178
 
    if (cl->shp) {
179
 
        delete cl->shp;
180
 
        cl->shp = NULL;
181
 
    }
182
 
    Path* thePath = new Path;
183
 
    thePath->MoveTo(NR::Point(cl->s.x, cl->s.y) * affine);
184
 
    thePath->LineTo(NR::Point(cl->e.x, cl->e.y) * affine);
185
 
 
186
 
    NRRectL  area;
187
 
    area.x0=(NR::ICoord)(double)item->x1;
188
 
    area.x1=(NR::ICoord)(double)item->x2;
189
 
    area.y0=(NR::ICoord)(double)item->y1;
190
 
    area.y1=(NR::ICoord)(double)item->y2;
191
 
    thePath->Convert(&area, 1.0);
192
 
    if ( cl->shp == NULL ) cl->shp=new Shape;
193
 
    thePath->Stroke(cl->shp,false,0.5,join_straight,butt_straight,20.0,false);
194
 
    cl->shp->CalcBBox();
195
 
    if ( cl->shp->leftX < cl->shp->rightX ) {
196
 
        if ( dbox.x0 >= dbox.x1 ) {
197
 
            dbox.x0=cl->shp->leftX;dbox.x1=cl->shp->rightX;
198
 
            dbox.y0=cl->shp->topY;dbox.y1=cl->shp->bottomY;
199
 
        } else {
200
 
            if ( cl->shp->leftX < dbox.x0 ) dbox.x0=cl->shp->leftX;
201
 
            if ( cl->shp->rightX > dbox.x1 ) dbox.x1=cl->shp->rightX;
202
 
            if ( cl->shp->topY < dbox.y0 ) dbox.y0=cl->shp->topY;
203
 
            if ( cl->shp->bottomY > dbox.y1 ) dbox.y1=cl->shp->bottomY;
204
 
        }
205
 
    }
206
 
    delete thePath;
207
 
 
208
 
    item->x1 = (int)dbox.x0;
209
 
    item->y1 = (int)dbox.y0;
210
 
    item->x2 = (int)dbox.x1;
211
 
    item->y2 = (int)dbox.y1;
212
 
 
213
 
    sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
 
138
    cl->affine = affine;
 
139
 
 
140
    if (cl->s == cl->e) {
 
141
        item->x1 = item->x2 = item->y1 = item->y2 = 0;
 
142
    } else {
 
143
 
 
144
        Geom::Point s = cl->s * affine;
 
145
        Geom::Point e = cl->e * affine;
 
146
 
 
147
        item->x1 = round(MIN(s[Geom::X], e[Geom::X]) - 1);
 
148
        item->y1 = round(MIN(s[Geom::Y], e[Geom::Y]) - 1);
 
149
        item->x2 = round(MAX(s[Geom::X], e[Geom::X]) + 1);
 
150
        item->y2 = round(MAX(s[Geom::Y], e[Geom::Y]) + 1);
 
151
 
 
152
        sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
 
153
 
 
154
    }
214
155
}
215
156
 
216
157
void
236
177
    g_return_if_fail (cl != NULL);
237
178
    g_return_if_fail (SP_IS_CTRLLINE (cl));
238
179
 
239
 
    if (DIFFER (x0, cl->s.x) || DIFFER (y0, cl->s.y) || DIFFER (x1, cl->e.x) || DIFFER (y1, cl->e.y)) {
240
 
        cl->s.x = x0;
241
 
        cl->s.y = y0;
242
 
        cl->e.x = x1;
243
 
        cl->e.y = y1;
 
180
    if (DIFFER (x0, cl->s[Geom::X]) || DIFFER (y0, cl->s[Geom::Y]) || DIFFER (x1, cl->e[Geom::X]) || DIFFER (y1, cl->e[Geom::Y])) {
 
181
        cl->s[Geom::X] = x0;
 
182
        cl->s[Geom::Y] = y0;
 
183
        cl->e[Geom::X] = x1;
 
184
        cl->e[Geom::Y] = y1;
244
185
        sp_canvas_item_request_update (SP_CANVAS_ITEM (cl));
245
186
    }
246
187
}
247
188
 
248
189
void
249
 
sp_ctrlline_set_coords (SPCtrlLine *cl, const NR::Point start, const NR::Point end)
 
190
sp_ctrlline_set_coords (SPCtrlLine *cl, const Geom::Point start, const Geom::Point end)
250
191
{
251
192
    sp_ctrlline_set_coords(cl, start[0], start[1], end[0], end[1]);
252
193
}