Blender  V2.93
space_statusbar.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 
21 #include <stdio.h>
22 #include <string.h>
23 
24 #include "MEM_guardedalloc.h"
25 
26 #include "BLI_blenlib.h"
27 
28 #include "BKE_context.h"
29 #include "BKE_screen.h"
30 
31 #include "ED_screen.h"
32 #include "ED_space_api.h"
33 
34 #include "RNA_access.h"
35 
36 #include "UI_interface.h"
37 
38 #include "WM_api.h"
39 #include "WM_message.h"
40 #include "WM_types.h"
41 
42 /* ******************** default callbacks for statusbar space ******************** */
43 
45 {
46  ARegion *region;
47  SpaceStatusBar *sstatusbar;
48 
49  sstatusbar = MEM_callocN(sizeof(*sstatusbar), "init statusbar");
50  sstatusbar->spacetype = SPACE_STATUSBAR;
51 
52  /* header region */
53  region = MEM_callocN(sizeof(*region), "header for statusbar");
54  BLI_addtail(&sstatusbar->regionbase, region);
55  region->regiontype = RGN_TYPE_HEADER;
56  region->alignment = RGN_ALIGN_NONE;
57 
58  return (SpaceLink *)sstatusbar;
59 }
60 
61 /* not spacelink itself */
62 static void statusbar_free(SpaceLink *UNUSED(sl))
63 {
64 }
65 
66 /* spacetype; init callback */
68 {
69 }
70 
72 {
73  SpaceStatusBar *sstatusbarn = MEM_dupallocN(sl);
74 
75  /* clear or remove stuff from old */
76 
77  return (SpaceLink *)sstatusbarn;
78 }
79 
80 /* add handlers, stuff you only do once or on area/region changes */
82 {
84  region->flag |= RGN_FLAG_DYNAMIC_SIZE;
85  }
86  ED_region_header_init(region);
87 }
88 
89 static void statusbar_operatortypes(void)
90 {
91 }
92 
93 static void statusbar_keymap(struct wmKeyConfig *UNUSED(keyconf))
94 {
95 }
96 
98 {
99  ARegion *region = params->region;
100  wmNotifier *wmn = params->notifier;
101 
102  /* context changes */
103  switch (wmn->category) {
104  case NC_SCREEN:
105  if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) {
106  ED_region_tag_redraw(region);
107  }
108  break;
109  case NC_WM:
110  if (wmn->data == ND_JOB) {
111  ED_region_tag_redraw(region);
112  }
113  break;
114  case NC_SCENE:
115  if (wmn->data == ND_RENDER_RESULT) {
116  ED_region_tag_redraw(region);
117  }
118  break;
119  case NC_SPACE:
120  if (wmn->data == ND_SPACE_INFO) {
121  ED_region_tag_redraw(region);
122  }
123  break;
124  case NC_ID:
125  if (wmn->action == NA_RENAME) {
126  ED_region_tag_redraw(region);
127  }
128  break;
129  }
130 }
131 
133 {
134  struct wmMsgBus *mbus = params->message_bus;
135  ARegion *region = params->region;
136 
137  wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
138  .owner = region,
139  .user_data = region,
141  };
142 
143  WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
144  WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
145 }
146 
147 /* only called once, from space/spacetypes.c */
149 {
150  SpaceType *st = MEM_callocN(sizeof(*st), "spacetype statusbar");
151  ARegionType *art;
152 
153  st->spaceid = SPACE_STATUSBAR;
154  strncpy(st->name, "Status Bar", BKE_ST_MAXNAME);
155 
156  st->create = statusbar_create;
157  st->free = statusbar_free;
158  st->init = statusbar_init;
161  st->keymap = statusbar_keymap;
162 
163  /* regions: header window */
164  art = MEM_callocN(sizeof(*art), "spacetype statusbar header region");
165  art->regionid = RGN_TYPE_HEADER;
166  art->prefsizey = 0.8f * HEADERY;
167  art->prefsizex = UI_UNIT_X * 5; /* Mainly to avoid glitches */
174  BLI_addhead(&st->regiontypes, art);
175 
177 }
#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
#define RGN_ALIGN_ENUM_FROM_MASK(align)
@ RGN_ALIGN_RIGHT
@ RGN_ALIGN_NONE
@ RGN_FLAG_DYNAMIC_SIZE
@ RGN_TYPE_HEADER
@ SPACE_STATUSBAR
void ED_region_do_msg_notify_tag_redraw(struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val)
void ED_region_header_layout(const struct bContext *C, struct ARegion *region)
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
void ED_region_header_draw(const struct bContext *C, struct ARegion *region)
Read Guarded memory(de)allocation.
#define UI_UNIT_X
#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_LAYER
Definition: WM_types.h:350
#define NA_RENAME
Definition: WM_types.h:466
#define NC_SPACE
Definition: WM_types.h:293
Scene scene
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 void statusbar_free(SpaceLink *UNUSED(sl))
static SpaceLink * statusbar_duplicate(SpaceLink *sl)
static void statusbar_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
static void statusbar_keymap(struct wmKeyConfig *UNUSED(keyconf))
static void statusbar_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
static void statusbar_header_region_listener(const wmRegionListenerParams *params)
static void statusbar_operatortypes(void)
static SpaceLink * statusbar_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
static void statusbar_header_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
void ED_spacetype_statusbar(void)
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(* layout)(const struct bContext *C, struct ARegion *region)
Definition: BKE_screen.h:179
void(* init)(struct wmWindowManager *wm, struct ARegion *region)
Definition: BKE_screen.h:165
short alignment
short regiontype
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
unsigned int data
Definition: WM_types.h:260
unsigned int action
Definition: WM_types.h:260
unsigned int category
Definition: WM_types.h:260
#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value)