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/interface_templates.c')
-rw-r--r--source/blender/editors/interface/interface_templates.c123
1 files changed, 60 insertions, 63 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 56807621358..8962755ea90 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -139,7 +139,7 @@ static void template_add_button_search_menu(const bContext *C,
const bool editable,
const bool live_icon)
{
- PointerRNA active_ptr = RNA_property_pointer_get(ptr, prop);
+ const PointerRNA active_ptr = RNA_property_pointer_get(ptr, prop);
ID *id = (active_ptr.data && RNA_struct_is_ID(active_ptr.type)) ? active_ptr.data : NULL;
const ID *idfrom = ptr->owner_id;
const StructRNA *type = active_ptr.type ? active_ptr.type : RNA_property_pointer_type(ptr, prop);
@@ -164,7 +164,7 @@ static void template_add_button_search_menu(const bContext *C,
but = uiDefBlockButN(block, block_func, block_argN, "", 0, 0, width, height, tip);
if (use_preview_icon) {
- int icon = id ? ui_id_icon_get(C, id, use_big_size) : RNA_struct_ui_icon(type);
+ const int icon = id ? ui_id_icon_get(C, id, use_big_size) : RNA_struct_ui_icon(type);
ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
}
else {
@@ -183,7 +183,7 @@ static void template_add_button_search_menu(const bContext *C,
but = uiDefBlockButN(block, block_func, block_argN, "", 0, 0, UI_UNIT_X * 1.6, UI_UNIT_Y, tip);
if (live_icon) {
- int icon = id ? ui_id_icon_get(C, id, false) : RNA_struct_ui_icon(type);
+ const int icon = id ? ui_id_icon_get(C, id, false) : RNA_struct_ui_icon(type);
ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
}
else {
@@ -395,11 +395,10 @@ static void id_search_cb(const bContext *C,
{
TemplateID *template_ui = (TemplateID *)arg_template;
ListBase *lb = template_ui->idlb;
- ID *id;
- int flag = RNA_property_flag(template_ui->prop);
+ const int flag = RNA_property_flag(template_ui->prop);
/* ID listbase */
- for (id = lb->first; id; id = id->next) {
+ LISTBASE_FOREACH (ID *, id, lb) {
if (!id_search_add(C, template_ui, flag, str, items, id)) {
break;
}
@@ -416,11 +415,10 @@ static void id_search_cb_tagged(const bContext *C,
{
TemplateID *template_ui = (TemplateID *)arg_template;
ListBase *lb = template_ui->idlb;
- ID *id;
- int flag = RNA_property_flag(template_ui->prop);
+ const int flag = RNA_property_flag(template_ui->prop);
/* ID listbase */
- for (id = lb->first; id; id = id->next) {
+ LISTBASE_FOREACH (ID *, id, lb) {
if (id->tag & LIB_TAG_DOIT) {
if (!id_search_add(C, template_ui, flag, str, items, id)) {
break;
@@ -522,7 +520,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
TemplateID *template_ui = (TemplateID *)arg_litem;
PointerRNA idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop);
ID *id = idptr.data;
- int event = POINTER_AS_INT(arg_event);
+ const int event = POINTER_AS_INT(arg_event);
const char *undo_push_label = NULL;
switch (event) {
@@ -572,6 +570,15 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
if (override_id != NULL) {
BKE_main_id_clear_newpoins(bmain);
+ if (GS(override_id->name) == ID_OB) {
+ Scene *scene = CTX_data_scene(C);
+ if (!BKE_collection_has_object_recursive(scene->master_collection,
+ (Object *)override_id)) {
+ BKE_collection_object_add_from(
+ bmain, scene, (Object *)id, (Object *)override_id);
+ }
+ }
+
/* Assign new pointer, takes care of updates/notifiers */
RNA_id_pointer_create(override_id, &idptr);
}
@@ -1051,7 +1058,7 @@ static void template_ID(const bContext *C,
RNA_int_set(but->opptr, "id_type", GS(id->name));
}
else if (flag & UI_ID_OPEN) {
- int w = id ? UI_UNIT_X : (flag & UI_ID_ADD_NEW) ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
+ const int w = id ? UI_UNIT_X : (flag & UI_ID_ADD_NEW) ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
if (openop) {
but = uiDefIconTextButO(block,
@@ -1852,13 +1859,12 @@ static void modifier_panel_id(void *md_link, char *r_name)
void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C)
{
- ScrArea *sa = CTX_wm_area(C);
ARegion *region = CTX_wm_region(C);
Object *ob = ED_object_active_context(C);
ListBase *modifiers = &ob->modifiers;
- bool panels_match = UI_panel_list_matches_data(region, modifiers, modifier_panel_id);
+ const bool panels_match = UI_panel_list_matches_data(region, modifiers, modifier_panel_id);
if (!panels_match) {
UI_panels_free_instanced(C, region);
@@ -1876,8 +1882,7 @@ void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C)
PointerRNA *md_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata");
RNA_pointer_create(&ob->id, &RNA_Modifier, md, md_ptr);
- Panel *new_panel = UI_panel_add_instanced(
- sa, region, &region->panels, panel_idname, i, md_ptr);
+ Panel *new_panel = UI_panel_add_instanced(region, &region->panels, panel_idname, i, md_ptr);
if (new_panel != NULL) {
UI_panel_set_expand_from_list_data(C, new_panel);
@@ -1962,7 +1967,7 @@ static ListBase *get_constraints(const bContext *C, bool use_bone_constraints)
*/
static void constraint_reorder(bContext *C, Panel *panel, int new_index)
{
- bool constraint_from_bone = constraint_panel_is_bone(panel);
+ const bool constraint_from_bone = constraint_panel_is_bone(panel);
ListBase *lb = get_constraints(C, constraint_from_bone);
bConstraint *con = BLI_findlink(lb, panel->runtime.list_index);
@@ -1982,7 +1987,7 @@ static void constraint_reorder(bContext *C, Panel *panel, int new_index)
*/
static short get_constraint_expand_flag(const bContext *C, Panel *panel)
{
- bool constraint_from_bone = constraint_panel_is_bone(panel);
+ const bool constraint_from_bone = constraint_panel_is_bone(panel);
ListBase *lb = get_constraints(C, constraint_from_bone);
bConstraint *con = BLI_findlink(lb, panel->runtime.list_index);
@@ -1994,7 +1999,7 @@ static short get_constraint_expand_flag(const bContext *C, Panel *panel)
*/
static void set_constraint_expand_flag(const bContext *C, Panel *panel, short expand_flag)
{
- bool constraint_from_bone = constraint_panel_is_bone(panel);
+ const bool constraint_from_bone = constraint_panel_is_bone(panel);
ListBase *lb = get_constraints(C, constraint_from_bone);
bConstraint *con = BLI_findlink(lb, panel->runtime.list_index);
@@ -2030,7 +2035,6 @@ static void bone_constraint_panel_id(void *md_link, char *r_name)
*/
void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_constraints)
{
- ScrArea *sa = CTX_wm_area(C);
ARegion *region = CTX_wm_region(C);
Object *ob = ED_object_active_context(C);
@@ -2040,7 +2044,7 @@ void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_
uiListPanelIDFromDataFunc panel_id_func = use_bone_constraints ? bone_constraint_panel_id :
object_constraint_panel_id;
- bool panels_match = UI_panel_list_matches_data(region, constraints, panel_id_func);
+ const bool panels_match = UI_panel_list_matches_data(region, constraints, panel_id_func);
if (!panels_match) {
UI_panels_free_instanced(C, region);
@@ -2053,8 +2057,7 @@ void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_
PointerRNA *con_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata");
RNA_pointer_create(&ob->id, &RNA_Constraint, con, con_ptr);
- Panel *new_panel = UI_panel_add_instanced(
- sa, region, &region->panels, panel_idname, i, con_ptr);
+ Panel *new_panel = UI_panel_add_instanced(region, &region->panels, panel_idname, i, con_ptr);
if (new_panel) {
/* Set the list panel functionality function pointers since we don't do it with python. */
@@ -2112,12 +2115,12 @@ static void gpencil_modifier_panel_id(void *md_link, char *r_name)
void uiTemplateGpencilModifiers(uiLayout *UNUSED(layout), bContext *C)
{
- ScrArea *sa = CTX_wm_area(C);
ARegion *region = CTX_wm_region(C);
Object *ob = ED_object_active_context(C);
ListBase *modifiers = &ob->greasepencil_modifiers;
- bool panels_match = UI_panel_list_matches_data(region, modifiers, gpencil_modifier_panel_id);
+ const bool panels_match = UI_panel_list_matches_data(
+ region, modifiers, gpencil_modifier_panel_id);
if (!panels_match) {
UI_panels_free_instanced(C, region);
@@ -2135,8 +2138,7 @@ void uiTemplateGpencilModifiers(uiLayout *UNUSED(layout), bContext *C)
PointerRNA *md_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata");
RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, md_ptr);
- Panel *new_panel = UI_panel_add_instanced(
- sa, region, &region->panels, panel_idname, i, md_ptr);
+ Panel *new_panel = UI_panel_add_instanced(region, &region->panels, panel_idname, i, md_ptr);
if (new_panel != NULL) {
UI_panel_set_expand_from_list_data(C, new_panel);
@@ -2201,12 +2203,11 @@ static void shaderfx_panel_id(void *fx_v, char *r_idname)
*/
void uiTemplateShaderFx(uiLayout *UNUSED(layout), bContext *C)
{
- ScrArea *sa = CTX_wm_area(C);
ARegion *region = CTX_wm_region(C);
Object *ob = ED_object_active_context(C);
ListBase *shaderfx = &ob->shader_fx;
- bool panels_match = UI_panel_list_matches_data(region, shaderfx, shaderfx_panel_id);
+ const bool panels_match = UI_panel_list_matches_data(region, shaderfx, shaderfx_panel_id);
if (!panels_match) {
UI_panels_free_instanced(C, region);
@@ -2219,8 +2220,7 @@ void uiTemplateShaderFx(uiLayout *UNUSED(layout), bContext *C)
PointerRNA *fx_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata");
RNA_pointer_create(&ob->id, &RNA_ShaderFx, fx, fx_ptr);
- Panel *new_panel = UI_panel_add_instanced(
- sa, region, &region->panels, panel_idname, i, fx_ptr);
+ Panel *new_panel = UI_panel_add_instanced(region, &region->panels, panel_idname, i, fx_ptr);
if (new_panel != NULL) {
UI_panel_set_expand_from_list_data(C, new_panel);
@@ -2303,7 +2303,7 @@ static eAutoPropButsReturn template_operator_property_buts_draw_single(
eAutoPropButsReturn return_info = 0;
if (!op->properties) {
- IDPropertyTemplate val = {0};
+ const IDPropertyTemplate val = {0};
op->properties = IDP_New(IDP_GROUP, &val, "wmOperatorProperties");
}
@@ -2411,9 +2411,8 @@ static eAutoPropButsReturn template_operator_property_buts_draw_single(
/* Only do this if we're not refreshing an existing UI. */
if (block->oldblock == NULL) {
const bool is_popup = (block->flag & UI_BLOCK_KEEP_OPEN) != 0;
- uiBut *but;
- for (but = block->buttons.first; but; but = but->next) {
+ LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
/* no undo for buttons for operator redo panels */
UI_but_flag_disable(but, UI_BUT_UNDO);
@@ -3029,8 +3028,8 @@ static void colorband_distribute_cb(bContext *C, ColorBand *coba, bool evenly)
{
if (coba->tot > 1) {
int a;
- int tot = evenly ? coba->tot - 1 : coba->tot;
- float gap = 1.0f / tot;
+ const int tot = evenly ? coba->tot - 1 : coba->tot;
+ const float gap = 1.0f / tot;
float pos = 0.0f;
for (a = 0; a < coba->tot; a++) {
coba->data[a].pos = pos;
@@ -3212,9 +3211,9 @@ static void colorband_buttons_layout(uiLayout *layout,
{
uiLayout *row, *split, *subsplit;
uiBut *bt;
- float unit = BLI_rctf_size_x(butr) / 14.0f;
- float xs = butr->xmin;
- float ys = butr->ymin;
+ const float unit = BLI_rctf_size_x(butr) / 14.0f;
+ const float xs = butr->xmin;
+ const float ys = butr->ymin;
PointerRNA ptr;
RNA_pointer_create(cb->ptr.owner_id, &RNA_ColorRamp, coba, &ptr);
@@ -3887,7 +3886,7 @@ static uiBlock *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap
CurveMapping *cumap = cumap_v;
uiBlock *block;
uiBut *bt;
- float width = 8 * UI_UNIT_X;
+ const float width = 8 * UI_UNIT_X;
block = UI_block_begin(C, region, __func__, UI_EMBOSS);
UI_block_flag_enable(block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_MOVEMOUSE_QUIT);
@@ -4229,7 +4228,7 @@ static void curvemap_buttons_layout(uiLayout *layout,
uiLayout *row, *sub, *split;
uiBlock *block;
uiBut *bt;
- float dx = UI_UNIT_X;
+ const float dx = UI_UNIT_X;
int icon, size;
int bg = -1, i;
@@ -4702,7 +4701,7 @@ static uiBlock *CurveProfile_tools_func(bContext *C, ARegion *region, CurveProfi
{
uiBlock *block;
short yco = 0;
- short menuwidth = 10 * UI_UNIT_X;
+ const short menuwidth = 10 * UI_UNIT_X;
block = UI_block_begin(C, region, __func__, UI_EMBOSS);
UI_block_func_butmenu_set(block, CurveProfile_tools_dofunc, profile);
@@ -5406,13 +5405,12 @@ void uiTemplatePalette(uiLayout *layout,
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
PointerRNA cptr;
Palette *palette;
- PaletteColor *color;
uiBlock *block;
uiLayout *col;
uiBut *but = NULL;
int row_cols = 0, col_id = 0;
- int cols_per_row = MAX2(uiLayoutGetWidth(layout) / UI_UNIT_X, 1);
+ const int cols_per_row = MAX2(uiLayoutGetWidth(layout) / UI_UNIT_X, 1);
if (!prop) {
RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
@@ -5428,8 +5426,6 @@ void uiTemplatePalette(uiLayout *layout,
palette = cptr.data;
- color = palette->colors.first;
-
col = uiLayoutColumn(layout, true);
uiLayoutRow(col, true);
uiDefIconButO(block,
@@ -5452,7 +5448,7 @@ void uiTemplatePalette(uiLayout *layout,
UI_UNIT_X,
UI_UNIT_Y,
NULL);
- if (color) {
+ if (palette->colors.first != NULL) {
but = uiDefIconButO(block,
UI_BTYPE_BUT,
"PALETTE_OT_color_move",
@@ -5487,7 +5483,7 @@ void uiTemplatePalette(uiLayout *layout,
col = uiLayoutColumn(layout, true);
uiLayoutRow(col, true);
- for (; color; color = color->next) {
+ LISTBASE_FOREACH (PaletteColor *, color, &palette->colors) {
PointerRNA color_ptr;
if (row_cols >= cols_per_row) {
@@ -5561,7 +5557,7 @@ void uiTemplateCryptoPicker(uiLayout *layout, PointerRNA *ptr, const char *propn
static void handle_layer_buttons(bContext *C, void *arg1, void *arg2)
{
uiBut *but = arg1;
- int cur = POINTER_AS_INT(arg2);
+ const int cur = POINTER_AS_INT(arg2);
wmWindow *win = CTX_wm_window(C);
int i, tot, shift = win->eventstate->shift;
@@ -5596,7 +5592,7 @@ void uiTemplateLayers(uiLayout *layout,
PropertyRNA *prop, *used_prop = NULL;
int groups, cols, layers;
int group, col, layer, row;
- int cols_per_group = 5;
+ const int cols_per_group = 5;
prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
@@ -5644,7 +5640,7 @@ void uiTemplateLayers(uiLayout *layout,
/* add layers as toggle buts */
for (col = 0; (col < cols_per_group) && (layer < layers); col++, layer++) {
int icon = 0;
- int butlay = 1 << layer;
+ const int butlay = 1 << layer;
if (active_layer & butlay) {
icon = ICON_LAYER_ACTIVE;
@@ -5759,7 +5755,7 @@ static void uilist_filter_items_default(struct uiList *ui_list,
const bool filter_exclude = (ui_list->filter_flag & UILST_FLT_EXCLUDE) != 0;
const bool order_by_name = (ui_list->filter_sort_flag & UILST_FLT_SORT_MASK) ==
UILST_FLT_SORT_ALPHA;
- int len = RNA_property_collection_length(dataptr, prop);
+ const int len = RNA_property_collection_length(dataptr, prop);
dyn_data->items_shown = dyn_data->items_len = len;
@@ -5771,7 +5767,7 @@ static void uilist_filter_items_default(struct uiList *ui_list,
names = MEM_callocN(sizeof(StringCmp) * len, "StringCmp");
}
if (filter_raw[0]) {
- size_t slen = strlen(filter_raw);
+ const size_t slen = strlen(filter_raw);
dyn_data->items_filter_flags = MEM_callocN(sizeof(int) * len, "items_filter_flags");
dyn_data->items_shown = 0;
@@ -6209,8 +6205,8 @@ void uiTemplateList(uiLayout *layout,
for (i = layoutdata.start_idx; i < layoutdata.end_idx; i++) {
PointerRNA *itemptr = &items_ptr[i].item;
void *dyntip_data;
- int org_i = items_ptr[i].org_idx;
- int flt_flag = items_ptr[i].flt_flag;
+ const int org_i = items_ptr[i].org_idx;
+ const int flt_flag = items_ptr[i].flt_flag;
subblock = uiLayoutGetBlock(col);
overlap = uiLayoutOverlap(col);
@@ -6296,7 +6292,7 @@ void uiTemplateList(uiLayout *layout,
if ((dataptr->data && prop) && (dyn_data->items_shown > 0) && (activei >= 0) &&
(activei < dyn_data->items_shown)) {
PointerRNA *itemptr = &items_ptr[activei].item;
- int org_i = items_ptr[activei].org_idx;
+ const int org_i = items_ptr[activei].org_idx;
icon = UI_rnaptr_icon_get(C, itemptr, rnaicon, false);
if (icon == ICON_DOT) {
@@ -6346,8 +6342,8 @@ void uiTemplateList(uiLayout *layout,
/* create list items */
for (i = layoutdata.start_idx; i < layoutdata.end_idx; i++) {
PointerRNA *itemptr = &items_ptr[i].item;
- int org_i = items_ptr[i].org_idx;
- int flt_flag = items_ptr[i].flt_flag;
+ const int org_i = items_ptr[i].org_idx;
+ const int flt_flag = items_ptr[i].flt_flag;
/* create button */
if (!(i % columns)) {
@@ -6641,9 +6637,8 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C)
UI_block_func_handle_set(block, do_running_jobs, NULL);
- Scene *scene;
/* another scene can be rendering too, for example via compositor */
- for (scene = bmain->scenes.first; scene; scene = scene->id.next) {
+ LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
if (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY)) {
handle_event = B_STOPOTHER;
icon = ICON_NONE;
@@ -6736,7 +6731,7 @@ void uiTemplateRunningJobs(uiLayout *layout, bContext *C)
if (owner) {
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
- bool active = !(G.is_break || WM_jobs_is_stopped(wm, owner));
+ const bool active = !(G.is_break || WM_jobs_is_stopped(wm, owner));
uiLayout *row = uiLayoutRow(layout, false);
block = uiLayoutGetBlock(row);
@@ -7084,7 +7079,7 @@ bool uiTemplateEventFromKeymapItem(struct uiLayout *layout,
#ifdef WITH_HEADLESS
int icon = 0;
#else
- int icon = UI_icon_from_keymap_item(kmi, icon_mod);
+ const int icon = UI_icon_from_keymap_item(kmi, icon_mod);
#endif
if (icon != 0) {
for (int j = 0; j < ARRAY_SIZE(icon_mod) && icon_mod[j]; j++) {
@@ -7357,10 +7352,12 @@ void uiTemplateCacheFile(uiLayout *layout,
int uiTemplateRecentFiles(uiLayout *layout, int rows)
{
- const RecentFile *recent;
int i;
+ LISTBASE_FOREACH_INDEX (RecentFile *, recent, &G.recent_files, i) {
+ if (i >= rows) {
+ break;
+ }
- for (recent = G.recent_files.first, i = 0; (i < rows) && (recent); recent = recent->next, i++) {
const char *filename = BLI_path_basename(recent->filepath);
PointerRNA ptr;
uiItemFullO(layout,