2.5 Texture paint:
authorNicholas Bishop <nicholasbishop@gmail.com>
Mon, 17 Aug 2009 04:40:59 +0000 (04:40 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Mon, 17 Aug 2009 04:40:59 +0000 (04:40 +0000)
* Converted to use Paint struct. Now all the brush modes are done.

TODO:
* Make the UI better

14 files changed:
source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/paint.c
source/blender/blenkernel/intern/scene.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/space_buttons/buttons_context.c
source/blender/editors/space_image/image_buttons.c
source/blender/editors/space_image/image_draw.c
source/blender/editors/space_node/node_edit.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_sculpt_paint.c
source/blender/makesrna/intern/rna_space.c

index ae18d0e9561b44fda7bdabdbde5473b75fe10e91..67b260b234829df3686371c94960afdd531a76b1 100644 (file)
@@ -33,9 +33,9 @@ struct Object;
 struct Paint;
 struct Scene;
 
-void paint_init(Paint *p, const char *brush_name);
-void free_paint(Paint *p);
-void copy_paint(Paint *orig, Paint *new);
+void paint_init(struct Paint *p, const char *brush_name);
+void free_paint(struct Paint *p);
+void copy_paint(struct Paint *orig, struct Paint *new);
 
 struct Paint *paint_get_active(struct Scene *sce);
 struct Brush *paint_brush(struct Paint *paint);
index 3524550925ef1423616aa06b49b500095c4a90bf..612f6d2051d9aa7394e4ecd5936c1272116328e3 100644 (file)
@@ -51,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"
 
@@ -153,7 +154,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;
                }
@@ -175,9 +176,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--;
                                }
index 8e774e4c85a45f3f6c1ca21c126a9fa52091e85c..5ae8411835609a0d7e8bdde12d0c75b534cb897c 100644 (file)
@@ -158,6 +158,10 @@ void free_paint(Paint *paint)
 
 void copy_paint(Paint *orig, Paint *new)
 {
-       if(orig->brushes)
+       if(orig->brushes) {
+               int i;
                new->brushes = MEM_dupallocN(orig->brushes);
+               for(i = 0; i < orig->brush_count; ++i)
+                       id_us_plus((ID *)new->brushes[i]);
+       }
 }
index dc1a55ed0eb525daf98cb9426f7292fe06a93647..8488d7ab2471f10b8cda7b63f1e4b22d29f380b4 100644 (file)
@@ -177,7 +177,7 @@ Scene *copy_scene(Main *bmain, Scene *sce, int type)
                                copy_paint(&ts->sculpt->paint, &ts->sculpt->paint);
                        }
 
-                       id_us_plus((ID *)ts->imapaint.brush);
+                       copy_paint(&ts->imapaint.paint, &ts->imapaint.paint);
                        ts->imapaint.paintcursor= NULL;
 
                        ts->particle.paintcursor= NULL;
@@ -284,7 +284,8 @@ void free_scene(Scene *sce)
                        free_paint(&sce->toolsettings->sculpt->paint);
                        MEM_freeN(sce->toolsettings->sculpt);
                }
-               
+               free_paint(&sce->toolsettings->imapaint.paint);
+
                MEM_freeN(sce->toolsettings);
                sce->toolsettings = NULL;       
        }
index 685c379dab23ad68be3de305de2a199cf9a1ef57..9272c6fe353a55541fd02bb2f4c00066c2bb7d6e 100644 (file)
@@ -4042,12 +4042,10 @@ static void lib_link_scene(FileData *fd, Main *main)
                        sce->set= newlibadr(fd, sce->id.lib, sce->set);
                        sce->ima= newlibadr_us(fd, sce->id.lib, sce->ima);
                        
-                       sce->toolsettings->imapaint.brush=
-                               newlibadr_us(fd, sce->id.lib, sce->toolsettings->imapaint.brush);
-
                        link_paint(fd, sce, &sce->toolsettings->sculpt->paint);
                        link_paint(fd, sce, &sce->toolsettings->vpaint->paint);
                        link_paint(fd, sce, &sce->toolsettings->wpaint->paint);
+                       link_paint(fd, sce, &sce->toolsettings->imapaint.paint);
 
                        sce->toolsettings->skgen_template = newlibadr(fd, sce->id.lib, sce->toolsettings->skgen_template);
 
@@ -4159,6 +4157,8 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                direct_link_paint(fd, (Paint**)&sce->toolsettings->vpaint);
                direct_link_paint(fd, (Paint**)&sce->toolsettings->wpaint);
 
