Blender  V2.93
space_info.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <stdio.h>
25 #include <string.h>
26 
27 #include "MEM_guardedalloc.h"
28 
29 #include "BLI_blenlib.h"
30 #include "BLI_utildefines.h"
31 
32 #include "BKE_context.h"
33 #include "BKE_screen.h"
34 
35 #include "ED_screen.h"
36 #include "ED_space_api.h"
37 
38 #include "WM_api.h"
39 #include "WM_message.h"
40 #include "WM_types.h"
41 
42 #include "RNA_access.h"
43 
44 #include "UI_resources.h"
45 #include "UI_view2d.h"
46 
47 #include "info_intern.h" /* own include */
48 
49 /* ******************** default callbacks for info space ***************** */
50 
52 {
53  ARegion *region;
54  SpaceInfo *sinfo;
55 
56  sinfo = MEM_callocN(sizeof(SpaceInfo), "initinfo");
57  sinfo->spacetype = SPACE_INFO;
58 
59  sinfo->rpt_mask = INFO_RPT_OP;
60 
61  /* header */
62  region = MEM_callocN(sizeof(ARegion), "header for info");
63 
64  BLI_addtail(&sinfo->regionbase, region);
65  region->regiontype = RGN_TYPE_HEADER;
67 
68  /* main region */
69  region = MEM_callocN(sizeof(ARegion), "main region for info");
70 
71  BLI_addtail(&sinfo->regionbase, region);
72  region->regiontype = RGN_TYPE_WINDOW;
73 
74  /* keep in sync with console */
75  region->v2d.scroll |= V2D_SCROLL_RIGHT;
76  region->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */
77  region->v2d.keepofs |= V2D_LOCKOFS_X;
79  region->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
80  region->v2d.minzoom = region->v2d.maxzoom = 1.0f;
81 
82  /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
83  // region->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM);
84 
85  return (SpaceLink *)sinfo;
86 }
87 
88 /* not spacelink itself */
89 static void info_free(SpaceLink *UNUSED(sl))
90 {
91  // SpaceInfo *sinfo = (SpaceInfo *) sl;
92 }
93 
94 /* spacetype; init callback */
95 static void info_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
96 {
97 }
98 
100 {
101  SpaceInfo *sinfon = MEM_dupallocN(sl);
102 
103  /* clear or remove stuff from old */
104 
105  return (SpaceLink *)sinfon;
106 }
107 
108 /* add handlers, stuff you only do once or on area/region changes */
110 {
111  wmKeyMap *keymap;
112 
113  /* force it on init, for old files, until it becomes config */
114  region->v2d.scroll = (V2D_SCROLL_RIGHT);
115 
116  UI_view2d_region_reinit(&region->v2d, V2D_COMMONVIEW_CUSTOM, region->winx, region->winy);
117 
118  /* own keymap */
119  keymap = WM_keymap_ensure(wm->defaultconf, "Info", SPACE_INFO, 0);
120  WM_event_add_keymap_handler(&region->handlers, keymap);
121 }
122 
123 static void info_textview_update_rect(const bContext *C, ARegion *region)
124 {
125  SpaceInfo *sinfo = CTX_wm_space_info(C);
126  View2D *v2d = &region->v2d;
127 
129  v2d, region->winx - 1, info_textview_height(sinfo, region, CTX_wm_reports(C)));
130 }
131 
132 static void info_main_region_draw(const bContext *C, ARegion *region)
133 {
134  /* draw entirely, view changes should be handled here */
135  SpaceInfo *sinfo = CTX_wm_space_info(C);
136  View2D *v2d = &region->v2d;
137 
138  /* clear and setup matrix */
140 
141  /* quick way to avoid drawing if not bug enough */
142  if (region->winy < 16) {
143  return;
144  }
145 
146  info_textview_update_rect(C, region);
147 
148  /* Works best with no view2d matrix set. */
150 
151  info_textview_main(sinfo, region, CTX_wm_reports(C));
152 
153  /* reset view matrix */
155 
156  /* scrollers */
158 }
159 
160 static void info_operatortypes(void)
161 {
168 
174 
175  /* info_report.c */
179 
183 }
184 
185 static void info_keymap(struct wmKeyConfig *keyconf)
186 {
187  WM_keymap_ensure(keyconf, "Window", 0, 0);
188  WM_keymap_ensure(keyconf, "Info", SPACE_INFO, 0);
189 }
190 
191 /* add handlers, stuff you only do once or on area/region changes */
193 {
194  ED_region_header_init(region);
195 }
196 
197 static void info_header_region_draw(const bContext *C, ARegion *region)
198 {
199  ED_region_header(C, region);
200 }
201 
203 {
204  ARegion *region = params->region;
205  wmNotifier *wmn = params->notifier;
206 
207  /* context changes */
208  switch (wmn->category) {
209  case NC_SPACE:
210  if (wmn->data == ND_SPACE_INFO_REPORT) {
211  /* redraw also but only for report view, could do less redraws by checking the type */
212  ED_region_tag_redraw(region);
213  }
214  break;
215  }
216 }
217 
219 {
220  ARegion *region = params->region;
221  wmNotifier *wmn = params->notifier;
222 
223  /* context changes */
224  switch (wmn->category) {
225  case NC_SCREEN:
226  if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) {
227  ED_region_tag_redraw(region);
228  }
229  break;
230  case NC_WM:
231  if (wmn->data == ND_JOB) {
232  ED_region_tag_redraw(region);
233  }
234  break;
235  case NC_SCENE:
236  if (wmn->data == ND_RENDER_RESULT) {
237  ED_region_tag_redraw(region);
238  }
239  break;
240  case NC_SPACE:
241  if (wmn->data == ND_SPACE_INFO) {
242  ED_region_tag_redraw(region);
243  }
244  break;
245  case NC_ID:
246  if (wmn->action == NA_RENAME) {
247  ED_region_tag_redraw(region);
248  }
249  break;
250  }
251 }
252 
254 {
255  struct wmMsgBus *mbus = params->message_bus;
256  ARegion *region = params->region;
257 
258  wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
259  .owner = region,
260  .user_data = region,
262  };
263 
264  WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
265  WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
266 }
267 
268 /* only called once, from space/spacetypes.c */
270 {
271  SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype info");
272  ARegionType *art;
273 
274  st->spaceid = SPACE_INFO;
275  strncpy(st->name, "Info", BKE_ST_MAXNAME);
276 
277  st->create = info_create;
278  st->free = info_free;
279  st->init = info_init;
282  st->keymap = info_keymap;
283 
284  /* regions: main window */
285  art = MEM_callocN(sizeof(ARegionType), "spacetype info region");
286  art->regionid = RGN_TYPE_WINDOW;
288 
292 
293  BLI_addhead(&st->regiontypes, art);
294 
295  /* regions: header */
296  art = MEM_callocN(sizeof(ARegionType), "spacetype info region");
297  art->regionid = RGN_TYPE_HEADER;
298  art->prefsizey = HEADERY;
299 
305 
306  BLI_addhead(&st->regiontypes, art);
307 
309 }
struct SpaceInfo * CTX_wm_space_info(const bContext *C)
Definition: context.c:881
struct ReportList * CTX_wm_reports(const bContext *C)
Definition: context.c:751
#define BKE_ST_MAXNAME
Definition: BKE_screen.h:68
void BKE_spacetype_register(struct SpaceType *st)
Definition: screen.c:420
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:87
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
#define UNUSED(x)
#define ELEM(...)
#define HEADERY
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_TOP
@ RGN_TYPE_WINDOW
@ RGN_TYPE_HEADER
@ SPACE_INFO
@ INFO_RPT_OP
@ USER_HEADER_BOTTOM
@ V2D_KEEPTOT_BOUNDS
@ V2D_SCROLL_RIGHT
@ V2D_ALIGN_NO_NEG_X
@ V2D_ALIGN_NO_NEG_Y
@ V2D_LIMITZOOM
@ V2D_LOCKZOOM_X
@ V2D_KEEPASPECT
@ V2D_LOCKZOOM_Y
@ V2D_LOCKOFS_X
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:667
void ED_region_header_init(struct ARegion *region)
Definition: area.c:3358
@ ED_KEYMAP_UI
Definition: ED_screen.h:440
@ ED_KEYMAP_HEADER
Definition: ED_screen.h:446
@ ED_KEYMAP_VIEW2D
Definition: ED_screen.h:443
@ ED_KEYMAP_FRAMES
Definition: ED_screen.h:445
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:39
@ TH_BACK
Definition: UI_resources.h:55
void UI_ThemeClearColor(int colorid)
Definition: resources.c:1478
void UI_view2d_region_reinit(struct View2D *v2d, short type, int winx, int winy)
Definition: view2d.c:240
void UI_view2d_totRect_set(struct View2D *v2d, int width, int height)
Definition: view2d.c:1052
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:49
#define NC_ID
Definition: WM_types.h:296
#define ND_SPACE_INFO
Definition: WM_types.h:416
#define ND_RENDER_RESULT
Definition: WM_types.h:346
#define ND_JOB
Definition: WM_types.h:315
#define NC_WM
Definition: WM_types.h:276
#define NC_SCREEN
Definition: WM_types.h:278
#define ND_ANIMPLAY
Definition: WM_types.h:323
#define NC_SCENE
Definition: WM_types.h:279
#define ND_SPACE_INFO_REPORT
Definition: WM_types.h:415
#define ND_LAYER
Definition: WM_types.h:350
#define NA_RENAME
Definition: WM_types.h:466
#define NC_SPACE
Definition: WM_types.h:293
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:241
int info_textview_height(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports)
Definition: info_draw.c:235
void INFO_OT_report_copy(struct wmOperatorType *ot)
Definition: info_report.c:395
void FILE_OT_report_missing_files(struct wmOperatorType *ot)
Definition: info_ops.c:454
void INFO_OT_reports_display_update(struct wmOperatorType *ot)
Definition: info_ops.c:607
void INFO_OT_report_delete(struct wmOperatorType *ot)
Definition: info_report.c:351
void INFO_OT_report_replay(struct wmOperatorType *ot)
Definition: info_report.c:131
void INFO_OT_select_all(struct wmOperatorType *ot)
Definition: info_report.c:223
void FILE_OT_pack_libraries(struct wmOperatorType *ot)
Definition: info_ops.c:70
void FILE_OT_pack_all(struct wmOperatorType *ot)
Definition: info_ops.c:176
void INFO_OT_select_pick(struct wmOperatorType *ot)
Definition: info_report.c:186
void FILE_OT_unpack_item(struct wmOperatorType *ot)
Definition: info_ops.c:346
void FILE_OT_unpack_libraries(struct wmOperatorType *ot)
Definition: info_ops.c:99
void FILE_OT_autopack_toggle(struct wmOperatorType *ot)
Definition: info_ops.c:131
void FILE_OT_make_paths_relative(struct wmOperatorType *ot)
Definition: info_ops.c:395
void INFO_OT_select_box(struct wmOperatorType *ot)
Definition: info_report.c:302
void FILE_OT_find_missing_files(struct wmOperatorType *ot)
Definition: info_ops.c:489
void FILE_OT_unpack_all(struct wmOperatorType *ot)
Definition: info_ops.c:263
void FILE_OT_make_paths_absolute(struct wmOperatorType *ot)
Definition: info_ops.c:428
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static void area(int d1, int d2, int e1, int e2, float weights[2])
static SpaceLink * info_duplicate(SpaceLink *sl)
Definition: space_info.c:99
static void info_keymap(struct wmKeyConfig *keyconf)
Definition: space_info.c:185
static void info_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
Definition: space_info.c:95
static void info_main_region_init(wmWindowManager *wm, ARegion *region)
Definition: space_info.c:109
static void info_main_region_listener(const wmRegionListenerParams *params)
Definition: space_info.c:202
static void info_textview_update_rect(const bContext *C, ARegion *region)
Definition: space_info.c:123
static void info_header_region_draw(const bContext *C, ARegion *region)
Definition: space_info.c:197
void ED_spacetype_info(void)
Definition: space_info.c:269
static SpaceLink * info_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
Definition: space_info.c:51
static void info_free(SpaceLink *UNUSED(sl))
Definition: space_info.c:89
static void info_header_listener(const wmRegionListenerParams *params)
Definition: space_info.c:218
static void info_main_region_draw(const bContext *C, ARegion *region)
Definition: space_info.c:132
static void info_header_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
Definition: space_info.c:253
static void info_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
Definition: space_info.c:192
static void info_operatortypes(void)
Definition: space_info.c:160
void(* draw)(const struct bContext *C, struct ARegion *region)
Definition: BKE_screen.h:169
void(* message_subscribe)(const wmRegionMessageSubscribeParams *params)
Definition: BKE_screen.h:185
void(* listener)(const wmRegionListenerParams *params)
Definition: BKE_screen.h:183
int keymapflag
Definition: BKE_screen.h:226
void(* init)(struct wmWindowManager *wm, struct ARegion *region)
Definition: BKE_screen.h:165
ListBase handlers
short alignment
short regiontype
ListBase regionbase
struct SpaceLink *(* duplicate)(struct SpaceLink *sl)
Definition: BKE_screen.h:104
ListBase regiontypes
Definition: BKE_screen.h:130
void(* keymap)(struct wmKeyConfig *keyconf)
Definition: BKE_screen.h:109
void(* operatortypes)(void)
Definition: BKE_screen.h:107
void(* free)(struct SpaceLink *sl)
Definition: BKE_screen.h:88
struct SpaceLink *(* create)(const struct ScrArea *area, const struct Scene *scene)
Definition: BKE_screen.h:86
void(* init)(struct wmWindowManager *wm, struct ScrArea *area)
Definition: BKE_screen.h:91
int spaceid
Definition: BKE_screen.h:81
char name[BKE_ST_MAXNAME]
Definition: BKE_screen.h:80
float minzoom
short align
short keeptot
short keepzoom
short keepofs
short scroll
float maxzoom
unsigned int data
Definition: WM_types.h:260
unsigned int action
Definition: WM_types.h:260
unsigned int category
Definition: WM_types.h:260
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 *))