Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_utils.c
| Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
| /* ******************************************************** */ | /* ******************************************************** */ | ||||
| /* Context Wrangling... */ | /* Context Wrangling... */ | ||||
| /** | /** | ||||
| * Get pointer to active Grease Pencil datablock, | * Get pointer to active Grease Pencil datablock, | ||||
| * and an RNA-pointer to trace back to whatever owns it, | * and an RNA-pointer to trace back to whatever owns it, | ||||
| * when context info is not available. | * when context info is not available. | ||||
| */ | */ | ||||
| bGPdata **ED_gpencil_data_get_pointers_direct( | bGPdata **ED_gpencil_data_get_pointers_direct(ScrArea *sa, Object *ob, PointerRNA *r_ptr) | ||||
| ID *screen_id, ScrArea *sa, Scene *scene, Object *ob, PointerRNA *r_ptr) | |||||
| { | { | ||||
| /* if there's an active area, check if the particular editor may | /* if there's an active area, check if the particular editor may | ||||
| * have defined any special Grease Pencil context for editing... | * have defined any special Grease Pencil context for editing... | ||||
| */ | */ | ||||
| if (sa) { | if (sa) { | ||||
| SpaceLink *sl = sa->spacedata.first; | |||||
| switch (sa->spacetype) { | switch (sa->spacetype) { | ||||
| /* XXX: Should we reduce reliance on context.gpencil_data for these cases? */ | |||||
| case SPACE_PROPERTIES: /* properties */ | case SPACE_PROPERTIES: /* properties */ | ||||
| case SPACE_INFO: /* header info (needed after workspaces merge) */ | case SPACE_INFO: /* header info (needed after workspaces merge) */ | ||||
| case SPACE_ACTION: /* Dopesheet header. */ | case SPACE_TOPBAR: /* Topbar (needed after topbar merge) */ | ||||
dfelinto: Why is this part of the patch? | |||||
antoniovAuthorUnsubmitted Done Inline ActionsBecause it fix a bug related. antoniov: Because it fix a bug related. | |||||
| case SPACE_VIEW3D: /* 3D-View */ | |||||
Not Done Inline Actions- case SPACE_TOPBAR: /* Topbar (needed after topbar merge) */ + case SPACE_TOPBAR: Or explain WHY it is needed, that is needed it is obvious given the code itself. dfelinto: ```
- case SPACE_TOPBAR: /* Topbar (needed after topbar merge) */
+ case SPACE_TOPBAR:
```… | |||||
| { | { | ||||
| if (ob && (ob->type == OB_GPENCIL)) { | if (ob && (ob->type == OB_GPENCIL)) { | ||||
| /* GP Object */ | /* GP Object */ | ||||
| if (r_ptr) { | if (r_ptr) { | ||||
| RNA_id_pointer_create(&ob->id, r_ptr); | RNA_id_pointer_create(&ob->id, r_ptr); | ||||
| } | } | ||||
| return (bGPdata **)&ob->data; | return (bGPdata **)&ob->data; | ||||
| } | } | ||||
| else { | else { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| default: /* unsupported space */ | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| return NULL; | |||||
| } | |||||
| /** | |||||
| * Get pointer to active Grease Pencil datablock for annotations, | |||||
| * and an RNA-pointer to trace back to whatever owns it, | |||||
| * when context info is not available. | |||||
| */ | |||||
| bGPdata **ED_annotation_data_get_pointers_direct(ID *screen_id, | |||||
| ScrArea *sa, | |||||
| Scene *scene, | |||||
| PointerRNA *r_ptr) | |||||
| { | |||||
| /* if there's an active area, check if the particular editor may | |||||
Not Done Inline ActionsSee other comments regarding comment code-style dfelinto: See other comments regarding comment code-style | |||||
| * have defined any special Grease Pencil context for editing... | |||||
| */ | |||||
| if (sa) { | |||||
| SpaceLink *sl = sa->spacedata.first; | |||||
| switch (sa->spacetype) { | |||||
| /* XXX: Should we reduce reliance on context.gpencil_data for these cases? */ | |||||
| case SPACE_PROPERTIES: /* properties */ | |||||
| case SPACE_INFO: /* header info (needed after workspaces merge) */ | |||||
| { | |||||
| return NULL; | |||||
| break; | |||||
| } | |||||
| case SPACE_TOPBAR: /* Topbar (needed after topbar merge) */ | case SPACE_TOPBAR: /* Topbar (needed after topbar merge) */ | ||||
| case SPACE_VIEW3D: /* 3D-View */ | case SPACE_VIEW3D: /* 3D-View */ | ||||
| { | { | ||||
| if (ob && (ob->type == OB_GPENCIL)) { | |||||
| /* GP Object */ | |||||
| if (r_ptr) { | |||||
| RNA_id_pointer_create(&ob->id, r_ptr); | |||||
| } | |||||
| return (bGPdata **)&ob->data; | |||||
| } | |||||
| else { | |||||
| /* Annotations */ | |||||
| /* XXX: */ | |||||
| if (r_ptr) { | if (r_ptr) { | ||||
| RNA_id_pointer_create(&scene->id, r_ptr); | RNA_id_pointer_create(&scene->id, r_ptr); | ||||
| } | } | ||||
| return &scene->gpd; | return &scene->gpd; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case SPACE_NODE: /* Nodes Editor */ | case SPACE_NODE: /* Nodes Editor */ | ||||
| { | { | ||||
| SpaceNode *snode = (SpaceNode *)sl; | SpaceNode *snode = (SpaceNode *)sl; | ||||
| /* return the GP data for the active node block/node */ | /* return the GP data for the active node block/node */ | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | bGPdata **ED_annotation_data_get_pointers_direct(ID *screen_id, | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* Get pointer to active Grease Pencil datablock, | /* Get pointer to active Grease Pencil datablock, | ||||
| * and an RNA-pointer to trace back to whatever owns it. */ | * and an RNA-pointer to trace back to whatever owns it. */ | ||||
| bGPdata **ED_gpencil_data_get_pointers(const bContext *C, PointerRNA *r_ptr) | bGPdata **ED_gpencil_data_get_pointers(const bContext *C, PointerRNA *r_ptr) | ||||
| { | { | ||||
| ID *screen_id = (ID *)CTX_wm_screen(C); | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| return ED_gpencil_data_get_pointers_direct(screen_id, sa, scene, ob, r_ptr); | return ED_gpencil_data_get_pointers_direct(sa, ob, r_ptr); | ||||
| } | } | ||||
| /* Get pointer to active Grease Pencil datablock, | |||||
| * and an RNA-pointer to trace back to whatever owns it. */ | |||||
| bGPdata **ED_annotation_data_get_pointers(const bContext *C, PointerRNA *r_ptr) | |||||
| { | |||||
| ID *screen_id = (ID *)CTX_wm_screen(C); | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| ScrArea *sa = CTX_wm_area(C); | |||||
| return ED_annotation_data_get_pointers_direct(screen_id, sa, scene, r_ptr); | |||||
| } | |||||
| /* -------------------------------------------------------- */ | /* -------------------------------------------------------- */ | ||||
| /* Get the active Grease Pencil datablock, when context is not available */ | /* Get the active Grease Pencil datablock, when context is not available */ | ||||
| bGPdata *ED_gpencil_data_get_active_direct(ID *screen_id, ScrArea *sa, Scene *scene, Object *ob) | bGPdata *ED_gpencil_data_get_active_direct(ScrArea *sa, Object *ob) | ||||
| { | |||||
| bGPdata **gpd_ptr = ED_gpencil_data_get_pointers_direct(sa, ob, NULL); | |||||
| return (gpd_ptr) ? *(gpd_ptr) : NULL; | |||||
| } | |||||
| /* Get the active Grease Pencil datablock, when context is not available */ | |||||
| bGPdata *ED_annotation_data_get_active_direct(ID *screen_id, ScrArea *sa, Scene *scene) | |||||
| { | { | ||||
| bGPdata **gpd_ptr = ED_gpencil_data_get_pointers_direct(screen_id, sa, scene, ob, NULL); | bGPdata **gpd_ptr = ED_annotation_data_get_pointers_direct(screen_id, sa, scene, NULL); | ||||
| return (gpd_ptr) ? *(gpd_ptr) : NULL; | return (gpd_ptr) ? *(gpd_ptr) : NULL; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the active Grease Pencil datablock | * Get the active Grease Pencil datablock | ||||
| */ | |||||
| bGPdata *ED_gpencil_data_get_active(const bContext *C) | |||||
| { | |||||
| Object *ob = CTX_data_active_object(C); | |||||
| if (ob == NULL) { | |||||
| return NULL; | |||||
| } | |||||
| bGPdata *gpd = (bGPdata *)ob->data; | |||||
| return gpd; | |||||
| } | |||||
| /* Get the active Grease Pencil datablock | |||||
| * \note This is the original (bmain) copy of the datablock, stored in files. | * \note This is the original (bmain) copy of the datablock, stored in files. | ||||
| * Do not use for reading evaluated copies of GP Objects data | * Do not use for reading evaluated copies of GP Objects data | ||||
| */ | */ | ||||
| bGPdata *ED_gpencil_data_get_active(const bContext *C) | bGPdata *ED_annotation_data_get_active(const bContext *C) | ||||
| { | { | ||||
| bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL); | bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, NULL); | ||||
| return (gpd_ptr) ? *(gpd_ptr) : NULL; | return (gpd_ptr) ? *(gpd_ptr) : NULL; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the evaluated copy of the active Grease Pencil datablock (where applicable) | * Get the evaluated copy of the active Grease Pencil datablock (where applicable) | ||||
| * - For the 3D View (i.e. "GP Objects"), this gives the evaluated copy of the GP datablock | * - For the 3D View (i.e. "GP Objects"), this gives the evaluated copy of the GP datablock | ||||
| * (i.e. a copy of the active GP datablock for the active object, where modifiers have been | * (i.e. a copy of the active GP datablock for the active object, where modifiers have been | ||||
| * applied). This is needed to correctly work with "Copy-on-Write". | * applied). This is needed to correctly work with "Copy-on-Write". | ||||
| * - For all other editors (i.e. "GP Annotations"), this just gives the active datablock | * - For all other editors (i.e. "GP Annotations"), this just gives the active datablock | ||||
| * like for #ED_gpencil_data_get_active() | * like for #ED_gpencil_data_get_active() | ||||
| */ | */ | ||||
| bGPdata *ED_gpencil_data_get_active_evaluated(const bContext *C) | bGPdata *ED_gpencil_data_get_active_evaluated(const bContext *C) | ||||
| { | { | ||||
| ID *screen_id = (ID *)CTX_wm_screen(C); | |||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | |||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | ||||
| #if 0 | return ED_gpencil_data_get_active_direct(sa, ob_eval); | ||||
| if (ob && ob->type == OB_GPENCIL) { | |||||
| BLI_assert(ob_eval->data == DEG_get_evaluated_id(ob->data)); | |||||
| } | |||||
| #endif | |||||
| return ED_gpencil_data_get_active_direct(screen_id, sa, scene_eval, ob_eval); | |||||
| } | } | ||||
| /* -------------------------------------------------------- */ | /* -------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * Utility to check whether the r_ptr output of ED_gpencil_data_get_pointers() | * Utility to check whether the r_ptr output of ED_gpencil_data_get_pointers() | ||||
| * is for annotation usage. | * is for annotation usage. | ||||
| */ | */ | ||||
| Show All 29 Lines | |||||
| } | } | ||||
| /* ******************************************************** */ | /* ******************************************************** */ | ||||
| /* Poll Callbacks */ | /* Poll Callbacks */ | ||||
| /* poll callback for adding data/layers - special */ | /* poll callback for adding data/layers - special */ | ||||
| bool gp_add_poll(bContext *C) | bool gp_add_poll(bContext *C) | ||||
| { | { | ||||
| /* the base line we have is that we have somewhere to add Grease Pencil data */ | Object *ob = CTX_data_active_object(C); | ||||
| return ED_gpencil_data_get_pointers(C, NULL) != NULL; | if (ob == NULL) { | ||||
| return false; | |||||
| } | |||||
| bGPdata *gpd = (bGPdata *)ob->data; | |||||
| return (gpd != NULL); | |||||
| } | } | ||||
| /* poll callback for checking if there is an active layer */ | /* poll callback for checking if there is an active layer */ | ||||
| bool gp_active_layer_poll(bContext *C) | bool gp_active_layer_poll(bContext *C) | ||||
| { | { | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | Object *ob = CTX_data_active_object(C); | ||||
| if (ob == NULL) { | |||||
| return false; | |||||
| } | |||||
| bGPdata *gpd = (bGPdata *)ob->data; | |||||
| bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); | bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); | ||||
| return (gpl != NULL); | return (gpl != NULL); | ||||
| } | } | ||||
| /* poll callback for checking if there is an active brush */ | /* poll callback for checking if there is an active brush */ | ||||
| bool gp_active_brush_poll(bContext *C) | bool gp_active_brush_poll(bContext *C) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 2,254 Lines • Show Last 20 Lines | |||||
Why is this part of the patch?