File: info.c

package info (click to toggle)
chameleon 1.0-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 136 kB
  • ctags: 27
  • sloc: ansic: 356; makefile: 68
file content (96 lines) | stat: -rw-r--r-- 2,543 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
** This code is for the color information dialog box.
** ff, 1998.
*/

#include <gtk/gtk.h>

void delete_event (GtkWidget *widget, GdkEvent *event, gpointer *data);


void kill_box(GtkWidget *widget, GdkEvent *event, gpointer *data)
{
	gtk_main_quit();
	gtk_widget_destroy(GTK_WIDGET(widget));
}

void color_info(GtkWidget *widget, gpointer *colorsel)
{
	gdouble data[3];
	int red, green, blue;
	char rgb[32], hex[32];

	GtkWidget *window, *button, *title, *box, *values,
		*string, *separator, *quitbox;


	gtk_color_selection_get_color(GTK_COLOR_SELECTION(colorsel),
		(gdouble *)&data);
	

/* Put together the RGB values in base 10 */
	sprintf(rgb, "%.0f", data[0]*255.0);
	red = atoi(rgb);
	sprintf(rgb, "%.0f", data[1]*255.0);
	green = atoi(rgb);
	sprintf(rgb, "%.0f", data[2]*255.0);
	blue = atoi(rgb);

	sprintf(rgb, "\nRGB (base 10):   %.3d %.3d %.3d", red, green, blue);


/* Put together the RGB string in hex notation */
	sprintf(hex, "Hex string:   #%.2x%.2x%.2x\n", red, green, blue);


	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW(window), "Color Info");

	gtk_signal_connect (GTK_OBJECT (window), "delete_event",
		GTK_SIGNAL_FUNC (delete_event), NULL);
	gtk_container_border_width (GTK_CONTAINER (window), 15);

	box = gtk_vbox_new (FALSE, 0);
 
 	title = gtk_label_new("Color Information\n");
	gtk_box_pack_start (GTK_BOX (box), title, FALSE, FALSE, 0);
	gtk_widget_show (title);

	separator = gtk_hseparator_new ();
	gtk_box_pack_start (GTK_BOX (box), separator, FALSE, TRUE, 5);
	gtk_widget_show (separator);

	values = gtk_label_new(rgb);
	gtk_misc_set_alignment(GTK_MISC(values), 0, 0);
	gtk_box_pack_start (GTK_BOX (box), values, FALSE, FALSE, 0);
	gtk_widget_show (values);

	string = gtk_label_new(hex);
	gtk_misc_set_alignment(GTK_MISC(string), 0, 0);
	gtk_box_pack_start (GTK_BOX (box), string, FALSE, FALSE, 0);
	gtk_widget_show (string);

	separator = gtk_hseparator_new ();
	gtk_box_pack_start (GTK_BOX (box), separator, FALSE, TRUE, 5);
	gtk_widget_show (separator);

	quitbox = gtk_hbox_new (FALSE, 0);

	button = gtk_button_new_with_label ("   Got it   ");

	gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
		(GtkSignalFunc)kill_box, GTK_OBJECT(window));

	gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (box), quitbox, FALSE, FALSE, 0);

	gtk_container_add (GTK_CONTAINER (window), box);

	gtk_widget_show (button);
	gtk_widget_show (quitbox);

	gtk_widget_show (box);
	gtk_widget_show (window);

	gtk_main ();
}