Blender V4.3
space_statusbar.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstdio>
10#include <cstring>
11
12#include "MEM_guardedalloc.h"
13
14#include "BLI_blenlib.h"
15
16#include "BKE_context.hh"
17#include "BKE_screen.hh"
18
19#include "ED_screen.hh"
20#include "ED_space_api.hh"
21
22#include "UI_interface.hh"
23
24#include "BLO_read_write.hh"
25
26#include "WM_message.hh"
27#include "WM_types.hh"
28
29/* ******************** default callbacks for statusbar space ******************** */
30
31static SpaceLink *statusbar_create(const ScrArea * /*area*/, const Scene * /*scene*/)
32{
33 ARegion *region;
34 SpaceStatusBar *sstatusbar;
35
36 sstatusbar = static_cast<SpaceStatusBar *>(MEM_callocN(sizeof(*sstatusbar), "init statusbar"));
37 sstatusbar->spacetype = SPACE_STATUSBAR;
38
39 /* header region */
40 region = static_cast<ARegion *>(MEM_callocN(sizeof(*region), "header for statusbar"));
41 BLI_addtail(&sstatusbar->regionbase, region);
42 region->regiontype = RGN_TYPE_HEADER;
43 region->alignment = RGN_ALIGN_NONE;
44
45 return (SpaceLink *)sstatusbar;
46}
47
48/* Doesn't free the space-link itself. */
49static void statusbar_free(SpaceLink * /*sl*/) {}
50
51/* spacetype; init callback */
52static void statusbar_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
53
55{
56 SpaceStatusBar *sstatusbarn = static_cast<SpaceStatusBar *>(MEM_dupallocN(sl));
57
58 /* clear or remove stuff from old */
59
60 return (SpaceLink *)sstatusbarn;
61}
62
63/* add handlers, stuff you only do once or on area/region changes */
65{
66 if (ELEM(RGN_ALIGN_ENUM_FROM_MASK(region->alignment), RGN_ALIGN_RIGHT)) {
67 region->flag |= RGN_FLAG_DYNAMIC_SIZE;
68 }
70}
71
73
74static void statusbar_keymap(wmKeyConfig * /*keyconf*/) {}
75
77{
78 ARegion *region = params->region;
79 const wmNotifier *wmn = params->notifier;
80
81 /* context changes */
82 switch (wmn->category) {
83 case NC_SCREEN:
84 if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) {
86 }
87 break;
88 case NC_WM:
89 if (wmn->data == ND_JOB) {
91 }
92 break;
93 case NC_SCENE:
94 if (wmn->data == ND_RENDER_RESULT) {
96 }
97 break;
98 case NC_SPACE:
99 if (wmn->data == ND_SPACE_INFO) {
100 ED_region_tag_redraw(region);
101 }
102 break;
103 case NC_ID:
104 if (wmn->action == NA_RENAME) {
105 ED_region_tag_redraw(region);
106 }
107 break;
108 }
109}
110
112{
113 wmMsgBus *mbus = params->message_bus;
114 ARegion *region = params->region;
115
116 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
117 msg_sub_value_region_tag_redraw.owner = region;
118 msg_sub_value_region_tag_redraw.user_data = region;
119 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
120
121 WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
122 WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
123}
124
126{
127 BLO_write_struct(writer, SpaceStatusBar, sl);
128}
129
131{
132 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
133 ARegionType *art;
134
135 st->spaceid = SPACE_STATUSBAR;
136 STRNCPY(st->name, "Status Bar");
137
138 st->create = statusbar_create;
139 st->free = statusbar_free;
140 st->init = statusbar_init;
141 st->duplicate = statusbar_duplicate;
142 st->operatortypes = statusbar_operatortypes;
143 st->keymap = statusbar_keymap;
144 st->blend_write = statusbar_space_blend_write;
145
146 /* regions: header window */
147 art = static_cast<ARegionType *>(MEM_callocN(sizeof(*art), "spacetype statusbar header region"));
149 art->prefsizey = 0.8f * HEADERY;
150 art->prefsizex = UI_UNIT_X * 5; /* Mainly to avoid glitches */
157 BLI_addhead(&st->regiontypes, art);
158
159 BKE_spacetype_register(std::move(st));
160}
void BKE_spacetype_register(std::unique_ptr< SpaceType > st)
Definition screen.cc:268
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:90
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:110
#define STRNCPY(dst, src)
Definition BLI_string.h:593
#define ELEM(...)
#define BLO_write_struct(writer, struct_name, data_ptr)
#define HEADERY
#define RGN_ALIGN_ENUM_FROM_MASK(align)
@ RGN_ALIGN_RIGHT
@ RGN_ALIGN_NONE
@ RGN_TYPE_HEADER
@ RGN_FLAG_DYNAMIC_SIZE
@ SPACE_STATUSBAR
void ED_region_header_init(ARegion *region)
Definition area.cc:3661
void ED_region_header_draw(const bContext *C, ARegion *region)
Definition area.cc:3621
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:634
@ ED_KEYMAP_UI
Definition ED_screen.hh:725
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:731
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:728
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:381
void ED_region_header_layout(const bContext *C, ARegion *region)
Definition area.cc:3522
Read Guarded memory(de)allocation.
#define UI_UNIT_X
#define NC_ID
Definition WM_types.hh:362
#define ND_SPACE_INFO
Definition WM_types.hh:487
#define ND_RENDER_RESULT
Definition WM_types.hh:413
#define ND_JOB
Definition WM_types.hh:383
#define NC_WM
Definition WM_types.hh:341
#define NC_SCREEN
Definition WM_types.hh:344
#define ND_ANIMPLAY
Definition WM_types.hh:391
#define NC_SCENE
Definition WM_types.hh:345
#define ND_LAYER
Definition WM_types.hh:417
#define NA_RENAME
Definition WM_types.hh:554
#define NC_SPACE
Definition WM_types.hh:359
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
void *(* MEM_dupallocN)(const void *vmemh)
Definition mallocn.cc:39
static void statusbar_header_region_init(wmWindowManager *, ARegion *region)
static SpaceLink * statusbar_duplicate(SpaceLink *sl)
static void statusbar_keymap(wmKeyConfig *)
static SpaceLink * statusbar_create(const ScrArea *, const Scene *)
static void statusbar_init(wmWindowManager *, ScrArea *)
static void statusbar_header_region_listener(const wmRegionListenerParams *params)
void ED_spacetype_statusbar()
static void statusbar_operatortypes()
static void statusbar_free(SpaceLink *)
static void statusbar_header_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
static void statusbar_space_blend_write(BlendWriter *writer, SpaceLink *sl)
void(* message_subscribe)(const wmRegionMessageSubscribeParams *params)
void(* listener)(const wmRegionListenerParams *params)
void(* draw)(const bContext *C, ARegion *region)
void(* layout)(const bContext *C, ARegion *region)
void(* init)(wmWindowManager *wm, ARegion *region)
unsigned int data
Definition WM_types.hh:325
unsigned int action
Definition WM_types.hh:325
unsigned int category
Definition WM_types.hh:325
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)