////////////////////////////////////////////////////////////////////////////////
#include <gtk/gtk.h>
GtkWidget *window;
GdkColor btn_color;
GtkWidget *red_entry;
GtkWidget *green_entry;
GtkWidget *blue_entry;
////////////////////////////////////////////////////////////////////////////////
void
cb_color_selected (GtkWidget *btn, gpointer user_data)
{
gchar buf[10];
gtk_color_button_get_color ( GTK_COLOR_BUTTON (btn), &btn_color);
sprintf (buf, "%d", btn_color.red);
gtk_entry_set_text (GTK_ENTRY (red_entry), buf);
sprintf (buf, "%d", btn_color.green);
gtk_entry_set_text (GTK_ENTRY (green_entry), buf);
sprintf (buf, "%d", btn_color.blue);
gtk_entry_set_text (GTK_ENTRY (blue_entry), buf);
}
//////////////////////////////////////////////////////////////////////////////
int
main (int argc, char **argv)
{
GtkWidget *main_vbox;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "COLOR_CHK");
gtk_container_set_border_width (GTK_CONTAINER (window), 2);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_set_size_request (window, 400, 300);
gtk_window_set_resizable(GTK_WINDOW (window), FALSE);
main_vbox = gtk_vbox_new (FALSE, 2);
gtk_container_add (GTK_CONTAINER (window), main_vbox);
{
GtkWidget *color_select_btn;
GtkWidget *rgb_entry_table;
GtkWidget *exit_btn;
btn_color.red = 0xffff;
btn_color.green = 0xffff;
btn_color.blue = 0xffff;
color_select_btn = gtk_color_button_new_with_color(&btn_color);
gtk_box_pack_start (GTK_BOX (main_vbox), color_select_btn,
TRUE, TRUE, 2);
rgb_entry_table = gtk_table_new (3, 2, FALSE); // col, row
gtk_box_pack_start (GTK_BOX (main_vbox), rgb_entry_table,
TRUE, TRUE, 2);
{
GtkWidget *red_label;
GtkWidget *green_label;
GtkWidget *blue_label;
red_label = gtk_label_new ("Red (16bit dec)");
green_label = gtk_label_new ("Green (16bit dec)");
blue_label = gtk_label_new ("Blue (16bit dec)");
red_entry = gtk_entry_new ();
green_entry = gtk_entry_new ();
blue_entry = gtk_entry_new ();
gtk_widget_set_size_request (red_entry, 200, 28);
gtk_widget_set_size_request (green_entry, 200, 28);
gtk_widget_set_size_request (blue_entry, 200, 28);
gtk_table_attach (GTK_TABLE (rgb_entry_table), red_label,
0, 1, // left - rigth
0, 1, // top - bottom
GTK_FILL | GTK_SHRINK | GTK_EXPAND,
GTK_FILL | GTK_SHRINK ,
2, 2);
gtk_table_attach (GTK_TABLE (rgb_entry_table), red_entry,
1, 2, // left - rigth
0, 1, // top - bottom
GTK_FILL | GTK_SHRINK ,
GTK_FILL | GTK_SHRINK ,
2, 2);
////
gtk_table_attach (GTK_TABLE (rgb_entry_table), green_label,
0, 1, // left - rigth
1, 2, // top - bottom
GTK_FILL | GTK_SHRINK | GTK_EXPAND,
GTK_FILL | GTK_SHRINK ,
2, 2);
gtk_table_attach (GTK_TABLE (rgb_entry_table), green_entry,
1, 2, // left - rigth
1, 2, // top - bottom
GTK_FILL | GTK_SHRINK ,
GTK_FILL | GTK_SHRINK ,
2, 2);
////
gtk_table_attach (GTK_TABLE (rgb_entry_table), blue_label,
0, 1, // left - rigth
2, 3, // top - bottom
GTK_FILL | GTK_SHRINK | GTK_EXPAND,
GTK_FILL | GTK_SHRINK ,
2, 2);
gtk_table_attach (GTK_TABLE (rgb_entry_table), blue_entry,
1, 2, // left - rigth
2, 3, // top - bottom
GTK_FILL | GTK_SHRINK ,
GTK_FILL | GTK_SHRINK ,
2, 2);
g_signal_connect ( G_OBJECT ( color_select_btn ), "color-set",
G_CALLBACK(cb_color_selected), NULL);
}
exit_btn = gtk_button_new_with_label ("Exit");
gtk_box_pack_start (GTK_BOX (main_vbox), exit_btn,
TRUE, TRUE, 2);
g_signal_connect (G_OBJECT (exit_btn), "clicked",
G_CALLBACK (gtk_main_quit), NULL);
}
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
/////////////////////////////////////// EOF ////////////////////////////////////
|