Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/view2d.c
| Show First 20 Lines • Show All 1,407 Lines • ▼ Show 20 Lines | struct View2DScrollers { | ||||
| int vert_min, vert_max; /* vertical scrollbar */ | int vert_min, vert_max; /* vertical scrollbar */ | ||||
| int hor_min, hor_max; /* horizontal scrollbar */ | int hor_min, hor_max; /* horizontal scrollbar */ | ||||
| rcti hor, vert; /* exact size of slider backdrop */ | rcti hor, vert; /* exact size of slider backdrop */ | ||||
| int horfull, vertfull; /* set if sliders are full, we don't draw them */ | int horfull, vertfull; /* set if sliders are full, we don't draw them */ | ||||
| }; | }; | ||||
| /* Calculate relevant scroller properties */ | /* Calculate relevant scroller properties */ | ||||
| View2DScrollers *UI_view2d_scrollers_calc(View2D *v2d, const rcti *mask_custom) | void UI_view2d_scrollers_calc(View2D *v2d, | ||||
| const rcti *mask_custom, | |||||
| struct View2DScrollers *r_scrollers) | |||||
| { | { | ||||
| View2DScrollers *scrollers; | |||||
| rcti vert, hor; | rcti vert, hor; | ||||
| float fac1, fac2, totsize, scrollsize; | float fac1, fac2, totsize, scrollsize; | ||||
| int scroll = view2d_scroll_mapped(v2d->scroll); | int scroll = view2d_scroll_mapped(v2d->scroll); | ||||
| int smaller; | int smaller; | ||||
| /* scrollers is allocated here... */ | |||||
| scrollers = MEM_callocN(sizeof(View2DScrollers), "View2DScrollers"); | |||||
| /* Always update before drawing (for dynamically sized scrollers). */ | /* Always update before drawing (for dynamically sized scrollers). */ | ||||
| view2d_masks(v2d, mask_custom); | view2d_masks(v2d, mask_custom); | ||||
| vert = v2d->vert; | vert = v2d->vert; | ||||
| hor = v2d->hor; | hor = v2d->hor; | ||||
| /* slider rects need to be smaller than region and not interfere with splitter areas */ | /* slider rects need to be smaller than region and not interfere with splitter areas */ | ||||
| hor.xmin += UI_HEADER_OFFSET; | hor.xmin += UI_HEADER_OFFSET; | ||||
| Show All 16 Lines | void UI_view2d_scrollers_calc(View2D *v2d, | ||||
| else { | else { | ||||
| vert.xmax -= smaller; | vert.xmax -= smaller; | ||||
| } | } | ||||
| CLAMP(vert.ymin, vert.ymin, vert.ymax - V2D_SCROLL_HANDLE_SIZE_HOTSPOT); | CLAMP(vert.ymin, vert.ymin, vert.ymax - V2D_SCROLL_HANDLE_SIZE_HOTSPOT); | ||||
| CLAMP(hor.xmin, hor.xmin, hor.xmax - V2D_SCROLL_HANDLE_SIZE_HOTSPOT); | CLAMP(hor.xmin, hor.xmin, hor.xmax - V2D_SCROLL_HANDLE_SIZE_HOTSPOT); | ||||
| /* store in scrollers, used for drawing */ | /* store in scrollers, used for drawing */ | ||||
| scrollers->vert = vert; | r_scrollers->vert = vert; | ||||
| scrollers->hor = hor; | r_scrollers->hor = hor; | ||||
| /* scroller 'buttons': | /* scroller 'buttons': | ||||
| * - These should always remain within the visible region of the scrollbar | * - These should always remain within the visible region of the scrollbar | ||||
| * - They represent the region of 'tot' that is visible in 'cur' | * - They represent the region of 'tot' that is visible in 'cur' | ||||
| */ | */ | ||||
| /* horizontal scrollers */ | /* horizontal scrollers */ | ||||
| if (scroll & V2D_SCROLL_HORIZONTAL) { | if (scroll & V2D_SCROLL_HORIZONTAL) { | ||||
| /* scroller 'button' extents */ | /* scroller 'button' extents */ | ||||
| totsize = BLI_rctf_size_x(&v2d->tot); | totsize = BLI_rctf_size_x(&v2d->tot); | ||||
| scrollsize = (float)BLI_rcti_size_x(&hor); | scrollsize = (float)BLI_rcti_size_x(&hor); | ||||
| if (totsize == 0.0f) { | if (totsize == 0.0f) { | ||||
| totsize = 1.0f; /* avoid divide by zero */ | totsize = 1.0f; /* avoid divide by zero */ | ||||
| } | } | ||||
| fac1 = (v2d->cur.xmin - v2d->tot.xmin) / totsize; | fac1 = (v2d->cur.xmin - v2d->tot.xmin) / totsize; | ||||
| if (fac1 <= 0.0f) { | if (fac1 <= 0.0f) { | ||||
| scrollers->hor_min = hor.xmin; | r_scrollers->hor_min = hor.xmin; | ||||
| } | } | ||||
| else { | else { | ||||
| scrollers->hor_min = (int)(hor.xmin + (fac1 * scrollsize)); | r_scrollers->hor_min = (int)(hor.xmin + (fac1 * scrollsize)); | ||||
| } | } | ||||
| fac2 = (v2d->cur.xmax - v2d->tot.xmin) / totsize; | fac2 = (v2d->cur.xmax - v2d->tot.xmin) / totsize; | ||||
| if (fac2 >= 1.0f) { | if (fac2 >= 1.0f) { | ||||
| scrollers->hor_max = hor.xmax; | r_scrollers->hor_max = hor.xmax; | ||||
| } | } | ||||
| else { | else { | ||||
| scrollers->hor_max = (int)(hor.xmin + (fac2 * scrollsize)); | r_scrollers->hor_max = (int)(hor.xmin + (fac2 * scrollsize)); | ||||
| } | } | ||||
| /* prevent inverted sliders */ | /* prevent inverted sliders */ | ||||
| if (scrollers->hor_min > scrollers->hor_max) { | if (r_scrollers->hor_min > r_scrollers->hor_max) { | ||||
| scrollers->hor_min = scrollers->hor_max; | r_scrollers->hor_min = r_scrollers->hor_max; | ||||
| } | } | ||||
| /* prevent sliders from being too small to grab */ | /* prevent sliders from being too small to grab */ | ||||
| if ((scrollers->hor_max - scrollers->hor_min) < V2D_SCROLL_THUMB_SIZE_MIN) { | if ((r_scrollers->hor_max - r_scrollers->hor_min) < V2D_SCROLL_THUMB_SIZE_MIN) { | ||||
| scrollers->hor_max = scrollers->hor_min + V2D_SCROLL_THUMB_SIZE_MIN; | r_scrollers->hor_max = r_scrollers->hor_min + V2D_SCROLL_THUMB_SIZE_MIN; | ||||
| CLAMP(scrollers->hor_max, hor.xmin + V2D_SCROLL_THUMB_SIZE_MIN, hor.xmax); | CLAMP(r_scrollers->hor_max, hor.xmin + V2D_SCROLL_THUMB_SIZE_MIN, hor.xmax); | ||||
| CLAMP(scrollers->hor_min, hor.xmin, hor.xmax - V2D_SCROLL_THUMB_SIZE_MIN); | CLAMP(r_scrollers->hor_min, hor.xmin, hor.xmax - V2D_SCROLL_THUMB_SIZE_MIN); | ||||
| } | } | ||||
| } | } | ||||
| /* vertical scrollers */ | /* vertical scrollers */ | ||||
| if (scroll & V2D_SCROLL_VERTICAL) { | if (scroll & V2D_SCROLL_VERTICAL) { | ||||
| /* scroller 'button' extents */ | /* scroller 'button' extents */ | ||||
| totsize = BLI_rctf_size_y(&v2d->tot); | totsize = BLI_rctf_size_y(&v2d->tot); | ||||
| scrollsize = (float)BLI_rcti_size_y(&vert); | scrollsize = (float)BLI_rcti_size_y(&vert); | ||||
| if (totsize == 0.0f) { | if (totsize == 0.0f) { | ||||
| totsize = 1.0f; /* avoid divide by zero */ | totsize = 1.0f; /* avoid divide by zero */ | ||||
| } | } | ||||
| fac1 = (v2d->cur.ymin - v2d->tot.ymin) / totsize; | fac1 = (v2d->cur.ymin - v2d->tot.ymin) / totsize; | ||||
| if (fac1 <= 0.0f) { | if (fac1 <= 0.0f) { | ||||
| scrollers->vert_min = vert.ymin; | r_scrollers->vert_min = vert.ymin; | ||||
| } | } | ||||
| else { | else { | ||||
| scrollers->vert_min = (int)(vert.ymin + (fac1 * scrollsize)); | r_scrollers->vert_min = (int)(vert.ymin + (fac1 * scrollsize)); | ||||
| } | } | ||||
| fac2 = (v2d->cur.ymax - v2d->tot.ymin) / totsize; | fac2 = (v2d->cur.ymax - v2d->tot.ymin) / totsize; | ||||
| if (fac2 >= 1.0f) { | if (fac2 >= 1.0f) { | ||||
| scrollers->vert_max = vert.ymax; | r_scrollers->vert_max = vert.ymax; | ||||
| } | } | ||||
| else { | else { | ||||
| scrollers->vert_max = (int)(vert.ymin + (fac2 * scrollsize)); | r_scrollers->vert_max = (int)(vert.ymin + (fac2 * scrollsize)); | ||||
| } | } | ||||
| /* prevent inverted sliders */ | /* prevent inverted sliders */ | ||||
| if (scrollers->vert_min > scrollers->vert_max) { | if (r_scrollers->vert_min > r_scrollers->vert_max) { | ||||
| scrollers->vert_min = scrollers->vert_max; | r_scrollers->vert_min = r_scrollers->vert_max; | ||||
| } | } | ||||
| /* prevent sliders from being too small to grab */ | /* prevent sliders from being too small to grab */ | ||||
| if ((scrollers->vert_max - scrollers->vert_min) < V2D_SCROLL_THUMB_SIZE_MIN) { | if ((r_scrollers->vert_max - r_scrollers->vert_min) < V2D_SCROLL_THUMB_SIZE_MIN) { | ||||
| scrollers->vert_max = scrollers->vert_min + V2D_SCROLL_THUMB_SIZE_MIN; | r_scrollers->vert_max = r_scrollers->vert_min + V2D_SCROLL_THUMB_SIZE_MIN; | ||||
| CLAMP(scrollers->vert_max, vert.ymin + V2D_SCROLL_THUMB_SIZE_MIN, vert.ymax); | CLAMP(r_scrollers->vert_max, vert.ymin + V2D_SCROLL_THUMB_SIZE_MIN, vert.ymax); | ||||
| CLAMP(scrollers->vert_min, vert.ymin, vert.ymax - V2D_SCROLL_THUMB_SIZE_MIN); | CLAMP(r_scrollers->vert_min, vert.ymin, vert.ymax - V2D_SCROLL_THUMB_SIZE_MIN); | ||||
| } | } | ||||
| } | } | ||||
| return scrollers; | |||||
| } | } | ||||
| /* Draw scrollbars in the given 2d-region */ | /* Draw scrollbars in the given 2d-region */ | ||||
| void UI_view2d_scrollers_draw(View2D *v2d, View2DScrollers *vs) | void UI_view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom) | ||||
| { | { | ||||
| View2DScrollers scrollers; | |||||
| UI_view2d_scrollers_calc(v2d, mask_custom, &scrollers); | |||||
| bTheme *btheme = UI_GetTheme(); | bTheme *btheme = UI_GetTheme(); | ||||
| rcti vert, hor; | rcti vert, hor; | ||||
| const int scroll = view2d_scroll_mapped(v2d->scroll); | const int scroll = view2d_scroll_mapped(v2d->scroll); | ||||
| const char emboss_alpha = btheme->tui.widget_emboss[3]; | const char emboss_alpha = btheme->tui.widget_emboss[3]; | ||||
| uchar scrollers_back_color[4]; | uchar scrollers_back_color[4]; | ||||
| /* Color for scrollbar backs */ | /* Color for scrollbar backs */ | ||||
| UI_GetThemeColor4ubv(TH_BACK, scrollers_back_color); | UI_GetThemeColor4ubv(TH_BACK, scrollers_back_color); | ||||
| /* make copies of rects for less typing */ | /* make copies of rects for less typing */ | ||||
| vert = vs->vert; | vert = scrollers.vert; | ||||
| hor = vs->hor; | hor = scrollers.hor; | ||||
| /* horizontal scrollbar */ | /* horizontal scrollbar */ | ||||
| if (scroll & V2D_SCROLL_HORIZONTAL) { | if (scroll & V2D_SCROLL_HORIZONTAL) { | ||||
| uiWidgetColors wcol = btheme->tui.wcol_scroll; | uiWidgetColors wcol = btheme->tui.wcol_scroll; | ||||
| const float alpha_fac = v2d->alpha_hor / 255.0f; | const float alpha_fac = v2d->alpha_hor / 255.0f; | ||||
| rcti slider; | rcti slider; | ||||
| int state; | int state; | ||||
| slider.xmin = vs->hor_min; | slider.xmin = scrollers.hor_min; | ||||
| slider.xmax = vs->hor_max; | slider.xmax = scrollers.hor_max; | ||||
| slider.ymin = hor.ymin; | slider.ymin = hor.ymin; | ||||
| slider.ymax = hor.ymax; | slider.ymax = hor.ymax; | ||||
| state = (v2d->scroll_ui & V2D_SCROLL_H_ACTIVE) ? UI_SCROLL_PRESSED : 0; | state = (v2d->scroll_ui & V2D_SCROLL_H_ACTIVE) ? UI_SCROLL_PRESSED : 0; | ||||
| wcol.inner[3] *= alpha_fac; | wcol.inner[3] *= alpha_fac; | ||||
| wcol.item[3] *= alpha_fac; | wcol.item[3] *= alpha_fac; | ||||
| wcol.outline[3] *= alpha_fac; | wcol.outline[3] *= alpha_fac; | ||||
| Show All 18 Lines | void UI_view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom) | ||||
| if (scroll & V2D_SCROLL_VERTICAL) { | if (scroll & V2D_SCROLL_VERTICAL) { | ||||
| uiWidgetColors wcol = btheme->tui.wcol_scroll; | uiWidgetColors wcol = btheme->tui.wcol_scroll; | ||||
| rcti slider; | rcti slider; | ||||
| const float alpha_fac = v2d->alpha_vert / 255.0f; | const float alpha_fac = v2d->alpha_vert / 255.0f; | ||||
| int state; | int state; | ||||
| slider.xmin = vert.xmin; | slider.xmin = vert.xmin; | ||||
| slider.xmax = vert.xmax; | slider.xmax = vert.xmax; | ||||
| slider.ymin = vs->vert_min; | slider.ymin = scrollers.vert_min; | ||||
| slider.ymax = vs->vert_max; | slider.ymax = scrollers.vert_max; | ||||
| state = (v2d->scroll_ui & V2D_SCROLL_V_ACTIVE) ? UI_SCROLL_PRESSED : 0; | state = (v2d->scroll_ui & V2D_SCROLL_V_ACTIVE) ? UI_SCROLL_PRESSED : 0; | ||||
| wcol.inner[3] *= alpha_fac; | wcol.inner[3] *= alpha_fac; | ||||
| wcol.item[3] *= alpha_fac; | wcol.item[3] *= alpha_fac; | ||||
| wcol.outline[3] *= alpha_fac; | wcol.outline[3] *= alpha_fac; | ||||
| btheme->tui.widget_emboss[3] *= alpha_fac; /* will be reset later */ | btheme->tui.widget_emboss[3] *= alpha_fac; /* will be reset later */ | ||||
| Show All 11 Lines | if (scroll & V2D_SCROLL_VERTICAL) { | ||||
| UI_draw_widget_scroll(&wcol, &vert, &slider, state); | UI_draw_widget_scroll(&wcol, &vert, &slider, state); | ||||
| } | } | ||||
| /* Was changed above, so reset. */ | /* Was changed above, so reset. */ | ||||
| btheme->tui.widget_emboss[3] = emboss_alpha; | btheme->tui.widget_emboss[3] = emboss_alpha; | ||||
| } | } | ||||
| /* free temporary memory used for drawing scrollers */ | |||||
| void UI_view2d_scrollers_free(View2DScrollers *scrollers) | |||||
| { | |||||
| MEM_freeN(scrollers); | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name List View Utilities | /** \name List View Utilities | ||||
| * \{ */ | * \{ */ | ||||
| /** | /** | ||||
| * Get the 'cell' (row, column) that the given 2D-view coordinates | * Get the 'cell' (row, column) that the given 2D-view coordinates | ||||
| ▲ Show 20 Lines • Show All 589 Lines • Show Last 20 Lines | |||||