diff options
Diffstat (limited to 'source/blender/editors/interface/interface_templates.c')
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 183 |
1 files changed, 130 insertions, 53 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 5bdf8f45832..5b9f9b1faf3 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -993,14 +993,14 @@ void uiTemplateIDPreview( } void uiTemplateGpencilColorPreview( - uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, - int rows, int cols, float scale, int filter) + 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, false); + 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, false); } /** @@ -1355,7 +1355,7 @@ static int modifier_is_simulation(ModifierData *md) { /* Physic Tab */ if (ELEM(md->type, eModifierType_Cloth, eModifierType_Collision, eModifierType_Fluidsim, eModifierType_Smoke, - eModifierType_Softbody, eModifierType_Surface, eModifierType_DynamicPaint)) + eModifierType_Softbody, eModifierType_Surface, eModifierType_DynamicPaint)) { return 1; } @@ -1533,7 +1533,7 @@ static uiLayout *draw_modifier( UI_block_lock_set(block, ob && ID_IS_LINKED(ob), ERROR_LIBDATA_MESSAGE); if (!ELEM(md->type, eModifierType_Fluidsim, eModifierType_Softbody, eModifierType_ParticleSystem, - eModifierType_Cloth, eModifierType_Smoke)) + eModifierType_Cloth, eModifierType_Smoke)) { uiItemO(row, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy"), ICON_NONE, "OBJECT_OT_modifier_copy"); @@ -1636,8 +1636,8 @@ static uiLayout *gpencil_draw_modifier( /* mode enabling buttons */ UI_block_align_begin(block); - uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE); - uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE); + 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); @@ -1675,7 +1675,7 @@ static uiLayout *gpencil_draw_modifier( uiItemEnumO(sub, "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"); + "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); @@ -1726,8 +1726,9 @@ uiLayout *uiTemplateGpencilModifier(uiLayout *layout, bContext *UNUSED(C), Point /************************ Shader FX Template *************************/ -static uiLayout *gpencil_draw_shaderfx(uiLayout *layout, Object *ob, - ShaderFxData *md) +static uiLayout *gpencil_draw_shaderfx( + uiLayout *layout, Object *ob, + ShaderFxData *md) { const ShaderFxTypeInfo *mti = BKE_shaderfxType_getInfo(md->type); PointerRNA ptr; @@ -2295,6 +2296,110 @@ static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg)) RNA_property_update(C, &cb->ptr, cb->prop); } +enum { + CB_FUNC_FLIP, + CB_FUNC_DISTRIBUTE_LR, + CB_FUNC_DISTRIBUTE_EVENLY, + CB_FUNC_RESET, +}; + +static void colorband_flip_cb(bContext *C, ColorBand *coba) +{ + CBData data_tmp[MAXCOLORBAND]; + + int a; + + for (a = 0; a < coba->tot; a++) { + data_tmp[a] = coba->data[coba->tot - (a + 1)]; + } + for (a = 0; a < coba->tot; a++) { + data_tmp[a].pos = 1.0f - data_tmp[a].pos; + coba->data[a] = data_tmp[a]; + } + + /* may as well flip the cur*/ + coba->cur = coba->tot - (coba->cur + 1); + + ED_undo_push(C, "Flip Color Ramp"); +} + +static void colorband_distribute_cb(bContext *C, ColorBand *coba, bool evenly) +{ + if (coba->tot > 1) { + int a; + int tot = evenly ? coba->tot - 1 : coba->tot; + float gap = 1.0f / tot; + float pos = 0.0f; + for (a = 0; a < coba->tot; a++) { + coba->data[a].pos = pos; + pos += gap; + } + ED_undo_push(C, evenly ? "Distribute Stops Evenly" : "Distribute Stops from Left"); + } +} + +static void colorband_tools_dofunc(bContext *C, void *coba_v, int event) +{ + ColorBand *coba = coba_v; + + switch (event) { + case CB_FUNC_FLIP: + colorband_flip_cb(C, coba); + break; + case CB_FUNC_DISTRIBUTE_LR: + colorband_distribute_cb(C, coba, false); + break; + case CB_FUNC_DISTRIBUTE_EVENLY: + colorband_distribute_cb(C, coba, true); + break; + case CB_FUNC_RESET: + BKE_colorband_init(coba, true); + ED_undo_push(C, "Reset Color Ramp"); + break; + } + ED_region_tag_redraw(CTX_wm_region(C)); +} + +static uiBlock *colorband_tools_func( + bContext *C, ARegion *ar, void *coba_v) +{ + ColorBand *coba = coba_v; + uiBlock *block; + short yco = 0, menuwidth = 10 * UI_UNIT_X; + + block = UI_block_begin(C, ar, __func__, UI_EMBOSS); + UI_block_func_butmenu_set(block, colorband_tools_dofunc, coba); + + { + uiBut *but; + uiDefIconTextBut( + block, UI_BTYPE_BUT_MENU, 1, ICON_BLANK1, + IFACE_("Flip Color Ramp"), 0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, + NULL, 0.0, 0.0, 0, CB_FUNC_FLIP, ""); + uiDefIconTextBut( + block, UI_BTYPE_BUT_MENU, 1, ICON_BLANK1, + IFACE_("Distribute Stops from Left"), 0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, + NULL, 0.0, 0.0, 0, CB_FUNC_DISTRIBUTE_LR, ""); + uiDefIconTextBut( + block, UI_BTYPE_BUT_MENU, 1, ICON_BLANK1, + IFACE_("Distribute Stops Evenly"), 0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, + NULL, 0.0, 0.0, 0, CB_FUNC_DISTRIBUTE_EVENLY, ""); + but = uiDefIconTextButO( + block, UI_BTYPE_BUT_MENU, "UI_OT_eyedropper_colorband", WM_OP_INVOKE_DEFAULT, ICON_EYEDROPPER, + IFACE_("Eyedropper"), 0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, + ""); + but->custom_data = coba; + uiDefIconTextBut( + block, UI_BTYPE_BUT_MENU, 1, ICON_BLANK1, IFACE_("Reset Color Ramp"), + 0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, CB_FUNC_RESET, ""); + } + + UI_block_direction_set(block, UI_DIR_DOWN); + UI_block_bounds_set_text(block, 3.0f * UI_UNIT_X); + + return block; +} + static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v) { ColorBand *coba = coba_v; @@ -2307,7 +2412,7 @@ static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v) if (BKE_colorband_element_add(coba, pos)) { rna_update_cb(C, cb_v, NULL); - ED_undo_push(C, "Add colorband"); + ED_undo_push(C, "Add Color Ramp Stop"); } } @@ -2316,34 +2421,11 @@ static void colorband_del_cb(bContext *C, void *cb_v, void *coba_v) ColorBand *coba = coba_v; if (BKE_colorband_element_remove(coba, coba->cur)) { - ED_undo_push(C, "Delete colorband"); + ED_undo_push(C, "Delete Color Ramp Stop"); rna_update_cb(C, cb_v, NULL); } } -static void colorband_flip_cb(bContext *C, void *cb_v, void *coba_v) -{ - CBData data_tmp[MAXCOLORBAND]; - - ColorBand *coba = coba_v; - int a; - - for (a = 0; a < coba->tot; a++) { - data_tmp[a] = coba->data[coba->tot - (a + 1)]; - } - for (a = 0; a < coba->tot; a++) { - data_tmp[a].pos = 1.0f - data_tmp[a].pos; - coba->data[a] = data_tmp[a]; - } - - /* may as well flip the cur*/ - coba->cur = coba->tot - (coba->cur + 1); - - ED_undo_push(C, "Flip colorband"); - - rna_update_cb(C, cb_v, NULL); -} - static void colorband_update_cb(bContext *UNUSED(C), void *bt_v, void *coba_v) { uiBut *bt = bt_v; @@ -2376,8 +2458,7 @@ static void colorband_buttons_layout( bt = uiDefIconTextBut( block, UI_BTYPE_BUT, 0, ICON_ADD, "", 0, 0, 2.0f * unit, UI_UNIT_Y, NULL, - 0, 0, 0, 0, TIP_("Add a new color stop to the colorband")); - + 0, 0, 0, 0, TIP_("Add a new color stop to the color ramp")); UI_but_funcN_set(bt, colorband_add_cb, MEM_dupallocN(cb), coba); bt = uiDefIconTextBut( @@ -2385,14 +2466,10 @@ static void colorband_buttons_layout( NULL, 0, 0, 0, 0, TIP_("Delete the active position")); UI_but_funcN_set(bt, colorband_del_cb, MEM_dupallocN(cb), coba); - bt = uiDefIconTextBut( - block, UI_BTYPE_BUT, 0, ICON_ARROW_LEFTRIGHT, "", xs + 4.0f * unit, ys + UI_UNIT_Y, 2.0f * unit, UI_UNIT_Y, - NULL, 0, 0, 0, 0, TIP_("Flip the color ramp")); - UI_but_funcN_set(bt, colorband_flip_cb, MEM_dupallocN(cb), coba); - - bt = uiDefIconButO(block, UI_BTYPE_BUT, "UI_OT_eyedropper_colorband", WM_OP_INVOKE_DEFAULT, ICON_EYEDROPPER, xs + 6.0f * unit, ys + UI_UNIT_Y, UI_UNIT_X, UI_UNIT_Y, NULL); - bt->custom_data = coba; - bt->func_argN = MEM_dupallocN(cb); + bt = uiDefIconBlockBut( + block, colorband_tools_func, coba, 0, ICON_DOWNARROW_HLT, + xs + 4.0f * unit, ys + UI_UNIT_Y, 2.0f * unit, UI_UNIT_Y, TIP_("Tools")); + UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), coba); UI_block_align_end(block); UI_block_emboss_set(block, UI_EMBOSS); @@ -2921,8 +2998,8 @@ static uiBlock *curvemap_tools_func( 0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, reset_mode, ""); } - UI_block_direction_set(block, UI_DIR_RIGHT); - UI_block_bounds_set_text(block, 50); + UI_block_direction_set(block, UI_DIR_DOWN); + UI_block_bounds_set_text(block, 3.0f * UI_UNIT_X); return block; } @@ -3507,7 +3584,7 @@ static void uilist_draw_filter_default(struct uiList *ui_list, struct bContext * subrow = uiLayoutRow(row, true); uiItemR(subrow, &listptr, "use_filter_sort_alpha", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_NONE); uiItemR(subrow, &listptr, "use_filter_sort_reverse", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", - (ui_list->filter_sort_flag & UILST_FLT_SORT_REVERSE) ? ICON_SORT_DESC : ICON_SORT_ASC); + (ui_list->filter_sort_flag & UILST_FLT_SORT_REVERSE) ? ICON_SORT_DESC : ICON_SORT_ASC); } } @@ -4224,8 +4301,8 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char /* check for hotkey */ if (len < sizeof(name) - 6) { if (WM_key_event_operator_string( - C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, true, - &name[len + 1], sizeof(name) - len - 1)) + C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, true, + &name[len + 1], sizeof(name) - len - 1)) { name[len] = UI_SEP_CHAR; } |