Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_templates.c
| Show First 20 Lines • Show All 2,289 Lines • ▼ Show 20 Lines | static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(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 it's own update | * owner of the curve mapping can still define it's 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); | ||||
| } | } | ||||
| static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v) | enum { | ||||
| CB_FUNC_FLIP, | |||||
| CB_FUNC_DISTRIBUTE_LR, | |||||
| CB_FUNC_DISTRIBUTE_EVENLY, | |||||
| CB_FUNC_RESET, | |||||
| }; | |||||
| static void colorband_flip_cb(bContext *C, ColorBand *coba) | |||||
| { | { | ||||
| ColorBand *coba = coba_v; | CBData data_tmp[MAXCOLORBAND]; | ||||
| float pos = 0.5f; | |||||
| if (coba->tot > 1) { | int a; | ||||
| if (coba->cur > 0) pos = (coba->data[coba->cur - 1].pos + coba->data[coba->cur].pos) * 0.5f; | |||||
| else pos = (coba->data[coba->cur + 1].pos + coba->data[coba->cur].pos) * 0.5f; | 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]; | |||||
| } | } | ||||
| if (BKE_colorband_element_add(coba, pos)) { | /* may as well flip the cur*/ | ||||
| rna_update_cb(C, cb_v, NULL); | coba->cur = coba->tot - (coba->cur + 1); | ||||
| ED_undo_push(C, "Add colorband"); | |||||
| 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_del_cb(bContext *C, void *cb_v, void *coba_v) | static void colorband_tools_dofunc(bContext *C, void *coba_v, int event) | ||||
| { | { | ||||
| ColorBand *coba = coba_v; | ColorBand *coba = coba_v; | ||||
| if (BKE_colorband_element_remove(coba, coba->cur)) { | switch (event) { | ||||
| ED_undo_push(C, "Delete colorband"); | case CB_FUNC_FLIP: | ||||
| rna_update_cb(C, cb_v, NULL); | 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 void colorband_flip_cb(bContext *C, void *cb_v, void *coba_v) | static uiBlock *colorband_tools_func( | ||||
| bContext *C, ARegion *ar, ColorBand *coba) | |||||
| { | { | ||||
| CBData data_tmp[MAXCOLORBAND]; | uiBut *bt; | ||||
| uiBlock *block; | |||||
| short yco = 0, menuwidth = 10 * UI_UNIT_X; | |||||
| ColorBand *coba = coba_v; | block = UI_block_begin(C, ar, __func__, UI_EMBOSS); | ||||
| int a; | UI_block_func_butmenu_set(block, colorband_tools_dofunc, coba); | ||||
| for (a = 0; a < coba->tot; a++) { | { | ||||
| data_tmp[a] = coba->data[coba->tot - (a + 1)]; | 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, ""); | |||||
brecht: Colorband is the old internal name, we call the color ramps in the UI. | |||||
| 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, ""); | |||||
| bt = 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, ""); | |||||
| bt->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, ""); | |||||
| } | } | ||||
| for (a = 0; a < coba->tot; a++) { | |||||
| data_tmp[a].pos = 1.0f - data_tmp[a].pos; | UI_block_direction_set(block, UI_DIR_DOWN); | ||||
| coba->data[a] = data_tmp[a]; | UI_block_bounds_set_text(block, 3.0f * UI_UNIT_X); | ||||
| return block; | |||||
| } | } | ||||
| /* may as well flip the cur*/ | static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v) | ||||
| coba->cur = coba->tot - (coba->cur + 1); | { | ||||
| ColorBand *coba = coba_v; | |||||
| float pos = 0.5f; | |||||
| ED_undo_push(C, "Flip colorband"); | if (coba->tot > 1) { | ||||
| if (coba->cur > 0) pos = (coba->data[coba->cur - 1].pos + coba->data[coba->cur].pos) * 0.5f; | |||||
| else pos = (coba->data[coba->cur + 1].pos + coba->data[coba->cur].pos) * 0.5f; | |||||
| } | |||||
| if (BKE_colorband_element_add(coba, pos)) { | |||||
| rna_update_cb(C, cb_v, NULL); | |||||
| ED_undo_push(C, "Add Color Ramp Stop"); | |||||
| } | |||||
| } | |||||
| 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 Color Ramp Stop"); | |||||
| rna_update_cb(C, cb_v, NULL); | rna_update_cb(C, cb_v, NULL); | ||||
| } | } | ||||
| } | |||||
| static void colorband_update_cb(bContext *UNUSED(C), void *bt_v, void *coba_v) | static void colorband_update_cb(bContext *UNUSED(C), void *bt_v, void *coba_v) | ||||
| { | { | ||||
| uiBut *bt = bt_v; | uiBut *bt = bt_v; | ||||
| ColorBand *coba = coba_v; | ColorBand *coba = coba_v; | ||||
| /* sneaky update here, we need to sort the colorband points to be in order, | /* sneaky update here, we need to sort the colorband 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 */ | ||||
| Show All 17 Lines | static void colorband_buttons_layout( | ||||
| split = uiLayoutSplit(layout, 0.4f, false); | split = uiLayoutSplit(layout, 0.4f, false); | ||||
| UI_block_emboss_set(block, UI_EMBOSS_NONE); | UI_block_emboss_set(block, UI_EMBOSS_NONE); | ||||
| UI_block_align_begin(block); | UI_block_align_begin(block); | ||||
| row = uiLayoutRow(split, false); | row = uiLayoutRow(split, false); | ||||
| bt = uiDefIconTextBut( | bt = uiDefIconTextBut( | ||||
| block, UI_BTYPE_BUT, 0, ICON_ADD, "", 0, 0, 2.0f * unit, UI_UNIT_Y, NULL, | 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); | UI_but_funcN_set(bt, colorband_add_cb, MEM_dupallocN(cb), coba); | ||||
| bt = uiDefIconTextBut( | bt = uiDefIconTextBut( | ||||
| block, UI_BTYPE_BUT, 0, ICON_REMOVE, "", xs + 2.0f * unit, ys + UI_UNIT_Y, 2.0f * unit, UI_UNIT_Y, | block, UI_BTYPE_BUT, 0, ICON_REMOVE, "", xs + 2.0f * unit, ys + UI_UNIT_Y, 2.0f * unit, UI_UNIT_Y, | ||||
| NULL, 0, 0, 0, 0, TIP_("Delete the active position")); | NULL, 0, 0, 0, 0, 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 = uiDefIconTextBut( | bt = uiDefIconBlockBut( | ||||
| block, UI_BTYPE_BUT, 0, ICON_ARROW_LEFTRIGHT, "", xs + 4.0f * unit, ys + UI_UNIT_Y, 2.0f * unit, UI_UNIT_Y, | block, colorband_tools_func, coba, 0, ICON_DOWNARROW_HLT, | ||||
| NULL, 0, 0, 0, 0, TIP_("Flip the color ramp")); | xs + 4.0f * unit, ys + UI_UNIT_Y, 2.0f * unit, UI_UNIT_Y, TIP_("Tools")); | ||||
| UI_but_funcN_set(bt, colorband_flip_cb, MEM_dupallocN(cb), coba); | UI_but_funcN_set(bt, rna_update_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); | |||||
| UI_block_align_end(block); | UI_block_align_end(block); | ||||
| UI_block_emboss_set(block, UI_EMBOSS); | UI_block_emboss_set(block, UI_EMBOSS); | ||||
| row = uiLayoutRow(split, false); | row = uiLayoutRow(split, false); | ||||
| UI_block_align_begin(block); | UI_block_align_begin(block); | ||||
| uiItemR(row, &ptr, "color_mode", 0, "", ICON_NONE); | uiItemR(row, &ptr, "color_mode", 0, "", ICON_NONE); | ||||
| ▲ Show 20 Lines • Show All 512 Lines • ▼ Show 20 Lines | static uiBlock *curvemap_tools_func( | ||||
| } | } | ||||
| { | { | ||||
| uiDefIconTextBut( | uiDefIconTextBut( | ||||
| block, UI_BTYPE_BUT_MENU, 1, ICON_BLANK1, IFACE_("Reset Curve"), | block, UI_BTYPE_BUT_MENU, 1, ICON_BLANK1, IFACE_("Reset Curve"), | ||||
| 0, yco -= UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, reset_mode, ""); | 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_direction_set(block, UI_DIR_DOWN); | ||||
| UI_block_bounds_set_text(block, 50); | UI_block_bounds_set_text(block, 3.0f * UI_UNIT_X); | ||||
| return block; | return block; | ||||
| } | } | ||||
| static uiBlock *curvemap_tools_posslope_func(bContext *C, ARegion *ar, void *cumap_v) | static uiBlock *curvemap_tools_posslope_func(bContext *C, ARegion *ar, void *cumap_v) | ||||
| { | { | ||||
| return curvemap_tools_func(C, ar, cumap_v, true, UICURVE_FUNC_RESET_POS); | return curvemap_tools_func(C, ar, cumap_v, true, UICURVE_FUNC_RESET_POS); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 2,079 Lines • Show Last 20 Lines | |||||
Colorband is the old internal name, we call the color ramps in the UI.