Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface_handlers.c2
-rw-r--r--source/blender/editors/interface/interface_panel.c70
-rw-r--r--source/blender/editors/interface/interface_templates.c4
-rw-r--r--source/blender/editors/interface/interface_utils.c19
4 files changed, 49 insertions, 46 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 336f942ad8c..42feda0e1bc 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -10892,7 +10892,7 @@ static void ui_popup_handler_remove(bContext *C, void *userdata)
/* More correct would be to expect UI_RETURN_CANCEL here, but not wanting to
* cancel when removing handlers because of file exit is a rare exception.
* So instead of setting cancel flag for all menus before removing handlers,
- * just explicitly flag menu with UI_RETURN_OK to avoid cancelling it. */
+ * just explicitly flag menu with UI_RETURN_OK to avoid canceling it. */
if ((menu->menuretval & UI_RETURN_OK) == 0 && menu->cancel_func) {
menu->cancel_func(C, menu->popup_arg);
}
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 5f56a93c5eb..55657d7297a 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -354,13 +354,19 @@ static void panel_delete(ARegion *region, ListBase *panels, Panel *panel)
MEM_freeN(panel);
}
+/**
+ * Remove instanced panels from the region's panel list.
+ *
+ * \note Can be called with NULL \a C, but it should be avoided because
+ * handlers might not be removed.
+ */
void UI_panels_free_instanced(bContext *C, ARegion *region)
{
/* Delete panels with the instanced flag. */
LISTBASE_FOREACH_MUTABLE (Panel *, panel, &region->panels) {
if ((panel->type != NULL) && (panel->type->flag & PNL_INSTANCED)) {
/* Make sure the panel's handler is removed before deleting it. */
- if (panel->activedata != NULL) {
+ if (C != NULL && panel->activedata != NULL) {
panel_activate_state(C, panel, PANEL_STATE_EXIT);
}
panel_delete(region, &region->panels, panel);
@@ -586,9 +592,8 @@ static void panels_collapse_all(const bContext *C,
const char *category = has_category_tabs ? UI_panel_category_active_get(region, false) : NULL;
const int flag = ((panel_aligned(area, region) == BUT_HORIZONTAL) ? PNL_CLOSEDX : PNL_CLOSEDY);
const PanelType *from_pt = from_panel->type;
- Panel *panel;
- for (panel = region->panels.first; panel; panel = panel->next) {
+ LISTBASE_FOREACH (Panel *, panel, &region->panels) {
PanelType *pt = panel->type;
/* close panels with headers in the same context */
@@ -615,10 +620,9 @@ static bool panel_type_context_poll(PanelType *panel_type, const char *context)
Panel *UI_panel_find_by_type(ListBase *lb, PanelType *pt)
{
- Panel *panel;
const char *idname = pt->idname;
- for (panel = lb->first; panel; panel = panel->next) {
+ LISTBASE_FOREACH (Panel *, panel, lb) {
if (STREQLEN(panel->panelname, idname, sizeof(panel->panelname))) {
return panel;
}
@@ -637,7 +641,7 @@ Panel *UI_panel_begin(ScrArea *area,
Panel *panel,
bool *r_open)
{
- Panel *panel_last, *panel_next;
+ Panel *panel_last;
const char *drawname = CTX_IFACE_(pt->translation_context, pt->label);
const char *idname = pt->idname;
const bool newpanel = (panel == NULL);
@@ -698,7 +702,7 @@ Panel *UI_panel_begin(ScrArea *area,
if (newpanel) {
panel->sortorder = (panel_last) ? panel_last->sortorder + 1 : 0;
- for (panel_next = lb->first; panel_next; panel_next = panel_next->next) {
+ LISTBASE_FOREACH (Panel *, panel_next, lb) {
if (panel_next != panel && panel_next->sortorder >= panel->sortorder) {
panel_next->sortorder++;
}
@@ -1393,14 +1397,13 @@ static void align_sub_panels(Panel *panel)
/* returns 1 when it did something */
static bool uiAlignPanelStep(ScrArea *area, ARegion *region, const float fac, const bool drag)
{
- Panel *panel;
PanelSort *ps, *panelsort, *psnext;
int a, tot = 0;
bool done;
int align = panel_aligned(area, region);
/* count active, not tabbed panels */
- for (panel = region->panels.first; panel; panel = panel->next) {
+ LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->runtime_flag & PNL_ACTIVE) {
tot++;
}
@@ -1411,7 +1414,7 @@ static bool uiAlignPanelStep(ScrArea *area, ARegion *region, const float fac, co
}
/* extra; change close direction? */
- for (panel = region->panels.first; panel; panel = panel->next) {
+ LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->runtime_flag & PNL_ACTIVE) {
if ((panel->flag & PNL_CLOSEDX) && (align == BUT_VERTICAL)) {
panel->flag ^= PNL_CLOSED;
@@ -1426,7 +1429,7 @@ static bool uiAlignPanelStep(ScrArea *area, ARegion *region, const float fac, co
panelsort = MEM_callocN(tot * sizeof(PanelSort), "panelsort");
ps = panelsort;
- for (panel = region->panels.first; panel; panel = panel->next) {
+ LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->runtime_flag & PNL_ACTIVE) {
ps->panel = MEM_dupallocN(panel);
ps->orig = panel;
@@ -1506,7 +1509,7 @@ static bool uiAlignPanelStep(ScrArea *area, ARegion *region, const float fac, co
}
/* set locations for tabbed and sub panels */
- for (panel = region->panels.first; panel; panel = panel->next) {
+ LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->runtime_flag & PNL_ACTIVE) {
if (panel->children.first) {
align_sub_panels(panel);
@@ -1525,13 +1528,12 @@ static bool uiAlignPanelStep(ScrArea *area, ARegion *region, const float fac, co
static void ui_panels_size(ScrArea *area, ARegion *region, int *r_x, int *r_y)
{
- Panel *panel;
int align = panel_aligned(area, region);
int sizex = 0;
int sizey = 0;
/* compute size taken up by panels, for setting in view2d */
- for (panel = region->panels.first; panel; panel = panel->next) {
+ LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->runtime_flag & PNL_ACTIVE) {
int pa_sizex, pa_sizey;
@@ -1617,11 +1619,10 @@ void UI_panels_begin(const bContext *UNUSED(C), ARegion *region)
void UI_panels_end(const bContext *C, ARegion *region, int *r_x, int *r_y)
{
ScrArea *area = CTX_wm_area(C);
- uiBlock *block;
Panel *panel, *panel_first;
/* offset contents */
- for (block = region->uiblocks.first; block; block = block->next) {
+ LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
if (block->active && block->panel) {
ui_offset_panel_block(block);
}
@@ -1639,7 +1640,7 @@ void UI_panels_end(const bContext *C, ARegion *region, int *r_x, int *r_y)
/* tag first panel */
panel_first = NULL;
- for (block = region->uiblocks.first; block; block = block->next) {
+ LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
if (block->active && block->panel) {
if (!panel_first || block->panel->sortorder < panel_first->sortorder) {
panel_first = block->panel;
@@ -1657,8 +1658,6 @@ void UI_panels_end(const bContext *C, ARegion *region, int *r_x, int *r_y)
void UI_panels_draw(const bContext *C, ARegion *region)
{
- uiBlock *block;
-
if (region->alignment != RGN_ALIGN_FLOAT) {
UI_ThemeClearColor(TH_BACK);
}
@@ -1666,13 +1665,13 @@ void UI_panels_draw(const bContext *C, ARegion *region)
/* Draw panels, selected on top. Also in reverse order, because
* UI blocks are added in reverse order and we need child panels
* to draw on top. */
- for (block = region->uiblocks.last; block; block = block->prev) {
+ LISTBASE_FOREACH_BACKWARD (uiBlock *, block, &region->uiblocks) {
if (block->active && block->panel && !(block->panel->flag & PNL_SELECT)) {
UI_block_draw(C, block);
}
}
- for (block = region->uiblocks.last; block; block = block->prev) {
+ LISTBASE_FOREACH_BACKWARD (uiBlock *, block, &region->uiblocks) {
if (block->active && block->panel && (block->panel->flag & PNL_SELECT)) {
UI_block_draw(C, block);
}
@@ -1681,15 +1680,12 @@ void UI_panels_draw(const bContext *C, ARegion *region)
void UI_panels_scale(ARegion *region, float new_width)
{
- uiBlock *block;
- uiBut *but;
-
- for (block = region->uiblocks.first; block; block = block->next) {
+ LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
if (block->panel) {
float fac = new_width / (float)block->panel->sizex;
block->panel->sizex = new_width;
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
but->rect.xmin *= fac;
but->rect.xmax *= fac;
}
@@ -1845,10 +1841,9 @@ static void ui_panel_drag_collapse(bContext *C,
{
ScrArea *area = CTX_wm_area(C);
ARegion *region = CTX_wm_region(C);
- uiBlock *block;
Panel *panel;
- for (block = region->uiblocks.first; block; block = block->next) {
+ LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
float xy_a_block[2] = {UNPACK2(dragcol_data->xy_init)};
float xy_b_block[2] = {UNPACK2(xy_dst)};
rctf rect = block->rect;
@@ -2160,9 +2155,7 @@ void UI_panel_category_active_set_default(ARegion *region, const char *idname)
const char *UI_panel_category_active_get(ARegion *region, bool set_fallback)
{
- PanelCategoryStack *pc_act;
-
- for (pc_act = region->panels_category_active.first; pc_act; pc_act = pc_act->next) {
+ LISTBASE_FOREACH (PanelCategoryStack *, pc_act, &region->panels_category_active) {
if (UI_panel_category_find(region, pc_act->idname)) {
return pc_act->idname;
}
@@ -2181,9 +2174,7 @@ const char *UI_panel_category_active_get(ARegion *region, bool set_fallback)
PanelCategoryDyn *UI_panel_category_find_mouse_over_ex(ARegion *region, const int x, const int y)
{
- PanelCategoryDyn *ptd;
-
- for (ptd = region->panels_category.first; ptd; ptd = ptd->next) {
+ LISTBASE_FOREACH (PanelCategoryDyn *, ptd, &region->panels_category) {
if (BLI_rcti_isect_pt(&ptd->rect, x, y)) {
return ptd;
}
@@ -2351,7 +2342,6 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
const uiFontStyle *fstyle = &style->widget;
const int fontid = fstyle->uifont_id;
short fstyle_points = fstyle->points;
- PanelCategoryDyn *pc_dyn;
const float aspect = ((uiBlock *)region->uiblocks.first)->aspect;
const float zoom = 1.0f / aspect;
const int px = max_ii(1, round_fl_to_int(U.pixelsize));
@@ -2428,7 +2418,8 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
}
/* calculate tab rect's and check if we need to scale down */
- for (pc_dyn = region->panels_category.first; pc_dyn; pc_dyn = pc_dyn->next) {
+ LISTBASE_FOREACH (PanelCategoryDyn *, pc_dyn, &region->panels_category) {
+
rcti *rct = &pc_dyn->rect;
const char *category_id = pc_dyn->idname;
const char *category_id_draw = IFACE_(category_id);
@@ -2446,7 +2437,7 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
if (y_ofs > BLI_rcti_size_y(&v2d->mask)) {
scaletabs = (float)BLI_rcti_size_y(&v2d->mask) / (float)y_ofs;
- for (pc_dyn = region->panels_category.first; pc_dyn; pc_dyn = pc_dyn->next) {
+ LISTBASE_FOREACH (PanelCategoryDyn *, pc_dyn, &region->panels_category) {
rcti *rct = &pc_dyn->rect;
rct->ymin = ((rct->ymin - v2d->mask.ymax) * scaletabs) + v2d->mask.ymax;
rct->ymax = ((rct->ymax - v2d->mask.ymax) * scaletabs) + v2d->mask.ymax;
@@ -2491,7 +2482,7 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
const int divider_xmax = is_left ? (v2d->mask.xmin + category_tabs_width) :
(v2d->mask.xmax - (category_tabs_width + px)) + px;
- for (pc_dyn = region->panels_category.first; pc_dyn; pc_dyn = pc_dyn->next) {
+ LISTBASE_FOREACH (PanelCategoryDyn *, pc_dyn, &region->panels_category) {
const rcti *rct = &pc_dyn->rect;
const char *category_id = pc_dyn->idname;
const char *category_id_draw = IFACE_(category_id);
@@ -2687,7 +2678,6 @@ int ui_handler_panel_region(bContext *C,
ARegion *region,
const uiBut *active_but)
{
- uiBlock *block;
Panel *panel;
int retval, mx, my;
bool has_category_tabs = UI_panel_category_is_visible(region);
@@ -2726,7 +2716,7 @@ int ui_handler_panel_region(bContext *C,
return retval;
}
- for (block = region->uiblocks.last; block; block = block->prev) {
+ LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
uiPanelMouseState mouse_state;
mx = event->x;
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 7d856a51720..1ce1e2950d5 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -364,8 +364,10 @@ static bool id_search_add(const bContext *C,
BKE_id_full_name_ui_prefix_get(name_ui, id, UI_SEP_CHAR);
int iconid = ui_id_icon_get(C, id, template_ui->preview);
+ bool has_sep_char = (id->lib != NULL);
- if (!UI_search_item_add(items, name_ui, id, iconid, UI_BUT_HAS_SEP_CHAR)) {
+ if (!UI_search_item_add(
+ items, name_ui, id, iconid, has_sep_char ? UI_BUT_HAS_SEP_CHAR : 0)) {
return false;
}
}
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 15db947bff6..3737b607305 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -384,6 +384,7 @@ typedef struct CollItemSearch {
char *name;
int index;
int iconid;
+ uint has_sep_char : 1;
} CollItemSearch;
static int sort_search_items_list(const void *a, const void *b)
@@ -405,7 +406,8 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
uiSearchItems *items)
{
uiRNACollectionSearch *data = arg;
- int i = 0, iconid = 0, flag = RNA_property_flag(data->target_prop);
+ const int flag = RNA_property_flag(data->target_prop);
+ int i = 0;
ListBase *items_list = MEM_callocN(sizeof(ListBase), "items_list");
CollItemSearch *cis;
const bool is_ptr_target = (RNA_property_type(data->target_prop) == PROP_POINTER);
@@ -433,7 +435,9 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
}
}
- iconid = 0;
+ int iconid = ICON_NONE;
+ bool has_sep_char = false;
+
if (itemptr.type && RNA_struct_is_ID(itemptr.type)) {
iconid = ui_id_icon_get(C, itemptr.data, false);
@@ -441,10 +445,12 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), NULL);
}
else {
- BKE_id_full_name_ui_prefix_get(name_buf, itemptr.data, UI_SEP_CHAR);
+ const ID *id = itemptr.data;
+ BKE_id_full_name_ui_prefix_get(name_buf, id, UI_SEP_CHAR);
BLI_STATIC_ASSERT(sizeof(name_buf) >= MAX_ID_FULL_NAME_UI,
"Name string buffer should be big enough to hold full UI ID name");
name = name_buf;
+ has_sep_char = (id->lib != NULL);
}
}
else {
@@ -458,6 +464,7 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
cis->name = BLI_strdup(name);
cis->index = i;
cis->iconid = iconid;
+ cis->has_sep_char = has_sep_char;
BLI_addtail(items_list, cis);
}
if (name != name_buf) {
@@ -473,7 +480,11 @@ void ui_rna_collection_search_update_fn(const struct bContext *C,
/* add search items from temporary list */
for (cis = items_list->first; cis; cis = cis->next) {
- if (!UI_search_item_add(items, cis->name, cis->data, cis->iconid, UI_BUT_HAS_SEP_CHAR)) {
+ if (!UI_search_item_add(items,
+ cis->name,
+ cis->data,
+ cis->iconid,
+ cis->has_sep_char ? UI_BUT_HAS_SEP_CHAR : 0)) {
break;
}
}