Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_templates.cc
- This file was moved from source/blender/editors/interface/interface_templates.c.
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| /** \file | /** \file | ||||
| * \ingroup edinterface | * \ingroup edinterface | ||||
| */ | */ | ||||
| #include <ctype.h> | #include <cctype> | ||||
| #include <stddef.h> | #include <cstddef> | ||||
| #include <stdlib.h> | #include <cstdlib> | ||||
| #include <string.h> | #include <cstring> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "DNA_brush_types.h" | #include "DNA_brush_types.h" | ||||
| #include "DNA_cachefile_types.h" | #include "DNA_cachefile_types.h" | ||||
| #include "DNA_collection_types.h" | #include "DNA_collection_types.h" | ||||
| #include "DNA_constraint_types.h" | #include "DNA_constraint_types.h" | ||||
| #include "DNA_curveprofile_types.h" | #include "DNA_curveprofile_types.h" | ||||
| ▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | static void template_add_button_search_menu(const bContext *C, | ||||
| uiBlockCreateFunc block_func, | uiBlockCreateFunc block_func, | ||||
| void *block_argN, | void *block_argN, | ||||
| const char *const tip, | const char *const tip, | ||||
| const bool use_previews, | const bool use_previews, | ||||
| const bool editable, | const bool editable, | ||||
| const bool live_icon) | const bool live_icon) | ||||
| { | { | ||||
| const 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; | ID *id = (active_ptr.data && RNA_struct_is_ID(active_ptr.type)) ? | ||||
| static_cast<ID *>(active_ptr.data) : | |||||
| nullptr; | |||||
| const ID *idfrom = ptr->owner_id; | const ID *idfrom = ptr->owner_id; | ||||
| const StructRNA *type = active_ptr.type ? active_ptr.type : RNA_property_pointer_type(ptr, prop); | const StructRNA *type = active_ptr.type ? active_ptr.type : RNA_property_pointer_type(ptr, prop); | ||||
| uiBut *but; | uiBut *but; | ||||
| if (use_previews) { | if (use_previews) { | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| /* Ugly tool header exception. */ | /* Ugly tool header exception. */ | ||||
| const bool use_big_size = (region->regiontype != RGN_TYPE_TOOL_HEADER); | const bool use_big_size = (region->regiontype != RGN_TYPE_TOOL_HEADER); | ||||
| /* Ugly exception for screens here, | /* Ugly exception for screens here, | ||||
| * drawing their preview in icon size looks ugly/useless */ | * drawing their preview in icon size looks ugly/useless */ | ||||
| const bool use_preview_icon = use_big_size || (id && (GS(id->name) != ID_SCR)); | const bool use_preview_icon = use_big_size || (id && (GS(id->name) != ID_SCR)); | ||||
| const short width = UI_UNIT_X * (use_big_size ? 6 : 1.6f); | const short width = UI_UNIT_X * (use_big_size ? 6 : 1.6f); | ||||
| const short height = UI_UNIT_Y * (use_big_size ? 6 : 1); | const short height = UI_UNIT_Y * (use_big_size ? 6 : 1); | ||||
| uiLayout *col = NULL; | uiLayout *col = nullptr; | ||||
| if (use_big_size) { | if (use_big_size) { | ||||
| /* Assume column layout here. To be more correct, we should check if the layout passed to | /* Assume column layout here. To be more correct, we should check if the layout passed to | ||||
| * template_id is a column one, but this should work well in practice. */ | * template_id is a column one, but this should work well in practice. */ | ||||
| col = uiLayoutColumn(layout, true); | col = uiLayoutColumn(layout, true); | ||||
| } | } | ||||
| but = uiDefBlockButN(block, block_func, block_argN, "", 0, 0, width, height, tip); | but = uiDefBlockButN(block, block_func, block_argN, "", 0, 0, width, height, tip); | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | static uiBlock *template_common_search_menu(const bContext *C, | ||||
| UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | ||||
| /* preview thumbnails */ | /* preview thumbnails */ | ||||
| if (preview_rows > 0 && preview_cols > 0) { | if (preview_rows > 0 && preview_cols > 0) { | ||||
| const int w = 4 * U.widget_unit * preview_cols * scale; | const int w = 4 * U.widget_unit * preview_cols * scale; | ||||
| const int h = 5 * U.widget_unit * preview_rows * scale; | const int h = 5 * U.widget_unit * preview_rows * scale; | ||||
| /* fake button, it holds space for search items */ | /* fake button, it holds space for search items */ | ||||
| uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 26, w, h, NULL, 0, 0, 0, 0, NULL); | uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 26, w, h, nullptr, 0, 0, 0, 0, nullptr); | ||||
| but = uiDefSearchBut(block, | but = uiDefSearchBut(block, | ||||
| search, | search, | ||||
| 0, | 0, | ||||
| ICON_VIEWZOOM, | ICON_VIEWZOOM, | ||||
| sizeof(search), | sizeof(search), | ||||
| 10, | 10, | ||||
| 0, | 0, | ||||
| Show All 12 Lines | else { | ||||
| uiDefBut(block, | uiDefBut(block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| "", | "", | ||||
| 10, | 10, | ||||
| 15, | 15, | ||||
| searchbox_width, | searchbox_width, | ||||
| searchbox_height, | searchbox_height, | ||||
| NULL, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| NULL); | nullptr); | ||||
| but = uiDefSearchBut(block, | but = uiDefSearchBut(block, | ||||
| search, | search, | ||||
| 0, | 0, | ||||
| ICON_VIEWZOOM, | ICON_VIEWZOOM, | ||||
| sizeof(search), | sizeof(search), | ||||
| 10, | 10, | ||||
| 0, | 0, | ||||
| searchbox_width, | searchbox_width, | ||||
| UI_UNIT_Y - 1, | UI_UNIT_Y - 1, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| } | } | ||||
| UI_but_func_search_set(but, | UI_but_func_search_set(but, | ||||
| ui_searchbox_create_generic, | ui_searchbox_create_generic, | ||||
| search_update_fn, | search_update_fn, | ||||
| search_arg, | search_arg, | ||||
| false, | false, | ||||
| NULL, | nullptr, | ||||
| search_exec_fn, | search_exec_fn, | ||||
| active_item); | active_item); | ||||
| UI_but_func_search_set_tooltip(but, item_tooltip_fn); | UI_but_func_search_set_tooltip(but, item_tooltip_fn); | ||||
| UI_block_bounds_set_normal(block, 0.3f * U.widget_unit); | UI_block_bounds_set_normal(block, 0.3f * U.widget_unit); | ||||
| UI_block_direction_set(block, UI_DIR_DOWN); | UI_block_direction_set(block, UI_DIR_DOWN); | ||||
| /* give search-field focus */ | /* give search-field focus */ | ||||
| UI_but_focus_on_enter_event(win, but); | UI_but_focus_on_enter_event(win, but); | ||||
| /* this type of search menu requires undo */ | /* this type of search menu requires undo */ | ||||
| but->flag |= UI_BUT_UNDO; | but->flag |= UI_BUT_UNDO; | ||||
| return block; | return block; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Search Callbacks | /** \name Search Callbacks | ||||
| * \{ */ | * \{ */ | ||||
| typedef struct TemplateID { | struct TemplateID { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| ListBase *idlb; | ListBase *idlb; | ||||
| short idcode; | short idcode; | ||||
| short filter; | short filter; | ||||
| int prv_rows, prv_cols; | int prv_rows, prv_cols; | ||||
| bool preview; | bool preview; | ||||
| float scale; | float scale; | ||||
| } TemplateID; | }; | ||||
| /* Search browse menu, assign. */ | /* Search browse menu, assign. */ | ||||
| static void template_ID_set_property_exec_fn(bContext *C, void *arg_template, void *item) | static void template_ID_set_property_exec_fn(bContext *C, void *arg_template, void *item) | ||||
| { | { | ||||
| TemplateID *template_ui = (TemplateID *)arg_template; | TemplateID *template_ui = (TemplateID *)arg_template; | ||||
| /* ID */ | /* ID */ | ||||
| if (item) { | if (item) { | ||||
| PointerRNA idptr; | PointerRNA idptr; | ||||
| RNA_id_pointer_create(item, &idptr); | RNA_id_pointer_create(static_cast<ID *>(item), &idptr); | ||||
| RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, NULL); | RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, nullptr); | ||||
| RNA_property_update(C, &template_ui->ptr, template_ui->prop); | RNA_property_update(C, &template_ui->ptr, template_ui->prop); | ||||
| } | } | ||||
| } | } | ||||
| static bool id_search_allows_id(TemplateID *template_ui, const int flag, ID *id, const char *query) | static bool id_search_allows_id(TemplateID *template_ui, const int flag, ID *id, const char *query) | ||||
| { | { | ||||
| ID *id_from = template_ui->ptr.owner_id; | ID *id_from = template_ui->ptr.owner_id; | ||||
| ▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | static bool id_search_add(const bContext *C, TemplateID *template_ui, uiSearchItems *items, ID *id) | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* ID Search browse menu, do the search */ | /* ID Search browse menu, do the search */ | ||||
| static void id_search_cb(const bContext *C, | static void id_search_cb(const bContext *C, | ||||
| void *arg_template, | void *arg_template, | ||||
| const char *str, | const char *str, | ||||
| uiSearchItems *items, | uiSearchItems *items, | ||||
| const bool UNUSED(is_first)) | const bool /*is_first*/) | ||||
| { | { | ||||
| TemplateID *template_ui = (TemplateID *)arg_template; | TemplateID *template_ui = (TemplateID *)arg_template; | ||||
| ListBase *lb = template_ui->idlb; | ListBase *lb = template_ui->idlb; | ||||
| const int flag = RNA_property_flag(template_ui->prop); | const int flag = RNA_property_flag(template_ui->prop); | ||||
| StringSearch *search = BLI_string_search_new(); | StringSearch *search = BLI_string_search_new(); | ||||
| /* ID listbase */ | /* ID listbase */ | ||||
| ▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * A version of 'id_search_cb' that lists scene objects. | * A version of 'id_search_cb' that lists scene objects. | ||||
| */ | */ | ||||
| static void id_search_cb_objects_from_scene(const bContext *C, | static void id_search_cb_objects_from_scene(const bContext *C, | ||||
| void *arg_template, | void *arg_template, | ||||
| const char *str, | const char *str, | ||||
| uiSearchItems *items, | uiSearchItems *items, | ||||
| const bool UNUSED(is_first)) | const bool /*is_first*/) | ||||
| { | { | ||||
| TemplateID *template_ui = (TemplateID *)arg_template; | TemplateID *template_ui = (TemplateID *)arg_template; | ||||
| ListBase *lb = template_ui->idlb; | ListBase *lb = template_ui->idlb; | ||||
| Scene *scene = NULL; | Scene *scene = nullptr; | ||||
| ID *id_from = template_ui->ptr.owner_id; | ID *id_from = template_ui->ptr.owner_id; | ||||
| if (id_from && GS(id_from->name) == ID_SCE) { | if (id_from && GS(id_from->name) == ID_SCE) { | ||||
| scene = (Scene *)id_from; | scene = (Scene *)id_from; | ||||
| } | } | ||||
| else { | else { | ||||
| scene = CTX_data_scene(C); | scene = CTX_data_scene(C); | ||||
| } | } | ||||
| BKE_main_id_flag_listbase(lb, LIB_TAG_DOIT, false); | BKE_main_id_flag_listbase(lb, LIB_TAG_DOIT, false); | ||||
| FOREACH_SCENE_OBJECT_BEGIN (scene, ob_iter) { | FOREACH_SCENE_OBJECT_BEGIN (scene, ob_iter) { | ||||
| ob_iter->id.tag |= LIB_TAG_DOIT; | ob_iter->id.tag |= LIB_TAG_DOIT; | ||||
| } | } | ||||
| FOREACH_SCENE_OBJECT_END; | FOREACH_SCENE_OBJECT_END; | ||||
| id_search_cb_tagged(C, arg_template, str, items); | id_search_cb_tagged(C, arg_template, str, items); | ||||
| } | } | ||||
| static ARegion *template_ID_search_menu_item_tooltip( | static ARegion *template_ID_search_menu_item_tooltip( | ||||
| bContext *C, ARegion *region, const rcti *item_rect, void *arg, void *active) | bContext *C, ARegion *region, const rcti *item_rect, void *arg, void *active) | ||||
| { | { | ||||
| TemplateID *template_ui = arg; | TemplateID *template_ui = static_cast<TemplateID *>(arg); | ||||
| ID *active_id = active; | ID *active_id = static_cast<ID *>(active); | ||||
| StructRNA *type = RNA_property_pointer_type(&template_ui->ptr, template_ui->prop); | StructRNA *type = RNA_property_pointer_type(&template_ui->ptr, template_ui->prop); | ||||
| uiSearchItemTooltipData tooltip_data = {0}; | uiSearchItemTooltipData tooltip_data = {0}; | ||||
| tooltip_data.name = active_id->name + 2; | tooltip_data.name = active_id->name + 2; | ||||
| BLI_snprintf(tooltip_data.description, | BLI_snprintf(tooltip_data.description, | ||||
| sizeof(tooltip_data.description), | sizeof(tooltip_data.description), | ||||
| TIP_("Choose %s data-block to be assigned to this user"), | TIP_("Choose %s data-block to be assigned to this user"), | ||||
| ▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
| */ | */ | ||||
| void UI_context_active_but_prop_get_templateID(bContext *C, | void UI_context_active_but_prop_get_templateID(bContext *C, | ||||
| PointerRNA *r_ptr, | PointerRNA *r_ptr, | ||||
| PropertyRNA **r_prop) | PropertyRNA **r_prop) | ||||
| { | { | ||||
| uiBut *but = UI_context_active_but_get(C); | uiBut *but = UI_context_active_but_get(C); | ||||
| memset(r_ptr, 0, sizeof(*r_ptr)); | memset(r_ptr, 0, sizeof(*r_ptr)); | ||||
| *r_prop = NULL; | *r_prop = nullptr; | ||||
| if (but && (but->funcN == template_id_cb) && but->func_argN) { | if (but && (but->funcN == template_id_cb) && but->func_argN) { | ||||
| TemplateID *template_ui = but->func_argN; | TemplateID *template_ui = static_cast<TemplateID *>(but->func_argN); | ||||
| *r_ptr = template_ui->ptr; | *r_ptr = template_ui->ptr; | ||||
| *r_prop = template_ui->prop; | *r_prop = template_ui->prop; | ||||
| } | } | ||||
| } | } | ||||
| static void template_id_liboverride_hierarchy_collection_root_find_recursive( | static void template_id_liboverride_hierarchy_collection_root_find_recursive( | ||||
| Collection *collection, | Collection *collection, | ||||
| const int parent_level, | const int parent_level, | ||||
| Collection **r_collection_parent_best, | Collection **r_collection_parent_best, | ||||
| int *r_parent_level_best) | int *r_parent_level_best) | ||||
| { | { | ||||
| if (!ID_IS_LINKED(collection) && !ID_IS_OVERRIDE_LIBRARY_REAL(collection)) { | if (!ID_IS_LINKED(collection) && !ID_IS_OVERRIDE_LIBRARY_REAL(collection)) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (ID_IS_OVERRIDABLE_LIBRARY(collection) || ID_IS_OVERRIDE_LIBRARY_REAL(collection)) { | if (ID_IS_OVERRIDABLE_LIBRARY(collection) || ID_IS_OVERRIDE_LIBRARY_REAL(collection)) { | ||||
| if (parent_level > *r_parent_level_best) { | if (parent_level > *r_parent_level_best) { | ||||
| *r_parent_level_best = parent_level; | *r_parent_level_best = parent_level; | ||||
| *r_collection_parent_best = collection; | *r_collection_parent_best = collection; | ||||
| } | } | ||||
| } | } | ||||
| for (CollectionParent *iter = collection->parents.first; iter != NULL; iter = iter->next) { | for (CollectionParent *iter = static_cast<CollectionParent *>(collection->parents.first); | ||||
| iter != nullptr; | |||||
| iter = iter->next) { | |||||
| if (iter->collection->id.lib != collection->id.lib && ID_IS_LINKED(iter->collection)) { | if (iter->collection->id.lib != collection->id.lib && ID_IS_LINKED(iter->collection)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| template_id_liboverride_hierarchy_collection_root_find_recursive( | template_id_liboverride_hierarchy_collection_root_find_recursive( | ||||
| iter->collection, parent_level + 1, r_collection_parent_best, r_parent_level_best); | iter->collection, parent_level + 1, r_collection_parent_best, r_parent_level_best); | ||||
| } | } | ||||
| } | } | ||||
| static void template_id_liboverride_hierarchy_collections_tag_recursive( | static void template_id_liboverride_hierarchy_collections_tag_recursive( | ||||
| Collection *root_collection, ID *target_id, const bool do_parents) | Collection *root_collection, ID *target_id, const bool do_parents) | ||||
| { | { | ||||
| root_collection->id.tag |= LIB_TAG_DOIT; | root_collection->id.tag |= LIB_TAG_DOIT; | ||||
| /* Tag all local parents of the root collection, so that usages of the root collection and other | /* Tag all local parents of the root collection, so that usages of the root collection and other | ||||
| * linked ones can be replaced by the local overrides in those parents too. */ | * linked ones can be replaced by the local overrides in those parents too. */ | ||||
| if (do_parents) { | if (do_parents) { | ||||
| for (CollectionParent *iter = root_collection->parents.first; iter != NULL; | for (CollectionParent *iter = static_cast<CollectionParent *>(root_collection->parents.first); | ||||
| iter != nullptr; | |||||
| iter = iter->next) { | iter = iter->next) { | ||||
| if (ID_IS_LINKED(iter->collection)) { | if (ID_IS_LINKED(iter->collection)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| iter->collection->id.tag |= LIB_TAG_DOIT; | iter->collection->id.tag |= LIB_TAG_DOIT; | ||||
| } | } | ||||
| } | } | ||||
| for (CollectionChild *iter = root_collection->children.first; iter != NULL; iter = iter->next) { | for (CollectionChild *iter = static_cast<CollectionChild *>(root_collection->children.first); | ||||
| iter != nullptr; | |||||
| iter = iter->next) { | |||||
| if (iter->collection->id.lib != root_collection->id.lib && ID_IS_LINKED(root_collection)) { | if (iter->collection->id.lib != root_collection->id.lib && ID_IS_LINKED(root_collection)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (ID_IS_LINKED(iter->collection) && iter->collection->id.lib != target_id->lib) { | if (ID_IS_LINKED(iter->collection) && iter->collection->id.lib != target_id->lib) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (GS(target_id->name) == ID_OB && | if (GS(target_id->name) == ID_OB && | ||||
| !BKE_collection_has_object_recursive(iter->collection, (Object *)target_id)) { | !BKE_collection_has_object_recursive(iter->collection, (Object *)target_id)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (GS(target_id->name) == ID_GR && | if (GS(target_id->name) == ID_GR && | ||||
| !BKE_collection_has_collection(iter->collection, (Collection *)target_id)) { | !BKE_collection_has_collection(iter->collection, (Collection *)target_id)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| template_id_liboverride_hierarchy_collections_tag_recursive( | template_id_liboverride_hierarchy_collections_tag_recursive( | ||||
| iter->collection, target_id, false); | iter->collection, target_id, false); | ||||
| } | } | ||||
| } | } | ||||
| ID *ui_template_id_liboverride_hierarchy_make( | ID *ui_template_id_liboverride_hierarchy_make( | ||||
| bContext *C, Main *bmain, ID *owner_id, ID *id, const char **r_undo_push_label) | bContext *C, Main *bmain, ID *owner_id, ID *id, const char **r_undo_push_label) | ||||
| { | { | ||||
| const char *undo_push_label; | const char *undo_push_label; | ||||
| if (r_undo_push_label == NULL) { | if (r_undo_push_label == nullptr) { | ||||
| r_undo_push_label = &undo_push_label; | r_undo_push_label = &undo_push_label; | ||||
| } | } | ||||
| /* If this is called on an already local override, 'toggle' between user-editable state, and | /* If this is called on an already local override, 'toggle' between user-editable state, and | ||||
| * system override with reset. */ | * system override with reset. */ | ||||
| if (!ID_IS_LINKED(id) && ID_IS_OVERRIDE_LIBRARY(id)) { | if (!ID_IS_LINKED(id) && ID_IS_OVERRIDE_LIBRARY(id)) { | ||||
| if (!ID_IS_OVERRIDE_LIBRARY_REAL(id)) { | if (!ID_IS_OVERRIDE_LIBRARY_REAL(id)) { | ||||
| BKE_lib_override_library_get(bmain, id, NULL, &id); | BKE_lib_override_library_get(bmain, id, nullptr, &id); | ||||
| } | } | ||||
| if (id->override_library->flag & IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED) { | if (id->override_library->flag & IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED) { | ||||
| id->override_library->flag &= ~IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED; | id->override_library->flag &= ~IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED; | ||||
| *r_undo_push_label = "Make Library Override Hierarchy Editable"; | *r_undo_push_label = "Make Library Override Hierarchy Editable"; | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_lib_override_library_id_reset(bmain, id, true); | BKE_lib_override_library_id_reset(bmain, id, true); | ||||
| *r_undo_push_label = "Clear Library Override Hierarchy"; | *r_undo_push_label = "Clear Library Override Hierarchy"; | ||||
| } | } | ||||
| WM_event_add_notifier(C, NC_WM | ND_DATACHANGED, NULL); | WM_event_add_notifier(C, NC_WM | ND_DATACHANGED, nullptr); | ||||
| WM_event_add_notifier(C, NC_WM | ND_LIB_OVERRIDE_CHANGED, NULL); | WM_event_add_notifier(C, NC_WM | ND_LIB_OVERRIDE_CHANGED, nullptr); | ||||
| WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL); | WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, nullptr); | ||||
| return id; | return id; | ||||
| } | } | ||||
| /* Attempt to perform a hierarchy override, based on contextual data available. | /* Attempt to perform a hierarchy override, based on contextual data available. | ||||
| * NOTE: do not attempt to perform such hierarchy override at all cost, if there is not enough | * NOTE: do not attempt to perform such hierarchy override at all cost, if there is not enough | ||||
| * context, better to abort than create random overrides all over the place. */ | * context, better to abort than create random overrides all over the place. */ | ||||
| if (!ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(id)) { | if (!ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(id)) { | ||||
| WM_reportf(RPT_ERROR, "The data-block %s is not overridable", id->name); | WM_reportf(RPT_ERROR, "The data-block %s is not overridable", id->name); | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| Object *object_active = CTX_data_active_object(C); | Object *object_active = CTX_data_active_object(C); | ||||
| if (object_active == NULL && GS(owner_id->name) == ID_OB) { | if (object_active == nullptr && GS(owner_id->name) == ID_OB) { | ||||
| object_active = (Object *)owner_id; | object_active = (Object *)owner_id; | ||||
| } | } | ||||
| if (object_active != NULL) { | if (object_active != nullptr) { | ||||
| if (ID_IS_LINKED(object_active)) { | if (ID_IS_LINKED(object_active)) { | ||||
| if (object_active->id.lib != id->lib || | if (object_active->id.lib != id->lib || | ||||
| !ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(object_active)) { | !ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(object_active)) { | ||||
| /* The active object is from a different library than the overridden ID, or otherwise | /* The active object is from a different library than the overridden ID, or otherwise | ||||
| * cannot be used in hierarchy. */ | * cannot be used in hierarchy. */ | ||||
| object_active = NULL; | object_active = nullptr; | ||||
| } | } | ||||
| } | } | ||||
| else if (!ID_IS_OVERRIDE_LIBRARY_REAL(object_active)) { | else if (!ID_IS_OVERRIDE_LIBRARY_REAL(object_active)) { | ||||
| /* Fully local object cannot be used in override hierarchy either. */ | /* Fully local object cannot be used in override hierarchy either. */ | ||||
| object_active = NULL; | object_active = nullptr; | ||||
| } | } | ||||
| } | } | ||||
| Collection *collection_active = CTX_data_collection(C); | Collection *collection_active = CTX_data_collection(C); | ||||
| if (collection_active == NULL && GS(owner_id->name) == ID_GR) { | if (collection_active == nullptr && GS(owner_id->name) == ID_GR) { | ||||
| collection_active = (Collection *)owner_id; | collection_active = (Collection *)owner_id; | ||||
| } | } | ||||
| if (collection_active != NULL) { | if (collection_active != nullptr) { | ||||
| if (ID_IS_LINKED(collection_active)) { | if (ID_IS_LINKED(collection_active)) { | ||||
| if (collection_active->id.lib != id->lib || | if (collection_active->id.lib != id->lib || | ||||
| !ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(collection_active)) { | !ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(collection_active)) { | ||||
| /* The active collection is from a different library than the overridden ID, or otherwise | /* The active collection is from a different library than the overridden ID, or otherwise | ||||
| * cannot be used in hierarchy. */ | * cannot be used in hierarchy. */ | ||||
| collection_active = NULL; | collection_active = nullptr; | ||||
| } | } | ||||
| else { | else { | ||||
| int parent_level_best = -1; | int parent_level_best = -1; | ||||
| Collection *collection_parent_best = NULL; | Collection *collection_parent_best = nullptr; | ||||
| template_id_liboverride_hierarchy_collection_root_find_recursive( | template_id_liboverride_hierarchy_collection_root_find_recursive( | ||||
| collection_active, 0, &collection_parent_best, &parent_level_best); | collection_active, 0, &collection_parent_best, &parent_level_best); | ||||
| collection_active = collection_parent_best; | collection_active = collection_parent_best; | ||||
| } | } | ||||
| } | } | ||||
| else if (!ID_IS_OVERRIDE_LIBRARY_REAL(collection_active)) { | else if (!ID_IS_OVERRIDE_LIBRARY_REAL(collection_active)) { | ||||
| /* Fully local collection cannot be used in override hierarchy either. */ | /* Fully local collection cannot be used in override hierarchy either. */ | ||||
| collection_active = NULL; | collection_active = nullptr; | ||||
| } | } | ||||
| } | } | ||||
| if (collection_active == NULL && object_active != NULL && | if (collection_active == nullptr && object_active != nullptr && | ||||
| (ID_IS_LINKED(object_active) || ID_IS_OVERRIDE_LIBRARY_REAL(object_active))) { | (ID_IS_LINKED(object_active) || ID_IS_OVERRIDE_LIBRARY_REAL(object_active))) { | ||||
| /* If we failed to find a valid 'active' collection so far for our override hierarchy, but do | /* If we failed to find a valid 'active' collection so far for our override hierarchy, but do | ||||
| * have a valid 'active' object, try to find a collection from that object. */ | * have a valid 'active' object, try to find a collection from that object. */ | ||||
| LISTBASE_FOREACH (Collection *, collection_iter, &bmain->collections) { | LISTBASE_FOREACH (Collection *, collection_iter, &bmain->collections) { | ||||
| if (!(ID_IS_LINKED(collection_iter) || ID_IS_OVERRIDE_LIBRARY_REAL(collection_iter))) { | if (!(ID_IS_LINKED(collection_iter) || ID_IS_OVERRIDE_LIBRARY_REAL(collection_iter))) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (!BKE_collection_has_object_recursive(collection_iter, object_active)) { | if (!BKE_collection_has_object_recursive(collection_iter, object_active)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| int parent_level_best = -1; | int parent_level_best = -1; | ||||
| Collection *collection_parent_best = NULL; | Collection *collection_parent_best = nullptr; | ||||
| template_id_liboverride_hierarchy_collection_root_find_recursive( | template_id_liboverride_hierarchy_collection_root_find_recursive( | ||||
| collection_iter, 0, &collection_parent_best, &parent_level_best); | collection_iter, 0, &collection_parent_best, &parent_level_best); | ||||
| collection_active = collection_parent_best; | collection_active = collection_parent_best; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| ID *id_override = NULL; | ID *id_override = nullptr; | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| switch (GS(id->name)) { | switch (GS(id->name)) { | ||||
| case ID_GR: | case ID_GR: | ||||
| if (collection_active != NULL && | if (collection_active != nullptr && | ||||
| BKE_collection_has_collection(collection_active, (Collection *)id)) { | BKE_collection_has_collection(collection_active, (Collection *)id)) { | ||||
| template_id_liboverride_hierarchy_collections_tag_recursive(collection_active, id, true); | template_id_liboverride_hierarchy_collections_tag_recursive(collection_active, id, true); | ||||
| if (object_active != NULL) { | if (object_active != nullptr) { | ||||
| object_active->id.tag |= LIB_TAG_DOIT; | object_active->id.tag |= LIB_TAG_DOIT; | ||||
| } | } | ||||
| BKE_lib_override_library_create( | BKE_lib_override_library_create(bmain, | ||||
| bmain, scene, view_layer, NULL, id, &collection_active->id, NULL, &id_override, false); | scene, | ||||
| view_layer, | |||||
| nullptr, | |||||
| id, | |||||
| &collection_active->id, | |||||
| nullptr, | |||||
| &id_override, | |||||
| false); | |||||
| } | } | ||||
| else if (object_active != NULL && !ID_IS_LINKED(object_active) && | else if (object_active != nullptr && !ID_IS_LINKED(object_active) && | ||||
| &object_active->instance_collection->id == id) { | &object_active->instance_collection->id == id) { | ||||
| object_active->id.tag |= LIB_TAG_DOIT; | object_active->id.tag |= LIB_TAG_DOIT; | ||||
| BKE_lib_override_library_create(bmain, | BKE_lib_override_library_create(bmain, | ||||
| scene, | scene, | ||||
| view_layer, | view_layer, | ||||
| id->lib, | id->lib, | ||||
| id, | id, | ||||
| &object_active->id, | &object_active->id, | ||||
| &object_active->id, | &object_active->id, | ||||
| &id_override, | &id_override, | ||||
| false); | false); | ||||
| } | } | ||||
| break; | break; | ||||
| case ID_OB: | case ID_OB: | ||||
| if (collection_active != NULL && | if (collection_active != nullptr && | ||||
| BKE_collection_has_object_recursive(collection_active, (Object *)id)) { | BKE_collection_has_object_recursive(collection_active, (Object *)id)) { | ||||
| template_id_liboverride_hierarchy_collections_tag_recursive(collection_active, id, true); | template_id_liboverride_hierarchy_collections_tag_recursive(collection_active, id, true); | ||||
| if (object_active != NULL) { | if (object_active != nullptr) { | ||||
| object_active->id.tag |= LIB_TAG_DOIT; | object_active->id.tag |= LIB_TAG_DOIT; | ||||
| } | } | ||||
| BKE_lib_override_library_create( | BKE_lib_override_library_create(bmain, | ||||
| bmain, scene, view_layer, NULL, id, &collection_active->id, NULL, &id_override, false); | scene, | ||||
| view_layer, | |||||
| nullptr, | |||||
| id, | |||||
| &collection_active->id, | |||||
| nullptr, | |||||
| &id_override, | |||||
| false); | |||||
| } | } | ||||
| else { | else { | ||||
| if (object_active != NULL) { | if (object_active != nullptr) { | ||||
| object_active->id.tag |= LIB_TAG_DOIT; | object_active->id.tag |= LIB_TAG_DOIT; | ||||
| } | } | ||||
| BKE_lib_override_library_create( | BKE_lib_override_library_create( | ||||
| bmain, scene, view_layer, NULL, id, NULL, NULL, &id_override, false); | bmain, scene, view_layer, nullptr, id, nullptr, nullptr, &id_override, false); | ||||
| BKE_scene_collections_object_remove(bmain, scene, (Object *)id, true); | BKE_scene_collections_object_remove(bmain, scene, (Object *)id, true); | ||||
| WM_event_add_notifier(C, NC_ID | NA_REMOVED, NULL); | WM_event_add_notifier(C, NC_ID | NA_REMOVED, nullptr); | ||||
| } | } | ||||
| break; | break; | ||||
| case ID_ME: | case ID_ME: | ||||
| case ID_CU_LEGACY: | case ID_CU_LEGACY: | ||||
| case ID_MB: | case ID_MB: | ||||
| case ID_LT: | case ID_LT: | ||||
| case ID_LA: | case ID_LA: | ||||
| case ID_CA: | case ID_CA: | ||||
| case ID_SPK: | case ID_SPK: | ||||
| case ID_AR: | case ID_AR: | ||||
| case ID_GD: | case ID_GD: | ||||
| case ID_CV: | case ID_CV: | ||||
| case ID_PT: | case ID_PT: | ||||
| case ID_VO: | case ID_VO: | ||||
| case ID_NT: /* Essentially geometry nodes from modifier currently. */ | case ID_NT: /* Essentially geometry nodes from modifier currently. */ | ||||
| if (object_active != NULL) { | if (object_active != nullptr) { | ||||
| if (collection_active != NULL && | if (collection_active != nullptr && | ||||
| BKE_collection_has_object_recursive(collection_active, object_active)) { | BKE_collection_has_object_recursive(collection_active, object_active)) { | ||||
| template_id_liboverride_hierarchy_collections_tag_recursive(collection_active, id, true); | template_id_liboverride_hierarchy_collections_tag_recursive(collection_active, id, true); | ||||
| if (object_active != NULL) { | if (object_active != nullptr) { | ||||
| object_active->id.tag |= LIB_TAG_DOIT; | object_active->id.tag |= LIB_TAG_DOIT; | ||||
| } | } | ||||
| BKE_lib_override_library_create(bmain, | BKE_lib_override_library_create(bmain, | ||||
| scene, | scene, | ||||
| view_layer, | view_layer, | ||||
| NULL, | nullptr, | ||||
| id, | id, | ||||
| &collection_active->id, | &collection_active->id, | ||||
| NULL, | nullptr, | ||||
| &id_override, | &id_override, | ||||
| false); | false); | ||||
| } | } | ||||
| else { | else { | ||||
| object_active->id.tag |= LIB_TAG_DOIT; | object_active->id.tag |= LIB_TAG_DOIT; | ||||
| BKE_lib_override_library_create( | BKE_lib_override_library_create(bmain, | ||||
| bmain, scene, view_layer, NULL, id, &object_active->id, NULL, &id_override, false); | scene, | ||||
| view_layer, | |||||
| nullptr, | |||||
| id, | |||||
| &object_active->id, | |||||
| nullptr, | |||||
| &id_override, | |||||
| false); | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_lib_override_library_create( | BKE_lib_override_library_create( | ||||
| bmain, scene, view_layer, NULL, id, id, NULL, &id_override, false); | bmain, scene, view_layer, nullptr, id, id, nullptr, &id_override, false); | ||||
| } | } | ||||
| break; | break; | ||||
| case ID_MA: | case ID_MA: | ||||
| case ID_TE: | case ID_TE: | ||||
| case ID_IM: | case ID_IM: | ||||
| WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name); | WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name); | ||||
| break; | break; | ||||
| case ID_WO: | case ID_WO: | ||||
| WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name); | WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name); | ||||
| break; | break; | ||||
| case ID_PA: | case ID_PA: | ||||
| WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name); | WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name); | ||||
| break; | break; | ||||
| default: | default: | ||||
| WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name); | WM_reportf(RPT_WARNING, "The type of data-block %s is not yet implemented", id->name); | ||||
| break; | break; | ||||
| } | } | ||||
| if (id_override != NULL) { | if (id_override != nullptr) { | ||||
| id_override->override_library->flag &= ~IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED; | id_override->override_library->flag &= ~IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED; | ||||
| *r_undo_push_label = "Make Library Override Hierarchy"; | *r_undo_push_label = "Make Library Override Hierarchy"; | ||||
| /* In theory we could rely on setting/updating the RNA ID pointer property (as done by calling | /* In theory we could rely on setting/updating the RNA ID pointer property (as done by calling | ||||
| * code) to be enough. | * code) to be enough. | ||||
| * | * | ||||
| * However, some rare ID pointers properties (like the 'active object in viewlayer' one used | * However, some rare ID pointers properties (like the 'active object in viewlayer' one used | ||||
| * for the Object templateID in the Object properties) use notifiers that do not enforce a | * for the Object templateID in the Object properties) use notifiers that do not enforce a | ||||
| * rebuild of outliner trees, leading to crashes. | * rebuild of outliner trees, leading to crashes. | ||||
| * | * | ||||
| * So for now, add some extra notifiers here. */ | * So for now, add some extra notifiers here. */ | ||||
| WM_event_add_notifier(C, NC_ID | NA_ADDED, NULL); | WM_event_add_notifier(C, NC_ID | NA_ADDED, nullptr); | ||||
| WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL); | WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, nullptr); | ||||
| } | } | ||||
| return id_override; | return id_override; | ||||
| } | } | ||||
| static void template_id_liboverride_hierarchy_make(bContext *C, | static void template_id_liboverride_hierarchy_make(bContext *C, | ||||
| Main *bmain, | Main *bmain, | ||||
| TemplateID *template_ui, | TemplateID *template_ui, | ||||
| PointerRNA *idptr, | PointerRNA *idptr, | ||||
| const char **r_undo_push_label) | const char **r_undo_push_label) | ||||
| { | { | ||||
| ID *id = idptr->data; | ID *id = static_cast<ID *>(idptr->data); | ||||
| ID *owner_id = template_ui->ptr.owner_id; | ID *owner_id = template_ui->ptr.owner_id; | ||||
| ID *id_override = ui_template_id_liboverride_hierarchy_make( | ID *id_override = ui_template_id_liboverride_hierarchy_make( | ||||
| C, bmain, owner_id, id, r_undo_push_label); | C, bmain, owner_id, id, r_undo_push_label); | ||||
| if (id_override != NULL) { | if (id_override != nullptr) { | ||||
| /* `idptr` is re-assigned to owner property to ensure proper updates etc. Here we also use it | /* `idptr` is re-assigned to owner property to ensure proper updates etc. Here we also use it | ||||
| * to ensure remapping of the owner property from the linked data to the newly created | * to ensure remapping of the owner property from the linked data to the newly created | ||||
| * liboverride (note that in theory this remapping has already been done by code above), but | * liboverride (note that in theory this remapping has already been done by code above), but | ||||
| * only in case owner ID was already local ID (override or pure local data). | * only in case owner ID was already local ID (override or pure local data). | ||||
| * | * | ||||
| * Otherwise, owner ID will also have been overridden, and remapped already to use it's | * Otherwise, owner ID will also have been overridden, and remapped already to use it's | ||||
| * override of the data too. */ | * override of the data too. */ | ||||
| if (!ID_IS_LINKED(owner_id)) { | if (!ID_IS_LINKED(owner_id)) { | ||||
| RNA_id_pointer_create(id_override, idptr); | RNA_id_pointer_create(id_override, idptr); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| WM_reportf(RPT_ERROR, "The data-block %s could not be overridden", id->name); | WM_reportf(RPT_ERROR, "The data-block %s could not be overridden", id->name); | ||||
| } | } | ||||
| } | } | ||||
| static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) | static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) | ||||
| { | { | ||||
| TemplateID *template_ui = (TemplateID *)arg_litem; | TemplateID *template_ui = (TemplateID *)arg_litem; | ||||
| PointerRNA idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop); | PointerRNA idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop); | ||||
| ID *id = idptr.data; | ID *id = static_cast<ID *>(idptr.data); | ||||
| const int event = POINTER_AS_INT(arg_event); | const int event = POINTER_AS_INT(arg_event); | ||||
| const char *undo_push_label = NULL; | const char *undo_push_label = nullptr; | ||||
| switch (event) { | switch (event) { | ||||
| case UI_ID_NOP: | case UI_ID_NOP: | ||||
| /* Don't do anything, typically set for buttons that execute an operator instead. They may | /* Don't do anything, typically set for buttons that execute an operator instead. They may | ||||
| * still assign the callback so the button can be identified as part of an ID-template. See | * still assign the callback so the button can be identified as part of an ID-template. See | ||||
| * #UI_context_active_but_prop_get_templateID(). */ | * #UI_context_active_but_prop_get_templateID(). */ | ||||
| break; | break; | ||||
| case UI_ID_BROWSE: | case UI_ID_BROWSE: | ||||
| case UI_ID_PIN: | case UI_ID_PIN: | ||||
| RNA_warning("warning, id event %d shouldn't come here", event); | RNA_warning("warning, id event %d shouldn't come here", event); | ||||
| break; | break; | ||||
| case UI_ID_OPEN: | case UI_ID_OPEN: | ||||
| case UI_ID_ADD_NEW: | case UI_ID_ADD_NEW: | ||||
| /* these call UI_context_active_but_prop_get_templateID */ | /* these call UI_context_active_but_prop_get_templateID */ | ||||
| break; | break; | ||||
| case UI_ID_DELETE: | case UI_ID_DELETE: | ||||
| memset(&idptr, 0, sizeof(idptr)); | memset(&idptr, 0, sizeof(idptr)); | ||||
| RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, NULL); | RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, nullptr); | ||||
| RNA_property_update(C, &template_ui->ptr, template_ui->prop); | RNA_property_update(C, &template_ui->ptr, template_ui->prop); | ||||
| if (id && CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { | if (id && CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { | ||||
| /* only way to force-remove data (on save) */ | /* only way to force-remove data (on save) */ | ||||
| id_us_clear_real(id); | id_us_clear_real(id); | ||||
| id_fake_user_clear(id); | id_fake_user_clear(id); | ||||
| id->us = 0; | id->us = 0; | ||||
| undo_push_label = "Delete Data-Block"; | undo_push_label = "Delete Data-Block"; | ||||
| Show All 24 Lines | case UI_ID_LOCAL: | ||||
| if (BKE_lib_id_make_local(bmain, id, 0)) { | if (BKE_lib_id_make_local(bmain, id, 0)) { | ||||
| BKE_id_newptr_and_tag_clear(id); | BKE_id_newptr_and_tag_clear(id); | ||||
| /* Reassign to get proper updates/notifiers. */ | /* Reassign to get proper updates/notifiers. */ | ||||
| idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop); | idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop); | ||||
| undo_push_label = "Make Local"; | undo_push_label = "Make Local"; | ||||
| } | } | ||||
| } | } | ||||
| if (undo_push_label != NULL) { | if (undo_push_label != nullptr) { | ||||
| RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, NULL); | RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, nullptr); | ||||
| RNA_property_update(C, &template_ui->ptr, template_ui->prop); | RNA_property_update(C, &template_ui->ptr, template_ui->prop); | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case UI_ID_OVERRIDE: | case UI_ID_OVERRIDE: | ||||
| if (id && ID_IS_OVERRIDE_LIBRARY(id)) { | if (id && ID_IS_OVERRIDE_LIBRARY(id)) { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| if (CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { | if (CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { | ||||
| template_id_liboverride_hierarchy_make(C, bmain, template_ui, &idptr, &undo_push_label); | template_id_liboverride_hierarchy_make(C, bmain, template_ui, &idptr, &undo_push_label); | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_lib_override_library_make_local(id); | BKE_lib_override_library_make_local(id); | ||||
| /* Reassign to get proper updates/notifiers. */ | /* Reassign to get proper updates/notifiers. */ | ||||
| idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop); | idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop); | ||||
| RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, NULL); | RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, nullptr); | ||||
| RNA_property_update(C, &template_ui->ptr, template_ui->prop); | RNA_property_update(C, &template_ui->ptr, template_ui->prop); | ||||
| undo_push_label = "Make Local"; | undo_push_label = "Make Local"; | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case UI_ID_ALONE: | case UI_ID_ALONE: | ||||
| if (id) { | if (id) { | ||||
| const bool do_scene_obj = ((GS(id->name) == ID_OB) && | const bool do_scene_obj = ((GS(id->name) == ID_OB) && | ||||
| (template_ui->ptr.type == &RNA_LayerObjects)); | (template_ui->ptr.type == &RNA_LayerObjects)); | ||||
| /* make copy */ | /* make copy */ | ||||
| if (do_scene_obj) { | if (do_scene_obj) { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ED_object_single_user(bmain, scene, (struct Object *)id); | ED_object_single_user(bmain, scene, (Object *)id); | ||||
| WM_event_add_notifier(C, NC_WINDOW, NULL); | WM_event_add_notifier(C, NC_WINDOW, nullptr); | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| } | } | ||||
| else { | else { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| id_single_user(C, id, &template_ui->ptr, template_ui->prop); | id_single_user(C, id, &template_ui->ptr, template_ui->prop); | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| } | } | ||||
| undo_push_label = "Make Single User"; | undo_push_label = "Make Single User"; | ||||
| } | } | ||||
| break; | break; | ||||
| #if 0 | #if 0 | ||||
| case UI_ID_AUTO_NAME: | case UI_ID_AUTO_NAME: | ||||
| break; | break; | ||||
| #endif | #endif | ||||
| } | } | ||||
| if (undo_push_label != NULL) { | if (undo_push_label != nullptr) { | ||||
| ED_undo_push(C, undo_push_label); | ED_undo_push(C, undo_push_label); | ||||
| } | } | ||||
| } | } | ||||
| static const char *template_id_browse_tip(const StructRNA *type) | static const char *template_id_browse_tip(const StructRNA *type) | ||||
| { | { | ||||
| if (type) { | if (type) { | ||||
| switch ((ID_Type)RNA_type_to_ID_code(type)) { | switch ((ID_Type)RNA_type_to_ID_code(type)) { | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | |||||
| * generalizing. | * generalizing. | ||||
| */ | */ | ||||
| static void template_id_workspace_pin_extra_icon(const TemplateID *template_ui, uiBut *but) | static void template_id_workspace_pin_extra_icon(const TemplateID *template_ui, uiBut *but) | ||||
| { | { | ||||
| if ((template_ui->idcode != ID_SCE) || (template_ui->ptr.type != &RNA_Window)) { | if ((template_ui->idcode != ID_SCE) || (template_ui->ptr.type != &RNA_Window)) { | ||||
| return; | return; | ||||
| } | } | ||||
| const wmWindow *win = template_ui->ptr.data; | const wmWindow *win = static_cast<const wmWindow *>(template_ui->ptr.data); | ||||
| const WorkSpace *workspace = WM_window_get_active_workspace(win); | const WorkSpace *workspace = WM_window_get_active_workspace(win); | ||||
| UI_but_extra_operator_icon_add(but, | UI_but_extra_operator_icon_add(but, | ||||
| "WORKSPACE_OT_scene_pin_toggle", | "WORKSPACE_OT_scene_pin_toggle", | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| (workspace->flags & WORKSPACE_USE_PIN_SCENE) ? ICON_PINNED : | (workspace->flags & WORKSPACE_USE_PIN_SCENE) ? ICON_PINNED : | ||||
| ICON_UNPINNED); | ICON_UNPINNED); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | but = uiDefIconTextButO(block, | ||||
| newop, | newop, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| (id && !use_tab_but) ? ICON_DUPLICATE : ICON_ADD, | (id && !use_tab_but) ? ICON_DUPLICATE : ICON_ADD, | ||||
| (id) ? "" : CTX_IFACE_(template_id_context(type), "New"), | (id) ? "" : CTX_IFACE_(template_id_context(type), "New"), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| w, | w, | ||||
| but_height, | but_height, | ||||
| NULL); | nullptr); | ||||
| UI_but_funcN_set( | UI_but_funcN_set( | ||||
| but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_ADD_NEW)); | but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_ADD_NEW)); | ||||
| } | } | ||||
| else { | else { | ||||
| but = uiDefIconTextBut(block, | but = uiDefIconTextBut(block, | ||||
| but_type, | but_type, | ||||
| 0, | 0, | ||||
| (id && !use_tab_but) ? ICON_DUPLICATE : ICON_ADD, | (id && !use_tab_but) ? ICON_DUPLICATE : ICON_ADD, | ||||
| (id) ? "" : CTX_IFACE_(template_id_context(type), "New"), | (id) ? "" : CTX_IFACE_(template_id_context(type), "New"), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| w, | w, | ||||
| but_height, | but_height, | ||||
| NULL, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| NULL); | nullptr); | ||||
| UI_but_funcN_set( | UI_but_funcN_set( | ||||
| but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_ADD_NEW)); | but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_ADD_NEW)); | ||||
| } | } | ||||
| if ((idfrom && idfrom->lib) || !editable) { | if ((idfrom && idfrom->lib) || !editable) { | ||||
| UI_but_flag_enable(but, UI_BUT_DISABLED); | UI_but_flag_enable(but, UI_BUT_DISABLED); | ||||
| } | } | ||||
| Show All 16 Lines | static void template_ID(const bContext *C, | ||||
| const bool live_icon, | const bool live_icon, | ||||
| const bool hide_buttons) | const bool hide_buttons) | ||||
| { | { | ||||
| uiBut *but; | uiBut *but; | ||||
| const bool editable = RNA_property_editable(&template_ui->ptr, template_ui->prop); | const bool editable = RNA_property_editable(&template_ui->ptr, template_ui->prop); | ||||
| const bool use_previews = template_ui->preview = (flag & UI_ID_PREVIEWS) != 0; | const bool use_previews = template_ui->preview = (flag & UI_ID_PREVIEWS) != 0; | ||||
| PointerRNA idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop); | PointerRNA idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop); | ||||
| ID *id = idptr.data; | ID *id = static_cast<ID *>(idptr.data); | ||||
| ID *idfrom = template_ui->ptr.owner_id; | ID *idfrom = template_ui->ptr.owner_id; | ||||
| // lb = template_ui->idlb; | // lb = template_ui->idlb; | ||||
| /* Allow operators to take the ID from context. */ | /* Allow operators to take the ID from context. */ | ||||
| uiLayoutSetContextPointer(layout, "id", &idptr); | uiLayoutSetContextPointer(layout, "id", &idptr); | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| UI_block_align_begin(block); | UI_block_align_begin(block); | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | if (ID_IS_LINKED(id)) { | ||||
| but = uiDefIconBut(block, | but = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_LIBRARY_DATA_INDIRECT, | ICON_LIBRARY_DATA_INDIRECT, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Indirect library data-block, cannot be made local, " | TIP_("Indirect library data-block, cannot be made local, " | ||||
| "Shift + Click to create a library override hierarchy")); | "Shift + Click to create a library override hierarchy")); | ||||
| } | } | ||||
| else { | else { | ||||
| but = uiDefIconBut(block, | but = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_LIBRARY_DATA_DIRECT, | ICON_LIBRARY_DATA_DIRECT, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Direct linked library data-block, click to make local, " | TIP_("Direct linked library data-block, click to make local, " | ||||
| "Shift + Click to create a library override")); | "Shift + Click to create a library override")); | ||||
| } | } | ||||
| if (disabled) { | if (disabled) { | ||||
| Show All 9 Lines | else if (ID_IS_OVERRIDE_LIBRARY(id)) { | ||||
| block, | block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_LIBRARY_DATA_OVERRIDE, | ICON_LIBRARY_DATA_OVERRIDE, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Library override of linked data-block, click to make fully local, " | TIP_("Library override of linked data-block, click to make fully local, " | ||||
| "Shift + Click to clear the library override and toggle if it can be edited")); | "Shift + Click to clear the library override and toggle if it can be edited")); | ||||
| UI_but_funcN_set( | UI_but_funcN_set( | ||||
| but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_OVERRIDE)); | but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_OVERRIDE)); | ||||
| Show All 9 Lines | if ((ID_REAL_USERS(id) > 1) && (hide_buttons == false)) { | ||||
| block, | block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| numstr, | numstr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| numstr_len * 0.2f * UI_UNIT_X + UI_UNIT_X, | numstr_len * 0.2f * UI_UNIT_X + UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Display number of users of this data (click to make a single-user copy)")); | TIP_("Display number of users of this data (click to make a single-user copy)")); | ||||
| but->flag |= UI_BUT_UNDO; | but->flag |= UI_BUT_UNDO; | ||||
| UI_but_funcN_set( | UI_but_funcN_set( | ||||
| Show All 18 Lines | if (!ID_IS_LINKED(id)) { | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| /* 'active' state of a toggle button uses icon + 1, so to get proper asset | /* 'active' state of a toggle button uses icon + 1, so to get proper asset | ||||
| * icon we need to pass its value - 1 here. */ | * icon we need to pass its value - 1 here. */ | ||||
| ICON_ASSET_MANAGER - 1, | ICON_ASSET_MANAGER - 1, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL); | nullptr); | ||||
| } | } | ||||
| else if (!ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_OB, ID_WS) && | else if (!ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_OB, ID_WS) && | ||||
| (hide_buttons == false)) { | (hide_buttons == false)) { | ||||
| uiDefIconButR(block, | uiDefIconButR(block, | ||||
| UI_BTYPE_ICON_TOGGLE, | UI_BTYPE_ICON_TOGGLE, | ||||
| 0, | 0, | ||||
| ICON_FAKE_USER_OFF, | ICON_FAKE_USER_OFF, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| &idptr, | &idptr, | ||||
| "use_fake_user", | "use_fake_user", | ||||
| -1, | -1, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| -1, | -1, | ||||
| -1, | -1, | ||||
| NULL); | nullptr); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if ((flag & UI_ID_ADD_NEW) && (hide_buttons == false)) { | if ((flag & UI_ID_ADD_NEW) && (hide_buttons == false)) { | ||||
| template_id_def_new_but( | template_id_def_new_but( | ||||
| block, id, template_ui, type, newop, editable, flag & UI_ID_OPEN, false, UI_UNIT_X); | block, id, template_ui, type, newop, editable, flag & UI_ID_OPEN, false, UI_UNIT_X); | ||||
| } | } | ||||
| Show All 25 Lines | if (openop) { | ||||
| openop, | openop, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| ICON_FILEBROWSER, | ICON_FILEBROWSER, | ||||
| (id) ? "" : IFACE_("Open"), | (id) ? "" : IFACE_("Open"), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| w, | w, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL); | nullptr); | ||||
| UI_but_funcN_set( | UI_but_funcN_set( | ||||
| but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_OPEN)); | but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_OPEN)); | ||||
| } | } | ||||
| else { | else { | ||||
| but = uiDefIconTextBut(block, | but = uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_FILEBROWSER, | ICON_FILEBROWSER, | ||||
| (id) ? "" : IFACE_("Open"), | (id) ? "" : IFACE_("Open"), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| w, | w, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| NULL); | nullptr); | ||||
| UI_but_funcN_set( | UI_but_funcN_set( | ||||
| but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_OPEN)); | but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_OPEN)); | ||||
| } | } | ||||
| if ((idfrom && idfrom->lib) || !editable) { | if ((idfrom && idfrom->lib) || !editable) { | ||||
| UI_but_flag_enable(but, UI_BUT_DISABLED); | UI_but_flag_enable(but, UI_BUT_DISABLED); | ||||
| } | } | ||||
| } | } | ||||
| /* delete button */ | /* delete button */ | ||||
| /* don't use RNA_property_is_unlink here */ | /* don't use RNA_property_is_unlink here */ | ||||
| if (id && (flag & UI_ID_DELETE) && (hide_buttons == false)) { | if (id && (flag & UI_ID_DELETE) && (hide_buttons == false)) { | ||||
| /* allow unlink if 'unlinkop' is passed, even when 'PROP_NEVER_UNLINK' is set */ | /* allow unlink if 'unlinkop' is passed, even when 'PROP_NEVER_UNLINK' is set */ | ||||
| but = NULL; | but = nullptr; | ||||
| if (unlinkop) { | if (unlinkop) { | ||||
| but = uiDefIconButO(block, | but = uiDefIconButO(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| unlinkop, | unlinkop, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| ICON_X, | ICON_X, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL); | nullptr); | ||||
| /* so we can access the template from operators, font unlinking needs this */ | /* so we can access the template from operators, font unlinking needs this */ | ||||
| UI_but_funcN_set( | UI_but_funcN_set( | ||||
| but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_NOP)); | but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_NOP)); | ||||
| } | } | ||||
| else { | else { | ||||
| if ((RNA_property_flag(template_ui->prop) & PROP_NEVER_UNLINK) == 0) { | if ((RNA_property_flag(template_ui->prop) & PROP_NEVER_UNLINK) == 0) { | ||||
| but = uiDefIconBut( | but = uiDefIconBut( | ||||
| block, | block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_X, | ICON_X, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Unlink data-block " | TIP_("Unlink data-block " | ||||
| "(Shift + Click to set users to zero, data will then not be saved)")); | "(Shift + Click to set users to zero, data will then not be saved)")); | ||||
| UI_but_funcN_set( | UI_but_funcN_set( | ||||
| but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_DELETE)); | but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_DELETE)); | ||||
| Show All 17 Lines | static void template_ID(const bContext *C, | ||||
| UI_block_align_end(block); | UI_block_align_end(block); | ||||
| } | } | ||||
| ID *UI_context_active_but_get_tab_ID(bContext *C) | ID *UI_context_active_but_get_tab_ID(bContext *C) | ||||
| { | { | ||||
| uiBut *but = UI_context_active_but_get(C); | uiBut *but = UI_context_active_but_get(C); | ||||
| if (but && but->type == UI_BTYPE_TAB) { | if (but && but->type == UI_BTYPE_TAB) { | ||||
| return but->custom_data; | return static_cast<ID *>(but->custom_data); | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| static void template_ID_tabs(const bContext *C, | static void template_ID_tabs(const bContext *C, | ||||
| uiLayout *layout, | uiLayout *layout, | ||||
| TemplateID *template, | TemplateID *template_id, | ||||
| StructRNA *type, | StructRNA *type, | ||||
| int flag, | int flag, | ||||
| const char *newop, | const char *newop, | ||||
| const char *menu) | const char *menu) | ||||
| { | { | ||||
| const ARegion *region = CTX_wm_region(C); | const ARegion *region = CTX_wm_region(C); | ||||
| const PointerRNA active_ptr = RNA_property_pointer_get(&template->ptr, template->prop); | const PointerRNA active_ptr = RNA_property_pointer_get(&template_id->ptr, template_id->prop); | ||||
| MenuType *mt = menu ? WM_menutype_find(menu, false) : NULL; | MenuType *mt = menu ? WM_menutype_find(menu, false) : nullptr; | ||||
| const int but_align = ui_but_align_opposite_to_area_align_get(region); | const int but_align = ui_but_align_opposite_to_area_align_get(region); | ||||
| const int but_height = UI_UNIT_Y * 1.1; | const int but_height = UI_UNIT_Y * 1.1; | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| const uiStyle *style = UI_style_get_dpi(); | const uiStyle *style = UI_style_get_dpi(); | ||||
| ListBase ordered; | ListBase ordered; | ||||
| BKE_id_ordered_list(&ordered, template->idlb); | BKE_id_ordered_list(&ordered, template_id->idlb); | ||||
| LISTBASE_FOREACH (LinkData *, link, &ordered) { | LISTBASE_FOREACH (LinkData *, link, &ordered) { | ||||
| ID *id = link->data; | ID *id = static_cast<ID *>(link->data); | ||||
| const int name_width = UI_fontstyle_string_width(&style->widget, id->name + 2); | const int name_width = UI_fontstyle_string_width(&style->widget, id->name + 2); | ||||
| const int but_width = name_width + UI_UNIT_X; | const int but_width = name_width + UI_UNIT_X; | ||||
| uiButTab *tab = (uiButTab *)uiDefButR_prop(block, | uiButTab *tab = (uiButTab *)uiDefButR_prop(block, | ||||
| UI_BTYPE_TAB, | UI_BTYPE_TAB, | ||||
| 0, | 0, | ||||
| id->name + 2, | id->name + 2, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| but_width, | but_width, | ||||
| but_height, | but_height, | ||||
| &template->ptr, | &template_id->ptr, | ||||
| template->prop, | template_id->prop, | ||||
| 0, | 0, | ||||
| 0.0f, | 0.0f, | ||||
| sizeof(id->name) - 2, | sizeof(id->name) - 2, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| ""); | ""); | ||||
| UI_but_funcN_set(&tab->but, template_ID_set_property_exec_fn, MEM_dupallocN(template), id); | UI_but_funcN_set(&tab->but, template_ID_set_property_exec_fn, MEM_dupallocN(template_id), id); | ||||
| UI_but_drag_set_id(&tab->but, id); | UI_but_drag_set_id(&tab->but, id); | ||||
| tab->but.custom_data = (void *)id; | tab->but.custom_data = (void *)id; | ||||
| tab->menu = mt; | tab->menu = mt; | ||||
| UI_but_drawflag_enable(&tab->but, but_align); | UI_but_drawflag_enable(&tab->but, but_align); | ||||
| } | } | ||||
| BLI_freelistN(&ordered); | BLI_freelistN(&ordered); | ||||
| if (flag & UI_ID_ADD_NEW) { | if (flag & UI_ID_ADD_NEW) { | ||||
| const bool editable = RNA_property_editable(&template->ptr, template->prop); | const bool editable = RNA_property_editable(&template_id->ptr, template_id->prop); | ||||
| uiBut *but; | uiBut *but; | ||||
| if (active_ptr.type) { | if (active_ptr.type) { | ||||
| type = active_ptr.type; | type = active_ptr.type; | ||||
| } | } | ||||
| but = template_id_def_new_but(block, | but = template_id_def_new_but(block, | ||||
| active_ptr.data, | static_cast<const ID *>(active_ptr.data), | ||||
| template, | template_id, | ||||
| type, | type, | ||||
| newop, | newop, | ||||
| editable, | editable, | ||||
| flag & UI_ID_OPEN, | flag & UI_ID_OPEN, | ||||
| true, | true, | ||||
| but_height); | but_height); | ||||
| UI_but_drawflag_enable(but, but_align); | UI_but_drawflag_enable(but, but_align); | ||||
| } | } | ||||
| Show All 20 Lines | |||||
| { | { | ||||
| PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | ||||
| if (!prop || RNA_property_type(prop) != PROP_POINTER) { | if (!prop || RNA_property_type(prop) != PROP_POINTER) { | ||||
| RNA_warning("pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); | RNA_warning("pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); | ||||
| return; | return; | ||||
| } | } | ||||
| TemplateID *template_ui = MEM_callocN(sizeof(TemplateID), "TemplateID"); | TemplateID *template_ui = MEM_cnew<TemplateID>(__func__); | ||||
| template_ui->ptr = *ptr; | template_ui->ptr = *ptr; | ||||
| template_ui->prop = prop; | template_ui->prop = prop; | ||||
| template_ui->prv_rows = prv_rows; | template_ui->prv_rows = prv_rows; | ||||
| template_ui->prv_cols = prv_cols; | template_ui->prv_cols = prv_cols; | ||||
| template_ui->scale = scale; | template_ui->scale = scale; | ||||
| if ((flag & UI_ID_PIN) == 0) { | if ((flag & UI_ID_PIN) == 0) { | ||||
| template_ui->filter = filter; | template_ui->filter = filter; | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| ui_template_id(layout, | ui_template_id(layout, | ||||
| C, | C, | ||||
| ptr, | ptr, | ||||
| propname, | propname, | ||||
| newop, | newop, | ||||
| openop, | openop, | ||||
| unlinkop, | unlinkop, | ||||
| NULL, | nullptr, | ||||
| text, | text, | ||||
| UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, | UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| filter, | filter, | ||||
| false, | false, | ||||
| 1.0f, | 1.0f, | ||||
| live_icon, | live_icon, | ||||
| Show All 12 Lines | |||||
| { | { | ||||
| ui_template_id(layout, | ui_template_id(layout, | ||||
| C, | C, | ||||
| ptr, | ptr, | ||||
| propname, | propname, | ||||
| newop, | newop, | ||||
| openop, | openop, | ||||
| unlinkop, | unlinkop, | ||||
| NULL, | nullptr, | ||||
| text, | text, | ||||
| UI_ID_BROWSE | UI_ID_RENAME, | UI_ID_BROWSE | UI_ID_RENAME, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| filter, | filter, | ||||
| false, | false, | ||||
| 1.0f, | 1.0f, | ||||
| false, | false, | ||||
| Show All 14 Lines | |||||
| { | { | ||||
| ui_template_id(layout, | ui_template_id(layout, | ||||
| C, | C, | ||||
| ptr, | ptr, | ||||
| propname, | propname, | ||||
| newop, | newop, | ||||
| openop, | openop, | ||||
| unlinkop, | unlinkop, | ||||
| NULL, | nullptr, | ||||
| NULL, | nullptr, | ||||
| UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE | UI_ID_PREVIEWS, | UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE | UI_ID_PREVIEWS, | ||||
| rows, | rows, | ||||
| cols, | cols, | ||||
| filter, | filter, | ||||
| false, | false, | ||||
| 1.0f, | 1.0f, | ||||
| false, | false, | ||||
| hide_buttons); | hide_buttons); | ||||
| } | } | ||||
| void uiTemplateGpencilColorPreview(uiLayout *layout, | void uiTemplateGpencilColorPreview(uiLayout *layout, | ||||
| bContext *C, | bContext *C, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| const char *propname, | const char *propname, | ||||
| int rows, | int rows, | ||||
| int cols, | int cols, | ||||
| float scale, | float scale, | ||||
| int filter) | int filter) | ||||
| { | { | ||||
| ui_template_id(layout, | ui_template_id(layout, | ||||
| C, | C, | ||||
| ptr, | ptr, | ||||
| propname, | propname, | ||||
| NULL, | nullptr, | ||||
| NULL, | nullptr, | ||||
| NULL, | nullptr, | ||||
| NULL, | nullptr, | ||||
| NULL, | nullptr, | ||||
| UI_ID_BROWSE | UI_ID_PREVIEWS | UI_ID_DELETE, | UI_ID_BROWSE | UI_ID_PREVIEWS | UI_ID_DELETE, | ||||
| rows, | rows, | ||||
| cols, | cols, | ||||
| filter, | filter, | ||||
| false, | false, | ||||
| scale < 0.5f ? 0.5f : scale, | scale < 0.5f ? 0.5f : scale, | ||||
| false, | false, | ||||
| false); | false); | ||||
| } | } | ||||
| void uiTemplateIDTabs(uiLayout *layout, | void uiTemplateIDTabs(uiLayout *layout, | ||||
| bContext *C, | bContext *C, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| const char *propname, | const char *propname, | ||||
| const char *newop, | const char *newop, | ||||
| const char *menu, | const char *menu, | ||||
| int filter) | int filter) | ||||
| { | { | ||||
| ui_template_id(layout, | ui_template_id(layout, | ||||
| C, | C, | ||||
| ptr, | ptr, | ||||
| propname, | propname, | ||||
| newop, | newop, | ||||
| NULL, | nullptr, | ||||
| NULL, | nullptr, | ||||
| menu, | menu, | ||||
| NULL, | nullptr, | ||||
| UI_ID_BROWSE | UI_ID_RENAME, | UI_ID_BROWSE | UI_ID_RENAME, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| filter, | filter, | ||||
| true, | true, | ||||
| 1.0f, | 1.0f, | ||||
| false, | false, | ||||
| false); | false); | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Search Template | /** \name Search Template | ||||
| * \{ */ | * \{ */ | ||||
| typedef struct TemplateSearch { | struct TemplateSearch { | ||||
| uiRNACollectionSearch search_data; | uiRNACollectionSearch search_data; | ||||
| bool use_previews; | bool use_previews; | ||||
| int preview_rows, preview_cols; | int preview_rows, preview_cols; | ||||
| } TemplateSearch; | }; | ||||
| static void template_search_exec_fn(bContext *C, void *arg_template, void *item) | static void template_search_exec_fn(bContext *C, void *arg_template, void *item) | ||||
| { | { | ||||
| TemplateSearch *template_search = arg_template; | TemplateSearch *template_search = static_cast<TemplateSearch *>(arg_template); | ||||
| uiRNACollectionSearch *coll_search = &template_search->search_data; | uiRNACollectionSearch *coll_search = &template_search->search_data; | ||||
| StructRNA *type = RNA_property_pointer_type(&coll_search->target_ptr, coll_search->target_prop); | StructRNA *type = RNA_property_pointer_type(&coll_search->target_ptr, coll_search->target_prop); | ||||
| PointerRNA item_ptr; | PointerRNA item_ptr; | ||||
| RNA_pointer_create(NULL, type, item, &item_ptr); | RNA_pointer_create(nullptr, type, item, &item_ptr); | ||||
| RNA_property_pointer_set(&coll_search->target_ptr, coll_search->target_prop, item_ptr, NULL); | RNA_property_pointer_set(&coll_search->target_ptr, coll_search->target_prop, item_ptr, nullptr); | ||||
| RNA_property_update(C, &coll_search->target_ptr, coll_search->target_prop); | RNA_property_update(C, &coll_search->target_ptr, coll_search->target_prop); | ||||
| } | } | ||||
| static uiBlock *template_search_menu(bContext *C, ARegion *region, void *arg_template) | static uiBlock *template_search_menu(bContext *C, ARegion *region, void *arg_template) | ||||
| { | { | ||||
| static TemplateSearch template_search; | static TemplateSearch template_search; | ||||
| /* arg_template is malloced, can be freed by parent button */ | /* arg_template is malloced, can be freed by parent button */ | ||||
| template_search = *((TemplateSearch *)arg_template); | template_search = *((TemplateSearch *)arg_template); | ||||
| PointerRNA active_ptr = RNA_property_pointer_get(&template_search.search_data.target_ptr, | PointerRNA active_ptr = RNA_property_pointer_get(&template_search.search_data.target_ptr, | ||||
| template_search.search_data.target_prop); | template_search.search_data.target_prop); | ||||
| return template_common_search_menu(C, | return template_common_search_menu(C, | ||||
| region, | region, | ||||
| ui_rna_collection_search_update_fn, | ui_rna_collection_search_update_fn, | ||||
| &template_search, | &template_search, | ||||
| template_search_exec_fn, | template_search_exec_fn, | ||||
| active_ptr.data, | active_ptr.data, | ||||
| NULL, | nullptr, | ||||
| template_search.preview_rows, | template_search.preview_rows, | ||||
| template_search.preview_cols, | template_search.preview_cols, | ||||
| 1.0f); | 1.0f); | ||||
| } | } | ||||
| static void template_search_add_button_searchmenu(const bContext *C, | static void template_search_add_button_searchmenu(const bContext *C, | ||||
| uiLayout *layout, | uiLayout *layout, | ||||
| uiBlock *block, | uiBlock *block, | ||||
| Show All 33 Lines | static void template_search_add_button_operator(uiBlock *block, | ||||
| const int icon, | const int icon, | ||||
| const bool editable) | const bool editable) | ||||
| { | { | ||||
| if (!operator_name) { | if (!operator_name) { | ||||
| return; | return; | ||||
| } | } | ||||
| uiBut *but = uiDefIconButO( | uiBut *but = uiDefIconButO( | ||||
| block, UI_BTYPE_BUT, operator_name, opcontext, icon, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL); | block, UI_BTYPE_BUT, operator_name, opcontext, icon, 0, 0, UI_UNIT_X, UI_UNIT_Y, nullptr); | ||||
| if (!editable) { | if (!editable) { | ||||
| UI_but_drawflag_enable(but, UI_BUT_DISABLED); | UI_but_drawflag_enable(but, UI_BUT_DISABLED); | ||||
| } | } | ||||
| } | } | ||||
| static void template_search_buttons(const bContext *C, | static void template_search_buttons(const bContext *C, | ||||
| uiLayout *layout, | uiLayout *layout, | ||||
| Show All 28 Lines | |||||
| static PropertyRNA *template_search_get_searchprop(PointerRNA *targetptr, | static PropertyRNA *template_search_get_searchprop(PointerRNA *targetptr, | ||||
| PropertyRNA *targetprop, | PropertyRNA *targetprop, | ||||
| PointerRNA *searchptr, | PointerRNA *searchptr, | ||||
| const char *const searchpropname) | const char *const searchpropname) | ||||
| { | { | ||||
| PropertyRNA *searchprop; | PropertyRNA *searchprop; | ||||
| if (searchptr && !searchptr->data) { | if (searchptr && !searchptr->data) { | ||||
| searchptr = NULL; | searchptr = nullptr; | ||||
| } | } | ||||
| if (!searchptr && !searchpropname) { | if (!searchptr && !searchpropname) { | ||||
| /* both NULL means we don't use a custom rna collection to search in */ | /* both nullptr means we don't use a custom rna collection to search in */ | ||||
| } | } | ||||
| else if (!searchptr && searchpropname) { | else if (!searchptr && searchpropname) { | ||||
| RNA_warning("searchpropname defined (%s) but searchptr is missing", searchpropname); | RNA_warning("searchpropname defined (%s) but searchptr is missing", searchpropname); | ||||
| } | } | ||||
| else if (searchptr && !searchpropname) { | else if (searchptr && !searchpropname) { | ||||
| RNA_warning("searchptr defined (%s) but searchpropname is missing", | RNA_warning("searchptr defined (%s) but searchpropname is missing", | ||||
| RNA_struct_identifier(searchptr->type)); | RNA_struct_identifier(searchptr->type)); | ||||
| } | } | ||||
| Show All 14 Lines | RNA_warning("search collection items from %s.%s are not of type %s", | ||||
| RNA_struct_identifier(searchptr->type), | RNA_struct_identifier(searchptr->type), | ||||
| searchpropname, | searchpropname, | ||||
| RNA_struct_identifier(RNA_property_pointer_type(targetptr, targetprop))); | RNA_struct_identifier(RNA_property_pointer_type(targetptr, targetprop))); | ||||
| } | } | ||||
| else { | else { | ||||
| return searchprop; | return searchprop; | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| static TemplateSearch *template_search_setup(PointerRNA *ptr, | static TemplateSearch *template_search_setup(PointerRNA *ptr, | ||||
| const char *const propname, | const char *const propname, | ||||
| PointerRNA *searchptr, | PointerRNA *searchptr, | ||||
| const char *const searchpropname) | const char *const searchpropname) | ||||
| { | { | ||||
| PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | ||||
| if (!prop || RNA_property_type(prop) != PROP_POINTER) { | if (!prop || RNA_property_type(prop) != PROP_POINTER) { | ||||
| RNA_warning("pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); | RNA_warning("pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| PropertyRNA *searchprop = template_search_get_searchprop(ptr, prop, searchptr, searchpropname); | PropertyRNA *searchprop = template_search_get_searchprop(ptr, prop, searchptr, searchpropname); | ||||
| TemplateSearch *template_search = MEM_callocN(sizeof(*template_search), __func__); | TemplateSearch *template_search = MEM_cnew<TemplateSearch>(__func__); | ||||
| template_search->search_data.target_ptr = *ptr; | template_search->search_data.target_ptr = *ptr; | ||||
| template_search->search_data.target_prop = prop; | template_search->search_data.target_prop = prop; | ||||
| template_search->search_data.search_ptr = *searchptr; | template_search->search_data.search_ptr = *searchptr; | ||||
| template_search->search_data.search_prop = searchprop; | template_search->search_data.search_prop = searchprop; | ||||
| return template_search; | return template_search; | ||||
| } | } | ||||
| void uiTemplateSearch(uiLayout *layout, | void uiTemplateSearch(uiLayout *layout, | ||||
| bContext *C, | bContext *C, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| const char *propname, | const char *propname, | ||||
| PointerRNA *searchptr, | PointerRNA *searchptr, | ||||
| const char *searchpropname, | const char *searchpropname, | ||||
| const char *newop, | const char *newop, | ||||
| const char *unlinkop) | const char *unlinkop) | ||||
| { | { | ||||
| TemplateSearch *template_search = template_search_setup( | TemplateSearch *template_search = template_search_setup( | ||||
| ptr, propname, searchptr, searchpropname); | ptr, propname, searchptr, searchpropname); | ||||
| if (template_search != NULL) { | if (template_search != nullptr) { | ||||
| template_search_buttons(C, layout, template_search, newop, unlinkop); | template_search_buttons(C, layout, template_search, newop, unlinkop); | ||||
| MEM_freeN(template_search); | MEM_freeN(template_search); | ||||
| } | } | ||||
| } | } | ||||
| void uiTemplateSearchPreview(uiLayout *layout, | void uiTemplateSearchPreview(uiLayout *layout, | ||||
| bContext *C, | bContext *C, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| const char *propname, | const char *propname, | ||||
| PointerRNA *searchptr, | PointerRNA *searchptr, | ||||
| const char *searchpropname, | const char *searchpropname, | ||||
| const char *newop, | const char *newop, | ||||
| const char *unlinkop, | const char *unlinkop, | ||||
| const int rows, | const int rows, | ||||
| const int cols) | const int cols) | ||||
| { | { | ||||
| TemplateSearch *template_search = template_search_setup( | TemplateSearch *template_search = template_search_setup( | ||||
| ptr, propname, searchptr, searchpropname); | ptr, propname, searchptr, searchpropname); | ||||
| if (template_search != NULL) { | if (template_search != nullptr) { | ||||
| template_search->use_previews = true; | template_search->use_previews = true; | ||||
| template_search->preview_rows = rows; | template_search->preview_rows = rows; | ||||
| template_search->preview_cols = cols; | template_search->preview_cols = cols; | ||||
| template_search_buttons(C, layout, template_search, newop, unlinkop); | template_search_buttons(C, layout, template_search, newop, unlinkop); | ||||
| MEM_freeN(template_search); | MEM_freeN(template_search); | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name RNA Path Builder Template | /** \name RNA Path Builder Template | ||||
| * \{ */ | * \{ */ | ||||
| /* ---------- */ | /* ---------- */ | ||||
| void uiTemplatePathBuilder(uiLayout *layout, | void uiTemplatePathBuilder(uiLayout *layout, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| const char *propname, | const char *propname, | ||||
| PointerRNA *UNUSED(root_ptr), | PointerRNA * /*root_ptr*/, | ||||
| const char *text) | const char *text) | ||||
| { | { | ||||
| /* check that properties are valid */ | /* check that properties are valid */ | ||||
| PropertyRNA *propPath = RNA_struct_find_property(ptr, propname); | PropertyRNA *propPath = RNA_struct_find_property(ptr, propname); | ||||
| if (!propPath || RNA_property_type(propPath) != PROP_STRING) { | if (!propPath || RNA_property_type(propPath) != PROP_STRING) { | ||||
| RNA_warning("path property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); | RNA_warning("path property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); | ||||
| return; | return; | ||||
| } | } | ||||
| Show All 14 Lines | |||||
| /** \name Modifiers Template | /** \name Modifiers Template | ||||
| * | * | ||||
| * Template for building the panel layout for the active object's modifiers. | * Template for building the panel layout for the active object's modifiers. | ||||
| * \{ */ | * \{ */ | ||||
| static void modifier_panel_id(void *md_link, char *r_name) | static void modifier_panel_id(void *md_link, char *r_name) | ||||
| { | { | ||||
| ModifierData *md = (ModifierData *)md_link; | ModifierData *md = (ModifierData *)md_link; | ||||
| BKE_modifier_type_panel_id(md->type, r_name); | BKE_modifier_type_panel_id(ModifierType(md->type), r_name); | ||||
| } | } | ||||
| void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C) | void uiTemplateModifiers(uiLayout * /*layout*/, bContext *C) | ||||
| { | { | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| ListBase *modifiers = &ob->modifiers; | ListBase *modifiers = &ob->modifiers; | ||||
| const 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) { | if (!panels_match) { | ||||
| UI_panels_free_instanced(C, region); | UI_panels_free_instanced(C, region); | ||||
| ModifierData *md = modifiers->first; | ModifierData *md = static_cast<ModifierData *>(modifiers->first); | ||||
| for (int i = 0; md; i++, md = md->next) { | for (int i = 0; md; i++, md = md->next) { | ||||
| const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); | const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type)); | ||||
| if (mti->panelRegister == NULL) { | if (mti->panelRegister == nullptr) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| char panel_idname[MAX_NAME]; | char panel_idname[MAX_NAME]; | ||||
| modifier_panel_id(md, panel_idname); | modifier_panel_id(md, panel_idname); | ||||
| /* Create custom data RNA pointer. */ | /* Create custom data RNA pointer. */ | ||||
| PointerRNA *md_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); | PointerRNA *md_ptr = static_cast<PointerRNA *>(MEM_mallocN(sizeof(PointerRNA), __func__)); | ||||
| RNA_pointer_create(&ob->id, &RNA_Modifier, md, md_ptr); | RNA_pointer_create(&ob->id, &RNA_Modifier, md, md_ptr); | ||||
| UI_panel_add_instanced(C, region, ®ion->panels, panel_idname, md_ptr); | UI_panel_add_instanced(C, region, ®ion->panels, panel_idname, md_ptr); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Assuming there's only one group of instanced panels, update the custom data pointers. */ | /* Assuming there's only one group of instanced panels, update the custom data pointers. */ | ||||
| Panel *panel = region->panels.first; | Panel *panel = static_cast<Panel *>(region->panels.first); | ||||
| LISTBASE_FOREACH (ModifierData *, md, modifiers) { | LISTBASE_FOREACH (ModifierData *, md, modifiers) { | ||||
| const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); | const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type)); | ||||
| if (mti->panelRegister == NULL) { | if (mti->panelRegister == nullptr) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* Move to the next instanced panel corresponding to the next modifier. */ | /* Move to the next instanced panel corresponding to the next modifier. */ | ||||
| while ((panel->type == NULL) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) { | while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) { | ||||
| panel = panel->next; | panel = panel->next; | ||||
| BLI_assert(panel != NULL); /* There shouldn't be fewer panels than modifiers with UIs. */ | BLI_assert(panel != | ||||
| nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */ | |||||
| } | } | ||||
| PointerRNA *md_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); | PointerRNA *md_ptr = static_cast<PointerRNA *>(MEM_mallocN(sizeof(PointerRNA), __func__)); | ||||
| RNA_pointer_create(&ob->id, &RNA_Modifier, md, md_ptr); | RNA_pointer_create(&ob->id, &RNA_Modifier, md, md_ptr); | ||||
| UI_panel_custom_data_set(panel, md_ptr); | UI_panel_custom_data_set(panel, md_ptr); | ||||
| panel = panel->next; | panel = panel->next; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 30 Lines | static void constraint_reorder(bContext *C, Panel *panel, int new_index) | ||||
| PointerRNA props_ptr; | PointerRNA props_ptr; | ||||
| wmOperatorType *ot = WM_operatortype_find("CONSTRAINT_OT_move_to_index", false); | wmOperatorType *ot = WM_operatortype_find("CONSTRAINT_OT_move_to_index", false); | ||||
| WM_operator_properties_create_ptr(&props_ptr, ot); | WM_operator_properties_create_ptr(&props_ptr, ot); | ||||
| RNA_string_set(&props_ptr, "constraint", con->name); | RNA_string_set(&props_ptr, "constraint", con->name); | ||||
| RNA_int_set(&props_ptr, "index", new_index); | RNA_int_set(&props_ptr, "index", new_index); | ||||
| /* Set owner to #EDIT_CONSTRAINT_OWNER_OBJECT or #EDIT_CONSTRAINT_OWNER_BONE. */ | /* Set owner to #EDIT_CONSTRAINT_OWNER_OBJECT or #EDIT_CONSTRAINT_OWNER_BONE. */ | ||||
| RNA_enum_set(&props_ptr, "owner", constraint_from_bone ? 1 : 0); | RNA_enum_set(&props_ptr, "owner", constraint_from_bone ? 1 : 0); | ||||
| WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, NULL); | WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, nullptr); | ||||
| WM_operator_properties_free(&props_ptr); | WM_operator_properties_free(&props_ptr); | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the expand flag from the active constraint to use for the panel. | * Get the expand flag from the active constraint to use for the panel. | ||||
| */ | */ | ||||
| static short get_constraint_expand_flag(const bContext *UNUSED(C), Panel *panel) | static short get_constraint_expand_flag(const bContext * /*C*/, Panel *panel) | ||||
| { | { | ||||
| PointerRNA *con_ptr = UI_panel_custom_data_get(panel); | PointerRNA *con_ptr = UI_panel_custom_data_get(panel); | ||||
| bConstraint *con = (bConstraint *)con_ptr->data; | bConstraint *con = (bConstraint *)con_ptr->data; | ||||
| return con->ui_expand_flag; | return con->ui_expand_flag; | ||||
| } | } | ||||
| /** | /** | ||||
| * Save the expand flag for the panel and sub-panels to the constraint. | * Save the expand flag for the panel and sub-panels to the constraint. | ||||
| */ | */ | ||||
| static void set_constraint_expand_flag(const bContext *UNUSED(C), Panel *panel, short expand_flag) | static void set_constraint_expand_flag(const bContext * /*C*/, Panel *panel, short expand_flag) | ||||
| { | { | ||||
| PointerRNA *con_ptr = UI_panel_custom_data_get(panel); | PointerRNA *con_ptr = UI_panel_custom_data_get(panel); | ||||
| bConstraint *con = (bConstraint *)con_ptr->data; | bConstraint *con = (bConstraint *)con_ptr->data; | ||||
| con->ui_expand_flag = expand_flag; | con->ui_expand_flag = expand_flag; | ||||
| } | } | ||||
| /** | /** | ||||
| * Function with void * argument for #uiListPanelIDFromDataFunc. | * Function with void * argument for #uiListPanelIDFromDataFunc. | ||||
| * | * | ||||
| * \note Constraint panel types are assumed to be named with the struct name field | * \note Constraint panel types are assumed to be named with the struct name field | ||||
| * concatenated to the defined prefix. | * concatenated to the defined prefix. | ||||
| */ | */ | ||||
| static void object_constraint_panel_id(void *md_link, char *r_name) | static void object_constraint_panel_id(void *md_link, char *r_name) | ||||
| { | { | ||||
| bConstraint *con = (bConstraint *)md_link; | bConstraint *con = (bConstraint *)md_link; | ||||
| const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_from_type(con->type); | const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_from_type(con->type); | ||||
| /* Cannot get TypeInfo for invalid/legacy constraints. */ | /* Cannot get TypeInfo for invalid/legacy constraints. */ | ||||
| if (cti == NULL) { | if (cti == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| strcpy(r_name, CONSTRAINT_TYPE_PANEL_PREFIX); | strcpy(r_name, CONSTRAINT_TYPE_PANEL_PREFIX); | ||||
| strcat(r_name, cti->structName); | strcat(r_name, cti->structName); | ||||
| } | } | ||||
| static void bone_constraint_panel_id(void *md_link, char *r_name) | static void bone_constraint_panel_id(void *md_link, char *r_name) | ||||
| { | { | ||||
| bConstraint *con = (bConstraint *)md_link; | bConstraint *con = (bConstraint *)md_link; | ||||
| const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_from_type(con->type); | const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_from_type(con->type); | ||||
| /* Cannot get TypeInfo for invalid/legacy constraints. */ | /* Cannot get TypeInfo for invalid/legacy constraints. */ | ||||
| if (cti == NULL) { | if (cti == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| strcpy(r_name, CONSTRAINT_BONE_TYPE_PANEL_PREFIX); | strcpy(r_name, CONSTRAINT_BONE_TYPE_PANEL_PREFIX); | ||||
| strcat(r_name, cti->structName); | strcat(r_name, cti->structName); | ||||
| } | } | ||||
| void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_constraints) | void uiTemplateConstraints(uiLayout * /*layout*/, bContext *C, bool use_bone_constraints) | ||||
| { | { | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| ListBase *constraints = {NULL}; | ListBase *constraints = {nullptr}; | ||||
| if (use_bone_constraints) { | if (use_bone_constraints) { | ||||
| constraints = ED_object_pose_constraint_list(C); | constraints = ED_object_pose_constraint_list(C); | ||||
| } | } | ||||
| else if (ob != NULL) { | else if (ob != nullptr) { | ||||
| constraints = &ob->constraints; | constraints = &ob->constraints; | ||||
| } | } | ||||
| /* Switch between the bone panel ID function and the object panel ID function. */ | /* Switch between the bone panel ID function and the object panel ID function. */ | ||||
| uiListPanelIDFromDataFunc panel_id_func = use_bone_constraints ? bone_constraint_panel_id : | uiListPanelIDFromDataFunc panel_id_func = use_bone_constraints ? bone_constraint_panel_id : | ||||
| object_constraint_panel_id; | object_constraint_panel_id; | ||||
| const 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) { | if (!panels_match) { | ||||
| UI_panels_free_instanced(C, region); | UI_panels_free_instanced(C, region); | ||||
| bConstraint *con = (constraints == NULL) ? NULL : constraints->first; | bConstraint *con = (constraints == nullptr) ? nullptr : | ||||
| static_cast<bConstraint *>(constraints->first); | |||||
| for (int i = 0; con; i++, con = con->next) { | for (int i = 0; con; i++, con = con->next) { | ||||
| /* Don't show invalid/legacy constraints. */ | /* Don't show invalid/legacy constraints. */ | ||||
| if (con->type == CONSTRAINT_TYPE_NULL) { | if (con->type == CONSTRAINT_TYPE_NULL) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* Don't show temporary constraints (AutoIK and target-less IK constraints). */ | /* Don't show temporary constraints (AutoIK and target-less IK constraints). */ | ||||
| if (con->type == CONSTRAINT_TYPE_KINEMATIC) { | if (con->type == CONSTRAINT_TYPE_KINEMATIC) { | ||||
| bKinematicConstraint *data = con->data; | bKinematicConstraint *data = static_cast<bKinematicConstraint *>(con->data); | ||||
| if (data->flag & CONSTRAINT_IK_TEMP) { | if (data->flag & CONSTRAINT_IK_TEMP) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| char panel_idname[MAX_NAME]; | char panel_idname[MAX_NAME]; | ||||
| panel_id_func(con, panel_idname); | panel_id_func(con, panel_idname); | ||||
| /* Create custom data RNA pointer. */ | /* Create custom data RNA pointer. */ | ||||
| PointerRNA *con_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); | PointerRNA *con_ptr = static_cast<PointerRNA *>(MEM_mallocN(sizeof(PointerRNA), __func__)); | ||||
| RNA_pointer_create(&ob->id, &RNA_Constraint, con, con_ptr); | RNA_pointer_create(&ob->id, &RNA_Constraint, con, con_ptr); | ||||
| Panel *new_panel = UI_panel_add_instanced(C, region, ®ion->panels, panel_idname, con_ptr); | Panel *new_panel = UI_panel_add_instanced(C, region, ®ion->panels, panel_idname, con_ptr); | ||||
| if (new_panel) { | if (new_panel) { | ||||
| /* Set the list panel functionality function pointers since we don't do it with python. */ | /* Set the list panel functionality function pointers since we don't do it with python. */ | ||||
| new_panel->type->set_list_data_expand_flag = set_constraint_expand_flag; | new_panel->type->set_list_data_expand_flag = set_constraint_expand_flag; | ||||
| new_panel->type->get_list_data_expand_flag = get_constraint_expand_flag; | new_panel->type->get_list_data_expand_flag = get_constraint_expand_flag; | ||||
| new_panel->type->reorder = constraint_reorder; | new_panel->type->reorder = constraint_reorder; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Assuming there's only one group of instanced panels, update the custom data pointers. */ | /* Assuming there's only one group of instanced panels, update the custom data pointers. */ | ||||
| Panel *panel = region->panels.first; | Panel *panel = static_cast<Panel *>(region->panels.first); | ||||
| LISTBASE_FOREACH (bConstraint *, con, constraints) { | LISTBASE_FOREACH (bConstraint *, con, constraints) { | ||||
| /* Don't show invalid/legacy constraints. */ | /* Don't show invalid/legacy constraints. */ | ||||
| if (con->type == CONSTRAINT_TYPE_NULL) { | if (con->type == CONSTRAINT_TYPE_NULL) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* Don't show temporary constraints (AutoIK and target-less IK constraints). */ | /* Don't show temporary constraints (AutoIK and target-less IK constraints). */ | ||||
| if (con->type == CONSTRAINT_TYPE_KINEMATIC) { | if (con->type == CONSTRAINT_TYPE_KINEMATIC) { | ||||
| bKinematicConstraint *data = con->data; | bKinematicConstraint *data = static_cast<bKinematicConstraint *>(con->data); | ||||
| if (data->flag & CONSTRAINT_IK_TEMP) { | if (data->flag & CONSTRAINT_IK_TEMP) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| /* Move to the next instanced panel corresponding to the next constraint. */ | /* Move to the next instanced panel corresponding to the next constraint. */ | ||||
| while ((panel->type == NULL) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) { | while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) { | ||||
| panel = panel->next; | panel = panel->next; | ||||
| BLI_assert(panel != NULL); /* There shouldn't be fewer panels than constraint panels. */ | BLI_assert(panel != nullptr); /* There shouldn't be fewer panels than constraint panels. */ | ||||
| } | } | ||||
| PointerRNA *con_ptr = MEM_mallocN(sizeof(PointerRNA), "constraint panel customdata"); | PointerRNA *con_ptr = static_cast<PointerRNA *>(MEM_mallocN(sizeof(PointerRNA), __func__)); | ||||
| RNA_pointer_create(&ob->id, &RNA_Constraint, con, con_ptr); | RNA_pointer_create(&ob->id, &RNA_Constraint, con, con_ptr); | ||||
| UI_panel_custom_data_set(panel, con_ptr); | UI_panel_custom_data_set(panel, con_ptr); | ||||
| panel = panel->next; | panel = panel->next; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #undef CONSTRAINT_TYPE_PANEL_PREFIX | #undef CONSTRAINT_TYPE_PANEL_PREFIX | ||||
| #undef CONSTRAINT_BONE_TYPE_PANEL_PREFIX | #undef CONSTRAINT_BONE_TYPE_PANEL_PREFIX | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Grease Pencil Modifiers Template | /** \name Grease Pencil Modifiers Template | ||||
| * \{ */ | * \{ */ | ||||
| /** | /** | ||||
| * Function with void * argument for #uiListPanelIDFromDataFunc. | * Function with void * argument for #uiListPanelIDFromDataFunc. | ||||
| */ | */ | ||||
| static void gpencil_modifier_panel_id(void *md_link, char *r_name) | static void gpencil_modifier_panel_id(void *md_link, char *r_name) | ||||
| { | { | ||||
| ModifierData *md = (ModifierData *)md_link; | ModifierData *md = (ModifierData *)md_link; | ||||
| BKE_gpencil_modifierType_panel_id(md->type, r_name); | BKE_gpencil_modifierType_panel_id(GpencilModifierType(md->type), r_name); | ||||
| } | } | ||||
| void uiTemplateGpencilModifiers(uiLayout *UNUSED(layout), bContext *C) | void uiTemplateGpencilModifiers(uiLayout * /*layout*/, bContext *C) | ||||
| { | { | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| ListBase *modifiers = &ob->greasepencil_modifiers; | ListBase *modifiers = &ob->greasepencil_modifiers; | ||||
| const bool panels_match = UI_panel_list_matches_data( | const bool panels_match = UI_panel_list_matches_data( | ||||
| region, modifiers, gpencil_modifier_panel_id); | region, modifiers, gpencil_modifier_panel_id); | ||||
| if (!panels_match) { | if (!panels_match) { | ||||
| UI_panels_free_instanced(C, region); | UI_panels_free_instanced(C, region); | ||||
| GpencilModifierData *md = modifiers->first; | GpencilModifierData *md = static_cast<GpencilModifierData *>(modifiers->first); | ||||
| for (int i = 0; md; i++, md = md->next) { | for (int i = 0; md; i++, md = md->next) { | ||||
| const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type); | const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info( | ||||
| if (mti->panelRegister == NULL) { | GpencilModifierType(md->type)); | ||||
| if (mti->panelRegister == nullptr) { | |||||
| continue; | continue; | ||||
| } | } | ||||
| char panel_idname[MAX_NAME]; | char panel_idname[MAX_NAME]; | ||||
| gpencil_modifier_panel_id(md, panel_idname); | gpencil_modifier_panel_id(md, panel_idname); | ||||
| /* Create custom data RNA pointer. */ | /* Create custom data RNA pointer. */ | ||||
| PointerRNA *md_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); | PointerRNA *md_ptr = static_cast<PointerRNA *>(MEM_mallocN(sizeof(PointerRNA), __func__)); | ||||
| RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, md_ptr); | RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, md_ptr); | ||||
| UI_panel_add_instanced(C, region, ®ion->panels, panel_idname, md_ptr); | UI_panel_add_instanced(C, region, ®ion->panels, panel_idname, md_ptr); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Assuming there's only one group of instanced panels, update the custom data pointers. */ | /* Assuming there's only one group of instanced panels, update the custom data pointers. */ | ||||
| Panel *panel = region->panels.first; | Panel *panel = static_cast<Panel *>(region->panels.first); | ||||
| LISTBASE_FOREACH (ModifierData *, md, modifiers) { | LISTBASE_FOREACH (ModifierData *, md, modifiers) { | ||||
| const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type); | const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info( | ||||
| if (mti->panelRegister == NULL) { | GpencilModifierType(md->type)); | ||||
| if (mti->panelRegister == nullptr) { | |||||
| continue; | continue; | ||||
| } | } | ||||
| /* Move to the next instanced panel corresponding to the next modifier. */ | /* Move to the next instanced panel corresponding to the next modifier. */ | ||||
| while ((panel->type == NULL) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) { | while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) { | ||||
| panel = panel->next; | panel = panel->next; | ||||
| BLI_assert(panel != NULL); /* There shouldn't be fewer panels than modifiers with UIs. */ | BLI_assert(panel != | ||||
| nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */ | |||||
| } | } | ||||
| PointerRNA *md_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); | PointerRNA *md_ptr = static_cast<PointerRNA *>(MEM_mallocN(sizeof(PointerRNA), __func__)); | ||||
| RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, md_ptr); | RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, md_ptr); | ||||
| UI_panel_custom_data_set(panel, md_ptr); | UI_panel_custom_data_set(panel, md_ptr); | ||||
| panel = panel->next; | panel = panel->next; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 9 Lines | |||||
| * \{ */ | * \{ */ | ||||
| /** | /** | ||||
| * Function with void * argument for #uiListPanelIDFromDataFunc. | * Function with void * argument for #uiListPanelIDFromDataFunc. | ||||
| */ | */ | ||||
| static void shaderfx_panel_id(void *fx_v, char *r_idname) | static void shaderfx_panel_id(void *fx_v, char *r_idname) | ||||
| { | { | ||||
| ShaderFxData *fx = (ShaderFxData *)fx_v; | ShaderFxData *fx = (ShaderFxData *)fx_v; | ||||
| BKE_shaderfxType_panel_id(fx->type, r_idname); | BKE_shaderfxType_panel_id(ShaderFxType(fx->type), r_idname); | ||||
| } | } | ||||
| void uiTemplateShaderFx(uiLayout *UNUSED(layout), bContext *C) | void uiTemplateShaderFx(uiLayout * /*layout*/, bContext *C) | ||||
| { | { | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| ListBase *shaderfx = &ob->shader_fx; | ListBase *shaderfx = &ob->shader_fx; | ||||
| const 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) { | if (!panels_match) { | ||||
| UI_panels_free_instanced(C, region); | UI_panels_free_instanced(C, region); | ||||
| ShaderFxData *fx = shaderfx->first; | ShaderFxData *fx = static_cast<ShaderFxData *>(shaderfx->first); | ||||
| for (int i = 0; fx; i++, fx = fx->next) { | for (int i = 0; fx; i++, fx = fx->next) { | ||||
| char panel_idname[MAX_NAME]; | char panel_idname[MAX_NAME]; | ||||
| shaderfx_panel_id(fx, panel_idname); | shaderfx_panel_id(fx, panel_idname); | ||||
| /* Create custom data RNA pointer. */ | /* Create custom data RNA pointer. */ | ||||
| PointerRNA *fx_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); | PointerRNA *fx_ptr = static_cast<PointerRNA *>(MEM_mallocN(sizeof(PointerRNA), __func__)); | ||||
| RNA_pointer_create(&ob->id, &RNA_ShaderFx, fx, fx_ptr); | RNA_pointer_create(&ob->id, &RNA_ShaderFx, fx, fx_ptr); | ||||
| UI_panel_add_instanced(C, region, ®ion->panels, panel_idname, fx_ptr); | UI_panel_add_instanced(C, region, ®ion->panels, panel_idname, fx_ptr); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Assuming there's only one group of instanced panels, update the custom data pointers. */ | /* Assuming there's only one group of instanced panels, update the custom data pointers. */ | ||||
| Panel *panel = region->panels.first; | Panel *panel = static_cast<Panel *>(region->panels.first); | ||||
| LISTBASE_FOREACH (ShaderFxData *, fx, shaderfx) { | LISTBASE_FOREACH (ShaderFxData *, fx, shaderfx) { | ||||
| const ShaderFxTypeInfo *fxi = BKE_shaderfx_get_info(fx->type); | const ShaderFxTypeInfo *fxi = BKE_shaderfx_get_info(ShaderFxType(fx->type)); | ||||
| if (fxi->panelRegister == NULL) { | if (fxi->panelRegister == nullptr) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* Move to the next instanced panel corresponding to the next modifier. */ | /* Move to the next instanced panel corresponding to the next modifier. */ | ||||
| while ((panel->type == NULL) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) { | while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) { | ||||
| panel = panel->next; | panel = panel->next; | ||||
| BLI_assert(panel != NULL); /* There shouldn't be fewer panels than modifiers with UIs. */ | BLI_assert(panel != | ||||
| nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */ | |||||
| } | } | ||||
| PointerRNA *fx_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); | PointerRNA *fx_ptr = static_cast<PointerRNA *>(MEM_mallocN(sizeof(PointerRNA), __func__)); | ||||
| RNA_pointer_create(&ob->id, &RNA_ShaderFx, fx, fx_ptr); | RNA_pointer_create(&ob->id, &RNA_ShaderFx, fx, fx_ptr); | ||||
| UI_panel_custom_data_set(panel, fx_ptr); | UI_panel_custom_data_set(panel, fx_ptr); | ||||
| panel = panel->next; | panel = panel->next; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Operator Property Buttons Template | /** \name Operator Property Buttons Template | ||||
| * \{ */ | * \{ */ | ||||
| typedef struct uiTemplateOperatorPropertyPollParam { | struct uiTemplateOperatorPropertyPollParam { | ||||
| const bContext *C; | const bContext *C; | ||||
| wmOperator *op; | wmOperator *op; | ||||
| short flag; | short flag; | ||||
| } uiTemplateOperatorPropertyPollParam; | }; | ||||
| #ifdef USE_OP_RESET_BUT | #ifdef USE_OP_RESET_BUT | ||||
| static void ui_layout_operator_buts__reset_cb(bContext *UNUSED(C), | static void ui_layout_operator_buts__reset_cb(bContext * /*C*/, void *op_pt, void * /*arg_dummy2*/) | ||||
| void *op_pt, | |||||
| void *UNUSED(arg_dummy2)) | |||||
| { | { | ||||
| WM_operator_properties_reset((wmOperator *)op_pt); | WM_operator_properties_reset((wmOperator *)op_pt); | ||||
| } | } | ||||
| #endif | #endif | ||||
| static bool ui_layout_operator_buts_poll_property(struct PointerRNA *UNUSED(ptr), | static bool ui_layout_operator_buts_poll_property(PointerRNA * /*ptr*/, | ||||
| struct PropertyRNA *prop, | PropertyRNA *prop, | ||||
| void *user_data) | void *user_data) | ||||
| { | { | ||||
| uiTemplateOperatorPropertyPollParam *params = user_data; | uiTemplateOperatorPropertyPollParam *params = static_cast<uiTemplateOperatorPropertyPollParam *>( | ||||
| user_data); | |||||
| if ((params->flag & UI_TEMPLATE_OP_PROPS_HIDE_ADVANCED) && | if ((params->flag & UI_TEMPLATE_OP_PROPS_HIDE_ADVANCED) && | ||||
| (RNA_property_tags(prop) & OP_PROP_TAG_ADVANCED)) { | (RNA_property_tags(prop) & OP_PROP_TAG_ADVANCED)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return params->op->type->poll_property(params->C, params->op, prop); | return params->op->type->poll_property(params->C, params->op, prop); | ||||
| } | } | ||||
| static eAutoPropButsReturn template_operator_property_buts_draw_single( | static eAutoPropButsReturn template_operator_property_buts_draw_single( | ||||
| const bContext *C, | const bContext *C, | ||||
| wmOperator *op, | wmOperator *op, | ||||
| uiLayout *layout, | uiLayout *layout, | ||||
| const eButLabelAlign label_align, | const eButLabelAlign label_align, | ||||
| int layout_flags) | int layout_flags) | ||||
| { | { | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| eAutoPropButsReturn return_info = 0; | eAutoPropButsReturn return_info = eAutoPropButsReturn(0); | ||||
| if (!op->properties) { | if (!op->properties) { | ||||
| const IDPropertyTemplate val = {0}; | const IDPropertyTemplate val = {0}; | ||||
| op->properties = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); | op->properties = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); | ||||
| } | } | ||||
| /* poll() on this operator may still fail, | /* poll() on this operator may still fail, | ||||
| * at the moment there is no nice feedback when this happens just fails silently. */ | * at the moment there is no nice feedback when this happens just fails silently. */ | ||||
| Show All 14 Lines | if (op->type->flag & OPTYPE_PRESET) { | ||||
| /* XXX, no simple way to get WM_MT_operator_presets.bl_label | /* XXX, no simple way to get WM_MT_operator_presets.bl_label | ||||
| * from python! Label remains the same always! */ | * from python! Label remains the same always! */ | ||||
| PointerRNA op_ptr; | PointerRNA op_ptr; | ||||
| uiLayout *row; | uiLayout *row; | ||||
| block->ui_operator = op; | block->ui_operator = op; | ||||
| row = uiLayoutRow(layout, true); | row = uiLayoutRow(layout, true); | ||||
| uiItemM(row, "WM_MT_operator_presets", NULL, ICON_NONE); | uiItemM(row, "WM_MT_operator_presets", nullptr, ICON_NONE); | ||||
| wmOperatorType *ot = WM_operatortype_find("WM_OT_operator_preset_add", false); | wmOperatorType *ot = WM_operatortype_find("WM_OT_operator_preset_add", false); | ||||
| uiItemFullO_ptr(row, ot, "", ICON_ADD, NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); | uiItemFullO_ptr(row, ot, "", ICON_ADD, nullptr, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); | ||||
| RNA_string_set(&op_ptr, "operator", op->type->idname); | RNA_string_set(&op_ptr, "operator", op->type->idname); | ||||
| uiItemFullO_ptr(row, ot, "", ICON_REMOVE, NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); | uiItemFullO_ptr(row, ot, "", ICON_REMOVE, nullptr, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); | ||||
| RNA_string_set(&op_ptr, "operator", op->type->idname); | RNA_string_set(&op_ptr, "operator", op->type->idname); | ||||
| RNA_boolean_set(&op_ptr, "remove_active", true); | RNA_boolean_set(&op_ptr, "remove_active", true); | ||||
| } | } | ||||
| if (op->type->ui) { | if (op->type->ui) { | ||||
| op->layout = layout; | op->layout = layout; | ||||
| op->type->ui((bContext *)C, op); | op->type->ui((bContext *)C, op); | ||||
| op->layout = NULL; | op->layout = nullptr; | ||||
| /* #UI_LAYOUT_OP_SHOW_EMPTY ignored. retun_info is ignored too. | /* #UI_LAYOUT_OP_SHOW_EMPTY ignored. retun_info is ignored too. | ||||
| * We could allow #wmOperatorType.ui callback to return this, but not needed right now. */ | * We could allow #wmOperatorType.ui callback to return this, but not needed right now. */ | ||||
| } | } | ||||
| else { | else { | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| uiTemplateOperatorPropertyPollParam user_data = {.C = C, .op = op, .flag = layout_flags}; | uiTemplateOperatorPropertyPollParam user_data{}; | ||||
| user_data.C = C; | |||||
| user_data.op = op; | |||||
| user_data.flag = layout_flags; | |||||
| const bool use_prop_split = (layout_flags & UI_TEMPLATE_OP_PROPS_NO_SPLIT_LAYOUT) == 0; | const bool use_prop_split = (layout_flags & UI_TEMPLATE_OP_PROPS_NO_SPLIT_LAYOUT) == 0; | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); | RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); | ||||
| uiLayoutSetPropSep(layout, use_prop_split); | uiLayoutSetPropSep(layout, use_prop_split); | ||||
| uiLayoutSetPropDecorate(layout, false); | uiLayoutSetPropDecorate(layout, false); | ||||
| /* main draw call */ | /* main draw call */ | ||||
| return_info = uiDefAutoButsRNA( | return_info = uiDefAutoButsRNA( | ||||
| layout, | layout, | ||||
| &ptr, | &ptr, | ||||
| op->type->poll_property ? ui_layout_operator_buts_poll_property : NULL, | op->type->poll_property ? ui_layout_operator_buts_poll_property : nullptr, | ||||
| op->type->poll_property ? &user_data : NULL, | op->type->poll_property ? &user_data : nullptr, | ||||
| op->type->prop, | op->type->prop, | ||||
| label_align, | label_align, | ||||
| (layout_flags & UI_TEMPLATE_OP_PROPS_COMPACT)); | (layout_flags & UI_TEMPLATE_OP_PROPS_COMPACT)); | ||||
| if ((return_info & UI_PROP_BUTS_NONE_ADDED) && | if ((return_info & UI_PROP_BUTS_NONE_ADDED) && | ||||
| (layout_flags & UI_TEMPLATE_OP_PROPS_SHOW_EMPTY)) { | (layout_flags & UI_TEMPLATE_OP_PROPS_SHOW_EMPTY)) { | ||||
| uiItemL(layout, IFACE_("No Properties"), ICON_NONE); | uiItemL(layout, IFACE_("No Properties"), ICON_NONE); | ||||
| } | } | ||||
| Show All 13 Lines | but = uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_FILE_REFRESH, | ICON_FILE_REFRESH, | ||||
| IFACE_("Reset"), | IFACE_("Reset"), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Reset operator defaults")); | TIP_("Reset operator defaults")); | ||||
| UI_but_func_set(but, ui_layout_operator_buts__reset_cb, op, NULL); | UI_but_func_set(but, ui_layout_operator_buts__reset_cb, op, nullptr); | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* set various special settings for buttons */ | /* set various special settings for buttons */ | ||||
| /* Only do this if we're not refreshing an existing UI. */ | /* Only do this if we're not refreshing an existing UI. */ | ||||
| if (block->oldblock == NULL) { | if (block->oldblock == nullptr) { | ||||
| const bool is_popup = (block->flag & UI_BLOCK_KEEP_OPEN) != 0; | const bool is_popup = (block->flag & UI_BLOCK_KEEP_OPEN) != 0; | ||||
| LISTBASE_FOREACH (uiBut *, but, &block->buttons) { | LISTBASE_FOREACH (uiBut *, but, &block->buttons) { | ||||
| /* no undo for buttons for operator redo panels */ | /* no undo for buttons for operator redo panels */ | ||||
| UI_but_flag_disable(but, UI_BUT_UNDO); | UI_but_flag_disable(but, UI_BUT_UNDO); | ||||
| /* only for popups, see T36109. */ | /* only for popups, see T36109. */ | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | static bool ui_layout_operator_properties_only_booleans(const bContext *C, | ||||
| if (op->type->flag & OPTYPE_MACRO) { | if (op->type->flag & OPTYPE_MACRO) { | ||||
| LISTBASE_FOREACH (wmOperator *, macro_op, &op->macro) { | LISTBASE_FOREACH (wmOperator *, macro_op, &op->macro) { | ||||
| if (!ui_layout_operator_properties_only_booleans(C, wm, macro_op, layout_flags)) { | if (!ui_layout_operator_properties_only_booleans(C, wm, macro_op, layout_flags)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| uiTemplateOperatorPropertyPollParam user_data = {.C = C, .op = op, .flag = layout_flags}; | uiTemplateOperatorPropertyPollParam user_data{}; | ||||
| user_data.C = C; | |||||
| user_data.op = op; | |||||
| user_data.flag = layout_flags; | |||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); | RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); | ||||
| RNA_STRUCT_BEGIN (&ptr, prop) { | RNA_STRUCT_BEGIN (&ptr, prop) { | ||||
| if (RNA_property_flag(prop) & PROP_HIDDEN) { | if (RNA_property_flag(prop) & PROP_HIDDEN) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| Show All 17 Lines | void uiTemplateOperatorPropertyButs( | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| /* If there are only checkbox items, don't use split layout by default. It looks weird if the | /* If there are only checkbox items, don't use split layout by default. It looks weird if the | ||||
| * check-boxes only use half the width. */ | * check-boxes only use half the width. */ | ||||
| if (ui_layout_operator_properties_only_booleans(C, wm, op, flag)) { | if (ui_layout_operator_properties_only_booleans(C, wm, op, flag)) { | ||||
| flag |= UI_TEMPLATE_OP_PROPS_NO_SPLIT_LAYOUT; | flag |= UI_TEMPLATE_OP_PROPS_NO_SPLIT_LAYOUT; | ||||
| } | } | ||||
| template_operator_property_buts_draw_recursive(C, op, layout, label_align, flag, NULL); | template_operator_property_buts_draw_recursive(C, op, layout, label_align, flag, nullptr); | ||||
| } | } | ||||
| void uiTemplateOperatorRedoProperties(uiLayout *layout, const bContext *C) | void uiTemplateOperatorRedoProperties(uiLayout *layout, const bContext *C) | ||||
| { | { | ||||
| wmOperator *op = WM_operator_last_redo(C); | wmOperator *op = WM_operator_last_redo(C); | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| if (op == NULL) { | if (op == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Disable for now, doesn't fit well in popover. */ | /* Disable for now, doesn't fit well in popover. */ | ||||
| #if 0 | #if 0 | ||||
| /* Repeat button with operator name as text. */ | /* Repeat button with operator name as text. */ | ||||
| uiItemFullO(layout, | uiItemFullO(layout, | ||||
| "SCREEN_OT_repeat_last", | "SCREEN_OT_repeat_last", | ||||
| WM_operatortype_name(op->type, op->ptr), | WM_operatortype_name(op->type, op->ptr), | ||||
| ICON_NONE, | ICON_NONE, | ||||
| NULL, | nullptr, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| 0, | 0, | ||||
| NULL); | nullptr); | ||||
| #endif | #endif | ||||
| if (WM_operator_repeat_check(C, op)) { | if (WM_operator_repeat_check(C, op)) { | ||||
| int layout_flags = 0; | int layout_flags = 0; | ||||
| if (block->panel == NULL) { | if (block->panel == nullptr) { | ||||
| layout_flags = UI_TEMPLATE_OP_PROPS_SHOW_TITLE; | layout_flags = UI_TEMPLATE_OP_PROPS_SHOW_TITLE; | ||||
| } | } | ||||
| #if 0 | #if 0 | ||||
| bool has_advanced = false; | bool has_advanced = false; | ||||
| #endif | #endif | ||||
| UI_block_func_handle_set(block, ED_undo_operator_repeat_cb_evt, op); | UI_block_func_handle_set(block, ED_undo_operator_repeat_cb_evt, op); | ||||
| template_operator_property_buts_draw_recursive( | template_operator_property_buts_draw_recursive( | ||||
| C, op, layout, UI_BUT_LABEL_ALIGN_NONE, layout_flags, NULL /* &has_advanced */); | C, op, layout, UI_BUT_LABEL_ALIGN_NONE, layout_flags, nullptr /* &has_advanced */); | ||||
| /* Warning! this leaves the handle function for any other users of this block. */ | /* Warning! this leaves the handle function for any other users of this block. */ | ||||
| #if 0 | #if 0 | ||||
| if (has_advanced) { | if (has_advanced) { | ||||
| uiItemO(layout, IFACE_("More..."), ICON_NONE, "SCREEN_OT_redo_last"); | uiItemO(layout, IFACE_("More..."), ICON_NONE, "SCREEN_OT_redo_last"); | ||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Constraint Header Template | /** \name Constraint Header Template | ||||
| * \{ */ | * \{ */ | ||||
| #define ERROR_LIBDATA_MESSAGE TIP_("Can't edit external library data") | #define ERROR_LIBDATA_MESSAGE TIP_("Can't edit external library data") | ||||
| static void constraint_active_func(bContext *UNUSED(C), void *ob_v, void *con_v) | static void constraint_active_func(bContext * /*C*/, void *ob_v, void *con_v) | ||||
| { | { | ||||
| ED_object_constraint_active_set(ob_v, con_v); | ED_object_constraint_active_set(static_cast<Object *>(ob_v), static_cast<bConstraint *>(con_v)); | ||||
| } | } | ||||
| static void constraint_ops_extra_draw(bContext *C, uiLayout *layout, void *con_v) | static void constraint_ops_extra_draw(bContext *C, uiLayout *layout, void *con_v) | ||||
| { | { | ||||
| PointerRNA op_ptr; | PointerRNA op_ptr; | ||||
| uiLayout *row; | uiLayout *row; | ||||
| bConstraint *con = (bConstraint *)con_v; | bConstraint *con = (bConstraint *)con_v; | ||||
| Show All 26 Lines | static void constraint_ops_extra_draw(bContext *C, uiLayout *layout, void *con_v) | ||||
| uiItemS(layout); | uiItemS(layout); | ||||
| /* Move to first. */ | /* Move to first. */ | ||||
| row = uiLayoutColumn(layout, false); | row = uiLayoutColumn(layout, false); | ||||
| uiItemFullO(row, | uiItemFullO(row, | ||||
| "CONSTRAINT_OT_move_to_index", | "CONSTRAINT_OT_move_to_index", | ||||
| IFACE_("Move to First"), | IFACE_("Move to First"), | ||||
| ICON_TRIA_UP, | ICON_TRIA_UP, | ||||
| NULL, | nullptr, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| 0, | 0, | ||||
| &op_ptr); | &op_ptr); | ||||
| RNA_int_set(&op_ptr, "index", 0); | RNA_int_set(&op_ptr, "index", 0); | ||||
| if (!con->prev) { | if (!con->prev) { | ||||
| uiLayoutSetEnabled(row, false); | uiLayoutSetEnabled(row, false); | ||||
| } | } | ||||
| /* Move to last. */ | /* Move to last. */ | ||||
| row = uiLayoutColumn(layout, false); | row = uiLayoutColumn(layout, false); | ||||
| uiItemFullO(row, | uiItemFullO(row, | ||||
| "CONSTRAINT_OT_move_to_index", | "CONSTRAINT_OT_move_to_index", | ||||
| IFACE_("Move to Last"), | IFACE_("Move to Last"), | ||||
| ICON_TRIA_DOWN, | ICON_TRIA_DOWN, | ||||
| NULL, | nullptr, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| 0, | 0, | ||||
| &op_ptr); | &op_ptr); | ||||
| ListBase *constraint_list = ED_object_constraint_list_from_constraint(ob, con, NULL); | ListBase *constraint_list = ED_object_constraint_list_from_constraint(ob, con, nullptr); | ||||
| RNA_int_set(&op_ptr, "index", BLI_listbase_count(constraint_list) - 1); | RNA_int_set(&op_ptr, "index", BLI_listbase_count(constraint_list) - 1); | ||||
| if (!con->next) { | if (!con->next) { | ||||
| uiLayoutSetEnabled(row, false); | uiLayoutSetEnabled(row, false); | ||||
| } | } | ||||
| } | } | ||||
| static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *con) | static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *con) | ||||
| { | { | ||||
| /* unless button has own callback, it adds this callback to button */ | /* unless button has own callback, it adds this callback to button */ | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| UI_block_func_set(block, constraint_active_func, ob, con); | UI_block_func_set(block, constraint_active_func, ob, con); | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| RNA_pointer_create(&ob->id, &RNA_Constraint, con, &ptr); | RNA_pointer_create(&ob->id, &RNA_Constraint, con, &ptr); | ||||
| if (block->panel) { | if (block->panel) { | ||||
| UI_panel_context_pointer_set(block->panel, "constraint", &ptr); | UI_panel_context_pointer_set(block->panel, "constraint", &ptr); | ||||
| } | } | ||||
| else { | else { | ||||
| uiLayoutSetContextPointer(layout, "constraint", &ptr); | uiLayoutSetContextPointer(layout, "constraint", &ptr); | ||||
| } | } | ||||
| /* Constraint type icon. */ | /* Constraint type icon. */ | ||||
| uiLayout *sub = uiLayoutRow(layout, false); | uiLayout *sub = uiLayoutRow(layout, false); | ||||
| uiLayoutSetEmboss(sub, false); | uiLayoutSetEmboss(sub, UI_EMBOSS); | ||||
| uiLayoutSetRedAlert(sub, (con->flag & CONSTRAINT_DISABLE)); | uiLayoutSetRedAlert(sub, (con->flag & CONSTRAINT_DISABLE)); | ||||
| uiItemL(sub, "", RNA_struct_ui_icon(ptr.type)); | uiItemL(sub, "", RNA_struct_ui_icon(ptr.type)); | ||||
| UI_block_emboss_set(block, UI_EMBOSS); | UI_block_emboss_set(block, UI_EMBOSS); | ||||
| uiLayout *row = uiLayoutRow(layout, true); | uiLayout *row = uiLayoutRow(layout, true); | ||||
| uiItemR(row, &ptr, "name", 0, "", ICON_NONE); | uiItemR(row, &ptr, "name", 0, "", ICON_NONE); | ||||
| Show All 21 Lines | |||||
| { | { | ||||
| /* verify we have valid data */ | /* verify we have valid data */ | ||||
| if (!RNA_struct_is_a(ptr->type, &RNA_Constraint)) { | if (!RNA_struct_is_a(ptr->type, &RNA_Constraint)) { | ||||
| RNA_warning("Expected constraint on object"); | RNA_warning("Expected constraint on object"); | ||||
| return; | return; | ||||
| } | } | ||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| bConstraint *con = ptr->data; | bConstraint *con = static_cast<bConstraint *>(ptr->data); | ||||
| if (!ob || !(GS(ob->id.name) == ID_OB)) { | if (!ob || !(GS(ob->id.name) == ID_OB)) { | ||||
| RNA_warning("Expected constraint on object"); | RNA_warning("Expected constraint on object"); | ||||
| return; | return; | ||||
| } | } | ||||
| UI_block_lock_set(uiLayoutGetBlock(layout), (ob && ID_IS_LINKED(ob)), ERROR_LIBDATA_MESSAGE); | UI_block_lock_set(uiLayoutGetBlock(layout), (ob && ID_IS_LINKED(ob)), ERROR_LIBDATA_MESSAGE); | ||||
| Show All 24 Lines | |||||
| void uiTemplatePreview(uiLayout *layout, | void uiTemplatePreview(uiLayout *layout, | ||||
| bContext *C, | bContext *C, | ||||
| ID *id, | ID *id, | ||||
| bool show_buttons, | bool show_buttons, | ||||
| ID *parent, | ID *parent, | ||||
| MTex *slot, | MTex *slot, | ||||
| const char *preview_id) | const char *preview_id) | ||||
| { | { | ||||
| Material *ma = NULL; | Material *ma = nullptr; | ||||
| Tex *tex = (Tex *)id; | Tex *tex = (Tex *)id; | ||||
| short *pr_texture = NULL; | short *pr_texture = nullptr; | ||||
| PointerRNA material_ptr; | PointerRNA material_ptr; | ||||
| PointerRNA texture_ptr; | PointerRNA texture_ptr; | ||||
| char _preview_id[UI_MAX_NAME_STR]; | char _preview_id[UI_MAX_NAME_STR]; | ||||
| if (id && !ELEM(GS(id->name), ID_MA, ID_TE, ID_WO, ID_LA, ID_LS)) { | if (id && !ELEM(GS(id->name), ID_MA, ID_TE, ID_WO, ID_LA, ID_LS)) { | ||||
| RNA_warning("Expected ID of type material, texture, light, world or line style"); | RNA_warning("Expected ID of type material, texture, light, world or line style"); | ||||
| return; | return; | ||||
| } | } | ||||
| /* decide what to render */ | /* decide what to render */ | ||||
| ID *pid = id; | ID *pid = id; | ||||
| ID *pparent = NULL; | ID *pparent = nullptr; | ||||
| if (id && (GS(id->name) == ID_TE)) { | if (id && (GS(id->name) == ID_TE)) { | ||||
| if (parent && (GS(parent->name) == ID_MA)) { | if (parent && (GS(parent->name) == ID_MA)) { | ||||
| pr_texture = &((Material *)parent)->pr_texture; | pr_texture = &((Material *)parent)->pr_texture; | ||||
| } | } | ||||
| else if (parent && (GS(parent->name) == ID_WO)) { | else if (parent && (GS(parent->name) == ID_WO)) { | ||||
| pr_texture = &((World *)parent)->pr_texture; | pr_texture = &((World *)parent)->pr_texture; | ||||
| } | } | ||||
| Show All 18 Lines | if (!preview_id || (preview_id[0] == '\0')) { | ||||
| /* If no identifier given, generate one from ID type. */ | /* If no identifier given, generate one from ID type. */ | ||||
| BLI_snprintf( | BLI_snprintf( | ||||
| _preview_id, UI_MAX_NAME_STR, "uiPreview_%s", BKE_idtype_idcode_to_name(GS(id->name))); | _preview_id, UI_MAX_NAME_STR, "uiPreview_%s", BKE_idtype_idcode_to_name(GS(id->name))); | ||||
| preview_id = _preview_id; | preview_id = _preview_id; | ||||
| } | } | ||||
| /* Find or add the uiPreview to the current Region. */ | /* Find or add the uiPreview to the current Region. */ | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| uiPreview *ui_preview = BLI_findstring( | uiPreview *ui_preview = static_cast<uiPreview *>( | ||||
| ®ion->ui_previews, preview_id, offsetof(uiPreview, preview_id)); | BLI_findstring(®ion->ui_previews, preview_id, offsetof(uiPreview, preview_id))); | ||||
| if (!ui_preview) { | if (!ui_preview) { | ||||
| ui_preview = MEM_callocN(sizeof(uiPreview), "uiPreview"); | ui_preview = MEM_cnew<uiPreview>(__func__); | ||||
| BLI_strncpy(ui_preview->preview_id, preview_id, sizeof(ui_preview->preview_id)); | BLI_strncpy(ui_preview->preview_id, preview_id, sizeof(ui_preview->preview_id)); | ||||
| ui_preview->height = (short)(UI_UNIT_Y * 7.6f); | ui_preview->height = (short)(UI_UNIT_Y * 7.6f); | ||||
| BLI_addtail(®ion->ui_previews, ui_preview); | BLI_addtail(®ion->ui_previews, ui_preview); | ||||
| } | } | ||||
| if (ui_preview->height < UI_UNIT_Y) { | if (ui_preview->height < UI_UNIT_Y) { | ||||
| ui_preview->height = UI_UNIT_Y; | ui_preview->height = UI_UNIT_Y; | ||||
| } | } | ||||
| Show All 18 Lines | uiDefBut(block, | ||||
| ui_preview->height, | ui_preview->height, | ||||
| pid, | pid, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| UI_but_func_drawextra_set(block, ED_preview_draw, pparent, slot); | UI_but_func_drawextra_set(block, ED_preview_draw, pparent, slot); | ||||
| UI_block_func_handle_set(block, do_preview_buttons, NULL); | UI_block_func_handle_set(block, do_preview_buttons, nullptr); | ||||
| uiDefIconButS(block, | uiDefIconButS(block, | ||||
| UI_BTYPE_GRIP, | UI_BTYPE_GRIP, | ||||
| 0, | 0, | ||||
| ICON_GRIP, | ICON_GRIP, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X * 10, | UI_UNIT_X * 10, | ||||
| ▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | if (pr_texture) { | ||||
| TEX_PR_BOTH, | TEX_PR_BOTH, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| /* Alpha button for texture preview */ | /* Alpha button for texture preview */ | ||||
| if (*pr_texture != TEX_PR_OTHER) { | if (*pr_texture != TEX_PR_OTHER) { | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiItemR(row, &texture_ptr, "use_preview_alpha", 0, NULL, ICON_NONE); | uiItemR(row, &texture_ptr, "use_preview_alpha", 0, nullptr, ICON_NONE); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name ColorRamp Template | /** \name ColorRamp Template | ||||
| * \{ */ | * \{ */ | ||||
| typedef struct RNAUpdateCb { | struct RNAUpdateCb { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| } RNAUpdateCb; | }; | ||||
| static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg)) | static void rna_update_cb(bContext *C, void *arg_cb, void * /*arg*/) | ||||
| { | { | ||||
| RNAUpdateCb *cb = (RNAUpdateCb *)arg_cb; | RNAUpdateCb *cb = (RNAUpdateCb *)arg_cb; | ||||
| /* we call update here on the pointer property, this way the | /* we call update here on the pointer property, this way the | ||||
| * owner of the curve mapping can still define its own update | * owner of the curve mapping can still define its own update | ||||
| * and notifier, even if the CurveMapping struct is shared. */ | * and notifier, even if the CurveMapping struct is shared. */ | ||||
| RNA_property_update(C, &cb->ptr, cb->prop); | RNA_property_update(C, &cb->ptr, cb->prop); | ||||
| } | } | ||||
| Show All 34 Lines | for (int a = 0; a < coba->tot; a++) { | ||||
| pos += gap; | pos += gap; | ||||
| } | } | ||||
| ED_undo_push(C, evenly ? "Distribute Stops Evenly" : "Distribute Stops from Left"); | ED_undo_push(C, evenly ? "Distribute Stops Evenly" : "Distribute Stops from Left"); | ||||
| } | } | ||||
| } | } | ||||
| static void colorband_tools_dofunc(bContext *C, void *coba_v, int event) | static void colorband_tools_dofunc(bContext *C, void *coba_v, int event) | ||||
| { | { | ||||
| ColorBand *coba = coba_v; | ColorBand *coba = static_cast<ColorBand *>(coba_v); | ||||
| switch (event) { | switch (event) { | ||||
| case CB_FUNC_FLIP: | case CB_FUNC_FLIP: | ||||
| colorband_flip_cb(C, coba); | colorband_flip_cb(C, coba); | ||||
| break; | break; | ||||
| case CB_FUNC_DISTRIBUTE_LR: | case CB_FUNC_DISTRIBUTE_LR: | ||||
| colorband_distribute_cb(C, coba, false); | colorband_distribute_cb(C, coba, false); | ||||
| break; | break; | ||||
| case CB_FUNC_DISTRIBUTE_EVENLY: | case CB_FUNC_DISTRIBUTE_EVENLY: | ||||
| colorband_distribute_cb(C, coba, true); | colorband_distribute_cb(C, coba, true); | ||||
| break; | break; | ||||
| case CB_FUNC_RESET: | case CB_FUNC_RESET: | ||||
| BKE_colorband_init(coba, true); | BKE_colorband_init(coba, true); | ||||
| ED_undo_push(C, "Reset Color Ramp"); | ED_undo_push(C, "Reset Color Ramp"); | ||||
| break; | break; | ||||
| } | } | ||||
| ED_region_tag_redraw(CTX_wm_region(C)); | ED_region_tag_redraw(CTX_wm_region(C)); | ||||
| } | } | ||||
| static uiBlock *colorband_tools_func(bContext *C, ARegion *region, void *coba_v) | static uiBlock *colorband_tools_func(bContext *C, ARegion *region, void *coba_v) | ||||
| { | { | ||||
| const uiStyle *style = UI_style_get_dpi(); | const uiStyle *style = UI_style_get_dpi(); | ||||
| ColorBand *coba = coba_v; | ColorBand *coba = static_cast<ColorBand *>(coba_v); | ||||
| short yco = 0; | short yco = 0; | ||||
| const short menuwidth = 10 * UI_UNIT_X; | const short menuwidth = 10 * UI_UNIT_X; | ||||
| uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS_PULLDOWN); | uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS_PULLDOWN); | ||||
| UI_block_func_butmenu_set(block, colorband_tools_dofunc, coba); | UI_block_func_butmenu_set(block, colorband_tools_dofunc, coba); | ||||
| uiLayout *layout = UI_block_layout(block, | uiLayout *layout = UI_block_layout(block, | ||||
| UI_LAYOUT_VERTICAL, | UI_LAYOUT_VERTICAL, | ||||
| UI_LAYOUT_MENU, | UI_LAYOUT_MENU, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_MENU_WIDTH_MIN, | UI_MENU_WIDTH_MIN, | ||||
| 0, | 0, | ||||
| UI_MENU_PADDING, | UI_MENU_PADDING, | ||||
| style); | style); | ||||
| UI_block_layout_set_current(block, layout); | UI_block_layout_set_current(block, layout); | ||||
| { | { | ||||
| PointerRNA coba_ptr; | PointerRNA coba_ptr; | ||||
| RNA_pointer_create(NULL, &RNA_ColorRamp, coba, &coba_ptr); | RNA_pointer_create(nullptr, &RNA_ColorRamp, coba, &coba_ptr); | ||||
| uiLayoutSetContextPointer(layout, "color_ramp", &coba_ptr); | uiLayoutSetContextPointer(layout, "color_ramp", &coba_ptr); | ||||
| } | } | ||||
| /* We could move these to operators, | /* We could move these to operators, | ||||
| * although this isn't important unless we want to assign key shortcuts to them. */ | * although this isn't important unless we want to assign key shortcuts to them. */ | ||||
| { | { | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Flip Color Ramp"), | IFACE_("Flip Color Ramp"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| menuwidth, | menuwidth, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| CB_FUNC_FLIP, | CB_FUNC_FLIP, | ||||
| ""); | ""); | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Distribute Stops from Left"), | IFACE_("Distribute Stops from Left"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| menuwidth, | menuwidth, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| CB_FUNC_DISTRIBUTE_LR, | CB_FUNC_DISTRIBUTE_LR, | ||||
| ""); | ""); | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Distribute Stops Evenly"), | IFACE_("Distribute Stops Evenly"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| menuwidth, | menuwidth, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| CB_FUNC_DISTRIBUTE_EVENLY, | CB_FUNC_DISTRIBUTE_EVENLY, | ||||
| ""); | ""); | ||||
| uiItemO(layout, IFACE_("Eyedropper"), ICON_EYEDROPPER, "UI_OT_eyedropper_colorramp"); | uiItemO(layout, IFACE_("Eyedropper"), ICON_EYEDROPPER, "UI_OT_eyedropper_colorramp"); | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Reset Color Ramp"), | IFACE_("Reset Color Ramp"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| menuwidth, | menuwidth, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| CB_FUNC_RESET, | CB_FUNC_RESET, | ||||
| ""); | ""); | ||||
| } | } | ||||
| UI_block_direction_set(block, UI_DIR_DOWN); | UI_block_direction_set(block, UI_DIR_DOWN); | ||||
| UI_block_bounds_set_text(block, 3.0f * UI_UNIT_X); | UI_block_bounds_set_text(block, 3.0f * UI_UNIT_X); | ||||
| return block; | return block; | ||||
| } | } | ||||
| static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v) | static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v) | ||||
| { | { | ||||
| ColorBand *coba = coba_v; | ColorBand *coba = static_cast<ColorBand *>(coba_v); | ||||
| float pos = 0.5f; | float pos = 0.5f; | ||||
| if (coba->tot > 1) { | if (coba->tot > 1) { | ||||
| if (coba->cur > 0) { | if (coba->cur > 0) { | ||||
| pos = (coba->data[coba->cur - 1].pos + coba->data[coba->cur].pos) * 0.5f; | pos = (coba->data[coba->cur - 1].pos + coba->data[coba->cur].pos) * 0.5f; | ||||
| } | } | ||||
| else { | else { | ||||
| pos = (coba->data[coba->cur + 1].pos + coba->data[coba->cur].pos) * 0.5f; | pos = (coba->data[coba->cur + 1].pos + coba->data[coba->cur].pos) * 0.5f; | ||||
| } | } | ||||
| } | } | ||||
| if (BKE_colorband_element_add(coba, pos)) { | if (BKE_colorband_element_add(coba, pos)) { | ||||
| rna_update_cb(C, cb_v, NULL); | rna_update_cb(C, cb_v, nullptr); | ||||
| ED_undo_push(C, "Add Color Ramp Stop"); | ED_undo_push(C, "Add Color Ramp Stop"); | ||||
| } | } | ||||
| } | } | ||||
| static void colorband_del_cb(bContext *C, void *cb_v, void *coba_v) | static void colorband_del_cb(bContext *C, void *cb_v, void *coba_v) | ||||
| { | { | ||||
| ColorBand *coba = coba_v; | ColorBand *coba = static_cast<ColorBand *>(coba_v); | ||||
| if (BKE_colorband_element_remove(coba, coba->cur)) { | if (BKE_colorband_element_remove(coba, coba->cur)) { | ||||
| ED_undo_push(C, "Delete Color Ramp Stop"); | ED_undo_push(C, "Delete Color Ramp Stop"); | ||||
| rna_update_cb(C, cb_v, NULL); | rna_update_cb(C, cb_v, nullptr); | ||||
| } | } | ||||
| } | } | ||||
| static void colorband_update_cb(bContext *UNUSED(C), void *bt_v, void *coba_v) | static void colorband_update_cb(bContext * /*C*/, void *bt_v, void *coba_v) | ||||
| { | { | ||||
| uiBut *bt = bt_v; | uiBut *bt = static_cast<uiBut *>(bt_v); | ||||
| ColorBand *coba = coba_v; | ColorBand *coba = static_cast<ColorBand *>(coba_v); | ||||
| /* Sneaky update here, we need to sort the color-band points to be in order, | /* Sneaky update here, we need to sort the color-band points to be in order, | ||||
| * however the RNA pointer then is wrong, so we update it */ | * however the RNA pointer then is wrong, so we update it */ | ||||
| BKE_colorband_update_sort(coba); | BKE_colorband_update_sort(coba); | ||||
| bt->rnapoin.data = coba->data + coba->cur; | bt->rnapoin.data = coba->data + coba->cur; | ||||
| } | } | ||||
| static void colorband_buttons_layout(uiLayout *layout, | static void colorband_buttons_layout(uiLayout *layout, | ||||
| Show All 21 Lines | bt = uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_ADD, | ICON_ADD, | ||||
| "", | "", | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 2.0f * unit, | 2.0f * unit, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Add a new color stop to the color ramp")); | TIP_("Add a new color stop to the color ramp")); | ||||
| UI_but_funcN_set(bt, colorband_add_cb, MEM_dupallocN(cb), coba); | UI_but_funcN_set(bt, colorband_add_cb, MEM_dupallocN(cb), coba); | ||||
| bt = uiDefIconTextBut(block, | bt = uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_REMOVE, | ICON_REMOVE, | ||||
| "", | "", | ||||
| xs + 2.0f * unit, | xs + 2.0f * unit, | ||||
| ys + UI_UNIT_Y, | ys + UI_UNIT_Y, | ||||
| 2.0f * unit, | 2.0f * unit, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Delete the active position")); | TIP_("Delete the active position")); | ||||
| UI_but_funcN_set(bt, colorband_del_cb, MEM_dupallocN(cb), coba); | UI_but_funcN_set(bt, colorband_del_cb, MEM_dupallocN(cb), coba); | ||||
| bt = uiDefIconBlockBut(block, | bt = uiDefIconBlockBut(block, | ||||
| Show All 34 Lines | bt = uiDefBut(block, | ||||
| BLI_rctf_size_x(butr), | BLI_rctf_size_x(butr), | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| coba, | coba, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL); | UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), nullptr); | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| if (coba->tot) { | if (coba->tot) { | ||||
| CBData *cbd = coba->data + coba->cur; | CBData *cbd = coba->data + coba->cur; | ||||
| RNA_pointer_create(cb->ptr.owner_id, &RNA_ColorRampElement, cbd, &ptr); | RNA_pointer_create(cb->ptr.owner_id, &RNA_ColorRampElement, cbd, &ptr); | ||||
| if (!expand) { | if (!expand) { | ||||
| split = uiLayoutSplit(layout, 0.3f, false); | split = uiLayoutSplit(layout, 0.3f, false); | ||||
| row = uiLayoutRow(split, false); | row = uiLayoutRow(split, false); | ||||
| bt = uiDefButS(block, | bt = uiDefButS(block, | ||||
| UI_BTYPE_NUM, | UI_BTYPE_NUM, | ||||
| 0, | 0, | ||||
| "", | "", | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 5.0f * UI_UNIT_X, | 5.0f * UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| &coba->cur, | &coba->cur, | ||||
| 0.0, | 0.0, | ||||
| (float)MAX2(0, coba->tot - 1), | float(MAX2(0, coba->tot - 1)), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Choose active color stop")); | TIP_("Choose active color stop")); | ||||
| UI_but_number_step_size_set(bt, 1); | UI_but_number_step_size_set(bt, 1); | ||||
| row = uiLayoutRow(split, false); | row = uiLayoutRow(split, false); | ||||
| uiItemR(row, &ptr, "position", 0, IFACE_("Pos"), ICON_NONE); | uiItemR(row, &ptr, "position", 0, IFACE_("Pos"), ICON_NONE); | ||||
| Show All 10 Lines | else { | ||||
| 0, | 0, | ||||
| "", | "", | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 5.0f * UI_UNIT_X, | 5.0f * UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| &coba->cur, | &coba->cur, | ||||
| 0.0, | 0.0, | ||||
| (float)MAX2(0, coba->tot - 1), | float(MAX2(0, coba->tot - 1)), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Choose active color stop")); | TIP_("Choose active color stop")); | ||||
| UI_but_number_step_size_set(bt, 1); | UI_but_number_step_size_set(bt, 1); | ||||
| row = uiLayoutRow(subsplit, false); | row = uiLayoutRow(subsplit, false); | ||||
| uiItemR(row, &ptr, "position", UI_ITEM_R_SLIDER, IFACE_("Pos"), ICON_NONE); | uiItemR(row, &ptr, "position", UI_ITEM_R_SLIDER, IFACE_("Pos"), ICON_NONE); | ||||
| Show All 11 Lines | LISTBASE_FOREACH_BACKWARD (uiBut *, but, &block->buttons) { | ||||
| } | } | ||||
| const char *prop_identifier = RNA_property_identifier(but->rnaprop); | const char *prop_identifier = RNA_property_identifier(but->rnaprop); | ||||
| if (STREQ(prop_identifier, "position")) { | if (STREQ(prop_identifier, "position")) { | ||||
| UI_but_func_set(but, colorband_update_cb, but, coba); | UI_but_func_set(but, colorband_update_cb, but, coba); | ||||
| } | } | ||||
| if (STREQ(prop_identifier, "color")) { | if (STREQ(prop_identifier, "color")) { | ||||
| UI_but_funcN_set(but, rna_update_cb, MEM_dupallocN(cb), NULL); | UI_but_funcN_set(but, rna_update_cb, MEM_dupallocN(cb), nullptr); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname, bool expand) | void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname, bool expand) | ||||
| { | { | ||||
| PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | ||||
| if (!prop || RNA_property_type(prop) != PROP_POINTER) { | if (!prop || RNA_property_type(prop) != PROP_POINTER) { | ||||
| return; | return; | ||||
| } | } | ||||
| const PointerRNA cptr = RNA_property_pointer_get(ptr, prop); | const PointerRNA cptr = RNA_property_pointer_get(ptr, prop); | ||||
| if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_ColorRamp)) { | if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_ColorRamp)) { | ||||
| return; | return; | ||||
| } | } | ||||
| RNAUpdateCb *cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb"); | RNAUpdateCb *cb = MEM_cnew<RNAUpdateCb>("RNAUpdateCb"); | ||||
| cb->ptr = *ptr; | cb->ptr = *ptr; | ||||
| cb->prop = prop; | cb->prop = prop; | ||||
| rctf rect; | rctf rect; | ||||
| rect.xmin = 0; | rect.xmin = 0; | ||||
| rect.xmax = 10.0f * UI_UNIT_X; | rect.xmax = 10.0f * UI_UNIT_X; | ||||
| rect.ymin = 0; | rect.ymin = 0; | ||||
| rect.ymax = 19.5f * UI_UNIT_X; | rect.ymax = 19.5f * UI_UNIT_X; | ||||
| uiBlock *block = uiLayoutAbsoluteBlock(layout); | uiBlock *block = uiLayoutAbsoluteBlock(layout); | ||||
| ID *id = cptr.owner_id; | ID *id = cptr.owner_id; | ||||
| UI_block_lock_set(block, (id && ID_IS_LINKED(id)), ERROR_LIBDATA_MESSAGE); | UI_block_lock_set(block, (id && ID_IS_LINKED(id)), ERROR_LIBDATA_MESSAGE); | ||||
| colorband_buttons_layout(layout, block, cptr.data, &rect, cb, expand); | colorband_buttons_layout(layout, block, static_cast<ColorBand *>(cptr.data), &rect, cb, expand); | ||||
| UI_block_lock_clear(block); | UI_block_lock_clear(block); | ||||
| MEM_freeN(cb); | MEM_freeN(cb); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Icon Template | /** \name Icon Template | ||||
| * \{ */ | * \{ */ | ||||
| void uiTemplateIcon(uiLayout *layout, int icon_value, float icon_scale) | void uiTemplateIcon(uiLayout *layout, int icon_value, float icon_scale) | ||||
| { | { | ||||
| uiBlock *block = uiLayoutAbsoluteBlock(layout); | uiBlock *block = uiLayoutAbsoluteBlock(layout); | ||||
| uiBut *but = uiDefIconBut(block, | uiBut *but = uiDefIconBut(block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| ICON_X, | ICON_X, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X * icon_scale, | UI_UNIT_X * icon_scale, | ||||
| UI_UNIT_Y * icon_scale, | UI_UNIT_Y * icon_scale, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| ""); | ""); | ||||
| ui_def_but_icon(but, icon_value, UI_HAS_ICON | UI_BUT_ICON_PREVIEW); | ui_def_but_icon(but, icon_value, UI_HAS_ICON | UI_BUT_ICON_PREVIEW); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Icon viewer Template | /** \name Icon viewer Template | ||||
| * \{ */ | * \{ */ | ||||
| typedef struct IconViewMenuArgs { | struct IconViewMenuArgs { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| bool show_labels; | bool show_labels; | ||||
| float icon_scale; | float icon_scale; | ||||
| } IconViewMenuArgs; | }; | ||||
| /* ID Search browse menu, open */ | /* ID Search browse menu, open */ | ||||
| static uiBlock *ui_icon_view_menu_cb(bContext *C, ARegion *region, void *arg_litem) | static uiBlock *ui_icon_view_menu_cb(bContext *C, ARegion *region, void *arg_litem) | ||||
| { | { | ||||
| static IconViewMenuArgs args; | static IconViewMenuArgs args; | ||||
| /* arg_litem is malloced, can be freed by parent button */ | /* arg_litem is malloced, can be freed by parent button */ | ||||
| args = *((IconViewMenuArgs *)arg_litem); | args = *((IconViewMenuArgs *)arg_litem); | ||||
| const int w = UI_UNIT_X * (args.icon_scale); | const int w = UI_UNIT_X * (args.icon_scale); | ||||
| const int h = UI_UNIT_X * (args.icon_scale + args.show_labels); | const int h = UI_UNIT_X * (args.icon_scale + args.show_labels); | ||||
| uiBlock *block = UI_block_begin(C, region, "_popup", UI_EMBOSS_PULLDOWN); | uiBlock *block = UI_block_begin(C, region, "_popup", UI_EMBOSS_PULLDOWN); | ||||
| UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_NO_FLIP); | UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_NO_FLIP); | ||||
| UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | ||||
| bool free; | bool free; | ||||
| const EnumPropertyItem *item; | const EnumPropertyItem *item; | ||||
| RNA_property_enum_items(C, &args.ptr, args.prop, &item, NULL, &free); | RNA_property_enum_items(C, &args.ptr, args.prop, &item, nullptr, &free); | ||||
| for (int a = 0; item[a].identifier; a++) { | for (int a = 0; item[a].identifier; a++) { | ||||
| const int x = (a % 8) * w; | const int x = (a % 8) * w; | ||||
| const int y = -(a / 8) * h; | const int y = -(a / 8) * h; | ||||
| const int icon = item[a].icon; | const int icon = item[a].icon; | ||||
| const int value = item[a].value; | const int value = item[a].value; | ||||
| uiBut *but; | uiBut *but; | ||||
| Show All 9 Lines | if (args.show_labels) { | ||||
| h, | h, | ||||
| &args.ptr, | &args.ptr, | ||||
| args.prop, | args.prop, | ||||
| -1, | -1, | ||||
| 0, | 0, | ||||
| value, | value, | ||||
| -1, | -1, | ||||
| -1, | -1, | ||||
| NULL); | nullptr); | ||||
| } | } | ||||
| else { | else { | ||||
| but = uiDefIconButR_prop(block, | but = uiDefIconButR_prop(block, | ||||
| UI_BTYPE_ROW, | UI_BTYPE_ROW, | ||||
| 0, | 0, | ||||
| icon, | icon, | ||||
| x, | x, | ||||
| y, | y, | ||||
| w, | w, | ||||
| h, | h, | ||||
| &args.ptr, | &args.ptr, | ||||
| args.prop, | args.prop, | ||||
| -1, | -1, | ||||
| 0, | 0, | ||||
| value, | value, | ||||
| -1, | -1, | ||||
| -1, | -1, | ||||
| NULL); | nullptr); | ||||
| } | } | ||||
| ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW); | ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW); | ||||
| } | } | ||||
| UI_block_bounds_set_normal(block, 0.3f * U.widget_unit); | UI_block_bounds_set_normal(block, 0.3f * U.widget_unit); | ||||
| UI_block_direction_set(block, UI_DIR_DOWN); | UI_block_direction_set(block, UI_DIR_DOWN); | ||||
| if (free) { | if (free) { | ||||
| Show All 18 Lines | if (!prop || RNA_property_type(prop) != PROP_ENUM) { | ||||
| return; | return; | ||||
| } | } | ||||
| uiBlock *block = uiLayoutAbsoluteBlock(layout); | uiBlock *block = uiLayoutAbsoluteBlock(layout); | ||||
| int tot_items; | int tot_items; | ||||
| bool free_items; | bool free_items; | ||||
| const EnumPropertyItem *items; | const EnumPropertyItem *items; | ||||
| RNA_property_enum_items(block->evil_C, ptr, prop, &items, &tot_items, &free_items); | RNA_property_enum_items( | ||||
| static_cast<bContext *>(block->evil_C), ptr, prop, &items, &tot_items, &free_items); | |||||
| const int value = RNA_property_enum_get(ptr, prop); | const int value = RNA_property_enum_get(ptr, prop); | ||||
| int icon = ICON_NONE; | int icon = ICON_NONE; | ||||
| RNA_enum_icon_from_value(items, value, &icon); | RNA_enum_icon_from_value(items, value, &icon); | ||||
| uiBut *but; | uiBut *but; | ||||
| if (RNA_property_editable(ptr, prop)) { | if (RNA_property_editable(ptr, prop)) { | ||||
| IconViewMenuArgs *cb_args = MEM_callocN(sizeof(IconViewMenuArgs), __func__); | IconViewMenuArgs *cb_args = MEM_cnew<IconViewMenuArgs>(__func__); | ||||
| cb_args->ptr = *ptr; | cb_args->ptr = *ptr; | ||||
| cb_args->prop = prop; | cb_args->prop = prop; | ||||
| cb_args->show_labels = show_labels; | cb_args->show_labels = show_labels; | ||||
| cb_args->icon_scale = icon_scale_popup; | cb_args->icon_scale = icon_scale_popup; | ||||
| but = uiDefBlockButN(block, | but = uiDefBlockButN(block, | ||||
| ui_icon_view_menu_cb, | ui_icon_view_menu_cb, | ||||
| cb_args, | cb_args, | ||||
| "", | "", | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X * icon_scale, | UI_UNIT_X * icon_scale, | ||||
| UI_UNIT_Y * icon_scale, | UI_UNIT_Y * icon_scale, | ||||
| ""); | ""); | ||||
| } | } | ||||
| else { | else { | ||||
| but = uiDefIconBut(block, | but = uiDefIconBut(block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| ICON_X, | ICON_X, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X * icon_scale, | UI_UNIT_X * icon_scale, | ||||
| UI_UNIT_Y * icon_scale, | UI_UNIT_Y * icon_scale, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| ""); | ""); | ||||
| } | } | ||||
| ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW); | ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW); | ||||
| ▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | static bool curvemap_can_zoom_out(CurveMapping *cumap) | ||||
| return BLI_rctf_size_x(&cumap->curr) < BLI_rctf_size_x(&cumap->clipr); | return BLI_rctf_size_x(&cumap->curr) < BLI_rctf_size_x(&cumap->clipr); | ||||
| } | } | ||||
| static bool curvemap_can_zoom_in(CurveMapping *cumap) | static bool curvemap_can_zoom_in(CurveMapping *cumap) | ||||
| { | { | ||||
| return BLI_rctf_size_x(&cumap->curr) > CURVE_ZOOM_MAX * BLI_rctf_size_x(&cumap->clipr); | return BLI_rctf_size_x(&cumap->curr) > CURVE_ZOOM_MAX * BLI_rctf_size_x(&cumap->clipr); | ||||
| } | } | ||||
| static void curvemap_buttons_zoom_in(bContext *C, void *cumap_v, void *UNUSED(arg)) | static void curvemap_buttons_zoom_in(bContext *C, void *cumap_v, void * /*arg*/) | ||||
| { | { | ||||
| CurveMapping *cumap = cumap_v; | CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v); | ||||
| if (curvemap_can_zoom_in(cumap)) { | if (curvemap_can_zoom_in(cumap)) { | ||||
| const float dx = 0.1154f * BLI_rctf_size_x(&cumap->curr); | const float dx = 0.1154f * BLI_rctf_size_x(&cumap->curr); | ||||
| cumap->curr.xmin += dx; | cumap->curr.xmin += dx; | ||||
| cumap->curr.xmax -= dx; | cumap->curr.xmax -= dx; | ||||
| const float dy = 0.1154f * BLI_rctf_size_y(&cumap->curr); | const float dy = 0.1154f * BLI_rctf_size_y(&cumap->curr); | ||||
| cumap->curr.ymin += dy; | cumap->curr.ymin += dy; | ||||
| cumap->curr.ymax -= dy; | cumap->curr.ymax -= dy; | ||||
| } | } | ||||
| ED_region_tag_redraw(CTX_wm_region(C)); | ED_region_tag_redraw(CTX_wm_region(C)); | ||||
| } | } | ||||
| static void curvemap_buttons_zoom_out(bContext *C, void *cumap_v, void *UNUSED(unused)) | static void curvemap_buttons_zoom_out(bContext *C, void *cumap_v, void * /*unused*/) | ||||
| { | { | ||||
| CurveMapping *cumap = cumap_v; | CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v); | ||||
| float d, d1; | float d, d1; | ||||
| if (curvemap_can_zoom_out(cumap)) { | if (curvemap_can_zoom_out(cumap)) { | ||||
| d = d1 = 0.15f * BLI_rctf_size_x(&cumap->curr); | d = d1 = 0.15f * BLI_rctf_size_x(&cumap->curr); | ||||
| if (cumap->flag & CUMA_DO_CLIP) { | if (cumap->flag & CUMA_DO_CLIP) { | ||||
| if (cumap->curr.xmin - d < cumap->clipr.xmin) { | if (cumap->curr.xmin - d < cumap->clipr.xmin) { | ||||
| d1 = cumap->curr.xmin - cumap->clipr.xmin; | d1 = cumap->curr.xmin - cumap->clipr.xmin; | ||||
| Show All 25 Lines | if (cumap->flag & CUMA_DO_CLIP) { | ||||
| } | } | ||||
| } | } | ||||
| cumap->curr.ymax += d1; | cumap->curr.ymax += d1; | ||||
| } | } | ||||
| ED_region_tag_redraw(CTX_wm_region(C)); | ED_region_tag_redraw(CTX_wm_region(C)); | ||||
| } | } | ||||
| static void curvemap_buttons_setclip(bContext *UNUSED(C), void *cumap_v, void *UNUSED(arg)) | static void curvemap_buttons_setclip(bContext * /*C*/, void *cumap_v, void * /*arg*/) | ||||
| { | { | ||||
| CurveMapping *cumap = cumap_v; | CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v); | ||||
| BKE_curvemapping_changed(cumap, false); | BKE_curvemapping_changed(cumap, false); | ||||
| } | } | ||||
| static void curvemap_buttons_delete(bContext *C, void *cb_v, void *cumap_v) | static void curvemap_buttons_delete(bContext *C, void *cb_v, void *cumap_v) | ||||
| { | { | ||||
| CurveMapping *cumap = cumap_v; | CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v); | ||||
| BKE_curvemap_remove(cumap->cm + cumap->cur, SELECT); | BKE_curvemap_remove(cumap->cm + cumap->cur, SELECT); | ||||
| BKE_curvemapping_changed(cumap, false); | BKE_curvemapping_changed(cumap, false); | ||||
| rna_update_cb(C, cb_v, NULL); | rna_update_cb(C, cb_v, nullptr); | ||||
| } | } | ||||
| /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */ | /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */ | ||||
| static uiBlock *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap_v) | static uiBlock *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap_v) | ||||
| { | { | ||||
| CurveMapping *cumap = cumap_v; | CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v); | ||||
| uiBut *bt; | uiBut *bt; | ||||
| const float width = 8 * UI_UNIT_X; | const float width = 8 * UI_UNIT_X; | ||||
| uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS); | uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS); | ||||
| UI_block_flag_enable(block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_MOVEMOUSE_QUIT); | UI_block_flag_enable(block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_MOVEMOUSE_QUIT); | ||||
| UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | ||||
| bt = uiDefButBitI(block, | bt = uiDefButBitI(block, | ||||
| UI_BTYPE_CHECKBOX, | UI_BTYPE_CHECKBOX, | ||||
| CUMA_DO_CLIP, | CUMA_DO_CLIP, | ||||
| 1, | 1, | ||||
| IFACE_("Use Clipping"), | IFACE_("Use Clipping"), | ||||
| 0, | 0, | ||||
| 5 * UI_UNIT_Y, | 5 * UI_UNIT_Y, | ||||
| width, | width, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| &cumap->flag, | &cumap->flag, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 10, | 10, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_setclip, cumap, NULL); | UI_but_func_set(bt, curvemap_buttons_setclip, cumap, nullptr); | ||||
| UI_block_align_begin(block); | UI_block_align_begin(block); | ||||
| bt = uiDefButF(block, | bt = uiDefButF(block, | ||||
| UI_BTYPE_NUM, | UI_BTYPE_NUM, | ||||
| 0, | 0, | ||||
| IFACE_("Min X:"), | IFACE_("Min X:"), | ||||
| 0, | 0, | ||||
| 4 * UI_UNIT_Y, | 4 * UI_UNIT_Y, | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | enum { | ||||
| UICURVE_FUNC_HANDLE_AUTO, | UICURVE_FUNC_HANDLE_AUTO, | ||||
| UICURVE_FUNC_HANDLE_AUTO_ANIM, | UICURVE_FUNC_HANDLE_AUTO_ANIM, | ||||
| UICURVE_FUNC_EXTEND_HOZ, | UICURVE_FUNC_EXTEND_HOZ, | ||||
| UICURVE_FUNC_EXTEND_EXP, | UICURVE_FUNC_EXTEND_EXP, | ||||
| }; | }; | ||||
| static void curvemap_tools_dofunc(bContext *C, void *cumap_v, int event) | static void curvemap_tools_dofunc(bContext *C, void *cumap_v, int event) | ||||
| { | { | ||||
| CurveMapping *cumap = cumap_v; | CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v); | ||||
| CurveMap *cuma = cumap->cm + cumap->cur; | CurveMap *cuma = cumap->cm + cumap->cur; | ||||
| switch (event) { | switch (event) { | ||||
| case UICURVE_FUNC_RESET_NEG: | case UICURVE_FUNC_RESET_NEG: | ||||
| case UICURVE_FUNC_RESET_POS: /* reset */ | case UICURVE_FUNC_RESET_POS: /* reset */ | ||||
| BKE_curvemap_reset(cuma, | BKE_curvemap_reset(cuma, | ||||
| &cumap->clipr, | &cumap->clipr, | ||||
| cumap->preset, | cumap->preset, | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Reset View"), | IFACE_("Reset View"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| menuwidth, | menuwidth, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| UICURVE_FUNC_RESET_VIEW, | UICURVE_FUNC_RESET_VIEW, | ||||
| ""); | ""); | ||||
| } | } | ||||
| if (show_extend) { | if (show_extend) { | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Extend Horizontal"), | IFACE_("Extend Horizontal"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| menuwidth, | menuwidth, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| UICURVE_FUNC_EXTEND_HOZ, | UICURVE_FUNC_EXTEND_HOZ, | ||||
| ""); | ""); | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Extend Extrapolated"), | IFACE_("Extend Extrapolated"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| menuwidth, | menuwidth, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| UICURVE_FUNC_EXTEND_EXP, | UICURVE_FUNC_EXTEND_EXP, | ||||
| ""); | ""); | ||||
| } | } | ||||
| { | { | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Reset Curve"), | IFACE_("Reset Curve"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| menuwidth, | menuwidth, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| reset_mode, | reset_mode, | ||||
| ""); | ""); | ||||
| } | } | ||||
| UI_block_direction_set(block, UI_DIR_DOWN); | UI_block_direction_set(block, UI_DIR_DOWN); | ||||
| UI_block_bounds_set_text(block, 3.0f * UI_UNIT_X); | UI_block_bounds_set_text(block, 3.0f * UI_UNIT_X); | ||||
| return block; | return block; | ||||
| } | } | ||||
| static uiBlock *curvemap_tools_posslope_func(bContext *C, ARegion *region, void *cumap_v) | static uiBlock *curvemap_tools_posslope_func(bContext *C, ARegion *region, void *cumap_v) | ||||
| { | { | ||||
| return curvemap_tools_func(C, region, cumap_v, true, UICURVE_FUNC_RESET_POS); | return curvemap_tools_func( | ||||
| C, region, static_cast<CurveMapping *>(cumap_v), true, UICURVE_FUNC_RESET_POS); | |||||
| } | } | ||||
| static uiBlock *curvemap_tools_negslope_func(bContext *C, ARegion *region, void *cumap_v) | static uiBlock *curvemap_tools_negslope_func(bContext *C, ARegion *region, void *cumap_v) | ||||
| { | { | ||||
| return curvemap_tools_func(C, region, cumap_v, true, UICURVE_FUNC_RESET_NEG); | return curvemap_tools_func( | ||||
| C, region, static_cast<CurveMapping *>(cumap_v), true, UICURVE_FUNC_RESET_NEG); | |||||
| } | } | ||||
| static uiBlock *curvemap_brush_tools_func(bContext *C, ARegion *region, void *cumap_v) | static uiBlock *curvemap_brush_tools_func(bContext *C, ARegion *region, void *cumap_v) | ||||
| { | { | ||||
| return curvemap_tools_func(C, region, cumap_v, false, UICURVE_FUNC_RESET_NEG); | return curvemap_tools_func( | ||||
| C, region, static_cast<CurveMapping *>(cumap_v), false, UICURVE_FUNC_RESET_NEG); | |||||
| } | } | ||||
| static uiBlock *curvemap_brush_tools_negslope_func(bContext *C, ARegion *region, void *cumap_v) | static uiBlock *curvemap_brush_tools_negslope_func(bContext *C, ARegion *region, void *cumap_v) | ||||
| { | { | ||||
| return curvemap_tools_func(C, region, cumap_v, false, UICURVE_FUNC_RESET_POS); | return curvemap_tools_func( | ||||
| C, region, static_cast<CurveMapping *>(cumap_v), false, UICURVE_FUNC_RESET_POS); | |||||
| } | } | ||||
| static void curvemap_tools_handle_vector(bContext *C, void *cumap_v, void *UNUSED(arg)) | static void curvemap_tools_handle_vector(bContext *C, void *cumap_v, void * /*arg*/) | ||||
| { | { | ||||
| curvemap_tools_dofunc(C, cumap_v, UICURVE_FUNC_HANDLE_VECTOR); | curvemap_tools_dofunc(C, cumap_v, UICURVE_FUNC_HANDLE_VECTOR); | ||||
| } | } | ||||
| static void curvemap_tools_handle_auto(bContext *C, void *cumap_v, void *UNUSED(arg)) | static void curvemap_tools_handle_auto(bContext *C, void *cumap_v, void * /*arg*/) | ||||
| { | { | ||||
| curvemap_tools_dofunc(C, cumap_v, UICURVE_FUNC_HANDLE_AUTO); | curvemap_tools_dofunc(C, cumap_v, UICURVE_FUNC_HANDLE_AUTO); | ||||
| } | } | ||||
| static void curvemap_tools_handle_auto_clamped(bContext *C, void *cumap_v, void *UNUSED(arg)) | static void curvemap_tools_handle_auto_clamped(bContext *C, void *cumap_v, void * /*arg*/) | ||||
| { | { | ||||
| curvemap_tools_dofunc(C, cumap_v, UICURVE_FUNC_HANDLE_AUTO_ANIM); | curvemap_tools_dofunc(C, cumap_v, UICURVE_FUNC_HANDLE_AUTO_ANIM); | ||||
| } | } | ||||
| static void curvemap_buttons_redraw(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2)) | static void curvemap_buttons_redraw(bContext *C, void * /*arg1*/, void * /*arg2*/) | ||||
| { | { | ||||
| ED_region_tag_redraw(CTX_wm_region(C)); | ED_region_tag_redraw(CTX_wm_region(C)); | ||||
| } | } | ||||
| static void curvemap_buttons_update(bContext *C, void *arg1_v, void *cumap_v) | static void curvemap_buttons_update(bContext *C, void *arg1_v, void *cumap_v) | ||||
| { | { | ||||
| CurveMapping *cumap = cumap_v; | CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v); | ||||
| BKE_curvemapping_changed(cumap, true); | BKE_curvemapping_changed(cumap, true); | ||||
| rna_update_cb(C, arg1_v, NULL); | rna_update_cb(C, arg1_v, nullptr); | ||||
| } | } | ||||
| static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v) | static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v) | ||||
| { | { | ||||
| CurveMapping *cumap = cumap_v; | CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v); | ||||
| cumap->preset = CURVE_PRESET_LINE; | cumap->preset = CURVE_PRESET_LINE; | ||||
| for (int a = 0; a < CM_TOT; a++) { | for (int a = 0; a < CM_TOT; a++) { | ||||
| BKE_curvemap_reset(cumap->cm + a, &cumap->clipr, cumap->preset, CURVEMAP_SLOPE_POSITIVE); | BKE_curvemap_reset(cumap->cm + a, &cumap->clipr, cumap->preset, CURVEMAP_SLOPE_POSITIVE); | ||||
| } | } | ||||
| cumap->black[0] = cumap->black[1] = cumap->black[2] = 0.0f; | cumap->black[0] = cumap->black[1] = cumap->black[2] = 0.0f; | ||||
| cumap->white[0] = cumap->white[1] = cumap->white[2] = 1.0f; | cumap->white[0] = cumap->white[1] = cumap->white[2] = 1.0f; | ||||
| BKE_curvemapping_set_black_white(cumap, NULL, NULL); | BKE_curvemapping_set_black_white(cumap, nullptr, nullptr); | ||||
| BKE_curvemapping_changed(cumap, false); | BKE_curvemapping_changed(cumap, false); | ||||
| rna_update_cb(C, cb_v, NULL); | rna_update_cb(C, cb_v, nullptr); | ||||
| } | } | ||||
| /** | /** | ||||
| * \note Still unsure how this call evolves. | * \note Still unsure how this call evolves. | ||||
| * | * | ||||
| * \param labeltype: Used for defining which curve-channels to show. | * \param labeltype: Used for defining which curve-channels to show. | ||||
| */ | */ | ||||
| static void curvemap_buttons_layout(uiLayout *layout, | static void curvemap_buttons_layout(uiLayout *layout, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| char labeltype, | char labeltype, | ||||
| bool levels, | bool levels, | ||||
| bool brush, | bool brush, | ||||
| bool neg_slope, | bool neg_slope, | ||||
| bool tone, | bool tone, | ||||
| RNAUpdateCb *cb) | RNAUpdateCb *cb) | ||||
| { | { | ||||
| CurveMapping *cumap = ptr->data; | CurveMapping *cumap = static_cast<CurveMapping *>(ptr->data); | ||||
| CurveMap *cm = &cumap->cm[cumap->cur]; | CurveMap *cm = &cumap->cm[cumap->cur]; | ||||
| uiBut *bt; | uiBut *bt; | ||||
| const float dx = UI_UNIT_X; | const float dx = UI_UNIT_X; | ||||
| int bg = -1; | int bg = -1; | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| UI_block_emboss_set(block, UI_EMBOSS); | UI_block_emboss_set(block, UI_EMBOSS); | ||||
| if (tone) { | if (tone) { | ||||
| uiLayout *split = uiLayoutSplit(layout, 0.0f, false); | uiLayout *split = uiLayoutSplit(layout, 0.0f, false); | ||||
| uiItemR(uiLayoutRow(split, false), ptr, "tone", UI_ITEM_R_EXPAND, NULL, ICON_NONE); | uiItemR(uiLayoutRow(split, false), ptr, "tone", UI_ITEM_R_EXPAND, nullptr, ICON_NONE); | ||||
| } | } | ||||
| /* curve chooser */ | /* curve chooser */ | ||||
| uiLayout *row = uiLayoutRow(layout, false); | uiLayout *row = uiLayoutRow(layout, false); | ||||
| if (labeltype == 'v') { | if (labeltype == 'v') { | ||||
| /* vector */ | /* vector */ | ||||
| uiLayout *sub = uiLayoutRow(row, true); | uiLayout *sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT); | uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT); | ||||
| if (cumap->cm[0].curve) { | if (cumap->cm[0].curve) { | ||||
| bt = uiDefButI( | bt = uiDefButI( | ||||
| block, UI_BTYPE_ROW, 0, "X", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, ""); | block, UI_BTYPE_ROW, 0, "X", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_redraw, NULL, NULL); | UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr); | ||||
| } | } | ||||
| if (cumap->cm[1].curve) { | if (cumap->cm[1].curve) { | ||||
| bt = uiDefButI( | bt = uiDefButI( | ||||
| block, UI_BTYPE_ROW, 0, "Y", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, ""); | block, UI_BTYPE_ROW, 0, "Y", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_redraw, NULL, NULL); | UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr); | ||||
| } | } | ||||
| if (cumap->cm[2].curve) { | if (cumap->cm[2].curve) { | ||||
| bt = uiDefButI( | bt = uiDefButI( | ||||
| block, UI_BTYPE_ROW, 0, "Z", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, ""); | block, UI_BTYPE_ROW, 0, "Z", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_redraw, NULL, NULL); | UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr); | ||||
| } | } | ||||
| } | } | ||||
| else if (labeltype == 'c') { | else if (labeltype == 'c') { | ||||
| /* color */ | /* color */ | ||||
| uiLayout *sub = uiLayoutRow(row, true); | uiLayout *sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT); | uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT); | ||||
| if (cumap->cm[3].curve) { | if (cumap->cm[3].curve) { | ||||
| bt = uiDefButI( | bt = uiDefButI( | ||||
| block, UI_BTYPE_ROW, 0, "C", 0, 0, dx, dx, &cumap->cur, 0.0, 3.0, 0.0, 0.0, ""); | block, UI_BTYPE_ROW, 0, "C", 0, 0, dx, dx, &cumap->cur, 0.0, 3.0, 0.0, 0.0, ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_redraw, NULL, NULL); | UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr); | ||||
| } | } | ||||
| if (cumap->cm[0].curve) { | if (cumap->cm[0].curve) { | ||||
| bt = uiDefButI( | bt = uiDefButI( | ||||
| block, UI_BTYPE_ROW, 0, "R", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, ""); | block, UI_BTYPE_ROW, 0, "R", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_redraw, NULL, NULL); | UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr); | ||||
| } | } | ||||
| if (cumap->cm[1].curve) { | if (cumap->cm[1].curve) { | ||||
| bt = uiDefButI( | bt = uiDefButI( | ||||
| block, UI_BTYPE_ROW, 0, "G", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, ""); | block, UI_BTYPE_ROW, 0, "G", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_redraw, NULL, NULL); | UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr); | ||||
| } | } | ||||
| if (cumap->cm[2].curve) { | if (cumap->cm[2].curve) { | ||||
| bt = uiDefButI( | bt = uiDefButI( | ||||
| block, UI_BTYPE_ROW, 0, "B", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, ""); | block, UI_BTYPE_ROW, 0, "B", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_redraw, NULL, NULL); | UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr); | ||||
| } | } | ||||
| } | } | ||||
| else if (labeltype == 'h') { | else if (labeltype == 'h') { | ||||
| /* HSV */ | /* HSV */ | ||||
| uiLayout *sub = uiLayoutRow(row, true); | uiLayout *sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT); | uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT); | ||||
| if (cumap->cm[0].curve) { | if (cumap->cm[0].curve) { | ||||
| bt = uiDefButI( | bt = uiDefButI( | ||||
| block, UI_BTYPE_ROW, 0, "H", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, ""); | block, UI_BTYPE_ROW, 0, "H", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_redraw, NULL, NULL); | UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr); | ||||
| } | } | ||||
| if (cumap->cm[1].curve) { | if (cumap->cm[1].curve) { | ||||
| bt = uiDefButI( | bt = uiDefButI( | ||||
| block, UI_BTYPE_ROW, 0, "S", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, ""); | block, UI_BTYPE_ROW, 0, "S", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_redraw, NULL, NULL); | UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr); | ||||
| } | } | ||||
| if (cumap->cm[2].curve) { | if (cumap->cm[2].curve) { | ||||
| bt = uiDefButI( | bt = uiDefButI( | ||||
| block, UI_BTYPE_ROW, 0, "V", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, ""); | block, UI_BTYPE_ROW, 0, "V", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, ""); | ||||
| UI_but_func_set(bt, curvemap_buttons_redraw, NULL, NULL); | UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); | uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); | ||||
| } | } | ||||
| if (labeltype == 'h') { | if (labeltype == 'h') { | ||||
| bg = UI_GRAD_H; | bg = UI_GRAD_H; | ||||
| } | } | ||||
| /* operation buttons */ | /* operation buttons */ | ||||
| /* (Right aligned) */ | /* (Right aligned) */ | ||||
| uiLayout *sub = uiLayoutRow(row, true); | uiLayout *sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_RIGHT); | uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_RIGHT); | ||||
| /* Zoom in */ | /* Zoom in */ | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_ZOOM_IN, | ICON_ZOOM_IN, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| dx, | dx, | ||||
| dx, | dx, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Zoom in")); | TIP_("Zoom in")); | ||||
| UI_but_func_set(bt, curvemap_buttons_zoom_in, cumap, NULL); | UI_but_func_set(bt, curvemap_buttons_zoom_in, cumap, nullptr); | ||||
| if (!curvemap_can_zoom_in(cumap)) { | if (!curvemap_can_zoom_in(cumap)) { | ||||
| UI_but_disable(bt, ""); | UI_but_disable(bt, ""); | ||||
| } | } | ||||
| /* Zoom out */ | /* Zoom out */ | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_ZOOM_OUT, | ICON_ZOOM_OUT, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| dx, | dx, | ||||
| dx, | dx, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Zoom out")); | TIP_("Zoom out")); | ||||
| UI_but_func_set(bt, curvemap_buttons_zoom_out, cumap, NULL); | UI_but_func_set(bt, curvemap_buttons_zoom_out, cumap, nullptr); | ||||
| if (!curvemap_can_zoom_out(cumap)) { | if (!curvemap_can_zoom_out(cumap)) { | ||||
| UI_but_disable(bt, ""); | UI_but_disable(bt, ""); | ||||
| } | } | ||||
| /* Clipping button. */ | /* Clipping button. */ | ||||
| const int icon = (cumap->flag & CUMA_DO_CLIP) ? ICON_CLIPUV_HLT : ICON_CLIPUV_DEHLT; | const int icon = (cumap->flag & CUMA_DO_CLIP) ? ICON_CLIPUV_HLT : ICON_CLIPUV_DEHLT; | ||||
| bt = uiDefIconBlockBut( | bt = uiDefIconBlockBut( | ||||
| block, curvemap_clipping_func, cumap, 0, icon, 0, 0, dx, dx, TIP_("Clipping Options")); | block, curvemap_clipping_func, cumap, 0, icon, 0, 0, dx, dx, TIP_("Clipping Options")); | ||||
| bt->drawflag &= ~UI_BUT_ICON_LEFT; | bt->drawflag &= ~UI_BUT_ICON_LEFT; | ||||
| UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL); | UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), nullptr); | ||||
| if (brush && neg_slope) { | if (brush && neg_slope) { | ||||
| bt = uiDefIconBlockBut( | bt = uiDefIconBlockBut( | ||||
| block, curvemap_brush_tools_negslope_func, cumap, 0, 0, 0, 0, dx, dx, TIP_("Tools")); | block, curvemap_brush_tools_negslope_func, cumap, 0, 0, 0, 0, dx, dx, TIP_("Tools")); | ||||
| } | } | ||||
| else if (brush) { | else if (brush) { | ||||
| bt = uiDefIconBlockBut( | bt = uiDefIconBlockBut( | ||||
| block, curvemap_brush_tools_func, cumap, 0, 0, 0, 0, dx, dx, TIP_("Tools")); | block, curvemap_brush_tools_func, cumap, 0, 0, 0, 0, dx, dx, TIP_("Tools")); | ||||
| } | } | ||||
| else if (neg_slope) { | else if (neg_slope) { | ||||
| bt = uiDefIconBlockBut( | bt = uiDefIconBlockBut( | ||||
| block, curvemap_tools_negslope_func, cumap, 0, 0, 0, 0, dx, dx, TIP_("Tools")); | block, curvemap_tools_negslope_func, cumap, 0, 0, 0, 0, dx, dx, TIP_("Tools")); | ||||
| } | } | ||||
| else { | else { | ||||
| bt = uiDefIconBlockBut( | bt = uiDefIconBlockBut( | ||||
| block, curvemap_tools_posslope_func, cumap, 0, 0, 0, 0, dx, dx, TIP_("Tools")); | block, curvemap_tools_posslope_func, cumap, 0, 0, 0, 0, dx, dx, TIP_("Tools")); | ||||
| } | } | ||||
| UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL); | UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), nullptr); | ||||
| UI_block_funcN_set(block, rna_update_cb, MEM_dupallocN(cb), NULL); | UI_block_funcN_set(block, rna_update_cb, MEM_dupallocN(cb), nullptr); | ||||
| /* Curve itself. */ | /* Curve itself. */ | ||||
| const int size = max_ii(uiLayoutGetWidth(layout), UI_UNIT_X); | const int size = max_ii(uiLayoutGetWidth(layout), UI_UNIT_X); | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiButCurveMapping *curve_but = (uiButCurveMapping *)uiDefBut( | uiButCurveMapping *curve_but = (uiButCurveMapping *)uiDefBut( | ||||
| block, UI_BTYPE_CURVE, 0, "", 0, 0, size, 8.0f * UI_UNIT_X, cumap, 0.0f, 1.0f, -1, 0, ""); | block, UI_BTYPE_CURVE, 0, "", 0, 0, size, 8.0f * UI_UNIT_X, cumap, 0.0f, 1.0f, -1, 0, ""); | ||||
| curve_but->gradient_type = bg; | curve_but->gradient_type = eButGradientType(bg); | ||||
| /* Sliders for selected curve point. */ | /* Sliders for selected curve point. */ | ||||
| int i; | int i; | ||||
| CurveMapPoint *cmp = NULL; | CurveMapPoint *cmp = nullptr; | ||||
| bool point_last_or_first = false; | bool point_last_or_first = false; | ||||
| for (i = 0; i < cm->totpoint; i++) { | for (i = 0; i < cm->totpoint; i++) { | ||||
| if (cm->curve[i].flag & CUMA_SELECT) { | if (cm->curve[i].flag & CUMA_SELECT) { | ||||
| cmp = &cm->curve[i]; | cmp = &cm->curve[i]; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (ELEM(i, 0, cm->totpoint - 1)) { | if (ELEM(i, 0, cm->totpoint - 1)) { | ||||
| Show All 18 Lines | if (cmp) { | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 1, | 1, | ||||
| ICON_HANDLE_AUTO, | ICON_HANDLE_AUTO, | ||||
| 0, | 0, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Auto Handle")); | TIP_("Auto Handle")); | ||||
| UI_but_func_set(bt, curvemap_tools_handle_auto, cumap, NULL); | UI_but_func_set(bt, curvemap_tools_handle_auto, cumap, nullptr); | ||||
| if (((cmp->flag & CUMA_HANDLE_AUTO_ANIM) == false) && | if (((cmp->flag & CUMA_HANDLE_AUTO_ANIM) == false) && | ||||
| ((cmp->flag & CUMA_HANDLE_VECTOR) == false)) { | ((cmp->flag & CUMA_HANDLE_VECTOR) == false)) { | ||||
| bt->flag |= UI_SELECT_DRAW; | bt->flag |= UI_SELECT_DRAW; | ||||
| } | } | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 1, | 1, | ||||
| ICON_HANDLE_VECTOR, | ICON_HANDLE_VECTOR, | ||||
| 0, | 0, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Vector Handle")); | TIP_("Vector Handle")); | ||||
| UI_but_func_set(bt, curvemap_tools_handle_vector, cumap, NULL); | UI_but_func_set(bt, curvemap_tools_handle_vector, cumap, nullptr); | ||||
| if (cmp->flag & CUMA_HANDLE_VECTOR) { | if (cmp->flag & CUMA_HANDLE_VECTOR) { | ||||
| bt->flag |= UI_SELECT_DRAW; | bt->flag |= UI_SELECT_DRAW; | ||||
| } | } | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 1, | 1, | ||||
| ICON_HANDLE_AUTOCLAMPED, | ICON_HANDLE_AUTOCLAMPED, | ||||
| 0, | 0, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Auto Clamped")); | TIP_("Auto Clamped")); | ||||
| UI_but_func_set(bt, curvemap_tools_handle_auto_clamped, cumap, NULL); | UI_but_func_set(bt, curvemap_tools_handle_auto_clamped, cumap, nullptr); | ||||
| if (cmp->flag & CUMA_HANDLE_AUTO_ANIM) { | if (cmp->flag & CUMA_HANDLE_AUTO_ANIM) { | ||||
| bt->flag |= UI_SELECT_DRAW; | bt->flag |= UI_SELECT_DRAW; | ||||
| } | } | ||||
| /* Curve handle position */ | /* Curve handle position */ | ||||
| UI_block_funcN_set(block, curvemap_buttons_update, MEM_dupallocN(cb), cumap); | UI_block_funcN_set(block, curvemap_buttons_update, MEM_dupallocN(cb), cumap); | ||||
| bt = uiDefButF(block, | bt = uiDefButF(block, | ||||
| UI_BTYPE_NUM, | UI_BTYPE_NUM, | ||||
| Show All 32 Lines | if (cmp) { | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_X, | ICON_X, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| dx, | dx, | ||||
| dx, | dx, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Delete points")); | TIP_("Delete points")); | ||||
| UI_but_funcN_set(bt, curvemap_buttons_delete, MEM_dupallocN(cb), cumap); | UI_but_funcN_set(bt, curvemap_buttons_delete, MEM_dupallocN(cb), cumap); | ||||
| if (point_last_or_first) { | if (point_last_or_first) { | ||||
| UI_but_flag_enable(bt, UI_BUT_DISABLED); | UI_but_flag_enable(bt, UI_BUT_DISABLED); | ||||
| } | } | ||||
| } | } | ||||
| /* black/white levels */ | /* black/white levels */ | ||||
| if (levels) { | if (levels) { | ||||
| uiLayout *split = uiLayoutSplit(layout, 0.0f, false); | uiLayout *split = uiLayoutSplit(layout, 0.0f, false); | ||||
| uiItemR(uiLayoutColumn(split, false), ptr, "black_level", UI_ITEM_R_EXPAND, NULL, ICON_NONE); | uiItemR( | ||||
| uiItemR(uiLayoutColumn(split, false), ptr, "white_level", UI_ITEM_R_EXPAND, NULL, ICON_NONE); | uiLayoutColumn(split, false), ptr, "black_level", UI_ITEM_R_EXPAND, nullptr, ICON_NONE); | ||||
| uiItemR( | |||||
| uiLayoutColumn(split, false), ptr, "white_level", UI_ITEM_R_EXPAND, nullptr, ICON_NONE); | |||||
| uiLayoutRow(layout, false); | uiLayoutRow(layout, false); | ||||
| bt = uiDefBut(block, | bt = uiDefBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| IFACE_("Reset"), | IFACE_("Reset"), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X * 10, | UI_UNIT_X * 10, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Reset Black/White point and curves")); | TIP_("Reset Black/White point and curves")); | ||||
| UI_but_funcN_set(bt, curvemap_buttons_reset, MEM_dupallocN(cb), cumap); | UI_but_funcN_set(bt, curvemap_buttons_reset, MEM_dupallocN(cb), cumap); | ||||
| } | } | ||||
| UI_block_funcN_set(block, NULL, NULL, NULL); | UI_block_funcN_set(block, nullptr, nullptr, nullptr); | ||||
| } | } | ||||
| void uiTemplateCurveMapping(uiLayout *layout, | void uiTemplateCurveMapping(uiLayout *layout, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| const char *propname, | const char *propname, | ||||
| int type, | int type, | ||||
| bool levels, | bool levels, | ||||
| bool brush, | bool brush, | ||||
| Show All 13 Lines | if (RNA_property_type(prop) != PROP_POINTER) { | ||||
| return; | return; | ||||
| } | } | ||||
| PointerRNA cptr = RNA_property_pointer_get(ptr, prop); | PointerRNA cptr = RNA_property_pointer_get(ptr, prop); | ||||
| if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_CurveMapping)) { | if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_CurveMapping)) { | ||||
| return; | return; | ||||
| } | } | ||||
| RNAUpdateCb *cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb"); | RNAUpdateCb *cb = MEM_cnew<RNAUpdateCb>("RNAUpdateCb"); | ||||
| cb->ptr = *ptr; | cb->ptr = *ptr; | ||||
| cb->prop = prop; | cb->prop = prop; | ||||
| ID *id = cptr.owner_id; | ID *id = cptr.owner_id; | ||||
| UI_block_lock_set(block, (id && ID_IS_LINKED(id)), ERROR_LIBDATA_MESSAGE); | UI_block_lock_set(block, (id && ID_IS_LINKED(id)), ERROR_LIBDATA_MESSAGE); | ||||
| curvemap_buttons_layout(layout, &cptr, type, levels, brush, neg_slope, tone, cb); | curvemap_buttons_layout(layout, &cptr, type, levels, brush, neg_slope, tone, cb); | ||||
| UI_block_lock_clear(block); | UI_block_lock_clear(block); | ||||
| MEM_freeN(cb); | MEM_freeN(cb); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Curve Profile Template | /** \name Curve Profile Template | ||||
| * \{ */ | * \{ */ | ||||
| static void CurveProfile_presets_dofunc(bContext *C, void *profile_v, int event) | static void CurveProfile_presets_dofunc(bContext *C, void *profile_v, int event) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = static_cast<CurveProfile *>(profile_v); | ||||
| profile->preset = event; | profile->preset = event; | ||||
| BKE_curveprofile_reset(profile); | BKE_curveprofile_reset(profile); | ||||
| BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | ||||
| ED_undo_push(C, "CurveProfile tools"); | ED_undo_push(C, "CurveProfile tools"); | ||||
| ED_region_tag_redraw(CTX_wm_region(C)); | ED_region_tag_redraw(CTX_wm_region(C)); | ||||
| } | } | ||||
| Show All 9 Lines | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Default"), | IFACE_("Default"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| 0, | 0, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| PROF_PRESET_LINE, | PROF_PRESET_LINE, | ||||
| ""); | ""); | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Support Loops"), | IFACE_("Support Loops"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| 0, | 0, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| PROF_PRESET_SUPPORTS, | PROF_PRESET_SUPPORTS, | ||||
| ""); | ""); | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Cornice Molding"), | IFACE_("Cornice Molding"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| 0, | 0, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| PROF_PRESET_CORNICE, | PROF_PRESET_CORNICE, | ||||
| ""); | ""); | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Crown Molding"), | IFACE_("Crown Molding"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| 0, | 0, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| PROF_PRESET_CROWN, | PROF_PRESET_CROWN, | ||||
| ""); | ""); | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Steps"), | IFACE_("Steps"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| 0, | 0, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| PROF_PRESET_STEPS, | PROF_PRESET_STEPS, | ||||
| ""); | ""); | ||||
| UI_block_direction_set(block, UI_DIR_DOWN); | UI_block_direction_set(block, UI_DIR_DOWN); | ||||
| UI_block_bounds_set_text(block, (int)(3.0f * UI_UNIT_X)); | UI_block_bounds_set_text(block, int(3.0f * UI_UNIT_X)); | ||||
| return block; | return block; | ||||
| } | } | ||||
| static uiBlock *CurveProfile_buttons_presets(bContext *C, ARegion *region, void *profile_v) | static uiBlock *CurveProfile_buttons_presets(bContext *C, ARegion *region, void *profile_v) | ||||
| { | { | ||||
| return CurveProfile_presets_func(C, region, (CurveProfile *)profile_v); | return CurveProfile_presets_func(C, region, (CurveProfile *)profile_v); | ||||
| } | } | ||||
| /* Only for CurveProfile tools block */ | /* Only for CurveProfile tools block */ | ||||
| enum { | enum { | ||||
| UIPROFILE_FUNC_RESET, | UIPROFILE_FUNC_RESET, | ||||
| UIPROFILE_FUNC_RESET_VIEW, | UIPROFILE_FUNC_RESET_VIEW, | ||||
| }; | }; | ||||
| static void CurveProfile_tools_dofunc(bContext *C, void *profile_v, int event) | static void CurveProfile_tools_dofunc(bContext *C, void *profile_v, int event) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = static_cast<CurveProfile *>(profile_v); | ||||
| switch (event) { | switch (event) { | ||||
| case UIPROFILE_FUNC_RESET: /* reset */ | case UIPROFILE_FUNC_RESET: /* reset */ | ||||
| BKE_curveprofile_reset(profile); | BKE_curveprofile_reset(profile); | ||||
| BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | ||||
| break; | break; | ||||
| case UIPROFILE_FUNC_RESET_VIEW: /* reset view to clipping rect */ | case UIPROFILE_FUNC_RESET_VIEW: /* reset view to clipping rect */ | ||||
| BKE_curveprofile_reset_view(profile); | BKE_curveprofile_reset_view(profile); | ||||
| Show All 14 Lines | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Reset View"), | IFACE_("Reset View"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| 0, | 0, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| UIPROFILE_FUNC_RESET_VIEW, | UIPROFILE_FUNC_RESET_VIEW, | ||||
| ""); | ""); | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT_MENU, | UI_BTYPE_BUT_MENU, | ||||
| 1, | 1, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| IFACE_("Reset Curve"), | IFACE_("Reset Curve"), | ||||
| 0, | 0, | ||||
| yco -= UI_UNIT_Y, | yco -= UI_UNIT_Y, | ||||
| 0, | 0, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0, | 0, | ||||
| UIPROFILE_FUNC_RESET, | UIPROFILE_FUNC_RESET, | ||||
| ""); | ""); | ||||
| UI_block_direction_set(block, UI_DIR_DOWN); | UI_block_direction_set(block, UI_DIR_DOWN); | ||||
| UI_block_bounds_set_text(block, (int)(3.0f * UI_UNIT_X)); | UI_block_bounds_set_text(block, int(3.0f * UI_UNIT_X)); | ||||
| return block; | return block; | ||||
| } | } | ||||
| static uiBlock *CurveProfile_buttons_tools(bContext *C, ARegion *region, void *profile_v) | static uiBlock *CurveProfile_buttons_tools(bContext *C, ARegion *region, void *profile_v) | ||||
| { | { | ||||
| return CurveProfile_tools_func(C, region, (CurveProfile *)profile_v); | return CurveProfile_tools_func(C, region, (CurveProfile *)profile_v); | ||||
| } | } | ||||
| static bool CurveProfile_can_zoom_in(CurveProfile *profile) | static bool CurveProfile_can_zoom_in(CurveProfile *profile) | ||||
| { | { | ||||
| return BLI_rctf_size_x(&profile->view_rect) > | return BLI_rctf_size_x(&profile->view_rect) > | ||||
| CURVE_ZOOM_MAX * BLI_rctf_size_x(&profile->clip_rect); | CURVE_ZOOM_MAX * BLI_rctf_size_x(&profile->clip_rect); | ||||
| } | } | ||||
| static bool CurveProfile_can_zoom_out(CurveProfile *profile) | static bool CurveProfile_can_zoom_out(CurveProfile *profile) | ||||
| { | { | ||||
| return BLI_rctf_size_x(&profile->view_rect) < BLI_rctf_size_x(&profile->clip_rect); | return BLI_rctf_size_x(&profile->view_rect) < BLI_rctf_size_x(&profile->clip_rect); | ||||
| } | } | ||||
| static void CurveProfile_buttons_zoom_in(bContext *C, void *profile_v, void *UNUSED(arg)) | static void CurveProfile_buttons_zoom_in(bContext *C, void *profile_v, void * /*arg*/) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = static_cast<CurveProfile *>(profile_v); | ||||
| if (CurveProfile_can_zoom_in(profile)) { | if (CurveProfile_can_zoom_in(profile)) { | ||||
| const float dx = 0.1154f * BLI_rctf_size_x(&profile->view_rect); | const float dx = 0.1154f * BLI_rctf_size_x(&profile->view_rect); | ||||
| profile->view_rect.xmin += dx; | profile->view_rect.xmin += dx; | ||||
| profile->view_rect.xmax -= dx; | profile->view_rect.xmax -= dx; | ||||
| const float dy = 0.1154f * BLI_rctf_size_y(&profile->view_rect); | const float dy = 0.1154f * BLI_rctf_size_y(&profile->view_rect); | ||||
| profile->view_rect.ymin += dy; | profile->view_rect.ymin += dy; | ||||
| profile->view_rect.ymax -= dy; | profile->view_rect.ymax -= dy; | ||||
| } | } | ||||
| ED_region_tag_redraw(CTX_wm_region(C)); | ED_region_tag_redraw(CTX_wm_region(C)); | ||||
| } | } | ||||
| static void CurveProfile_buttons_zoom_out(bContext *C, void *profile_v, void *UNUSED(arg)) | static void CurveProfile_buttons_zoom_out(bContext *C, void *profile_v, void * /*arg*/) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = static_cast<CurveProfile *>(profile_v); | ||||
| if (CurveProfile_can_zoom_out(profile)) { | if (CurveProfile_can_zoom_out(profile)) { | ||||
| float d = 0.15f * BLI_rctf_size_x(&profile->view_rect); | float d = 0.15f * BLI_rctf_size_x(&profile->view_rect); | ||||
| float d1 = d; | float d1 = d; | ||||
| if (profile->flag & PROF_USE_CLIP) { | if (profile->flag & PROF_USE_CLIP) { | ||||
| if (profile->view_rect.xmin - d < profile->clip_rect.xmin) { | if (profile->view_rect.xmin - d < profile->clip_rect.xmin) { | ||||
| d1 = profile->view_rect.xmin - profile->clip_rect.xmin; | d1 = profile->view_rect.xmin - profile->clip_rect.xmin; | ||||
| Show All 27 Lines | if (CurveProfile_can_zoom_out(profile)) { | ||||
| profile->view_rect.ymax += d1; | profile->view_rect.ymax += d1; | ||||
| } | } | ||||
| ED_region_tag_redraw(CTX_wm_region(C)); | ED_region_tag_redraw(CTX_wm_region(C)); | ||||
| } | } | ||||
| static void CurveProfile_clipping_toggle(bContext *C, void *cb_v, void *profile_v) | static void CurveProfile_clipping_toggle(bContext *C, void *cb_v, void *profile_v) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = static_cast<CurveProfile *>(profile_v); | ||||
| profile->flag ^= PROF_USE_CLIP; | profile->flag ^= PROF_USE_CLIP; | ||||
| BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | ||||
| rna_update_cb(C, cb_v, NULL); | rna_update_cb(C, cb_v, nullptr); | ||||
| } | } | ||||
| static void CurveProfile_buttons_reverse(bContext *C, void *cb_v, void *profile_v) | static void CurveProfile_buttons_reverse(bContext *C, void *cb_v, void *profile_v) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = static_cast<CurveProfile *>(profile_v); | ||||
| BKE_curveprofile_reverse(profile); | BKE_curveprofile_reverse(profile); | ||||
| BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | ||||
| rna_update_cb(C, cb_v, NULL); | rna_update_cb(C, cb_v, nullptr); | ||||
| } | } | ||||
| static void CurveProfile_buttons_delete(bContext *C, void *cb_v, void *profile_v) | static void CurveProfile_buttons_delete(bContext *C, void *cb_v, void *profile_v) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = static_cast<CurveProfile *>(profile_v); | ||||
| BKE_curveprofile_remove_by_flag(profile, SELECT); | BKE_curveprofile_remove_by_flag(profile, SELECT); | ||||
| BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | ||||
| rna_update_cb(C, cb_v, NULL); | rna_update_cb(C, cb_v, nullptr); | ||||
| } | } | ||||
| static void CurveProfile_buttons_update(bContext *C, void *arg1_v, void *profile_v) | static void CurveProfile_buttons_update(bContext *C, void *arg1_v, void *profile_v) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = static_cast<CurveProfile *>(profile_v); | ||||
| BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); | BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); | ||||
| rna_update_cb(C, arg1_v, NULL); | rna_update_cb(C, arg1_v, nullptr); | ||||
| } | } | ||||
| static void CurveProfile_buttons_reset(bContext *C, void *arg1_v, void *profile_v) | static void CurveProfile_buttons_reset(bContext *C, void *arg1_v, void *profile_v) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = static_cast<CurveProfile *>(profile_v); | ||||
| BKE_curveprofile_reset(profile); | BKE_curveprofile_reset(profile); | ||||
| BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | BKE_curveprofile_update(profile, PROF_UPDATE_NONE); | ||||
| rna_update_cb(C, arg1_v, NULL); | rna_update_cb(C, arg1_v, nullptr); | ||||
| } | } | ||||
| static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUpdateCb *cb) | static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUpdateCb *cb) | ||||
| { | { | ||||
| CurveProfile *profile = ptr->data; | CurveProfile *profile = static_cast<CurveProfile *>(ptr->data); | ||||
| uiBut *bt; | uiBut *bt; | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| UI_block_emboss_set(block, UI_EMBOSS); | UI_block_emboss_set(block, UI_EMBOSS); | ||||
| uiLayoutSetPropSep(layout, false); | uiLayoutSetPropSep(layout, false); | ||||
| /* Preset selector */ | /* Preset selector */ | ||||
| /* There is probably potential to use simpler "uiItemR" functions here, but automatic updating | /* There is probably potential to use simpler "uiItemR" functions here, but automatic updating | ||||
| * after a preset is selected would be more complicated. */ | * after a preset is selected would be more complicated. */ | ||||
| uiLayout *row = uiLayoutRow(layout, true); | uiLayout *row = uiLayoutRow(layout, true); | ||||
| bt = uiDefBlockBut( | bt = uiDefBlockBut( | ||||
| block, CurveProfile_buttons_presets, profile, "Preset", 0, 0, UI_UNIT_X, UI_UNIT_X, ""); | block, CurveProfile_buttons_presets, profile, "Preset", 0, 0, UI_UNIT_X, UI_UNIT_X, ""); | ||||
| UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL); | UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), nullptr); | ||||
| /* Show a "re-apply" preset button when it has been changed from the preset. */ | /* Show a "re-apply" preset button when it has been changed from the preset. */ | ||||
| if (profile->flag & PROF_DIRTY_PRESET) { | if (profile->flag & PROF_DIRTY_PRESET) { | ||||
| /* Only for dynamic presets. */ | /* Only for dynamic presets. */ | ||||
| if (ELEM(profile->preset, PROF_PRESET_STEPS, PROF_PRESET_SUPPORTS)) { | if (ELEM(profile->preset, PROF_PRESET_STEPS, PROF_PRESET_SUPPORTS)) { | ||||
| bt = uiDefIconTextBut(block, | bt = uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_NONE, | ICON_NONE, | ||||
| "Apply Preset", | "Apply Preset", | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Reapply and update the preset, removing changes")); | TIP_("Reapply and update the preset, removing changes")); | ||||
| UI_but_funcN_set(bt, CurveProfile_buttons_reset, MEM_dupallocN(cb), profile); | UI_but_funcN_set(bt, CurveProfile_buttons_reset, MEM_dupallocN(cb), profile); | ||||
| } | } | ||||
| } | } | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| /* (Left aligned) */ | /* (Left aligned) */ | ||||
| uiLayout *sub = uiLayoutRow(row, true); | uiLayout *sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT); | uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT); | ||||
| /* Zoom in */ | /* Zoom in */ | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_ZOOM_IN, | ICON_ZOOM_IN, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Zoom in")); | TIP_("Zoom in")); | ||||
| UI_but_func_set(bt, CurveProfile_buttons_zoom_in, profile, NULL); | UI_but_func_set(bt, CurveProfile_buttons_zoom_in, profile, nullptr); | ||||
| if (!CurveProfile_can_zoom_in(profile)) { | if (!CurveProfile_can_zoom_in(profile)) { | ||||
| UI_but_disable(bt, ""); | UI_but_disable(bt, ""); | ||||
| } | } | ||||
| /* Zoom out */ | /* Zoom out */ | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_ZOOM_OUT, | ICON_ZOOM_OUT, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Zoom out")); | TIP_("Zoom out")); | ||||
| UI_but_func_set(bt, CurveProfile_buttons_zoom_out, profile, NULL); | UI_but_func_set(bt, CurveProfile_buttons_zoom_out, profile, nullptr); | ||||
| if (!CurveProfile_can_zoom_out(profile)) { | if (!CurveProfile_can_zoom_out(profile)) { | ||||
| UI_but_disable(bt, ""); | UI_but_disable(bt, ""); | ||||
| } | } | ||||
| /* (Right aligned) */ | /* (Right aligned) */ | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_RIGHT); | uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_RIGHT); | ||||
| /* Flip path */ | /* Flip path */ | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_ARROW_LEFTRIGHT, | ICON_ARROW_LEFTRIGHT, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Reverse Path")); | TIP_("Reverse Path")); | ||||
| UI_but_funcN_set(bt, CurveProfile_buttons_reverse, MEM_dupallocN(cb), profile); | UI_but_funcN_set(bt, CurveProfile_buttons_reverse, MEM_dupallocN(cb), profile); | ||||
| /* Clipping toggle */ | /* Clipping toggle */ | ||||
| const int icon = (profile->flag & PROF_USE_CLIP) ? ICON_CLIPUV_HLT : ICON_CLIPUV_DEHLT; | const int icon = (profile->flag & PROF_USE_CLIP) ? ICON_CLIPUV_HLT : ICON_CLIPUV_DEHLT; | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| icon, | icon, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Toggle Profile Clipping")); | TIP_("Toggle Profile Clipping")); | ||||
| UI_but_funcN_set(bt, CurveProfile_clipping_toggle, MEM_dupallocN(cb), profile); | UI_but_funcN_set(bt, CurveProfile_clipping_toggle, MEM_dupallocN(cb), profile); | ||||
| /* Reset view, reset curve */ | /* Reset view, reset curve */ | ||||
| bt = uiDefIconBlockBut( | bt = uiDefIconBlockBut( | ||||
| block, CurveProfile_buttons_tools, profile, 0, 0, 0, 0, UI_UNIT_X, UI_UNIT_X, TIP_("Tools")); | block, CurveProfile_buttons_tools, profile, 0, 0, 0, 0, UI_UNIT_X, UI_UNIT_X, TIP_("Tools")); | ||||
| UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL); | UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), nullptr); | ||||
| UI_block_funcN_set(block, rna_update_cb, MEM_dupallocN(cb), NULL); | UI_block_funcN_set(block, rna_update_cb, MEM_dupallocN(cb), nullptr); | ||||
| /* The path itself */ | /* The path itself */ | ||||
| int path_width = max_ii(uiLayoutGetWidth(layout), UI_UNIT_X); | int path_width = max_ii(uiLayoutGetWidth(layout), UI_UNIT_X); | ||||
| path_width = min_ii(path_width, (int)(16.0f * UI_UNIT_X)); | path_width = min_ii(path_width, int(16.0f * UI_UNIT_X)); | ||||
| const int path_height = path_width; | const int path_height = path_width; | ||||
| uiLayoutRow(layout, false); | uiLayoutRow(layout, false); | ||||
| uiDefBut(block, | uiDefBut(block, | ||||
| UI_BTYPE_CURVEPROFILE, | UI_BTYPE_CURVEPROFILE, | ||||
| 0, | 0, | ||||
| "", | "", | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| (short)path_width, | (short)path_width, | ||||
| (short)path_height, | (short)path_height, | ||||
| profile, | profile, | ||||
| 0.0f, | 0.0f, | ||||
| 1.0f, | 1.0f, | ||||
| -1, | -1, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| /* Position sliders for (first) selected point */ | /* Position sliders for (first) selected point */ | ||||
| int i; | int i; | ||||
| float *selection_x, *selection_y; | float *selection_x, *selection_y; | ||||
| bool point_last_or_first = false; | bool point_last_or_first = false; | ||||
| CurveProfilePoint *point = NULL; | CurveProfilePoint *point = nullptr; | ||||
| for (i = 0; i < profile->path_len; i++) { | for (i = 0; i < profile->path_len; i++) { | ||||
| if (profile->path[i].flag & PROF_SELECT) { | if (profile->path[i].flag & PROF_SELECT) { | ||||
| point = &profile->path[i]; | point = &profile->path[i]; | ||||
| selection_x = &point->x; | selection_x = &point->x; | ||||
| selection_y = &point->y; | selection_y = &point->y; | ||||
| break; | break; | ||||
| } | } | ||||
| if (profile->path[i].flag & PROF_H1_SELECT) { | if (profile->path[i].flag & PROF_H1_SELECT) { | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | if (point) { | ||||
| bt = uiDefIconBut(block, | bt = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_X, | ICON_X, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Delete points")); | TIP_("Delete points")); | ||||
| UI_but_funcN_set(bt, CurveProfile_buttons_delete, MEM_dupallocN(cb), profile); | UI_but_funcN_set(bt, CurveProfile_buttons_delete, MEM_dupallocN(cb), profile); | ||||
| if (point_last_or_first) { | if (point_last_or_first) { | ||||
| UI_but_flag_enable(bt, UI_BUT_DISABLED); | UI_but_flag_enable(bt, UI_BUT_DISABLED); | ||||
| } | } | ||||
| } | } | ||||
| uiItemR(layout, ptr, "use_sample_straight_edges", 0, NULL, ICON_NONE); | uiItemR(layout, ptr, "use_sample_straight_edges", 0, nullptr, ICON_NONE); | ||||
| uiItemR(layout, ptr, "use_sample_even_lengths", 0, NULL, ICON_NONE); | uiItemR(layout, ptr, "use_sample_even_lengths", 0, nullptr, ICON_NONE); | ||||
| UI_block_funcN_set(block, NULL, NULL, NULL); | UI_block_funcN_set(block, nullptr, nullptr, nullptr); | ||||
| } | } | ||||
| void uiTemplateCurveProfile(uiLayout *layout, PointerRNA *ptr, const char *propname) | void uiTemplateCurveProfile(uiLayout *layout, PointerRNA *ptr, const char *propname) | ||||
| { | { | ||||
| PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| Show All 10 Lines | void uiTemplateCurveProfile(uiLayout *layout, PointerRNA *ptr, const char *propname) | ||||
| } | } | ||||
| PointerRNA cptr = RNA_property_pointer_get(ptr, prop); | PointerRNA cptr = RNA_property_pointer_get(ptr, prop); | ||||
| if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_CurveProfile)) { | if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_CurveProfile)) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Share update functionality with the CurveMapping widget template. */ | /* Share update functionality with the CurveMapping widget template. */ | ||||
| RNAUpdateCb *cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb"); | RNAUpdateCb *cb = MEM_cnew<RNAUpdateCb>("RNAUpdateCb"); | ||||
| cb->ptr = *ptr; | cb->ptr = *ptr; | ||||
| cb->prop = prop; | cb->prop = prop; | ||||
| ID *id = cptr.owner_id; | ID *id = cptr.owner_id; | ||||
| UI_block_lock_set(block, (id && ID_IS_LINKED(id)), ERROR_LIBDATA_MESSAGE); | UI_block_lock_set(block, (id && ID_IS_LINKED(id)), ERROR_LIBDATA_MESSAGE); | ||||
| CurveProfile_buttons_layout(layout, &cptr, cb); | CurveProfile_buttons_layout(layout, &cptr, cb); | ||||
| Show All 28 Lines | void uiTemplateColorPicker(uiLayout *layout, | ||||
| } | } | ||||
| float softmin, softmax, step, precision; | float softmin, softmax, step, precision; | ||||
| RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision); | RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision); | ||||
| uiLayout *col = uiLayoutColumn(layout, true); | uiLayout *col = uiLayoutColumn(layout, true); | ||||
| uiLayout *row = uiLayoutRow(col, true); | uiLayout *row = uiLayoutRow(col, true); | ||||
| uiBut *but = NULL; | uiBut *but = nullptr; | ||||
| uiButHSVCube *hsv_but; | uiButHSVCube *hsv_but; | ||||
| switch (U.color_picker_type) { | switch (U.color_picker_type) { | ||||
| case USER_CP_SQUARE_SV: | case USER_CP_SQUARE_SV: | ||||
| case USER_CP_SQUARE_HS: | case USER_CP_SQUARE_HS: | ||||
| case USER_CP_SQUARE_HV: | case USER_CP_SQUARE_HV: | ||||
| hsv_but = (uiButHSVCube *)uiDefButR_prop(block, | hsv_but = (uiButHSVCube *)uiDefButR_prop(block, | ||||
| UI_BTYPE_HSVCUBE, | UI_BTYPE_HSVCUBE, | ||||
| 0, | 0, | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | switch (U.color_picker_type) { | ||||
| ptr, | ptr, | ||||
| prop, | prop, | ||||
| -1, | -1, | ||||
| softmin, | softmin, | ||||
| softmax, | softmax, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| hsv_but->gradient_type = UI_GRAD_SV + 3; | hsv_but->gradient_type = eButGradientType(UI_GRAD_SV + 3); | ||||
| break; | break; | ||||
| case USER_CP_SQUARE_HS: | case USER_CP_SQUARE_HS: | ||||
| uiItemS(col); | uiItemS(col); | ||||
| hsv_but = (uiButHSVCube *)uiDefButR_prop(block, | hsv_but = (uiButHSVCube *)uiDefButR_prop(block, | ||||
| UI_BTYPE_HSVCUBE, | UI_BTYPE_HSVCUBE, | ||||
| 0, | 0, | ||||
| "", | "", | ||||
| 0, | 0, | ||||
| 4, | 4, | ||||
| WHEEL_SIZE, | WHEEL_SIZE, | ||||
| 18 * UI_DPI_FAC, | 18 * UI_DPI_FAC, | ||||
| ptr, | ptr, | ||||
| prop, | prop, | ||||
| -1, | -1, | ||||
| softmin, | softmin, | ||||
| softmax, | softmax, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| hsv_but->gradient_type = UI_GRAD_HS + 3; | hsv_but->gradient_type = eButGradientType(UI_GRAD_HS + 3); | ||||
| break; | break; | ||||
| case USER_CP_SQUARE_HV: | case USER_CP_SQUARE_HV: | ||||
| uiItemS(col); | uiItemS(col); | ||||
| hsv_but = (uiButHSVCube *)uiDefButR_prop(block, | hsv_but = (uiButHSVCube *)uiDefButR_prop(block, | ||||
| UI_BTYPE_HSVCUBE, | UI_BTYPE_HSVCUBE, | ||||
| 0, | 0, | ||||
| "", | "", | ||||
| 0, | 0, | ||||
| 4, | 4, | ||||
| WHEEL_SIZE, | WHEEL_SIZE, | ||||
| 18 * UI_DPI_FAC, | 18 * UI_DPI_FAC, | ||||
| ptr, | ptr, | ||||
| prop, | prop, | ||||
| -1, | -1, | ||||
| softmin, | softmin, | ||||
| softmax, | softmax, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| hsv_but->gradient_type = UI_GRAD_HV + 3; | hsv_but->gradient_type = eButGradientType(UI_GRAD_HV + 3); | ||||
| break; | break; | ||||
| /* user default */ | /* user default */ | ||||
| case USER_CP_CIRCLE_HSV: | case USER_CP_CIRCLE_HSV: | ||||
| default: | default: | ||||
| uiItemS(row); | uiItemS(row); | ||||
| hsv_but = (uiButHSVCube *)uiDefButR_prop(block, | hsv_but = (uiButHSVCube *)uiDefButR_prop(block, | ||||
| UI_BTYPE_HSVCUBE, | UI_BTYPE_HSVCUBE, | ||||
| Show All 14 Lines | switch (U.color_picker_type) { | ||||
| hsv_but->gradient_type = UI_GRAD_V_ALT; | hsv_but->gradient_type = UI_GRAD_V_ALT; | ||||
| break; | break; | ||||
| } | } | ||||
| hsv_but->but.custom_data = cpicker; | hsv_but->but.custom_data = cpicker; | ||||
| } | } | ||||
| } | } | ||||
| static void ui_template_palette_menu(bContext *UNUSED(C), uiLayout *layout, void *UNUSED(but_p)) | static void ui_template_palette_menu(bContext * /* C*/, uiLayout *layout, void * /*but_p*/) | ||||
| { | { | ||||
| uiLayout *row; | uiLayout *row; | ||||
| uiItemL(layout, IFACE_("Sort By:"), ICON_NONE); | uiItemL(layout, IFACE_("Sort By:"), ICON_NONE); | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiItemEnumO_value(row, IFACE_("Hue"), ICON_NONE, "PALETTE_OT_sort", "type", 1); | uiItemEnumO_value(row, IFACE_("Hue"), ICON_NONE, "PALETTE_OT_sort", "type", 1); | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiItemEnumO_value(row, IFACE_("Saturation"), ICON_NONE, "PALETTE_OT_sort", "type", 2); | uiItemEnumO_value(row, IFACE_("Saturation"), ICON_NONE, "PALETTE_OT_sort", "type", 2); | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiItemEnumO_value(row, IFACE_("Value"), ICON_NONE, "PALETTE_OT_sort", "type", 3); | uiItemEnumO_value(row, IFACE_("Value"), ICON_NONE, "PALETTE_OT_sort", "type", 3); | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiItemEnumO_value(row, IFACE_("Luminance"), ICON_NONE, "PALETTE_OT_sort", "type", 4); | uiItemEnumO_value(row, IFACE_("Luminance"), ICON_NONE, "PALETTE_OT_sort", "type", 4); | ||||
| } | } | ||||
| void uiTemplatePalette(uiLayout *layout, | void uiTemplatePalette(uiLayout *layout, PointerRNA *ptr, const char *propname, bool /*colors*/) | ||||
| PointerRNA *ptr, | |||||
| const char *propname, | |||||
| bool UNUSED(colors)) | |||||
| { | { | ||||
| PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | ||||
| uiBut *but = NULL; | uiBut *but = nullptr; | ||||
| const 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) { | if (!prop) { | ||||
| RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); | RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); | ||||
| return; | return; | ||||
| } | } | ||||
| const PointerRNA cptr = RNA_property_pointer_get(ptr, prop); | const PointerRNA cptr = RNA_property_pointer_get(ptr, prop); | ||||
| if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_Palette)) { | if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_Palette)) { | ||||
| return; | return; | ||||
| } | } | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| Palette *palette = cptr.data; | Palette *palette = static_cast<Palette *>(cptr.data); | ||||
| uiLayout *col = uiLayoutColumn(layout, true); | uiLayout *col = uiLayoutColumn(layout, true); | ||||
| uiLayoutRow(col, true); | uiLayoutRow(col, true); | ||||
| uiDefIconButO(block, | uiDefIconButO(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| "PALETTE_OT_color_add", | "PALETTE_OT_color_add", | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| ICON_ADD, | ICON_ADD, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL); | nullptr); | ||||
| uiDefIconButO(block, | uiDefIconButO(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| "PALETTE_OT_color_delete", | "PALETTE_OT_color_delete", | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| ICON_REMOVE, | ICON_REMOVE, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL); | nullptr); | ||||
| if (palette->colors.first != NULL) { | if (palette->colors.first != nullptr) { | ||||
| but = uiDefIconButO(block, | but = uiDefIconButO(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| "PALETTE_OT_color_move", | "PALETTE_OT_color_move", | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| ICON_TRIA_UP, | ICON_TRIA_UP, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL); | nullptr); | ||||
| UI_but_operator_ptr_get(but); | UI_but_operator_ptr_get(but); | ||||
| RNA_enum_set(but->opptr, "type", -1); | RNA_enum_set(but->opptr, "type", -1); | ||||
| but = uiDefIconButO(block, | but = uiDefIconButO(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| "PALETTE_OT_color_move", | "PALETTE_OT_color_move", | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| ICON_TRIA_DOWN, | ICON_TRIA_DOWN, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL); | nullptr); | ||||
| UI_but_operator_ptr_get(but); | UI_but_operator_ptr_get(but); | ||||
| RNA_enum_set(but->opptr, "type", 1); | RNA_enum_set(but->opptr, "type", 1); | ||||
| /* Menu. */ | /* Menu. */ | ||||
| uiDefIconMenuBut( | uiDefIconMenuBut( | ||||
| block, ui_template_palette_menu, NULL, ICON_SORTSIZE, 0, 0, UI_UNIT_X, UI_UNIT_Y, ""); | block, ui_template_palette_menu, nullptr, ICON_SORTSIZE, 0, 0, UI_UNIT_X, UI_UNIT_Y, ""); | ||||
| } | } | ||||
| col = uiLayoutColumn(layout, true); | col = uiLayoutColumn(layout, true); | ||||
| uiLayoutRow(col, true); | uiLayoutRow(col, true); | ||||
| int row_cols = 0, col_id = 0; | int row_cols = 0, col_id = 0; | ||||
| LISTBASE_FOREACH (PaletteColor *, color, &palette->colors) { | LISTBASE_FOREACH (PaletteColor *, color, &palette->colors) { | ||||
| if (row_cols >= cols_per_row) { | if (row_cols >= cols_per_row) { | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Layer Buttons Template | /** \name Layer Buttons Template | ||||
| * \{ */ | * \{ */ | ||||
| static void handle_layer_buttons(bContext *C, void *arg1, void *arg2) | static void handle_layer_buttons(bContext *C, void *arg1, void *arg2) | ||||
| { | { | ||||
| uiBut *but = arg1; | uiBut *but = static_cast<uiBut *>(arg1); | ||||
| const int cur = POINTER_AS_INT(arg2); | const int cur = POINTER_AS_INT(arg2); | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| const bool shift = win->eventstate->modifier & KM_SHIFT; | const bool shift = win->eventstate->modifier & KM_SHIFT; | ||||
| if (!shift) { | if (!shift) { | ||||
| const int tot = RNA_property_array_length(&but->rnapoin, but->rnaprop); | const int tot = RNA_property_array_length(&but->rnapoin, but->rnaprop); | ||||
| /* Normally clicking only selects one layer */ | /* Normally clicking only selects one layer */ | ||||
| Show All 29 Lines | void uiTemplateLayers(uiLayout *layout, | ||||
| * - The number of columns (cols) is the total number of buttons per row the 'remainder' | * - The number of columns (cols) is the total number of buttons per row the 'remainder' | ||||
| * is added to this, as it will be ok to have first row slightly wider if need be. | * is added to this, as it will be ok to have first row slightly wider if need be. | ||||
| * - For now, only split into groups if group will have at least 5 items. | * - For now, only split into groups if group will have at least 5 items. | ||||
| */ | */ | ||||
| const int layers = RNA_property_array_length(ptr, prop); | const int layers = RNA_property_array_length(ptr, prop); | ||||
| const int cols = (layers / 2) + (layers % 2); | const int cols = (layers / 2) + (layers % 2); | ||||
| const int groups = ((cols / 2) < cols_per_group) ? (1) : (cols / cols_per_group); | const int groups = ((cols / 2) < cols_per_group) ? (1) : (cols / cols_per_group); | ||||
| PropertyRNA *used_prop = NULL; | PropertyRNA *used_prop = nullptr; | ||||
| if (used_ptr && used_propname) { | if (used_ptr && used_propname) { | ||||
| used_prop = RNA_struct_find_property(used_ptr, used_propname); | used_prop = RNA_struct_find_property(used_ptr, used_propname); | ||||
| if (!used_prop) { | if (!used_prop) { | ||||
| RNA_warning("used layers property not found: %s.%s", | RNA_warning("used layers property not found: %s.%s", | ||||
| RNA_struct_identifier(ptr->type), | RNA_struct_identifier(ptr->type), | ||||
| used_propname); | used_propname); | ||||
| return; | return; | ||||
| } | } | ||||
| if (RNA_property_array_length(used_ptr, used_prop) < layers) { | if (RNA_property_array_length(used_ptr, used_prop) < layers) { | ||||
| used_prop = NULL; | used_prop = nullptr; | ||||
| } | } | ||||
| } | } | ||||
| /* layers are laid out going across rows, with the columns being divided into groups */ | /* layers are laid out going across rows, with the columns being divided into groups */ | ||||
| for (int group = 0; group < groups; group++) { | for (int group = 0; group < groups; group++) { | ||||
| uiLayout *uCol = uiLayoutColumn(layout, true); | uiLayout *uCol = uiLayoutColumn(layout, true); | ||||
| Show All 33 Lines | |||||
| #define B_STOPCAST 2 | #define B_STOPCAST 2 | ||||
| #define B_STOPANIM 3 | #define B_STOPANIM 3 | ||||
| #define B_STOPCOMPO 4 | #define B_STOPCOMPO 4 | ||||
| #define B_STOPSEQ 5 | #define B_STOPSEQ 5 | ||||
| #define B_STOPCLIP 6 | #define B_STOPCLIP 6 | ||||
| #define B_STOPFILE 7 | #define B_STOPFILE 7 | ||||
| #define B_STOPOTHER 8 | #define B_STOPOTHER 8 | ||||
| static void do_running_jobs(bContext *C, void *UNUSED(arg), int event) | static void do_running_jobs(bContext *C, void * /*arg*/, int event) | ||||
| { | { | ||||
| switch (event) { | switch (event) { | ||||
| case B_STOPRENDER: | case B_STOPRENDER: | ||||
| G.is_break = true; | G.is_break = true; | ||||
| break; | break; | ||||
| case B_STOPCAST: | case B_STOPCAST: | ||||
| WM_jobs_stop(CTX_wm_manager(C), CTX_wm_screen(C), NULL); | WM_jobs_stop(CTX_wm_manager(C), CTX_wm_screen(C), nullptr); | ||||
| break; | break; | ||||
| case B_STOPANIM: | case B_STOPANIM: | ||||
| WM_operator_name_call(C, "SCREEN_OT_animation_play", WM_OP_INVOKE_SCREEN, NULL, NULL); | WM_operator_name_call(C, "SCREEN_OT_animation_play", WM_OP_INVOKE_SCREEN, nullptr, nullptr); | ||||
| break; | break; | ||||
| case B_STOPCOMPO: | case B_STOPCOMPO: | ||||
| WM_jobs_stop(CTX_wm_manager(C), CTX_data_scene(C), NULL); | WM_jobs_stop(CTX_wm_manager(C), CTX_data_scene(C), nullptr); | ||||
| break; | break; | ||||
| case B_STOPSEQ: | case B_STOPSEQ: | ||||
| WM_jobs_stop(CTX_wm_manager(C), CTX_data_scene(C), NULL); | WM_jobs_stop(CTX_wm_manager(C), CTX_data_scene(C), nullptr); | ||||
| break; | break; | ||||
| case B_STOPCLIP: | case B_STOPCLIP: | ||||
| WM_jobs_stop(CTX_wm_manager(C), CTX_data_scene(C), NULL); | WM_jobs_stop(CTX_wm_manager(C), CTX_data_scene(C), nullptr); | ||||
| break; | break; | ||||
| case B_STOPFILE: | case B_STOPFILE: | ||||
| WM_jobs_stop(CTX_wm_manager(C), CTX_data_scene(C), NULL); | WM_jobs_stop(CTX_wm_manager(C), CTX_data_scene(C), nullptr); | ||||
| break; | break; | ||||
| case B_STOPOTHER: | case B_STOPOTHER: | ||||
| G.is_break = true; | G.is_break = true; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| struct ProgressTooltip_Store { | struct ProgressTooltip_Store { | ||||
| wmWindowManager *wm; | wmWindowManager *wm; | ||||
| void *owner; | void *owner; | ||||
| }; | }; | ||||
| static char *progress_tooltip_func(bContext *UNUSED(C), void *argN, const char *UNUSED(tip)) | static char *progress_tooltip_func(bContext * /*C*/, void *argN, const char * /*tip*/) | ||||
| { | { | ||||
| struct ProgressTooltip_Store *arg = argN; | ProgressTooltip_Store *arg = static_cast<ProgressTooltip_Store *>(argN); | ||||
| wmWindowManager *wm = arg->wm; | wmWindowManager *wm = arg->wm; | ||||
| void *owner = arg->owner; | void *owner = arg->owner; | ||||
| const float progress = WM_jobs_progress(wm, owner); | const float progress = WM_jobs_progress(wm, owner); | ||||
| /* create tooltip text and associate it with the job */ | /* create tooltip text and associate it with the job */ | ||||
| char elapsed_str[32]; | char elapsed_str[32]; | ||||
| char remaining_str[32] = "Unknown"; | char remaining_str[32] = "Unknown"; | ||||
| Show All 12 Lines | return BLI_sprintfN( | ||||
| elapsed_str); | elapsed_str); | ||||
| } | } | ||||
| void uiTemplateRunningJobs(uiLayout *layout, bContext *C) | void uiTemplateRunningJobs(uiLayout *layout, bContext *C) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| void *owner = NULL; | void *owner = nullptr; | ||||
| int handle_event, icon = 0; | int handle_event, icon = 0; | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| UI_block_layout_set_current(block, layout); | UI_block_layout_set_current(block, layout); | ||||
| UI_block_func_handle_set(block, do_running_jobs, NULL); | UI_block_func_handle_set(block, do_running_jobs, nullptr); | ||||
| /* another scene can be rendering too, for example via compositor */ | /* another scene can be rendering too, for example via compositor */ | ||||
| LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { | LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { | ||||
| if (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY)) { | if (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY)) { | ||||
| handle_event = B_STOPOTHER; | handle_event = B_STOPOTHER; | ||||
| icon = ICON_NONE; | icon = ICON_NONE; | ||||
| owner = scene; | owner = scene; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | if (owner) { | ||||
| const 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); | uiLayout *row = uiLayoutRow(layout, false); | ||||
| block = uiLayoutGetBlock(row); | block = uiLayoutGetBlock(row); | ||||
| /* get percentage done and set it as the UI text */ | /* get percentage done and set it as the UI text */ | ||||
| const float progress = WM_jobs_progress(wm, owner); | const float progress = WM_jobs_progress(wm, owner); | ||||
| char text[8]; | char text[8]; | ||||
| BLI_snprintf(text, 8, "%d%%", (int)(progress * 100)); | BLI_snprintf(text, 8, "%d%%", int(progress * 100)); | ||||
| const char *name = active ? WM_jobs_name(wm, owner) : "Canceling..."; | const char *name = active ? WM_jobs_name(wm, owner) : "Canceling..."; | ||||
| /* job name and icon */ | /* job name and icon */ | ||||
| const int textwidth = UI_fontstyle_string_width(fstyle, name); | const int textwidth = UI_fontstyle_string_width(fstyle, name); | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| icon, | icon, | ||||
| name, | name, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| textwidth + UI_UNIT_X * 1.5f, | textwidth + UI_UNIT_X * 1.5f, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| ""); | ""); | ||||
| /* stick progress bar and cancel button together */ | /* stick progress bar and cancel button together */ | ||||
| row = uiLayoutRow(layout, true); | row = uiLayoutRow(layout, true); | ||||
| uiLayoutSetActive(row, active); | uiLayoutSetActive(row, active); | ||||
| block = uiLayoutGetBlock(row); | block = uiLayoutGetBlock(row); | ||||
| { | { | ||||
| struct ProgressTooltip_Store *tip_arg = MEM_mallocN(sizeof(*tip_arg), __func__); | ProgressTooltip_Store *tip_arg = static_cast<ProgressTooltip_Store *>( | ||||
| MEM_mallocN(sizeof(*tip_arg), __func__)); | |||||
| tip_arg->wm = wm; | tip_arg->wm = wm; | ||||
| tip_arg->owner = owner; | tip_arg->owner = owner; | ||||
| uiButProgressbar *but_progress = (uiButProgressbar *)uiDefIconTextBut(block, | uiButProgressbar *but_progress = (uiButProgressbar *)uiDefIconTextBut(block, | ||||
| UI_BTYPE_PROGRESS_BAR, | UI_BTYPE_PROGRESS_BAR, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| text, | text, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| 0, | 0, | ||||
| UI_UNIT_X * 6.0f, | UI_UNIT_X * 6.0f, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| 0, | 0, | ||||
| NULL); | nullptr); | ||||
| but_progress->progress = progress; | but_progress->progress = progress; | ||||
| UI_but_func_tooltip_set(&but_progress->but, progress_tooltip_func, tip_arg, MEM_freeN); | UI_but_func_tooltip_set(&but_progress->but, progress_tooltip_func, tip_arg, MEM_freeN); | ||||
| } | } | ||||
| if (!wm->is_interface_locked) { | if (!wm->is_interface_locked) { | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| handle_event, | handle_event, | ||||
| ICON_PANEL_CLOSE, | ICON_PANEL_CLOSE, | ||||
| "", | "", | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Stop this job")); | TIP_("Stop this job")); | ||||
| } | } | ||||
| } | } | ||||
| if (ED_screen_animation_no_scrub(wm)) { | if (ED_screen_animation_no_scrub(wm)) { | ||||
| uiDefIconTextBut(block, | uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| B_STOPANIM, | B_STOPANIM, | ||||
| ICON_CANCEL, | ICON_CANCEL, | ||||
| IFACE_("Anim Player"), | IFACE_("Anim Player"), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X * 5.0f, | UI_UNIT_X * 5.0f, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Stop animation playback")); | TIP_("Stop animation playback")); | ||||
| } | } | ||||
| } | } | ||||
| Show All 23 Lines | void uiTemplateReportsBanner(uiLayout *layout, bContext *C) | ||||
| } | } | ||||
| uiLayout *ui_abs = uiLayoutAbsolute(layout, false); | uiLayout *ui_abs = uiLayoutAbsolute(layout, false); | ||||
| uiBlock *block = uiLayoutGetBlock(ui_abs); | uiBlock *block = uiLayoutGetBlock(ui_abs); | ||||
| eUIEmbossType previous_emboss = UI_block_emboss_get(block); | eUIEmbossType previous_emboss = UI_block_emboss_get(block); | ||||
| UI_fontstyle_set(&style->widgetlabel); | UI_fontstyle_set(&style->widgetlabel); | ||||
| int width = BLF_width(style->widgetlabel.uifont_id, report->message, report->len); | int width = BLF_width(style->widgetlabel.uifont_id, report->message, report->len); | ||||
| width = min_ii((int)(rti->widthfac * width), width); | width = min_ii(int(rti->widthfac * width), width); | ||||
| width = max_ii(width, 10 * UI_DPI_FAC); | width = max_ii(width, 10 * UI_DPI_FAC); | ||||
| UI_block_align_begin(block); | UI_block_align_begin(block); | ||||
| /* Background for icon. */ | /* Background for icon. */ | ||||
| but = uiDefBut(block, | but = uiDefBut(block, | ||||
| UI_BTYPE_ROUNDBOX, | UI_BTYPE_ROUNDBOX, | ||||
| 0, | 0, | ||||
| "", | "", | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X + (6 * UI_DPI_FAC), | UI_UNIT_X + (6 * UI_DPI_FAC), | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| /* UI_BTYPE_ROUNDBOX's bg color is set in but->col. */ | /* UI_BTYPE_ROUNDBOX's bg color is set in but->col. */ | ||||
| UI_GetThemeColorType4ubv(UI_icon_colorid_from_report_type(report->type), SPACE_INFO, but->col); | UI_GetThemeColorType4ubv(UI_icon_colorid_from_report_type(report->type), SPACE_INFO, but->col); | ||||
| /* Background for the rest of the message. */ | /* Background for the rest of the message. */ | ||||
| but = uiDefBut(block, | but = uiDefBut(block, | ||||
| UI_BTYPE_ROUNDBOX, | UI_BTYPE_ROUNDBOX, | ||||
| 0, | 0, | ||||
| "", | "", | ||||
| UI_UNIT_X + (6 * UI_DPI_FAC), | UI_UNIT_X + (6 * UI_DPI_FAC), | ||||
| 0, | 0, | ||||
| UI_UNIT_X + width, | UI_UNIT_X + width, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0f, | 0.0f, | ||||
| 0.0f, | 0.0f, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| ""); | ""); | ||||
| /* Use icon background at low opacity to highlight, but still contrasting with area TH_TEXT. */ | /* Use icon background at low opacity to highlight, but still contrasting with area TH_TEXT. */ | ||||
| UI_GetThemeColorType4ubv(UI_icon_colorid_from_report_type(report->type), SPACE_INFO, but->col); | UI_GetThemeColorType4ubv(UI_icon_colorid_from_report_type(report->type), SPACE_INFO, but->col); | ||||
| Show All 26 Lines | but = uiDefButO(block, | ||||
| 0, | 0, | ||||
| width + UI_UNIT_X, | width + UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| TIP_("Show in Info Log")); | TIP_("Show in Info Log")); | ||||
| UI_block_emboss_set(block, previous_emboss); | UI_block_emboss_set(block, previous_emboss); | ||||
| } | } | ||||
| void uiTemplateInputStatus(uiLayout *layout, struct bContext *C) | void uiTemplateInputStatus(uiLayout *layout, bContext *C) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| WorkSpace *workspace = CTX_wm_workspace(C); | WorkSpace *workspace = CTX_wm_workspace(C); | ||||
| /* Workspace status text has priority. */ | /* Workspace status text has priority. */ | ||||
| if (workspace->status_text) { | if (workspace->status_text) { | ||||
| uiItemL(layout, workspace->status_text, ICON_NONE); | uiItemL(layout, workspace->status_text, ICON_NONE); | ||||
| return; | return; | ||||
| Show All 10 Lines | for (int i = 0; i < 3; i++) { | ||||
| uiLayout *row = uiLayoutRow(col, true); | uiLayout *row = uiLayoutRow(col, true); | ||||
| uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_LEFT); | uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_LEFT); | ||||
| const char *msg = CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, | const char *msg = CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, | ||||
| WM_window_cursor_keymap_status_get(win, i, 0)); | WM_window_cursor_keymap_status_get(win, i, 0)); | ||||
| const char *msg_drag = CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, | const char *msg_drag = CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, | ||||
| WM_window_cursor_keymap_status_get(win, i, 1)); | WM_window_cursor_keymap_status_get(win, i, 1)); | ||||
| if (msg || (msg_drag == NULL)) { | if (msg || (msg_drag == nullptr)) { | ||||
| uiItemL(row, msg ? msg : "", (ICON_MOUSE_LMB + i)); | uiItemL(row, msg ? msg : "", (ICON_MOUSE_LMB + i)); | ||||
| } | } | ||||
| if (msg_drag) { | if (msg_drag) { | ||||
| uiItemL(row, msg_drag, (ICON_MOUSE_LMB_DRAG + i)); | uiItemL(row, msg_drag, (ICON_MOUSE_LMB_DRAG + i)); | ||||
| } | } | ||||
| /* Use trick with empty string to keep icons in same position. */ | /* Use trick with empty string to keep icons in same position. */ | ||||
| row = uiLayoutRow(col, false); | row = uiLayoutRow(col, false); | ||||
| uiItemL(row, " ", ICON_NONE); | uiItemL(row, " ", ICON_NONE); | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Keymap Template | /** \name Keymap Template | ||||
| * \{ */ | * \{ */ | ||||
| static void keymap_item_modified(bContext *UNUSED(C), void *kmi_p, void *UNUSED(unused)) | static void keymap_item_modified(bContext * /*C*/, void *kmi_p, void * /*unused*/) | ||||
| { | { | ||||
| wmKeyMapItem *kmi = (wmKeyMapItem *)kmi_p; | wmKeyMapItem *kmi = (wmKeyMapItem *)kmi_p; | ||||
| WM_keyconfig_update_tag(NULL, kmi); | WM_keyconfig_update_tag(nullptr, kmi); | ||||
| } | } | ||||
| static void template_keymap_item_properties(uiLayout *layout, const char *title, PointerRNA *ptr) | static void template_keymap_item_properties(uiLayout *layout, const char *title, PointerRNA *ptr) | ||||
| { | { | ||||
| uiItemS(layout); | uiItemS(layout); | ||||
| if (title) { | if (title) { | ||||
| uiItemL(layout, title, ICON_NONE); | uiItemL(layout, title, ICON_NONE); | ||||
| Show All 16 Lines | if (RNA_property_type(prop) == PROP_POINTER) { | ||||
| } | } | ||||
| } | } | ||||
| uiLayout *box = uiLayoutBox(flow); | uiLayout *box = uiLayoutBox(flow); | ||||
| uiLayoutSetActive(box, is_set); | uiLayoutSetActive(box, is_set); | ||||
| uiLayout *row = uiLayoutRow(box, false); | uiLayout *row = uiLayoutRow(box, false); | ||||
| /* property value */ | /* property value */ | ||||
| uiItemFullR(row, ptr, prop, -1, 0, 0, NULL, ICON_NONE); | uiItemFullR(row, ptr, prop, -1, 0, 0, nullptr, ICON_NONE); | ||||
| if (is_set) { | if (is_set) { | ||||
| /* unset operator */ | /* unset operator */ | ||||
| uiBlock *block = uiLayoutGetBlock(row); | uiBlock *block = uiLayoutGetBlock(row); | ||||
| UI_block_emboss_set(block, UI_EMBOSS_NONE); | UI_block_emboss_set(block, UI_EMBOSS_NONE); | ||||
| but = uiDefIconButO(block, | but = uiDefIconButO(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| "UI_OT_unset_property_button", | "UI_OT_unset_property_button", | ||||
| WM_OP_EXEC_DEFAULT, | WM_OP_EXEC_DEFAULT, | ||||
| ICON_X, | ICON_X, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL); | nullptr); | ||||
| but->rnapoin = *ptr; | but->rnapoin = *ptr; | ||||
| but->rnaprop = prop; | but->rnaprop = prop; | ||||
| UI_block_emboss_set(block, UI_EMBOSS); | UI_block_emboss_set(block, UI_EMBOSS); | ||||
| } | } | ||||
| } | } | ||||
| RNA_STRUCT_END; | RNA_STRUCT_END; | ||||
| } | } | ||||
| void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr) | void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr) | ||||
| { | { | ||||
| PointerRNA propptr = RNA_pointer_get(ptr, "properties"); | PointerRNA propptr = RNA_pointer_get(ptr, "properties"); | ||||
| if (propptr.data) { | if (propptr.data) { | ||||
| uiBut *but = uiLayoutGetBlock(layout)->buttons.last; | uiBut *but = static_cast<uiBut *>(uiLayoutGetBlock(layout)->buttons.last); | ||||
| WM_operator_properties_sanitize(&propptr, false); | WM_operator_properties_sanitize(&propptr, false); | ||||
| template_keymap_item_properties(layout, NULL, &propptr); | template_keymap_item_properties(layout, nullptr, &propptr); | ||||
| /* attach callbacks to compensate for missing properties update, | /* attach callbacks to compensate for missing properties update, | ||||
| * we don't know which keymap (item) is being modified there */ | * we don't know which keymap (item) is being modified there */ | ||||
| for (; but; but = but->next) { | for (; but; but = but->next) { | ||||
| /* operator buttons may store props for use (file selector, T36492) */ | /* operator buttons may store props for use (file selector, T36492) */ | ||||
| if (but->rnaprop) { | if (but->rnaprop) { | ||||
| UI_but_func_set(but, keymap_item_modified, ptr->data, NULL); | UI_but_func_set(but, keymap_item_modified, ptr->data, nullptr); | ||||
| /* Otherwise the keymap will be re-generated which we're trying to edit, | /* Otherwise the keymap will be re-generated which we're trying to edit, | ||||
| * see: T47685 */ | * see: T47685 */ | ||||
| UI_but_flag_enable(but, UI_BUT_UPDATE_DELAY); | UI_but_flag_enable(but, UI_BUT_UPDATE_DELAY); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Event Icon Template | /** \name Event Icon Template | ||||
| * \{ */ | * \{ */ | ||||
| bool uiTemplateEventFromKeymapItem(struct uiLayout *layout, | bool uiTemplateEventFromKeymapItem(uiLayout *layout, | ||||
| const char *text, | const char *text, | ||||
| const struct wmKeyMapItem *kmi, | const wmKeyMapItem *kmi, | ||||
| bool text_fallback) | bool text_fallback) | ||||
| { | { | ||||
| bool ok = false; | bool ok = false; | ||||
| int icon_mod[4]; | int icon_mod[4]; | ||||
| #ifdef WITH_HEADLESS | #ifdef WITH_HEADLESS | ||||
| int icon = 0; | int icon = 0; | ||||
| #else | #else | ||||
| Show All 32 Lines | void uiTemplateColorspaceSettings(uiLayout *layout, PointerRNA *ptr, const char *propname) | ||||
| } | } | ||||
| PointerRNA colorspace_settings_ptr = RNA_property_pointer_get(ptr, prop); | PointerRNA colorspace_settings_ptr = RNA_property_pointer_get(ptr, prop); | ||||
| uiItemR(layout, &colorspace_settings_ptr, "name", 0, IFACE_("Color Space"), ICON_NONE); | uiItemR(layout, &colorspace_settings_ptr, "name", 0, IFACE_("Color Space"), ICON_NONE); | ||||
| } | } | ||||
| void uiTemplateColormanagedViewSettings(uiLayout *layout, | void uiTemplateColormanagedViewSettings(uiLayout *layout, | ||||
| bContext *UNUSED(C), | bContext * /*C*/, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| const char *propname) | const char *propname) | ||||
| { | { | ||||
| PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | PropertyRNA *prop = RNA_struct_find_property(ptr, propname); | ||||
| if (!prop) { | if (!prop) { | ||||
| printf( | printf( | ||||
| "%s: property not found: %s.%s\n", __func__, RNA_struct_identifier(ptr->type), propname); | "%s: property not found: %s.%s\n", __func__, RNA_struct_identifier(ptr->type), propname); | ||||
| return; | return; | ||||
| } | } | ||||
| PointerRNA view_transform_ptr = RNA_property_pointer_get(ptr, prop); | PointerRNA view_transform_ptr = RNA_property_pointer_get(ptr, prop); | ||||
| ColorManagedViewSettings *view_settings = view_transform_ptr.data; | ColorManagedViewSettings *view_settings = static_cast<ColorManagedViewSettings *>( | ||||
| view_transform_ptr.data); | |||||
| uiLayout *col = uiLayoutColumn(layout, false); | uiLayout *col = uiLayoutColumn(layout, false); | ||||
| uiItemR(col, &view_transform_ptr, "view_transform", 0, IFACE_("View"), ICON_NONE); | uiItemR(col, &view_transform_ptr, "view_transform", 0, IFACE_("View"), ICON_NONE); | ||||
| uiItemR(col, &view_transform_ptr, "look", 0, IFACE_("Look"), ICON_NONE); | uiItemR(col, &view_transform_ptr, "look", 0, IFACE_("Look"), ICON_NONE); | ||||
| col = uiLayoutColumn(layout, false); | col = uiLayoutColumn(layout, false); | ||||
| uiItemR(col, &view_transform_ptr, "exposure", 0, NULL, ICON_NONE); | uiItemR(col, &view_transform_ptr, "exposure", 0, nullptr, ICON_NONE); | ||||
| uiItemR(col, &view_transform_ptr, "gamma", 0, NULL, ICON_NONE); | uiItemR(col, &view_transform_ptr, "gamma", 0, nullptr, ICON_NONE); | ||||
| col = uiLayoutColumn(layout, false); | col = uiLayoutColumn(layout, false); | ||||
| uiItemR(col, &view_transform_ptr, "use_curve_mapping", 0, NULL, ICON_NONE); | uiItemR(col, &view_transform_ptr, "use_curve_mapping", 0, nullptr, ICON_NONE); | ||||
| if (view_settings->flag & COLORMANAGE_VIEW_USE_CURVES) { | if (view_settings->flag & COLORMANAGE_VIEW_USE_CURVES) { | ||||
| uiTemplateCurveMapping( | uiTemplateCurveMapping( | ||||
| col, &view_transform_ptr, "curve_mapping", 'c', true, false, false, false); | col, &view_transform_ptr, "curve_mapping", 'c', true, false, false, false); | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Component Menu | /** \name Component Menu | ||||
| * \{ */ | * \{ */ | ||||
| typedef struct ComponentMenuArgs { | struct ComponentMenuArgs { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| char propname[64]; /* XXX arbitrary */ | char propname[64]; /* XXX arbitrary */ | ||||
| } ComponentMenuArgs; | }; | ||||
| /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */ | /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */ | ||||
| static uiBlock *component_menu(bContext *C, ARegion *region, void *args_v) | static uiBlock *component_menu(bContext *C, ARegion *region, void *args_v) | ||||
| { | { | ||||
| ComponentMenuArgs *args = (ComponentMenuArgs *)args_v; | ComponentMenuArgs *args = (ComponentMenuArgs *)args_v; | ||||
| uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS); | uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS); | ||||
| UI_block_flag_enable(block, UI_BLOCK_KEEP_OPEN); | UI_block_flag_enable(block, UI_BLOCK_KEEP_OPEN); | ||||
| Show All 15 Lines | static uiBlock *component_menu(bContext *C, ARegion *region, void *args_v) | ||||
| return block; | return block; | ||||
| } | } | ||||
| void uiTemplateComponentMenu(uiLayout *layout, | void uiTemplateComponentMenu(uiLayout *layout, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| const char *propname, | const char *propname, | ||||
| const char *name) | const char *name) | ||||
| { | { | ||||
| ComponentMenuArgs *args = MEM_callocN(sizeof(ComponentMenuArgs), "component menu template args"); | ComponentMenuArgs *args = MEM_cnew<ComponentMenuArgs>(__func__); | ||||
| args->ptr = *ptr; | args->ptr = *ptr; | ||||
| BLI_strncpy(args->propname, propname, sizeof(args->propname)); | BLI_strncpy(args->propname, propname, sizeof(args->propname)); | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| UI_block_align_begin(block); | UI_block_align_begin(block); | ||||
| uiBut *but = uiDefBlockButN( | uiBut *but = uiDefBlockButN( | ||||
| block, component_menu, args, name, 0, 0, UI_UNIT_X * 6, UI_UNIT_Y, ""); | block, component_menu, args, name, 0, 0, UI_UNIT_X * 6, UI_UNIT_Y, ""); | ||||
| /* set rna directly, uiDefBlockButN doesn't do this */ | /* set rna directly, uiDefBlockButN doesn't do this */ | ||||
| but->rnapoin = *ptr; | but->rnapoin = *ptr; | ||||
| but->rnaprop = RNA_struct_find_property(ptr, propname); | but->rnaprop = RNA_struct_find_property(ptr, propname); | ||||
| but->rnaindex = 0; | but->rnaindex = 0; | ||||
| UI_block_align_end(block); | UI_block_align_end(block); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Node Socket Icon Template | /** \name Node Socket Icon Template | ||||
| * \{ */ | * \{ */ | ||||
| void uiTemplateNodeSocket(uiLayout *layout, bContext *UNUSED(C), float color[4]) | void uiTemplateNodeSocket(uiLayout *layout, bContext * /*C*/, float color[4]) | ||||
| { | { | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| UI_block_align_begin(block); | UI_block_align_begin(block); | ||||
| /* XXX using explicit socket colors is not quite ideal. | /* XXX using explicit socket colors is not quite ideal. | ||||
| * Eventually it should be possible to use theme colors for this purpose, | * Eventually it should be possible to use theme colors for this purpose, | ||||
| * but this requires a better design for extendable color palettes in user prefs. | * but this requires a better design for extendable color palettes in user prefs. | ||||
| */ | */ | ||||
| uiBut *but = uiDefBut( | uiBut *but = uiDefBut( | ||||
| block, UI_BTYPE_NODE_SOCKET, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); | block, UI_BTYPE_NODE_SOCKET, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, nullptr, 0, 0, 0, 0, ""); | ||||
| rgba_float_to_uchar(but->col, color); | rgba_float_to_uchar(but->col, color); | ||||
| UI_block_align_end(block); | UI_block_align_end(block); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Cache File Template | /** \name Cache File Template | ||||
| * \{ */ | * \{ */ | ||||
| void uiTemplateCacheFileVelocity(uiLayout *layout, PointerRNA *fileptr) | void uiTemplateCacheFileVelocity(uiLayout *layout, PointerRNA *fileptr) | ||||
| { | { | ||||
| if (RNA_pointer_is_null(fileptr)) { | if (RNA_pointer_is_null(fileptr)) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */ | /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */ | ||||
| uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr); | uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr); | ||||
| uiItemR(layout, fileptr, "velocity_name", 0, NULL, ICON_NONE); | uiItemR(layout, fileptr, "velocity_name", 0, nullptr, ICON_NONE); | ||||
| uiItemR(layout, fileptr, "velocity_unit", 0, NULL, ICON_NONE); | uiItemR(layout, fileptr, "velocity_unit", 0, nullptr, ICON_NONE); | ||||
| } | } | ||||
| void uiTemplateCacheFileProcedural(uiLayout *layout, const bContext *C, PointerRNA *fileptr) | void uiTemplateCacheFileProcedural(uiLayout *layout, const bContext *C, PointerRNA *fileptr) | ||||
| { | { | ||||
| if (RNA_pointer_is_null(fileptr)) { | if (RNA_pointer_is_null(fileptr)) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */ | /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */ | ||||
| uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr); | uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr); | ||||
| uiLayout *row, *sub; | uiLayout *row, *sub; | ||||
| /* Only enable render procedural option if the active engine supports it. */ | /* Only enable render procedural option if the active engine supports it. */ | ||||
| const struct RenderEngineType *engine_type = CTX_data_engine_type(C); | const RenderEngineType *engine_type = CTX_data_engine_type(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| const bool engine_supports_procedural = RE_engine_supports_alembic_procedural(engine_type, | const bool engine_supports_procedural = RE_engine_supports_alembic_procedural(engine_type, | ||||
| scene); | scene); | ||||
| if (!engine_supports_procedural) { | if (!engine_supports_procedural) { | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| /* For Cycles, verify that experimental features are enabled. */ | /* For Cycles, verify that experimental features are enabled. */ | ||||
| if (BKE_scene_uses_cycles(scene) && !BKE_scene_uses_cycles_experimental_features(scene)) { | if (BKE_scene_uses_cycles(scene) && !BKE_scene_uses_cycles_experimental_features(scene)) { | ||||
| uiItemL( | uiItemL( | ||||
| row, | row, | ||||
| TIP_( | TIP_( | ||||
| "The Cycles Alembic Procedural is only available with the experimental feature set"), | "The Cycles Alembic Procedural is only available with the experimental feature set"), | ||||
| ICON_INFO); | ICON_INFO); | ||||
| } | } | ||||
| else { | else { | ||||
| uiItemL( | uiItemL( | ||||
| row, TIP_("The active render engine does not have an Alembic Procedural"), ICON_INFO); | row, TIP_("The active render engine does not have an Alembic Procedural"), ICON_INFO); | ||||
| } | } | ||||
| } | } | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiLayoutSetActive(row, engine_supports_procedural); | uiLayoutSetActive(row, engine_supports_procedural); | ||||
| uiItemR(row, fileptr, "use_render_procedural", 0, NULL, ICON_NONE); | uiItemR(row, fileptr, "use_render_procedural", 0, nullptr, ICON_NONE); | ||||
| const bool use_render_procedural = RNA_boolean_get(fileptr, "use_render_procedural"); | const bool use_render_procedural = RNA_boolean_get(fileptr, "use_render_procedural"); | ||||
| const bool use_prefetch = RNA_boolean_get(fileptr, "use_prefetch"); | const bool use_prefetch = RNA_boolean_get(fileptr, "use_prefetch"); | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiLayoutSetEnabled(row, use_render_procedural); | uiLayoutSetEnabled(row, use_render_procedural); | ||||
| uiItemR(row, fileptr, "use_prefetch", 0, NULL, ICON_NONE); | uiItemR(row, fileptr, "use_prefetch", 0, nullptr, ICON_NONE); | ||||
| sub = uiLayoutRow(layout, false); | sub = uiLayoutRow(layout, false); | ||||
| uiLayoutSetEnabled(sub, use_prefetch && use_render_procedural); | uiLayoutSetEnabled(sub, use_prefetch && use_render_procedural); | ||||
| uiItemR(sub, fileptr, "prefetch_cache_size", 0, NULL, ICON_NONE); | uiItemR(sub, fileptr, "prefetch_cache_size", 0, nullptr, ICON_NONE); | ||||
| } | } | ||||
| void uiTemplateCacheFileTimeSettings(uiLayout *layout, PointerRNA *fileptr) | void uiTemplateCacheFileTimeSettings(uiLayout *layout, PointerRNA *fileptr) | ||||
| { | { | ||||
| if (RNA_pointer_is_null(fileptr)) { | if (RNA_pointer_is_null(fileptr)) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */ | /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */ | ||||
| uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr); | uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr); | ||||
| uiLayout *row, *sub, *subsub; | uiLayout *row, *sub, *subsub; | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiItemR(row, fileptr, "is_sequence", 0, NULL, ICON_NONE); | uiItemR(row, fileptr, "is_sequence", 0, nullptr, ICON_NONE); | ||||
| row = uiLayoutRowWithHeading(layout, true, IFACE_("Override Frame")); | row = uiLayoutRowWithHeading(layout, true, IFACE_("Override Frame")); | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetPropDecorate(sub, false); | uiLayoutSetPropDecorate(sub, false); | ||||
| uiItemR(sub, fileptr, "override_frame", 0, "", ICON_NONE); | uiItemR(sub, fileptr, "override_frame", 0, "", ICON_NONE); | ||||
| subsub = uiLayoutRow(sub, true); | subsub = uiLayoutRow(sub, true); | ||||
| uiLayoutSetActive(subsub, RNA_boolean_get(fileptr, "override_frame")); | uiLayoutSetActive(subsub, RNA_boolean_get(fileptr, "override_frame")); | ||||
| uiItemR(subsub, fileptr, "frame", 0, "", ICON_NONE); | uiItemR(subsub, fileptr, "frame", 0, "", ICON_NONE); | ||||
| uiItemDecoratorR(row, fileptr, "frame", 0); | uiItemDecoratorR(row, fileptr, "frame", 0); | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiItemR(row, fileptr, "frame_offset", 0, NULL, ICON_NONE); | uiItemR(row, fileptr, "frame_offset", 0, nullptr, ICON_NONE); | ||||
| uiLayoutSetActive(row, !RNA_boolean_get(fileptr, "is_sequence")); | uiLayoutSetActive(row, !RNA_boolean_get(fileptr, "is_sequence")); | ||||
| } | } | ||||
| static void cache_file_layer_item(uiList *UNUSED(ui_list), | static void cache_file_layer_item(uiList * /*ui_list*/, | ||||
| const bContext *UNUSED(C), | const bContext * /*C*/, | ||||
| uiLayout *layout, | uiLayout *layout, | ||||
| PointerRNA *UNUSED(dataptr), | PointerRNA * /*dataptr*/, | ||||
| PointerRNA *itemptr, | PointerRNA *itemptr, | ||||
| int UNUSED(icon), | int /*icon*/, | ||||
| PointerRNA *UNUSED(active_dataptr), | PointerRNA * /*active_dataptr*/, | ||||
| const char *UNUSED(active_propname), | const char * /*active_propname*/, | ||||
| int UNUSED(index), | int /*index*/, | ||||
| int UNUSED(flt_flag)) | int /*flt_flag*/) | ||||
| { | { | ||||
| uiLayout *row = uiLayoutRow(layout, true); | uiLayout *row = uiLayoutRow(layout, true); | ||||
| uiItemR(row, itemptr, "hide_layer", UI_ITEM_R_NO_BG, "", ICON_NONE); | uiItemR(row, itemptr, "hide_layer", UI_ITEM_R_NO_BG, "", ICON_NONE); | ||||
| uiItemR(row, itemptr, "filepath", UI_ITEM_R_NO_BG, "", ICON_NONE); | uiItemR(row, itemptr, "filepath", UI_ITEM_R_NO_BG, "", ICON_NONE); | ||||
| } | } | ||||
| uiListType *UI_UL_cache_file_layers() | uiListType *UI_UL_cache_file_layers() | ||||
| { | { | ||||
| Show All 31 Lines | uiTemplateList(col, | ||||
| UILST_LAYOUT_DEFAULT, | UILST_LAYOUT_DEFAULT, | ||||
| 1, | 1, | ||||
| UI_TEMPLATE_LIST_FLAG_NONE); | UI_TEMPLATE_LIST_FLAG_NONE); | ||||
| col = uiLayoutColumn(row, true); | col = uiLayoutColumn(row, true); | ||||
| uiItemO(col, "", ICON_ADD, "cachefile.layer_add"); | uiItemO(col, "", ICON_ADD, "cachefile.layer_add"); | ||||
| uiItemO(col, "", ICON_REMOVE, "cachefile.layer_remove"); | uiItemO(col, "", ICON_REMOVE, "cachefile.layer_remove"); | ||||
| CacheFile *file = fileptr->data; | CacheFile *file = static_cast<CacheFile *>(fileptr->data); | ||||
| if (BLI_listbase_count(&file->layers) > 1) { | if (BLI_listbase_count(&file->layers) > 1) { | ||||
| uiItemS_ex(col, 1.0f); | uiItemS_ex(col, 1.0f); | ||||
| uiItemO(col, "", ICON_TRIA_UP, "cachefile.layer_move"); | uiItemO(col, "", ICON_TRIA_UP, "cachefile.layer_move"); | ||||
| uiItemO(col, "", ICON_TRIA_DOWN, "cachefile.layer_move"); | uiItemO(col, "", ICON_TRIA_DOWN, "cachefile.layer_move"); | ||||
| } | } | ||||
| } | } | ||||
| bool uiTemplateCacheFilePointer(PointerRNA *ptr, const char *propname, PointerRNA *r_file_ptr) | bool uiTemplateCacheFilePointer(PointerRNA *ptr, const char *propname, PointerRNA *r_file_ptr) | ||||
| Show All 27 Lines | if (!ptr->data) { | ||||
| return; | return; | ||||
| } | } | ||||
| PointerRNA fileptr; | PointerRNA fileptr; | ||||
| if (!uiTemplateCacheFilePointer(ptr, propname, &fileptr)) { | if (!uiTemplateCacheFilePointer(ptr, propname, &fileptr)) { | ||||
| return; | return; | ||||
| } | } | ||||
| CacheFile *file = fileptr.data; | CacheFile *file = static_cast<CacheFile *>(fileptr.data); | ||||
| uiLayoutSetContextPointer(layout, "edit_cachefile", &fileptr); | uiLayoutSetContextPointer(layout, "edit_cachefile", &fileptr); | ||||
| uiTemplateID(layout, | uiTemplateID(layout, | ||||
| C, | C, | ||||
| ptr, | ptr, | ||||
| propname, | propname, | ||||
| NULL, | nullptr, | ||||
| "CACHEFILE_OT_open", | "CACHEFILE_OT_open", | ||||
| NULL, | nullptr, | ||||
| UI_TEMPLATE_ID_FILTER_ALL, | UI_TEMPLATE_ID_FILTER_ALL, | ||||
| false, | false, | ||||
| NULL); | nullptr); | ||||
| if (!file) { | if (!file) { | ||||
| return; | return; | ||||
| } | } | ||||
| SpaceProperties *sbuts = CTX_wm_space_properties(C); | SpaceProperties *sbuts = CTX_wm_space_properties(C); | ||||
| uiLayout *row, *sub; | uiLayout *row, *sub; | ||||
| uiLayoutSetPropSep(layout, true); | uiLayoutSetPropSep(layout, true); | ||||
| row = uiLayoutRow(layout, true); | row = uiLayoutRow(layout, true); | ||||
| uiItemR(row, &fileptr, "filepath", 0, NULL, ICON_NONE); | uiItemR(row, &fileptr, "filepath", 0, nullptr, ICON_NONE); | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| uiItemO(sub, "", ICON_FILE_REFRESH, "cachefile.reload"); | uiItemO(sub, "", ICON_FILE_REFRESH, "cachefile.reload"); | ||||
| if (sbuts->mainb == BCONTEXT_CONSTRAINT) { | if (sbuts->mainb == BCONTEXT_CONSTRAINT) { | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| uiItemR(row, &fileptr, "scale", 0, IFACE_("Manual Scale"), ICON_NONE); | uiItemR(row, &fileptr, "scale", 0, IFACE_("Manual Scale"), ICON_NONE); | ||||
| } | } | ||||
| Show All 22 Lines | LISTBASE_FOREACH_INDEX (RecentFile *, recent, &G.recent_files, i) { | ||||
| } | } | ||||
| const char *filename = BLI_path_basename(recent->filepath); | const char *filename = BLI_path_basename(recent->filepath); | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| uiItemFullO(layout, | uiItemFullO(layout, | ||||
| "WM_OT_open_mainfile", | "WM_OT_open_mainfile", | ||||
| filename, | filename, | ||||
| BLO_has_bfile_extension(filename) ? ICON_FILE_BLEND : ICON_FILE_BACKUP, | BLO_has_bfile_extension(filename) ? ICON_FILE_BLEND : ICON_FILE_BACKUP, | ||||
| NULL, | nullptr, | ||||
| WM_OP_INVOKE_DEFAULT, | WM_OP_INVOKE_DEFAULT, | ||||
| 0, | 0, | ||||
| &ptr); | &ptr); | ||||
| RNA_string_set(&ptr, "filepath", recent->filepath); | RNA_string_set(&ptr, "filepath", recent->filepath); | ||||
| RNA_boolean_set(&ptr, "display_file_selector", false); | RNA_boolean_set(&ptr, "display_file_selector", false); | ||||
| } | } | ||||
| return i; | return i; | ||||
| Show All 17 Lines | |||||