"Fossies" - the Fresh Open Source Software Archive

Member "gtkdatabox-1.0.0/examples/basics.c" (9 Apr 2021, 4574 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 "basics.c": 0.9.3.1_vs_1.0.0.

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: basics.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 basics
   34  *----------------------------------------------------------------*/
   35 
   36 static void
   37 create_basics (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    gfloat *X;
   48    gfloat *Y;
   49    GdkRGBA color;
   50    gint i;
   51 
   52    /* We define some data */
   53    X = g_new0 (gfloat, POINTS);
   54    Y = g_new0 (gfloat, 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 (POINTS, X, Y, &color, 1);
  100    gtk_databox_graph_add (GTK_DATABOX (box), graph);
  101 
  102    gtk_databox_set_total_limits (GTK_DATABOX (box), -1000., 5000., -10000., 23000.);
  103    gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
  104 
  105    /* -----------------------------------------------------------------
  106     * Done :-)
  107     * -----------------------------------------------------------------
  108     */
  109 
  110    separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
  111    gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 0);
  112 
  113    close_button = gtk_button_new_with_label ("close");
  114    g_signal_connect_swapped (G_OBJECT (close_button), "clicked",
  115                  G_CALLBACK (gtk_main_quit), G_OBJECT (box));
  116    gtk_box_pack_start (GTK_BOX (vbox), close_button, FALSE, FALSE, 0);
  117    gtk_widget_set_can_default(close_button, TRUE);
  118    gtk_widget_grab_default (close_button);
  119    gtk_widget_grab_focus (close_button);
  120 
  121    gtk_widget_show_all (window);
  122    gdk_window_set_cursor (gtk_widget_get_window(box), gdk_cursor_new_for_display (gdk_display_get_default (), GDK_CROSS));
  123 }
  124 
  125 gint
  126 main (gint argc, char *argv[])
  127 {
  128    gtk_init (&argc, &argv);
  129 
  130    create_basics ();
  131    gtk_main ();
  132 
  133    return 0;
  134 }