Blender  V3.3
space_info.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2008 Blender Foundation. All rights reserved. */
3 
8 #include <stdio.h>
9 #include <string.h>
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "BLI_blenlib.h"
14 #include "BLI_utildefines.h"
15 
16 #include "BKE_context.h"
17 #include "BKE_screen.h"
18 
19 #include "ED_screen.h"
20 #include "ED_space_api.h"
21 
22 #include "WM_api.h"
23 #include "WM_message.h"
24 #include "WM_types.h"
25 
26 #include "RNA_access.h"
27 
28 #include "UI_resources.h"
29 #include "UI_view2d.h"
30 
31 #include "info_intern.h" /* own include */
32 
33 /* ******************** default callbacks for info space ***************** */
34 
36 {
37  ARegion *region;
38  SpaceInfo *sinfo;
39 
40  sinfo = MEM_callocN(sizeof(SpaceInfo), "initinfo");
41  sinfo->spacetype = SPACE_INFO;
42 
43  sinfo->rpt_mask = INFO_RPT_OP;
44 
45  /* header */
46  region = MEM_callocN(sizeof(ARegion), "header for info");
47 
48  BLI_addtail(&sinfo->regionbase, region);
49  region->regiontype = RGN_TYPE_HEADER;
51 
52  /* main region */
53  region = MEM_callocN(sizeof(ARegion), "main region for info");
54 
55  BLI_addtail(&sinfo->regionbase, region);
56  region->regiontype = RGN_TYPE_WINDOW;
57 
58  /* keep in sync with console */
59  region->v2d.scroll |= V2D_SCROLL_RIGHT;
60  region->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */
61  region->v2d.keepofs |= V2D_LOCKOFS_X;
63  region->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
64  region->v2d.minzoom = region->v2d.maxzoom = 1.0f;
65 
66  /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
67  // region->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM);
68 
69  return (SpaceLink *)sinfo;
70 }
71 
72 /* not spacelink itself */
73 static void info_free(SpaceLink *UNUSED(sl))
74 {
75  // SpaceInfo *sinfo = (SpaceInfo *) sl;
76 }
77 
78 /* spacetype; init callback */
79 static void info_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
80 {
81 }
82 
84 {
85  SpaceInfo *sinfon = MEM_dupallocN(sl);
86 
87  /* clear or remove stuff from old */
88 
89  return (SpaceLink *)sinfon;
90 }
91 
92 /* add handlers, stuff you only do once or on area/region changes */
94 {
95  wmKeyMap *keymap;
96 
97  /* force it on init, for old files, until it becomes config */
98  region->v2d.scroll = (V2D_SCROLL_RIGHT);
99 
100  UI_view2d_region_reinit(&region->v2d, V2D_COMMONVIEW_CUSTOM, region->winx, region->winy);
101 
102  /* own keymap */
103  keymap = WM_keymap_ensure(wm->defaultconf, "Info", SPACE_INFO, 0);
104  WM_event_add_keymap_handler(&region->handlers, keymap);
105 }
106 
107 static void info_textview_update_rect(const bContext *C, ARegion *region)
108 {
109  SpaceInfo *sinfo = CTX_wm_space_info(C);
110  View2D *v2d = &region->v2d;
111 
113  v2d, region->winx - 1, info_textview_height(sinfo, region, CTX_wm_reports(C)));
114 }
115 
116 static void info_main_region_draw(const bContext *C, ARegion *region)
117 {
118  /* draw entirely, view changes should be handled here */
119  SpaceInfo *sinfo = CTX_wm_space_info(C);
120  View2D *v2d = &region->v2d;
121 
122  /* clear and setup matrix */
124 
125  /* quick way to avoid drawing if not bug enough */
126  if (region->winy < 16) {
127  return;
128  }
129 
130  info_textview_update_rect(C, region);
131 
132  /* Works best with no view2d matrix set. */
134 
135  info_textview_main(sinfo, region, CTX_wm_reports(C));
136 
137  /* reset view matrix */
139 
140  /* scrollers */
142 }
143 
144 static void info_operatortypes(void)
145 {
152 
158 
159  /* info_report.c */
163 
167 }
168 
169 static void info_keymap(struct wmKeyConfig *keyconf)
170 {
171  WM_keymap_ensure(keyconf, "Window", 0, 0);
172  WM_keymap_ensure(keyconf, "Info", SPACE_INFO, 0);
173 }
174 
175 /* add handlers, stuff you only do once or on area/region changes */
177 {
178  ED_region_header_init(region);
179 }
180 
181 static void info_header_region_draw(const bContext *C, ARegion *region)
182 {
183  ED_region_header(C, region);
184 }
185 
187 {
188  ARegion *region = params->region;
189  wmNotifier *wmn = params->notifier;
190 
191  /* context changes */
192  switch (wmn->category) {
193  case NC_SPACE:
194  if (wmn->data == ND_SPACE_INFO_REPORT) {
195  /* redraw also but only for report view, could do less redraws by checking the type */
196  ED_region_tag_redraw(region);
197  }
198  break;
199  }
200 }
201 
203 {
204  ARegion *region = params->region;
205  wmNotifier *wmn = params->notifier;
206 
207  /* context changes */
208  switch (wmn->category) {
209  case NC_SCREEN:
210  if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) {
211  ED_region_tag_redraw(region);
212  }
213  break;
214  case NC_WM:
215  if (wmn->data == ND_JOB) {
216  ED_region_tag_redraw(region);
217  }
218  break;
219  case NC_SCENE:
220  if (wmn->data == ND_RENDER_RESULT) {
221  ED_region_tag_redraw(region);
222  }
223  break;
224  case NC_SPACE:
225  if (wmn->data == ND_SPACE_INFO) {
226  ED_region_tag_redraw(region);
227  }
228  break;
229  case NC_ID:
230  if (wmn->action == NA_RENAME) {
231  ED_region_tag_redraw(region);
232  }
233  break;
234  }
235 }
236 
238 {
239  struct wmMsgBus *mbus = params->message_bus;
240  ARegion *region = params->region;
241 
242  wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {NULL};
243  msg_sub_value_region_tag_redraw.owner = region;
244  msg_sub_value_region_tag_redraw.user_data = region;
245  msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
246 
247  WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
248  WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
249 }
250 
252 {
253  SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype info");
254  ARegionType *art;
255 
256  st->spaceid = SPACE_INFO;
257  strncpy(st->name, "Info", BKE_ST_MAXNAME);
258 
259  st->create = info_create;
260  st->free = info_free;
261  st->init = info_init;
262  st->duplicate = info_duplicate;
263  st->operatortypes = info_operatortypes;
264  st->keymap = info_keymap;
265 
266  /* regions: main window */
267  art = MEM_callocN(sizeof(ARegionType), "spacetype info region");
268  art->regionid = RGN_TYPE_WINDOW;
270 
274 
275  BLI_addhead(&st->regiontypes, art);
276 
277  /* regions: header */
278  art = MEM_callocN(sizeof(ARegionType), "spacetype info region");
279  art->regionid = RGN_TYPE_HEADER;
280  art->prefsizey = HEADERY;
281 
287 
288  BLI_addhead(&st->regiontypes, art);
289 
291 }
struct SpaceInfo * CTX_wm_space_info(const bContext *C)
Definition: context.c:905
struct ReportList * CTX_wm_reports(const bContext *C)
Definition: context.c:775
#define BKE_ST_MAXNAME
Definition: BKE_screen.h:53
void BKE_spacetype_register(struct SpaceType *st)
Definition: screen.c:391
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:60
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
#define UNUSED(x)
#define ELEM(...)
#define HEADERY
@ RGN_TYPE_WINDOW
@ RGN_TYPE_HEADER
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_TOP
@ SPACE_INFO
@ INFO_RPT_OP
@ USER_HEADER_BOTTOM
@ V2D_KEEPTOT_BOUNDS
@ V2D_LOCKOFS_X
@ V2D_LIMITZOOM
@ V2D_LOCKZOOM_X
@ V2D_KEEPASPECT
@ V2D_LOCKZOOM_Y
@ V2D_SCROLL_RIGHT
@ V2D_ALIGN_NO_NEG_X
@ V2D_ALIGN_NO_NEG_Y
@ ED_KEYMAP_UI
Definition: ED_screen.h:691
@ ED_KEYMAP_HEADER
Definition: ED_screen.h:697
@ ED_KEYMAP_VIEW2D
Definition: ED_screen.h:694
@ ED_KEYMAP_FRAMES
Definition: ED_screen.h:696
void ED_region_header(const struct bContext *C, struct ARegion *region)
void ED_region_do_msg_notify_tag_redraw(struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val)
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:655
void ED_region_header_init(struct ARegion *region)
Definition: area.c:3417
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:25
@ TH_BACK
Definition: UI_resources.h:39
void UI_ThemeClearColor(int colorid)
Definition: resources.c:1448
void UI_view2d_region_reinit(struct View2D *v2d, short type, int winx, int winy)
Definition: view2d.cc:217
void UI_view2d_totRect_set(struct View2D *v2d, int width, int height)
Definition: view2d.cc:1022
void UI_view2d_view_restore(const struct bContext *C)
void UI_view2d_view_ortho(const struct View2D *v2d)
void UI_view2d_scrollers_draw(struct View2D *v2d, const struct rcti *mask_custom)
@ V2D_COMMONVIEW_CUSTOM
Definition: UI_view2d.h:34
#define NC_ID
Definition: WM_types.h:345
#define ND_SPACE_INFO
Definition: WM_types.h:464
#define ND_RENDER_RESULT
Definition: WM_types.h:394
#define ND_JOB
Definition: WM_types.h:364
#define NC_WM
Definition: WM_types.h:324
#define NC_SCREEN
Definition: WM_types.h:327
#define ND_ANIMPLAY
Definition: WM_types.h:372
#define NC_SCENE
Definition: WM_types.h:328
#define ND_SPACE_INFO_REPORT
Definition: WM_types.h:463
#define ND_LAYER
Definition: WM_types.h:398
#define NA_RENAME
Definition: WM_types.h:527
#define NC_SPACE
Definition: WM_types.h:342
unsigned int U
Definition: btGjkEpa3.h:78
Scene scene
void info_textview_main(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition: info_draw.c:223
int info_textview_height(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition: info_draw.c:217
void INFO_OT_report_copy(struct wmOperatorType *ot)
Definition: info_report.c:382
void FILE_OT_report_missing_files(struct wmOperatorType *ot)
Definition: info_ops.c:478
void INFO_OT_reports_display_update(struct wmOperatorType *ot)
Definition: info_ops.c:638
void INFO_OT_report_delete(struct wmOperatorType *ot)
Definition: info_report.c:338
void INFO_OT_report_replay(struct wmOperatorType *ot)
Definition: info_report.c:117
void INFO_OT_select_all(struct wmOperatorType *ot)
Definition: info_report.c:209
void FILE_OT_pack_libraries(struct wmOperatorType *ot)
Definition: info_ops.c:56
void FILE_OT_pack_all(struct wmOperatorType *ot)
Definition: info_ops.c:178
void INFO_OT_select_pick(struct wmOperatorType *ot)
Definition: info_report.c:172
void FILE_OT_unpack_item(struct wmOperatorType *ot)
Definition: info_ops.c:356
void FILE_OT_unpack_libraries(struct wmOperatorType *ot)
Definition: info_ops.c:93
void FILE_OT_autopack_toggle(struct wmOperatorType *ot)
Definition: info_ops.c:129
void FILE_OT_make_paths_relative(struct wmOperatorType *ot)
Definition: info_ops.c:410
void INFO_OT_select_box(struct wmOperatorType *ot)
Definition: info_report.c:289
void FILE_OT_find_missing_files(struct wmOperatorType *ot)
Definition: info_ops.c:517
void FILE_OT_unpack_all(struct wmOperatorType *ot)
Definition: info_ops.c:269
void FILE_OT_make_paths_absolute(struct wmOperatorType *ot)
Definition: info_ops.c:448
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:28
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static void area(int d1, int d2, int e1, int e2, float weights[2])
static const pxr::TfToken st("st", pxr::TfToken::Immortal)
static SpaceLink * info_duplicate(SpaceLink *sl)
Definition: space_info.c:83
static void info_keymap(struct wmKeyConfig *keyconf)
Definition: space_info.c:169
static void info_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
Definition: space_info.c:79
static void info_main_region_init(wmWindowManager *wm, ARegion *region)
Definition: space_info.c:93
static void info_main_region_listener(const wmRegionListenerParams *params)
Definition: space_info.c:186
static void info_textview_update_rect(const bContext *C, ARegion *region)
Definition: space_info.c:107
static void info_header_region_draw(const bContext *C, ARegion *region)
Definition: space_info.c:181
void ED_spacetype_info(void)
Definition: space_info.c:251
static SpaceLink * info_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
Definition: space_info.c:35
static void info_free(SpaceLink *UNUSED(sl))
Definition: space_info.c:73
static void info_header_listener(const wmRegionListenerParams *params)
Definition: space_info.c:202
static void info_main_region_draw(const bContext *C, ARegion *region)
Definition: space_info.c:116
static void info_header_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
Definition: space_info.c:237
static void info_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
Definition: space_info.c:176
static void info_operatortypes(void)
Definition: space_info.c:144
void(* draw)(const struct bContext *C, struct ARegion *region)
Definition: BKE_screen.h:151
void(* message_subscribe)(const wmRegionMessageSubscribeParams *params)
Definition: BKE_screen.h:167
void(* listener)(const wmRegionListenerParams *params)
Definition: BKE_screen.h:165
int keymapflag
Definition: BKE_screen.h:208
void(* init)(struct wmWindowManager *wm, struct ARegion *region)
Definition: BKE_screen.h:147
ListBase handlers
short alignment
short regiontype
ListBase regionbase
float minzoom
short align
short keeptot
short keepzoom
short keepofs
short scroll
float maxzoom
wmMsgNotifyFn notify
unsigned int data
Definition: WM_types.h:308
unsigned int action
Definition: WM_types.h:308
unsigned int category
Definition: WM_types.h:308
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.c:852
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))