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_points.c
Go to the documentation of this file.
1 /* $Id: gtkdatabox_points.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_points.h>
21 
23  GtkDatabox * box);
24 /**
25  * GtkDataboxPointsPrivate
26  *
27  * A private data structure used by the #GtkDataboxPoints. It shields all internal things
28  * from developers who are just using the object.
29  *
30  **/
32 
34 {
35  gint16 *xpixels;
36  gint16 *ypixels;
37  guint pixelsalloc;
38 };
39 
42 
43 static void
44 points_finalize (GObject * object)
45 {
46  GtkDataboxPoints *points = GTK_DATABOX_POINTS (object);
48  gtk_databox_points_get_instance_private (points);
49 
50  g_free (priv->xpixels);
51  g_free (priv->ypixels);
52 
53  /* Chain up to the parent class */
54  G_OBJECT_CLASS (gtk_databox_points_parent_class)->finalize (object);
55 }
56 
57 static void
59 {
60  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
61  GtkDataboxGraphClass *graph_class = GTK_DATABOX_GRAPH_CLASS (klass);
62 
63  gobject_class->finalize = points_finalize;
64 
65  graph_class->draw = gtk_databox_points_real_draw;
66 }
67 
68 static void
70 {
72  gtk_databox_points_get_instance_private (points);
73 
74  priv->xpixels = NULL;
75  priv->ypixels = NULL;
76  priv->pixelsalloc = 0;
77 }
78 
79 static void
81 {
82  g_signal_connect (points, "notify::length",
83  G_CALLBACK (gtk_databox_points_complete), NULL);
84 }
85 
86 /**
87  * gtk_databox_points_new:
88  * @len: length of @X and @Y
89  * @X: array of horizontal position values of markers
90  * @Y: array of vertical position values of markers
91  * @color: color of the markers
92  * @size: marker size or line width (depending on the @type)
93  *
94  * Creates a new #GtkDataboxPoints object which can be added to a #GtkDatabox widget.
95  *
96  * Return value: A new #GtkDataboxPoints object
97  **/
99 gtk_databox_points_new (guint len, gfloat * X, gfloat * Y,
100  GdkRGBA * color, gint size)
101 {
102  GtkDataboxPoints *points;
103  g_return_val_if_fail (X, NULL);
104  g_return_val_if_fail (Y, NULL);
105  g_return_val_if_fail ((len > 0), NULL);
106 
107  points = g_object_new (GTK_DATABOX_TYPE_POINTS,
108  "X-Values", X,
109  "Y-Values", Y,
110  "xstart", 0,
111  "ystart", 0,
112  "xstride", 1,
113  "ystride", 1,
114  "xtype", G_TYPE_FLOAT,
115  "ytype", G_TYPE_FLOAT,
116  "length", len,
117  "maxlen", len, "color", color, "size", size, NULL);
118 
119  return GTK_DATABOX_GRAPH (points);
120 }
121 
122 /**
123  * gtk_databox_points_new_full:
124  * @maxlen: maximum length of @X and @Y
125  * @len: actual number of @X and @Y values to plot
126  * @X: array of horizontal position values of markers
127  * @Y: array of vertical position values of markers
128  * @xstart: the first element in the X array to plot (usually 0)
129  * @ystart: the first element in the Y array to plot (usually 0)
130  * @xstride: successive elements in the X array are separated by this much (1 if array, ncols if matrix)
131  * @ystride: successive elements in the Y array are separated by this much (1 if array, ncols if matrix)
132  * @xtype: the GType of the X array elements. G_TYPE_FLOAT, G_TYPE_DOUBLE, etc.
133  * @ytype: the GType of the Y array elements. G_TYPE_FLOAT, G_TYPE_DOUBLE, etc.
134  * @color: color of the markers
135  * @size: marker size or line width (depending on the @type)
136  *
137  * Creates a new #GtkDataboxPoints object which can be added to a #GtkDatabox widget.
138  *
139  * Return value: A new #GtkDataboxPoints object
140  **/
142 gtk_databox_points_new_full (guint maxlen, guint len,
143  void *X, guint xstart, guint xstride,
144  GType xtype, void *Y, guint ystart,
145  guint ystride, GType ytype, GdkRGBA * color,
146  gint size)
147 {
148  GtkDataboxPoints *points;
149  g_return_val_if_fail (X, NULL);
150  g_return_val_if_fail (Y, NULL);
151  g_return_val_if_fail ((len > 0), NULL);
152 
153  points = g_object_new (GTK_DATABOX_TYPE_POINTS,
154  "X-Values", X,
155  "Y-Values", Y,
156  "xstart", xstart,
157  "ystart", ystart,
158  "xstride", xstride,
159  "ystride", ystride,
160  "xtype", xtype,
161  "ytype", ytype,
162  "length", len,
163  "maxlen", maxlen,
164  "color", color, "size", size, NULL);
165 
166  return GTK_DATABOX_GRAPH (points);
167 }
168 
169 static void
171 {
172  GtkDataboxPoints *points = GTK_DATABOX_POINTS (graph);
174  gtk_databox_points_get_instance_private (points);
175  guint i = 0;
176  void *X;
177  void *Y;
178  guint len, maxlen;
179  gint pointsize = 0;
180  cairo_t *cr;
181  gint16 *xpixels, *ypixels;
182  guint xstart, xstride, ystart, ystride;
183  GType xtype, ytype;
184 
185  g_return_if_fail (GTK_DATABOX_IS_POINTS (points));
186  g_return_if_fail (GTK_IS_DATABOX (box));
187 
188  cr = gtk_databox_graph_create_gc (graph, box);
189 
192 
193  if (priv->pixelsalloc < len)
194  {
195  priv->pixelsalloc = len;
196  priv->xpixels =
197  (gint16 *) g_realloc (priv->xpixels, len * sizeof (gint16));
198  priv->ypixels =
199  (gint16 *) g_realloc (priv->ypixels, len * sizeof (gint16));
200  }
201 
202  xpixels = priv->xpixels;
203  ypixels = priv->ypixels;
204 
207  xstride =
210  gtk_databox_values_to_xpixels (box, xpixels, X, xtype, maxlen, xstart,
211  xstride, len);
212 
215  ystride =
218  gtk_databox_values_to_ypixels (box, ypixels, Y, ytype, maxlen, ystart,
219  ystride, len);
220 
221  pointsize = gtk_databox_graph_get_size (graph);
222 
223  for (i = 0; i < len; i++, xpixels++, ypixels++)
224  cairo_rectangle (cr, *xpixels - pointsize / 2, *ypixels - pointsize / 2,
225  pointsize, pointsize);
226 
227  cairo_fill (cr);
228  cairo_destroy (cr);
229  return;
230 }
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)
static void gtk_databox_points_class_init(GtkDataboxPointsClass *klass)
static void gtk_databox_points_complete(GtkDataboxPoints *points)
static void gtk_databox_points_init(GtkDataboxPoints *points)
GtkDataboxGraph * gtk_databox_points_new(guint len, gfloat *X, gfloat *Y, GdkRGBA *color, gint size)
static void gtk_databox_points_real_draw(GtkDataboxGraph *points, GtkDatabox *box)
GtkDataboxGraph * gtk_databox_points_new_full(guint maxlen, guint len, void *X, guint xstart, guint xstride, GType xtype, void *Y, guint ystart, guint ystride, GType ytype, GdkRGBA *color, gint size)
G_DEFINE_TYPE_WITH_PRIVATE(GtkDataboxPoints, gtk_databox_points, GTK_DATABOX_TYPE_XYC_GRAPH)
#define GTK_DATABOX_IS_POINTS(obj)
#define GTK_DATABOX_POINTS(obj)
#define GTK_DATABOX_TYPE_POINTS
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)