Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/screen.c
| Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "DNA_workspace_types.h" | #include "DNA_workspace_types.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_rect.h" | #include "BLI_rect.h" | ||||
| #include "BLI_string.h" | |||||
| #include "BKE_icons.h" | #include "BKE_icons.h" | ||||
| #include "BKE_idprop.h" | #include "BKE_idprop.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_workspace.h" | #include "BKE_workspace.h" | ||||
| #include "RNA_define.h" | |||||
| /* ************ Spacetype/regiontype handling ************** */ | /* ************ Spacetype/regiontype handling ************** */ | ||||
| /* keep global; this has to be accessible outside of windowmanager */ | /* keep global; this has to be accessible outside of windowmanager */ | ||||
| static ListBase spacetypes = {NULL, NULL}; | static ListBase spacetypes = {NULL, NULL}; | ||||
| /* not SpaceType itself */ | /* not SpaceType itself */ | ||||
| static void spacetype_free(SpaceType *st) | static void spacetype_free(SpaceType *st) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 775 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| return ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL); | return ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL); | ||||
| } | } | ||||
| bool BKE_screen_is_used(const bScreen *screen) | bool BKE_screen_is_used(const bScreen *screen) | ||||
| { | { | ||||
| return (screen->winid != 0); | return (screen->winid != 0); | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Dynamic Space Type API | |||||
| * \{ */ | |||||
| #define SPACE_TYPE_LEN (SPACE_TYPE_LAST + 1) | |||||
| typedef struct SpaceTypeDyn { | |||||
| struct SpaceTypeDyn *next, *prev; | |||||
| /** Used in enum. */ | |||||
| char idname[MAX_NAME]; | |||||
| /** Used in UI. */ | |||||
| char label[MAX_NAME]; | |||||
| int icon; | |||||
| /* Inherit from this. */ | |||||
| int base_space_type; | |||||
| struct { | |||||
| void (*draw_main_region)(const struct bContext *C, struct ARegion *ar); | |||||
| } callbacks; | |||||
| /* Py/RNA info. */ | |||||
| ExtensionRNA ext; | |||||
| } SpaceTypeDyn; | |||||
| static ListBase g_dyn_space_types[SPACE_TYPE_LEN] = {NULL}; | |||||
| static SpaceTypeDyn *screen_dynspace_find_by_name(int space_type, const char *idname) | |||||
| { | |||||
| BLI_assert(space_type < SPACE_TYPE_LEN); | |||||
| const ListBase *lb = &g_dyn_space_types[space_type]; | |||||
| return BLI_findstring(lb, idname, offsetof(SpaceTypeDyn, idname)); | |||||
| } | |||||
| SpaceTypeDyn *BKE_screen_dynspace_register( | |||||
| int space_type, const char *idname, const char *label, int icon) | |||||
| { | |||||
| BLI_assert(space_type < SPACE_TYPE_LEN); | |||||
| ListBase *lb = &g_dyn_space_types[space_type]; | |||||
| SpaceTypeDyn *ds = screen_dynspace_find_by_name(space_type, idname); | |||||
| if (ds != NULL) { | |||||
| /* This exists, fail. */ | |||||
| return false; | |||||
| } | |||||
| ds = MEM_callocN(sizeof(*ds), __func__); | |||||
| STRNCPY(ds->idname, idname); | |||||
| STRNCPY(ds->label, label); | |||||
| ds->icon = icon; | |||||
| ds->base_space_type = space_type; | |||||
| BLI_addtail(lb, ds); | |||||
| return ds; | |||||
| } | |||||
| ExtensionRNA *BKE_screen_dynspace_get_rna_ext(SpaceTypeDyn *ds) | |||||
| { | |||||
| return &ds->ext; | |||||
| } | |||||
| void BKE_screen_dynspace_set_main_region_draw( | |||||
| SpaceTypeDyn *ds, | |||||
| void (*draw_main_region)(const struct bContext *C, struct ARegion *ar)) | |||||
| { | |||||
| ds->callbacks.draw_main_region = draw_main_region; | |||||
| } | |||||
| void BKE_screen_dynspace_call_main_region_draw( | |||||
| SpaceTypeDyn *ds, | |||||
| const struct bContext *C, struct ARegion *ar) | |||||
| { | |||||
| ds->callbacks.draw_main_region(C, ar); | |||||
| } | |||||
| void BKE_screen_dynspace_enum_item_extend( | |||||
| int space_type, struct EnumPropertyItem **item, int *totitem) | |||||
| { | |||||
| EnumPropertyItem temp_item = {0}; | |||||
| ListBase *lb = &g_dyn_space_types[space_type]; | |||||
| int i = 0; | |||||
| for (SpaceTypeDyn *ds = lb->first; ds; ds = ds->next, i++) { | |||||
| temp_item.name = ds->label; | |||||
| temp_item.identifier = ds->idname; | |||||
| temp_item.value = i | SPACE_DYN_FLAG | (space_type << 16); | |||||
| temp_item.icon = ds->icon; | |||||
| RNA_enum_item_add(item, totitem, &temp_item); | |||||
| } | |||||
| } | |||||
| SpaceTypeDyn *BKE_screen_dynspace_from_index( | |||||
| int space_type, int space_subtype) | |||||
| { | |||||
| BLI_assert(space_type < SPACE_TYPE_LEN); | |||||
| ListBase *lb = &g_dyn_space_types[space_type]; | |||||
| SpaceTypeDyn *ds = BLI_findlink(lb, space_subtype); | |||||
| return ds; | |||||
| } | |||||
| /** \} */ | |||||