Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/screen/screen_context.c
| Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | const char *screen_context_dir[] = { | ||||
| "selected_visible_fcurves", | "selected_visible_fcurves", | ||||
| "selected_editable_fcurves", | "selected_editable_fcurves", | ||||
| "active_editable_fcurve", | "active_editable_fcurve", | ||||
| NULL, | NULL, | ||||
| }; | }; | ||||
| /* Each function `screen_ctx_XXX()` will be called when the screen context "XXX" is requested. | /* Each function `screen_ctx_XXX()` will be called when the screen context "XXX" is requested. | ||||
| * ensure_ed_screen_context_functions() is responsible for creating the hash map from context | * ensure_ed_screen_context_functions() is responsible for creating the hash map from context | ||||
| * member name to function. | * member name to function. */ | ||||
| * | |||||
| * Each function returns: | |||||
| * 1 for "the member name was found and returned data is valid" | |||||
| * 0 for "the member name was not found" | |||||
| * -1 for "the member name was found but data is not available" | |||||
| * | |||||
| * */ | |||||
| static int screen_ctx_scene(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_scene(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| CTX_data_id_pointer_set(result, &scene->id); | CTX_data_id_pointer_set(result, &scene->id); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_visible_objects(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_visible_objects(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | ||||
| if (BASE_VISIBLE(v3d, base)) { | if (BASE_VISIBLE(v3d, base)) { | ||||
| CTX_data_id_list_add(result, &base->object->id); | CTX_data_id_list_add(result, &base->object->id); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_selectable_objects(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selectable_objects(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | ||||
| if (BASE_SELECTABLE(v3d, base)) { | if (BASE_SELECTABLE(v3d, base)) { | ||||
| CTX_data_id_list_add(result, &base->object->id); | CTX_data_id_list_add(result, &base->object->id); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_selected_objects(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selected_objects(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | ||||
| if (BASE_SELECTED(v3d, base)) { | if (BASE_SELECTED(v3d, base)) { | ||||
| CTX_data_id_list_add(result, &base->object->id); | CTX_data_id_list_add(result, &base->object->id); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_selected_editable_objects(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selected_editable_objects(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | ||||
| if (BASE_SELECTED_EDITABLE(v3d, base)) { | if (BASE_SELECTED_EDITABLE(v3d, base)) { | ||||
| CTX_data_id_list_add(result, &base->object->id); | CTX_data_id_list_add(result, &base->object->id); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_editable_objects(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_editable_objects(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| /* Visible + Editable, but not necessarily selected */ | /* Visible + Editable, but not necessarily selected */ | ||||
| LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { | ||||
| if (BASE_EDITABLE(v3d, base)) { | if (BASE_EDITABLE(v3d, base)) { | ||||
| CTX_data_id_list_add(result, &base->object->id); | CTX_data_id_list_add(result, &base->object->id); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_objects_in_mode(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_objects_in_mode(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| if (obact && (obact->mode != OB_MODE_OBJECT)) { | if (obact && (obact->mode != OB_MODE_OBJECT)) { | ||||
| FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) { | FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) { | ||||
| CTX_data_id_list_add(result, &ob_iter->id); | CTX_data_id_list_add(result, &ob_iter->id); | ||||
| } | } | ||||
| FOREACH_OBJECT_IN_MODE_END; | FOREACH_OBJECT_IN_MODE_END; | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_objects_in_mode_unique_data(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_objects_in_mode_unique_data(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| if (obact && (obact->mode != OB_MODE_OBJECT)) { | if (obact && (obact->mode != OB_MODE_OBJECT)) { | ||||
| FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) { | FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) { | ||||
| ob_iter->id.tag |= LIB_TAG_DOIT; | ob_iter->id.tag |= LIB_TAG_DOIT; | ||||
| } | } | ||||
| FOREACH_OBJECT_IN_MODE_END; | FOREACH_OBJECT_IN_MODE_END; | ||||
| FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) { | FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) { | ||||
| if (ob_iter->id.tag & LIB_TAG_DOIT) { | if (ob_iter->id.tag & LIB_TAG_DOIT) { | ||||
| ob_iter->id.tag &= ~LIB_TAG_DOIT; | ob_iter->id.tag &= ~LIB_TAG_DOIT; | ||||
| CTX_data_id_list_add(result, &ob_iter->id); | CTX_data_id_list_add(result, &ob_iter->id); | ||||
| } | } | ||||
| } | } | ||||
| FOREACH_OBJECT_IN_MODE_END; | FOREACH_OBJECT_IN_MODE_END; | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_visible_or_editable_bones_(const bContext *C, | static eContextResult screen_ctx_visible_or_editable_bones_(const bContext *C, | ||||
| bContextDataResult *result, | bContextDataResult *result, | ||||
| const bool editable_bones) | const bool editable_bones) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); | Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); | ||||
| bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL; | bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL; | ||||
| EditBone *flipbone = NULL; | EditBone *flipbone = NULL; | ||||
| Show All 40 Lines | for (uint i = 0; i < objects_len; i++) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| MEM_freeN(objects); | MEM_freeN(objects); | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_visible_bones(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_visible_bones(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| return screen_ctx_visible_or_editable_bones_(C, result, false); | return screen_ctx_visible_or_editable_bones_(C, result, false); | ||||
| } | } | ||||
| static int screen_ctx_editable_bones(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_editable_bones(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| return screen_ctx_visible_or_editable_bones_(C, result, true); | return screen_ctx_visible_or_editable_bones_(C, result, true); | ||||
| } | } | ||||
| static int screen_ctx_selected_bones_(const bContext *C, | static eContextResult screen_ctx_selected_bones_(const bContext *C, | ||||
| bContextDataResult *result, | bContextDataResult *result, | ||||
| const bool selected_editable_bones) | const bool selected_editable_bones) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); | Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); | ||||
| bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL; | bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL; | ||||
| EditBone *flipbone = NULL; | EditBone *flipbone = NULL; | ||||
| if (arm && arm->edbo) { | if (arm && arm->edbo) { | ||||
| Show All 39 Lines | for (uint i = 0; i < objects_len; i++) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| MEM_freeN(objects); | MEM_freeN(objects); | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_selected_bones(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selected_bones(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| return screen_ctx_selected_bones_(C, result, false); | return screen_ctx_selected_bones_(C, result, false); | ||||
| } | } | ||||
| static int screen_ctx_selected_editable_bones(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selected_editable_bones(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| return screen_ctx_selected_bones_(C, result, true); | return screen_ctx_selected_bones_(C, result, true); | ||||
| } | } | ||||
| static int screen_ctx_visible_pose_bones(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_visible_pose_bones(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| Object *obpose = BKE_object_pose_armature_get(obact); | Object *obpose = BKE_object_pose_armature_get(obact); | ||||
| if (obpose && obpose->pose && obpose->data) { | if (obpose && obpose->pose && obpose->data) { | ||||
| if (obpose != obact) { | if (obpose != obact) { | ||||
| FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (obpose, pchan) { | FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (obpose, pchan) { | ||||
| CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan); | CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan); | ||||
| } | } | ||||
| FOREACH_PCHAN_SELECTED_IN_OBJECT_END; | FOREACH_PCHAN_SELECTED_IN_OBJECT_END; | ||||
| } | } | ||||
| else if (obact->mode & OB_MODE_POSE) { | else if (obact->mode & OB_MODE_POSE) { | ||||
| FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob_iter) { | FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob_iter) { | ||||
| FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (ob_iter, pchan) { | FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (ob_iter, pchan) { | ||||
| CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan); | CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan); | ||||
| } | } | ||||
| FOREACH_PCHAN_VISIBLE_IN_OBJECT_END; | FOREACH_PCHAN_VISIBLE_IN_OBJECT_END; | ||||
| } | } | ||||
| FOREACH_OBJECT_IN_MODE_END; | FOREACH_OBJECT_IN_MODE_END; | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_selected_pose_bones(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selected_pose_bones(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | View3D *v3d = CTX_wm_view3d(C); /* This may be NULL in a lot of cases. */ | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| Object *obpose = BKE_object_pose_armature_get(obact); | Object *obpose = BKE_object_pose_armature_get(obact); | ||||
| if (obpose && obpose->pose && obpose->data) { | if (obpose && obpose->pose && obpose->data) { | ||||
| if (obpose != obact) { | if (obpose != obact) { | ||||
| FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obpose, pchan) { | FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obpose, pchan) { | ||||
| CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan); | CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan); | ||||
| } | } | ||||
| FOREACH_PCHAN_SELECTED_IN_OBJECT_END; | FOREACH_PCHAN_SELECTED_IN_OBJECT_END; | ||||
| } | } | ||||
| else if (obact->mode & OB_MODE_POSE) { | else if (obact->mode & OB_MODE_POSE) { | ||||
| FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob_iter) { | FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob_iter) { | ||||
| FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob_iter, pchan) { | FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob_iter, pchan) { | ||||
| CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan); | CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan); | ||||
| } | } | ||||
| FOREACH_PCHAN_SELECTED_IN_OBJECT_END; | FOREACH_PCHAN_SELECTED_IN_OBJECT_END; | ||||
| } | } | ||||
| FOREACH_OBJECT_IN_MODE_END; | FOREACH_OBJECT_IN_MODE_END; | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_selected_pose_bones_from_active_object(const bContext *C, | static eContextResult screen_ctx_selected_pose_bones_from_active_object(const bContext *C, | ||||
| bContextDataResult *result) | bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| Object *obpose = BKE_object_pose_armature_get(obact); | Object *obpose = BKE_object_pose_armature_get(obact); | ||||
| if (obpose && obpose->pose && obpose->data) { | if (obpose && obpose->pose && obpose->data) { | ||||
| if (obpose != obact) { | if (obpose != obact) { | ||||
| FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obpose, pchan) { | FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obpose, pchan) { | ||||
| CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan); | CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan); | ||||
| } | } | ||||
| FOREACH_PCHAN_SELECTED_IN_OBJECT_END; | FOREACH_PCHAN_SELECTED_IN_OBJECT_END; | ||||
| } | } | ||||
| else if (obact->mode & OB_MODE_POSE) { | else if (obact->mode & OB_MODE_POSE) { | ||||
| FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obact, pchan) { | FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obact, pchan) { | ||||
| CTX_data_list_add(result, &obact->id, &RNA_PoseBone, pchan); | CTX_data_list_add(result, &obact->id, &RNA_PoseBone, pchan); | ||||
| } | } | ||||
| FOREACH_PCHAN_SELECTED_IN_OBJECT_END; | FOREACH_PCHAN_SELECTED_IN_OBJECT_END; | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_active_bone(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_active_bone(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| if (obact && obact->type == OB_ARMATURE) { | if (obact && obact->type == OB_ARMATURE) { | ||||
| bArmature *arm = obact->data; | bArmature *arm = obact->data; | ||||
| if (arm->edbo) { | if (arm->edbo) { | ||||
| if (arm->act_edbone) { | if (arm->act_edbone) { | ||||
| CTX_data_pointer_set(result, &arm->id, &RNA_EditBone, arm->act_edbone); | CTX_data_pointer_set(result, &arm->id, &RNA_EditBone, arm->act_edbone); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (arm->act_bone) { | if (arm->act_bone) { | ||||
| CTX_data_pointer_set(result, &arm->id, &RNA_Bone, arm->act_bone); | CTX_data_pointer_set(result, &arm->id, &RNA_Bone, arm->act_bone); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_active_pose_bone(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_active_pose_bone(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| bPoseChannel *pchan; | bPoseChannel *pchan; | ||||
| Object *obpose = BKE_object_pose_armature_get(obact); | Object *obpose = BKE_object_pose_armature_get(obact); | ||||
| 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 CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_active_object(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_active_object(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| if (obact) { | if (obact) { | ||||
| CTX_data_id_pointer_set(result, &obact->id); | CTX_data_id_pointer_set(result, &obact->id); | ||||
| } | } | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_object(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_object(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| if (obact) { | if (obact) { | ||||
| CTX_data_id_pointer_set(result, &obact->id); | CTX_data_id_pointer_set(result, &obact->id); | ||||
| } | } | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_edit_object(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_edit_object(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); | Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); | ||||
| /* convenience for now, 1 object per scene in editmode */ | /* convenience for now, 1 object per scene in editmode */ | ||||
| if (obedit) { | if (obedit) { | ||||
| CTX_data_id_pointer_set(result, &obedit->id); | CTX_data_id_pointer_set(result, &obedit->id); | ||||
| } | } | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_sculpt_object(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_sculpt_object(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| if (obact && (obact->mode & OB_MODE_SCULPT)) { | if (obact && (obact->mode & OB_MODE_SCULPT)) { | ||||
| CTX_data_id_pointer_set(result, &obact->id); | CTX_data_id_pointer_set(result, &obact->id); | ||||
| } | } | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_vertex_paint_object(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_vertex_paint_object(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| if (obact && (obact->mode & OB_MODE_VERTEX_PAINT)) { | if (obact && (obact->mode & OB_MODE_VERTEX_PAINT)) { | ||||
| CTX_data_id_pointer_set(result, &obact->id); | CTX_data_id_pointer_set(result, &obact->id); | ||||
| } | } | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_weight_paint_object(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_weight_paint_object(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| if (obact && (obact->mode & OB_MODE_ALL_WEIGHT_PAINT)) { | if (obact && (obact->mode & OB_MODE_ALL_WEIGHT_PAINT)) { | ||||
| CTX_data_id_pointer_set(result, &obact->id); | CTX_data_id_pointer_set(result, &obact->id); | ||||
| } | } | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_image_paint_object(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_image_paint_object(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| if (obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) { | if (obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) { | ||||
| CTX_data_id_pointer_set(result, &obact->id); | CTX_data_id_pointer_set(result, &obact->id); | ||||
| } | } | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_particle_edit_object(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_particle_edit_object(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| if (obact && (obact->mode & OB_MODE_PARTICLE_EDIT)) { | if (obact && (obact->mode & OB_MODE_PARTICLE_EDIT)) { | ||||
| CTX_data_id_pointer_set(result, &obact->id); | CTX_data_id_pointer_set(result, &obact->id); | ||||
| } | } | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_pose_object(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_pose_object(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| Object *obpose = BKE_object_pose_armature_get(obact); | Object *obpose = BKE_object_pose_armature_get(obact); | ||||
| if (obpose) { | if (obpose) { | ||||
| CTX_data_id_pointer_set(result, &obpose->id); | CTX_data_id_pointer_set(result, &obpose->id); | ||||
| } | } | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| static int screen_ctx_sequences(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_sequences(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| Editing *ed = BKE_sequencer_editing_get(scene, false); | Editing *ed = BKE_sequencer_editing_get(scene, false); | ||||
| if (ed) { | if (ed) { | ||||
| LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) { | LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) { | ||||
| CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq); | CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq); | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_selected_sequences(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selected_sequences(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| Editing *ed = BKE_sequencer_editing_get(scene, false); | Editing *ed = BKE_sequencer_editing_get(scene, false); | ||||
| if (ed) { | if (ed) { | ||||
| LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) { | LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) { | ||||
| if (seq->flag & SELECT) { | if (seq->flag & SELECT) { | ||||
| CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq); | CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_selected_editable_sequences(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selected_editable_sequences(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| Editing *ed = BKE_sequencer_editing_get(scene, false); | Editing *ed = BKE_sequencer_editing_get(scene, false); | ||||
| if (ed) { | if (ed) { | ||||
| LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) { | LISTBASE_FOREACH (Sequence *, seq, ed->seqbasep) { | ||||
| if (seq->flag & SELECT && !(seq->flag & SEQ_LOCK)) { | if (seq->flag & SELECT && !(seq->flag & SEQ_LOCK)) { | ||||
| CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq); | CTX_data_list_add(result, &scene->id, &RNA_Sequence, seq); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_selected_nla_strips(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selected_nla_strips(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| bAnimContext ac; | bAnimContext ac; | ||||
| if (ANIM_animdata_get_context(C, &ac) != 0) { | if (ANIM_animdata_get_context(C, &ac) != 0) { | ||||
| ListBase anim_data = {NULL, NULL}; | ListBase anim_data = {NULL, NULL}; | ||||
| ANIM_animdata_filter(&ac, &anim_data, ANIMFILTER_DATA_VISIBLE, ac.data, ac.datatype); | ANIM_animdata_filter(&ac, &anim_data, ANIMFILTER_DATA_VISIBLE, ac.data, ac.datatype); | ||||
| LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { | LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { | ||||
| if (ale->datatype != ALE_NLASTRIP) { | if (ale->datatype != ALE_NLASTRIP) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| NlaTrack *nlt = (NlaTrack *)ale->data; | NlaTrack *nlt = (NlaTrack *)ale->data; | ||||
| LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { | LISTBASE_FOREACH (NlaStrip *, strip, &nlt->strips) { | ||||
| if (strip->flag & NLASTRIP_FLAG_SELECT) { | if (strip->flag & NLASTRIP_FLAG_SELECT) { | ||||
| CTX_data_list_add(result, &scene->id, &RNA_NlaStrip, strip); | CTX_data_list_add(result, &scene->id, &RNA_NlaStrip, strip); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ANIM_animdata_freelist(&anim_data); | ANIM_animdata_freelist(&anim_data); | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_gpencil_data(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_gpencil_data(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| /* FIXME: for some reason, CTX_data_active_object(C) returns NULL when called from these | /* FIXME: for some reason, CTX_data_active_object(C) returns NULL when called from these | ||||
| * situations (as outlined above - see Campbell's #ifdefs). | * situations (as outlined above - see Campbell's #ifdefs). | ||||
| * That causes the get_active function to fail when called from context. | * That causes the get_active function to fail when called from context. | ||||
| * For that reason, we end up using an alternative where we pass everything in! | * For that reason, we end up using an alternative where we pass everything in! | ||||
| */ | */ | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | ||||
| if (gpd) { | if (gpd) { | ||||
| CTX_data_id_pointer_set(result, &gpd->id); | CTX_data_id_pointer_set(result, &gpd->id); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_gpencil_data_owner(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_gpencil_data_owner(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| /* Pointer to which data/datablock owns the reference to the Grease Pencil data being used | /* Pointer to which data/datablock owns the reference to the Grease Pencil data being used | ||||
| * (as gpencil_data). */ | * (as gpencil_data). */ | ||||
| bGPdata **gpd_ptr = NULL; | bGPdata **gpd_ptr = NULL; | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| /* get pointer to Grease Pencil Data */ | /* get pointer to Grease Pencil Data */ | ||||
| gpd_ptr = ED_gpencil_data_get_pointers_direct(area, obact, &ptr); | gpd_ptr = ED_gpencil_data_get_pointers_direct(area, obact, &ptr); | ||||
| if (gpd_ptr) { | if (gpd_ptr) { | ||||
| CTX_data_pointer_set(result, ptr.owner_id, ptr.type, ptr.data); | CTX_data_pointer_set(result, ptr.owner_id, ptr.type, ptr.data); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_annotation_data(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_annotation_data(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| bScreen *screen = CTX_wm_screen(C); | bScreen *screen = CTX_wm_screen(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| bGPdata *gpd = ED_annotation_data_get_active_direct((ID *)screen, area, scene); | bGPdata *gpd = ED_annotation_data_get_active_direct((ID *)screen, area, scene); | ||||
| if (gpd) { | if (gpd) { | ||||
| CTX_data_id_pointer_set(result, &gpd->id); | CTX_data_id_pointer_set(result, &gpd->id); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_annotation_data_owner(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_annotation_data_owner(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| bScreen *screen = CTX_wm_screen(C); | bScreen *screen = CTX_wm_screen(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| /* Pointer to which data/datablock owns the reference to the Grease Pencil data being used. */ | /* Pointer to which data/datablock owns the reference to the Grease Pencil data being used. */ | ||||
| bGPdata **gpd_ptr = NULL; | bGPdata **gpd_ptr = NULL; | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| /* Get pointer to Grease Pencil Data. */ | /* Get pointer to Grease Pencil Data. */ | ||||
| gpd_ptr = ED_annotation_data_get_pointers_direct((ID *)screen, area, scene, &ptr); | gpd_ptr = ED_annotation_data_get_pointers_direct((ID *)screen, area, scene, &ptr); | ||||
| if (gpd_ptr) { | if (gpd_ptr) { | ||||
| CTX_data_pointer_set(result, ptr.owner_id, ptr.type, ptr.data); | CTX_data_pointer_set(result, ptr.owner_id, ptr.type, ptr.data); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_active_gpencil_layer(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_active_gpencil_layer(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | ||||
| if (gpd) { | if (gpd) { | ||||
| bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd); | bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd); | ||||
| if (gpl) { | if (gpl) { | ||||
| CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl); | CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_active_annotation_layer(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_active_annotation_layer(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| bScreen *screen = CTX_wm_screen(C); | bScreen *screen = CTX_wm_screen(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| bGPdata *gpd = ED_annotation_data_get_active_direct((ID *)screen, area, scene); | bGPdata *gpd = ED_annotation_data_get_active_direct((ID *)screen, area, scene); | ||||
| if (gpd) { | if (gpd) { | ||||
| bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd); | bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd); | ||||
| if (gpl) { | if (gpl) { | ||||
| CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl); | CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_active_gpencil_frame(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_active_gpencil_frame(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | ||||
| if (gpd) { | if (gpd) { | ||||
| bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd); | bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd); | ||||
| if (gpl) { | if (gpl) { | ||||
| CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl->actframe); | CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl->actframe); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_visible_gpencil_layers(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_visible_gpencil_layers(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | ||||
| if (gpd) { | if (gpd) { | ||||
| LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { | LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { | ||||
| if ((gpl->flag & GP_LAYER_HIDE) == 0) { | if ((gpl->flag & GP_LAYER_HIDE) == 0) { | ||||
| CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl); | CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_editable_gpencil_layers(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_editable_gpencil_layers(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | ||||
| if (gpd) { | if (gpd) { | ||||
| LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { | LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { | ||||
| if (BKE_gpencil_layer_is_editable(gpl)) { | if (BKE_gpencil_layer_is_editable(gpl)) { | ||||
| CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl); | CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl); | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_editable_gpencil_strokes(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_editable_gpencil_strokes(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | Object *obact = view_layer->basact ? view_layer->basact->object : NULL; | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | bGPdata *gpd = ED_gpencil_data_get_active_direct(area, obact); | ||||
| const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd); | const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd); | ||||
| Show All 23 Lines | LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { | ||||
| /* if not multiedit out of loop */ | /* if not multiedit out of loop */ | ||||
| if (!is_multiedit) { | if (!is_multiedit) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_active_operator(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_active_operator(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| wmOperator *op = NULL; | wmOperator *op = NULL; | ||||
| SpaceFile *sfile = CTX_wm_space_file(C); | SpaceFile *sfile = CTX_wm_space_file(C); | ||||
| if (sfile) { | if (sfile) { | ||||
| op = sfile->op; | op = sfile->op; | ||||
| } | } | ||||
| else if ((op = UI_context_active_operator_get(C))) { | else if ((op = UI_context_active_operator_get(C))) { | ||||
| /* do nothing */ | /* do nothing */ | ||||
| } | } | ||||
| else { | else { | ||||
| /* note, this checks poll, could be a problem, but this also | /* note, this checks poll, could be a problem, but this also | ||||
| * happens for the toolbar */ | * happens for the toolbar */ | ||||
| op = WM_operator_last_redo(C); | op = WM_operator_last_redo(C); | ||||
| } | } | ||||
| /* TODO, get the operator from popup's */ | /* TODO, get the operator from popup's */ | ||||
| if (op && op->ptr) { | if (op && op->ptr) { | ||||
| CTX_data_pointer_set(result, NULL, &RNA_Operator, op); | CTX_data_pointer_set(result, NULL, &RNA_Operator, op); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_sel_edit_fcurves_(const bContext *C, | static eContextResult screen_ctx_sel_edit_fcurves_(const bContext *C, | ||||
| bContextDataResult *result, | bContextDataResult *result, | ||||
| const int extra_filter) | const int extra_filter) | ||||
| { | { | ||||
| bAnimContext ac; | bAnimContext ac; | ||||
| if (ANIM_animdata_get_context(C, &ac) && ELEM(ac.spacetype, SPACE_ACTION, SPACE_GRAPH)) { | if (ANIM_animdata_get_context(C, &ac) && ELEM(ac.spacetype, SPACE_ACTION, SPACE_GRAPH)) { | ||||
| ListBase anim_data = {NULL, NULL}; | ListBase anim_data = {NULL, NULL}; | ||||
| int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_NODUPLIS) | | int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_NODUPLIS) | | ||||
| (ac.spacetype == SPACE_GRAPH ? ANIMFILTER_CURVE_VISIBLE : | (ac.spacetype == SPACE_GRAPH ? ANIMFILTER_CURVE_VISIBLE : | ||||
| ANIMFILTER_LIST_VISIBLE) | | ANIMFILTER_LIST_VISIBLE) | | ||||
| extra_filter; | extra_filter; | ||||
| ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); | ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); | ||||
| LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { | LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { | ||||
| if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) { | if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) { | ||||
| CTX_data_list_add(result, ale->fcurve_owner_id, &RNA_FCurve, ale->data); | CTX_data_list_add(result, ale->fcurve_owner_id, &RNA_FCurve, ale->data); | ||||
| } | } | ||||
| } | } | ||||
| ANIM_animdata_freelist(&anim_data); | ANIM_animdata_freelist(&anim_data); | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| static int screen_ctx_editable_fcurves(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_editable_fcurves(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| return screen_ctx_sel_edit_fcurves_(C, result, ANIMFILTER_FOREDIT); | return screen_ctx_sel_edit_fcurves_(C, result, ANIMFILTER_FOREDIT); | ||||
| } | } | ||||
| static int screen_ctx_visible_fcurves(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_visible_fcurves(const bContext *C, bContextDataResult *result) | ||||
| { | { | ||||
| return screen_ctx_sel_edit_fcurves_(C, result, 0); | return screen_ctx_sel_edit_fcurves_(C, result, 0); | ||||
| } | } | ||||
| static int screen_ctx_selected_editable_fcurves(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selected_editable_fcurves(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| return screen_ctx_sel_edit_fcurves_(C, result, ANIMFILTER_SEL | ANIMFILTER_FOREDIT); | return screen_ctx_sel_edit_fcurves_(C, result, ANIMFILTER_SEL | ANIMFILTER_FOREDIT); | ||||
| } | } | ||||
| static int screen_ctx_selected_visible_fcurves(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_selected_visible_fcurves(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| return screen_ctx_sel_edit_fcurves_(C, result, ANIMFILTER_SEL); | return screen_ctx_sel_edit_fcurves_(C, result, ANIMFILTER_SEL); | ||||
| } | } | ||||
| static int screen_ctx_active_editable_fcurve(const bContext *C, bContextDataResult *result) | static eContextResult screen_ctx_active_editable_fcurve(const bContext *C, | ||||
| bContextDataResult *result) | |||||
| { | { | ||||
| bAnimContext ac; | bAnimContext ac; | ||||
| if (ANIM_animdata_get_context(C, &ac) && ELEM(ac.spacetype, SPACE_GRAPH)) { | if (ANIM_animdata_get_context(C, &ac) && ELEM(ac.spacetype, SPACE_GRAPH)) { | ||||
| ListBase anim_data = {NULL, NULL}; | ListBase anim_data = {NULL, NULL}; | ||||
| int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ACTIVE | ANIMFILTER_FOREDIT | | int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ACTIVE | ANIMFILTER_FOREDIT | | ||||
| ANIMFILTER_CURVE_VISIBLE); | ANIMFILTER_CURVE_VISIBLE); | ||||
| ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); | ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); | ||||
| LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { | LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { | ||||
| if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) { | if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) { | ||||
| CTX_data_pointer_set(result, ale->fcurve_owner_id, &RNA_FCurve, ale->data); | CTX_data_pointer_set(result, ale->fcurve_owner_id, &RNA_FCurve, ale->data); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| ANIM_animdata_freelist(&anim_data); | ANIM_animdata_freelist(&anim_data); | ||||
| return 1; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| return -1; /* found but not available */ | return CTX_RESULT_NO_DATA; | ||||
| } | } | ||||
| /* Registry of context callback functions. */ | /* Registry of context callback functions. */ | ||||
| typedef int (*context_callback)(const bContext *C, bContextDataResult *result); | typedef int (*context_callback)(const bContext *C, bContextDataResult *result); | ||||
| static GHash *ed_screen_context_functions = NULL; | static GHash *ed_screen_context_functions = NULL; | ||||
| static void free_context_function_ghash(void *UNUSED(user_data)) | static void free_context_function_ghash(void *UNUSED(user_data)) | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | static void ensure_ed_screen_context_functions(void) | ||||
| register_context_function("active_editable_fcurve", screen_ctx_active_editable_fcurve); | register_context_function("active_editable_fcurve", screen_ctx_active_editable_fcurve); | ||||
| } | } | ||||
| /* Entry point for the screen context. */ | /* Entry point for the screen context. */ | ||||
| int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result) | int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result) | ||||
| { | { | ||||
| 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 CTX_RESULT_OK; | ||||
| } | } | ||||
| ensure_ed_screen_context_functions(); | ensure_ed_screen_context_functions(); | ||||
| context_callback callback = BLI_ghash_lookup(ed_screen_context_functions, member); | context_callback callback = BLI_ghash_lookup(ed_screen_context_functions, member); | ||||
| if (callback == NULL) { | if (callback == NULL) { | ||||
| return 0; /* not found */ | return CTX_RESULT_MEMBER_NOT_FOUND; | ||||
| } | } | ||||
| return callback(C, result); | return callback(C, result); | ||||
| } | } | ||||