"Fossies" - the Fresh Open Source Software Archive 
Member "gtkdatabox-1.0.0/examples/grid_array.c" (31 Mar 2021, 4601 Bytes) of package /linux/privat/gtkdatabox-1.0.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "grid_array.c":
0.9.3.1_vs_1.0.0.
1 /* $Id: grid.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 #include <stdio.h>
20
21 #include <gtk/gtk.h>
22 #include <gtkdatabox.h>
23 #include <gtkdatabox_points.h>
24 #include <gtkdatabox_grid.h>
25 #include <math.h>
26
27 #define POINTS 2000
28
29 /*----------------------------------------------------------------
30 * databox grid
31 *----------------------------------------------------------------*/
32
33 static gfloat gridVert[]={100.0,300.0,500.0,700.0,900.0,1100.0,1300.0,1500.0,1700.0, 1900.0};
34 static gfloat gridHoriz[]={-100.0,-80.0,-60.0,-40.0,-20.0,0.0,20.0,40.0,60.0,80.0,100.0};
35
36 static void
37 create_grid (void)
38 {
39 GtkWidget *window = NULL;
40 GtkWidget *box1;
41 GtkWidget *box2;
42 GtkWidget *close_button;
43 GtkWidget *box;
44 GtkWidget *label;
45 GtkWidget *table;
46 GtkWidget *separator;
47 GtkDataboxGraph *graph;
48 gfloat *X;
49 gfloat *Y;
50 GdkRGBA color;
51 gint i;
52
53 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
54 gtk_widget_set_size_request (window, 500, 500);
55
56 g_signal_connect (G_OBJECT (window), "destroy",
57 G_CALLBACK (gtk_main_quit), NULL);
58
59 gtk_window_set_title (GTK_WINDOW (window),
60 "GtkDatabox: Grid Array Example");
61 gtk_container_set_border_width (GTK_CONTAINER (window), 0);
62
63 box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
64 gtk_container_add (GTK_CONTAINER (window), box1);
65
66 label =
67 gtk_label_new
68 ("This is an example of grid value arrays");
69 gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
70 separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
71 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 0);
72
73 /* Create a GtkDatabox widget along with scrollbars and rulers */
74 gtk_databox_create_box_with_scrollbars_and_rulers (&box, &table,
75 TRUE, TRUE, TRUE, TRUE);
76 gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);
77
78 gtk_databox_set_bg_color (GTK_DATABOX (box), "#272727");
79
80 X = g_new0 (gfloat, POINTS);
81 Y = g_new0 (gfloat, POINTS);
82
83 for (i = 0; i < POINTS; i++)
84 {
85 X[i] = i;
86 Y[i] = 100. * sin (i * 2 * G_PI / POINTS);
87 }
88 color.red = 0;
89 color.green = 1;
90 color.blue = 0;
91 color.alpha = 1;
92
93 graph = gtk_databox_points_new (POINTS, X, Y, &color, 3);
94 gtk_databox_graph_add (GTK_DATABOX (box), graph);
95
96 Y = g_new0 (gfloat, POINTS);
97
98 for (i = 0; i < POINTS; i++)
99 {
100 Y[i] = 100. * cos (i * 2 * G_PI / POINTS);
101 }
102 color.red = 1;
103 color.green = 0;
104 color.blue = 0;
105 color.alpha = 1;
106
107 graph = gtk_databox_points_new (POINTS, X, Y, &color, 3);
108 gtk_databox_graph_add (GTK_DATABOX (box), graph);
109
110 /* Here we start with the first grid */
111 color.red = 0;
112 color.green = 0;
113 color.blue = 1;
114 color.alpha = 1;
115
116 graph = gtk_databox_grid_array_new (11, 10, gridHoriz, gridVert, &color, 1);
117 gtk_databox_graph_add (GTK_DATABOX (box), graph);
118
119 color.red = 51000;
120 color.green = 0;
121 color.blue = 0;
122 color.alpha = 1;
123
124
125 gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
126
127 separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
128 gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
129
130 box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
131 gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
132 gtk_box_pack_end (GTK_BOX (box1), box2, FALSE, TRUE, 0);
133 close_button = gtk_button_new_with_label ("close");
134 g_signal_connect_swapped (G_OBJECT (close_button), "clicked",
135 G_CALLBACK (gtk_main_quit),
136 G_OBJECT (box));
137 gtk_box_pack_start (GTK_BOX (box2), close_button, TRUE, TRUE, 0);
138 gtk_widget_set_can_default(close_button, TRUE);
139 gtk_widget_grab_default (close_button);
140
141 gtk_widget_show_all (window);
142
143 }
144
145 gint
146 main (gint argc, char *argv[])
147 {
148 gtk_init (&argc, &argv);
149
150 create_grid ();
151 gtk_main ();
152
153 return 0;
154 }