Blender V4.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
9#include <cstdio>
10#include <cstring>
11
12#include "MEM_guardedalloc.h"
13
14#include "BLI_blenlib.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 = static_cast<SpaceInfo *>(MEM_callocN(sizeof(SpaceInfo), "initinfo"));
42 sinfo->spacetype = SPACE_INFO;
43
44 sinfo->rpt_mask = INFO_RPT_OP;
45
46 /* header */
47 region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "header for info"));
48
49 BLI_addtail(&sinfo->regionbase, region);
50 region->regiontype = RGN_TYPE_HEADER;
51 region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
52
53 /* main region */
54 region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "main region for info"));
55
56 BLI_addtail(&sinfo->regionbase, region);
57 region->regiontype = RGN_TYPE_WINDOW;
58
59 /* keep in sync with console */
60 region->v2d.scroll |= V2D_SCROLL_RIGHT;
61 region->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */
62 region->v2d.keepofs |= V2D_LOCKOFS_X;
63 region->v2d.keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | V2D_KEEPASPECT);
64 region->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
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 /* force it on init, for old files, until it becomes config */
97 region->v2d.scroll = (V2D_SCROLL_RIGHT);
98
99 UI_view2d_region_reinit(&region->v2d, V2D_COMMONVIEW_CUSTOM, region->winx, region->winy);
100
101 /* own keymap */
103 WM_event_add_keymap_handler(&region->handlers, keymap);
104}
105
106static void info_textview_update_rect(const bContext *C, ARegion *region)
107{
108 SpaceInfo *sinfo = CTX_wm_space_info(C);
109 View2D *v2d = &region->v2d;
110
112 v2d, region->winx - 1, info_textview_height(sinfo, region, CTX_wm_reports(C)));
113}
114
115static void info_main_region_draw(const bContext *C, ARegion *region)
116{
117 /* draw entirely, view changes should be handled here */
118 SpaceInfo *sinfo = CTX_wm_space_info(C);
119 View2D *v2d = &region->v2d;
120
121 /* clear and setup matrix */
123
124 /* quick way to avoid drawing if not bug enough */
125 if (region->winy < 16) {
126 return;
127 }
128
129 info_textview_update_rect(C, region);
130
131 /* Works best with no view2d matrix set. */
133
134 info_textview_main(sinfo, region, CTX_wm_reports(C));
135
136 /* reset view matrix */
138
139 /* scrollers */
140 UI_view2d_scrollers_draw(v2d, nullptr);
141}
142
167
168static void info_keymap(wmKeyConfig *keyconf)
169{
170 WM_keymap_ensure(keyconf, "Window", SPACE_EMPTY, RGN_TYPE_WINDOW);
172}
173
174/* add handlers, stuff you only do once or on area/region changes */
175static void info_header_region_init(wmWindowManager * /*wm*/, ARegion *region)
176{
177 ED_region_header_init(region);
178}
179
180static void info_header_region_draw(const bContext *C, ARegion *region)
181{
182 ED_region_header(C, region);
183}
184
186{
187 ARegion *region = params->region;
188 const wmNotifier *wmn = params->notifier;
189
190 /* context changes */
191 switch (wmn->category) {
192 case NC_SPACE:
193 if (wmn->data == ND_SPACE_INFO_REPORT) {
194 /* redraw also but only for report view, could do less redraws by checking the type */
195 ED_region_tag_redraw(region);
196 }
197 break;
198 }
199}
200
202{
203 ARegion *region = params->region;
204 const wmNotifier *wmn = params->notifier;
205
206 /* context changes */
207 switch (wmn->category) {
208 case NC_SCREEN:
209 if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) {
210 ED_region_tag_redraw(region);
211 }
212 break;
213 case NC_WM:
214 if (wmn->data == ND_JOB) {
215 ED_region_tag_redraw(region);
216 }
217 break;
218 case NC_SCENE:
219 if (wmn->data == ND_RENDER_RESULT) {
220 ED_region_tag_redraw(region);
221 }
222 break;
223 case NC_SPACE:
224 if (wmn->data == ND_SPACE_INFO) {
225 ED_region_tag_redraw(region);
226 }
227 break;
228 case NC_ID:
229 if (wmn->action == NA_RENAME) {
230 ED_region_tag_redraw(region);
231 }
232 break;
233 }
234}
235
237{
238 wmMsgBus *mbus = params->message_bus;
239 ARegion *region = params->region;
240
241 wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {nullptr};
242 msg_sub_value_region_tag_redraw.owner = region;
243 msg_sub_value_region_tag_redraw.user_data = region;
244 msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
245
246 WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
247 WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
248}
249
251{
252 BLO_write_struct(writer, SpaceInfo, sl);
253}
254
256{
257 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
258 ARegionType *art;
259
260 st->spaceid = SPACE_INFO;
261 STRNCPY(st->name, "Info");
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 = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype info region"));
275
279
280 BLI_addhead(&st->regiontypes, art);
281
282 /* regions: header */
283 art = static_cast<ARegionType *>(MEM_callocN(sizeof(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}
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: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
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_TOP
@ RGN_TYPE_WINDOW
@ RGN_TYPE_HEADER
@ SPACE_EMPTY
@ SPACE_INFO
@ INFO_RPT_OP
@ USER_HEADER_BOTTOM
@ V2D_ALIGN_NO_NEG_X
@ V2D_ALIGN_NO_NEG_Y
@ V2D_LOCKOFS_X
@ V2D_SCROLL_RIGHT
@ V2D_KEEPTOT_BOUNDS
@ V2D_LIMITZOOM
@ V2D_LOCKZOOM_X
@ V2D_KEEPASPECT
@ V2D_LOCKZOOM_Y
void ED_region_header(const bContext *C, ARegion *region)
Definition area.cc:3646
void ED_region_header_init(ARegion *region)
Definition area.cc:3661
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
@ ED_KEYMAP_FRAMES
Definition ED_screen.hh:730
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:381
Read Guarded memory(de)allocation.
@ TH_BACK
void UI_ThemeClearColor(int colorid)
void UI_view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
Definition view2d.cc:1605
void UI_view2d_view_restore(const bContext *C)
Definition view2d.cc:1158
void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
Definition view2d.cc:212
void UI_view2d_totRect_set(View2D *v2d, int width, int height)
Definition view2d.cc:1032
void UI_view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1091
@ V2D_COMMONVIEW_CUSTOM
Definition UI_view2d.hh:31
#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_SPACE_INFO_REPORT
Definition WM_types.hh:486
#define ND_LAYER
Definition WM_types.hh:417
#define NA_RENAME
Definition WM_types.hh:554
#define NC_SPACE
Definition WM_types.hh:359
unsigned int U
Definition btGjkEpa3.h:78
void info_textview_main(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition info_draw.cc:223
int info_textview_height(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition info_draw.cc:217
void FILE_OT_make_paths_absolute(wmOperatorType *ot)
Definition info_ops.cc:473
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:377
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:505
void FILE_OT_pack_libraries(wmOperatorType *ot)
Definition info_ops.cc:56
void FILE_OT_unpack_libraries(wmOperatorType *ot)
Definition info_ops.cc:100
void FILE_OT_make_paths_relative(wmOperatorType *ot)
Definition info_ops.cc:433
void FILE_OT_find_missing_files(wmOperatorType *ot)
Definition info_ops.cc:546
void INFO_OT_select_box(wmOperatorType *ot)
void INFO_OT_reports_display_update(wmOperatorType *ot)
Definition info_ops.cc:652
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 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)
ListBase regionbase
unsigned int data
Definition WM_types.hh:325
unsigned int action
Definition WM_types.hh:325
unsigned int category
Definition WM_types.hh:325
struct wmKeyConfig * defaultconf
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:897
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))