1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software Foundation, 14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 * 16 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 17 * All rights reserved. 18 */ 19 #pragma once 20 21 /** \file 22 * \ingroup bke 23 */ 24 25 #include "BLI_compiler_attrs.h" 26 27 #include "RNA_types.h" 28 29 #include "BKE_context.h" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 struct ARegion; 36 struct Header; 37 struct ID; 38 struct LibraryForeachIDData; 39 struct ListBase; 40 struct Menu; 41 struct Panel; 42 struct Scene; 43 struct ScrArea; 44 struct ScrAreaMap; 45 struct ScrVert; 46 struct SpaceType; 47 struct View3D; 48 struct View3DShading; 49 struct WorkSpace; 50 struct bContext; 51 struct bContextDataResult; 52 struct bScreen; 53 struct uiLayout; 54 struct uiList; 55 struct wmGizmoMap; 56 struct wmKeyConfig; 57 struct wmMsgBus; 58 struct wmNotifier; 59 struct wmWindow; 60 struct wmWindowManager; 61 62 /* spacetype has everything stored to get an editor working, it gets initialized via 63 * ED_spacetypes_init() in editors/space_api/spacetypes.c */ 64 /* an editor in Blender is a combined ScrArea + SpaceType + SpaceData */ 65 66 #define BKE_ST_MAXNAME 64 67 68 typedef struct SpaceType { 69 struct SpaceType *next, *prev; 70 71 char name[BKE_ST_MAXNAME]; /* for menus */ 72 int spaceid; /* unique space identifier */ 73 int iconid; /* icon lookup for menus */ 74 75 /* Initial allocation, after this WM will call init() too. Some editors need 76 * area and scene data (e.g. frame range) to set their initial scrolling. */ 77 struct SpaceLink *(*create)(const struct ScrArea *area, const struct Scene *scene); 78 /* not free spacelink itself */ 79 void (*free)(struct SpaceLink *sl); 80 81 /* init is to cope with file load, screen (size) changes, check handlers */ 82 void (*init)(struct wmWindowManager *wm, struct ScrArea *area); 83 /* exit is called when the area is hidden or removed */ 84 void (*exit)(struct wmWindowManager *wm, struct ScrArea *area); 85 /* Listeners can react to bContext changes */ 86 void (*listener)(struct wmWindow *win, 87 struct ScrArea *area, 88 struct wmNotifier *wmn, 89 struct Scene *scene); 90 91 /* called when the mouse moves out of the area */ 92 void (*deactivate)(struct ScrArea *area); 93 94 /* refresh context, called after filereads, ED_area_tag_refresh() */ 95 void (*refresh)(const struct bContext *C, struct ScrArea *area); 96 97 /* after a spacedata copy, an init should result in exact same situation */ 98 struct SpaceLink *(*duplicate)(struct SpaceLink *sl); 99 100 /* register operator types on startup */ 101 void (*operatortypes)(void); 102 /* add default items to WM keymap */ 103 void (*keymap)(struct wmKeyConfig *keyconf); 104 /* on startup, define dropboxes for spacetype+regions */ 105 void (*dropboxes)(void); 106 107 /* initialize gizmo-map-types and gizmo-group-types with the region */ 108 void (*gizmos)(void); 109 110 /* return context data */ 111 bContextDataCallback context; 112 113 /* Used when we want to replace an ID by another (or NULL). */ 114 void (*id_remap)(struct ScrArea *area, 115 struct SpaceLink *sl, 116 struct ID *old_id, 117 struct ID *new_id); 118 119 int (*space_subtype_get)(struct ScrArea *area); 120 void (*space_subtype_set)(struct ScrArea *area, int value); 121 void (*space_subtype_item_extend)(struct bContext *C, EnumPropertyItem **item, int *totitem); 122 123 /* region type definitions */ 124 ListBase regiontypes; 125 126 /* read and write... */ 127 128 /* default keymaps to add */ 129 int keymapflag; 130 131 } SpaceType; 132 133 /* region types are also defined using spacetypes_init, via a callback */ 134 135 typedef struct ARegionType { 136 struct ARegionType *next, *prev; 137 138 int regionid; /* unique identifier within this space, defines RGN_TYPE_xxxx */ 139 140 /* add handlers, stuff you only do once or on area/region type/size changes */ 141 void (*init)(struct wmWindowManager *wm, struct ARegion *region); 142 /* exit is called when the region is hidden or removed */ 143 void (*exit)(struct wmWindowManager *wm, struct ARegion *region); 144 /* draw entirely, view changes should be handled here */ 145 void (*draw)(const struct bContext *C, struct ARegion *region); 146 /** 147 * Handler to draw overlays. This handler is called every draw loop. 148 * 149 * \note Some editors should return early if the interface is locked 150 * (check with #CTX_wm_interface_locked) to avoid accessing scene data 151 * that another thread may be modifying 152 */ 153 void (*draw_overlay)(const struct bContext *C, struct ARegion *region); 154 /* optional, compute button layout before drawing for dynamic size */ 155 void (*layout)(const struct bContext *C, struct ARegion *region); 156 /* snap the size of the region (can be NULL for no snapping). */ 157 int (*snap_size)(const struct ARegion *region, int size, int axis); 158 /* contextual changes should be handled here */ 159 void (*listener)(struct wmWindow *win, 160 struct ScrArea *area, 161 struct ARegion *region, 162 struct wmNotifier *wmn, 163 const struct Scene *scene); 164 /* Optional callback to generate subscriptions. */ 165 void (*message_subscribe)(const struct bContext *C, 166 struct WorkSpace *workspace, 167 struct Scene *scene, 168 struct bScreen *screen, 169 struct ScrArea *area, 170 struct ARegion *region, 171 struct wmMsgBus *mbus); 172 173 void (*free)(struct ARegion *); 174 175 /* split region, copy data optionally */ 176 void *(*duplicate)(void *poin); 177 178 /* register operator types on startup */ 179 void (*operatortypes)(void); 180 /* add own items to keymap */ 181 void (*keymap)(struct wmKeyConfig *keyconf); 182 /* allows default cursor per region */ 183 void (*cursor)(struct wmWindow *win, struct ScrArea *area, struct ARegion *region); 184 185 /* return context data */ 186 bContextDataCallback context; 187 188 /* Is called whenever the current visible View2D's region changes. 189 * 190 * Used from user code such as view navigation/zoom operators to inform region about changes. 191 * The goal is to support zoom-to-fit features which gets disabled when manual navigation is 192 * performed. 193 * 194 * This callback is not called on indirect changes of the current viewport (which could happen 195 * when the `v2d->tot is changed and `cur` is adopted accordingly). */ 196 void (*on_view2d_changed)(const struct bContext *C, struct ARegion *region); 197 198 /* custom drawing callbacks */ 199 ListBase drawcalls; 200 201 /* panels type definitions */ 202 ListBase paneltypes; 203 204 /* header type definitions */ 205 ListBase headertypes; 206 207 /* hardcoded constraints, smaller than these values region is not visible */ 208 int minsizex, minsizey; 209 /* when new region opens (region prefsizex/y are zero then */ 210 int prefsizex, prefsizey; 211 /* default keymaps to add */ 212 int keymapflag; 213 /* return without drawing. 214 * lock is set by region definition, and copied to do_lock by render. can become flag. */ 215 short do_lock, lock; 216 /** Don't handle gizmos events behind #uiBlock's with #UI_BLOCK_CLIP_EVENTS flag set. */ 217 bool clip_gizmo_events_by_ui; 218 /* call cursor function on each move event */ 219 short event_cursor; 220 } ARegionType; 221 222 /* panel types */ 223 224 typedef struct PanelType { 225 struct PanelType *next, *prev; 226 227 char idname[BKE_ST_MAXNAME]; /* unique name */ 228 char label[BKE_ST_MAXNAME]; /* for panel header */ 229 char translation_context[BKE_ST_MAXNAME]; 230 char context[BKE_ST_MAXNAME]; /* for buttons window */ 231 char category[BKE_ST_MAXNAME]; /* for category tabs */ 232 char owner_id[BKE_ST_MAXNAME]; /* for work-spaces to selectively show. */ 233 char parent_id[BKE_ST_MAXNAME]; /* parent idname for sub-panels */ 234 short space_type; 235 short region_type; 236 /* For popovers, 0 for default. */ 237 int ui_units_x; 238 int order; 239 240 int flag; 241 242 /* verify if the panel should draw or not */ 243 bool (*poll)(const struct bContext *C, struct PanelType *pt); 244 /* draw header (optional) */ 245 void (*draw_header)(const struct bContext *C, struct Panel *panel); 246 /* draw header preset (optional) */ 247 void (*draw_header_preset)(const struct bContext *C, struct Panel *panel); 248 /* draw entirely, view changes should be handled here */ 249 void (*draw)(const struct bContext *C, struct Panel *panel); 250 251 /* For instanced panels corresponding to a list: */ 252 253 /** Reorder function, called when drag and drop finishes. */ 254 void (*reorder)(struct bContext *C, struct Panel *pa, int new_index); 255 /** 256 * Get the panel and sub-panel's expansion state from the expansion flag in the corresponding 257 * data item. Called on draw updates. 258 * \note Sub-panels are indexed in depth first order, 259 * the visual order you would see if all panels were expanded. 260 */ 261 short (*get_list_data_expand_flag)(const struct bContext *C, struct Panel *pa); 262 /** 263 * Set the expansion bit-field from the closed / open state of this panel and its sub-panels. 264 * Called when the expansion state of the panel changes with user input. 265 * \note Sub-panels are indexed in depth first order, 266 * the visual order you would see if all panels were expanded. 267 */ 268 void (*set_list_data_expand_flag)(const struct bContext *C, struct Panel *pa, short expand_flag); 269 270 /* sub panels */ 271 struct PanelType *parent; 272 ListBase children; 273 274 /* RNA integration */ 275 ExtensionRNA rna_ext; 276 } PanelType; 277 278 /* uilist types */ 279 280 /* Draw an item in the uiList */ 281 typedef void (*uiListDrawItemFunc)(struct uiList *ui_list, 282 struct bContext *C, 283 struct uiLayout *layout, 284 struct PointerRNA *dataptr, 285 struct PointerRNA *itemptr, 286 int icon, 287 struct PointerRNA *active_dataptr, 288 const char *active_propname, 289 int index, 290 int flt_flag); 291 292 /* Draw the filtering part of an uiList */ 293 typedef void (*uiListDrawFilterFunc)(struct uiList *ui_list, 294 struct bContext *C, 295 struct uiLayout *layout); 296 297 /* Filter items of an uiList */ 298 typedef void (*uiListFilterItemsFunc)(struct uiList *ui_list, 299 struct bContext *C, 300 struct PointerRNA *, 301 const char *propname); 302 303 typedef struct uiListType { 304 struct uiListType *next, *prev; 305 306 char idname[BKE_ST_MAXNAME]; /* unique name */ 307 308 uiListDrawItemFunc draw_item; 309 uiListDrawFilterFunc draw_filter; 310 uiListFilterItemsFunc filter_items; 311 312 /* RNA integration */ 313 ExtensionRNA rna_ext; 314 } uiListType; 315 316 /* header types */ 317 318 typedef struct HeaderType { 319 struct HeaderType *next, *prev; 320 321 char idname[BKE_ST_MAXNAME]; /* unique name */ 322 int space_type; 323 int region_type; 324 325 bool (*poll)(const struct bContext *C, struct HeaderType *ht); 326 /* draw entirely, view changes should be handled here */ 327 void (*draw)(const struct bContext *C, struct Header *header); 328 329 /* RNA integration */ 330 ExtensionRNA rna_ext; 331 } HeaderType; 332 333 typedef struct Header { 334 struct HeaderType *type; /* runtime */ 335 struct uiLayout *layout; /* runtime for drawing */ 336 } Header; 337 338 /* menu types */ 339 340 typedef struct MenuType { 341 struct MenuType *next, *prev; 342 343 char idname[BKE_ST_MAXNAME]; /* unique name */ 344 char label[BKE_ST_MAXNAME]; /* for button text */ 345 char translation_context[BKE_ST_MAXNAME]; 346 char owner_id[BKE_ST_MAXNAME]; /* optional, see: #wmOwnerID */ 347 const char *description; 348 349 /* verify if the menu should draw or not */ 350 bool (*poll)(const struct bContext *C, struct MenuType *mt); 351 /* draw entirely, view changes should be handled here */ 352 void (*draw)(const struct bContext *C, struct Menu *menu); 353 354 /* RNA integration */ 355 ExtensionRNA rna_ext; 356 } MenuType; 357 358 typedef struct Menu { 359 struct MenuType *type; /* runtime */ 360 struct uiLayout *layout; /* runtime for drawing */ 361 } Menu; 362 363 /* spacetypes */ 364 struct SpaceType *BKE_spacetype_from_id(int spaceid); 365 struct ARegionType *BKE_regiontype_from_id_or_first(struct SpaceType *st, int regionid); 366 struct ARegionType *BKE_regiontype_from_id(struct SpaceType *st, int regionid); 367 const struct ListBase *BKE_spacetypes_list(void); 368 void BKE_spacetype_register(struct SpaceType *st); 369 bool BKE_spacetype_exists(int spaceid); 370 void BKE_spacetypes_free(void); /* only for quitting blender */ 371 372 /* spacedata */ 373 void BKE_spacedata_freelist(ListBase *lb); 374 void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2); 375 void BKE_spacedata_draw_locks(int set); 376 377 struct ARegion *BKE_spacedata_find_region_type(const struct SpaceLink *slink, 378 const struct ScrArea *area, 379 int region_type) ATTR_WARN_UNUSED_RESULT 380 ATTR_NONNULL(); 381 382 void BKE_spacedata_callback_id_remap_set(void (*func)( 383 struct ScrArea *area, struct SpaceLink *sl, struct ID *old_id, struct ID *new_id)); 384 void BKE_spacedata_id_unref(struct ScrArea *area, struct SpaceLink *sl, struct ID *id); 385 386 /* area/regions */ 387 struct ARegion *BKE_area_region_copy(struct SpaceType *st, struct ARegion *region); 388 void BKE_area_region_free(struct SpaceType *st, struct ARegion *region); 389 void BKE_area_region_panels_free(struct ListBase *panels); 390 void BKE_screen_area_free(struct ScrArea *area); 391 /* Gizmo-maps of a region need to be freed with the region. 392 * Uses callback to avoid low-level call. */ 393 void BKE_region_callback_free_gizmomap_set(void (*callback)(struct wmGizmoMap *)); 394 void BKE_region_callback_refresh_tag_gizmomap_set(void (*callback)(struct wmGizmoMap *)); 395 396 struct ARegion *BKE_area_find_region_type(const struct ScrArea *area, int type); 397 struct ARegion *BKE_area_find_region_active_win(struct ScrArea *area); 398 struct ARegion *BKE_area_find_region_xy(struct ScrArea *area, const int regiontype, int x, int y); 399 struct ARegion *BKE_screen_find_region_xy(struct bScreen *screen, 400 const int regiontype, 401 int x, 402 int y) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); 403 404 struct ARegion *BKE_screen_find_main_region_at_xy(struct bScreen *screen, 405 const int space_type, 406 const int x, 407 const int y); 408 409 struct ScrArea *BKE_screen_find_area_from_space(struct bScreen *screen, 410 struct SpaceLink *sl) ATTR_WARN_UNUSED_RESULT 411 ATTR_NONNULL(1, 2); 412 struct ScrArea *BKE_screen_find_big_area(struct bScreen *screen, 413 const int spacetype, 414 const short min); 415 struct ScrArea *BKE_screen_area_map_find_area_xy(const struct ScrAreaMap *areamap, 416 const int spacetype, 417 int x, 418 int y); 419 struct ScrArea *BKE_screen_find_area_xy(struct bScreen *screen, const int spacetype, int x, int y); 420 421 void BKE_screen_gizmo_tag_refresh(struct bScreen *screen); 422 423 void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene); 424 void BKE_screen_view3d_scene_sync(struct bScreen *screen, struct Scene *scene); 425 bool BKE_screen_is_fullscreen_area(const struct bScreen *screen) ATTR_WARN_UNUSED_RESULT 426 ATTR_NONNULL(); 427 bool BKE_screen_is_used(const struct bScreen *screen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); 428 429 /* zoom factor conversion */ 430 float BKE_screen_view3d_zoom_to_fac(float camzoom); 431 float BKE_screen_view3d_zoom_from_fac(float zoomfac); 432 433 void BKE_screen_view3d_shading_init(struct View3DShading *shading); 434 435 /* screen */ 436 void BKE_screen_foreach_id_screen_area(struct LibraryForeachIDData *data, struct ScrArea *area); 437 438 void BKE_screen_free(struct bScreen *screen); 439 void BKE_screen_area_map_free(struct ScrAreaMap *area_map) ATTR_NONNULL(); 440 441 struct ScrEdge *BKE_screen_find_edge(const struct bScreen *screen, 442 struct ScrVert *v1, 443 struct ScrVert *v2); 444 void BKE_screen_sort_scrvert(struct ScrVert **v1, struct ScrVert **v2); 445 void BKE_screen_remove_double_scrverts(struct bScreen *screen); 446 void BKE_screen_remove_double_scredges(struct bScreen *screen); 447 void BKE_screen_remove_unused_scredges(struct bScreen *screen); 448 void BKE_screen_remove_unused_scrverts(struct bScreen *screen); 449 450 void BKE_screen_header_alignment_reset(struct bScreen *screen); 451 452 #ifdef __cplusplus 453 } 454 #endif 455