UI: Asset Shelf (Experimental Feature) #104831
|
@ -163,7 +163,8 @@ typedef struct RegionPollParams {
|
||||||
const struct ScrArea *area;
|
const struct ScrArea *area;
|
||||||
const struct ARegion *region;
|
const struct ARegion *region;
|
||||||
|
|
||||||
/* For now only WM context members here, could add the scene or even #bContext if needed. */
|
/* Full context, if WM context above is not enough. */
|
||||||
|
const struct bContext *context;
|
||||||
} RegionPollParams;
|
} RegionPollParams;
|
||||||
|
|
||||||
typedef struct ARegionType {
|
typedef struct ARegionType {
|
||||||
|
|
|
@ -17,10 +17,13 @@ struct bContextDataResult;
|
||||||
struct BlendDataReader;
|
struct BlendDataReader;
|
||||||
struct BlendWriter;
|
struct BlendWriter;
|
||||||
struct wmWindowManager;
|
struct wmWindowManager;
|
||||||
|
struct RegionPollParams;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* Asset Shelf Regions */
|
/* Asset Shelf Regions */
|
||||||
|
|
||||||
|
bool ED_asset_shelf_poll(const struct RegionPollParams *params);
|
||||||
|
|
||||||
/** Only needed for #RGN_TYPE_ASSET_SHELF (not #RGN_TYPE_ASSET_SHELF_FOOTER). */
|
/** Only needed for #RGN_TYPE_ASSET_SHELF (not #RGN_TYPE_ASSET_SHELF_FOOTER). */
|
||||||
void ED_asset_shelf_region_listen(const struct wmRegionListenerParams *params);
|
void ED_asset_shelf_region_listen(const struct wmRegionListenerParams *params);
|
||||||
void ED_asset_shelf_region_draw(const bContext *C, struct ARegion *region);
|
void ED_asset_shelf_region_draw(const bContext *C, struct ARegion *region);
|
||||||
|
|
|
@ -46,6 +46,26 @@ void send_redraw_notifier(const bContext &C)
|
||||||
/** \name Asset Shelf Regions
|
/** \name Asset Shelf Regions
|
||||||
* \{ */
|
* \{ */
|
||||||
|
|
||||||
|
static bool asset_shelf_poll(const bContext *C, const SpaceLink *space_link)
|
||||||
|
{
|
||||||
|
const SpaceType *space_type = BKE_spacetype_from_id(space_link->spacetype);
|
||||||
|
|
||||||
|
/* Is there any asset shelf type registered that returns true for it's poll? */
|
||||||
|
LISTBASE_FOREACH (AssetShelfType *, shelf_type, &space_type->asset_shelf_types) {
|
||||||
|
if (shelf_type->poll && shelf_type->poll(C, shelf_type)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ED_asset_shelf_poll(const RegionPollParams *params)
|
||||||
|
{
|
||||||
|
return asset_shelf_poll(params->context,
|
||||||
|
static_cast<SpaceLink *>(params->area->spacedata.first));
|
||||||
|
}
|
||||||
|
|
||||||
static void asset_shelf_region_listen(const wmRegionListenerParams *params)
|
static void asset_shelf_region_listen(const wmRegionListenerParams *params)
|
||||||
{
|
{
|
||||||
ARegion *region = params->region;
|
ARegion *region = params->region;
|
||||||
|
@ -83,17 +103,7 @@ void ED_asset_shelf_region_listen(const wmRegionListenerParams *params)
|
||||||
*/
|
*/
|
||||||
static bool asset_shelf_region_header_type_poll(const bContext *C, HeaderType * /*header_type*/)
|
static bool asset_shelf_region_header_type_poll(const bContext *C, HeaderType * /*header_type*/)
|
||||||
{
|
{
|
||||||
const SpaceLink *space_link = CTX_wm_space_data(C);
|
return asset_shelf_poll(C, CTX_wm_space_data(C));
|
||||||
const SpaceType *space_type = BKE_spacetype_from_id(space_link->spacetype);
|
|
||||||
|
|
||||||
/* Is there any asset shelf type registered that returns true for it's poll? */
|
|
||||||
LISTBASE_FOREACH (AssetShelfType *, shelf_type, &space_type->asset_shelf_types) {
|
|
||||||
if (shelf_type->poll && shelf_type->poll(C, shelf_type)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ED_asset_shelf_region_draw(const bContext *C, ARegion *region)
|
void ED_asset_shelf_region_draw(const bContext *C, ARegion *region)
|
||||||
|
|
|
@ -713,7 +713,10 @@ void ED_screens_init(Main *bmain, wmWindowManager *wm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool region_poll(const bScreen *screen, const ScrArea *area, const ARegion *region)
|
static bool region_poll(const bContext *C,
|
||||||
|
const bScreen *screen,
|
||||||
|
const ScrArea *area,
|
||||||
|
const ARegion *region)
|
||||||
{
|
{
|
||||||
if (!region->type || !region->type->poll) {
|
if (!region->type || !region->type->poll) {
|
||||||
/* Show region by default. */
|
/* Show region by default. */
|
||||||
|
@ -724,20 +727,27 @@ static bool region_poll(const bScreen *screen, const ScrArea *area, const ARegio
|
||||||
params.screen = screen;
|
params.screen = screen;
|
||||||
params.area = area;
|
params.area = area;
|
||||||
params.region = region;
|
params.region = region;
|
||||||
|
params.context = C;
|
||||||
|
|
||||||
return region->type->poll(¶ms);
|
return region->type->poll(¶ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void screen_regions_poll(bContext *C, const wmWindow *win, bScreen *screen)
|
static void screen_regions_poll(bContext *C, const wmWindow *win, bScreen *screen)
|
||||||
{
|
{
|
||||||
|
ScrArea *prev_area = CTX_wm_area(C);
|
||||||
|
ARegion *prev_region = CTX_wm_region(C);
|
||||||
|
|
||||||
bool any_changed = false;
|
bool any_changed = false;
|
||||||
ED_screen_areas_iter (win, screen, area) {
|
ED_screen_areas_iter (win, screen, area) {
|
||||||
|
CTX_wm_area_set(C, area);
|
||||||
|
|
||||||
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
|
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
|
||||||
const int old_region_flag = region->flag;
|
const int old_region_flag = region->flag;
|
||||||
|
|
||||||
region->flag &= ~RGN_FLAG_POLL_FAILED;
|
region->flag &= ~RGN_FLAG_POLL_FAILED;
|
||||||
|
|
||||||
if (region_poll(screen, area, region) == false) {
|
CTX_wm_region_set(C, region);
|
||||||
|
if (region_poll(C, screen, area, region) == false) {
|
||||||
region->flag |= RGN_FLAG_POLL_FAILED;
|
region->flag |= RGN_FLAG_POLL_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,6 +764,8 @@ static void screen_regions_poll(bContext *C, const wmWindow *win, bScreen *scree
|
||||||
if (any_changed) {
|
if (any_changed) {
|
||||||
screen->do_refresh = true;
|
screen->do_refresh = true;
|
||||||
}
|
}
|
||||||
|
CTX_wm_area_set(C, prev_area);
|
||||||
|
CTX_wm_region_set(C, prev_region);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ED_screen_ensure_updated(bContext *C, wmWindowManager *wm, wmWindow *win, bScreen *screen)
|
void ED_screen_ensure_updated(bContext *C, wmWindowManager *wm, wmWindow *win, bScreen *screen)
|
||||||
|
|
|
@ -2244,6 +2244,7 @@ void ED_spacetype_view3d()
|
||||||
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_ASSET_SHELF | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES |
|
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_ASSET_SHELF | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES |
|
||||||
ED_KEYMAP_HEADER;
|
ED_KEYMAP_HEADER;
|
||||||
art->listener = ED_asset_shelf_region_listen;
|
art->listener = ED_asset_shelf_region_listen;
|
||||||
|
art->poll = ED_asset_shelf_poll;
|
||||||
art->context = view3d_asset_shelf_context;
|
art->context = view3d_asset_shelf_context;
|
||||||
art->init = view3d_header_region_init;
|
art->init = view3d_header_region_init;
|
||||||
art->draw = ED_asset_shelf_region_draw;
|
art->draw = ED_asset_shelf_region_draw;
|
||||||
|
@ -2256,6 +2257,7 @@ void ED_spacetype_view3d()
|
||||||
art->prefsizey = HEADERY;
|
art->prefsizey = HEADERY;
|
||||||
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_ASSET_SHELF | ED_KEYMAP_VIEW2D | ED_KEYMAP_FOOTER;
|
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_ASSET_SHELF | ED_KEYMAP_VIEW2D | ED_KEYMAP_FOOTER;
|
||||||
art->init = ED_asset_shelf_footer_region_init;
|
art->init = ED_asset_shelf_footer_region_init;
|
||||||
|
art->poll = ED_asset_shelf_poll;
|
||||||
art->draw = ED_asset_shelf_footer_region;
|
art->draw = ED_asset_shelf_footer_region;
|
||||||
art->listener = ED_asset_shelf_footer_region_listen;
|
art->listener = ED_asset_shelf_footer_region_listen;
|
||||||
art->context = view3d_asset_shelf_context;
|
art->context = view3d_asset_shelf_context;
|
||||||
|
|
Loading…
Reference in New Issue