~ubuntu-branches/ubuntu/feisty/gnumeric/feisty

« back to all changes in this revision

Viewing changes to src/gnm-so-line.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2006-11-14 14:02:03 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061114140203-iv3j2aii3vch6isl
Tags: 1.7.2-1ubuntu1
* Merge with debian experimental:
  - debian/control, debian/*-gtk-*, debian/rules,
    debian/shlibs.local: Xubuntu changes for
    gtk/gnome multibuild.
  - run intltool-update in po*
  - Build Depend on intltool

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <goffice/graph/gog-style.h>
31
31
#include <goffice/utils/go-color.h>
32
32
#include <gsf/gsf-impl-utils.h>
33
 
#include <glib/gi18n.h>
 
33
#include <glib/gi18n-lib.h>
34
34
#include <string.h>
35
35
 
36
36
#define GNM_SO_LINE(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), GNM_SO_LINE_TYPE, GnmSOLine))
206
206
        if (style->color == 0 || style->width < 0 || style->pattern == 0)
207
207
                return;
208
208
 
209
 
        switch (so->anchor.direction) {
210
 
        case SO_DIR_UP_RIGHT:
211
 
        case SO_DIR_DOWN_RIGHT:
 
209
        switch (so->anchor.base.direction) {
 
210
        case GOD_ANCHOR_DIR_UP_RIGHT:
 
211
        case GOD_ANCHOR_DIR_DOWN_RIGHT:
212
212
                x1 = 0.;
213
213
                x2 = width;
214
214
                break;
215
 
        case SO_DIR_UP_LEFT:
216
 
        case SO_DIR_DOWN_LEFT:
 
215
        case GOD_ANCHOR_DIR_UP_LEFT:
 
216
        case GOD_ANCHOR_DIR_DOWN_LEFT:
217
217
                x1 = width;
218
218
                x2 = 0.;
219
219
                break;
222
222
                return;
223
223
        }
224
224
 
225
 
        switch (so->anchor.direction) {
226
 
        case SO_DIR_UP_LEFT:
227
 
        case SO_DIR_UP_RIGHT:
 
225
        switch (so->anchor.base.direction) {
 
226
        case GOD_ANCHOR_DIR_UP_LEFT:
 
227
        case GOD_ANCHOR_DIR_UP_RIGHT:
228
228
                y1 = -height;
229
229
                y2 = 0.;
230
230
                break;
231
 
        case SO_DIR_DOWN_LEFT:
232
 
        case SO_DIR_DOWN_RIGHT:
 
231
        case GOD_ANCHOR_DIR_DOWN_LEFT:
 
232
        case GOD_ANCHOR_DIR_DOWN_RIGHT:
233
233
                y1 = 0.;
234
234
                y2 = -height;
235
235
                break;
239
239
        }
240
240
 
241
241
        gnome_print_setrgbcolor (ctx,
242
 
                style->color / (double) 0xffff,
243
 
                style->color / (double) 0xffff,
244
 
                style->color / (double) 0xffff);
 
242
                DOUBLE_RGBA_R (style->color),
 
243
                DOUBLE_RGBA_G (style->color),
 
244
                DOUBLE_RGBA_B (style->color));
245
245
 
246
246
        if (sol->end_arrow.c > 0.) {
247
247
                double phi;
276
276
 
277
277
#endif /* WITH_GTK */
278
278
 
 
279
static void
 
280
gnm_so_line_draw_cairo (SheetObject const *so, gpointer data,
 
281
        double width, double height)
 
