Blender V5.3
space_info.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 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.hh"
14#include "BLI_string_utf8.hh"
15#include "BLI_utildefines.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 "WM_api.hh"
24#include "WM_message.hh"
25#include "WM_types.hh"
26
27#include "UI_resources.hh"
28#include "UI_view2d.hh"
29
30#include "BLO_read_write.hh"
31
32#include "info_intern.hh" /* own include */
33
34namespace blender {
35
36/* ******************** default callbacks for info space ***************** */
37
38static SpaceLink *info_create(const ScrArea * /*area*/, const Scene * /*scene*/)
39{
40 ARegion *region;
41 SpaceInfo *sinfo;
42
43 sinfo = MEM_new<SpaceInfo>("initinfo");
44 sinfo->spacetype = SPACE_INFO;
45
46 sinfo->rpt_mask = INFO_RPT_OP;
47
48 /* header */
49 region = BKE_area_region_new();
50
51 BLI_addtail(&sinfo->regionbase, region);
54
55 /* main region */
56 region = BKE_area_region_new();
57
58 BLI_addtail(&sinfo->regionbase, region);
60
61 /* keep in sync with console */
63 region->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */
64 region->v2d.keepofs |= V2D_LOCKOFS_X;
67 region->v2d.minzoom = region->v2d.maxzoom = 1.0f;
68
69 /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
70 // region->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM);
71
72 return reinterpret_cast<SpaceLink *>(sinfo);
73}
74
75/* Doesn't free the space-link itself. */
76static void info_free(SpaceLink * /*sl*/)
77{
78 // SpaceInfo *sinfo = (SpaceInfo *) sl;
79}
80
81/* spacetype; init callback */
82static void info_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
83
85{
86 SpaceInfo *sinfon = MEM_dupalloc(reinterpret_cast<SpaceInfo *>(sl));
87
88 /* clear or remove stuff from old */
89
90 return reinterpret_cast<SpaceLink *>(sinfon);
91}
92
93/* add handlers, stuff you only do once or on area/region changes */
95{
96 wmKeyMap *keymap;
97
98 view2d_region_reinit(&region->v2d, ui::V2D_COMMONVIEW_CUSTOM, region->winx, region->winy);
99
100 /* own keymap */
101 keymap = WM_keymap_ensure(wm->runtime->defaultconf, "Info", SPACE_INFO, RGN_TYPE_WINDOW);
103}
104
105static void info_textview_update_rect(const bContext *C, ARegion *region)
106{
107 SpaceInfo *sinfo = CTX_wm_space_info(C);
108 View2D *v2d = &region->v2d;
109
111 v2d, region->winx - 1, info_textview_height(sinfo, region, CTX_wm_reports(C)));
112}
113
114static void info_main_region_draw(const bContext *C, ARegion *region)
115{
116 /* draw entirely, view changes should be handled here */
117 SpaceInfo *sinfo = CTX_wm_space_info(C);
118 View2D *v2d = &region->v2d;
119
120 /* clear and setup matrix */
122
123 /* quick way to avoid drawing if not bug enough */
124 if (region->winy < 16) {
125 return;
126 }
127
129
130 /* Works best with no view2d matrix set. */
132
133 info_textview_main(sinfo, region, CTX_wm_reports(C));
134
135 /* reset view matrix */
137
138 /* scrollers */
139 ui::view2d_scrollers_draw(v2d, nullptr);
140}
141
166
167static void info_keymap(wmKeyConfig *keyconf)
168{
169 WM_keymap_ensure(keyconf, "Window", SPACE_EMPTY, RGN_TYPE_WINDOW);
171}
172
173/* add handlers, stuff you only do once or on area/region changes */
174static void info_header_region_init(wmWindowManager * /*wm*/, ARegion *region)
175{
176 ED_region_header_init(region);
177}
178
179static void info_header_region_draw(const bContext *C, ARegion *region)
180{
181 ED_region_header(C, region);
182}
183
185{
186 ARegion *region = params->region;
187 const wmNotifier *wmn = params->notifier;
188
189 /* context changes */
190 switch (wmn->category) {
191 case NC_SPACE:
192 if (wmn->data == ND_SPACE_INFO_REPORT) {
193 /* redraw also but only for report view, could do less redraws by checking the type */
194 ED_region_tag_redraw(region);
195 }
196 break;
197 }
198}
199
201{
202 ARegion *region = params->region;
203 const wmNotifier *wmn = params->notifier;
204
205 /* context changes */
206 switch (wmn->category) {
207 case NC_SCREEN:
208 if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) {
209 ED_region_tag_redraw(region);
210 }
211 break;
212 case NC_WM:
213 if (wmn->data == ND_JOB) {
214 ED_region_tag_redraw(region);
215 }
216 break;
217 case NC_SCENE:
218 if (wmn->data == ND_RENDER_RESULT) {
219 ED_region_tag_redraw(region);
220 }
221 break;
222 case NC_SPACE:
223 if (wmn->data == ND_SPACE_INFO) {
224 ED_region_tag_redraw(region);
225 }
226 break;
227 case NC_ID:
228 if (wmn->action == NA_RENAME) {
229 ED_region_tag_redraw(region);
230 }
231 break;
232 }
233}
234
236{
237 wmMsgBus *mbus = params->message_bus;
238 ARegion *region = params->region;
239
240 wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {nullptr};
241 msg_sub_value_region_tag_redraw.owner = region;
242 msg_sub_value_region_tag_redraw.user_data = region;
243 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
244
245 WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
246 WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
247}
248
250{
251 writer->write_struct_cast<SpaceInfo>(sl);
252}
253
255{
256 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
257 ARegionType *art;
258
259 st->spaceid = SPACE_INFO;
260 STRNCPY_UTF8(st->name, "Info");
261 st->struct_size = sizeof(SpaceInfo);
262
263 st->create = info_create;
264 st->free = info_free;
265 st->init = info_init;
266 st->duplicate = info_duplicate;
267 st->operatortypes = info_operatortypes;
268 st->keymap = info_keymap;
269 st->blend_write = info_space_blend_write;
270
271 /* regions: main window */
272 art = MEM_new_zeroed<ARegionType>("spacetype info region");
275
279
280 BLI_addhead(&st->regiontypes, art);
281
282 /* regions: header */
283 art = MEM_new_zeroed<ARegionType>("spacetype info region");
285 art->prefsizey = HEADERY;
286
292
293 BLI_addhead(&st->regiontypes, art);
294
295 BKE_spacetype_register(std::move(st));
296}
297
298} // namespace blender
#define STRNCPY_UTF8(dst, src)
#define HEADERY
#define Window
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#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_SPACE_INFO_REPORT
Definition WM_types.hh:563
#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(...)
void frame_buffer_clear(int colorid)
void view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1080
void view2d_totRect_set(View2D *v2d, int width, int height)
Definition view2d.cc:1021
void view2d_view_restore(const bContext *C)
Definition view2d.cc:1147
void view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
Definition view2d.cc:1487
@ V2D_COMMONVIEW_CUSTOM
Definition UI_view2d.hh:56
BMesh Iterators.
UserDef U
Definition blender.cc:58
static void info_textview_update_rect(const bContext *C, ARegion *region)
void FILE_OT_unpack_all(wmOperatorType *ot)
Definition info_ops.cc:285
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
void FILE_OT_pack_all(wmOperatorType *ot)
Definition info_ops.cc:199
static SpaceLink * info_duplicate(SpaceLink *sl)
Definition space_info.cc:84
static void info_main_region_listener(const wmRegionListenerParams *params)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
static void info_keymap(wmKeyConfig *keyconf)
void FILE_OT_unpack_item(wmOperatorType *ot)
Definition info_ops.cc:385
void FILE_OT_make_paths_relative(wmOperatorType *ot)
Definition info_ops.cc:441
void FILE_OT_unpack_libraries(wmOperatorType *ot)
Definition info_ops.cc:106
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
static void info_space_blend_write(BlendWriter *writer, SpaceLink *sl)
int info_textview_height(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition info_draw.cc:215
static void info_init(wmWindowManager *, ScrArea *)
Definition space_info.cc:82
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void info_textview_main(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition info_draw.cc:221
void FILE_OT_pack_libraries(wmOperatorType *ot)
Definition info_ops.cc:60
SpaceInfo * CTX_wm_space_info(const bContext *C)
static void info_header_listener(const wmRegionListenerParams *params)
static void info_header_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
void INFO_OT_select_pick(wmOperatorType *ot)
void INFO_OT_reports_display_update(wmOperatorType *ot)
Definition info_ops.cc:670
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
ARegion * BKE_area_region_new()
Definition screen.cc:522
void INFO_OT_select_box(wmOperatorType *ot)
@ ED_KEYMAP_UI
Definition ED_screen.hh:852
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:858
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:855
@ ED_KEYMAP_FRAMES
Definition ED_screen.hh:857
static void info_main_region_init(wmWindowManager *wm, ARegion *region)
Definition space_info.cc:94
static SpaceLink * info_create(const ScrArea *, const Scene *)
Definition space_info.cc:38
@ V2D_SCROLL_VERTICAL_HIDE
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void FILE_OT_find_missing_files(wmOperatorType *ot)
Definition info_ops.cc:562
static void info_header_region_init(wmWindowManager *, ARegion *region)
static void info_main_region_draw(const bContext *C, ARegion *region)
void BKE_spacetype_register(std::unique_ptr< SpaceType > st)
Definition screen.cc:379
void INFO_OT_report_delete(wmOperatorType *ot)
void ED_region_header_init(ARegion *region)
Definition area.cc:4406
void ED_spacetype_info()
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:394
ReportList * CTX_wm_reports(const bContext *C)
static void info_operatortypes()
void ED_region_header(const bContext *C, ARegion *region)
Definition area.cc:4391
static void info_header_region_draw(const bContext *C, ARegion *region)
void FILE_OT_autopack_toggle(wmOperatorType *ot)
Definition info_ops.cc:142
void INFO_OT_report_replay(wmOperatorType *ot)
void INFO_OT_select_all(wmOperatorType *ot)
void INFO_OT_report_copy(wmOperatorType *ot)
void FILE_OT_report_missing_files(wmOperatorType *ot)
Definition info_ops.cc:513
void FILE_OT_make_paths_absolute(wmOperatorType *ot)
Definition info_ops.cc:481
static void info_free(SpaceLink *)
Definition space_info.cc:76
void(*) message_subscribe(const wmRegionMessageSubscribeParams *params)
void(*) draw(const bContext *C, ARegion *region)
void(*) listener(const wmRegionListenerParams *params)
void(*) init(wmWindowManager *wm, ARegion *region)
bke::ARegionRuntime * runtime
eRegion_Alignment alignment
eRegion_Type regiontype
void write_struct_cast(const void *data, BlendStructWriterTypedFn< T > fn=nullptr)
ListBaseT< ARegion > regionbase
eView2D_KeepTot keeptot
eView2D_KeepOfs keepofs
eView2D_KeepZoom keepzoom
eView2D_Scroll scroll
eView2D_Align align
ListBaseT< wmEventHandler > handlers
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)