diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-06-26 21:12:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-06-26 21:12:55 +0400 |
commit | 7ad1491fce07e3c7d3c26902fc1a5d4142e9ad5d (patch) | |
tree | a49d778eb5b733de3138d0eb2b7ed4f649b6319e | |
parent | bd03f26c3a281cd2080e6c4ec1aacdb8049d88c5 (diff) |
alpha drawing for color picker, move alpha button into the picker.
5 files changed, 83 insertions, 23 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index d91cdd5c20d..35e813b1efc 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -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); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index d44e4b2b4dc..fb00d4f968e 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -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)); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index fb515d55854..70112e1fd09 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -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); - } - */ - } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 8f0f794585a..2cfdf2d5e04 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -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); } diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 72c067c9752..16a3b95d71a 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -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 { |