Sculpt+Paint/2.5:
[blender-staging.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
48         if(CTX_data_dir(member)) {
49                 static const char *dir[] = {
50                         "scene", "selected_objects", "selected_bases",
51                         "selected_editable_objects", "selected_editable_bases"
52                         "active_base", "active_object", "edit_object",
53                         "sculpt_object", "vpaint_object", "wpaint_object", NULL};
54
55                 CTX_data_dir_set(result, dir);
56                 return 1;
57         }
58         else if(CTX_data_equals(member, "scene")) {
59                 CTX_data_id_pointer_set(result, &scene->id);
60                 return 1;
61         }
62         else if(CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) {
63                 int selected_objects= CTX_data_equals(member, "selected_objects");
64
65                 for(base=scene->base.first; base; base=base->next) {
66                         if((base->flag & SELECT) && (base->lay & scene->lay)) {
67                                 if(selected_objects)
68                                         CTX_data_id_list_add(result, &base->object->id);
69                                 else
70                                         CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base);
71                         }
72                 }
73
74                 return 1;
75         }
76         else if(CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) {
77                 int selected_editable_objects= CTX_data_equals(member, "selected_editable_objects");
78
79                 for(base=scene->base.first; base; base=base->next) {
80                         if((base->flag & SELECT) && (base->lay & scene->lay)) {
81                                 if((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
82                                         if(0==object_is_libdata(base->object)) {
83                                                 if(selected_editable_objects)
84                                                         CTX_data_id_list_add(result, &base->object->id);
85                                                 else
86                                                         CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base);
87                                         }
88                                 }
89                         }
90                 }
91
92                 return 1;
93         }
94         else if(CTX_data_equals(member, "active_base")) {
95                 if(scene->basact)
96                         CTX_data_pointer_set(result, &scene->id, &RNA_UnknownType, &scene->basact);
97
98                 return 1;
99         }
100         else if(CTX_data_equals(member, "active_object")) {
101                 if(scene->basact)
102                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
103
104                 return 1;
105         }
106         else if(CTX_data_equals(member, "edit_object")) {
107                 /* convenience for now, 1 object per scene in editmode */
108                 if(scene->obedit)
109                         CTX_data_id_pointer_set(result, &scene->obedit->id);
110                 
111                 return 1;
112         }
113         else if(CTX_data_equals(member, "sculpt_object")) {
114                 if(G.f & G_SCULPTMODE && scene->basact)
115                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
116
117                 return 1;
118         }
119         else if(CTX_data_equals(member, "vpaint_object")) {
120                 if(G.f & G_VERTEXPAINT && scene->basact)
121                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
122
123                 return 1;
124         }
125         else if(CTX_data_equals(member, "wpaint_object")) {
126                 if(G.f & G_WEIGHTPAINT && scene->basact)
127                         CTX_data_id_pointer_set(result, &scene->basact->object->id);
128
129                 return 1;
130         }
131         
132         return 0;
133 }
134