svn merge -r37793:37865 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / blenkernel / intern / paint.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software  Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2009 by Nicholas Bishop
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 /** \file blender/blenkernel/intern/paint.c
31  *  \ingroup bke
32  */
33
34
35
36 #include "DNA_object_types.h"
37 #include "DNA_mesh_types.h"
38 #include "DNA_scene_types.h"
39 #include "DNA_brush_types.h"
40
41 #include "BLI_utildefines.h"
42
43
44 #include "BKE_brush.h"
45 #include "BKE_library.h"
46 #include "BKE_paint.h"
47
48 #include <stdlib.h>
49 #include <string.h>
50
51 const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100};
52 const char PAINT_CURSOR_VERTEX_PAINT[3] = {255, 255, 255};
53 const char PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255};
54 const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255};
55
56 Paint *paint_get_active(Scene *sce)
57 {
58         if(sce) {
59                 ToolSettings *ts = sce->toolsettings;
60                 
61                 if(sce->basact && sce->basact->object) {
62                         switch(sce->basact->object->mode) {
63                         case OB_MODE_SCULPT:
64                                 return &ts->sculpt->paint;
65                         case OB_MODE_VERTEX_PAINT:
66                                 return &ts->vpaint->paint;
67                         case OB_MODE_WEIGHT_PAINT:
68                                 return &ts->wpaint->paint;
69                         case OB_MODE_TEXTURE_PAINT:
70                                 return &ts->imapaint.paint;
71                         }
72                 }
73
74                 /* default to image paint */
75                 return &ts->imapaint.paint;
76         }
77
78         return NULL;
79 }
80
81 Brush *paint_brush(Paint *p)
82 {
83         return p ? p->brush : NULL;
84 }
85
86 void paint_brush_set(Paint *p, Brush *br)
87 {
88         if(p) {
89                 id_us_min((ID *)p->brush);
90                 id_us_plus((ID *)br);
91                 p->brush= br;
92         }
93 }
94
95 int paint_facesel_test(Object *ob)
96 {
97         return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_MASK) && (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)));
98 }
99 /* Jason */
100 int paint_vertsel_test(Object *ob)
101 {
102         return (ob && ob->type==OB_MESH && ob->data && (((Mesh *)ob->data)->editflag & ME_EDIT_VERT_SEL) && (ob->mode & (OB_MODE_WEIGHT_PAINT)));
103 }
104 void paint_init(Paint *p, const char col[3])
105 {
106         Brush *brush;
107
108         /* If there's no brush, create one */
109         brush = paint_brush(p);
110         if(brush == NULL)
111                 brush= add_brush("Brush");
112         paint_brush_set(p, brush);
113
114         memcpy(p->paint_cursor_col, col, 3);
115         p->paint_cursor_col[3] = 128;
116
117         p->flags |= PAINT_SHOW_BRUSH;
118 }
119
120 void free_paint(Paint *paint)
121 {
122         id_us_min((ID *)paint->brush);
123 }
124
125 /* called when copying scene settings, so even if 'src' and 'tar' are the same
126  * still do a id_us_plus(), rather then if we were copying betweem 2 existing
127  * scenes where a matching value should decrease the existing user count as
128  * with paint_brush_set() */
129 void copy_paint(Paint *src, Paint *tar)
130 {
131         tar->brush= src->brush;
132         id_us_plus((ID *)tar->brush);
133 }