Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_templates.c
| Show All 33 Lines | |||||
| #include "DNA_cachefile_types.h" | #include "DNA_cachefile_types.h" | ||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_object_force_types.h" | #include "DNA_object_force_types.h" | ||||
| #include "DNA_brush_types.h" | #include "DNA_brush_types.h" | ||||
| #include "DNA_texture_types.h" | #include "DNA_texture_types.h" | ||||
| #include "DNA_gpencil_modifier_types.h" | |||||
| #include "DNA_shader_fx_types.h" | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_alloca.h" | #include "BLI_alloca.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "BLI_rect.h" | #include "BLI_rect.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_fnmatch.h" | #include "BLI_fnmatch.h" | ||||
| #include "BLI_timecode.h" | #include "BLI_timecode.h" | ||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "BKE_colorband.h" | #include "BKE_colorband.h" | ||||
| #include "BKE_colortools.h" | #include "BKE_colortools.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_gpencil_modifier.h" | |||||
| #include "BKE_idcode.h" | #include "BKE_idcode.h" | ||||
| #include "BKE_idprop.h" | #include "BKE_idprop.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_library_override.h" | #include "BKE_library_override.h" | ||||
| #include "BKE_linestyle.h" | #include "BKE_linestyle.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_packedFile.h" | #include "BKE_packedFile.h" | ||||
| #include "BKE_particle.h" | #include "BKE_particle.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_shader_fx.h" | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_build.h" | #include "DEG_depsgraph_build.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_object.h" | #include "ED_object.h" | ||||
| #include "ED_render.h" | #include "ED_render.h" | ||||
| #include "ED_undo.h" | #include "ED_undo.h" | ||||
| Show All 23 Lines | |||||
| /** | /** | ||||
| * Add a block button for the search menu for templateID and templateSearch. | * Add a block button for the search menu for templateID and templateSearch. | ||||
| */ | */ | ||||
| static void template_add_button_search_menu( | static void template_add_button_search_menu( | ||||
| const bContext *C, uiLayout *layout, uiBlock *block, | const bContext *C, uiLayout *layout, uiBlock *block, | ||||
| PointerRNA *ptr, PropertyRNA *prop, | PointerRNA *ptr, PropertyRNA *prop, | ||||
| uiBlockCreateFunc block_func, void *block_argN, const char * const tip, | uiBlockCreateFunc block_func, void *block_argN, const char * const tip, | ||||
| const bool use_previews, const bool editable) | const bool use_previews, const bool editable, const bool live_icon) | ||||
| { | { | ||||
| PointerRNA active_ptr = RNA_property_pointer_get(ptr, prop); | 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)) ? active_ptr.data : NULL; | ||||
| const ID *idfrom = ptr->id.data; | const ID *idfrom = ptr->id.data; | ||||
| 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) { | ||||
| Show All 19 Lines | if (use_previews) { | ||||
| 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); | ||||
| if (use_big_size) { | if (use_big_size) { | ||||
| uiLayoutRow(layout, true); | uiLayoutRow(layout, true); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| but = uiDefBlockButN(block, block_func, block_argN, "", 0, 0, UI_UNIT_X * 1.6, UI_UNIT_Y, tip); | but = uiDefBlockButN(block, block_func, block_argN, "", 0, 0, UI_UNIT_X * 1.6, UI_UNIT_Y, tip); | ||||
| if (live_icon) { | |||||
| int icon = id ? ui_id_icon_get(C, id, false) : RNA_struct_ui_icon(type); | |||||
| ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW); | |||||
| } | |||||
| else { | |||||
| ui_def_but_icon(but, RNA_struct_ui_icon(type), UI_HAS_ICON); | ui_def_but_icon(but, RNA_struct_ui_icon(type), UI_HAS_ICON); | ||||
| } | |||||
| if (id) { | if (id) { | ||||
| /* default dragging of icon for id browse buttons */ | /* default dragging of icon for id browse buttons */ | ||||
| UI_but_drag_set_id(but, id); | UI_but_drag_set_id(but, id); | ||||
| } | } | ||||
| UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT); | UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT); | ||||
| 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); | ||||
| } | } | ||||
| } | } | ||||
| static uiBlock *template_common_search_menu( | static uiBlock *template_common_search_menu( | ||||
| const bContext *C, ARegion *region, | const bContext *C, ARegion *region, | ||||
| uiButSearchFunc search_func, void *search_arg, | uiButSearchFunc search_func, void *search_arg, | ||||
| uiButHandleFunc handle_func, void *active_item, | uiButHandleFunc handle_func, void *active_item, | ||||
| const int preview_rows, const int preview_cols) | const int preview_rows, const int preview_cols, | ||||
| float scale) | |||||
| { | { | ||||
| static char search[256]; | static char search[256]; | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but; | uiBut *but; | ||||
| /* clear initial search string, then all items show */ | /* clear initial search string, then all items show */ | ||||
| search[0] = 0; | search[0] = 0; | ||||
| block = UI_block_begin(C, region, "_popup", UI_EMBOSS); | block = UI_block_begin(C, region, "_popup", UI_EMBOSS); | ||||
| UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_SEARCH_MENU); | UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_SEARCH_MENU); | ||||
| /* 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; | const int w = 4 * U.widget_unit * preview_cols * scale; | ||||
| const int h = 5 * U.widget_unit * preview_rows; | 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, NULL, 0, 0, 0, 0, NULL); | ||||
| but = uiDefSearchBut( | but = uiDefSearchBut( | ||||
| block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, w, UI_UNIT_Y, | block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, w, UI_UNIT_Y, | ||||
| preview_rows, preview_cols, ""); | preview_rows, preview_cols, ""); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | typedef 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; | |||||
| } TemplateID; | } TemplateID; | ||||
| /* Search browse menu, assign */ | /* Search browse menu, assign */ | ||||
| static void template_ID_set_property_cb(bContext *C, void *arg_template, void *item) | static void template_ID_set_property_cb(bContext *C, void *arg_template, void *item) | ||||
| { | { | ||||
| TemplateID *template_ui = (TemplateID *)arg_template; | TemplateID *template_ui = (TemplateID *)arg_template; | ||||
| /* ID */ | /* ID */ | ||||
| ▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | if (template_ui.idcode == ID_OB) { | ||||
| if (template_ui.filter == UI_TEMPLATE_ID_FILTER_AVAILABLE) { | if (template_ui.filter == UI_TEMPLATE_ID_FILTER_AVAILABLE) { | ||||
| id_search_cb_p = id_search_cb_objects_from_scene; | id_search_cb_p = id_search_cb_objects_from_scene; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return template_common_search_menu( | return template_common_search_menu( | ||||
| C, ar, id_search_cb_p, &template_ui, template_ID_set_property_cb, active_item_ptr.data, | C, ar, id_search_cb_p, &template_ui, template_ID_set_property_cb, active_item_ptr.data, | ||||
| template_ui.prv_rows, template_ui.prv_cols); | template_ui.prv_rows, template_ui.prv_cols, template_ui.scale); | ||||
| } | } | ||||
| /************************ ID Template ***************************/ | /************************ ID Template ***************************/ | ||||
| /* This is for browsing and editing the ID-blocks used */ | /* This is for browsing and editing the ID-blocks used */ | ||||
| /* for new/open operators */ | /* for new/open operators */ | ||||
| void UI_context_active_but_prop_get_templateID( | void UI_context_active_but_prop_get_templateID( | ||||
| bContext *C, | bContext *C, | ||||
| ▲ Show 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | #ifndef WITH_INTERNATIONAL | ||||
| UNUSED_VARS(type); | UNUSED_VARS(type); | ||||
| #endif | #endif | ||||
| return but; | return but; | ||||
| } | } | ||||
| static void template_ID( | static void template_ID( | ||||
| bContext *C, uiLayout *layout, TemplateID *template_ui, StructRNA *type, int flag, | bContext *C, uiLayout *layout, TemplateID *template_ui, StructRNA *type, int flag, | ||||
| const char *newop, const char *openop, const char *unlinkop) | const char *newop, const char *openop, const char *unlinkop, | ||||
| float scale, const bool live_icon) | |||||
| { | { | ||||
| uiBut *but; | uiBut *but; | ||||
| uiBlock *block; | uiBlock *block; | ||||
| PointerRNA idptr; | PointerRNA idptr; | ||||
| // ListBase *lb; // UNUSED | // ListBase *lb; // UNUSED | ||||
| ID *id, *idfrom; | ID *id, *idfrom; | ||||
| 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; | ||||
| idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop); | idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop); | ||||
| id = idptr.data; | id = idptr.data; | ||||
| idfrom = template_ui->ptr.id.data; | idfrom = template_ui->ptr.id.data; | ||||
| // lb = template_ui->idlb; | // lb = template_ui->idlb; | ||||
| block = uiLayoutGetBlock(layout); | block = uiLayoutGetBlock(layout); | ||||
| UI_block_align_begin(block); | UI_block_align_begin(block); | ||||
| if (idptr.type) | if (idptr.type) | ||||
| type = idptr.type; | type = idptr.type; | ||||
| if (flag & UI_ID_BROWSE) { | if (flag & UI_ID_BROWSE) { | ||||
| template_add_button_search_menu( | template_add_button_search_menu( | ||||
| C, layout, block, &template_ui->ptr, template_ui->prop, | C, layout, block, &template_ui->ptr, template_ui->prop, | ||||
| id_search_menu, MEM_dupallocN(template_ui), TIP_(template_id_browse_tip(type)), | id_search_menu, MEM_dupallocN(template_ui), TIP_(template_id_browse_tip(type)), | ||||
| use_previews, editable); | use_previews, editable, live_icon); | ||||
| } | } | ||||
| /* text button with name */ | /* text button with name */ | ||||
| if (id) { | if (id) { | ||||
| char name[UI_MAX_NAME_STR]; | char name[UI_MAX_NAME_STR]; | ||||
| const bool user_alert = (id->us <= 0); | const bool user_alert = (id->us <= 0); | ||||
| //text_idbutton(id, name); | //text_idbutton(id, name); | ||||
| ▲ Show 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | if (flag & UI_ID_ADD_NEW) { | ||||
| UI_but_drawflag_enable(but, but_align); | UI_but_drawflag_enable(but, but_align); | ||||
| } | } | ||||
| } | } | ||||
| static void ui_template_id( | static void ui_template_id( | ||||
| uiLayout *layout, bContext *C, | uiLayout *layout, bContext *C, | ||||
| PointerRNA *ptr, const char *propname, | PointerRNA *ptr, const char *propname, | ||||
| const char *newop, const char *openop, const char *unlinkop, | const char *newop, const char *openop, const char *unlinkop, | ||||
| int flag, int prv_rows, int prv_cols, int filter, bool use_tabs) | int flag, int prv_rows, int prv_cols, int filter, bool use_tabs, | ||||
| float scale, bool live_icon) | |||||
| { | { | ||||
| TemplateID *template_ui; | TemplateID *template_ui; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| StructRNA *type; | StructRNA *type; | ||||
| short idcode; | short idcode; | ||||
| prop = RNA_struct_find_property(ptr, propname); | 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; | ||||
| } | } | ||||
| template_ui = MEM_callocN(sizeof(TemplateID), "TemplateID"); | template_ui = MEM_callocN(sizeof(TemplateID), "TemplateID"); | ||||
| 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; | |||||
| if ((flag & UI_ID_PIN) == 0) { | if ((flag & UI_ID_PIN) == 0) { | ||||
| template_ui->filter = filter; | template_ui->filter = filter; | ||||
| } | } | ||||
| else { | else { | ||||
| template_ui->filter = 0; | template_ui->filter = 0; | ||||
| } | } | ||||
| Show All 12 Lines | static void ui_template_id( | ||||
| */ | */ | ||||
| if (template_ui->idlb) { | if (template_ui->idlb) { | ||||
| if (use_tabs) { | if (use_tabs) { | ||||
| uiLayoutRow(layout, true); | uiLayoutRow(layout, true); | ||||
| template_ID_tabs(C, layout, template_ui, type, flag, newop, openop, unlinkop); | template_ID_tabs(C, layout, template_ui, type, flag, newop, openop, unlinkop); | ||||
| } | } | ||||
| else { | else { | ||||
| uiLayoutRow(layout, true); | uiLayoutRow(layout, true); | ||||
| template_ID(C, layout, template_ui, type, flag, newop, openop, unlinkop); | template_ID(C, layout, template_ui, type, flag, newop, openop, unlinkop, scale, live_icon); | ||||
| } | } | ||||
| } | } | ||||
| MEM_freeN(template_ui); | MEM_freeN(template_ui); | ||||
| } | } | ||||
| void uiTemplateID( | void uiTemplateID( | ||||
| uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop, | uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop, | ||||
| const char *openop, const char *unlinkop, int filter) | const char *openop, const char *unlinkop, | ||||
| int filter, const bool live_icon) | |||||
| { | { | ||||
| ui_template_id( | ui_template_id( | ||||
| layout, C, ptr, propname, | layout, C, ptr, propname, | ||||
| newop, openop, unlinkop, | newop, openop, unlinkop, | ||||
| UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, | UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, | ||||
| 0, 0, filter, false); | 0, 0, filter, false, 1.0f, live_icon); | ||||
| } | } | ||||
| void uiTemplateIDBrowse( | void uiTemplateIDBrowse( | ||||
| uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop, | uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop, | ||||
| const char *openop, const char *unlinkop, int filter) | const char *openop, const char *unlinkop, int filter) | ||||
| { | { | ||||
| ui_template_id( | ui_template_id( | ||||
| layout, C, ptr, propname, | layout, C, ptr, propname, | ||||
| newop, openop, unlinkop, | newop, openop, unlinkop, | ||||
| UI_ID_BROWSE | UI_ID_RENAME, | UI_ID_BROWSE | UI_ID_RENAME, | ||||
| 0, 0, filter, false); | 0, 0, filter, false, 1.0f, false); | ||||
| } | } | ||||
| void uiTemplateIDPreview( | void uiTemplateIDPreview( | ||||
| uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop, | uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop, | ||||
| const char *openop, const char *unlinkop, int rows, int cols, int filter) | const char *openop, const char *unlinkop, int rows, int cols, int filter) | ||||
| { | { | ||||
| ui_template_id( | ui_template_id( | ||||
| layout, C, ptr, propname, | layout, C, ptr, propname, | ||||
| newop, openop, unlinkop, | newop, openop, unlinkop, | ||||
| 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, cols, filter, false); | rows, cols, filter, false, 1.0f, false); | ||||
| } | |||||
| void uiTemplateGpencilColorPreview( | |||||
| uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, | |||||
| int rows, int cols, float scale, int filter) | |||||
| { | |||||
| ui_template_id( | |||||
| layout, C, ptr, propname, | |||||
| NULL, NULL, NULL, | |||||
| UI_ID_BROWSE | UI_ID_PREVIEWS | UI_ID_DELETE, | |||||
| rows, cols, filter, false, scale < 0.5f ? 0.5f : scale, false); | |||||
| } | } | ||||
| /** | /** | ||||
| * Version of #uiTemplateID using tabs. | * Version of #uiTemplateID using tabs. | ||||
| */ | */ | ||||
| void uiTemplateIDTabs( | void uiTemplateIDTabs( | ||||
| uiLayout *layout, bContext *C, | uiLayout *layout, bContext *C, | ||||
| PointerRNA *ptr, const char *propname, | PointerRNA *ptr, const char *propname, | ||||
| const char *newop, const char *openop, const char *unlinkop, | const char *newop, const char *openop, const char *unlinkop, | ||||
| int filter) | int filter) | ||||
| { | { | ||||
| ui_template_id( | ui_template_id( | ||||
| layout, C, ptr, propname, | layout, C, ptr, propname, | ||||
| newop, openop, unlinkop, | newop, openop, unlinkop, | ||||
| UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, | UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, | ||||
| 0, 0, filter, true); | 0, 0, filter, true, 1.0f, false); | ||||
| } | } | ||||
| /************************ ID Chooser Template ***************************/ | /************************ ID Chooser Template ***************************/ | ||||
| /** | /** | ||||
| * This is for selecting the type of ID-block to use, and then from the relevant type choosing the block to use | * This is for selecting the type of ID-block to use, and then from the relevant type choosing the block to use | ||||
| * | * | ||||
| * - propname: property identifier for property that ID-pointer gets stored to | * - propname: property identifier for property that ID-pointer gets stored to | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | static uiBlock *template_search_menu(bContext *C, ARegion *region, void *arg_template) | ||||
| template_search = *((TemplateSearch *)arg_template); | template_search = *((TemplateSearch *)arg_template); | ||||
| active_ptr = RNA_property_pointer_get( | active_ptr = RNA_property_pointer_get( | ||||
| &template_search.search_data.target_ptr, | &template_search.search_data.target_ptr, | ||||
| template_search.search_data.target_prop); | template_search.search_data.target_prop); | ||||
| return template_common_search_menu( | return template_common_search_menu( | ||||
| C, region, ui_rna_collection_search_cb, &template_search, | C, region, ui_rna_collection_search_cb, &template_search, | ||||
| template_search_handle_cb, active_ptr.data, | template_search_handle_cb, active_ptr.data, | ||||
| template_search.preview_rows, template_search.preview_cols); | template_search.preview_rows, template_search.preview_cols, 1.0f); | ||||
| } | } | ||||
| static void template_search_add_button_searchmenu( | static void template_search_add_button_searchmenu( | ||||
| const bContext *C, uiLayout *layout, uiBlock *block, | const bContext *C, uiLayout *layout, uiBlock *block, | ||||
| TemplateSearch *template_search, const bool editable) | TemplateSearch *template_search, const bool editable, const bool live_icon) | ||||
| { | { | ||||
| const char *ui_description = RNA_property_ui_description(template_search->search_data.target_prop); | const char *ui_description = RNA_property_ui_description(template_search->search_data.target_prop); | ||||
| template_add_button_search_menu( | template_add_button_search_menu( | ||||
| C, layout, block, | C, layout, block, | ||||
| &template_search->search_data.target_ptr, template_search->search_data.target_prop, | &template_search->search_data.target_ptr, template_search->search_data.target_prop, | ||||
| template_search_menu, MEM_dupallocN(template_search), ui_description, | template_search_menu, MEM_dupallocN(template_search), ui_description, | ||||
| template_search->use_previews, editable); | template_search->use_previews, editable, live_icon); | ||||
| } | } | ||||
| static void template_search_add_button_name( | static void template_search_add_button_name( | ||||
| uiBlock *block, PointerRNA *active_ptr, const StructRNA *type) | uiBlock *block, PointerRNA *active_ptr, const StructRNA *type) | ||||
| { | { | ||||
| uiDefAutoButR( | uiDefAutoButR( | ||||
| block, active_ptr, RNA_struct_name_property(type), 0, "", ICON_NONE, | block, active_ptr, RNA_struct_name_property(type), 0, "", ICON_NONE, | ||||
| 0, 0, TEMPLATE_SEARCH_TEXTBUT_WIDTH, TEMPLATE_SEARCH_TEXTBUT_HEIGHT); | 0, 0, TEMPLATE_SEARCH_TEXTBUT_WIDTH, TEMPLATE_SEARCH_TEXTBUT_HEIGHT); | ||||
| Show All 29 Lines | static void template_search_buttons( | ||||
| if (active_ptr.type) { | if (active_ptr.type) { | ||||
| /* can only get correct type when there is an active item */ | /* can only get correct type when there is an active item */ | ||||
| type = active_ptr.type; | type = active_ptr.type; | ||||
| } | } | ||||
| uiLayoutRow(layout, true); | uiLayoutRow(layout, true); | ||||
| UI_block_align_begin(block); | UI_block_align_begin(block); | ||||
| template_search_add_button_searchmenu(C, layout, block, template_search, editable); | template_search_add_button_searchmenu(C, layout, block, template_search, editable, false); | ||||
| template_search_add_button_name(block, &active_ptr, type); | template_search_add_button_name(block, &active_ptr, type); | ||||
| template_search_add_button_operator(block, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN, editable); | template_search_add_button_operator(block, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN, editable); | ||||
| template_search_add_button_operator(block, unlinkop, WM_OP_INVOKE_REGION_WIN, ICON_X, editable); | template_search_add_button_operator(block, unlinkop, WM_OP_INVOKE_REGION_WIN, ICON_X, editable); | ||||
| UI_block_align_end(block); | UI_block_align_end(block); | ||||
| } | } | ||||
| static PropertyRNA *template_search_get_searchprop( | static PropertyRNA *template_search_get_searchprop( | ||||
| ▲ Show 20 Lines • Show All 406 Lines • ▼ Show 20 Lines | if (md == vmd) | ||||
| return draw_modifier(layout, scene, ob, md, i, cageIndex, lastCageIndex); | return draw_modifier(layout, scene, ob, md, i, cageIndex, lastCageIndex); | ||||
| else if (vmd->mode & eModifierMode_Virtual) | else if (vmd->mode & eModifierMode_Virtual) | ||||
| i--; | i--; | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /************************ Grease Pencil Modifier Template *************************/ | |||||
| static uiLayout *gpencil_draw_modifier(uiLayout *layout, Object *ob, | |||||
| GpencilModifierData *md) | |||||
| { | |||||
| const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type); | |||||
| PointerRNA ptr; | |||||
| uiBlock *block; | |||||
| uiLayout *box, *column, *row, *sub; | |||||
| uiLayout *result = NULL; | |||||
| /* create RNA pointer */ | |||||
| RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr); | |||||
| column = uiLayoutColumn(layout, true); | |||||
| uiLayoutSetContextPointer(column, "modifier", &ptr); | |||||
| /* rounded header ------------------------------------------------------------------- */ | |||||
| box = uiLayoutBox(column); | |||||
| row = uiLayoutRow(box, false); | |||||
| block = uiLayoutGetBlock(row); | |||||
| UI_block_emboss_set(block, UI_EMBOSS_NONE); | |||||
| /* Open/Close ................................. */ | |||||
| uiItemR(row, &ptr, "show_expanded", 0, "", ICON_NONE); | |||||
| /* modifier-type icon */ | |||||
| uiItemL(row, "", RNA_struct_ui_icon(ptr.type)); | |||||
| UI_block_emboss_set(block, UI_EMBOSS); | |||||
| /* modifier name */ | |||||
| if (mti->isDisabled && mti->isDisabled(md, 0)) { | |||||
| uiLayoutSetRedAlert(row, true); | |||||
| } | |||||
| uiItemR(row, &ptr, "name", 0, "", ICON_NONE); | |||||
| uiLayoutSetRedAlert(row, false); | |||||
| /* mode enabling buttons */ | |||||
| UI_block_align_begin(block); | |||||
| uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE); | |||||
| uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE); | |||||
| if (mti->flags & eGpencilModifierTypeFlag_SupportsEditmode) { | |||||
| sub = uiLayoutRow(row, true); | |||||
| uiLayoutSetActive(sub, false); | |||||
| uiItemR(sub, &ptr, "show_in_editmode", 0, "", ICON_NONE); | |||||
| } | |||||
| UI_block_align_end(block); | |||||
| /* Up/Down + Delete ........................... */ | |||||
| UI_block_align_begin(block); | |||||
| uiItemO(row, "", ICON_TRIA_UP, "OBJECT_OT_gpencil_modifier_move_up"); | |||||
| uiItemO(row, "", ICON_TRIA_DOWN, "OBJECT_OT_gpencil_modifier_move_down"); | |||||
| UI_block_align_end(block); | |||||
| UI_block_emboss_set(block, UI_EMBOSS_NONE); | |||||
| uiItemO(row, "", ICON_X, "OBJECT_OT_gpencil_modifier_remove"); | |||||
| UI_block_emboss_set(block, UI_EMBOSS); | |||||
| /* modifier settings (under the header) --------------------------------------------------- */ | |||||
| if (md->mode & eGpencilModifierMode_Expanded) { | |||||
| /* apply/convert/copy */ | |||||
| box = uiLayoutBox(column); | |||||
| row = uiLayoutRow(box, false); | |||||
| /* only here obdata, the rest of modifiers is ob level */ | |||||
| UI_block_lock_set(block, BKE_object_obdata_is_libdata(ob), ERROR_LIBDATA_MESSAGE); | |||||
| uiLayoutSetOperatorContext(row, WM_OP_INVOKE_DEFAULT); | |||||
| uiItemEnumO(row, "OBJECT_OT_gpencil_modifier_apply", CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply"), | |||||
| 0, "apply_as", MODIFIER_APPLY_DATA); | |||||
| uiItemO(row, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy"), ICON_NONE, | |||||
| "OBJECT_OT_gpencil_modifier_copy"); | |||||
| /* result is the layout block inside the box, that we return so that modifier settings can be drawn */ | |||||
| result = uiLayoutColumn(box, false); | |||||
| block = uiLayoutAbsoluteBlock(box); | |||||
| } | |||||
| /* error messages */ | |||||
| if (md->error) { | |||||
| box = uiLayoutBox(column); | |||||
| row = uiLayoutRow(box, false); | |||||
| uiItemL(row, md->error, ICON_ERROR); | |||||
| } | |||||
| return result; | |||||
| } | |||||
| uiLayout *uiTemplateGpencilModifier(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | |||||
| { | |||||
| Object *ob; | |||||
| GpencilModifierData *md, *vmd; | |||||
| int i; | |||||
| /* verify we have valid data */ | |||||
| if (!RNA_struct_is_a(ptr->type, &RNA_GpencilModifier)) { | |||||
| RNA_warning("Expected modifier on object"); | |||||
| return NULL; | |||||
| } | |||||
| ob = ptr->id.data; | |||||
| md = ptr->data; | |||||
| if (!ob || !(GS(ob->id.name) == ID_OB)) { | |||||
| RNA_warning("Expected modifier on object"); | |||||
| return NULL; | |||||
| } | |||||
| UI_block_lock_set(uiLayoutGetBlock(layout), (ob && ID_IS_LINKED(ob)), ERROR_LIBDATA_MESSAGE); | |||||
| /* find modifier and draw it */ | |||||
| vmd = ob->greasepencil_modifiers.first; | |||||
| for (i = 0; vmd; i++, vmd = vmd->next) { | |||||
| if (md == vmd) | |||||
| return gpencil_draw_modifier(layout, ob, md); | |||||
| } | |||||
| return NULL; | |||||
| } | |||||
| /************************ Shader FX Template *************************/ | |||||
| static uiLayout *gpencil_draw_shaderfx(uiLayout *layout, Object *ob, | |||||
| ShaderFxData *md) | |||||
| { | |||||
| const ShaderFxTypeInfo *mti = BKE_shaderfxType_getInfo(md->type); | |||||
| PointerRNA ptr; | |||||
| uiBlock *block; | |||||
| uiLayout *box, *column, *row, *sub; | |||||
| uiLayout *result = NULL; | |||||
| /* create RNA pointer */ | |||||
| RNA_pointer_create(&ob->id, &RNA_ShaderFx, md, &ptr); | |||||
| column = uiLayoutColumn(layout, true); | |||||
| uiLayoutSetContextPointer(column, "shaderfx", &ptr); | |||||
| /* rounded header ------------------------------------------------------------------- */ | |||||
| box = uiLayoutBox(column); | |||||
| row = uiLayoutRow(box, false); | |||||
| block = uiLayoutGetBlock(row); | |||||
| UI_block_emboss_set(block, UI_EMBOSS_NONE); | |||||
| /* Open/Close ................................. */ | |||||
| uiItemR(row, &ptr, "show_expanded", 0, "", ICON_NONE); | |||||
| /* shader-type icon */ | |||||
| uiItemL(row, "", RNA_struct_ui_icon(ptr.type)); | |||||
| UI_block_emboss_set(block, UI_EMBOSS); | |||||
| /* effect name */ | |||||
| if (mti->isDisabled && mti->isDisabled(md, 0)) { | |||||
| uiLayoutSetRedAlert(row, true); | |||||
| } | |||||
| uiItemR(row, &ptr, "name", 0, "", ICON_NONE); | |||||
| uiLayoutSetRedAlert(row, false); | |||||
| /* mode enabling buttons */ | |||||
| UI_block_align_begin(block); | |||||
| uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE); | |||||
| uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE); | |||||
| if (mti->flags & eShaderFxTypeFlag_SupportsEditmode) { | |||||
| sub = uiLayoutRow(row, true); | |||||
| uiLayoutSetActive(sub, false); | |||||
| uiItemR(sub, &ptr, "show_in_editmode", 0, "", ICON_NONE); | |||||
| } | |||||
| UI_block_align_end(block); | |||||
| /* Up/Down + Delete ........................... */ | |||||
| UI_block_align_begin(block); | |||||
| uiItemO(row, "", ICON_TRIA_UP, "OBJECT_OT_shaderfx_move_up"); | |||||
| uiItemO(row, "", ICON_TRIA_DOWN, "OBJECT_OT_shaderfx_move_down"); | |||||
| UI_block_align_end(block); | |||||
| UI_block_emboss_set(block, UI_EMBOSS_NONE); | |||||
| uiItemO(row, "", ICON_X, "OBJECT_OT_shaderfx_remove"); | |||||
| UI_block_emboss_set(block, UI_EMBOSS); | |||||
| /* effect settings (under the header) --------------------------------------------------- */ | |||||
| if (md->mode & eShaderFxMode_Expanded) { | |||||
| /* apply/convert/copy */ | |||||
| box = uiLayoutBox(column); | |||||
| row = uiLayoutRow(box, false); | |||||
| /* only here obdata, the rest of effect is ob level */ | |||||
| UI_block_lock_set(block, BKE_object_obdata_is_libdata(ob), ERROR_LIBDATA_MESSAGE); | |||||
| /* result is the layout block inside the box, that we return so that effect settings can be drawn */ | |||||
| result = uiLayoutColumn(box, false); | |||||
| block = uiLayoutAbsoluteBlock(box); | |||||
| } | |||||
| /* error messages */ | |||||
| if (md->error) { | |||||
| box = uiLayoutBox(column); | |||||
| row = uiLayoutRow(box, false); | |||||
| uiItemL(row, md->error, ICON_ERROR); | |||||
| } | |||||
| return result; | |||||
| } | |||||
| uiLayout *uiTemplateShaderFx(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | |||||
| { | |||||
| Object *ob; | |||||
| ShaderFxData *fx, *vfx; | |||||
| int i; | |||||
| /* verify we have valid data */ | |||||
| if (!RNA_struct_is_a(ptr->type, &RNA_ShaderFx)) { | |||||
| RNA_warning("Expected shader fx on object"); | |||||
| return NULL; | |||||
| } | |||||
| ob = ptr->id.data; | |||||
| fx = ptr->data; | |||||
| if (!ob || !(GS(ob->id.name) == ID_OB)) { | |||||
| RNA_warning("Expected shader fx on object"); | |||||
| return NULL; | |||||
| } | |||||
| UI_block_lock_set(uiLayoutGetBlock(layout), (ob && ID_IS_LINKED(ob)), ERROR_LIBDATA_MESSAGE); | |||||
| /* find modifier and draw it */ | |||||
| vfx = ob->shader_fx.first; | |||||
| for (i = 0; vfx; i++, vfx = vfx->next) { | |||||
| if (fx == vfx) | |||||
| return gpencil_draw_shaderfx(layout, ob, fx); | |||||
| } | |||||
| return NULL; | |||||
| } | |||||
| /************************ Redo Buttons Template *************************/ | /************************ Redo Buttons Template *************************/ | ||||
| static bool template_operator_redo_property_buts_poll(PointerRNA *UNUSED(ptr), PropertyRNA *prop) | static bool template_operator_redo_property_buts_poll(PointerRNA *UNUSED(ptr), PropertyRNA *prop) | ||||
| { | { | ||||
| return (RNA_property_tags(prop) & OP_PROP_TAG_ADVANCED) == 0; | return (RNA_property_tags(prop) & OP_PROP_TAG_ADVANCED) == 0; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 3,051 Lines • ▼ Show 20 Lines | if (RNA_property_type(prop) != PROP_POINTER) { | ||||
| return; | return; | ||||
| } | } | ||||
| PointerRNA fileptr = RNA_property_pointer_get(ptr, prop); | PointerRNA fileptr = RNA_property_pointer_get(ptr, prop); | ||||
| CacheFile *file = fileptr.data; | CacheFile *file = fileptr.data; | ||||
| uiLayoutSetContextPointer(layout, "edit_cachefile", &fileptr); | uiLayoutSetContextPointer(layout, "edit_cachefile", &fileptr); | ||||
| uiTemplateID(layout, C, ptr, propname, NULL, "CACHEFILE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL); | uiTemplateID(layout, C, ptr, propname, NULL, "CACHEFILE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); | ||||
| if (!file) { | if (!file) { | ||||
| return; | return; | ||||
| } | } | ||||
| SpaceButs *sbuts = CTX_wm_space_buts(C); | SpaceButs *sbuts = CTX_wm_space_buts(C); | ||||
| uiLayout *row = uiLayoutRow(layout, false); | uiLayout *row = uiLayoutRow(layout, false); | ||||
| Show All 39 Lines | |||||