1 /*
2 * gog-series-lines.c :
3 *
4 * Copyright (C) 2005 Jean Brefort (jean.brefort@normalesup.org)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21 #include <goffice/goffice-config.h>
22 #include <goffice/goffice.h>
23
24 #include <gsf/gsf-impl-utils.h>
25 #include <string.h>
26
27 typedef GogStyledObjectClass GogSeriesLinesClass;
28 struct _GogSeriesLines {
29 GogStyledObject base;
30
31 gboolean use_markers;
32 };
33
34 static void
gog_series_lines_init_style(GogStyledObject * gso,GOStyle * style)35 gog_series_lines_init_style (GogStyledObject *gso, GOStyle *style)
36 {
37 style->interesting_fields = (GOG_SERIES_LINES (gso)->use_markers)
38 ? GO_STYLE_LINE | GO_STYLE_MARKER
39 : GO_STYLE_LINE;
40 gog_theme_fillin_style (gog_object_get_theme (GOG_OBJECT (gso)),
41 style, GOG_OBJECT (gso), 0, style->interesting_fields);
42 }
43
44 static void
gog_series_lines_update(GogObject * obj)45 gog_series_lines_update (GogObject *obj)
46 {
47 gog_object_request_update (obj->parent);
48 }
49
50 static void
gog_series_lines_changed(GogObject * obj,gboolean size)51 gog_series_lines_changed (GogObject *obj, gboolean size)
52 {
53 gog_object_emit_changed (obj->parent, size);
54 }
55
56 static void
gog_series_lines_class_init(GogObjectClass * klass)57 gog_series_lines_class_init (GogObjectClass *klass)
58 {
59 GogStyledObjectClass *style_klass = (GogStyledObjectClass *) klass;
60
61 klass->update = gog_series_lines_update;
62 klass->changed = gog_series_lines_changed;
63 style_klass->init_style = gog_series_lines_init_style;
64 }
65
GSF_CLASS(GogSeriesLines,gog_series_lines,gog_series_lines_class_init,NULL,GOG_TYPE_STYLED_OBJECT)66 GSF_CLASS (GogSeriesLines, gog_series_lines,
67 gog_series_lines_class_init, NULL,
68 GOG_TYPE_STYLED_OBJECT)
69
70 static void
71 path_move_to (void *closure, GOPathPoint const *point)
72 {
73 gog_renderer_draw_marker (GOG_RENDERER (closure), point->x, point->y);
74 }
75
76 static void
path_curve_to(void * closure,GOPathPoint const * point0,GOPathPoint const * point1,GOPathPoint const * point2)77 path_curve_to (void *closure,
78 GOPathPoint const *point0,
79 GOPathPoint const *point1,
80 GOPathPoint const *point2)
81 {
82 gog_renderer_draw_marker (GOG_RENDERER (closure), point2->x, point2->y);
83 }
84
85 static void
path_close_path(void * closure)86 path_close_path (void *closure)
87 {
88 }
89
gog_series_lines_stroke(GogSeriesLines * lines,GogRenderer * rend,GogViewAllocation const * bbox,GOPath * path,gboolean invert)90 void gog_series_lines_stroke (GogSeriesLines *lines, GogRenderer *rend,
91 GogViewAllocation const *bbox, GOPath *path, gboolean invert)
92 {
93 GOStyle *style = go_styled_object_get_style (GO_STYLED_OBJECT (lines));
94
95 if (invert) {
96 GOMarker *marker;
97 GOColor color;
98
99 style = go_style_dup (style);
100 style->line.color ^= 0xffffff00;
101 marker = style->marker.mark;
102 color = go_marker_get_outline_color (marker);
103 go_marker_set_outline_color (marker, color ^ 0xffffff00);
104 color = go_marker_get_fill_color (marker);
105 go_marker_set_fill_color (marker, color ^ 0xffffff00);
106 }
107 gog_renderer_push_style (rend, style);
108 gog_renderer_stroke_serie (rend, path);
109 if ((style->interesting_fields & GO_STYLE_MARKER) != 0)
110 go_path_interpret (path, GO_PATH_DIRECTION_FORWARD,
111 path_move_to,
112 path_move_to,
113 path_curve_to,
114 path_close_path,
115 rend);
116 gog_renderer_pop_style (rend);
117 if (invert)
118 g_object_unref (style);
119 }
120
121 void
gog_series_lines_use_markers(GogSeriesLines * lines,gboolean use_markers)122 gog_series_lines_use_markers (GogSeriesLines *lines, gboolean use_markers)
123 {
124 lines->use_markers = use_markers;
125 }
126