Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/screen/screen_context.c
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_armature.h" | #include "BKE_armature.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_layer.h" | |||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_sequencer.h" | #include "BKE_sequencer.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "ED_gpencil.h" | #include "ED_gpencil.h" | ||||
| Show All 10 Lines | if (sc && sa_ctx && (sa_ctx->spacetype == SPACE_BUTS)) { | ||||
| if (lay) { | if (lay) { | ||||
| return lay; | return lay; | ||||
| } | } | ||||
| } | } | ||||
| return scene->lay; | return scene->lay; | ||||
| } | } | ||||
| const char *screen_context_dir[] = { | const char *screen_context_dir[] = { | ||||
| "scene", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases", | "scene", "render_layer", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases", | ||||
| "selected_objects", "selected_bases", | "selected_objects", "selected_bases", | ||||
| "editable_objects", "editable_bases", | "editable_objects", "editable_bases", | ||||
| "selected_editable_objects", "selected_editable_bases", | "selected_editable_objects", "selected_editable_bases", | ||||
| "visible_bones", "editable_bones", "selected_bones", "selected_editable_bones", | "visible_bones", "editable_bones", "selected_bones", "selected_editable_bones", | ||||
| "visible_pose_bones", "selected_pose_bones", "active_bone", "active_pose_bone", | "visible_pose_bones", "selected_pose_bones", "active_bone", "active_pose_bone", | ||||
| "active_base", "active_object", "object", "edit_object", | "active_base", "active_object", "object", "edit_object", | ||||
| "sculpt_object", "vertex_paint_object", "weight_paint_object", | "sculpt_object", "vertex_paint_object", "weight_paint_object", | ||||
| "image_paint_object", "particle_edit_object", | "image_paint_object", "particle_edit_object", | ||||
| "sequences", "selected_sequences", "selected_editable_sequences", /* sequencer */ | "sequences", "selected_sequences", "selected_editable_sequences", /* sequencer */ | ||||
| "gpencil_data", "gpencil_data_owner", /* grease pencil data */ | "gpencil_data", "gpencil_data_owner", /* grease pencil data */ | ||||
| "visible_gpencil_layers", "editable_gpencil_layers", "editable_gpencil_strokes", | "visible_gpencil_layers", "editable_gpencil_layers", "editable_gpencil_strokes", | ||||
| "active_gpencil_layer", "active_gpencil_frame", "active_gpencil_palette", | "active_gpencil_layer", "active_gpencil_frame", "active_gpencil_palette", | ||||
| "active_gpencil_palettecolor", "active_gpencil_brush", | "active_gpencil_palettecolor", "active_gpencil_brush", | ||||
| "active_operator", | "active_operator", | ||||
| NULL}; | NULL}; | ||||
| int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result) | int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result) | ||||
| { | { | ||||
| bScreen *sc = CTX_wm_screen(C); | bScreen *sc = CTX_wm_screen(C); | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| Scene *scene = sc->scene; | Scene *scene = sc->scene; | ||||
| Base *base; | SceneLayer *sl = CTX_data_scene_layer(C); | ||||
| #if 0 /* Using the context breaks adding objects in the UI. Need to find out why - campbell */ | |||||
| Object *obact = CTX_data_active_object(C); | |||||
| Object *obedit = CTX_data_edit_object(C); | |||||
| base = CTX_data_active_base(C); | |||||
| #else | |||||
| Object *obedit = scene->obedit; | Object *obedit = scene->obedit; | ||||
| Object *obact = OBACT; | Object *obact = sl->basact ? sl->basact->object : NULL; | ||||
| base = BASACT; | |||||
| #endif | |||||
| if (CTX_data_dir(member)) { | if (CTX_data_dir(member)) { | ||||
| CTX_data_dir_set(result, screen_context_dir); | CTX_data_dir_set(result, screen_context_dir); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "scene")) { | else if (CTX_data_equals(member, "scene")) { | ||||
| CTX_data_id_pointer_set(result, &scene->id); | CTX_data_id_pointer_set(result, &scene->id); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "visible_objects") || CTX_data_equals(member, "visible_bases")) { | else if (CTX_data_equals(member, "visible_objects")) { | ||||
| for (ObjectBase *base = sl->object_bases.first; base; base = base->next) { | |||||
| if (((base->object->restrictflag & OB_RESTRICT_VIEW) == 0)) { | |||||
| CTX_data_id_list_add(result, &base->object->id); | |||||
| } | |||||
| } | |||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | |||||
| return 1; | |||||
| } | |||||
| else if (CTX_data_equals(member, "selectable_objects")) { | |||||
| for (ObjectBase *base = sl->object_bases.first; base; base = base->next) { | |||||
| if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0 && (base->object->restrictflag & OB_RESTRICT_SELECT) == 0) { | |||||
| CTX_data_id_list_add(result, &base->object->id); | |||||
| } | |||||
| } | |||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | |||||
| return 1; | |||||
| } | |||||
| else if (CTX_data_equals(member, "selected_objects")) { | |||||
| Object *ob; | |||||
| FOREACH_SELECTED_OBJECT(sl, ob) | |||||
| { | |||||
| CTX_data_id_list_add(result, &ob->id); | |||||
| } | |||||
| FOREACH_SELECTED_OBJECT_END | |||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | |||||
| return 1; | |||||
| } | |||||
| else if (CTX_data_equals(member, "selected_editable_objects")) { | |||||
| Object *ob; | |||||
| FOREACH_SELECTED_OBJECT(sl, ob) | |||||
| { | |||||
| if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0) { | |||||
| if (0 == BKE_object_is_libdata(ob)) { | |||||
| CTX_data_id_list_add(result, &ob->id); | |||||
| } | |||||
| } | |||||
| } | |||||
| FOREACH_SELECTED_OBJECT_END | |||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | |||||
| return 1; | |||||
| } | |||||
| else if (CTX_data_equals(member, "editable_objects")) { | |||||
| /* Visible + Editable, but not necessarily selected */ | |||||
| for (ObjectBase *base = sl->object_bases.first; base; base = base->next) { | |||||
| if (((base->object->restrictflag & OB_RESTRICT_VIEW) == 0)) { | |||||
| if (0 == BKE_object_is_libdata(base->object)) { | |||||
| CTX_data_id_list_add(result, &base->object->id); | |||||
| } | |||||
| } | |||||
| } | |||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | |||||
| return 1; | |||||
| } | |||||
| else if ( CTX_data_equals(member, "visible_bases")) { | |||||
| const unsigned int lay = context_layers(sc, scene, sa); | const unsigned int lay = context_layers(sc, scene, sa); | ||||
| const bool visible_objects = CTX_data_equals(member, "visible_objects"); | |||||
| for (base = scene->base.first; base; base = base->next) { | for (Base *base = scene->base.first; base; base = base->next) { | ||||
| if (((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) && (base->lay & lay)) { | if (((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) && (base->lay & lay)) { | ||||
| if (visible_objects) | |||||
| CTX_data_id_list_add(result, &base->object->id); | |||||
| else | |||||
| CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "selectable_objects") || CTX_data_equals(member, "selectable_bases")) { | else if (CTX_data_equals(member, "selectable_bases")) { | ||||
| const unsigned int lay = context_layers(sc, scene, sa); | const unsigned int lay = context_layers(sc, scene, sa); | ||||
| const bool selectable_objects = CTX_data_equals(member, "selectable_objects"); | |||||
| for (base = scene->base.first; base; base = base->next) { | for (Base *base = scene->base.first; base; base = base->next) { | ||||
| if (base->lay & lay) { | if (base->lay & lay) { | ||||
| if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0 && (base->object->restrictflag & OB_RESTRICT_SELECT) == 0) { | if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0 && (base->object->restrictflag & OB_RESTRICT_SELECT) == 0) { | ||||
| if (selectable_objects) | |||||
| CTX_data_id_list_add(result, &base->object->id); | |||||
| else | |||||
| CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) { | else if (CTX_data_equals(member, "selected_bases")) { | ||||
| const unsigned int lay = context_layers(sc, scene, sa); | const unsigned int lay = context_layers(sc, scene, sa); | ||||
| const bool selected_objects = CTX_data_equals(member, "selected_objects"); | |||||
| for (base = scene->base.first; base; base = base->next) { | for (Base *base = scene->base.first; base; base = base->next) { | ||||
| if ((base->flag & SELECT) && (base->lay & lay)) { | if ((base->flag & SELECT) && (base->lay & lay)) { | ||||
| if (selected_objects) | |||||
| CTX_data_id_list_add(result, &base->object->id); | |||||
| else | |||||
| CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) { | else if (CTX_data_equals(member, "selected_editable_bases")) { | ||||
| const unsigned int lay = context_layers(sc, scene, sa); | const unsigned int lay = context_layers(sc, scene, sa); | ||||
| const bool selected_editable_objects = CTX_data_equals(member, "selected_editable_objects"); | |||||
| for (base = scene->base.first; base; base = base->next) { | for (Base *base = scene->base.first; base; base = base->next) { | ||||
| if ((base->flag & SELECT) && (base->lay & lay)) { | if ((base->flag & SELECT) && (base->lay & lay)) { | ||||
| if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) { | if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) { | ||||
| if (0 == BKE_object_is_libdata(base->object)) { | if (0 == BKE_object_is_libdata(base->object)) { | ||||
| if (selected_editable_objects) | |||||
| CTX_data_id_list_add(result, &base->object->id); | |||||
| else | |||||
| CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "editable_objects") || CTX_data_equals(member, "editable_bases")) { | else if (CTX_data_equals(member, "editable_bases")) { | ||||
| const unsigned int lay = context_layers(sc, scene, sa); | const unsigned int lay = context_layers(sc, scene, sa); | ||||
| const bool editable_objects = CTX_data_equals(member, "editable_objects"); | |||||
| /* Visible + Editable, but not necessarily selected */ | /* Visible + Editable, but not necessarily selected */ | ||||
| for (base = scene->base.first; base; base = base->next) { | for (Base *base = scene->base.first; base; base = base->next) { | ||||
| if (((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) && (base->lay & lay)) { | if (((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) && (base->lay & lay)) { | ||||
| if (0 == BKE_object_is_libdata(base->object)) { | if (0 == BKE_object_is_libdata(base->object)) { | ||||
| if (editable_objects) | |||||
| CTX_data_id_list_add(result, &base->object->id); | |||||
| else | |||||
| CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "visible_bones") || CTX_data_equals(member, "editable_bones")) { | else if (CTX_data_equals(member, "visible_bones") || CTX_data_equals(member, "editable_bones")) { | ||||
| bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL; | bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL; | ||||
| ▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | else if (CTX_data_equals(member, "active_pose_bone")) { | ||||
| pchan = BKE_pose_channel_active(obpose); | pchan = BKE_pose_channel_active(obpose); | ||||
| if (pchan) { | if (pchan) { | ||||
| CTX_data_pointer_set(result, &obpose->id, &RNA_PoseBone, pchan); | CTX_data_pointer_set(result, &obpose->id, &RNA_PoseBone, pchan); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "active_base")) { | else if (CTX_data_equals(member, "active_base")) { | ||||
| if (base) | if (sl->basact) | ||||
| CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, base); | CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, sl->basact); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "active_object")) { | else if (CTX_data_equals(member, "active_object")) { | ||||
| if (obact) | if (obact) | ||||
| CTX_data_id_pointer_set(result, &obact->id); | CTX_data_id_pointer_set(result, &obact->id); | ||||
| return 1; | return 1; | ||||
| ▲ Show 20 Lines • Show All 261 Lines • Show Last 20 Lines | |||||