e53888127f2012e9d3bfe96e9759b2825432c4f9
[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
31 #include "DNA_object_types.h"
32 #include "DNA_mesh_types.h"
33 #include "DNA_scene_types.h"
34 #include "DNA_brush_types.h"
35
36 #include "BLI_utildefines.h"
37
38
39 #include "BKE_brush.h"
40 #include "BKE_library.h"
41 #include "BKE_paint.h"
42
43 #include <stdlib.h>
44 #include <string.h>
45
46 const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100};
47 const char PAINT_CURSOR_VERTEX_PAINT[3] = {255, 255, 255};
48 const char PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255};
49 const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255};
50
51 Paint *paint_get_active(Scene *sce)
52 {
53         if(sce) {
54                 ToolSettings *ts = sce->toolsettings;
55                 
56                 if(sce->basact && sce->basact->object) {
57                         switch(sce->basact->object->mode) {
58                         case OB_MODE_SCULPT:
59                                 return &ts->sculpt->paint;
60                         case OB_MODE_VERTEX_PAINT:
61                                 return &ts->vpaint->paint;
62                         case OB_MODE_WEIGHT_PAINT:
63                                 return &ts->wpaint->paint;
64                         case OB_MODE_TEXTURE_PAINT:
65                                 return &ts->imapaint.paint;
66                         }
67                 }
68
69                 /* default to image paint */
70                 return &ts->imapaint.paint;
71         }
72
73         return NULL;
74 }
75
76 Brush *paint_brush(Paint *p)
77 {
78         return p ? p->brush : NULL;
79 }
80
81 void paint_brush_set(Paint *p, Brush *br)
82 {
83         if(p)
84                 p->brush= br;
85 }
86
87 int paint_facesel_test(Object *ob)
88 {
89         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)));
90 }
91
92 void paint_init(Paint *p, const char col[3])
93 {
94         Brush *brush;
95
96         /* If there's no brush, create one */
97         brush = paint_brush(p);
98         if(brush == NULL)
99                 brush= add_brush("Brush");
100         paint_brush_set(p, brush);
101
102         memcpy(p->paint_cursor_col, col, 3);
103         p->paint_cursor_col[3] = 128;
104
105         p->flags |= PAINT_SHOW_BRUSH;
106 }
107
108 void free_paint(Paint *UNUSED(paint))
109 {
110         /* nothing */
111 }
112
113 void copy_paint(Paint *src, Paint *tar)
114 {
115         tar->brush= src->brush;
116 }