Blender  V2.59
paint.c
Go to the documentation of this file.
00001 /*
00002  * $Id: paint.c 37839 2011-06-27 04:05:19Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software  Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2009 by Nicholas Bishop
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00036 #include "DNA_object_types.h"
00037 #include "DNA_mesh_types.h"
00038 #include "DNA_scene_types.h"
00039 #include "DNA_brush_types.h"
00040 
00041 #include "BLI_utildefines.h"
00042 
00043 
00044 #include "BKE_brush.h"
00045 #include "BKE_library.h"
00046 #include "BKE_paint.h"
00047 
00048 #include <stdlib.h>
00049 #include <string.h>
00050 
00051 const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100};
00052 const char PAINT_CURSOR_VERTEX_PAINT[3] = {255, 255, 255};
00053 const char PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255};
00054 const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255};
00055 
00056 Paint *paint_get_active(Scene *sce)
00057 {
00058         if(sce) {
00059                 ToolSettings *ts = sce->toolsettings;
00060                 
00061                 if(sce->basact && sce->basact->object) {
00062                         switch(sce->basact->object->mode) {
00063                         case OB_MODE_SCULPT:
00064                                 return &ts->sculpt->paint;
00065                         case OB_MODE_VERTEX_PAINT:
00066                                 return &ts->vpaint->paint;
00067                         case OB_MODE_WEIGHT_PAINT:
00068                                 return &ts->wpaint->paint;
00069                         case OB_MODE_TEXTURE_PAINT:
00070                                 return &ts->imapaint.paint;
00071                         }
00072                 }
00073 
00074                 /* default to image paint */
00075                 return &ts->imapaint.paint;
00076         }
00077 
00078         return NULL;
00079 }
00080 
00081 Brush *paint_brush(Paint *p)
00082 {
00083         return p ? p->brush : NULL;
00084 }
00085 
00086 void paint_brush_set(Paint *p, Brush *br)
00087 {
00088         if(p) {
00089                 id_us_min((ID *)p->brush);
00090                 id_us_plus((ID *)br);
00091                 p->brush= br;
00092         }
00093 }
00094 
00095 int paint_facesel_test(Object *ob)
00096 {
00097         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)));
00098 }
00099 
00100 void paint_init(Paint *p, const char col[3])
00101 {
00102         Brush *brush;
00103 
00104         /* If there's no brush, create one */
00105         brush = paint_brush(p);
00106         if(brush == NULL)
00107                 brush= add_brush("Brush");
00108         paint_brush_set(p, brush);
00109 
00110         memcpy(p->paint_cursor_col, col, 3);
00111         p->paint_cursor_col[3] = 128;
00112 
00113         p->flags |= PAINT_SHOW_BRUSH;
00114 }
00115 
00116 void free_paint(Paint *paint)
00117 {
00118         id_us_min((ID *)paint->brush);
00119 }
00120 
00121 /* called when copying scene settings, so even if 'src' and 'tar' are the same
00122  * still do a id_us_plus(), rather then if we were copying betweem 2 existing
00123  * scenes where a matching value should decrease the existing user count as
00124  * with paint_brush_set() */
00125 void copy_paint(Paint *src, Paint *tar)
00126 {
00127         tar->brush= src->brush;
00128         id_us_plus((ID *)tar->brush);
00129 }