Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_buttons/buttons_context.c
| Show All 16 Lines | |||||
| #include "DNA_armature_types.h" | #include "DNA_armature_types.h" | ||||
| #include "DNA_brush_types.h" | #include "DNA_brush_types.h" | ||||
| #include "DNA_collection_types.h" | #include "DNA_collection_types.h" | ||||
| #include "DNA_linestyle_types.h" | #include "DNA_linestyle_types.h" | ||||
| #include "DNA_material_types.h" | #include "DNA_material_types.h" | ||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_video_edit_types.h" | |||||
| #include "DNA_windowmanager_types.h" | #include "DNA_windowmanager_types.h" | ||||
| #include "DNA_world_types.h" | #include "DNA_world_types.h" | ||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_armature.h" | #include "BKE_armature.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_linestyle.h" | #include "BKE_linestyle.h" | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
| static bool buttons_context_path_scene(ButsContextPath *path) | static bool buttons_context_path_scene(ButsContextPath *path) | ||||
| { | { | ||||
| PointerRNA *ptr = &path->ptr[path->len - 1]; | PointerRNA *ptr = &path->ptr[path->len - 1]; | ||||
| /* this one just verifies */ | /* this one just verifies */ | ||||
| return RNA_struct_is_a(ptr->type, &RNA_Scene); | return RNA_struct_is_a(ptr->type, &RNA_Scene); | ||||
| } | } | ||||
| static bool buttons_context_path_video_edit(ButsContextPath *path) | |||||
| { | |||||
| PointerRNA *ptr = &path->ptr[path->len - 1]; | |||||
| return RNA_struct_is_a(ptr->type, &RNA_VideoEdit); | |||||
| } | |||||
| static bool buttons_context_path_view_layer(ButsContextPath *path, wmWindow *win) | static bool buttons_context_path_view_layer(ButsContextPath *path, wmWindow *win) | ||||
| { | { | ||||
| PointerRNA *ptr = &path->ptr[path->len - 1]; | PointerRNA *ptr = &path->ptr[path->len - 1]; | ||||
| /* View Layer may have already been resolved in a previous call | /* View Layer may have already been resolved in a previous call | ||||
| * (e.g. in buttons_context_path_linestyle). */ | * (e.g. in buttons_context_path_linestyle). */ | ||||
| if (RNA_struct_is_a(ptr->type, &RNA_ViewLayer)) { | if (RNA_struct_is_a(ptr->type, &RNA_ViewLayer)) { | ||||
| return true; | return true; | ||||
| ▲ Show 20 Lines • Show All 437 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| #endif | #endif | ||||
| static bool buttons_context_path( | static bool buttons_context_path( | ||||
| const bContext *C, SpaceProperties *sbuts, ButsContextPath *path, int mainb, int flag) | const bContext *C, SpaceProperties *sbuts, ButsContextPath *path, int mainb, int flag) | ||||
| { | { | ||||
| /* Note we don't use CTX_data here, instead we get it from the window. | /* Note we don't use CTX_data here, instead we get it from the window. | ||||
| * Otherwise there is a loop reading the context that we are setting. */ | * Otherwise there is a loop reading the context that we are setting. */ | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | |||||
| wmWindow *window = CTX_wm_window(C); | wmWindow *window = CTX_wm_window(C); | ||||
| Scene *scene = WM_window_get_active_scene(window); | Scene *scene = WM_window_get_active_scene(window); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(window); | ViewLayer *view_layer = WM_window_get_active_view_layer(window); | ||||
| VideoEdit *video_edit = WM_window_get_active_video_edit(window); | |||||
| memset(path, 0, sizeof(*path)); | memset(path, 0, sizeof(*path)); | ||||
| path->flag = flag; | path->flag = flag; | ||||
| /* If some ID datablock is pinned, set the root pointer. */ | /* If some ID datablock is pinned, set the root pointer. */ | ||||
| if (sbuts->pinid) { | if (sbuts->pinid) { | ||||
| ID *id = sbuts->pinid; | ID *id = sbuts->pinid; | ||||
| RNA_id_pointer_create(id, &path->ptr[0]); | RNA_id_pointer_create(id, &path->ptr[0]); | ||||
| path->len++; | path->len++; | ||||
| } | } | ||||
| /* No pinned root, use scene as initial root. */ | /* No pinned root, use scene as initial root. */ | ||||
| else if (mainb != BCONTEXT_TOOL) { | else if (mainb != BCONTEXT_TOOL) { | ||||
| /* Use the active video edit as the root if we are in the output context and the source is set | |||||
| * to video_edit. */ | |||||
| if (mainb == BCONTEXT_OUTPUT && wm->output_source == WM_OUTPUT_SOURCE_VIDEO_EDIT) { | |||||
| RNA_id_pointer_create(&video_edit->id, &path->ptr[0]); | |||||
| } | |||||
| else { | |||||
| RNA_id_pointer_create(&scene->id, &path->ptr[0]); | RNA_id_pointer_create(&scene->id, &path->ptr[0]); | ||||
| } | |||||
| path->len++; | path->len++; | ||||
| if (!ELEM(mainb, | if (!ELEM(mainb, | ||||
| BCONTEXT_SCENE, | BCONTEXT_SCENE, | ||||
| BCONTEXT_RENDER, | BCONTEXT_RENDER, | ||||
| BCONTEXT_OUTPUT, | BCONTEXT_OUTPUT, | ||||
| BCONTEXT_VIEW_LAYER, | BCONTEXT_VIEW_LAYER, | ||||
| BCONTEXT_WORLD)) { | BCONTEXT_WORLD)) { | ||||
| RNA_pointer_create(NULL, &RNA_ViewLayer, view_layer, &path->ptr[path->len]); | RNA_pointer_create(NULL, &RNA_ViewLayer, view_layer, &path->ptr[path->len]); | ||||
| path->len++; | path->len++; | ||||
| } | } | ||||
| } | } | ||||
| /* now for each buttons context type, we try to construct a path, | /* now for each buttons context type, we try to construct a path, | ||||
| * tracing back recursively */ | * tracing back recursively */ | ||||
| bool found; | bool found; | ||||
| switch (mainb) { | switch (mainb) { | ||||
| case BCONTEXT_SCENE: | case BCONTEXT_SCENE: | ||||
| case BCONTEXT_RENDER: | case BCONTEXT_RENDER: | ||||
| found = buttons_context_path_scene(path); | |||||
| break; | |||||
| case BCONTEXT_OUTPUT: | case BCONTEXT_OUTPUT: | ||||
| if (wm->output_source == WM_OUTPUT_SOURCE_VIDEO_EDIT) { | |||||
| found = buttons_context_path_video_edit(path); | |||||
| } | |||||
| else { | |||||
| found = buttons_context_path_scene(path); | found = buttons_context_path_scene(path); | ||||
| } | |||||
| break; | break; | ||||
| case BCONTEXT_VIEW_LAYER: | case BCONTEXT_VIEW_LAYER: | ||||
| #ifdef WITH_FREESTYLE | #ifdef WITH_FREESTYLE | ||||
| if (buttons_context_linestyle_pinnable(C, view_layer)) { | if (buttons_context_linestyle_pinnable(C, view_layer)) { | ||||
| found = buttons_context_path_linestyle(path, window); | found = buttons_context_path_linestyle(path, window); | ||||
| if (found) { | if (found) { | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 242 Lines • ▼ Show 20 Lines | const char *buttons_context_dir[] = { | ||||
| "dynamic_paint", | "dynamic_paint", | ||||
| "line_style", | "line_style", | ||||
| "collection", | "collection", | ||||
| "gpencil", | "gpencil", | ||||
| "curves", | "curves", | ||||
| #ifdef WITH_POINT_CLOUD | #ifdef WITH_POINT_CLOUD | ||||
| "pointcloud", | "pointcloud", | ||||
| #endif | #endif | ||||
| "video_edit", | |||||
| "volume", | "volume", | ||||
| NULL, | NULL, | ||||
| }; | }; | ||||
| int /*eContextResult*/ buttons_context(const bContext *C, | int /*eContextResult*/ buttons_context(const bContext *C, | ||||
| const char *member, | const char *member, | ||||
| bContextDataResult *result) | bContextDataResult *result) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | #endif | ||||
| if (CTX_data_equals(member, "line_style")) { | if (CTX_data_equals(member, "line_style")) { | ||||
| set_pointer_type(path, result, &RNA_FreestyleLineStyle); | set_pointer_type(path, result, &RNA_FreestyleLineStyle); | ||||
| return CTX_RESULT_OK; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| if (CTX_data_equals(member, "gpencil")) { | if (CTX_data_equals(member, "gpencil")) { | ||||
| set_pointer_type(path, result, &RNA_GreasePencil); | set_pointer_type(path, result, &RNA_GreasePencil); | ||||
| return CTX_RESULT_OK; | return CTX_RESULT_OK; | ||||
| } | } | ||||
| if (CTX_data_equals(member, "video_edit")) { | |||||
| set_pointer_type(path, result, &RNA_VideoEdit); | |||||
| return CTX_RESULT_OK; | |||||
| } | |||||
| return CTX_RESULT_MEMBER_NOT_FOUND; | return CTX_RESULT_MEMBER_NOT_FOUND; | ||||
| } | } | ||||
| /************************* Drawing the Path ************************/ | /************************* Drawing the Path ************************/ | ||||
| static bool buttons_panel_context_poll(const bContext *C, PanelType *UNUSED(pt)) | static bool buttons_panel_context_poll(const bContext *C, PanelType *UNUSED(pt)) | ||||
| { | { | ||||
| SpaceProperties *sbuts = CTX_wm_space_properties(C); | SpaceProperties *sbuts = CTX_wm_space_properties(C); | ||||
| return sbuts->mainb != BCONTEXT_TOOL; | return sbuts->mainb != BCONTEXT_TOOL; | ||||
| } | } | ||||
| static void buttons_panel_context_draw(const bContext *C, Panel *panel) | static void buttons_panel_context_draw(const bContext *C, Panel *panel) | ||||
| { | { | ||||
| SpaceProperties *sbuts = CTX_wm_space_properties(C); | SpaceProperties *sbuts = CTX_wm_space_properties(C); | ||||
| ButsContextPath *path = sbuts->path; | ButsContextPath *path = sbuts->path; | ||||
| if (!path) { | if (!path) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (sbuts->mainb == BCONTEXT_OUTPUT && !sbuts->pinid) { | |||||
| uiLayout *header = uiLayoutRow(panel->layout, true); | |||||
| uiLayoutSetAlignment(header, UI_LAYOUT_ALIGN_EXPAND); | |||||
| PointerRNA wm_ptr; | |||||
| wmWindowManager *wm = CTX_wm_manager(C); | |||||
| RNA_id_pointer_create(&wm->id, &wm_ptr); | |||||
| uiItemR(header, &wm_ptr, "output_source", UI_ITEM_R_EXPAND, NULL, 0); | |||||
| } | |||||
| uiLayout *row = uiLayoutRow(panel->layout, true); | uiLayout *row = uiLayoutRow(panel->layout, true); | ||||
| uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_LEFT); | uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_LEFT); | ||||
| bool first = true; | bool first = true; | ||||
| for (int i = 0; i < path->len; i++) { | for (int i = 0; i < path->len; i++) { | ||||
| PointerRNA *ptr = &path->ptr[i]; | PointerRNA *ptr = &path->ptr[i]; | ||||
| /* Skip scene and view layer to save space. */ | /* Skip scene and view layer to save space. */ | ||||
| ▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines | |||||