alpha drawing for color picker, move alpha button into the picker.

This commit is contained in:
Campbell Barton 2010-06-26 17:12:55 +00:00
parent bd03f26c3a
commit 7ad1491fce
5 changed files with 83 additions and 23 deletions

@ -431,11 +431,6 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, char *name, int icon
but->type= TOG;
}
}
else if(ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA) && len == 4) {
but= uiDefAutoButR(block, ptr, prop, 3, "A:", 0, 0, 0, w, UI_UNIT_Y);
if(slider && but->type==NUM)
but->type= NUMSLI;
}
}
uiBlockSetCurLayout(block, layout);

@ -1795,6 +1795,9 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
linearrgb_to_srgb_v3_v3(rgb_gamma, rgb);
}
/* sneaky way to check for alpha */
rgb[3]= FLT_MAX;
RNA_property_float_ui_range(ptr, prop, &min, &max, &step, &precision);
RNA_property_float_get_array(ptr, prop, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
@ -1835,6 +1838,7 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
bt= uiDefButR(block, NUMSLI, 0, "B ", 0, -100, butwidth, UI_UNIT_Y, ptr, propname, 2, 0.0, 0.0, 0, 0, "");
uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
// could use uiItemFullR(col, ptr, prop, -1, 0, UI_ITEM_R_EXPAND|UI_ITEM_R_SLIDER, "", 0);
// but need to use uiButSetFunc for updating other fake buttons
@ -1847,7 +1851,15 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
bt= uiDefButF(block, NUMSLI, 0, "V ", 0, -100, butwidth, UI_UNIT_Y, hsv+2, 0.0, max, 10, 3, "");
uiButSetFunc(bt, do_hsv_rna_cb, bt, hsv);
uiBlockEndAlign(block);
if(rgb[3] != FLT_MAX) {
bt= uiDefButR(block, NUMSLI, 0, "A ", 0, -120, butwidth, UI_UNIT_Y, ptr, propname, 3, 0.0, 0.0, 0, 0, "");
uiButSetFunc(bt, do_picker_rna_cb, bt, NULL);
}
else {
rgb[3]= 1.0f;
}
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
sprintf(hexcol, "%02X%02X%02X", (unsigned int)(rgb_gamma[0]*255.0), (unsigned int)(rgb_gamma[1]*255.0), (unsigned int)(rgb_gamma[2]*255.0));

@ -1929,14 +1929,6 @@ void uiTemplateColorWheel(uiLayout *layout, PointerRNA *ptr, char *propname, int
if (value_slider)
uiDefButR(block, HSVCUBE, 0, "", WHEEL_SIZE+6, 0, 14, WHEEL_SIZE, ptr, propname, -1, softmin, softmax, 9, 0, "");
/* maybe a switch for this?
row= uiLayoutRow(col, 0);
if(ELEM(RNA_property_subtype(prop), PROP_COLOR, PROP_COLOR_GAMMA) && RNA_property_array_length(ptr, prop) == 4) {
but= uiDefAutoButR(block, ptr, prop, 3, "A:", 0, 0, 0, WHEEL_SIZE+20, UI_UNIT_Y);
}
*/
}

@ -608,14 +608,67 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
/* backdrop non AA */
if(wtb->inner) {
if(wcol->shaded==0) {
/* filled center, solid */
glColor4ubv((unsigned char*)wcol->inner);
glBegin(GL_POLYGON);
for(a=0; a<wtb->totvert; a++)
glVertex2fv(wtb->inner_v[a]);
glEnd();
if (wcol->alpha_check) {
GLubyte checker_stipple_sml[32*32/8] =
{
255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
};
float x_mid= 0.0f; /* used for dumb clamping of values */
/* dark checkers */
glColor4ub(100, 100, 100, 255);
glBegin(GL_POLYGON);
for(a=0; a<wtb->totvert; a++) {
glVertex2fv(wtb->inner_v[a]);
}
glEnd();
/* light checkers */
glEnable(GL_POLYGON_STIPPLE);
glColor4ub(160, 160, 160, 255);
glPolygonStipple(checker_stipple_sml);
glBegin(GL_POLYGON);
for(a=0; a<wtb->totvert; a++) {
glVertex2fv(wtb->inner_v[a]);
}
glEnd();
glDisable(GL_POLYGON_STIPPLE);
/* alpha fill */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4ubv((unsigned char*)wcol->inner);
glBegin(GL_POLYGON);
for(a=0; a<wtb->totvert; a++) {
glVertex2fv(wtb->inner_v[a]);
x_mid += wtb->inner_v[a][0];
}
x_mid /= wtb->totvert;
glEnd();
/* 1/2 solid color */
glColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255);
glBegin(GL_POLYGON);
for(a=0; a<wtb->totvert; a++)
glVertex2f(MIN2(wtb->inner_v[a][0], x_mid), wtb->inner_v[a][1]);
glEnd();
}
else {
/* simple fill */
glColor4ubv((unsigned char*)wcol->inner);
glBegin(GL_POLYGON);
for(a=0; a<wtb->totvert; a++)
glVertex2fv(wtb->inner_v[a]);
glEnd();
}
}
else {
char col1[4], col2[4];
@ -2208,9 +2261,15 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
float col[4];
int color_profile = but->block->color_profile;
col[3]= 1.0f;
if (but->rnaprop) {
if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
color_profile = BLI_PR_NONE;
if(RNA_property_array_length(&but->rnapoin, but->rnaprop)==4) {
col[3]= RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3);
}
}
widget_init(&wtb);
@ -2226,8 +2285,10 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
wcol->inner[0]= FTOCHAR(col[0]);
wcol->inner[1]= FTOCHAR(col[1]);
wcol->inner[2]= FTOCHAR(col[2]);
wcol->inner[3]= FTOCHAR(col[3]);
wcol->shaded = 0;
wcol->alpha_check = (wcol->inner[3] < 255);
widgetbase_draw(&wtb, wcol);
}

@ -119,7 +119,7 @@ typedef struct uiWidgetColors {
char text_sel[4];
short shaded;
short shadetop, shadedown;
short pad;
short alpha_check;
} uiWidgetColors;
typedef struct uiWidgetStateColors {