+               sce->toolsettings->imapaint.paint.brushes= newdataadr(fd, sce->toolsettings->imapaint.paint.brushes);
+
                sce->toolsettings->imapaint.paintcursor= NULL;
                sce->toolsettings->particle.paintcursor= NULL;
        }
index f59fc769d5d2590964b54fb4e503c552374eeefb..cd388cdf9cc5256cfdb4a18a6a12ae86efcdb0c1 100644 (file)
@@ -1726,6 +1726,8 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                        write_paint(wd, &tos->sculpt->paint);
                }
 
+               write_paint(wd, &tos->imapaint.paint);
+
                ed= sce->ed;
                if(ed) {
                        writestruct(wd, DATA, "Editing", 1, ed);
index 93744072fffaa9ed5e517af77d603edda6e7a163..975bfd8dbe70df1b57241a0252bd8939c6a6624d 100644 (file)
@@ -71,6 +71,7 @@
 #include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_node.h"
+#include "BKE_paint.h"
 #include "BKE_utildefines.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_report.h"
@@ -4375,7 +4376,7 @@ static Brush *image_paint_brush(bContext *C)
        Scene *scene= CTX_data_scene(C);
        ToolSettings *settings= scene->toolsettings;
 
-       return settings->imapaint.brush;
+       return paint_brush(&settings->imapaint.paint);
 }
 
 static int image_paint_poll(bContext *C)
@@ -4486,11 +4487,12 @@ static void paint_redraw(bContext *C, ImagePaintState *s, int final)
        }
 }
 
