From 3564eb7763b2c6ea0410c47e06773c5b456f2b63 Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Sat, 9 Jan 2010 06:44:54 +0000 Subject: [PATCH] Added user preferences for color picker type, includes colour wheel + 3 square types. Find it in prefs -> system --- release/scripts/ui/space_userpref.py | 6 +- .../editors/interface/interface_handlers.c | 18 +++-- .../editors/interface/interface_regions.c | 69 +++++++++++++++---- .../editors/interface/interface_widgets.c | 68 +++++++++++++----- source/blender/makesdna/DNA_userdef_types.h | 8 +++ source/blender/makesrna/intern/rna_userdef.c | 19 +++-- 6 files changed, 144 insertions(+), 44 deletions(-) diff --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py index 8d52d05101e..60f419e2901 100644 --- a/release/scripts/ui/space_userpref.py +++ b/release/scripts/ui/space_userpref.py @@ -506,7 +506,11 @@ class USERPREF_PT_system(bpy.types.Panel): column.separator() col = column.column() - + + col.prop(system, "color_picker_type") + + column.separator() + col.prop(system, "use_weight_color_range", text="Custom Weight Paint Range") sub = col.column() sub.active = system.use_weight_color_range diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 597f5a9d8cd..916a48b7442 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -2711,21 +2711,27 @@ static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx, CLAMP(y, 0.0, 1.0); if(but->a1==0) { - hsv[0]= x; - hsv[2]= y; + hsv[2]= x; + hsv[1]= y; } else if(but->a1==1) { hsv[0]= x; - hsv[1]= y; + hsv[2]= y; } else if(but->a1==2) { - hsv[2]= x; + hsv[0]= x; hsv[1]= y; } else if(but->a1==3) { hsv[0]= x; } - else { + else if(but->a1==4) { + hsv[1]= x; + } + else if(but->a1==5) { + hsv[2]= x; + } + else if (but->a1==9){ /* vertical 'value' strip */ hsv[2]= y; if (color_profile) @@ -3791,7 +3797,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) retval= ui_do_but_BUT(C, but, data, event); break; case COL: - if(but->a1 == -1) // signal to prevent calling up color picker + if(but->a1 == 9) // signal to prevent calling up color picker retval= ui_do_but_EXIT(C, but, data, event); else retval= ui_do_but_BLOCK(C, but, data, event); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index d4302aa9c52..c7ea06e2166 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1647,10 +1647,6 @@ static void close_popup_cb(bContext *C, void *bt1, void *arg) popup->menuretval= UI_RETURN_OK; } -/* picker sizes S hsize, F full size, D spacer, B button/pallette height */ -#define SPICK1 150.0 -#define DPICK1 6.0 - static void picker_new_hide_reveal(uiBlock *block, short colormode) { uiBut *bt; @@ -1682,6 +1678,46 @@ static void do_picker_new_mode_cb(bContext *C, void *bt1, void *colv) picker_new_hide_reveal(bt->block, colormode); } +/* picker sizes S hsize, F full size, D spacer, B button/pallette height */ +#define SPICK1 150.0 +#define DPICK1 6.0 + +#define PICKER_H 150 +#define PICKER_W 150 +#define PICKER_SPACE 6 +#define PICKER_BAR 14 + +#define PICKER_TOTAL_W (PICKER_W+PICKER_SPACE+PICKER_BAR) + +static void circle_picker(uiBlock *block, PointerRNA *ptr, const char *propname) +{ + uiBut *bt; + + /* HS circle */ + bt= uiDefButR(block, HSVCIRCLE, 0, "", 0, 0, PICKER_H, PICKER_W, ptr, propname, -1, 0.0, 0.0, 0, 0, ""); + uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); + + /* value */ + uiDefButR(block, HSVCUBE, 0, "", PICKER_W+PICKER_SPACE,0,PICKER_BAR,PICKER_H, ptr, propname, -1, 0.0, 0.0, 9, 0, ""); + uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); +} + + +static void square_picker(uiBlock *block, PointerRNA *ptr, const char *propname, int type) +{ + uiBut *bt; + int bartype = type + 3; + + /* HS square */ + bt= uiDefButR(block, HSVCUBE, 0, "", 0, PICKER_BAR+PICKER_SPACE, PICKER_TOTAL_W, PICKER_H, ptr, propname, -1, 0.0, 0.0, type, 0, ""); + uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); + + /* value */ + uiDefButR(block, HSVCUBE, 0, "", 0, 0, PICKER_TOTAL_W, PICKER_BAR, ptr, propname, -1, 0.0, 0.0, bartype, 0, ""); + uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); +} + + /* a HS circle, V slider, rgb/hsv/hex sliders */ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyRNA *prop) { @@ -1693,7 +1729,7 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR static char hexcol[128]; const char *propname = RNA_property_identifier(prop); - width= (SPICK1+DPICK1+14); + width= PICKER_TOTAL_W; butwidth = width - UI_UNIT_X - 10; /* existence of profile means storage is in linear colour space, with display correction */ @@ -1704,14 +1740,21 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR RNA_property_float_get_array(ptr, prop, rgb); rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); - - /* HS circle */ - bt= uiDefButR(block, HSVCIRCLE, 0, "", 0, 0, SPICK1, SPICK1, ptr, propname, -1, 0.0, 0.0, 0, 0, ""); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); - - /* value */ - uiDefButR(block, HSVCUBE, 0, "", SPICK1+DPICK1,0,14,SPICK1, ptr, propname, -1, 0.0, 0.0, 4, 0, ""); - uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); + + switch (U.color_picker_type) { + case USER_CP_CIRCLE: + circle_picker(block, ptr, propname); + break; + case USER_CP_SQUARE_SV: + square_picker(block, ptr, propname, 0); + break; + case USER_CP_SQUARE_HS: + square_picker(block, ptr, propname, 1); + break; + case USER_CP_SQUARE_HV: + square_picker(block, ptr, propname, 2); + break; + } /* mode */ uiBlockBeginAlign(block); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 7b251b2d22e..82c79c32c6c 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -1616,34 +1616,52 @@ static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect) /* draw series of gouraud rects */ glShadeModel(GL_SMOOTH); - if(but->a1==0) { // H and V vary + + if(but->a1==0) { // S and V vary + hsv_to_rgb(h, 0.0, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]); + hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]); + hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]); + hsv_to_rgb(h, 1.0, 0.0, &col1[3][0], &col1[3][1], &col1[3][2]); + x= v; y= s; + } + else if(but->a1==1) { // H and V vary hsv_to_rgb(0.0, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]); hsv_to_rgb(0.0, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]); hsv_to_rgb(0.0, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]); hsv_to_rgb(0.0, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]); x= h; y= v; } - else if(but->a1==1) { // H and S vary + else if(but->a1==2) { // H and S vary hsv_to_rgb(0.0, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]); hsv_to_rgb(0.0, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]); hsv_to_rgb(0.0, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]); hsv_to_rgb(0.0, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]); x= h; y= s; } - else if(but->a1==2) { // S and V vary - hsv_to_rgb(h, 0.0, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]); - hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]); - hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]); - hsv_to_rgb(h, 1.0, 0.0, &col1[3][0], &col1[3][1], &col1[3][2]); - x= v; y= s; - } - else if(but->a1==3) { // only hue slider + else if(but->a1==3) { // only H hsv_to_rgb(0.0, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]); VECCOPY(col1[1], col1[0]); VECCOPY(col1[2], col1[0]); VECCOPY(col1[3], col1[0]); x= h; y= 0.5; } + else if(but->a1==4) { // only S + hsv_to_rgb(1.0, 0.0, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]); + VECCOPY(col1[0], col1[1]); + VECCOPY(col1[2], col1[1]); + VECCOPY(col1[3], col1[1]); + x= s; y= 0.5; + } + else if(but->a1==5) { // only V + hsv_to_rgb(1.0, 1.0, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]); + VECCOPY(col1[0], col1[2]); + VECCOPY(col1[1], col1[2]); + VECCOPY(col1[3], col1[2]); + x= v; y= 0.5; + } + + + /* old below */ for(dx=0.0; dx<1.0; dx+= 0.05) { // previous color @@ -1653,30 +1671,42 @@ static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect) VECCOPY(col0[3], col1[3]); // new color - if(but->a1==0) { // H and V vary + if(but->a1==0) { // S and V vary + hsv_to_rgb(h, 0.0, dx, &col1[0][0], &col1[0][1], &col1[0][2]); + hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]); + hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]); + hsv_to_rgb(h, 1.0, dx, &col1[3][0], &col1[3][1], &col1[3][2]); + } + else if(but->a1==1) { // H and V vary hsv_to_rgb(dx, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]); hsv_to_rgb(dx, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]); hsv_to_rgb(dx, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]); hsv_to_rgb(dx, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]); } - else if(but->a1==1) { // H and S vary + else if(but->a1==2) { // H and S vary hsv_to_rgb(dx, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]); hsv_to_rgb(dx, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]); hsv_to_rgb(dx, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]); hsv_to_rgb(dx, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]); } - else if(but->a1==2) { // S and V vary - hsv_to_rgb(h, 0.0, dx, &col1[0][0], &col1[0][1], &col1[0][2]); - hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]); - hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]); - hsv_to_rgb(h, 1.0, dx, &col1[3][0], &col1[3][1], &col1[3][2]); - } else if(but->a1==3) { // only H hsv_to_rgb(dx, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]); VECCOPY(col1[1], col1[0]); VECCOPY(col1[2], col1[0]); VECCOPY(col1[3], col1[0]); } + else if(but->a1==4) { // only S + hsv_to_rgb(h, dx, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]); + VECCOPY(col1[0], col1[1]); + VECCOPY(col1[2], col1[1]); + VECCOPY(col1[3], col1[1]); + } + else if(but->a1==5) { // only V + hsv_to_rgb(h, 1.0, dx, &col1[2][0], &col1[2][1], &col1[2][2]); + VECCOPY(col1[0], col1[2]); + VECCOPY(col1[1], col1[2]); + VECCOPY(col1[3], col1[2]); + } // rect sx1= rect->xmin + dx*(rect->xmax-rect->xmin); @@ -2589,7 +2619,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct break; case HSVCUBE: - if(but->a1==4) // vertical V slider, uses new widget draw now + if(but->a1==9) // vertical V slider, uses new widget draw now ui_draw_but_HSV_v(but, rect); else // other HSV pickers... ui_draw_but_HSVCUBE(but, rect); diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index cc33d556726..2cedecc372e 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -337,6 +337,8 @@ typedef struct UserDef { short glreslimit; short ndof_pan, ndof_rotate; short curssize, ipo_new; + short color_picker_type; + short pad2[3]; char versemaster[160]; char verseuser[160]; @@ -481,6 +483,12 @@ extern UserDef U; /* from blenkernel blender.c */ #define GP_PAINT_DOSMOOTH (1<<0) #define GP_PAINT_DOSIMPLIFY (1<<1) +/* color picker types */ +#define USER_CP_CIRCLE 0 +#define USER_CP_SQUARE_SV 1 +#define USER_CP_SQUARE_HS 2 +#define USER_CP_SQUARE_HV 3 + /* theme drawtypes */ #define TH_MINIMAL 0 #define TH_ROUNDSHADED 1 diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index c2871298dbd..94c61fdd2ba 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -1811,8 +1811,6 @@ static void rna_def_userdef_view(BlenderRNA *brna) RNA_def_property_range(prop, 4, 10); RNA_def_property_ui_text(prop, "Object Origin Size", "Diameter in Pixels for Object/Lamp origin display."); RNA_def_property_update(prop, 0, "rna_userdef_update"); - - } static void rna_def_userdef_edit(BlenderRNA *brna) @@ -1841,7 +1839,6 @@ static void rna_def_userdef_edit(BlenderRNA *brna) {USER_ADD_VIEWALIGNED, "VIEW", 0, "View", "Align newly added objects to the world coordinates"}, {0, NULL, 0, NULL, NULL}}; - srna= RNA_def_struct(brna, "UserPreferencesEdit", NULL); RNA_def_struct_sdna(srna, "UserDef"); RNA_def_struct_nested(brna, srna, "UserPreferences"); @@ -1927,7 +1924,7 @@ static void rna_def_userdef_edit(BlenderRNA *brna) RNA_def_property_enum_items(prop, new_interpolation_types); RNA_def_property_enum_sdna(prop, NULL, "ipo_new"); RNA_def_property_ui_text(prop, "New Interpolation Type", ""); - + prop= RNA_def_property(srna, "grease_pencil_manhattan_distance", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "gp_manhattendist"); RNA_def_property_range(prop, 0, 100); @@ -2075,7 +2072,14 @@ static void rna_def_userdef_system(BlenderRNA *brna) {USER_DRAW_OVERLAP, "OVERLAP", 0, "Overlap", "Redraw all overlapping regions, minimal memory usage but more redraws."}, {USER_DRAW_FULL, "FULL", 0, "Full", "Do a full redraw each time, slow, only use for reference or when all else fails."}, {0, NULL, 0, NULL, NULL}}; - + + static EnumPropertyItem color_picker_types[] = { + {USER_CP_CIRCLE, "CIRCLE", 0, "Circle", "A circular Hue/Saturation color wheel, with Value slider"}, + {USER_CP_SQUARE_SV, "SQUARE_SV", 0, "Square (SV + H)", "A square showing Saturation/Value, with Hue slider"}, + {USER_CP_SQUARE_HS, "SQUARE_HS", 0, "Square (HS + V)", "A square showing Hue/Saturation, with Value slider"}, + {USER_CP_SQUARE_HV, "SQUARE_HV", 0, "Square (HV + S)", "A square showing Hue/Value, with Saturation slider"}, + {0, NULL, 0, NULL, NULL}}; + /* hardcoded here, could become dynamic somehow */ static EnumPropertyItem language_items[] = { {0, "ENGLISH", 0, "English", ""}, @@ -2172,6 +2176,11 @@ static void rna_def_userdef_system(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Weight Color Range", "Color range used for weight visualization in weight painting mode."); RNA_def_property_update(prop, 0, "rna_UserDef_weight_color_update"); + prop= RNA_def_property(srna, "color_picker_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, color_picker_types); + RNA_def_property_enum_sdna(prop, NULL, "color_picker_type"); + RNA_def_property_ui_text(prop, "Color Picker Type", "Different styles of displaying the color picker widget"); + prop= RNA_def_property(srna, "enable_all_codecs", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "uiflag", USER_ALLWINCODECS); RNA_def_property_ui_text(prop, "Enable All Codecs", "Enables automatic saving of preview images in the .blend file (Windows only)."); -- 2.28.0