2.5/Vertex paint:
[blender.git] / source / blender / editors / screen / screen_context.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "DNA_object_types.h"
31 #include "DNA_scene_types.h"
32 #include "DNA_screen_types.h"
33
34 #include "BKE_context.h"
35 #include "BKE_utildefines.h"
36 #include "BKE_global.h"
37
38 #include "RNA_access.h"
39
40 #include "ED_object.h"
41
42 int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
43 {
44         bScreen *sc= CTX_wm_screen(C);
45         Scene *scene= sc->scene;
46         Base *base;
47         Object *ob = NULL;
48
49         if(scene && scene->basact)
50                 ob = scene->basact->object;
51
52         if(CTX_data_dir(member)) {
53                 static const char *dir[] = {
54                         "scene", "selected_objects", "selected_bases",
55                         "selected_editable_objects", "selected_editable_bases"
56                         "active_base", "active_object", "edit_object",
57                         "sculpt_object", "vertex_paint_object", "weight_paint_object",
58                         "texture_paint_object", "brush", "particle_edit_object", NULL};
59
60                 CTX_data_dir_set(result, dir);
61                 return 1;
62         }
63         else if(CTX_data_equals(member, "scene")) {
64                 CTX_data_id_pointer_set(result, &scene->id);
65                 return 1;
66         }
67         else if(CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) {
68                 int selected_objects= CTX_data_equals(member, "selected_objects");
69
70                 for(base=scene->base.first; base; base=base->next) {
71                         if((base->flag & SELECT) && (base->lay & scene->lay)) {
72                                 if(selected_objects)
73                                         CTX_data_id_list_add(result, &base->object->id);
74                                 else
75                                         CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base);
76                         }
77                 }
78
79                 return 1;
80         }
81         else if(CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) {
82                 int selected_editable_objects= CTX_data_equals(member, "selected_editable_objects");
83
84                 for(base=scene->base.first; base; base=base->next) {
85                         if((base->flag & SELECT) && (base->lay & scene->lay)) {
86                                 if((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
87                                         if(0==object_is_libdata(base->object)) {
88                                                 if(selected_editable_objects)
89                                                         CTX_data_id_list_add(result, &base->object->id);
90                                                 else
91                                                         CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base);
92                                         }
93                                 }
94                         }
95                 }
96
97                 return 1;
98         }
99         else if(CTX_data_equals(member, "active_base")) {
100                 if(scene->basact)
101                         CTX_data_pointer_set(result, &scene->id, &RNA_UnknownType, scene->basact);
102
103                 return 1;
104         }
105         else if(CTX_data_equals(member, "active_object")) {
106                 if(scene->basact)
107                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
108
109                 return 1;
110         }
111         else if(CTX_data_equals(member, "edit_object")) {
112                 /* convenience for now, 1 object per scene in editmode */
113                 if(scene->obedit)
114                         CTX_data_id_pointer_set(result, &scene->obedit->id);
115                 
116                 return 1;
117         }
118         else if(CTX_data_equals(member, "sculpt_object")) {
119                 if(ob && (ob->mode & OB_MODE_SCULPT))
120                         CTX_data_id_pointer_set(result, &ob->id);
121
122                 return 1;
123         }
124         else if(CTX_data_equals(member, "vertex_paint_object")) {
125                 if(ob && (ob->mode & OB_MODE_VERTEX_PAINT))
126                         CTX_data_id_pointer_set(result, &ob->id);
127
128                 return 1;
129         }
130         else if(CTX_data_equals(member, "weight_paint_object")) {
131                 if(G.f & G_WEIGHTPAINT && scene->basact)
132                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
133
134                 return 1;
135         }
136         else if(CTX_data_equals(member, "texture_paint_object")) {
137                 if(G.f & G_TEXTUREPAINT && scene->basact)
138                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
139
140                 return 1;
141         }
142         else if(CTX_data_equals(member, "particle_edit_object")) {
143                 if(G.f & G_PARTICLEEDIT && scene->basact)
144                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
145
146                 return 1;
147         }
148
149         return 0;
150 }
151