part 1 of cleaning up my little array macro library to be a formal API. also removed...
[blender.git] / source / blender / blenkernel / intern / brush.c
index 08a2b1dcecb482979eb344de41fea674736417fd..76a26762abeb55e13b8b36d43085be38d45b1e5f 100644 (file)
@@ -35,6 +35,7 @@
 #include "DNA_brush_types.h"
 #include "DNA_color_types.h"
 #include "DNA_image_types.h"
+#include "DNA_object_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_windowmanager_types.h"
@@ -50,6 +51,7 @@
 #include "BKE_image.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_paint.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
 
@@ -61,7 +63,7 @@
 
 /* Datablock add/copy/free/make_local */
 
-Brush *add_brush(char *name)
+Brush *add_brush(const char *name)
 {
        Brush *brush;
 
@@ -73,6 +75,8 @@ Brush *add_brush(char *name)
        brush->alpha= 0.2f;
        brush->size= 25;
        brush->spacing= 10.0f;
+       brush->smooth_stroke_radius= 75;
+       brush->smooth_stroke_factor= 0.9;
        brush->rate= 0.1f;
        brush->innerradius= 0.5f;
        brush->clone.alpha= 0.5;
@@ -103,6 +107,8 @@ Brush *copy_brush(Brush *brush)
                }
        }
 
+       brushn->curve= curvemapping_copy(brush->curve);
+
        /* enable fake user by default */
        if (!(brushn->id.flag & LIB_FAKEUSER)) {
                brushn->id.flag |= LIB_FAKEUSER;
@@ -150,7 +156,7 @@ void make_local_brush(Brush *brush)
        }
 
        for(scene= G.main->scene.first; scene; scene=scene->id.next)
-               if(scene->toolsettings->imapaint.brush==brush) {
+               if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
                        if(scene->id.lib) lib= 1;
                        else local= 1;
                }
@@ -172,9 +178,9 @@ void make_local_brush(Brush *brush)
                brushn->id.flag |= LIB_FAKEUSER;
                
                for(scene= G.main->scene.first; scene; scene=scene->id.next)
-                       if(scene->toolsettings->imapaint.brush==brush)
+                       if(paint_brush(&scene->toolsettings->imapaint.paint)==brush)
                                if(scene->id.lib==0) {
-                                       scene->toolsettings->imapaint.brush= brushn;
+                                       paint_brush_set(&scene->toolsettings->imapaint.paint, brushn);
                                        brushn->id.us++;
                                        brush->id.us--;
                                }
@@ -183,7 +189,7 @@ void make_local_brush(Brush *brush)
 
 /* Library Operations */
 
-int brush_set_nr(Brush **current_brush, int nr)
+int brush_set_nr(Brush **current_brush, int nr, const char *name)
 {
        ID *idtest, *id;
        
@@ -192,7 +198,7 @@ int brush_set_nr(Brush **current_brush, int nr)
        
        if(idtest==0) { /* new brush */
                if(id) idtest= (ID *)copy_brush((Brush *)id);
-               else idtest= (ID *)add_brush("Brush");
+               else idtest= (ID *)add_brush(name);
                idtest->us--;
        }
        if(idtest!=id) {
@@ -285,6 +291,13 @@ void brush_curve_preset(Brush *b, BrushCurvePreset preset)
        curvemapping_changed(b->curve, 0);
 }
 
+static MTex *brush_active_texture(Brush *brush)
+{
+       if(brush && brush->texact >= 0)
+               return brush->mtex[brush->texact];
+       return NULL;
+}
+
 int brush_texture_set_nr(Brush *brush, int nr)
 {
        ID *idtest, *id=NULL;
@@ -359,10 +372,10 @@ int brush_clone_image_delete(Brush *brush)
        return 0;
 }
 
-void brush_check_exists(Brush **brush)
+void brush_check_exists(Brush **brush, const char *name)
 {
        if(*brush==NULL)
-               brush_set_nr(brush, 1);
+               brush_set_nr(brush, 1, name);
 }
 
 /* Brush Sampling */
@@ -396,23 +409,6 @@ float brush_sample_falloff(Brush *brush, float dist)
                return 0.0f;
 }
 
-float brush_sample_falloff_noalpha(Brush *brush, float dist)
-{
-       float outer, inner;
-
-       outer = brush->size >> 1;
-       inner = outer*brush->innerradius;
-
-       if (dist <= inner) {
-               return 1.0f;
-       }
-       else if ((dist < outer) && (inner < outer)) {
-               return 1.0f - sqrt((dist - inner)/(outer - inner));
-       }
-       else 
-               return 0.0f;
-}
-
 void brush_sample_tex(Brush *brush, float *xy, float *rgba)
 {
        MTex *mtex= brush->mtex[brush->texact];
@@ -715,7 +711,7 @@ static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, i
        }
 }
 
-void brush_painter_fixed_tex_partial_update(BrushPainter *painter, float *pos)
+static void brush_painter_fixed_tex_partial_update(BrushPainter *painter, float *pos)
 {
        Brush *brush= painter->brush;
        BrushPainterCache *cache= &painter->cache;
@@ -1053,34 +1049,40 @@ static struct ImBuf *brush_gen_radial_control_imbuf(Brush *br)
        return im;
 }
 
-void brush_radial_control_invoke(wmOperator *op, Brush *br)
+void brush_radial_control_invoke(wmOperator *op, Brush *br, float size_weight)
 {
        int mode = RNA_int_get(op->ptr, "mode");
-       float original_value;
+       float original_value= 0;
 
        if(mode == WM_RADIALCONTROL_SIZE)
-               original_value = br->size;
+               original_value = br->size * size_weight;
        else if(mode == WM_RADIALCONTROL_STRENGTH)
                original_value = br->alpha;
-       else if(mode == WM_RADIALCONTROL_ANGLE)
-               original_value = br->rot;
+       else if(mode == WM_RADIALCONTROL_ANGLE) {
+               MTex *mtex = brush_active_texture(br);
+               if(mtex)
+                       original_value = mtex->rot;
+       }
 
        RNA_float_set(op->ptr, "initial_value", original_value);
        op->customdata = brush_gen_radial_control_imbuf(br);
 }
 
-int brush_radial_control_exec(wmOperator *op, Brush *br)
+int brush_radial_control_exec(wmOperator *op, Brush *br, float size_weight)
 {
        int mode = RNA_int_get(op->ptr, "mode");
        float new_value = RNA_float_get(op->ptr, "new_value");
        const float conv = 0.017453293;
 
        if(mode == WM_RADIALCONTROL_SIZE)
-               br->size = new_value;
+               br->size = new_value * size_weight;
        else if(mode == WM_RADIALCONTROL_STRENGTH)
                br->alpha = new_value;
-       else if(mode == WM_RADIALCONTROL_ANGLE)
-               br->rot = new_value * conv;
+       else if(mode == WM_RADIALCONTROL_ANGLE) {
+               MTex *mtex = brush_active_texture(br);
+               if(mtex)
+                       mtex->rot = new_value * conv;
+       }
 
        return OPERATOR_FINISHED;
 }