Blender V4.3
space_userpref.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 "RNA_access.hh"
24#include "RNA_enum_types.hh"
25
26#include "WM_types.hh"
27
28#include "UI_interface.hh"
29
30#include "BLO_read_write.hh"
31
32/* ******************** default callbacks for userpref space ***************** */
33
34static SpaceLink *userpref_create(const ScrArea *area, const Scene * /*scene*/)
35{
36 ARegion *region;
37 SpaceUserPref *spref;
38
39 spref = static_cast<SpaceUserPref *>(MEM_callocN(sizeof(SpaceUserPref), "inituserpref"));
41
42 /* header */
43 region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "header for userpref"));
44
45 BLI_addtail(&spref->regionbase, region);
46 region->regiontype = RGN_TYPE_HEADER;
47 /* Ignore user preference "USER_HEADER_BOTTOM" here (always show bottom for new types). */
48 region->alignment = RGN_ALIGN_BOTTOM;
49
50 /* navigation region */
51 region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "navigation region for userpref"));
52
53 BLI_addtail(&spref->regionbase, region);
54 region->regiontype = RGN_TYPE_NAV_BAR;
55 region->alignment = RGN_ALIGN_LEFT;
56
57 /* Use smaller size when opened in area like properties editor. */
58 if (area->winx && area->winx < 3.0f * UI_NAVIGATION_REGION_WIDTH * UI_SCALE_FAC) {
60 }
61
62 /* execution region */
63 region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "execution region for userpref"));
64
65 BLI_addtail(&spref->regionbase, region);
66 region->regiontype = RGN_TYPE_EXECUTE;
67 region->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
69
70 /* main region */
71 region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "main region for userpref"));
72
73 BLI_addtail(&spref->regionbase, region);
74 region->regiontype = RGN_TYPE_WINDOW;
75
76 return (SpaceLink *)spref;
77}
78
79/* Doesn't free the space-link itself. */
80static void userpref_free(SpaceLink * /*sl*/)
81{
82 // SpaceUserPref *spref = (SpaceUserPref *)sl;
83}
84
85/* spacetype; init callback */
86static void userpref_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
87
89{
90 SpaceUserPref *sprefn = static_cast<SpaceUserPref *>(MEM_dupallocN(sl));
91
92 /* clear or remove stuff from old */
93
94 return (SpaceLink *)sprefn;
95}
96
97/* add handlers, stuff you only do once or on area/region changes */
99{
100 /* do not use here, the properties changed in user-preferences do a system-wide refresh,
101 * then scroller jumps back */
102 // region->v2d.flag &= ~V2D_IS_INIT;
103
104 region->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
105
106 ED_region_panels_init(wm, region);
107}
108
109static void userpref_main_region_layout(const bContext *C, ARegion *region)
110{
111 char id_lower[64];
112 const char *contexts[2] = {id_lower, nullptr};
113
114 /* Avoid duplicating identifiers, use existing RNA enum. */
115 {
117 int i = RNA_enum_from_value(items, U.space_data.section_active);
118 /* File is from the future. */
119 if (i == -1) {
120 i = 0;
121 }
122 const char *id = items[i].identifier;
123 BLI_assert(strlen(id) < sizeof(id_lower));
124 STRNCPY(id_lower, id);
125 BLI_str_tolower_ascii(id_lower, strlen(id_lower));
126 }
127
129 C, region, &region->type->paneltypes, WM_OP_INVOKE_REGION_WIN, contexts, nullptr);
130}
131
133
134static void userpref_keymap(wmKeyConfig * /*keyconf*/) {}
135
136/* add handlers, stuff you only do once or on area/region changes */
138{
139 ED_region_header_init(region);
140}
141
142static void userpref_header_region_draw(const bContext *C, ARegion *region)
143{
144 ED_region_header(C, region);
145}
146
147/* add handlers, stuff you only do once or on area/region changes */
149{
150 region->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
151
152 ED_region_panels_init(wm, region);
153}
154
156{
157 ED_region_panels(C, region);
158}
159
161{
162 const ARegion *region_header = BKE_area_find_region_type(params->area, RGN_TYPE_HEADER);
163 return !region_header->visible;
164}
165
166/* add handlers, stuff you only do once or on area/region changes */
168{
169 ED_region_panels_init(wm, region);
170 region->v2d.keepzoom |= V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y;
171}
172
174
175static void userpref_header_listener(const wmRegionListenerParams * /*params*/) {}
176
178
180
182{
183 BLO_write_struct(writer, SpaceUserPref, sl);
184}
185
187{
188 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
189 ARegionType *art;
190
191 st->spaceid = SPACE_USERPREF;
192 STRNCPY(st->name, "Userpref");
193
194 st->create = userpref_create;
195 st->free = userpref_free;
196 st->init = userpref_init;
197 st->duplicate = userpref_duplicate;
198 st->operatortypes = userpref_operatortypes;
199 st->keymap = userpref_keymap;
200 st->blend_write = userpref_space_blend_write;
201
202 /* regions: main window */
203 art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype userpref region"));
210
211 BLI_addhead(&st->regiontypes, art);
212
213 /* regions: header */
214 art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype userpref region"));
216 art->prefsizey = HEADERY;
221
222 BLI_addhead(&st->regiontypes, art);
223
224 /* regions: navigation window */
225 art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype userpref region"));
232
233 BLI_addhead(&st->regiontypes, art);
234
235 /* regions: execution window */
236 art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype userpref region"));
238 art->prefsizey = HEADERY;
245
246 BLI_addhead(&st->regiontypes, art);
247
248 BKE_spacetype_register(std::move(st));
249}
void BKE_spacetype_register(std::unique_ptr< SpaceType > st)
Definition screen.cc:268
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:815
#define BLI_assert(a)
Definition BLI_assert.h:50
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
void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(1)
Definition string.c:952
#define BLO_write_struct(writer, struct_name, data_ptr)
#define HEADERY
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_LEFT
@ RGN_SPLIT_PREV
@ RGN_TYPE_EXECUTE
@ RGN_TYPE_WINDOW
@ RGN_TYPE_NAV_BAR
@ RGN_TYPE_HEADER
@ RGN_FLAG_DYNAMIC_SIZE
@ RGN_FLAG_NO_USER_RESIZE
@ SPACE_USERPREF
#define UI_SCALE_FAC
@ V2D_SCROLL_VERTICAL_HIDE
@ V2D_SCROLL_RIGHT
@ V2D_LOCKZOOM_X
@ V2D_LOCKZOOM_Y
void ED_region_panels(const bContext *C, ARegion *region)
Definition area.cc:3336
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_panels_layout_ex(const bContext *C, ARegion *region, ListBase *paneltypes, wmOperatorCallContext op_context, const char *contexts[], const char *category_override)
Definition area.cc:3099
void ED_region_panels_layout(const bContext *C, ARegion *region)
Definition area.cc:3271
void ED_region_panels_init(wmWindowManager *wm, ARegion *region)
Definition area.cc:3343
@ ED_KEYMAP_NAVBAR
Definition ED_screen.hh:734
@ ED_KEYMAP_UI
Definition ED_screen.hh:725
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:731
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:728
void ED_region_panels_draw(const bContext *C, ARegion *region)
Definition area.cc:3277
Read Guarded memory(de)allocation.
#define UI_NAVIGATION_REGION_WIDTH
#define UI_NARROW_NAVIGATION_REGION_WIDTH
@ WM_OP_INVOKE_REGION_WIN
Definition WM_types.hh:219
unsigned int U
Definition btGjkEpa3.h:78
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
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
const EnumPropertyItem rna_enum_preference_section_items[]
static void userpref_main_region_listener(const wmRegionListenerParams *)
void ED_spacetype_userpref()
static void userpref_keymap(wmKeyConfig *)
static void userpref_operatortypes()
static void userpref_init(wmWindowManager *, ScrArea *)
static bool userpref_execute_region_poll(const RegionPollParams *params)
static void userpref_execute_region_listener(const wmRegionListenerParams *)
static SpaceLink * userpref_create(const ScrArea *area, const Scene *)
static void userpref_navigation_region_listener(const wmRegionListenerParams *)
static void userpref_free(SpaceLink *)
static void userpref_execute_region_init(wmWindowManager *wm, ARegion *region)
static void userpref_space_blend_write(BlendWriter *writer, SpaceLink *sl)
static void userpref_main_region_layout(const bContext *C, ARegion *region)
static void userpref_header_listener(const wmRegionListenerParams *)
static void userpref_main_region_init(wmWindowManager *wm, ARegion *region)
static SpaceLink * userpref_duplicate(SpaceLink *sl)
static void userpref_header_region_draw(const bContext *C, ARegion *region)
static void userpref_header_region_init(wmWindowManager *, ARegion *region)
static void userpref_navigation_region_draw(const bContext *C, ARegion *region)
static void userpref_navigation_region_init(wmWindowManager *wm, ARegion *region)
bool(* poll)(const RegionPollParams *params)
void(* listener)(const wmRegionListenerParams *params)
void(* draw)(const bContext *C, ARegion *region)
void(* layout)(const bContext *C, ARegion *region)
void(* init)(wmWindowManager *wm, ARegion *region)
const char * identifier
Definition RNA_types.hh:506