282
{
 
283
#ifdef GOFFICE_WITH_CAIRO
 
284
        GnmSOLine *sol = GNM_SO_LINE (so);
 
285
        cairo_t *cairo = (cairo_t*) data;
 
286
        GogStyleLine const *style = &sol->style->line;
 
287
        double x1, y1, x2, y2;
 
288
 
 
289
        if (style->color == 0 || style->width < 0 || style->pattern == 0)
 
290
                return;
 
291
 
 
292
        switch (so->anchor.base.direction) {
 
293
        case GOD_ANCHOR_DIR_UP_RIGHT:
 
294
        case GOD_ANCHOR_DIR_DOWN_RIGHT:
 
295
                x1 = 0.;
 
296
                x2 = width;
 
297
                break;
 
298
        case GOD_ANCHOR_DIR_UP_LEFT:
 
299
        case GOD_ANCHOR_DIR_DOWN_LEFT:
 
300
                x1 = width;
 
301
                x2 = 0.;
 
302
                break;
 
303
        default:
 
304
                g_warning ("Cannot guess direction!");
 
305
                return;
 
306
        }
 
307
 
 
308
        switch (so->anchor.base.direction) {
 
309
        case GOD_ANCHOR_DIR_UP_LEFT:
 
310
        case GOD_ANCHOR_DIR_UP_RIGHT:
 
311
                y1 = height;
 
312
                y2 = 0.;
 
313
                break;
 
314
        case GOD_ANCHOR_DIR_DOWN_LEFT:
 
315
        case GOD_ANCHOR_DIR_DOWN_RIGHT:
 
316
                y1 = 0.;
 
317
                y2 = height;
 
318
                break;
 
319
        default:
 
320
                g_warning ("Cannot guess direction!");
 
321
                return;
 
322
        }
 
323
 
 
324
        cairo_set_line_width (cairo, (style->width)? style->width: 1.);
 
325
        cairo_set_source_rgba (cairo,
 
326
                UINT_RGBA_R(style->color),
 
327
                UINT_RGBA_B(style->color),
 
328
                UINT_RGBA_G(style->color),
 
329
                UINT_RGBA_A(style->color));
 
330
 
 
331
        if (sol->end_arrow.c > 0.) {
 
332
                double phi;
 
333
 
 
334
                phi = atan2 (y2 - y1, x2 - x1) - M_PI_2;
 
335
 
 
336
                cairo_save (cairo);
 
337
                cairo_translate (cairo, x2, y2);
 
338
                cairo_rotate (cairo, phi);
 
339
                cairo_set_line_width (cairo, 1.0);
 
340
                cairo_new_path (cairo);
 
341
                cairo_move_to (cairo, 0.0, 0.0);
 
342
                cairo_line_to (cairo, -sol->end_arrow.c, -sol->end_arrow.b);
 
343
                cairo_line_to (cairo, 0.0, -sol->end_arrow.a);
 
344
                cairo_line_to (cairo, sol->end_arrow.c, -sol->end_arrow.b);
 
345
                cairo_close_path (cairo);
 
346
                cairo_fill (cairo);
 
347
                cairo_restore (cairo);
 
348
 
 
349
                /* Make the line shorter so that the arrow won't be
 
350
                 * on top of a (perhaps quite fat) line.  */
 
351
                x2 += sol->end_arrow.a * sin (phi);
 
352
                y2 -= sol->end_arrow.a * cos (phi);
 
353
        }
 
354
 
 
355
        cairo_set_line_width (cairo, style->width);
 
356
        cairo_new_path (cairo);
 
357
        cairo_move_to (cairo, x1, y1);
 
358
        cairo_line_to (cairo, x2, y2);
 
359
        cairo_stroke (cairo);
 
360
#endif
 
361
}
 
362
 
279
363
static gboolean
280
364
gnm_so_line_read_xml_dom (SheetObject *so, char const *typename,
281
365
                          XmlParseContext const *ctxt,
412
496
        so_class->xml_export_name       = "SheetObjectGraphic";
413
497
 
414
498
#ifdef WITH_GTK
 
499
        so_class->draw_cairo    = gnm_so_line_draw_cairo;
415
500
        so_class->user_config           = gnm_so_line_user_config;
416
501
        so_class->new_view              = gnm_so_line_new_view;
417
502
        so_class->print                 = gnm_so_line_print;
439
524
        go_arrow_init (&sol->start_arrow, 0., 0., 0.);
440
525
        go_arrow_init (&sol->end_arrow,   0., 0., 0.);
441
526
 
442
 
        SHEET_OBJECT (obj)->anchor.direction = SO_DIR_NONE_MASK;
 
527
        SHEET_OBJECT (obj)->anchor.base.direction = GOD_ANCHOR_DIR_NONE_MASK;
443
528
}
444
529
 
445
530
GSF_CLASS (GnmSOLine, gnm_so_line,