/* $Id: demo.c,v 1.10 2002/01/08 06:28:57 trow Exp $ */ /* * demo.c * * Copyright (C) 1999, 2000 EMC Capital Management, Inc. * Copyright (C) 2001 The Free Software Foundation * * Developed by Jon Trowbridge and * Havoc Pennington . * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include #include #include #include #include "guppi-root-group-view.h" #include "guppi-group-view-layout.h" #include #include #include #include #include #include #include #include #include #include #include #include GtkWidget *window; GtkWidget *canvas; GuppiRootGroupView *root_view; GuppiElementState *g1_state, *g2_state, *text_state, *bp_state, *ax_state; GuppiElementView *g1_view, *g2_view, *text_view, *bp_view, *ax_view; GuppiData *d1, *d2, *d3; GuppiColorPalette *pal; const gchar *labels[] = { "This is a demo program for Guppi", "
This text element can handle
two lines of text
", "A fun number: ", "Another fun number: ", "Fun Large Text!", "
Three lines
of text is also
not a problem
", "
It
is
possible
to
go
a
bit
too
far
though
", NULL }; gint label_index = 0; guint timeout = 0; static void init (gint argc, gchar *argv[]) { gnome_init ("demo", "0.0", argc, argv); glade_gnome_init (); guppi_useful_init_without_guile (); guppi_data_init (); guppi_plot_init (); guppi_plug_in_path_set ("../plug-ins"); guppi_plug_in_spec_find_all (); } static gboolean label_timeout (gpointer foo) { guppi_element_state_set (text_state, "text", labels[label_index], NULL); ++label_index; if (labels[label_index] == NULL) label_index = 0; /* guppi_color_palette_set_offset (pal, guppi_color_palette_get_offset (pal) + 1); */ /* guppi_element_view_set_preferred_view (bar_view, GUPPI_X_AXIS); guppi_element_view_set_preferred_view (bar_view, GUPPI_Y_AXIS); */ return TRUE; } static void quit (GtkWidget *w, GdkEventAny *ev, gpointer closure) { if (timeout) gtk_timeout_remove (timeout); guppi_unref (root_view); guppi_unref (g1_state); guppi_unref (g2_state); guppi_unref (text_state); guppi_unref (ax_state); guppi_unref (bp_state); guppi_unref (g1_view); guppi_unref (g2_view); guppi_unref (text_view); guppi_unref (bp_view); guppi_unref (ax_view); guppi_unref (d1); guppi_unref (d2); guppi_unref (d3); guppi_unref (pal); gtk_widget_destroy (window); gtk_main_quit (); } static void build_gui (void) { canvas = (GtkWidget *) guppi_root_group_view_make_canvas (root_view, NULL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_usize (window, 800, 600); gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (quit), NULL); gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (canvas)); gtk_widget_show_all (window); } /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */ #define DATA_COUNT 250 static GuppiElementView * build_scatter_demo (void) { GuppiElementState *scatter_state, *frame_state, *x_ax_state, *y_ax_state, *x_bp_state, *y_bp_state; GuppiElementView *scatter_view, *frame_view, *x_ax_view, *y_ax_view, *x_bp_view, *y_bp_view; GuppiGroupView *group_view; GuppiSeqScalar *x_data, *y_data; gint i; double t, x, y; x_data = guppi_seq_scalar_core_new (); y_data = guppi_seq_scalar_core_new (); for (i=0; icompass
item", NULL); compass_box_state = guppi_element_state_new ("compass-box", "position", compass_pos, NULL); compass_box_view = guppi_element_view_new (compass_box_state, NULL); gtk_timeout_add (2000, compass_cb, compass_box_state); floating_view = guppi_element_view_new (text_state, NULL); fixed_view = build_pie_demo (); guppi_group_view_add (GUPPI_GROUP_VIEW (compass_box_view), floating_view); guppi_group_view_add (GUPPI_GROUP_VIEW (compass_box_view), fixed_view); return compass_box_view; } /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */ static GuppiElementView * build_image_demo (void) { GuppiElementState *img_state; GuppiElementView *img_view; img_state = guppi_element_state_new ("image", "filename", "../pixmaps/guppi-splash.png", NULL); img_view = guppi_element_view_new (img_state, NULL); return img_view; } /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */ static void layout_elements (void) { GuppiGroupView *group; GuppiElementView *bar_view = build_barchart_demo (); GuppiElementView *scatter_view = build_scatter_demo (); GuppiElementView *pie_view = build_compass_pie_demo (); GuppiElementView *img_view = build_image_demo (); root_view = GUPPI_ROOT_GROUP_VIEW (guppi_root_group_view_new ()); guppi_root_group_view_set_size (root_view, 72*11, 72*8.5); text_state = guppi_element_state_new ("text", "label", "text_state", "text", "Initial Text", NULL); text_view = guppi_element_view_new (text_state, NULL); /* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */ group = GUPPI_GROUP_VIEW (root_view); guppi_group_view_layout_horizontally_aligned (group, scatter_view, pie_view, 0); guppi_group_view_layout_horizontally_aligned (group, pie_view, bar_view, 0); guppi_group_view_layout_flush_left (group, scatter_view, 0); guppi_group_view_layout_flush_bottom (group, scatter_view, 0); guppi_group_view_layout_flush_right (group, bar_view, 0); guppi_group_view_layout_same_width (group, scatter_view, pie_view); guppi_group_view_layout_same_width (group, pie_view, bar_view); guppi_group_view_layout_flush_top (group, img_view, 0); guppi_group_view_layout_vertically_adjacent (group, img_view, text_view, 0); guppi_group_view_layout_center_horizontally (group, img_view); guppi_group_view_layout_center_horizontally (group, text_view); guppi_group_view_layout_vertically_adjacent (group, text_view, scatter_view, 0); { GuppiConfigModel *model; GtkWidget *w; model = guppi_element_view_make_config_model ((GuppiElementView *) root_view); w = guppi_config_dialog_new (model, root_view); guppi_unref (model); gtk_widget_show (w); } } int main (int argc, char *argv[]) { gint fd; fd = open ("workaround.c", O_RDONLY); if (fd == -1) { g_print ("For obscure technical reasons, you need to be in the same directory as the\n"); g_print ("'demo' executable in order for things to work properly.\n"); exit (0); } close (fd); init (argc, argv); // guppi_memory_trace (TRUE); // guppi_set_verbosity (GUPPI_VERBOSE); #if 0 g_message ("building data"); build_data (); g_message ("building elements"); build_elements (); #endif g_message ("laying out elements"); layout_elements (); #if 0 { GuppiXMLDocument *doc; xmlNodePtr node; doc = guppi_xml_document_new (); guppi_xml_document_set_root (doc, guppi_element_view_export_xml (root_view, doc)); guppi_xml_document_write_file (doc, "/tmp/guppi.foo"); guppi_xml_document_free (doc); guppi_unref (root_view); doc = guppi_xml_document_read_file ("/tmp/guppi.foo"); root_view = guppi_element_view_import_xml (doc, guppi_xml_document_get_root (doc)); guppi_xml_document_free (doc); doc = guppi_xml_document_new (); guppi_xml_document_set_root (doc, guppi_element_view_export_xml (root_view, doc)); guppi_xml_document_write_file (doc, "/tmp/guppi.bar"); guppi_xml_document_free (doc); } #endif g_message ("building gui"); build_gui (); #if 0 g_message ("printing"); guppi_element_view_print_ps_to_file ((GuppiElementView *) root_view, "./demo.ps"); g_message ("done printing"); #endif timeout = gtk_timeout_add (3000, label_timeout, NULL); gtk_main (); return 0; } /* $Id: demo.c,v 1.10 2002/01/08 06:28:57 trow Exp $ */