diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_texture.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/texture.c | 67 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 20 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 80 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_color.c | 79 |
6 files changed, 159 insertions, 94 deletions
diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h index 39c12a2bfd8..380672dae04 100644 --- a/source/blender/blenkernel/BKE_texture.h +++ b/source/blender/blenkernel/BKE_texture.h @@ -61,6 +61,9 @@ void init_colorband(struct ColorBand *coba, int rangetype); struct ColorBand *add_colorband(int rangetype); int do_colorband(struct ColorBand *coba, float in, float out[4]); void colorband_table_RGBA(struct ColorBand *coba, float **array, int *size); +int vergcband(const void *a1, const void *a2); +struct CBData *colorband_element_add(struct ColorBand *coba, float position); +int colorband_element_remove(struct ColorBand *coba, int index); void default_tex(struct Tex *tex); struct Tex *add_texture(const char *name); diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 57816b7e470..d05d8ccbc08 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -403,6 +403,73 @@ void colorband_table_RGBA(ColorBand *coba, float **array, int *size) do_colorband(coba, (float)a/(float)CM_TABLE, &(*array)[a*4]); } +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; +} + +CBData *colorband_element_add(struct ColorBand *coba, float position) +{ + int a; + + if(coba->tot==MAXCOLORBAND) { + return NULL; + } + else if(coba->tot > 0) { + CBData *xnew; + float col[4]; + + do_colorband(coba, position, col); + + xnew = &coba->data[coba->tot]; + xnew->pos = position; + + xnew->r = col[0]; + xnew->g = col[1]; + xnew->b = col[2]; + xnew->a = col[3]; + } + + coba->tot++; + coba->cur = coba->tot-1; + + for(a = 0; a < coba->tot; a++) + coba->data[a].cur = a; + + qsort(coba->data, coba->tot, sizeof(CBData), vergcband); + + for(a = 0; a < coba->tot; a++) { + if(coba->data[a].cur == coba->cur) { + coba->cur = a; + break; + } + } + + return coba->data + coba->cur; +} + +int colorband_element_remove(struct ColorBand *coba, int index) +{ + int a; + + if(coba->tot < 2) + return 0; + + if(index < 0 || index >= coba->tot) + return 0; + + for(a = index; a < coba->tot; a++) { + coba->data[a] = coba->data[a + 1]; + } + if(coba->cur) coba->cur--; + coba->tot--; + return 1; +} + /* ******************* TEX ************************ */ void free_texture(Tex *tex) diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 3227d4b25bb..c050f25256a 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -11078,10 +11078,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main) if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) { - GroupObject *go = NULL; - Base *base = NULL; - Scene *scene = NULL; - smd->domain->vorticity = 2.0f; smd->domain->time_scale = 1.0f; diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 0f8f84b94dc..f617cc4ae8d 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -3251,24 +3251,8 @@ static int ui_do_but_COLORBAND(bContext *C, uiBlock *block, uiBut *but, uiHandle if(event->ctrl) { /* insert new key on mouse location */ - if(coba->tot < MAXCOLORBAND-1) { - float pos= ((float)(mx - but->x1))/(but->x2-but->x1); - float col[4]; - - do_colorband(coba, pos, col); /* executes it */ - - coba->tot++; - coba->cur= coba->tot-1; - - coba->data[coba->cur].r= col[0]; - coba->data[coba->cur].g= col[1]; - coba->data[coba->cur].b= col[2]; - coba->data[coba->cur].a= col[3]; - coba->data[coba->cur].pos= pos; - - ui_colorband_update(coba); - } - + float pos= ((float)(mx - but->x1))/(but->x2-but->x1); + colorband_element_add(coba, pos); button_activate_state(C, but, BUTTON_STATE_EXIT); } else { diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 28d0e131ef2..01d2ad29b0e 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -1302,71 +1302,20 @@ static void rna_update_cb(bContext *C, void *arg_cb, void *arg_unused) #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 *cb_v, void *coba_v) -{ - ColorBand *coba= coba_v; - int a; - - if(coba->tot<2) return; - - for(a=0; a<coba->tot; a++) coba->data[a].cur= a; - qsort(coba->data, coba->tot, sizeof(CBData), vergcband); - for(a=0; a<coba->tot; a++) { - if(coba->data[a].cur==coba->cur) { - coba->cur= a; - break; - } - } - - rna_update_cb(C, cb_v, NULL); -} - static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v) { ColorBand *coba= coba_v; + float pos= 0.5f; - if(coba->tot > 0) { - CBData *xnew, *x1, *x2; - float col[4]; - - xnew= &coba->data[coba->tot]; - - if(coba->tot > 1) { - if(coba->cur > 0) { - x1= &coba->data[coba->cur-1]; - x2= &coba->data[coba->cur]; - } - else { - x1= &coba->data[coba->cur]; - x2= &coba->data[coba->cur+1]; - } - - xnew->pos = x1->pos + ((x2->pos - x1->pos) / 2); - } - - do_colorband(coba, xnew->pos, col); - - xnew->r= col[0]; - xnew->g= col[1]; - xnew->b= col[2]; - xnew->a= col[3]; + if(coba->tot > 1) { + if(coba->cur > 0) pos= (coba->data[coba->cur-1].pos + coba->data[coba->cur].pos) * 0.5f; + else pos= (coba->data[coba->cur+1].pos + coba->data[coba->cur].pos) * 0.5f; } - if(coba->tot < MAXCOLORBAND-1) coba->tot++; - coba->cur= coba->tot-1; - - colorband_pos_cb(C, cb_v, coba_v); - - ED_undo_push(C, "Add colorband"); + if(colorband_element_add(coba, pos)) { + rna_update_cb(C, cb_v, NULL); + ED_undo_push(C, "Add colorband"); + } } static void colorband_del_cb(bContext *C, void *cb_v, void *coba_v) @@ -1374,17 +1323,10 @@ static void colorband_del_cb(bContext *C, void *cb_v, void *coba_v) ColorBand *coba= coba_v; int a; - if(coba->tot<2) return; - - for(a=coba->cur; a<coba->tot; a++) { - coba->data[a]= coba->data[a+1]; + if(colorband_element_remove(coba, coba->cur)) { + ED_undo_push(C, "Delete colorband"); + rna_update_cb(C, cb_v, NULL); } - if(coba->cur) coba->cur--; - coba->tot--; - - ED_undo_push(C, "Delete colorband"); - - rna_update_cb(C, cb_v, NULL); } static void colorband_flip_cb(bContext *C, void *cb_v, void *coba_v) diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c index 9e004cd5946..f33ca10f934 100644 --- a/source/blender/makesrna/intern/rna_color.c +++ b/source/blender/makesrna/intern/rna_color.c @@ -42,6 +42,7 @@ #include "BKE_colortools.h" #include "BKE_depsgraph.h" #include "BKE_node.h" +#include "BKE_texture.h" #include "WM_api.h" #include "WM_types.h" @@ -270,6 +271,29 @@ static void rna_ColorRamp_update(Main *bmain, Scene *scene, PointerRNA *ptr) } } +static void rna_ColorRamp_eval(struct ColorBand *coba, float position, float color[4]) +{ + do_colorband(coba, position, color); +} + +static CBData *rna_ColorRampElement_new(struct ColorBand *coba, ReportList *reports, float position) +{ + CBData *element= colorband_element_add(coba, position); + + if(element==NULL) + BKE_reportf(reports, RPT_ERROR, "Unable to add element to colorband (limit %d)", MAXCOLORBAND); + + return element; +} + +static void rna_ColorRampElement_remove(struct ColorBand *coba, ReportList *reports, CBData *element) +{ + int index = (int)(element - coba->data); + if(colorband_element_remove(coba, index) == 0) + BKE_report(reports, RPT_ERROR, "Element not found in element collection or last element"); + +} + static void rna_Scopes_update(Main *bmain, Scene *scene, PointerRNA *ptr) { Scopes *s= (Scopes*)ptr->data; @@ -396,7 +420,7 @@ static void rna_def_color_ramp_element(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; - + srna= RNA_def_struct(brna, "ColorRampElement", NULL); RNA_def_struct_sdna(srna, "CBData"); RNA_def_struct_path_func(srna, "rna_ColorRampElement_path"); @@ -415,11 +439,42 @@ static void rna_def_color_ramp_element(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_ColorRamp_update"); } +static void rna_def_color_ramp_element_api(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + PropertyRNA *parm; + FunctionRNA *func; + + RNA_def_property_srna(cprop, "ColorRampElements"); + srna= RNA_def_struct(brna, "ColorRampElements", NULL); + RNA_def_struct_sdna(srna, "ColorBand"); + RNA_def_struct_path_func(srna, "rna_ColorRampElement_path"); + RNA_def_struct_ui_text(srna, "Color Ramp Elements", "Collection of Color Ramp Elements"); + + /* TODO, make these functions generic in texture.c */ + func = RNA_def_function(srna, "new", "rna_ColorRampElement_new"); + RNA_def_function_ui_description(func, "Add element to ColorRamp"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm= RNA_def_float(func, "position", 0.0f, 0.0f, 1.0f, "Position", "Position to add element", 0.0f, 1.0f); + RNA_def_property_flag(parm, PROP_REQUIRED); + /* return type */ + parm= RNA_def_pointer(func, "element", "ColorRampElement", "", "New element."); + RNA_def_function_return(func, parm); + + func = RNA_def_function(srna, "remove", "rna_ColorRampElement_remove"); + RNA_def_function_ui_description(func, "Delete element from ColorRamp"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + //parm= RNA_def_int(func, "index", 0, 0, 31, "Index", "Element to delete.", 0, 31); + parm= RNA_def_pointer(func, "element", "ColorRampElement", "", "Element to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED); +} + static void rna_def_color_ramp(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; - + FunctionRNA *func; + static EnumPropertyItem prop_interpolation_items[] = { {1, "EASE", 0, "Ease", ""}, {3, "CARDINAL", 0, "Cardinal", ""}, @@ -438,12 +493,30 @@ static void rna_def_color_ramp(BlenderRNA *brna) RNA_def_property_struct_type(prop, "ColorRampElement"); RNA_def_property_ui_text(prop, "Elements", ""); RNA_def_property_update(prop, 0, "rna_ColorRamp_update"); - + rna_def_color_ramp_element_api(brna, prop); + prop= RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "ipotype"); RNA_def_property_enum_items(prop, prop_interpolation_items); RNA_def_property_ui_text(prop, "Interpolation", ""); RNA_def_property_update(prop, 0, "rna_ColorRamp_update"); + + prop= RNA_def_property(srna, "total", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "tot"); + /* needs a function to do the right thing when adding elements like colorband_add_cb() */ + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_range(prop, 0, 31); /* MAXCOLORBAND = 32 */ + RNA_def_property_ui_text(prop, "Total", "Total number of elements"); + RNA_def_property_update(prop, 0, "rna_ColorRamp_update"); + + func = RNA_def_function(srna, "evaluate", "rna_ColorRamp_eval"); + RNA_def_function_ui_description(func, "Evaluate ColorRamp"); + prop= RNA_def_float(func, "position", 1.0f, 0.0f, 1.0f, "Position", "Evaluate ColorRamp at position", 0.0f, 1.0f); + RNA_def_property_flag(prop, PROP_REQUIRED); + /* return */ + prop = RNA_def_float_color(func, "color", 4, NULL, -FLT_MAX, FLT_MAX, "Color", "Color at given position", -FLT_MAX, FLT_MAX); + RNA_def_property_flag(prop, PROP_THICK_WRAP); + RNA_def_function_output(func, prop); } static void rna_def_histogram(BlenderRNA *brna) |