"Fossies" - the Fresh Open Source Software Archive

Member "gtkdatabox-1.0.0/examples/grid.c" (31 Mar 2021, 4654 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.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 void
   34 create_grid (void)
   35 {
   36    GtkWidget *window = NULL;
   37    GtkWidget *box1;
   38    GtkWidget *box2;
   39    GtkWidget *close_button;
   40    GtkWidget *box;
   41    GtkWidget *label;
   42    GtkWidget *table;
   43    GtkWidget *separator;
   44    GtkDataboxGraph *graph;
   45    gfloat *X;
   46    gfloat *Y;
   47    GdkRGBA color;
   48    gint i;
   49 
   50    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   51    gtk_widget_set_size_request (window, 500, 500);
   52 
   53    g_signal_connect (G_OBJECT (window), "destroy",
   54              G_CALLBACK (gtk_main_quit), NULL);
   55 
   56    gtk_window_set_title (GTK_WINDOW (window),
   57              "GtkDatabox: Double Grid Example");
   58    gtk_container_set_border_width (GTK_CONTAINER (window), 0);
   59 
   60    box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   61    gtk_container_add (GTK_CONTAINER (window), box1);
   62 
   63    label =
   64       gtk_label_new
   65       ("This is an example of two grids\nLove it or hate it.\nI love it...\n\nFor basic understanding see basics :-)");
   66    gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
   67    separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
   68    gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 0);
   69 
   70    /* Create a GtkDatabox widget along with scrollbars and rulers */
   71    gtk_databox_create_box_with_scrollbars_and_rulers (&box, &table,
   72                               TRUE, TRUE, TRUE, TRUE);
   73    gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);
   74 
   75    gtk_databox_set_bg_color (GTK_DATABOX (box), "#9A9A9A");
   76 
   77    X = g_new0 (gfloat, POINTS);
   78    Y = g_new0 (gfloat, POINTS);
   79 
   80    for (i = 0; i < POINTS; i++)
   81    {
   82       X[i] = i;
   83       Y[i] = 100. * sin (i * 2 * G_PI / POINTS);
   84    }
   85    color.red = 0;
   86    color.green = 1;
   87    color.blue = 0;
   88    color.alpha = 1;
   89 
   90    graph = gtk_databox_points_new (POINTS, X, Y, &color, 3);
   91    gtk_databox_graph_add (GTK_DATABOX (box), graph);
   92 
   93    Y = g_new0 (gfloat, POINTS);
   94 
   95    for (i = 0; i < POINTS; i++)
   96    {
   97       Y[i] = 100. * cos (i * 2 * G_PI / POINTS);
   98    }
   99    color.red = 1;
  100    color.green = 0;
  101    color.blue = 0;
  102    color.alpha = 1;
  103 
  104    graph = gtk_databox_points_new (POINTS, X, Y, &color, 3);
  105    gtk_databox_graph_add (GTK_DATABOX (box), graph);
  106 
  107    /* Here we start with the first grid */
  108    color.red = 0;
  109    color.green = 0;
  110    color.blue = 1;
  111    color.alpha = 1;
  112 
  113    graph = gtk_databox_grid_new (7, 7, &color, 2);
  114    gtk_databox_graph_add (GTK_DATABOX (box), graph);
  115 
  116    color.red = 0.9;
  117    color.green = 0;
  118    color.blue = 0;
  119    color.alpha = 1;
  120 
  121    graph = gtk_databox_grid_new (15, 15, &color, 2);
  122    gtk_databox_graph_add (GTK_DATABOX (box), graph);
  123    gtk_databox_grid_set_line_style (GTK_DATABOX_GRID(graph), GTK_DATABOX_GRID_DOTTED_LINES);
  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 }