Blender V5.0
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.h"
14#include "BLI_string_utf8.h"
15#include "BLI_utildefines.h"
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
34/* ******************** default callbacks for info space ***************** */
35
36static SpaceLink *info_create(const ScrArea * /*area*/, const Scene * /*scene*/)
37{
38 ARegion *region;
39 SpaceInfo *sinfo;
40
41 sinfo = MEM_callocN<SpaceInfo>("initinfo");
42 sinfo->spacetype = SPACE_INFO;
43
44 sinfo->rpt_mask = INFO_RPT_OP;
45
46 /* header */
47 region = BKE_area_region_new();
48
49 BLI_addtail(&sinfo->regionbase, region);
52
53 /* main region */
54 region = BKE_area_region_new();
55
56 BLI_addtail(&sinfo->regionbase, region);
58
59 /* keep in sync with console */
61 region->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */
62 region->v2d.keepofs |= V2D_LOCKOFS_X;
65 region->v2d.minzoom = region->v2d.maxzoom = 1.0f;
66
67 /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
68 // region->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM);
69
70 return (SpaceLink *)sinfo;
71}
72
73/* Doesn't free the space-link itself. */
74static void info_free(SpaceLink * /*sl*/)
75{
76 // SpaceInfo *sinfo = (SpaceInfo *) sl;
77}
78
79/* spacetype; init callback */
80static void info_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
81
83{
84 SpaceInfo *sinfon = static_cast<SpaceInfo *>(MEM_dupallocN(sl));
85
86 /* clear or remove stuff from old */
87
88 return (SpaceLink *)sinfon;
89}
90
91/* add handlers, stuff you only do once or on area/region changes */
93{
94 wmKeyMap *keymap;
95
96 UI_view2d_region_reinit(&region->v2d, V2D_COMMONVIEW_CUSTOM, region->winx, region->winy);
97
98 /* own keymap */
99 keymap = WM_keymap_ensure(wm->runtime->defaultconf, "Info", SPACE_INFO, RGN_TYPE_WINDOW);
100 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
101}
102
103static void info_textview_update_rect(const bContext *C, ARegion *region)
104{
105 SpaceInfo *sinfo = CTX_wm_space_info(C);
106 View2D *v2d = &region->v2d;
107
109 v2d, region->winx - 1, info_textview_height(sinfo, region, CTX_wm_reports(C)));
110}
111
112static void info_main_region_draw(const bContext *C, ARegion *region)
113{
114 /* draw entirely, view changes should be handled here */
115 SpaceInfo *sinfo = CTX_wm_space_info(C);
116 View2D *v2d = &region->v2d;
117
118 /* clear and setup matrix */
120
121 /* quick way to avoid drawing if not bug enough */
122 if (region->winy < 16) {
123 return;
124 }
125
127
128 /* Works best with no view2d matrix set. */
130
131 info_textview_main(sinfo, region, CTX_wm_reports(C));
132
133 /* reset view matrix */
135
136 /* scrollers */
137 UI_view2d_scrollers_draw(v2d, nullptr);
138}
139
164
165static void info_keymap(wmKeyConfig *keyconf)
166{
167 WM_keymap_ensure(keyconf, "Window", SPACE_EMPTY, RGN_TYPE_WINDOW);
169}
170
171/* add handlers, stuff you only do once or on area/region changes */
172static void info_header_region_init(wmWindowManager * /*wm*/, ARegion *region)
173{
174 ED_region_header_init(region);
175}
176
177static void info_header_region_draw(const bContext *C, ARegion *region)
178{
179 ED_region_header(C, region);
180}
181
183{
184 ARegion *region = params->region;
185 const wmNotifier *wmn = params->notifier;
186
187 /* context changes */
188 switch (wmn->category) {
189 case NC_SPACE:
190 if (wmn->data == ND_SPACE_INFO_REPORT) {
191 /* redraw also but only for report view, could do less redraws by checking the type */
192 ED_region_tag_redraw(region);
193 }
194 break;
195 }
196}
197
199{
200 ARegion *region = params->region;
201 const wmNotifier *wmn = params->notifier;
202
203 /* context changes */
204 switch (wmn->category) {
205 case NC_SCREEN:
206 if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) {
207 ED_region_tag_redraw(region);
208 }
209 break;
210 case NC_WM:
211 if (wmn->data == ND_JOB) {
212 ED_region_tag_redraw(region);
213 }
214 break;
215 case NC_SCENE:
216 if (wmn->data == ND_RENDER_RESULT) {
217 ED_region_tag_redraw(region);
218 }
219 break;
220 case NC_SPACE:
221 if (wmn->data == ND_SPACE_INFO) {
222 ED_region_tag_redraw(region);
223 }
224 break;
225 case NC_ID:
226 if (wmn->action == NA_RENAME) {
227 ED_region_tag_redraw(region);
228 }
229 break;
230 }
231}
232
234{
235 wmMsgBus *mbus = params->message_bus;
236 ARegion *region = params->region;
237
238 wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {nullptr};
239 msg_sub_value_region_tag_redraw.owner = region;
240 msg_sub_value_region_tag_redraw.user_data = region;
241 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
242
243 WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
244 WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
245}
246
248{
249 BLO_write_struct(writer, SpaceInfo, sl);
250}
251
253{
254 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
255 ARegionType *art;
256
257 st->spaceid = SPACE_INFO;
258 STRNCPY_UTF8(st->name, "Info");
259
260 st->create = info_create;
261 st->free = info_free;
262 st->init = info_init;
263 st->duplicate = info_duplicate;
264 st->operatortypes = info_operatortypes;
265 st->keymap = info_keymap;
266 st->blend_write = info_space_blend_write;
267
268 /* regions: main window */
269 art = MEM_callocN<ARegionType>("spacetype info region");
272
276
277 BLI_addhead(&st->regiontypes, art);
278
279 /* regions: header */
280 art = MEM_callocN<ARegionType>("spacetype info region");
282 art->prefsizey = HEADERY;
283
289
290 BLI_addhead(&st->regiontypes, art);
291
292 BKE_spacetype_register(std::move(st));
293}
ReportList * CTX_wm_reports(const bContext *C)
SpaceInfo * CTX_wm_space_info(const bContext *C)
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
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_TOP
@ RGN_TYPE_WINDOW
@ RGN_TYPE_HEADER
@ SPACE_EMPTY
@ SPACE_INFO
@ INFO_RPT_OP
@ USER_HEADER_BOTTOM
@ V2D_LOCKOFS_X
@ V2D_KEEPTOT_BOUNDS
@ V2D_LIMITZOOM
@ V2D_LOCKZOOM_X
@ V2D_KEEPASPECT
@ V2D_LOCKZOOM_Y
@ V2D_SCROLL_VERTICAL_HIDE
@ V2D_SCROLL_RIGHT
@ V2D_ALIGN_NO_NEG_X
@ V2D_ALIGN_NO_NEG_Y
void ED_region_header(const bContext *C, ARegion *region)
Definition area.cc:3935
void ED_region_header_init(ARegion *region)
Definition area.cc:3950
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
@ ED_KEYMAP_FRAMES
Definition ED_screen.hh:763
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:361
#define Window
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
@ TH_BACK
void UI_ThemeClearColor(int colorid)
void UI_view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
Definition view2d.cc:1504
void UI_view2d_view_restore(const bContext *C)
Definition view2d.cc:1162
void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
Definition view2d.cc:221
void UI_view2d_totRect_set(View2D *v2d, int width, int height)
Definition view2d.cc:1036
void UI_view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1095
@ V2D_COMMONVIEW_CUSTOM
Definition UI_view2d.hh:31
#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_SPACE_INFO_REPORT
Definition WM_types.hh:520
#define ND_LAYER
Definition WM_types.hh:450
#define NA_RENAME
Definition WM_types.hh:588
#define NC_SPACE
Definition WM_types.hh:392
#define U
void info_textview_main(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition info_draw.cc:219
int info_textview_height(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition info_draw.cc:213
void FILE_OT_make_paths_absolute(wmOperatorType *ot)
Definition info_ops.cc:477
void INFO_OT_select_all(wmOperatorType *ot)
void INFO_OT_report_copy(wmOperatorType *ot)
void INFO_OT_select_pick(wmOperatorType *ot)
void FILE_OT_unpack_all(wmOperatorType *ot)
Definition info_ops.cc:283
void FILE_OT_unpack_item(wmOperatorType *ot)
Definition info_ops.cc:381
void FILE_OT_pack_all(wmOperatorType *ot)
Definition info_ops.cc:195
void INFO_OT_report_replay(wmOperatorType *ot)
void FILE_OT_autopack_toggle(wmOperatorType *ot)
Definition info_ops.cc:136
void INFO_OT_report_delete(wmOperatorType *ot)
void FILE_OT_report_missing_files(wmOperatorType *ot)
Definition info_ops.cc:509
void FILE_OT_pack_libraries(wmOperatorType *ot)
Definition info_ops.cc:54
void FILE_OT_unpack_libraries(wmOperatorType *ot)
Definition info_ops.cc:100
void FILE_OT_make_paths_relative(wmOperatorType *ot)
Definition info_ops.cc:437
void FILE_OT_find_missing_files(wmOperatorType *ot)
Definition info_ops.cc:551
void INFO_OT_select_box(wmOperatorType *ot)
void INFO_OT_reports_display_update(wmOperatorType *ot)
Definition info_ops.cc:659
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 SpaceLink * info_duplicate(SpaceLink *sl)
Definition space_info.cc:82
static void info_keymap(wmKeyConfig *keyconf)
static void info_main_region_init(wmWindowManager *wm, ARegion *region)
Definition space_info.cc:92
static void info_main_region_listener(const wmRegionListenerParams *params)
static void info_init(wmWindowManager *, ScrArea *)
Definition space_info.cc:80
static void info_textview_update_rect(const bContext *C, ARegion *region)
static void info_header_region_draw(const bContext *C, ARegion *region)
static void info_operatortypes()
static void info_header_region_init(wmWindowManager *, ARegion *region)
static void info_header_listener(const wmRegionListenerParams *params)
static void info_main_region_draw(const bContext *C, ARegion *region)
static void info_header_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
static void info_space_blend_write(BlendWriter *writer, SpaceLink *sl)
void ED_spacetype_info()
static SpaceLink * info_create(const ScrArea *, const Scene *)
Definition space_info.cc:36
static void info_free(SpaceLink *)
Definition space_info.cc:74
void(* message_subscribe)(const wmRegionMessageSubscribeParams *params)
void(* listener)(const wmRegionListenerParams *params)
void(* draw)(const bContext *C, ARegion *region)
void(* init)(wmWindowManager *wm, ARegion *region)
ARegionRuntimeHandle * runtime
ListBase regionbase
float minzoom
short keeptot
short keepzoom
short keepofs
float maxzoom
unsigned int data
Definition WM_types.hh:358
unsigned int action
Definition WM_types.hh:358
unsigned int category
Definition WM_types.hh:358
WindowManagerRuntimeHandle * runtime
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap)
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:895
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))