static void iupgdkColorSet(GdkColor* c, long color) { c->red = iupCOLOR8TO16(iupDrawRed(color)); c->green = iupCOLOR8TO16(iupDrawGreen(color)); c->blue = iupCOLOR8TO16(iupDrawBlue(color)); c->pixel = 0; }
static int iColorDlgColorCnvButton_CB(Ihandle* ih, int b, int press, int x, int y) { IcolorDlgData* colordlg_data = (IcolorDlgData*)iupAttribGetInherit(ih, "_IUP_GC_DATA"); int width; (void)y; if (b != IUP_BUTTON1 || !press) return IUP_DEFAULT; width = colordlg_data->color_cnv->currentwidth; if (x < width/2) { /* reset color to previous */ colordlg_data->red = iupDrawRed(colordlg_data->previous_color); colordlg_data->green = iupDrawGreen(colordlg_data->previous_color); colordlg_data->blue = iupDrawBlue(colordlg_data->previous_color); colordlg_data->alpha = iupDrawAlpha(colordlg_data->previous_color); IupSetInt(colordlg_data->alpha_txt, "VALUE", (int)colordlg_data->alpha); IupSetInt(colordlg_data->alpha_val, "VALUE", (int)colordlg_data->alpha); iColorDlgRGB_TXT_Update(colordlg_data); iColorDlgRGBChanged(colordlg_data); } return IUP_DEFAULT; }
static void iColorDrawTransparentRectangle(Ihandle* color_cnv, int xmin, int ymin, int xmax, int ymax, long color) { if (iupDrawAlpha(color) == 255) { iupDrawSetColor(color_cnv, "DRAWCOLOR", color); IupDrawRectangle(color_cnv, xmin, ymin, xmax, ymax); } else { int w = xmax - xmin + 1; int h = ymax - ymin + 1; Ihandle* image = IupImageRGBA(w,h,NULL); unsigned char *colors = (unsigned char*)iupAttribGet(image, "WID"); int x, y; unsigned char red = iupDrawRed(color); unsigned char green = iupDrawGreen(color); unsigned char blue = iupDrawBlue(color); unsigned char alpha = iupDrawAlpha(color); for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { colors[0] = red; colors[1] = green; colors[2] = blue; colors[3] = alpha; colors += 4; } } iupAttribSetHandleName(image); IupDrawImage(color_cnv, iupAttribGetHandleName(image), xmin, ymin, -1, -1); IupDestroy(image); } }
static int iColorDlgSetAlphaAttrib(Ihandle* ih, const char* value) { IcolorDlgData* colordlg_data = (IcolorDlgData*)iupAttribGetInherit(ih, "_IUP_GC_DATA"); int alpha; if (iupStrToInt(value, &alpha)) { colordlg_data->alpha = (unsigned char)alpha; IupSetInt(colordlg_data->alpha_txt, "VALUE", (int)colordlg_data->alpha); IupSetInt(colordlg_data->alpha_val, "VALUE", (int)colordlg_data->alpha); colordlg_data->color = iupDrawColor(colordlg_data->red, colordlg_data->green, colordlg_data->blue, colordlg_data->alpha); colordlg_data->previous_color = iupDrawColor(iupDrawRed(colordlg_data->previous_color), iupDrawGreen(colordlg_data->previous_color), iupDrawBlue(colordlg_data->previous_color), colordlg_data->alpha); IupUpdate(colordlg_data->color_cnv); if (!ih->handle) /* do it only before map */ IupSetAttribute(ih, "SHOWALPHA", "YES"); } return 1; }