"Fossies" - the Fresh Open Source Software Archive

Member "gtkdatabox-1.0.0/examples/markers.c" (31 Mar 2021, 8373 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 "markers.c": 0.9.3.1_vs_1.0.0.

    1 /* $Id: markers.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_markers.h>
   25 #include <math.h>
   26 
   27 #define POINTS 24
   28 
   29 /*----------------------------------------------------------------
   30  *  databox markerss
   31  *----------------------------------------------------------------*/
   32 
   33 void
   34 setM (GtkDataboxGraph * graph,
   35       guint index,
   36       GtkDataboxMarkersPosition position,
   37       GtkDataboxMarkersTextPosition label_position, gchar * label, gboolean boxed)
   38 {
   39    GtkDataboxMarkers *markers = GTK_DATABOX_MARKERS (graph);
   40 
   41    g_return_if_fail (GTK_DATABOX_IS_MARKERS (markers));
   42 
   43    gtk_databox_markers_set_position (markers, index, position);
   44    gtk_databox_markers_set_label (markers, index, label_position, label, boxed);
   45 }
   46 
   47 void
   48 setL (GtkDataboxGraph * graph,
   49       guint index,
   50       GtkDataboxMarkersPosition position,
   51       GtkDataboxMarkersTextPosition label_position, gchar * label, gboolean boxed)
   52 {
   53    GtkDataboxMarkers *markers = GTK_DATABOX_MARKERS (graph);
   54 
   55    g_return_if_fail (GTK_DATABOX_IS_MARKERS (markers));
   56 
   57    gtk_databox_markers_set_position (markers, index, position);
   58    gtk_databox_markers_set_label (markers, index, label_position, label, boxed);
   59 }
   60 
   61 void
   62 setT (GtkDataboxGraph * graph,
   63       guint index,
   64       GtkDataboxMarkersTextPosition label_position, gchar * label, gboolean boxed)
   65 {
   66    GtkDataboxMarkers *markers = GTK_DATABOX_MARKERS (graph);
   67 
   68    g_return_if_fail (GTK_DATABOX_IS_MARKERS (markers));
   69 
   70    gtk_databox_markers_set_label (markers, index, label_position, label, boxed);
   71 }
   72 
   73 static void
   74 create_markerss (void)
   75 {
   76    GtkWidget *window = NULL;
   77    GtkWidget *box1;
   78    GtkWidget *box2;
   79    GtkWidget *close_button;
   80    GtkWidget *box;
   81    GtkWidget *table;
   82    GtkWidget *label;
   83    GtkWidget *separator;
   84    gfloat *X;
   85    gfloat *Y;
   86    gint i;
   87    GtkDataboxGraph *graph;
   88    GdkRGBA color;
   89 
   90    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   91    gtk_widget_set_size_request (window, 600, 600);
   92 
   93    g_signal_connect (G_OBJECT (window), "destroy",
   94              G_CALLBACK (gtk_main_quit), NULL);
   95 
   96    gtk_window_set_title (GTK_WINDOW (window), "GtkDatabox: Markers");
   97    gtk_container_set_border_width (GTK_CONTAINER (window), 0);
   98 
   99    box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  100    gtk_container_add (GTK_CONTAINER (window), box1);
  101 
  102    label =
  103       gtk_label_new
  104       ("Some markers (green) are shown below.\nThe text corresponds to the position of the text, relative to the markers.\n\nThere are also some texts (yellow).\n\nData points are red\n");
  105    gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
  106    separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
  107    gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 0);
  108 
  109    gtk_databox_create_box_with_scrollbars_and_rulers (&box, &table,
  110                               TRUE, TRUE, TRUE, TRUE);
  111    gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);
  112 
  113    gtk_databox_set_bg_color (GTK_DATABOX (box), "#545454");
  114 
  115    X = g_new0 (gfloat, 20 + 4 + 5);
  116    Y = g_new0 (gfloat, 20 + 4 + 5);
  117 
  118    for (i = 0; i < 20 + 4 + 5; ++i)
  119    {
  120       X[i] = i % 4;
  121       Y[i] = i / 4;
  122    }
  123    X[20] = -0.5;
  124    Y[20] = -0.5;
  125    X[21] = -0.5;
  126    Y[21] = 4.5;
  127    X[22] = 3.5;
  128    Y[22] = -0.5;
  129    X[23] = 3.5;
  130    Y[23] = 4.5;
  131 
  132    X[24] = -1.;
  133    Y[24] = -1.;
  134    X[25] = -1.;
  135    Y[25] = +5.;
  136    X[26] = +4.;
  137    Y[26] = -1.;
  138    X[27] = +4.;
  139    Y[27] = +5.;
  140    X[28] = +1.5;
  141    Y[28] = +2.;
  142 
  143    color.red = 1;
  144    color.green = 0;
  145    color.blue = 0;
  146    color.alpha = 1;
  147 
  148    graph = gtk_databox_points_new (20 + 4 + 5, X, Y, &color, 3);
  149    gtk_databox_graph_add (GTK_DATABOX (box), graph);
  150 
  151    color.red = 0;
  152    color.green = 1;
  153    color.blue = 0;
  154    color.alpha = 1;
  155 
  156    graph = gtk_databox_markers_new (20, X, Y, &color, 15,
  157                    GTK_DATABOX_MARKERS_TRIANGLE);
  158 
  159    gtk_databox_graph_add (GTK_DATABOX (box), graph);
  160    setM (graph, 0, GTK_DATABOX_MARKERS_W, GTK_DATABOX_MARKERS_TEXT_W, "West", FALSE);
  161    setM (graph, 1, GTK_DATABOX_MARKERS_N, GTK_DATABOX_MARKERS_TEXT_N, "North", FALSE);
  162    setM (graph, 2, GTK_DATABOX_MARKERS_S, GTK_DATABOX_MARKERS_TEXT_S, "South", FALSE);
  163    setM (graph, 3, GTK_DATABOX_MARKERS_E, GTK_DATABOX_MARKERS_TEXT_E, "East", FALSE);
  164 
  165    setM (graph, 4, GTK_DATABOX_MARKERS_W, GTK_DATABOX_MARKERS_TEXT_W, "West", TRUE);
  166    setM (graph, 5, GTK_DATABOX_MARKERS_N, GTK_DATABOX_MARKERS_TEXT_N, "North", TRUE);
  167    setM (graph, 6, GTK_DATABOX_MARKERS_S, GTK_DATABOX_MARKERS_TEXT_S, "South", TRUE);
  168    setM (graph, 7, GTK_DATABOX_MARKERS_E, GTK_DATABOX_MARKERS_TEXT_E, "East", TRUE);
  169 
  170    setM (graph, 8, GTK_DATABOX_MARKERS_E, GTK_DATABOX_MARKERS_TEXT_W, "West", TRUE);
  171    setM (graph, 9, GTK_DATABOX_MARKERS_S, GTK_DATABOX_MARKERS_TEXT_N, "North", TRUE);
  172    setM (graph, 10, GTK_DATABOX_MARKERS_N, GTK_DATABOX_MARKERS_TEXT_S, "South", TRUE);
  173    setM (graph, 11, GTK_DATABOX_MARKERS_W, GTK_DATABOX_MARKERS_TEXT_E, "East", TRUE);
  174 
  175    setM (graph, 12, GTK_DATABOX_MARKERS_W, GTK_DATABOX_MARKERS_TEXT_S, "South", TRUE);
  176    setM (graph, 13, GTK_DATABOX_MARKERS_N, GTK_DATABOX_MARKERS_TEXT_W, "West", TRUE);
  177    setM (graph, 14, GTK_DATABOX_MARKERS_S, GTK_DATABOX_MARKERS_TEXT_E, "East", TRUE);
  178    setM (graph, 15, GTK_DATABOX_MARKERS_E, GTK_DATABOX_MARKERS_TEXT_N, "North", TRUE);
  179 
  180    setM (graph, 16, GTK_DATABOX_MARKERS_W, GTK_DATABOX_MARKERS_TEXT_SW, "SW", TRUE);
  181    setM (graph, 17, GTK_DATABOX_MARKERS_N, GTK_DATABOX_MARKERS_TEXT_NW, "NW", TRUE);
  182    setM (graph, 18, GTK_DATABOX_MARKERS_S, GTK_DATABOX_MARKERS_TEXT_SE, "SE", TRUE);
  183    setM (graph, 19, GTK_DATABOX_MARKERS_E, GTK_DATABOX_MARKERS_TEXT_NE, "NE", TRUE);
  184 
  185 
  186    graph = gtk_databox_markers_new (4, X + 20, Y + 20, &color, 1,
  187                    GTK_DATABOX_MARKERS_DASHED_LINE);
  188 
  189    gtk_databox_graph_add (GTK_DATABOX (box), graph);
  190    setL (graph, 0, GTK_DATABOX_MARKERS_N, GTK_DATABOX_MARKERS_TEXT_W, "West", TRUE);
  191    setL (graph, 1, GTK_DATABOX_MARKERS_E, GTK_DATABOX_MARKERS_TEXT_S, "South", TRUE);
  192    setL (graph, 2, GTK_DATABOX_MARKERS_W, GTK_DATABOX_MARKERS_TEXT_N, "North", TRUE);
  193    setL (graph, 3, GTK_DATABOX_MARKERS_S, GTK_DATABOX_MARKERS_TEXT_E, "East", TRUE);
  194 
  195    color.red = 1;
  196    color.green = 1;
  197    color.blue = 0;
  198    color.alpha = 1;
  199 
  200    graph = gtk_databox_markers_new (5, X + 20 + 4, Y + 20 + 4, &color, 1,
  201                    GTK_DATABOX_MARKERS_NONE);
  202 
  203    gtk_databox_graph_add (GTK_DATABOX (box), graph);
  204    setT (graph, 0, GTK_DATABOX_MARKERS_TEXT_N, "North", FALSE);
  205    setT (graph, 1, GTK_DATABOX_MARKERS_TEXT_E, "East", FALSE);
  206    setT (graph, 2, GTK_DATABOX_MARKERS_TEXT_S, "South", FALSE);
  207    setT (graph, 3, GTK_DATABOX_MARKERS_TEXT_W, "West", FALSE);
  208    setT (graph, 4, GTK_DATABOX_MARKERS_TEXT_CENTER, "Centered", TRUE);
  209 
  210 
  211    gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
  212 
  213    separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
  214    gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
  215 
  216    box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
  217    gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
  218    gtk_box_pack_end (GTK_BOX (box1), box2, FALSE, TRUE, 0);
  219    close_button = gtk_button_new_with_label ("close");
  220    g_signal_connect_swapped (G_OBJECT (close_button), "clicked",
  221                  G_CALLBACK (gtk_main_quit), G_OBJECT (box));
  222    gtk_box_pack_start (GTK_BOX (box2), close_button, TRUE, TRUE, 0);
  223    gtk_widget_set_can_default(close_button, TRUE);
  224    gtk_widget_grab_default (close_button);
  225 
  226    gtk_widget_show_all (window);
  227 
  228 }
  229 
  230 gint
  231 main (gint argc, char *argv[])
  232 {
  233    gtk_init (&argc, &argv);
  234 
  235    create_markerss ();
  236    gtk_main ();
  237 
  238    return 0;
  239 }