From abfc3daaf4dc6234ac4a48e72747a0b3fa559d2c Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 3 Jun 2009 00:14:12 +0000 Subject: [PATCH] UI: * Added initial color ramp and curve mapping templates. --- source/blender/editors/include/UI_interface.h | 5 +- .../blender/editors/interface/interface_api.c | 15 +++ .../editors/interface/interface_templates.c | 34 +++++ .../editors/interface/interface_utils.c | 127 ++++++++++++++++++ 4 files changed, 180 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 45f26ecdcab..4c2634e2a75 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -52,6 +52,7 @@ struct rctf; struct uiStyle; struct uiFontStyle; struct ColorBand; +struct CurveMapping; typedef struct uiBut uiBut; typedef struct uiBlock uiBlock; @@ -514,9 +515,9 @@ void test_imapoin_but(struct bContext *C, char *name, struct ID **idpp); void autocomplete_bone(struct bContext *C, char *str, void *arg_v); void autocomplete_vgroup(struct bContext *C, char *str, void *arg_v); -struct CurveMapping; struct rctf; void curvemap_buttons(uiBlock *block, struct CurveMapping *cumap, char labeltype, short event, short redraw, struct rctf *rect); +void colorband_buttons(uiBlock *block, struct ColorBand *coba, struct rctf *rect, int small); /* Module @@ -604,6 +605,8 @@ void uiTemplateHeaderID(uiLayout *layout, struct bContext *C, struct PointerRNA uiLayout *uiTemplateModifier(uiLayout *layout, struct PointerRNA *ptr); uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr); void uiTemplatePreview(uiLayout *layout, struct ID *id); +void uiTemplateColorRamp(uiLayout *layout, struct ColorBand *coba, int expand); +void uiTemplateCurveMapping(uiLayout *layout, struct CurveMapping *cumap, int type); /* items */ void uiItemO(uiLayout *layout, char *name, int icon, char *opname); diff --git a/source/blender/editors/interface/interface_api.c b/source/blender/editors/interface/interface_api.c index 2bbaee857d1..5aff0c0ad82 100644 --- a/source/blender/editors/interface/interface_api.c +++ b/source/blender/editors/interface/interface_api.c @@ -54,6 +54,12 @@ void RNA_api_ui_layout(StructRNA *srna) FunctionRNA *func; PropertyRNA *parm; + static EnumPropertyItem curve_type_items[] = { + {0, "NONE", "None", ""}, + {'v', "VECTOR", "Vector", ""}, + {'c', "COLOR", "Color", ""}, + {0, NULL, NULL, NULL}}; + /* simple layout specifiers */ func= RNA_def_function(srna, "row", "uiLayoutRow"); parm= RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in."); @@ -214,5 +220,14 @@ void RNA_api_ui_layout(StructRNA *srna) parm= RNA_def_pointer(func, "id", "ID", "", "ID datablock."); RNA_def_property_flag(parm, PROP_REQUIRED); + func= RNA_def_function(srna, "template_curve_mapping", "uiTemplateCurveMapping"); + parm= RNA_def_pointer(func, "curvemap", "CurveMapping", "", "Curve mapping pointer."); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_enum(func, "type", curve_type_items, 0, "Type", "Type of curves to display."); + + func= RNA_def_function(srna, "template_color_ramp", "uiTemplateColorRamp"); + parm= RNA_def_pointer(func, "ramp", "ColorRamp", "", "Color ramp pointer."); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_boolean(func, "expand", 0, "", "Expand button to show more detail."); } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 4df5f99f224..12954fe77c0 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -1311,3 +1311,37 @@ void uiTemplatePreview(uiLayout *layout, ID *id) } +/********************** ColorRamp Template **************************/ + +void uiTemplateColorRamp(uiLayout *layout, ColorBand *coba, int expand) +{ + uiBlock *block; + rctf rect; + + if(coba) { + rect.xmin= 0; rect.xmax= 200; + rect.ymin= 0; rect.ymax= 190; + + block= uiLayoutFreeBlock(layout); + colorband_buttons(block, coba, &rect, !expand); + } +} + +/********************* CurveMapping Template ************************/ + +#include "DNA_color_types.h" + +void uiTemplateCurveMapping(uiLayout *layout, CurveMapping *cumap, int type) +{ + uiBlock *block; + rctf rect; + + if(cumap) { + rect.xmin= 0; rect.xmax= 200; + rect.ymin= 0; rect.ymax= 190; + + block= uiLayoutFreeBlock(layout); + curvemap_buttons(block, cumap, type, 0, 0, &rect); + } +} + diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 7c739adf1b9..76247258a71 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -35,6 +35,7 @@ #include "DNA_material_types.h" #include "DNA_object_types.h" #include "DNA_screen_types.h" +#include "DNA_texture_types.h" #include "DNA_windowmanager_types.h" #include "BKE_colortools.h" @@ -42,6 +43,7 @@ #include "BKE_idprop.h" #include "BKE_library.h" #include "BKE_main.h" +#include "BKE_texture.h" #include "BKE_utildefines.h" #include "RNA_access.h" @@ -1098,3 +1100,128 @@ void curvemap_buttons(uiBlock *block, CurveMapping *cumap, char labeltype, short cumap, 0.0f, 1.0f, 0, 0, ""); } +#define B_BANDCOL 1 + +static int vergcband(const void *a1, const void *a2) +{ + const CBData *x1=a1, *x2=a2; + + if( x1->pos > x2->pos ) return 1; + else if( x1->pos < x2->pos) return -1; + return 0; +} + +static void colorband_pos_cb(bContext *C, void *coba_v, void *unused_v) +{ + ColorBand *coba= coba_v; + int a; + + if(coba->tot<2) return; + + for(a=0; atot; a++) coba->data[a].cur= a; + qsort(coba->data, coba->tot, sizeof(CBData), vergcband); + for(a=0; atot; a++) { + if(coba->data[a].cur==coba->cur) { + // XXX if(coba->cur!=a) addqueue(curarea->win, REDRAW, 0); /* button cur */ + coba->cur= a; + break; + } + } +} + +static void colorband_add_cb(bContext *C, void *coba_v, void *unused_v) +{ + ColorBand *coba= coba_v; + + if(coba->tot < MAXCOLORBAND-1) coba->tot++; + coba->cur= coba->tot-1; + + colorband_pos_cb(C, coba, NULL); + ED_undo_push(C, "Add colorband"); +} + +static void colorband_del_cb(bContext *C, void *coba_v, void *unused_v) +{ + ColorBand *coba= coba_v; + int a; + + if(coba->tot<2) return; + + for(a=coba->cur; atot; a++) { + coba->data[a]= coba->data[a+1]; + } + if(coba->cur) coba->cur--; + coba->tot--; + + ED_undo_push(C, "Delete colorband"); + // XXX BIF_preview_changed(ID_TE); +} + + +/* offset aligns from bottom, standard width 300, height 115 */ +static void colorband_buttons_large(uiBlock *block, ColorBand *coba, int xoffs, int yoffs, int redraw) +{ + CBData *cbd; + uiBut *bt; + + if(coba==NULL) return; + + bt= uiDefBut(block, BUT, redraw, "Add", 80+xoffs,95+yoffs,37,20, 0, 0, 0, 0, 0, "Adds a new color position to the colorband"); + uiButSetFunc(bt, colorband_add_cb, coba, NULL); + uiDefButS(block, NUM, redraw, "Cur:", 117+xoffs,95+yoffs,81,20, &coba->cur, 0.0, (float)(coba->tot-1), 0, 0, "Displays the active color from the colorband"); + bt= uiDefBut(block, BUT, redraw, "Del", 199+xoffs,95+yoffs,37,20, 0, 0, 0, 0, 0, "Deletes the active position"); + uiButSetFunc(bt, colorband_del_cb, coba, NULL); + + uiDefButS(block, MENU, redraw, "Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4", + 236+xoffs, 95+yoffs, 64, 20, &coba->ipotype, 0.0, 0.0, 0, 0, "Sets interpolation type"); + + uiDefBut(block, BUT_COLORBAND, redraw, "", xoffs,65+yoffs,300,30, coba, 0, 0, 0, 0, ""); + + cbd= coba->data + coba->cur; + + uiBlockBeginAlign(block); + bt= uiDefButF(block, NUM, redraw, "Pos", xoffs,40+yoffs,110,20, &cbd->pos, 0.0, 1.0, 10, 0, "Sets the position of the active color"); + uiButSetFunc(bt, colorband_pos_cb, coba, NULL); + uiDefButF(block, COL, redraw, "", xoffs,20+yoffs,110,20, &(cbd->r), 0, 0, 0, B_BANDCOL, ""); + uiDefButF(block, NUMSLI, redraw, "A ", xoffs,yoffs,110,20, &cbd->a, 0.0, 1.0, 10, 0, "Sets the alpha value for this position"); + + uiBlockBeginAlign(block); + uiDefButF(block, NUMSLI, redraw, "R ", 115+xoffs,40+yoffs,185,20, &cbd->r, 0.0, 1.0, B_BANDCOL, 0, "Sets the red value for the active color"); + uiDefButF(block, NUMSLI, redraw, "G ", 115+xoffs,20+yoffs,185,20, &cbd->g, 0.0, 1.0, B_BANDCOL, 0, "Sets the green value for the active color"); + uiDefButF(block, NUMSLI, redraw, "B ", 115+xoffs,yoffs,185,20, &cbd->b, 0.0, 1.0, B_BANDCOL, 0, "Sets the blue value for the active color"); + uiBlockEndAlign(block); +} + +static void colorband_buttons_small(uiBlock *block, ColorBand *coba, rctf *butr, int event) +{ + CBData *cbd; + uiBut *bt; + float unit= (butr->xmax-butr->xmin)/14.0f; + float xs= butr->xmin; + + cbd= coba->data + coba->cur; + + uiBlockBeginAlign(block); + uiDefButF(block, COL, event, "", xs,butr->ymin+20.0f,2.0f*unit,20, &(cbd->r), 0, 0, 0, B_BANDCOL, ""); + uiDefButF(block, NUM, event, "A:", xs+2.0f*unit,butr->ymin+20.0f,4.0f*unit,20, &(cbd->a), 0.0f, 1.0f, 10, 2, ""); + bt= uiDefBut(block, BUT, event, "Add", xs+6.0f*unit,butr->ymin+20.0f,2.0f*unit,20, NULL, 0, 0, 0, 0, "Adds a new color position to the colorband"); + uiButSetFunc(bt, colorband_add_cb, coba, NULL); + bt= uiDefBut(block, BUT, event, "Del", xs+8.0f*unit,butr->ymin+20.0f,2.0f*unit,20, NULL, 0, 0, 0, 0, "Deletes the active position"); + uiButSetFunc(bt, colorband_del_cb, coba, NULL); + + uiDefButS(block, MENU, event, "Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4", + xs+10.0f*unit, butr->ymin+20.0f, unit*4, 20, &coba->ipotype, 0.0, 0.0, 0, 0, "Sets interpolation type"); + + uiDefBut(block, BUT_COLORBAND, event, "", xs,butr->ymin,butr->xmax-butr->xmin,20.0f, coba, 0, 0, 0, 0, ""); + uiBlockEndAlign(block); + +} + +void colorband_buttons(uiBlock *block, ColorBand *coba, rctf *butr, int small) +{ + if(small) + colorband_buttons_small(block, coba, butr, 0); + else + colorband_buttons_large(block, coba, 0, 0, 0); +} +