Blender V2.61 - r43446

paint.c

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