-static int paint_init(bContext *C, wmOperator *op)
+static int texture_paint_init(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
        ToolSettings *settings= scene->toolsettings;
        PaintOperation *pop;
+       Brush *brush;
 
        pop= MEM_callocN(sizeof(PaintOperation), "PaintOperation");
        pop->first= 1;
@@ -4518,10 +4520,11 @@ static int paint_init(bContext *C, wmOperator *op)
        pop->ps.ar= CTX_wm_region(C);
 
        /* intialize brush */
-       if(!settings->imapaint.brush)
+       brush= paint_brush(&settings->imapaint.paint);
+       if(!brush)
                return 0;
 
-       pop->s.brush = settings->imapaint.brush;
+       pop->s.brush = brush;
        pop->s.tool = settings->imapaint.tool;
        if(pop->mode == PAINT_MODE_3D && (pop->s.tool == PAINT_TOOL_CLONE))
                pop->s.tool = PAINT_TOOL_DRAW;
@@ -4672,7 +4675,7 @@ static void paint_exit(bContext *C, wmOperator *op)
 
 static int paint_exec(bContext *C, wmOperator *op)
 {
-       if(!paint_init(C, op)) {
+       if(!texture_paint_init(C, op)) {
                MEM_freeN(op->customdata);
                return OPERATOR_CANCELLED;
        }
@@ -4746,7 +4749,7 @@ static int paint_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        PaintOperation *pop;
 
-       if(!paint_init(C, op)) {
+       if(!texture_paint_init(C, op)) {
                MEM_freeN(op->customdata);
                return OPERATOR_CANCELLED;
        }
@@ -4874,7 +4877,7 @@ static int paint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *eve
        ToolSettings *ts = CTX_data_scene(C)->toolsettings;
        get_imapaint_zoom(C, &zoom, &zoom);
        toggle_paint_cursor(C, !ts->imapaint.paintcursor);
-       brush_radial_control_invoke(op, ts->imapaint.brush, 0.5 * zoom);
+       brush_radial_control_invoke(op, paint_brush(&ts->imapaint.paint), 0.5 * zoom);
        return WM_radial_control_invoke(C, op, event);
 }
 
@@ -4893,7 +4896,7 @@ static int paint_radial_control_exec(bContext *C, wmOperator *op)
        int ret;
        char str[256];
        get_imapaint_zoom(C, &zoom, &zoom);
-       ret = brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->imapaint.brush, 2.0 / zoom);
+       ret = brush_radial_control_exec(op, paint_brush(&CTX_data_scene(C)->toolsettings->imapaint.paint), 2.0 / zoom);
        WM_radial_control_string(op, str, 256);
 
        return ret;
@@ -5167,7 +5170,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
                        me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT,
                                                         NULL, me->totface);
 
-               brush_check_exists(&scene->toolsettings->imapaint.brush, "Brush");
+               paint_init(&scene->toolsettings->imapaint.paint, "Brush");
 
                if(U.glreslimit != 0)
                        GPU_free_images();
@@ -5202,13 +5205,13 @@ static int texture_paint_radial_control_invoke(bContext *C, wmOperator *op, wmEv
 {
        ToolSettings *ts = CTX_data_scene(C)->toolsettings;
        toggle_paint_cursor(C, !ts->imapaint.paintcursor);
-       brush_radial_control_invoke(op, ts->imapaint.brush, 0.5);
+       brush_radial_control_invoke(op, paint_brush(&ts->imapaint.paint), 0.5);
        return WM_radial_control_invoke(C, op, event);
 }
 
 static int texture_paint_radial_control_exec(bContext *C, wmOperator *op)
 {
-       int ret = brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->imapaint.brush, 2);
+       int ret = brush_radial_control_exec(op, paint_brush(&CTX_data_scene(C)->toolsettings->imapaint.paint), 2);
        char str[256];
        WM_radial_control_string(op, str, 256);
 
index 318e0b0f5587d0c6150b5406c5b45c744468394f..6b89532cdafdb5f823ef0df20406a70029507148 100644 (file)
@@ -322,16 +322,8 @@ static int buttons_context_path_brush(const bContext *C, ButsContextPath *path)
                scene= path->ptr[path->len-1].data;
                ts= scene->toolsettings;
 
-               if(obact) {
-                       if(obact->mode & OB_MODE_SCULPT)
-                               paint_brush(&ts->sculpt->paint);
-                       else if(obact->mode & OB_MODE_VERTEX_PAINT)
-                               paint_brush(&ts->vpaint->paint);
-                       else if(obact->mode & OB_MODE_WEIGHT_PAINT)
-                               paint_brush(&ts->wpaint->paint);
-                       else if(obact->mode & OB_MODE_TEXTURE_PAINT)
-                               br= ts->imapaint.brush;
-               }
+               if(scene)
+                       br= paint_brush(paint_get_active(scene));
 
                if(br) {
                        RNA_id_pointer_create(&br->id, &path->ptr[path->len]);
index e4fbaad656f1d361758d27baba5fee9acdb67d5a..ac0a5c7f53acc1cfad14add65febc85163e98feb 100644 (file)
@@ -451,7 +451,7 @@ void brush_buttons(const bContext *C, uiBlock *block, short fromsima,
 {
 //     SpaceImage *sima= CTX_wm_space_image(C);
        ToolSettings *settings= CTX_data_tool_settings(C);
-       Brush *brush= settings->imapaint.brush;
+       Brush *brush= paint_brush(&settings->imapaint.paint);
        ID *id;
        int yco, xco, butw, but_idx;
 //     short *menupoin = &(sima->menunr); // XXX : &(G.buts->menunr);
@@ -473,7 +473,7 @@ void brush_buttons(const bContext *C, uiBlock *block, short fromsima,
        uiBlockEndAlign(block);
        yco -= 30;
        
-       id= (ID*)settings->imapaint.brush;
+       id= (ID*)brush;
        xco= 200; // std_libbuttons(block, 0, yco, 0, NULL, evt_browse, ID_BR, 0, id, NULL, menupoin, 0, evt_local, evt_del, 0, evt_keepdata);
        
        if(brush && !brush->id.lib) {
@@ -575,7 +575,7 @@ static void image_panel_paintcolor(const bContext *C, Panel *pa)
 {
        SpaceImage *sima= CTX_wm_space_image(C);
        ToolSettings *settings= CTX_data_tool_settings(C);
-       Brush *brush= settings->imapaint.brush;
+       Brush *brush= paint_brush(&settings->imapaint.paint);
        uiBlock *block;
        static float hsv[3], old[3];    // used as temp mem for picker
        static char hexcol[128];
index ff25a2635d242e9d334bd018554835ba378beff4..2f5fc805367122bf6d2bf4a5b6e7d46eafe0e640 100644 (file)
@@ -47,6 +47,7 @@
 #include "BKE_colortools.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
+#include "BKE_paint.h"
 #include "BKE_utildefines.h"
 
 #include "BIF_gl.h"
@@ -577,7 +578,7 @@ static void draw_image_view_tool(Scene *scene)
 
 static unsigned char *get_alpha_clone_image(Scene *scene, int *width, int *height)
 {
-       Brush *brush = scene->toolsettings->imapaint.brush;
+       Brush *brush = paint_brush(&scene->toolsettings->imapaint.paint);
        ImBuf *ibuf;
        unsigned int size, alpha;
        unsigned char *rect, *cp;
@@ -615,7 +616,7 @@ static void draw_image_paint_helpers(SpaceImage *sima, ARegion *ar, Scene *scene
        int x, y, w, h;
        unsigned char *clonerect;
 
-       brush= scene->toolsettings->imapaint.brush;
+       brush= paint_brush(&scene->toolsettings->imapaint.paint);
 
        if(brush && (scene->toolsettings->imapaint.tool == PAINT_TOOL_CLONE)) {
                /* this is not very efficient, but glDrawPixels doesn't allow
index d19dc897a8922e822d6d80a456ee0e262237db39..d66cbb55baa4ce9a457ccbc50820ab43ed407904 100644 (file)
@@ -624,17 +624,18 @@ void snode_set_context(SpaceNode *snode, Scene *scene)
                }
                else {
                        MTex *mtex= NULL;
+                       Brush *brush= NULL;
                        
                        if(ob && ob->mode & OB_MODE_SCULPT) {
-                               Brush *brush = paint_brush(&scene->toolsettings->sculpt->paint);
+                               brush= paint_brush(&scene->toolsettings->sculpt->paint);
+                       }
+                       else
+                               brush= paint_brush(&scene->toolsettings->imapaint.paint);
+
+                       if(brush) {
                                if(brush && brush->texact != -1)
                                        mtex= brush->mtex[brush->texact];
                        }
-                       else {
-                               Brush *br= scene->toolsettings->imapaint.brush;
-                               if(br) 
-                                       mtex= br->mtex[br->texact];
-                       }
                        
                        if(mtex) {
                                snode->from= (ID *)scene;
index 28eddeb6f2e349e58363195b4319c6194784069a..f00813b58f1d4576d7d3ddb2744a0925f7a4ec86 100644 (file)
@@ -429,8 +429,18 @@ typedef struct TimeMarker {
        unsigned int flag;
 } TimeMarker;
 
+typedef struct Paint {
+       /* Array of brushes selected for use in this paint mode */
+       Brush **brushes;
+       int active_brush_index, brush_count;
+       
+       /* WM handle */
+       void *paint_cursor;
+} Paint;
+
 typedef struct ImagePaintSettings {
-       struct Brush *brush;
+       Paint paint;
+
        short flag, tool;
        
        /* for projection painting only */
@@ -465,15 +475,6 @@ typedef struct TransformOrientation {
        float mat[3][3];
 } TransformOrientation;
 
-typedef struct Paint {
-       /* Array of brushes selected for use in this paint mode */
-       Brush **brushes;
-       int active_brush_index, brush_count;
-       
-       /* WM handle */
-       void *paint_cursor;
-} Paint;
-
 typedef struct Sculpt {
        Paint paint;
        
index f3b970c765964bb149f2d790347ba3fa45b9f7a6..c2c906e38f2694c663594cec52e867b395a92a54 100644 (file)
@@ -204,14 +204,10 @@ static void rna_def_image_paint(BlenderRNA *brna)
                {PAINT_TOOL_CLONE, "CLONE", 0, "Clone", ""},
                {0, NULL, 0, NULL, NULL}};
        
-       srna= RNA_def_struct(brna, "ImagePaint", NULL);
+       srna= RNA_def_struct(brna, "ImagePaint", "Paint");
        RNA_def_struct_sdna(srna, "ImagePaintSettings");
        RNA_def_struct_ui_text(srna, "Image Paint", "Properties of image and texture painting mode.");
  
-       prop= RNA_def_property(srna, "brush", PROP_POINTER, PROP_NONE);
-       RNA_def_property_struct_type(prop, "Brush");
-       RNA_def_property_ui_text(prop, "Brush", "");
-   
        prop= RNA_def_property(srna, "tool", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_items(prop, tool_items);
        RNA_def_property_ui_text(prop, "Tool", "");
index 24337c0fc7056c0753472cb962e886e1565b41bb..6ecf533e39df00faec5982407049fa80320baa08 100644 (file)
@@ -37,6 +37,8 @@
 #include "DNA_space_types.h"
 #include "DNA_view3d_types.h"
 
+#include "BKE_paint.h"
+
 #include "WM_types.h"
 
 EnumPropertyItem space_type_items[] = {
@@ -145,7 +147,7 @@ static void rna_SpaceImageEditor_paint_update(bContext *C, PointerRNA *ptr)
        Scene *scene= CTX_data_scene(C);
 
        if(scene)
-               brush_check_exists(&scene->toolsettings->imapaint.brush, "Brush");
+               paint_init(&scene->toolsettings->imapaint.paint, "Brush");
 }
 
 static int rna_SpaceImageEditor_show_render_get(PointerRNA *ptr)