1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file
* \ingroup spassets
*/
#include <cstring>
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "BKE_asset.h"
#include "BKE_screen.h"
#include "BLI_listbase.h"
#include "ED_asset.h"
#include "ED_screen.h"
#include "ED_space_api.h"
#include "MEM_guardedalloc.h"
#include "RNA_access.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"
#include "WM_api.h"
#include "WM_message.h"
#include "asset_browser_intern.hh"
#include "asset_view.hh"
/* ---------------------------------------------------------------------- */
/* Asset Browser Space */
static SpaceLink *asset_browser_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
SpaceAssets *assets_space = MEM_cnew<SpaceAssets>("asset browser space");
assets_space->spacetype = SPACE_ASSETS;
BKE_asset_library_reference_init_default(&assets_space->asset_library_ref);
{
/* Header. */
ARegion *region = MEM_cnew<ARegion>("asset browser header");
BLI_addtail(&assets_space->regionbase, region);
region->regiontype = RGN_TYPE_HEADER;
region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
}
{
/* Navigation region */
ARegion *region = MEM_cnew<ARegion>("asset browser navigation region");
BLI_addtail(&assets_space->regionbase, region);
region->regiontype = RGN_TYPE_NAV_BAR;
region->alignment = RGN_ALIGN_LEFT;
}
{
/* Sidebar region */
ARegion *region = MEM_cnew<ARegion>("asset browser sidebar region");
BLI_addtail(&assets_space->regionbase, region);
region->regiontype = RGN_TYPE_UI;
region->alignment = RGN_ALIGN_RIGHT;
region->flag = RGN_FLAG_HIDDEN;
}
{
/* Main region. */
ARegion *region = MEM_cnew<ARegion>("asset browser main region");
BLI_addtail(&assets_space->regionbase, region);
region->regiontype = RGN_TYPE_WINDOW;
region->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM);
region->v2d.align = (V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_POS_Y);
region->v2d.keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | V2D_KEEPASPECT);
region->v2d.keeptot = V2D_KEEPTOT_STRICT;
region->v2d.minzoom = region->v2d.maxzoom = 1.0f;
}
return (SpaceLink *)assets_space;
}
static void asset_browser_free(SpaceLink *UNUSED(sl))
{
}
static void asset_browser_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
{
}
static SpaceLink *asset_browser_duplicate(SpaceLink *sl)
{
const SpaceAssets *asset_browser_old = (SpaceAssets *)sl;
SpaceAssets *asset_browser_new = reinterpret_cast<SpaceAssets *>(
MEM_dupallocN(asset_browser_old));
return (SpaceLink *)asset_browser_new;
}
static void asset_browser_keymap(wmKeyConfig *keyconf)
{
/* keys for all regions */
WM_keymap_ensure(keyconf, "Asset Browser", SPACE_ASSETS, 0);
}
const char *asset_browser_context_dir[] = {
"asset_handle",
"asset_library_ref",
NULL,
};
static int /*eContextResult*/ asset_browser_context(const bContext *C,
const char *member,
bContextDataResult *result)
{
if (CTX_data_dir(member)) {
CTX_data_dir_set(result, asset_browser_context_dir);
return CTX_RESULT_OK;
}
bScreen *screen = CTX_wm_screen(C);
SpaceAssets *assets_space = CTX_wm_space_assets(C);
if (CTX_data_equals(member, "asset_library_ref")) {
CTX_data_pointer_set(
result, &screen->id, &RNA_AssetLibraryReference, &assets_space->asset_library_ref);
return CTX_RESULT_OK;
}
if (CTX_data_equals(member, "asset_handle")) {
AssetHandle *asset = ED_assetlist_asset_get_from_index(&assets_space->asset_library_ref,
assets_space->active_asset_idx);
if (!asset) {
return CTX_RESULT_NO_DATA;
}
CTX_data_pointer_set(result, &screen->id, &RNA_AssetHandle, asset);
return CTX_RESULT_OK;
}
return CTX_RESULT_MEMBER_NOT_FOUND;
}
/* ---------------------------------------------------------------------- */
/* Main Region */
static void asset_browser_main_region_init(wmWindowManager *wm, ARegion *region)
{
UI_view2d_region_reinit(®ion->v2d, V2D_COMMONVIEW_LIST, region->winx, region->winy);
{
wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Asset Browser", SPACE_ASSETS, 0);
WM_event_add_keymap_handler(®ion->handlers, keymap);
}
}
static void asset_browser_main_region_listener(const wmRegionListenerParams *params)
{
wmNotifier *notifier = params->notifier;
ARegion *region = params->region;
switch (notifier->category) {
case NC_ASSET:
if (ELEM(notifier->data, ND_SPACE_ASSET_PARAMS)) {
ED_region_tag_redraw(region);
}
break;
}
}
/* FIXME: See comment above #WM_msg_publish_rna_prop(). */
extern "C" {
static void asset_browser_main_region_message_subscribe(
const wmRegionMessageSubscribeParams *params)
{
struct wmMsgBus *mbus = params->message_bus;
bScreen *screen = params->screen;
SpaceAssets *assets_space = reinterpret_cast<SpaceAssets *>(params->area->spacedata.first);
wmMsgSubscribeValue msg_sub_value_region_tag_redraw{};
msg_sub_value_region_tag_redraw.owner = params->region;
msg_sub_value_region_tag_redraw.user_data = params->region;
msg_sub_value_region_tag_redraw.notify = ED_region_do_msg_notify_tag_redraw;
WM_msg_subscribe_rna_prop(mbus,
&screen->id,
assets_space,
SpaceAssetBrowser,
catalog_filter,
&msg_sub_value_region_tag_redraw);
}
}
/* ---------------------------------------------------------------------- */
/* Header Region */
static void asset_browser_header_init(wmWindowManager *UNUSED(wm), ARegion *region)
{
ED_region_header_init(region);
}
static void asset_browser_header_listener(const wmRegionListenerParams *UNUSED(params))
{
}
/* ---------------------------------------------------------------------- */
/* Navigation Region */
static void asset_browser_navigation_region_init(wmWindowManager *wm, ARegion *region)
{
region->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
ED_region_panels_init(wm, region);
{
wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Asset Browser", SPACE_ASSETS, 0);
WM_event_add_keymap_handler(®ion->handlers, keymap);
}
}
static void asset_browser_navigation_region_draw(const bContext *C, ARegion *region)
{
ED_region_panels(C, region);
}
static void asset_browser_navigation_region_listener(
const wmRegionListenerParams *UNUSED(listener_params))
{
}
/* ---------------------------------------------------------------------- */
/* Sidebar Region */
static void asset_browser_sidebar_region_init(wmWindowManager *wm, ARegion *region)
{
region->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
ED_region_panels_init(wm, region);
{
wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Asset Browser", SPACE_ASSETS, 0);
WM_event_add_keymap_handler(®ion->handlers, keymap);
}
}
static void asset_browser_sidebar_region_draw(const bContext *C, ARegion *region)
{
ED_region_panels(C, region);
}
static void asset_browser_sidebar_region_listener(
const wmRegionListenerParams *UNUSED(listener_params))
{
}
/* ---------------------------------------------------------------------- */
/* Asset Browser Space-Type */
void ED_spacetype_assets(void)
{
SpaceType *st = MEM_cnew<SpaceType>("spacetype asset browser");
ARegionType *art;
st->spaceid = SPACE_ASSETS;
strncpy(st->name, "Asset Browser", BKE_ST_MAXNAME);
st->create = asset_browser_create;
st->free = asset_browser_free;
st->init = asset_browser_init;
st->duplicate = asset_browser_duplicate;
st->operatortypes = asset_browser_operatortypes;
st->keymap = asset_browser_keymap;
st->context = asset_browser_context;
/* Main region. */
art = MEM_cnew<ARegionType>("spacetype asset browser main region");
art->regionid = RGN_TYPE_WINDOW;
art->init = asset_browser_main_region_init;
art->draw = asset_browser_main_region_draw;
art->listener = asset_browser_main_region_listener;
art->message_subscribe = asset_browser_main_region_message_subscribe;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
BLI_addhead(&st->regiontypes, art);
/* Header region. */
art = MEM_cnew<ARegionType>("spacetype asset browser header region");
art->regionid = RGN_TYPE_HEADER;
art->prefsizey = HEADERY;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
art->listener = asset_browser_header_listener;
art->init = asset_browser_header_init;
art->layout = ED_region_header_layout;
art->draw = ED_region_header_draw;
BLI_addhead(&st->regiontypes, art);
/* Navigation region */
art = MEM_cnew<ARegionType>("spacetype asset browser navigation region");
art->regionid = RGN_TYPE_NAV_BAR;
art->prefsizex = UI_COMPACT_PANEL_WIDTH;
art->init = asset_browser_navigation_region_init;
art->draw = asset_browser_navigation_region_draw;
art->listener = asset_browser_navigation_region_listener;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_NAVBAR;
asset_browser_navigation_region_panels_register(art);
BLI_addhead(&st->regiontypes, art);
/* Sidebar region */
art = MEM_cnew<ARegionType>("spacetype asset browser sidebar region");
art->regionid = RGN_TYPE_UI;
art->prefsizex = 240;
art->init = asset_browser_sidebar_region_init;
art->draw = asset_browser_sidebar_region_draw;
art->listener = asset_browser_sidebar_region_listener;
art->keymapflag = ED_KEYMAP_UI;
BLI_addhead(&st->regiontypes, art);
BKE_spacetype_register(st);
}
|