Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/screen/screen_context.c
| Show All 36 Lines | |||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| #include "DNA_windowmanager_types.h" | #include "DNA_windowmanager_types.h" | ||||
| #include "DNA_workspace_types.h" | #include "DNA_workspace_types.h" | ||||
| #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_paint.h" | |||||
| #include "BKE_main.h" | |||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_sequencer.h" | #include "BKE_sequencer.h" | ||||
| #include "BKE_workspace.h" | #include "BKE_workspace.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| Show All 16 Lines | const char *screen_context_dir[] = { | ||||
| "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_palette", "active_palettecolor", "available_palettes", "available_palettecolors", | |||||
| "active_operator", "selected_editable_fcurves", | "active_operator", "selected_editable_fcurves", | ||||
| 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) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| bScreen *sc = CTX_wm_screen(C); | bScreen *sc = CTX_wm_screen(C); | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| ▲ Show 20 Lines • Show All 385 Lines • ▼ Show 20 Lines | if (gpd) { | ||||
| CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl); | CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilLayer, gpl); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "active_gpencil_palette")) { | else if (CTX_data_equals(member, "active_gpencil_palette")) { | ||||
| /* XXX: see comment for gpencil_data case... */ | /* XXX: see comment for gpencil_data case... */ | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact); | bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact); | ||||
| bGPDpaletteref *palslot = BKE_gpencil_paletteslot_get_active(gpd); | |||||
| if (gpd) { | if (palslot && palslot->palette) { | ||||
| bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd); | Palette *palette = palslot->palette; | ||||
| CTX_data_pointer_set(result, &palette->id, &RNA_Palette, palette); | |||||
| if (palette) { | |||||
| CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilPalette, palette); | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| else if (CTX_data_equals(member, "active_gpencil_palettecolor")) { | else if (CTX_data_equals(member, "active_gpencil_palettecolor")) { | ||||
| /* XXX: see comment for gpencil_data case... */ | /* XXX: see comment for gpencil_data case... */ | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact); | bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact); | ||||
| bGPDpaletteref *palslot = BKE_gpencil_paletteslot_get_active(gpd); | |||||
| if (gpd) { | if (palslot && palslot->palette) { | ||||
| bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd); | Palette *palette = palslot->palette; | ||||
| PaletteColor *palcolor = BKE_palette_color_get_active(palette); | |||||
| if (palette) { | |||||
| bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_getactive(palette); | |||||
| if (palcolor) { | if (palcolor) { | ||||
| CTX_data_pointer_set(result, &gpd->id, &RNA_GPencilPaletteColor, palcolor); | CTX_data_pointer_set(result, &palette->id, &RNA_PaletteColor, palcolor); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| else if (CTX_data_equals(member, "active_gpencil_brush")) { | else if (CTX_data_equals(member, "active_gpencil_brush")) { | ||||
| /* XXX: see comment for gpencil_data case... */ | |||||
| bGPDbrush *brush = BKE_gpencil_brush_getactive(scene->toolsettings); | bGPDbrush *brush = BKE_gpencil_brush_getactive(scene->toolsettings); | ||||
| if (brush) { | if (brush) { | ||||
| CTX_data_pointer_set(result, &scene->id, &RNA_GPencilBrush, brush); | CTX_data_pointer_set(result, &scene->id, &RNA_GPencilBrush, brush); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "active_gpencil_frame")) { | else if (CTX_data_equals(member, "active_gpencil_frame")) { | ||||
| Show All 39 Lines | if (gpd) { | ||||
| } | } | ||||
| 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_gpencil_strokes")) { | else if (CTX_data_equals(member, "editable_gpencil_strokes")) { | ||||
| /* XXX: see comment for gpencil_data case... */ | /* XXX: see comment for gpencil_data case... */ | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact); | bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, scene, sa, obact); | ||||
| bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd); | |||||
| if (gpd) { | if (gpd) { | ||||
| bGPDlayer *gpl; | bGPDlayer *gpl; | ||||
| for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { | for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { | ||||
| if (gpencil_layer_is_editable(gpl) && (gpl->actframe)) { | if (gpencil_layer_is_editable(gpl) && (gpl->actframe)) { | ||||
| bGPDframe *gpf = gpl->actframe; | bGPDframe *gpf; | ||||
| bGPDstroke *gps; | bGPDstroke *gps; | ||||
| bGPDframe *init_gpf = gpl->actframe; | |||||
| if (is_multiedit) { | |||||
| init_gpf = gpl->frames.first; | |||||
| } | |||||
| for (gpf = init_gpf; gpf; gpf = gpf->next) { | |||||
| if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { | |||||
| for (gps = gpf->strokes.first; gps; gps = gps->next) { | for (gps = gpf->strokes.first; gps; gps = gps->next) { | ||||
| if (ED_gpencil_stroke_can_use_direct(sa, gps)) { | if (ED_gpencil_stroke_can_use_direct(sa, gps)) { | ||||
| /* check if the color is editable */ | /* check if the color is editable */ | ||||
| if (ED_gpencil_stroke_color_use(gpl, gps) == false) { | if (ED_gpencil_stroke_color_use(gpl, gps) == false) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| CTX_data_list_add(result, &gpd->id, &RNA_GPencilStroke, gps); | CTX_data_list_add(result, &gpd->id, &RNA_GPencilStroke, gps); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* if not multiedit out of loop */ | |||||
| if (!is_multiedit) { | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| 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, "active_palette")) { | |||||
| Palette *palette = BKE_palette_get_active_from_context(C); | |||||
| if (palette) { | |||||
| CTX_data_pointer_set(result, &palette->id, &RNA_Palette, palette); | |||||
| return 1; | |||||
| } | |||||
| } | |||||
| else if (CTX_data_equals(member, "active_palettecolor")) { | |||||
| Palette *palette = BKE_palette_get_active_from_context(C); | |||||
| PaletteColor *palcolor = BKE_palette_color_get_active(palette); | |||||
| if (palcolor) { | |||||
| CTX_data_pointer_set(result, &palette->id, &RNA_PaletteColor, palcolor); | |||||
| return 1; | |||||
| } | |||||
| } | |||||
| else if (CTX_data_equals(member, "active_palettecolors")) { | |||||
| Palette *palette = BKE_palette_get_active_from_context(C); | |||||
| if (palette) { | |||||
| for (PaletteColor *palcolor = palette->colors.first; palcolor; palcolor = palcolor->next) { | |||||
| CTX_data_list_add(result, &palette->id, &RNA_PaletteColor, palcolor); | |||||
| } | |||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | |||||
| return 1; | |||||
| } | |||||
| } | |||||
| else if (CTX_data_equals(member, "available_palettes")) { | |||||
| Main *bmain = CTX_data_main(C); | |||||
| for (Palette *palette = bmain->palettes.first; palette; palette = palette->id.next) { | |||||
| // TODO: filter to palettes on scene | |||||
| CTX_data_list_add(result, &palette->id, &RNA_Palette, palette); | |||||
| } | |||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | |||||
| return 1; | |||||
| } | |||||
| else if (CTX_data_equals(member, "available_palettecolors")) { | |||||
| Main *bmain = CTX_data_main(C); | |||||
| for (Palette *palette = bmain->palettes.first; palette; palette = palette->id.next) { | |||||
| // TODO: filter to palettes on scene | |||||
| for (PaletteColor *palcolor = palette->colors.first; palcolor; palcolor = palcolor->next) { | |||||
| CTX_data_list_add(result, &palette->id, &RNA_PaletteColor, palcolor); | |||||
| } | |||||
| } | |||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | |||||
| return 1; | |||||
| } | |||||
| else if (CTX_data_equals(member, "active_operator")) { | else if (CTX_data_equals(member, "active_operator")) { | ||||
| 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))) { | ||||
| ▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines | |||||