void select_color (GtkButton *widget, gpointer user_data) { GtkColorSelectionDialog* dialog = GTK_COLOR_SELECTION_DIALOG(gtk_color_selection_dialog_new("Select Color")); //todo put the old color selection in gint result = gtk_dialog_run(GTK_DIALOG(dialog)); // if(result == GTK_RESPONSE_OK) { select_color_info* info = (select_color_info*)user_data; GtkColorSelection* colsel = GTK_COLOR_SELECTION(dialog->colorsel); GdkColor* sel_color = malloc(sizeof(GdkColor)); gtk_color_selection_get_current_color(colsel, sel_color); GeglColor* color = gegl_color_new(NULL); gegl_color_set_rgba(color, (double)sel_color->red/65535.0, (double)sel_color->green/65535.0, (double)sel_color->blue/65535.0, (double)gtk_color_selection_get_current_alpha(colsel)/65535.0); free(sel_color); gegl_node_set(info->node, info->property, color, NULL); refresh_images(info->layer); } gtk_widget_destroy(GTK_WIDGET(dialog)); }
/** * Print the color currently selected in a color selection widget. * @param color_selection color selection widget to print information about */ void mk_print_GtkColorSelection_info(GtkColorSelection* color_selection) { GdkColor color; gtk_color_selection_get_current_color(color_selection, &color); guint16 alpha = gtk_color_selection_get_current_alpha(color_selection); g_printf("\t%d,%d,%d,%d", color.red, color.green, color.blue, alpha); }
int clip_GTK_COLORSELECTIONGETCURRENTALPHA(ClipMachine * ClipMachineMemory) { C_widget *ccsel = _fetch_cw_arg(ClipMachineMemory); CHECKCWID(ccsel, GTK_IS_COLOR_SELECTION); _clip_retni(ClipMachineMemory, (int) gtk_color_selection_get_current_alpha(GTK_COLOR_SELECTION(ccsel->widget))); return 0; err: return 1; }
static gboolean handle_color_sel (GtkColorSelectionDialog *dialog, gint response_id, GOColor *res) { if (response_id == GTK_RESPONSE_OK) { GdkColor gdk; GtkColorSelection *colorsel = GTK_COLOR_SELECTION (dialog->colorsel); guint16 alpha = gtk_color_selection_get_current_alpha (colorsel); gtk_color_selection_get_current_color (colorsel, &gdk); *res = GDK_TO_UINT (gdk); alpha >>= 8; *res = UINT_RGBA_CHANGE_A (*res, alpha); }
static void dialog_ok_clicked (GtkWidget *widget, gpointer data) { GtkColorButton *color_button = GTK_COLOR_BUTTON (data); GtkColorSelection *color_selection; color_selection = GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog)->colorsel); gtk_color_selection_get_current_color (color_selection, &color_button->priv->color); color_button->priv->alpha = gtk_color_selection_get_current_alpha (color_selection); gtk_widget_hide (color_button->priv->cs_dialog); gtk_widget_queue_draw (color_button->priv->draw_area); g_signal_emit (color_button, color_button_signals[COLOR_SET], 0); g_object_freeze_notify (G_OBJECT (color_button)); g_object_notify (G_OBJECT (color_button), "color"); g_object_notify (G_OBJECT (color_button), "alpha"); g_object_thaw_notify (G_OBJECT (color_button)); }
static int gtkColorDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); GtkColorSelectionDialog* dialog; GtkColorSelection* colorsel; GdkColor color; char *value; unsigned char r = 0, g = 0, b = 0, a = 255; int response, ret; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); dialog = (GtkColorSelectionDialog*)gtk_color_selection_dialog_new(iupgtkStrConvertToUTF8(iupAttribGet(ih, "TITLE"))); if (!dialog) return IUP_ERROR; if (parent) gtk_window_set_transient_for((GtkWindow*)dialog, (GtkWindow*)parent); ret = iupStrToRGBA(iupAttribGet(ih, "VALUE"), &r, &g, &b, &a); colorsel = (GtkColorSelection*)dialog->colorsel; iupgdkColorSet(&color, r, g, b); gtk_color_selection_set_current_color(colorsel, &color); value = iupAttribGetStr(ih, "ALPHA"); if (value) { int alpha; if (iupStrToInt(value, &alpha)) { if (alpha<0) alpha=0; if (alpha>255) alpha=255; gtk_color_selection_set_has_opacity_control(colorsel, TRUE); gtk_color_selection_set_current_alpha(colorsel, iupCOLOR8TO16(alpha)); } } else if (iupAttribGetBoolean(ih, "SHOWALPHA") || ret == 4) { gtk_color_selection_set_has_opacity_control(colorsel, TRUE); gtk_color_selection_set_current_alpha(colorsel, iupCOLOR8TO16(a)); } else gtk_color_selection_set_has_opacity_control(colorsel, FALSE); value = iupAttribGetStr(ih, "COLORTABLE"); if (value) { gtk_color_selection_set_has_palette (colorsel, TRUE); gtkColorDlgSetPalette(colorsel, value); } else if (iupAttribGetBoolean(ih, "SHOWCOLORTABLE")) gtk_color_selection_set_has_palette (colorsel, TRUE); else gtk_color_selection_set_has_palette (colorsel, FALSE); if (IupGetCallback(ih, "HELP_CB")) gtk_widget_show(dialog->help_button); /* initialize the widget */ gtk_widget_realize(GTK_WIDGET(dialog)); ih->handle = GTK_WIDGET(dialog); iupDialogUpdatePosition(ih); ih->handle = NULL; do { response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_HELP) { Icallback cb = IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) response = GTK_RESPONSE_CANCEL; } } while (response == GTK_RESPONSE_HELP); if (response == GTK_RESPONSE_OK) { GdkColor color; gtk_color_selection_get_current_color(colorsel, &color); IupSetAttribute(ih, "STATUS", "1"); if (gtk_color_selection_get_has_opacity_control(colorsel)) { int alpha = gtk_color_selection_get_current_alpha(colorsel); iupAttribSetInt(ih, "ALPHA", (int)iupCOLOR16TO8(alpha)); iupAttribSetStrf(ih, "VALUE", "%d %d %d %d", (int)iupCOLOR16TO8(color.red), (int)iupCOLOR16TO8(color.green), (int)iupCOLOR16TO8(color.blue), (int)iupCOLOR16TO8(alpha)); } else iupAttribSetStrf(ih, "VALUE", "%d %d %d", (int)iupCOLOR16TO8(color.red), (int)iupCOLOR16TO8(color.green), (int)iupCOLOR16TO8(color.blue)); if (gtk_color_selection_get_has_palette(colorsel)) gtkColorDlgGetPalette(ih, colorsel); } else { iupAttribSetStr(ih, "ALPHA", NULL); iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "COLORTABLE", NULL); iupAttribSetStr(ih, "STATUS", NULL); } gtk_widget_destroy(GTK_WIDGET(dialog)); return IUP_NOERROR; }
gint main(gint argc, gchar * argv[]){ GtkWidget *colorseldlg; GdkColor color; GtkColorSelection *colorsel; gint response; gint r, g, b; guint16 alpha=65535; float f; self = argv[0]; gtk_init(&argc, &argv); if(argc == 2){ g = 0; b = 0; if(argv[1][0] == 'r'){ if(argv[1][3] == 'a'){ //rgba(...) sscanf(argv[1], "rgba(%d, %d, %d, %f)", &r, &g, &b, &f); color.red = r * 256; color.green = g * 256; color.blue = b * 256; alpha = f * 65535; }else if(argv[1][3] == '('){ //rgb(...) sscanf(argv[1], "rgb(%d, %d, %d)", &r, &g, &b); color.red = r * 256; color.green = g * 256; color.blue = b * 256; }else{ usage(); return 2; } goto option_ok; } if(argv[1][0] == '#'){ b = 1; } for(r=b; r<b+6; r++){ if(!isxdigit(argv[1][r])){ usage(); return 2; } } if(b){ /* # 开头 */ argv[1]++; } sscanf(argv[1], "%2x%2x%2x", &r, &g, &b); color.red = r * 256; color.green = g * 256; color.blue = b * 256; }else if(argc == 1){ color.red = 0xffff; color.green = 0xffff; color.blue = 0xffff; }else{ usage(); return 2; } option_ok: colorseldlg = gtk_color_selection_dialog_new("Select color"); colorsel = GTK_COLOR_SELECTION( gtk_color_selection_dialog_get_color_selection( GTK_COLOR_SELECTION_DIALOG(colorseldlg))); gtk_color_selection_set_current_color(colorsel, &color); gtk_color_selection_set_has_palette(colorsel, TRUE); gtk_color_selection_set_has_opacity_control(colorsel, TRUE); gtk_color_selection_set_current_alpha(colorsel, alpha); gtk_window_set_position(GTK_WINDOW(colorseldlg), GTK_WIN_POS_MOUSE); gtk_window_set_keep_above(GTK_WINDOW(colorseldlg), TRUE); response = gtk_dialog_run(GTK_DIALOG(colorseldlg)); if(response == GTK_RESPONSE_OK){ gtk_color_selection_get_current_color(colorsel, &color); r = color.red / 256; g = color.green / 256; b = color.blue / 256; alpha = gtk_color_selection_get_current_alpha(colorsel); alpha /= 256; if(alpha == 255) printf("#%02x%02x%02x\n", r, g, b); else printf("rgba(%d, %d, %d, %.2f)\n", r, g, b, (float)alpha/256); }else /* 取消了 */ return 1; return 0; }
void dpa(GtkWidget *wgt, gpointer dta) { GArray *car, *cag, *cab, *caa; gchar *str, *str2; GdkColor clr; gdouble mny, mxy, xi, xf; gdouble *dpr; GtkPlot *pt; GtkPlotLinear *plt; guint16 alp; PangoFontDescription *ds1, *ds2; switch (gtk_notebook_get_current_page(GTK_NOTEBOOK(nb2))) { case 1: plt=GTK_PLOT_LINEAR(pt2); pt=GTK_PLOT(pt2); {str=g_strdup(gtk_entry_get_text(GTK_ENTRY(en3))); str2=g_strdup(gtk_entry_get_text(GTK_ENTRY(en4)));} gtk_plot_linear_set_label(plt, str, str2); {g_free(str); g_free(str2);} ds1=pango_font_description_from_string(gtk_font_button_get_font_name(GTK_FONT_BUTTON(bt3))); ds2=pango_font_description_from_string(gtk_font_button_get_font_name(GTK_FONT_BUTTON(bt4))); gtk_plot_set_font(pt, ds1, ds2); {pango_font_description_free(ds1); pango_font_description_free(ds2);} car=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 2); cag=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 2); cab=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 2); caa=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 2); gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(cs2), &clr); alp=gtk_color_selection_get_current_alpha(GTK_COLOR_SELECTION(cs2)); if (gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(jix2))) { xi=g_array_index((pt->rd), gdouble, 0); g_array_append_val(car, xi); xi=((gdouble) (clr.red))/65535; g_array_append_val(car, xi); xi=g_array_index((pt->gr), gdouble, 0); g_array_append_val(cag, xi); xi=((gdouble) (clr.green))/65535; g_array_append_val(cag, xi); xi=g_array_index((pt->bl), gdouble, 0); g_array_append_val(cab, xi); xi=((gdouble) (clr.blue))/65535; g_array_append_val(cab, xi); xi=g_array_index((pt->al), gdouble, 0); g_array_append_val(caa, xi); xi=((gdouble) alp)/65535; g_array_append_val(caa, xi); } else { xi=((gdouble) (clr.red))/65535; xf=g_array_index((pt->rd), gdouble, 1); g_array_append_val(car, xi); g_array_append_val(car, xf); xi=((gdouble) (clr.green))/65535; xf=g_array_index((pt->gr), gdouble, 1); g_array_append_val(cag, xi); g_array_append_val(cag, xf); xi=((gdouble) (clr.blue))/65535; xf=g_array_index((pt->bl), gdouble, 1); g_array_append_val(cab, xi); g_array_append_val(cab, xf); xi=((gdouble) alp)/65535; xf=g_array_index((pt->al), gdouble, 1); g_array_append_val(caa, xi); g_array_append_val(caa, xf); } gtk_plot_set_colour(pt, car, cag, cab, caa); {g_array_unref(car); g_array_unref(cag); g_array_unref(cab); g_array_unref(caa);} g_object_get(G_OBJECT(pt2), "xmin", &xi, "xmax", &xf, "ymin", &mny, "ymax", &mxy, NULL); gtk_plot_linear_update_scale(pt2, xi, xf, mny, mxy); break; default: plt=GTK_PLOT_LINEAR(pt1); pt=GTK_PLOT(pt1); {str=g_strdup(gtk_entry_get_text(GTK_ENTRY(en1))); str2=g_strdup(gtk_entry_get_text(GTK_ENTRY(en2)));} gtk_plot_linear_set_label(plt, str, str2); {g_free(str); g_free(str2);} ds1=pango_font_description_from_string(gtk_font_button_get_font_name(GTK_FONT_BUTTON(bt1))); ds2=pango_font_description_from_string(gtk_font_button_get_font_name(GTK_FONT_BUTTON(bt2))); gtk_plot_set_font(pt, ds1, ds2); pango_font_description_free(ds1); pango_font_description_free(ds2); car=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 2); cag=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 2); cab=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 2); caa=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 2); gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(cs1), &clr); alp=gtk_color_selection_get_current_alpha(GTK_COLOR_SELECTION(cs1)); if (gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(jix))) { xi=g_array_index((pt->rd), gdouble, 0); g_array_append_val(car, xi); xi=((gdouble) (clr.red))/65535; g_array_append_val(car, xi); xi=g_array_index((pt->gr), gdouble, 0); g_array_append_val(cag, xi); xi=((gdouble) (clr.green))/65535; g_array_append_val(cag, xi); xi=g_array_index((pt->bl), gdouble, 0); g_array_append_val(cab, xi); xi=((gdouble) (clr.blue))/65535; g_array_append_val(cab, xi); xi=g_array_index((pt->al), gdouble, 0); g_array_append_val(caa, xi); xi=((gdouble) alp)/65535; g_array_append_val(caa, xi); } else { xi=((gdouble) (clr.red))/65535; xf=g_array_index((pt->rd), gdouble, 1); g_array_append_val(car, xi); g_array_append_val(car, xf); xi=((gdouble) (clr.green))/65535; xf=g_array_index((pt->gr), gdouble, 1); g_array_append_val(cag, xi); g_array_append_val(cag, xf); xi=((gdouble) (clr.blue))/65535; xf=g_array_index((pt->bl), gdouble, 1); g_array_append_val(cab, xi); g_array_append_val(cab, xf); xi=((gdouble) alp)/65535; xf=g_array_index((pt->al), gdouble, 1); g_array_append_val(caa, xi); g_array_append_val(caa, xf); } gtk_plot_set_colour(pt, car, cag, cab, caa); {g_array_unref(car); g_array_unref(cag); g_array_unref(cab); g_array_unref(caa);} g_object_get(G_OBJECT(pt1), "xmin", &xi, "xmax", &xf, "ymin", &mny, "ymax", &mxy, NULL); gtk_plot_linear_update_scale(pt1, xi, xf, mny, mxy); break; } }