Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_templates.c
| Show First 20 Lines • Show All 4,105 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name CurveMapping Template | /** \name CurveMapping Template | ||||
| * \{ */ | * \{ */ | ||||
| #define CURVE_ZOOM_MAX (1.0f / 25.0f) | |||||
| static bool curvemap_can_zoom_out(CurveMapping *cumap) | |||||
| { | |||||
| return BLI_rctf_size_x(&cumap->curr) < BLI_rctf_size_x(&cumap->clipr); | |||||
| } | |||||
| static bool curvemap_can_zoom_in(CurveMapping *cumap) | |||||
| { | |||||
| 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 *UNUSED(arg)) | ||||
| { | { | ||||
| CurveMapping *cumap = cumap_v; | CurveMapping *cumap = cumap_v; | ||||
| /* we allow 20 times zoom */ | if (curvemap_can_zoom_in(cumap)) { | ||||
| if (BLI_rctf_size_x(&cumap->curr) > 0.04f * BLI_rctf_size_x(&cumap->clipr)) { | |||||
| 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(unused)) | ||||
| { | { | ||||
| CurveMapping *cumap = cumap_v; | CurveMapping *cumap = cumap_v; | ||||
| float d, d1; | float d, d1; | ||||
| /* we allow 20 times zoom, but don't view outside clip */ | if (curvemap_can_zoom_out(cumap)) { | ||||
| if (BLI_rctf_size_x(&cumap->curr) < 20.0f * BLI_rctf_size_x(&cumap->clipr)) { | |||||
| 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; | ||||
| } | } | ||||
| } | } | ||||
| cumap->curr.xmin -= d1; | cumap->curr.xmin -= d1; | ||||
| ▲ Show 20 Lines • Show All 471 Lines • ▼ Show 20 Lines | bt = uiDefIconBut(block, | ||||
| dx, | dx, | ||||
| NULL, | NULL, | ||||
| 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, NULL); | ||||
| if (!curvemap_can_zoom_in(cumap)) { | |||||
| 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, | NULL, | ||||
| 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, NULL); | ||||
| if (!curvemap_can_zoom_out(cumap)) { | |||||
| UI_but_disable(bt, ""); | |||||
| } | |||||
| /* Clippoing 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), NULL); | ||||
| if (brush && neg_slope) { | if (brush && neg_slope) { | ||||
| bt = uiDefIconBlockBut( | bt = uiDefIconBlockBut( | ||||
| ▲ Show 20 Lines • Show All 412 Lines • ▼ Show 20 Lines | static uiBlock *CurveProfile_tools_func(bContext *C, ARegion *region, CurveProfile *profile) | ||||
| 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) | |||||
| { | |||||
| return BLI_rctf_size_x(&profile->view_rect) > CURVE_ZOOM_MAX * BLI_rctf_size_x(&profile->clip_rect); | |||||
| } | |||||
| static bool CurveProfile_can_zoom_out(CurveProfile *profile) | |||||
| { | |||||
| 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 *UNUSED(arg)) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = profile_v; | ||||
| /* Allow a 20x zoom. */ | if (CurveProfile_can_zoom_in(profile)) { | ||||
| if (BLI_rctf_size_x(&profile->view_rect) > 0.04f * BLI_rctf_size_x(&profile->clip_rect)) { | |||||
| 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 *UNUSED(arg)) | ||||
| { | { | ||||
| CurveProfile *profile = profile_v; | CurveProfile *profile = profile_v; | ||||
| /* Allow 20 times zoom, but don't view outside clip */ | if (CurveProfile_can_zoom_out(profile)) { | ||||
| if (BLI_rctf_size_x(&profile->view_rect) < 20.0f * BLI_rctf_size_x(&profile->clip_rect)) { | |||||
| 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 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | bt = uiDefIconBut(block, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| NULL, | NULL, | ||||
| 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, NULL); | ||||
| if (!CurveProfile_can_zoom_in(profile)) { | |||||
| 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, | NULL, | ||||
| 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, NULL); | ||||
| if (!CurveProfile_can_zoom_out(profile)) { | |||||
| 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, | ||||
| ▲ Show 20 Lines • Show All 1,668 Lines • Show Last 20 Lines | |||||