Multi-View and Stereo 3D
[blender-staging.git] / source / blender / makesrna / intern / rna_color.c
index c430a89655dd0382b81a7a439fe72a3b52b29203..0c871317d04bb0fecea090a64364dd888042bb0f 100644 (file)
@@ -46,6 +46,8 @@
 #include "DNA_material_types.h"
 #include "DNA_movieclip_types.h"
 #include "DNA_node_types.h"
+#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
 #include "DNA_sequence_types.h"
 
 #include "MEM_guardedalloc.h"
@@ -62,6 +64,7 @@
 #include "ED_node.h"
 
 #include "IMB_colormanagement.h"
+#include "IMB_imbuf.h"
 
 static int rna_CurveMapping_curves_length(PointerRNA *ptr)
 {
@@ -89,7 +92,7 @@ static void rna_CurveMapping_clip_set(PointerRNA *ptr, int value)
        if (value) cumap->flag |= CUMA_DO_CLIP;
        else cumap->flag &= ~CUMA_DO_CLIP;
 
-       curvemapping_changed(cumap, FALSE);
+       curvemapping_changed(cumap, false);
 }
 
 static void rna_CurveMapping_black_level_set(PointerRNA *ptr, const float *values)
@@ -175,7 +178,7 @@ static char *rna_ColorRamp_path(PointerRNA *ptr)
                                char *node_path;
                                
                                for (node = ntree->nodes.first; node; node = node->next) {
-                                       if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
+                                       if (ELEM(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
                                                if (node->storage == ptr->data) {
                                                        /* all node color ramp properties called 'color_ramp'
                                                         * prepend path from ID to the node
@@ -192,7 +195,7 @@ static char *rna_ColorRamp_path(PointerRNA *ptr)
                        
                        case ID_LS:
                        {
-                               char *path = BKE_path_from_ID_to_color_ramp((FreestyleLineStyle *)id, (ColorBand *)ptr->data);
+                               char *path = BKE_linestyle_path_to_color_ramp((FreestyleLineStyle *)id, (ColorBand *)ptr->data);
                                if (path)
                                        return path;
                                break;
@@ -228,7 +231,7 @@ static char *rna_ColorRampElement_path(PointerRNA *ptr)
        prop = RNA_struct_find_property(&ramp_ptr, "elements");                   \
        if (prop) {                                                               \
                index = RNA_property_collection_lookup_index(&ramp_ptr, prop, ptr);   \
-               if (index >= 0) {                                                     \
+               if (index != -1) {                                                    \
                        char *texture_path = rna_ColorRamp_path(&ramp_ptr);               \
                        path = BLI_sprintfN("%s.elements[%d]", texture_path, index);      \
                        MEM_freeN(texture_path);                                          \
@@ -264,7 +267,7 @@ static char *rna_ColorRampElement_path(PointerRNA *ptr)
                                bNode *node;
                                
                                for (node = ntree->nodes.first; node; node = node->next) {
-                                       if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
+                                       if (ELEM(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
                                                RNA_pointer_create(id, &RNA_ColorRamp, node->storage, &ramp_ptr);
                                                COLRAMP_GETPATH;
                                        }
@@ -276,7 +279,7 @@ static char *rna_ColorRampElement_path(PointerRNA *ptr)
                                ListBase listbase;
                                LinkData *link;
 
-                               BKE_list_modifier_color_ramps((FreestyleLineStyle *)id, &listbase);
+                               BKE_linestyle_modifier_list_color_ramps((FreestyleLineStyle *)id, &listbase);
                                for (link = (LinkData *)listbase.first; link; link = link->next) {
                                        RNA_pointer_create(id, &RNA_ColorRamp, link->data, &ramp_ptr);
                                        COLRAMP_GETPATH;
@@ -323,7 +326,7 @@ static void rna_ColorRamp_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *
                                bNode *node;
 
                                for (node = ntree->nodes.first; node; node = node->next) {
-                                       if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
+                                       if (ELEM(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
                                                ED_node_tag_update_nodetree(bmain, ntree);
                                        }
                                }
@@ -344,6 +347,13 @@ static void rna_ColorRamp_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *
                                WM_main_add_notifier(NC_LINESTYLE, linestyle);
                                break;
                        }
+                       case ID_PA:
+                       {
+                               ParticleSettings *part = ptr->id.data;
+                               
+                               DAG_id_tag_update(&part->id, OB_RECALC_DATA | PSYS_RECALC_REDO);
+                               WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, part);
+                       }
                        default:
                                break;
                }
@@ -369,7 +379,7 @@ static void rna_ColorRampElement_remove(struct ColorBand *coba, ReportList *repo
 {
        CBData *element = element_ptr->data;
        int index = (int)(element - coba->data);
-       if (colorband_element_remove(coba, index) == FALSE) {
+       if (colorband_element_remove(coba, index) == false) {
                BKE_report(reports, RPT_ERROR, "Element not found in element collection or last element");
                return;
        }
@@ -377,10 +387,10 @@ static void rna_ColorRampElement_remove(struct ColorBand *coba, ReportList *repo
        RNA_POINTER_INVALIDATE(element_ptr);
 }
 
-void rna_CurveMap_remove_point(CurveMap *cuma, ReportList *reports, PointerRNA *point_ptr)
+static void rna_CurveMap_remove_point(CurveMap *cuma, ReportList *reports, PointerRNA *point_ptr)
 {
        CurveMapPoint *point = point_ptr->data;
-       if (curvemap_remove_point(cuma, point) == FALSE) {
+       if (curvemap_remove_point(cuma, point) == false) {
                BKE_report(reports, RPT_ERROR, "Unable to remove curve point");
                return;
        }
@@ -412,7 +422,7 @@ static void rna_ColorManagedDisplaySettings_display_device_set(struct PointerRNA
 }
 
 static EnumPropertyItem *rna_ColorManagedDisplaySettings_display_device_itemf(
-        bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
+        bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
 {
        EnumPropertyItem *items = NULL;
        int totitem = 0;
@@ -420,7 +430,7 @@ static EnumPropertyItem *rna_ColorManagedDisplaySettings_display_device_itemf(
        IMB_colormanagement_display_items_add(&items, &totitem);
        RNA_enum_item_end(&items, &totitem);
 
-       *free = TRUE;
+       *r_free = true;
 
        return items;
 }
@@ -437,6 +447,7 @@ static void rna_ColorManagedDisplaySettings_display_device_update(Main *UNUSED(b
 
                IMB_colormanagement_validate_settings(&scene->display_settings, &scene->view_settings);
 
+               DAG_id_tag_update(id, 0);
                WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
        }
 }
@@ -465,7 +476,7 @@ static void rna_ColorManagedViewSettings_view_transform_set(PointerRNA *ptr, int
 }
 
 static EnumPropertyItem *rna_ColorManagedViewSettings_view_transform_itemf(
-        bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
+        bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
 {
        Scene *scene = CTX_data_scene(C);
        EnumPropertyItem *items = NULL;
@@ -475,7 +486,7 @@ static EnumPropertyItem *rna_ColorManagedViewSettings_view_transform_itemf(
        IMB_colormanagement_view_items_add(&items, &totitem, display_settings->display_device);
        RNA_enum_item_end(&items, &totitem);
 
-       *free = TRUE;
+       *r_free = true;
        return items;
 }
 
@@ -498,7 +509,7 @@ static void rna_ColorManagedViewSettings_look_set(PointerRNA *ptr, int value)
 }
 
 static EnumPropertyItem *rna_ColorManagedViewSettings_look_itemf(
-        bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
+        bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
 {
        EnumPropertyItem *items = NULL;
        int totitem = 0;
@@ -506,7 +517,7 @@ static EnumPropertyItem *rna_ColorManagedViewSettings_look_itemf(
        IMB_colormanagement_look_items_add(&items, &totitem);
        RNA_enum_item_end(&items, &totitem);
 
-       *free = TRUE;
+       *r_free = true;
        return items;
 }
 
@@ -544,13 +555,13 @@ static void rna_ColorManagedColorspaceSettings_colorspace_set(struct PointerRNA
        ColorManagedColorspaceSettings *colorspace = (ColorManagedColorspaceSettings *) ptr->data;
        const char *name = IMB_colormanagement_colorspace_get_indexed_name(value);
 
-       if (name) {
+       if (name && name[0]) {
                BLI_strncpy(colorspace->name, name, sizeof(colorspace->name));
        }
 }
 
 static EnumPropertyItem *rna_ColorManagedColorspaceSettings_colorspace_itemf(
-        bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
+        bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
 {
        EnumPropertyItem *items = NULL;
        int totitem = 0;
@@ -558,7 +569,7 @@ static EnumPropertyItem *rna_ColorManagedColorspaceSettings_colorspace_itemf(
        IMB_colormanagement_colorspace_items_add(&items, &totitem);
        RNA_enum_item_end(&items, &totitem);
 
-       *free = TRUE;
+       *r_free = true;
 
        return items;
 }
@@ -595,13 +606,13 @@ static void rna_ColorManagedColorspaceSettings_reload_update(Main *UNUSED(bmain)
                if (scene->ed) {
                        ColorManagedColorspaceSettings *colorspace_settings = (ColorManagedColorspaceSettings *) ptr->data;
                        Sequence *seq;
-                       int seq_found = FALSE;
+                       bool seq_found = false;
 
                        if (&scene->sequencer_colorspace_settings != colorspace_settings) {
                                SEQ_BEGIN(scene->ed, seq);
                                {
                                        if (seq->strip && &seq->strip->colorspace_settings == colorspace_settings) {
-                                               seq_found = TRUE;
+                                               seq_found = true;
                                                break;
                                        }
                                }
@@ -609,10 +620,23 @@ static void rna_ColorManagedColorspaceSettings_reload_update(Main *UNUSED(bmain)
                        }
 
                        if (seq_found) {
+                               BKE_sequence_free_anim(seq);
+
+                               if (seq->strip->proxy && seq->strip->proxy->anim) {
+                                       IMB_free_anim(seq->strip->proxy->anim);
+                                       seq->strip->proxy->anim = NULL;
+                               }
+
                                BKE_sequence_invalidate_cache(scene, seq);
                                BKE_sequencer_preprocessed_cache_cleanup_sequence(seq);
                        }
                        else {
+                               SEQ_BEGIN(scene->ed, seq);
+                               {
+                                       BKE_sequence_free_anim(seq);
+                               }
+                               SEQ_END;
+
                                BKE_sequencer_cache_cleanup();
                                BKE_sequencer_preprocessed_cache_cleanup();
                        }
@@ -801,13 +825,15 @@ static void rna_def_curvemapping(BlenderRNA *brna)
 
        prop = RNA_def_property(srna, "black_level", PROP_FLOAT, PROP_COLOR);
        RNA_def_property_float_sdna(prop, NULL, "black");
-       RNA_def_property_range(prop, -1000.0f, 1000.0f);
+       RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
+       RNA_def_property_ui_range(prop, -1000.0f, 1000.0f, 1, 3);
        RNA_def_property_ui_text(prop, "Black Level", "For RGB curves, the color that black is mapped to");
        RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_black_level_set", NULL);
 
        prop = RNA_def_property(srna, "white_level", PROP_FLOAT, PROP_COLOR);
        RNA_def_property_float_sdna(prop, NULL, "white");
-       RNA_def_property_range(prop, -1000.0f, 1000.0f);
+       RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
+       RNA_def_property_ui_range(prop, -1000.0f, 1000.0f, 1, 3);
        RNA_def_property_ui_text(prop, "White Level", "For RGB curves, the color that white is mapped to");
        RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_white_level_set", NULL);
 
@@ -833,7 +859,12 @@ static void rna_def_color_ramp_element(BlenderRNA *brna)
        RNA_def_property_array(prop, 4);
        RNA_def_property_ui_text(prop, "Color", "Set color of selected color stop");
        RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
-       
+
+       prop = RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_COLOR);
+       RNA_def_property_float_sdna(prop, NULL, "a");
+       RNA_def_property_ui_text(prop, "Alpha", "Set alpha of selected color stop");
+       RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
+
        prop = RNA_def_property(srna, "position", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "pos");
        RNA_def_property_range(prop, 0, 1);
@@ -878,14 +909,29 @@ static void rna_def_color_ramp(BlenderRNA *brna)
        FunctionRNA *func;
 
        static EnumPropertyItem prop_interpolation_items[] = {
-               {1, "EASE", 0, "Ease", ""},
-               {3, "CARDINAL", 0, "Cardinal", ""},
-               {0, "LINEAR", 0, "Linear", ""},
-               {2, "B_SPLINE", 0, "B-Spline", ""},
-               {4, "CONSTANT", 0, "Constant", ""},
+               {COLBAND_INTERP_EASE, "EASE", 0, "Ease", ""},
+               {COLBAND_INTERP_CARDINAL, "CARDINAL", 0, "Cardinal", ""},
+               {COLBAND_INTERP_LINEAR, "LINEAR", 0, "Linear", ""},
+               {COLBAND_INTERP_B_SPLINE, "B_SPLINE", 0, "B-Spline", ""},
+               {COLBAND_INTERP_CONSTANT, "CONSTANT", 0, "Constant", ""},
                {0, NULL, 0, NULL, NULL}
        };
        
+       static EnumPropertyItem prop_mode_items[] = {
+               {COLBAND_BLEND_RGB, "RGB", 0, "RGB", ""},
+               {COLBAND_BLEND_HSV, "HSV", 0, "HSV", ""},
+               {COLBAND_BLEND_HSL, "HSL", 0, "HSL", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       static EnumPropertyItem prop_hsv_items[] = {
+               {COLBAND_HUE_NEAR, "NEAR", 0, "Near", ""},
+               {COLBAND_HUE_FAR, "FAR", 0, "Far", ""},
+               {COLBAND_HUE_CW, "CW", 0, "Clockwise", ""},
+               {COLBAND_HUE_CCW, "CCW", 0, "Counter-Clockwise", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
        srna = RNA_def_struct(brna, "ColorRamp", NULL);
        RNA_def_struct_sdna(srna, "ColorBand");
        RNA_def_struct_path_func(srna, "rna_ColorRamp_path");
@@ -901,7 +947,19 @@ static void rna_def_color_ramp(BlenderRNA *brna)
        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_ui_text(prop, "Interpolation", "Set interpolation between color stops");
+       RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
+
+       prop = RNA_def_property(srna, "hue_interpolation", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "ipotype_hue");
+       RNA_def_property_enum_items(prop, prop_hsv_items);
+       RNA_def_property_ui_text(prop, "Color Interpolation", "Set color interpolation");
+       RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
+
+       prop = RNA_def_property(srna, "color_mode", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "color_mode");
+       RNA_def_property_enum_items(prop, prop_mode_items);
+       RNA_def_property_ui_text(prop, "Color Mode", "Set color mode to use for interpolation");
        RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
 
 #if 0 /* use len(elements) */