"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "examples/colors.c" between
gtkdatabox-0.9.3.1.tar.gz and gtkdatabox-1.0.0.tar.gz

About: GtkDatabox is a Gtk+-widget for live display of large amounts of fluctuating numerical data.

colors.c  (gtkdatabox-0.9.3.1):colors.c  (gtkdatabox-1.0.0)
skipping to change at line 17 skipping to change at line 17
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version. * version 2 of the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details. * Library General Public License for more details.
* *
* You should have received a copy of the GNU Library General Public * You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the * License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1307, USA. * Boston, MA 02110-1301 USA.
*/ */
#include <stdio.h> #include <stdio.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gtkdatabox.h> #include <gtkdatabox.h>
#include <gtkdatabox_points.h> #include <gtkdatabox_points.h>
#include <math.h> #include <math.h>
#define POINTS 2000 #define POINTS 2000
#define NO_OF_DATASETS 5 #define NO_OF_DATASETS 5
typedef struct typedef struct
{ {
GtkColorSelectionDialog *selector; GtkWidget *selector;
GtkWidget *box; GtkWidget *box;
GtkDataboxGraph *graph; GtkDataboxGraph *graph;
gint index; gint index;
} }
col_sel; col_sel;
static void static void
get_color_cb (col_sel * sel /*, GtkWidget *widget */ ) get_color_cb(GtkDialog *dialog, gint response_id, gpointer user_data)
{ {
GdkColor color; GdkRGBA rgba;
col_sel *sel = (col_sel *)user_data;
g_return_if_fail (GTK_IS_COLOR_SELECTION_DIALOG (sel->selector)); g_return_if_fail (GTK_IS_DATABOX (sel->box));
g_return_if_fail (GTK_IS_DATABOX (sel->box));
gtk_color_selection_get_current_color (GTK_COLOR_SELECTION if (response_id == GTK_RESPONSE_OK)
(sel->selector->colorsel), &color); {
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(dialog), &rgba);
gtk_databox_graph_set_color (sel->graph, &color); gtk_databox_graph_set_color (sel->graph, &rgba);
gtk_widget_queue_draw (GTK_WIDGET (sel->box)); gtk_widget_queue_draw (GTK_WIDGET (sel->box));
}
gtk_widget_destroy(GTK_WIDGET(dialog));
} }
static void static void
menu_color_change_cb (col_sel * sel) menu_color_change_cb (col_sel * sel)
{ {
GtkColorSelectionDialog *selector; GtkWidget *selector;
gchar title[20]; gchar title[20];
GdkColor *color; GdkRGBA rgba;
sprintf (title, "Choose color #%d", sel->index); sprintf (title, "Choose color #%d", sel->index);
selector = selector = gtk_color_chooser_dialog_new(title, NULL);
GTK_COLOR_SELECTION_DIALOG (gtk_color_selection_dialog_new (title));
gtk_widget_destroy (selector->help_button);
sel->selector = selector; sel->selector = selector;
color = gtk_databox_graph_get_color (sel->graph); rgba = *gtk_databox_graph_get_color (sel->graph);
gtk_color_selection_set_current_color (GTK_COLOR_SELECTION gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(sel->selector), &rgba);
(selector->colorsel), color); gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(sel->selector), FALSE);
g_signal_connect(G_OBJECT(sel->selector), "response", G_CALLBACK(get_color_cb
g_signal_connect_object (G_OBJECT (selector->cancel_button), "clicked", ), (gpointer)sel);
G_CALLBACK (gtk_widget_destroy), gtk_widget_show (GTK_WIDGET (sel->selector));
G_OBJECT (selector), G_CONNECT_SWAPPED);
g_signal_connect_swapped (G_OBJECT
(selector->ok_button),
"clicked", G_CALLBACK (get_color_cb),
(gpointer) sel);
gtk_widget_show (GTK_WIDGET (selector));
return; return;
} }
static void static void
create_menu_entry (GtkWidget * menu, int index, create_menu_entry (GtkWidget * menu, int index,
GtkWidget * box, GtkDataboxGraph * graph) GtkWidget * box, GtkDataboxGraph * graph)
{ {
GtkWidget *menu_items; GtkWidget *menu_items;
char buf[128]; char buf[128];
skipping to change at line 120 skipping to change at line 113
GtkWidget *close_button = NULL; GtkWidget *close_button = NULL;
GtkWidget *box = NULL; GtkWidget *box = NULL;
GtkWidget *separator; GtkWidget *separator;
GtkWidget *label; GtkWidget *label;
GtkWidget *menu; GtkWidget *menu;
GtkWidget *root_menu; GtkWidget *root_menu;
GtkWidget *menu_bar; GtkWidget *menu_bar;
gfloat *X = NULL; gfloat *X = NULL;
gfloat *Y = NULL; gfloat *Y = NULL;
gint i, j; gint i, j;
GdkColor color;
GtkDataboxGraph *graph; GtkDataboxGraph *graph;
GdkRGBA color;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (window, 500, 300); gtk_widget_set_size_request (window, 500, 300);
g_signal_connect (G_OBJECT (window), "destroy", g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL); G_CALLBACK (gtk_main_quit), NULL);
gtk_window_set_title (GTK_WINDOW (window), "GtkDatabox: Colors"); gtk_window_set_title (GTK_WINDOW (window), "GtkDatabox: Colors");
gtk_container_set_border_width (GTK_CONTAINER (window), 0); gtk_container_set_border_width (GTK_CONTAINER (window), 0);
box1 = gtk_vbox_new (FALSE, 0); box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (window), box1); gtk_container_add (GTK_CONTAINER (window), box1);
box = gtk_databox_new (); box = gtk_databox_new ();
gtk_databox_set_enable_selection (GTK_DATABOX (box), FALSE); gtk_databox_set_enable_selection (GTK_DATABOX (box), FALSE);
gtk_databox_set_enable_zoom (GTK_DATABOX (box), FALSE); gtk_databox_set_enable_zoom (GTK_DATABOX (box), FALSE);
color.red = 0; gtk_databox_set_bg_color (GTK_DATABOX (box), "black");
color.green = 0;
color.blue = 0;
gtk_widget_modify_bg (box, GTK_STATE_NORMAL, &color);
menu = gtk_menu_new (); menu = gtk_menu_new ();
root_menu = gtk_menu_item_new_with_label ("Color Menu"); root_menu = gtk_menu_item_new_with_label ("Color Menu");
gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu); gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);
menu_bar = gtk_menu_bar_new (); menu_bar = gtk_menu_bar_new ();
gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), root_menu); gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), root_menu);
gtk_box_pack_start (GTK_BOX (box1), menu_bar, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), menu_bar, FALSE, TRUE, 0);
label = label =
gtk_label_new gtk_label_new
("You can change the colors of the shown datasets via the menu.\n\n"); ("You can change the colors of the shown datasets via the menu.\n\n");
gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
separator = gtk_hseparator_new (); separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 0);
g_signal_connect (G_OBJECT (box), "destroy", g_signal_connect (G_OBJECT (box), "destroy",
G_CALLBACK (gtk_main_quit), NULL); G_CALLBACK (gtk_main_quit), NULL);
color.alpha = 1.0;
for (i = 0; i < NO_OF_DATASETS; i++) for (i = 0; i < NO_OF_DATASETS; i++)
{ {
if (!i) if (!i)
X = g_new0 (gfloat, POINTS); X = g_new0 (gfloat, POINTS);
Y = g_new0 (gfloat, POINTS); Y = g_new0 (gfloat, POINTS);
for (j = 0; j < POINTS; j++) for (j = 0; j < POINTS; j++)
{ {
X[j] = j; X[j] = j;
Y[j] = 100. * sin ((i + 1) * 2 * j * G_PI / POINTS); Y[j] = 100. * sin ((i + 1) * 2 * j * G_PI / POINTS);
} }
color.red = 65535 * ((i + 1) % 2); color.red = 1 * ((i + 1) % 2);
color.green = (65535 / 2) * ((i + 1) % 3); color.green = (1 / 2) * ((i + 1) % 3);
color.blue = (65535 / 3) * ((i + 1) % 4); color.blue = (1 / 3) * ((i + 1) % 4);
graph = gtk_databox_points_new (POINTS, X, Y, &color, 1); graph = gtk_databox_points_new (POINTS, X, Y, &color, 1);
gtk_databox_graph_add (GTK_DATABOX (box), graph); gtk_databox_graph_add (GTK_DATABOX (box), graph);
create_menu_entry (menu, i, box, graph); create_menu_entry (menu, i, box, graph);
} }
gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05); gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
gtk_box_pack_start (GTK_BOX (box1), box, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), box, TRUE, TRUE, 0);
separator = gtk_hseparator_new (); separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
box2 = gtk_vbox_new (FALSE, 10); box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10); gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_end (GTK_BOX (box1), box2, FALSE, TRUE, 0); gtk_box_pack_end (GTK_BOX (box1), box2, FALSE, TRUE, 0);
close_button = gtk_button_new_with_label ("close"); close_button = gtk_button_new_with_label ("close");
g_signal_connect (G_OBJECT (close_button), "clicked", g_signal_connect (G_OBJECT (close_button), "clicked",
G_CALLBACK (gtk_main_quit), (gpointer) NULL); G_CALLBACK (gtk_main_quit), (gpointer) NULL);
gtk_box_pack_start (GTK_BOX (box2), close_button, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box2), close_button, TRUE, TRUE, 0);
gtk_widget_set_can_default(close_button, GTK_CAN_DEFAULT); gtk_widget_set_can_default(close_button, TRUE);
gtk_widget_grab_default (close_button); gtk_widget_grab_default (close_button);
gtk_widget_show_all (window); gtk_widget_show_all (window);
} }
gint gint
main (gint argc, char *argv[]) main (gint argc, char *argv[])
{ {
gtk_init (&argc, &argv); gtk_init (&argc, &argv);
 End of changes. 20 change blocks. 
42 lines changed or deleted 34 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)