Blender V5.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
8
9#include <cstring>
10
11#include "DNA_space_types.h"
12#include "MEM_guardedalloc.h"
13
14#include "BLI_listbase.hh"
15#include "BLI_string_utf8.hh"
16
17#include "BKE_context.hh"
18#include "BKE_screen.hh"
19
20#include "ED_screen.hh"
21#include "ED_space_api.hh"
22
23#include "UI_interface.hh"
24
25#include "BLO_read_write.hh"
26
27#include "WM_message.hh"
28#include "WM_types.hh"
29
30namespace blender {
31
32/* ******************** default callbacks for statusbar space ******************** */
33
34static SpaceLink *statusbar_create(const ScrArea * /*area*/, const Scene * /*scene*/)
35{
36 ARegion *region;
37 SpaceStatusBar *sstatusbar;
38
39 sstatusbar = MEM_new<SpaceStatusBar>("init statusbar");
40 sstatusbar->spacetype = SPACE_STATUSBAR;
41
42 /* header region */
43 region = BKE_area_region_new();
44 BLI_addtail(&sstatusbar->regionbase, region);
46 region->alignment = RGN_ALIGN_NONE;
47
48 return reinterpret_cast<SpaceLink *>(sstatusbar);
49}
50
51/* Doesn't free the space-link itself. */
52static void statusbar_free(SpaceLink * /*sl*/) {}
53
54/* spacetype; init callback */
55static void statusbar_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
56
58{
59 SpaceStatusBar *sstatusbarn = MEM_dupalloc(reinterpret_cast<SpaceStatusBar *>(sl));
60
61 /* clear or remove stuff from old */
62
63 return reinterpret_cast<SpaceLink *>(sstatusbarn);
64}
65
66/* add handlers, stuff you only do once or on area/region changes */
68{
70 region->flag |= RGN_FLAG_DYNAMIC_SIZE;
71 }
73}
74
76
77static void statusbar_keymap(wmKeyConfig * /*keyconf*/) {}
78
80{
81 ARegion *region = params->region;
82 const wmNotifier *wmn = params->notifier;
83
84 /* context changes */
85 switch (wmn->category) {
86 case NC_SCREEN:
87 if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) {
89 }
90 break;
91 case NC_WM:
92 if (wmn->data == ND_JOB) {
94 }
95 break;
96 case NC_SCENE:
97 if (wmn->data == ND_RENDER_RESULT) {
99 }
100 break;
101 case NC_SPACE:
102 if (wmn->data == ND_SPACE_INFO) {
103 ED_region_tag_redraw(region);
104 }
105 break;
106 case NC_ID:
107 if (wmn->action == NA_RENAME) {
108 ED_region_tag_redraw(region);
109 }
110 break;
111 }
112}
113
115{
116 wmMsgBus *mbus = params->message_bus;
117 ARegion *region = params->region;
118
119 wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
120 msg_sub_value_region_tag_redraw.owner = region;
121 msg_sub_value_region_tag_redraw.user_data = region;
122 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
123
124 WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
125 WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
126}
127
129{
131}
132
134{
135 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
136 ARegionType *art;
137
138 st->spaceid = SPACE_STATUSBAR;
139 STRNCPY_UTF8(st->name, "Status Bar");
140 st->struct_size = sizeof(SpaceStatusBar);
141
142 st->create = statusbar_create;
143 st->free = statusbar_free;
144 st->init = statusbar_init;
145 st->duplicate = statusbar_duplicate;
146 st->operatortypes = statusbar_operatortypes;
147 st->keymap = statusbar_keymap;
148 st->blend_write = statusbar_space_blend_write;
149
150 /* regions: header window */
151 art = MEM_new_zeroed<ARegionType>("spacetype statusbar header region");
153 art->prefsizey = 0.8f * HEADERY;
154 art->prefsizex = UI_UNIT_X * 5; /* Mainly to avoid glitches */
161 BLI_addhead(&st->regiontypes, art);
162
163 BKE_spacetype_register(std::move(st));
164}
165
166} // namespace blender
#define STRNCPY_UTF8(dst, src)
#define HEADERY
#define RGN_ALIGN_ENUM_FROM_MASK(align)
#define Window
Read Blender memory allocation and freeing.
#define UI_UNIT_X
#define NC_ID
Definition WM_types.hh:408
#define ND_SPACE_INFO
Definition WM_types.hh:564
#define ND_RENDER_RESULT
Definition WM_types.hh:465
#define ND_JOB
Definition WM_types.hh:432
#define NC_WM
Definition WM_types.hh:387
#define NC_SCREEN
Definition WM_types.hh:390
#define ND_ANIMPLAY
Definition WM_types.hh:441
#define NC_SCENE
Definition WM_types.hh:391
#define ND_LAYER
Definition WM_types.hh:469
#define NA_RENAME
Definition WM_types.hh:638
#define NC_SPACE
Definition WM_types.hh:405
#define ELEM(...)
BMesh Iterators.
static void statusbar_init(wmWindowManager *, ScrArea *)
static SpaceLink * statusbar_create(const ScrArea *, const Scene *)
static void statusbar_header_region_listener(const wmRegionListenerParams *params)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
static void statusbar_header_region_init(wmWindowManager *, ARegion *region)
void ED_region_header_draw(const bContext *C, ARegion *region)
Definition area.cc:4358
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
static void statusbar_header_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
ARegion * BKE_area_region_new()
Definition screen.cc:522
@ ED_KEYMAP_UI
Definition ED_screen.hh:852
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:858
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:855
static void statusbar_keymap(wmKeyConfig *)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void BKE_spacetype_register(std::unique_ptr< SpaceType > st)
Definition screen.cc:379
static void statusbar_free(SpaceLink *)
void ED_spacetype_statusbar()
void ED_region_header_init(ARegion *region)
Definition area.cc:4406
void ED_region_header_layout(const bContext *C, ARegion *region)
Definition area.cc:4257
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:394
static void statusbar_space_blend_write(BlendWriter *writer, SpaceLink *sl)
static void statusbar_operatortypes()
static SpaceLink * statusbar_duplicate(SpaceLink *sl)
void(*) message_subscribe(const wmRegionMessageSubscribeParams *params)
void(*) draw(const bContext *C, ARegion *region)
void(*) listener(const wmRegionListenerParams *params)
void(*) layout(const bContext *C, ARegion *region)
void(*) init(wmWindowManager *wm, ARegion *region)
eRegion_Alignment alignment
eRegion_Type regiontype
void write_struct_cast(const void *data, BlendStructWriterTypedFn< T > fn=nullptr)
ListBaseT< ARegion > regionbase
unsigned int action
Definition WM_types.hh:371
unsigned int category
Definition WM_types.hh:371
unsigned int data
Definition WM_types.hh:371
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)