"Fossies" - the Fresh Open Source Software Archive

Member "gtkdatabox-1.0.0/examples/full.c" (9 Apr 2021, 4625 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.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.


    1 /* $Id: full.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_ruler.h>
   25 #include <math.h>
   26 
   27 #define POINTS 2000
   28 #define STEPS 50
   29 #define BARS 25
   30 #define MARKER 10
   31 
   32 /*----------------------------------------------------------------
   33  *  databox full
   34  *----------------------------------------------------------------*/
   35 
   36 static void
   37 create_full (void)
   38 {
   39    GtkWidget *window = NULL;
   40    GtkWidget *vbox;
   41    GtkWidget *close_button;
   42    GtkWidget *box;
   43    GtkWidget *label;
   44    GtkWidget *separator;
   45    GtkWidget *table;
   46    GtkDataboxGraph *graph;
   47    guint *X;
   48    gdouble *Y;
   49    GdkRGBA color;
   50    gint i;
   51 
   52    /* We define some data */
   53    X = g_new0 (guint, POINTS);
   54    Y = g_new0 (gdouble, POINTS);
   55 
   56    for (i = 0; i < POINTS; i++)
   57    {
   58       X[i] = i;
   59       Y[i] = sin (i * 4 * G_PI / POINTS);
   60    }
   61 
   62    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   63    gtk_widget_set_size_request (window, 500, 500);
   64 
   65    g_signal_connect (G_OBJECT (window), "destroy",
   66              G_CALLBACK (gtk_main_quit), NULL);
   67 
   68    gtk_window_set_title (GTK_WINDOW (window), "GtkDatabox: Basics");
   69    gtk_container_set_border_width (GTK_CONTAINER (window), 0);
   70 
   71    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   72    gtk_container_add (GTK_CONTAINER (window), vbox);
   73 
   74    label =
   75       gtk_label_new
   76       ("\nThe code for this example demonstrates\n the simplet way to use a GtkDatabox widget.\n\nUsage:\nDraw a selection with the left button pressed,\nThan click into the selection.\nUse the right mouse button to zoom out.\nShift+ right mouse button zooms to default.\n\nMouse scroll-wheel: \n*Holding Ctrl+ scrollwheel zooms in/out. \nScroll-wheel moves up/down. \n*Holding Shift+ scroll-wheel moves left/right in the plot.");
   77    gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
   78    separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
   79    gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
   80 
   81    /* -----------------------------------------------------------------
   82     * This is all you need:
   83     * -----------------------------------------------------------------
   84     */
   85 
   86    /* Create the GtkDatabox widget */
   87    gtk_databox_create_box_with_scrollbars_and_rulers (&box, &table,
   88                               TRUE, TRUE, TRUE, TRUE);
   89 
   90    /* Put it somewhere */
   91    gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
   92 
   93    /* Add your data data in some color */
   94    color.red = 0;
   95    color.green = 0;
   96    color.blue = 0;
   97    color.alpha = 1;
   98 
   99    graph = gtk_databox_points_new_full (POINTS, POINTS,
  100         X, 0, 1, G_TYPE_UINT,
  101         Y, 0, 1, G_TYPE_DOUBLE,
  102         &color, 1);
  103    gtk_databox_graph_add (GTK_DATABOX (box), graph);
  104 
  105    gtk_databox_set_total_limits (GTK_DATABOX (box), -1000., 5000., -10000., 23000.);
  106    gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
  107 
  108    /* -----------------------------------------------------------------
  109     * Done :-)
  110     * -----------------------------------------------------------------
  111     */
  112 
  113    separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
  114    gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 0);
  115 
  116    close_button = gtk_button_new_with_label ("close");
  117    g_signal_connect_swapped (G_OBJECT (close_button), "clicked",
  118                  G_CALLBACK (gtk_main_quit), G_OBJECT (box));
  119    gtk_box_pack_start (GTK_BOX (vbox), close_button, FALSE, FALSE, 0);
  120    gtk_widget_set_can_default(close_button, TRUE);
  121    gtk_widget_grab_default (close_button);
  122    gtk_widget_grab_focus (close_button);
  123 
  124    gtk_widget_show_all (window);
  125    gdk_window_set_cursor (gtk_widget_get_window(box), gdk_cursor_new_for_display (gdk_display_get_default (), GDK_CROSS));
  126 }
  127 
  128 gint
  129 main (gint argc, char *argv[])
  130 {
  131    gtk_init (&argc, &argv);
  132 
  133    create_full ();
  134    gtk_main ();
  135 
  136    return 0;
  137 }