gtkdatabox  1.0.0
About: GtkDatabox is a Gtk+-widget for live display of large amounts of fluctuating numerical data.
  Fossies Dox: gtkdatabox-1.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

gtkdatabox_lines.c
Go to the documentation of this file.
1 /* $Id: gtkdatabox_lines.c 4 2008-06-22 09:19:11Z rbock $ */
2 /* GtkDatabox - An extension to the gtk+ library
3  * Copyright (C) 1998 - 2008 Dr. Roland Bock
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation; either version 2.1
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include <gtkdatabox_lines.h>
21 
23  GtkDatabox* box);
24 
25 /**
26  * GtkDataboxLinesPrivate
27  * @see_also: #GtkDatabox, #GtkDataboxGraph, #GtkDataboxPoints, #GtkDataboxBars, #GtkDataboxMarkers
28  *
29  * A private data structure used by the #GtkDataboxLines. It shields all internal things
30  * from developers who are just using the object.
31  *
32  **/
34 
36 {
37  gint16 *xpixels;
38  gint16 *ypixels;
39  guint pixelsalloc;
40 };
41 
44 
45 static void
46 lines_finalize (GObject * object)
47 {
48  GtkDataboxLines *lines = GTK_DATABOX_LINES (object);
49  GtkDataboxLinesPrivate *priv=gtk_databox_lines_get_instance_private(lines);
50 
51  g_free (priv->xpixels);
52  g_free (priv->ypixels);
53 
54  /* Chain up to the parent class */
55  G_OBJECT_CLASS (gtk_databox_lines_parent_class)->finalize (object);
56 }
57 
58 static void
60 {
61  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
62  GtkDataboxGraphClass *graph_class = GTK_DATABOX_GRAPH_CLASS (klass);
63 
64  gobject_class->finalize = lines_finalize;
65 
66  graph_class->draw = gtk_databox_lines_real_draw;
67 }
68 
69 static void
71 {
72  GtkDataboxLinesPrivate *priv=gtk_databox_lines_get_instance_private(lines);
73  priv->xpixels = NULL;
74  priv->ypixels = NULL;
75  priv->pixelsalloc = 0;
76 }
77 
78 /**
79  * gtk_databox_lines_new:
80  * @len: length of @X and @Y
81  * @X: array of horizontal position values of markers
82  * @Y: array of vertical position values of markers
83  * @color: color of the markers
84  * @size: marker size or line width (depending on the @type)
85  *
86  * Creates a new #GtkDataboxLines object which can be added to a #GtkDatabox widget.
87  *
88  * Return value: A new #GtkDataboxLines object
89  **/
91 gtk_databox_lines_new (guint len, gfloat * X, gfloat * Y,
92  GdkRGBA * color, guint size)
93 {
94  GtkDataboxLines *lines;
95  g_return_val_if_fail (X, NULL);
96  g_return_val_if_fail (Y, NULL);
97  g_return_val_if_fail ((len > 0), NULL);
98 
99  lines = g_object_new (GTK_DATABOX_TYPE_LINES,
100  "X-Values", X,
101  "Y-Values", Y,
102  "xstart", 0,
103  "ystart", 0,
104  "xstride", 1,
105  "ystride", 1,
106  "xtype", G_TYPE_FLOAT,
107  "ytype", G_TYPE_FLOAT,
108  "length", len,
109  "maxlen", len,
110  "color", color, "size", size, NULL);
111 
112  return GTK_DATABOX_GRAPH (lines);
113 }
114 
115 /**
116  * gtk_databox_lines_new_full:
117  * @maxlen: maximum length of @X and @Y
118  * @len: actual number of @X and @Y values to plot
119  * @X: array of horizontal position values of markers
120  * @Y: array of vertical position values of markers
121  * @xstart: the first element in the X array to plot (usually 0)
122  * @ystart: the first element in the Y array to plot (usually 0)
123  * @xstride: successive elements in the X array are separated by this much (1 if array, ncols if matrix)
124  * @ystride: successive elements in the Y array are separated by this much (1 if array, ncols if matrix)
125  * @xtype: the GType of the X array elements. G_TYPE_FLOAT, G_TYPE_DOUBLE, etc.
126  * @ytype: the GType of the Y array elements. G_TYPE_FLOAT, G_TYPE_DOUBLE, etc.
127  * @color: color of the markers
128  * @size: marker size or line width (depending on the @type)
129  *
130  * Creates a new #GtkDataboxLines object which can be added to a #GtkDatabox widget.
131  *
132  * Return value: A new #GtkDataboxLines object
133  **/
135 gtk_databox_lines_new_full (guint maxlen, guint len,
136  void * X, guint xstart, guint xstride, GType xtype,
137  void * Y, guint ystart, guint ystride, GType ytype,
138  GdkRGBA * color, guint size)
139 {
140  GtkDataboxLines *lines;
141  g_return_val_if_fail (X, NULL);
142  g_return_val_if_fail (Y, NULL);
143  g_return_val_if_fail ((len > 0), NULL);
144 
145  lines = g_object_new (GTK_DATABOX_TYPE_LINES,
146  "X-Values", X,
147  "Y-Values", Y,
148  "xstart", xstart,
149  "ystart", ystart,
150  "xstride", xstride,
151  "ystride", ystride,
152  "xtype", xtype,
153  "ytype", ytype,
154  "length", len,
155  "maxlen", maxlen,
156  "color", color, "size", size, NULL);
157 
158  return GTK_DATABOX_GRAPH (lines);
159 }
160 
161 static void
163  GtkDatabox * box)
164 {
165  GtkDataboxLines *lines = GTK_DATABOX_LINES (graph);
166  GtkDataboxLinesPrivate *priv=gtk_databox_lines_get_instance_private(lines);
167  guint i = 0;
168  void *X;
169  void *Y;
170  guint len, maxlen;
171  cairo_t *cr;
172  gint16 *xpixels, *ypixels;
173  guint xstart, xstride, ystart, ystride;
174  GType xtype, ytype;
175  float linewidth;
176 
177  g_return_if_fail (GTK_DATABOX_IS_LINES (lines));
178  g_return_if_fail (GTK_IS_DATABOX (box));
179 
182 
183  if (priv->pixelsalloc < len)
184  {
185  priv->pixelsalloc = len;
186  priv->xpixels = (gint16 *)g_realloc(priv->xpixels, len * sizeof(gint16));
187  priv->ypixels = (gint16 *)g_realloc(priv->ypixels, len * sizeof(gint16));
188  }
189 
190  xpixels = priv->xpixels;
191  ypixels = priv->ypixels;
192 
197  gtk_databox_values_to_xpixels(box, xpixels, X, xtype, maxlen, xstart, xstride, len);
198 
203  gtk_databox_values_to_ypixels(box, ypixels, Y, ytype, maxlen, ystart, ystride, len);
204 
205  cr = gtk_databox_graph_create_gc (graph, box);
206 
207  linewidth = gtk_databox_graph_get_size (graph);
208  cairo_set_line_width(cr, linewidth + 0.1);
209 
210  cairo_move_to(cr, xpixels[0] + 0.5, ypixels[0] + 0.5);
211  for (i = 1; i < len; i++)
212  cairo_line_to(cr, xpixels[i] + 0.5, ypixels[i] + 0.5);
213 
214  cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
215  cairo_stroke(cr);
216  cairo_destroy(cr);
217 
218  return;
219 }
void gtk_databox_values_to_xpixels(GtkDatabox *box, gint16 *pixels, void *values, GType vtype, guint maxlen, guint start, guint stride, guint len)
Definition: gtkdatabox.c:2236
void gtk_databox_values_to_ypixels(GtkDatabox *box, gint16 *pixels, void *values, GType vtype, guint maxlen, guint start, guint stride, guint len)
Definition: gtkdatabox.c:2308
#define GTK_IS_DATABOX(obj)
Definition: gtkdatabox.h:62
gint gtk_databox_graph_get_size(GtkDataboxGraph *graph)
cairo_t * gtk_databox_graph_create_gc(GtkDataboxGraph *graph, GtkDatabox *box)
#define GTK_DATABOX_GRAPH(obj)
#define GTK_DATABOX_GRAPH_CLASS(klass)
G_DEFINE_TYPE_WITH_PRIVATE(GtkDataboxLines, gtk_databox_lines, GTK_DATABOX_TYPE_XYC_GRAPH)
static void gtk_databox_lines_class_init(GtkDataboxLinesClass *klass)
GtkDataboxGraph * gtk_databox_lines_new(guint len, gfloat *X, gfloat *Y, GdkRGBA *color, guint size)
static void gtk_databox_lines_init(GtkDataboxLines *lines)
static void gtk_databox_lines_real_draw(GtkDataboxGraph *lines, GtkDatabox *box)
GtkDataboxGraph * gtk_databox_lines_new_full(guint maxlen, guint len, void *X, guint xstart, guint xstride, GType xtype, void *Y, guint ystart, guint ystride, GType ytype, GdkRGBA *color, guint size)
#define GTK_DATABOX_LINES(obj)
#define GTK_DATABOX_IS_LINES(obj)
#define GTK_DATABOX_TYPE_LINES
typedefG_BEGIN_DECLS struct _GtkDatabox GtkDatabox
gfloat * gtk_databox_xyc_graph_get_Y(GtkDataboxXYCGraph *xyc_graph)
guint gtk_databox_xyc_graph_get_xstride(GtkDataboxXYCGraph *xyc_graph)
guint gtk_databox_xyc_graph_get_ystride(GtkDataboxXYCGraph *xyc_graph)
guint gtk_databox_xyc_graph_get_xstart(GtkDataboxXYCGraph *xyc_graph)
gfloat * gtk_databox_xyc_graph_get_X(GtkDataboxXYCGraph *xyc_graph)
#define GTK_DATABOX_XYC_GRAPH(obj)
GType gtk_databox_xyc_graph_get_ytype(GtkDataboxXYCGraph *xyc_graph)
guint gtk_databox_xyc_graph_get_maxlen(GtkDataboxXYCGraph *xyc_graph)
GType gtk_databox_xyc_graph_get_xtype(GtkDataboxXYCGraph *xyc_graph)
#define GTK_DATABOX_TYPE_XYC_GRAPH
guint gtk_databox_xyc_graph_get_length(GtkDataboxXYCGraph *xyc_graph)
guint gtk_databox_xyc_graph_get_ystart(GtkDataboxXYCGraph *xyc_graph)
void(* draw)(GtkDataboxGraph *graph, GtkDatabox *box)