Blender V5.0
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
8
9#include <cstring>
10
11#include "MEM_guardedalloc.h"
12
13#include "BLI_listbase.h"
14#include "BLI_string_utf8.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 = MEM_callocN<SpaceStatusBar>("init statusbar");
37 sstatusbar->spacetype = SPACE_STATUSBAR;
38
39 /* header region */
40 region = BKE_area_region_new();
41 BLI_addtail(&sstatusbar->regionbase, region);
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{
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_UTF8(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 = MEM_callocN<ARegionType>("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:282
ARegion * BKE_area_region_new()
Definition screen.cc:387
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:91
#define STRNCPY_UTF8(dst, src)
#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:3950
void ED_region_header_draw(const bContext *C, ARegion *region)
Definition area.cc:3902
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:618
@ ED_KEYMAP_UI
Definition ED_screen.hh:758
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:764
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:761
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:361
void ED_region_header_layout(const bContext *C, ARegion *region)
Definition area.cc:3801
#define Window
Read Guarded memory(de)allocation.
#define UI_UNIT_X
#define NC_ID
Definition WM_types.hh:395
#define ND_SPACE_INFO
Definition WM_types.hh:521
#define ND_RENDER_RESULT
Definition WM_types.hh:446
#define ND_JOB
Definition WM_types.hh:416
#define NC_WM
Definition WM_types.hh:374
#define NC_SCREEN
Definition WM_types.hh:377
#define ND_ANIMPLAY
Definition WM_types.hh:424
#define NC_SCENE
Definition WM_types.hh:378
#define ND_LAYER
Definition WM_types.hh:450
#define NA_RENAME
Definition WM_types.hh:588
#define NC_SPACE
Definition WM_types.hh:392
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_dupallocN(const void *vmemh)
Definition mallocn.cc:143
const char * name
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:358
unsigned int action
Definition WM_types.hh:358
unsigned int category
Definition WM_types.hh:358
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)