UI: Improve scaling of widgets when zooming

This commit improves the scaling of some ui widgets when
zooming by making the radius of the rounded corners
dependent on the element's zoom level.

Needed to fix T92278 without padding issues, see D13125.

Reviewed By: Hans Goudey, Julian Eisel

Differential Revision: https://developer.blender.org/D12842
This commit is contained in:
Leon Leno
2021-11-24 21:04:29 +01:00
committed by Julian Eisel
parent 752c6d668b
commit a9642f8d61
4 changed files with 170 additions and 85 deletions

View File

@@ -1351,7 +1351,10 @@ void ui_draw_but_COLORBAND(uiBut *but, const uiWidgetColors *UNUSED(wcol), const
immUnbindProgram(); immUnbindProgram();
} }
void ui_draw_but_UNITVEC(uiBut *but, const uiWidgetColors *wcol, const rcti *rect) void ui_draw_but_UNITVEC(uiBut *but,
const uiWidgetColors *wcol,
const rcti *rect,
const float radius)
{ {
/* sphere color */ /* sphere color */
const float diffuse[3] = {1.0f, 1.0f, 1.0f}; const float diffuse[3] = {1.0f, 1.0f, 1.0f};
@@ -1368,7 +1371,7 @@ void ui_draw_but_UNITVEC(uiBut *but, const uiWidgetColors *wcol, const rcti *rec
.ymax = rect->ymax, .ymax = rect->ymax,
}, },
true, true,
5.0f, radius,
wcol->inner, wcol->inner,
255); 255);

View File

@@ -931,7 +931,10 @@ void ui_draw_but_VECTORSCOPE(struct ARegion *region,
const struct uiWidgetColors *wcol, const struct uiWidgetColors *wcol,
const rcti *rect); const rcti *rect);
void ui_draw_but_COLORBAND(uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); void ui_draw_but_COLORBAND(uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect);
void ui_draw_but_UNITVEC(uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); void ui_draw_but_UNITVEC(uiBut *but,
const struct uiWidgetColors *wcol,
const rcti *rect,
const float radius);
void ui_draw_but_CURVE(struct ARegion *region, void ui_draw_but_CURVE(struct ARegion *region,
uiBut *but, uiBut *but,
const struct uiWidgetColors *wcol, const struct uiWidgetColors *wcol,

View File

@@ -1122,7 +1122,8 @@ static void panel_draw_highlight_border(const Panel *panel,
} }
const bTheme *btheme = UI_GetTheme(); const bTheme *btheme = UI_GetTheme();
const float radius = btheme->tui.panel_roundness * U.widget_unit * 0.5f; const float aspect = panel->runtime.block->aspect;
const float radius = (btheme->tui.panel_roundness * U.widget_unit * 0.5f) / aspect;
UI_draw_roundbox_corner_set(UI_CNR_ALL); UI_draw_roundbox_corner_set(UI_CNR_ALL);
float color[4]; float color[4];
@@ -1245,7 +1246,8 @@ static void panel_draw_aligned_backdrop(const Panel *panel,
} }
const bTheme *btheme = UI_GetTheme(); const bTheme *btheme = UI_GetTheme();
const float radius = btheme->tui.panel_roundness * U.widget_unit * 0.5f; const float aspect = panel->runtime.block->aspect;
const float radius = btheme->tui.panel_roundness * U.widget_unit * 0.5f / aspect;
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
GPU_blend(GPU_BLEND_ALPHA); GPU_blend(GPU_BLEND_ALPHA);

View File

@@ -26,6 +26,7 @@
#include <string.h> #include <string.h>
#include "DNA_brush_types.h" #include "DNA_brush_types.h"
#include "DNA_screen_types.h"
#include "DNA_userdef_types.h" #include "DNA_userdef_types.h"
#include "BLI_listbase.h" #include "BLI_listbase.h"
@@ -45,6 +46,7 @@
#include "UI_interface.h" #include "UI_interface.h"
#include "UI_interface_icons.h" #include "UI_interface_icons.h"
#include "UI_view2d.h"
#include "interface_intern.h" #include "interface_intern.h"
@@ -268,8 +270,9 @@ typedef struct uiWidgetType {
uiWidgetColors wcol; uiWidgetColors wcol;
void (*state)(struct uiWidgetType *, int state, int drawflag, eUIEmbossType emboss); void (*state)(struct uiWidgetType *, int state, int drawflag, eUIEmbossType emboss);
void (*draw)(uiWidgetColors *, rcti *, int state, int roundboxalign); void (*draw)(uiWidgetColors *, rcti *, int state, int roundboxalign, const float zoom);
void (*custom)(uiBut *, uiWidgetColors *, rcti *, int state, int roundboxalign); void (*custom)(
uiBut *, uiWidgetColors *, rcti *, int state, int roundboxalign, const float zoom);
void (*text)(const uiFontStyle *, const uiWidgetColors *, uiBut *, rcti *); void (*text)(const uiFontStyle *, const uiWidgetColors *, uiBut *, rcti *);
} uiWidgetType; } uiWidgetType;
@@ -2595,6 +2598,27 @@ static void widget_state(uiWidgetType *wt, int state, int drawflag, eUIEmbossTyp
/** \} */ /** \} */
/* -------------------------------------------------------------------- */
/** \name Widget Corner Radius Calculation
*
* A lot of places of the UI like the Node Editor or panels are zoomable. In most cases we can
* get the zoom factor from the aspect, but in some cases like popups we need to fall back to
* using the the size of the element. The latter method relies on the element always being the same
* size.
* \{ */
static float widget_radius_from_zoom(const float zoom, const uiWidgetColors *wcol)
{
return wcol->roundness * U.widget_unit * zoom;
}
static float widget_radius_from_rcti(const rcti *rect, const uiWidgetColors *wcol)
{
return wcol->roundness * BLI_rcti_size_y(rect);
}
/** \} */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/** \name Widget Types /** \name Widget Types
* \{ */ * \{ */
@@ -2786,7 +2810,8 @@ static void widget_softshadow(const rcti *rect, int roundboxalign, const float r
immUnbindProgram(); immUnbindProgram();
} }
static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int direction) static void widget_menu_back(
uiWidgetColors *wcol, rcti *rect, int flag, int direction, const float zoom)
{ {
uiWidgetBase wtb; uiWidgetBase wtb;
int roundboxalign = UI_CNR_ALL; int roundboxalign = UI_CNR_ALL;
@@ -2808,9 +2833,10 @@ static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int dir
} }
GPU_blend(GPU_BLEND_ALPHA); GPU_blend(GPU_BLEND_ALPHA);
widget_softshadow(rect, roundboxalign, wcol->roundness * U.widget_unit); const float radius = widget_radius_from_zoom(zoom, wcol);
widget_softshadow(rect, roundboxalign, radius);
round_box_edges(&wtb, roundboxalign, rect, wcol->roundness * U.widget_unit); round_box_edges(&wtb, roundboxalign, rect, radius);
wtb.draw_emboss = false; wtb.draw_emboss = false;
widgetbase_draw(&wtb, wcol); widgetbase_draw(&wtb, wcol);
@@ -3315,9 +3341,9 @@ static void ui_draw_separator(const rcti *rect, const uiWidgetColors *wcol)
* \{ */ * \{ */
static void widget_numbut_draw( static void widget_numbut_draw(
uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, bool emboss) uiWidgetColors *wcol, rcti *rect, const float zoom, int state, int roundboxalign, bool emboss)
{ {
const float rad = wcol->roundness * BLI_rcti_size_y(rect); const float rad = widget_radius_from_zoom(zoom, wcol);
const int handle_width = min_ii(BLI_rcti_size_x(rect) / 3, BLI_rcti_size_y(rect) * 0.7f); const int handle_width = min_ii(BLI_rcti_size_x(rect) / 3, BLI_rcti_size_y(rect) * 0.7f);
if (state & UI_SELECT) { if (state & UI_SELECT) {
@@ -3416,17 +3442,19 @@ static void widget_numbut_draw(
} }
} }
static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) static void widget_numbut(
uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, const float zoom)
{ {
widget_numbut_draw(wcol, rect, state, roundboxalign, false); widget_numbut_draw(wcol, rect, zoom, state, roundboxalign, false);
} }
static void widget_menubut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign) static void widget_menubut(
uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign, const float zoom)
{ {
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, roundboxalign, rect, rad); round_box_edges(&wtb, roundboxalign, rect, rad);
/* decoration */ /* decoration */
@@ -3465,10 +3493,14 @@ static void widget_menubut_embossn(const uiBut *UNUSED(but),
/** /**
* Draw number buttons still with triangles when field is not embossed * Draw number buttons still with triangles when field is not embossed
*/ */
static void widget_numbut_embossn( static void widget_numbut_embossn(const uiBut *UNUSED(but),
const uiBut *UNUSED(but), uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) uiWidgetColors *wcol,
rcti *rect,
int state,
int roundboxalign,
const float zoom)
{ {
widget_numbut_draw(wcol, rect, state, roundboxalign, true); widget_numbut_draw(wcol, rect, zoom, state, roundboxalign, true);
} }
/* function in use for buttons and for view2d sliders */ /* function in use for buttons and for view2d sliders */
@@ -3559,8 +3591,12 @@ void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *s
} }
} }
static void widget_scroll( static void widget_scroll(uiBut *but,
uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign)) uiWidgetColors *wcol,
rcti *rect,
int state,
int UNUSED(roundboxalign),
const float UNUSED(zoom))
{ {
/* calculate slider part */ /* calculate slider part */
const float value = (float)ui_but_value_get(but); const float value = (float)ui_but_value_get(but);
@@ -3617,8 +3653,12 @@ static void widget_scroll(
UI_draw_widget_scroll(wcol, rect, &rect1, state); UI_draw_widget_scroll(wcol, rect, &rect1, state);
} }
static void widget_progressbar( static void widget_progressbar(uiBut *but,
uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign) uiWidgetColors *wcol,
rcti *rect,
int UNUSED(state),
int roundboxalign,
const float zoom)
{ {
uiButProgressbar *but_progressbar = (uiButProgressbar *)but; uiButProgressbar *but_progressbar = (uiButProgressbar *)but;
rcti rect_prog = *rect, rect_bar = *rect; rcti rect_prog = *rect, rect_bar = *rect;
@@ -3629,7 +3669,7 @@ static void widget_progressbar(
/* round corners */ /* round corners */
const float value = but_progressbar->progress; const float value = but_progressbar->progress;
const float ofs = wcol->roundness * BLI_rcti_size_y(&rect_prog); const float ofs = widget_radius_from_zoom(zoom, wcol);
float w = value * BLI_rcti_size_x(&rect_prog); float w = value * BLI_rcti_size_x(&rect_prog);
/* Ensure minimum size. */ /* Ensure minimum size. */
@@ -3648,15 +3688,19 @@ static void widget_progressbar(
widgetbase_draw(&wtb_bar, wcol); widgetbase_draw(&wtb_bar, wcol);
} }
static void widget_treerow_exec( static void widget_treerow_exec(uiWidgetColors *wcol,
uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign), int indentation) rcti *rect,
int state,
int UNUSED(roundboxalign),
int indentation,
const float zoom)
{ {
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
/* no outline */ /* no outline */
wtb.draw_outline = false; wtb.draw_outline = false;
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, UI_CNR_ALL, rect, rad); round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
if ((state & UI_ACTIVE) || (state & UI_SELECT)) { if ((state & UI_ACTIVE) || (state & UI_SELECT)) {
@@ -3668,23 +3712,27 @@ static void widget_treerow_exec(
} }
static void widget_treerow( static void widget_treerow(
uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, const float zoom)
{ {
uiButTreeRow *tree_row = (uiButTreeRow *)but; uiButTreeRow *tree_row = (uiButTreeRow *)but;
BLI_assert(but->type == UI_BTYPE_TREEROW); BLI_assert(but->type == UI_BTYPE_TREEROW);
widget_treerow_exec(wcol, rect, state, roundboxalign, tree_row->indentation); widget_treerow_exec(wcol, rect, state, roundboxalign, tree_row->indentation, zoom);
} }
static void widget_datasetrow( static void widget_datasetrow(
uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, const float zoom)
{ {
uiButDatasetRow *dataset_row = (uiButDatasetRow *)but; uiButDatasetRow *dataset_row = (uiButDatasetRow *)but;
BLI_assert(but->type == UI_BTYPE_DATASETROW); BLI_assert(but->type == UI_BTYPE_DATASETROW);
widget_treerow_exec(wcol, rect, state, roundboxalign, dataset_row->indentation); widget_treerow_exec(wcol, rect, state, roundboxalign, dataset_row->indentation, zoom);
} }
static void widget_nodesocket( static void widget_nodesocket(uiBut *but,
uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign)) uiWidgetColors *wcol,
rcti *rect,
int UNUSED(state),
int UNUSED(roundboxalign),
const float UNUSED(zoom))
{ {
const int radi = 0.25f * BLI_rcti_size_y(rect); const int radi = 0.25f * BLI_rcti_size_y(rect);
@@ -3719,14 +3767,14 @@ static void widget_nodesocket(
} }
static void widget_numslider( static void widget_numslider(
uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, const float zoom)
{ {
uiWidgetBase wtb, wtb1; uiWidgetBase wtb, wtb1;
widget_init(&wtb); widget_init(&wtb);
widget_init(&wtb1); widget_init(&wtb1);
/* Backdrop first. */ /* Backdrop first. */
const float ofs = wcol->roundness * BLI_rcti_size_y(rect); const float ofs = widget_radius_from_zoom(zoom, wcol);
const float toffs = ofs * 0.75f; const float toffs = ofs * 0.75f;
round_box_edges(&wtb, roundboxalign, rect, ofs); round_box_edges(&wtb, roundboxalign, rect, ofs);
@@ -3829,7 +3877,7 @@ static void widget_numslider(
#define SWATCH_KEYED_BORDER 3 #define SWATCH_KEYED_BORDER 3
static void widget_swatch( static void widget_swatch(
uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, const float zoom)
{ {
BLI_assert(but->type == UI_BTYPE_COLOR); BLI_assert(but->type == UI_BTYPE_COLOR);
uiButColor *color_but = (uiButColor *)but; uiButColor *color_but = (uiButColor *)but;
@@ -3848,7 +3896,7 @@ static void widget_swatch(
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, roundboxalign, rect, rad); round_box_edges(&wtb, roundboxalign, rect, rad);
ui_but_v3_get(but, col); ui_but_v3_get(but, col);
@@ -3913,14 +3961,19 @@ static void widget_swatch(
} }
} }
static void widget_unitvec( static void widget_unitvec(uiBut *but,
uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign)) uiWidgetColors *wcol,
rcti *rect,
int UNUSED(state),
int UNUSED(roundboxalign),
const float zoom)
{ {
ui_draw_but_UNITVEC(but, wcol, rect); const float rad = widget_radius_from_zoom(zoom, wcol);
ui_draw_but_UNITVEC(but, wcol, rect, rad);
} }
static void widget_icon_has_anim( static void widget_icon_has_anim(
uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, const float zoom)
{ {
if (state & (UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN | UI_BUT_REDALERT) && if (state & (UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN | UI_BUT_REDALERT) &&
but->emboss != UI_EMBOSS_NONE) { but->emboss != UI_EMBOSS_NONE) {
@@ -3928,14 +3981,14 @@ static void widget_icon_has_anim(
widget_init(&wtb); widget_init(&wtb);
wtb.draw_outline = false; wtb.draw_outline = false;
const float rad = wcol->roundness * BLI_rcti_size_y(rect); const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, UI_CNR_ALL, rect, rad); round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
widgetbase_draw(&wtb, wcol); widgetbase_draw(&wtb, wcol);
} }
else if (but->type == UI_BTYPE_NUM) { else if (but->type == UI_BTYPE_NUM) {
/* Draw number buttons still with left/right /* Draw number buttons still with left/right
* triangles when field is not embossed */ * triangles when field is not embossed */
widget_numbut_embossn(but, wcol, rect, state, roundboxalign); widget_numbut_embossn(but, wcol, rect, state, roundboxalign, zoom);
} }
else if (but->type == UI_BTYPE_MENU) { else if (but->type == UI_BTYPE_MENU) {
/* Draw menu buttons still with down arrow. */ /* Draw menu buttons still with down arrow. */
@@ -3943,7 +3996,8 @@ static void widget_icon_has_anim(
} }
} }
static void widget_textbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) static void widget_textbut(
uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, const float zoom)
{ {
if (state & UI_SELECT) { if (state & UI_SELECT) {
SWAP(short, wcol->shadetop, wcol->shadedown); SWAP(short, wcol->shadetop, wcol->shadedown);
@@ -3952,43 +4006,46 @@ static void widget_textbut(uiWidgetColors *wcol, rcti *rect, int state, int roun
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, roundboxalign, rect, rad); round_box_edges(&wtb, roundboxalign, rect, rad);
widgetbase_draw(&wtb, wcol); widgetbase_draw(&wtb, wcol);
} }
static void widget_preview_tile( static void widget_preview_tile(uiBut *but,
uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign)) uiWidgetColors *wcol,
rcti *rect,
int UNUSED(state),
int UNUSED(roundboxalign),
const float UNUSED(zoom))
{ {
const uiStyle *style = UI_style_get(); const uiStyle *style = UI_style_get();
ui_draw_preview_item_stateless( ui_draw_preview_item_stateless(
&style->widget, rect, but->drawstr, but->icon, wcol->text, UI_STYLE_TEXT_CENTER); &style->widget, rect, but->drawstr, but->icon, wcol->text, UI_STYLE_TEXT_CENTER);
} }
static void widget_menuiconbut(uiWidgetColors *wcol, static void widget_menuiconbut(
rcti *rect, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign, const float zoom)
int UNUSED(state),
int roundboxalign)
{ {
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, roundboxalign, rect, rad); round_box_edges(&wtb, roundboxalign, rect, rad);
/* decoration */ /* decoration */
widgetbase_draw(&wtb, wcol); widgetbase_draw(&wtb, wcol);
} }
static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) static void widget_pulldownbut(
uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, const float zoom)
{ {
float back[4]; float back[4];
UI_GetThemeColor4fv(TH_BACK, back); UI_GetThemeColor4fv(TH_BACK, back);
if ((state & UI_ACTIVE) || (back[3] < 1.0f)) { if ((state & UI_ACTIVE) || (back[3] < 1.0f)) {
uiWidgetBase wtb; uiWidgetBase wtb;
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
if (state & UI_ACTIVE) { if (state & UI_ACTIVE) {
copy_v4_v4_uchar(wcol->inner, wcol->inner_sel); copy_v4_v4_uchar(wcol->inner, wcol->inner_sel);
@@ -4012,26 +4069,33 @@ static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int
static void widget_menu_itembut(uiWidgetColors *wcol, static void widget_menu_itembut(uiWidgetColors *wcol,
rcti *rect, rcti *rect,
int UNUSED(state), int UNUSED(state),
int UNUSED(roundboxalign)) int UNUSED(roundboxalign),
const float zoom)
{ {
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
/* Padding on the sides. */ /* Padding on the sides. */
const float padding = 0.125f * BLI_rcti_size_y(rect); const float padding = zoom * 0.125f * U.widget_unit;
rect->xmin += padding; rect->xmin += padding;
rect->xmax -= padding; rect->xmax -= padding;
/* No outline. */ /* No outline. */
wtb.draw_outline = false; wtb.draw_outline = false;
const float rad = wcol->roundness * BLI_rcti_size_y(rect);
const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, UI_CNR_ALL, rect, rad); round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
widgetbase_draw(&wtb, wcol); widgetbase_draw(&wtb, wcol);
} }
static void widget_menu_radial_itembut( static void widget_menu_radial_itembut(uiBut *but,
uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign)) uiWidgetColors *wcol,
rcti *rect,
int UNUSED(state),
int UNUSED(roundboxalign),
const float zoom)
{ {
const float fac = but->block->pie_data.alphafac; const float fac = but->block->pie_data.alphafac;
@@ -4040,7 +4104,7 @@ static void widget_menu_radial_itembut(
wtb.draw_emboss = false; wtb.draw_emboss = false;
const float rad = wcol->roundness * BLI_rcti_size_y(rect); const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, UI_CNR_ALL, rect, rad); round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
wcol->inner[3] *= fac; wcol->inner[3] *= fac;
@@ -4056,14 +4120,15 @@ static void widget_menu_radial_itembut(
static void widget_list_itembut(uiWidgetColors *wcol, static void widget_list_itembut(uiWidgetColors *wcol,
rcti *rect, rcti *rect,
int UNUSED(state), int UNUSED(state),
int UNUSED(roundboxalign)) int UNUSED(roundboxalign),
const float zoom)
{ {
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
/* no outline */ /* no outline */
wtb.draw_outline = false; wtb.draw_outline = false;
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, UI_CNR_ALL, rect, rad); round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
widgetbase_draw(&wtb, wcol); widgetbase_draw(&wtb, wcol);
@@ -4072,7 +4137,8 @@ static void widget_list_itembut(uiWidgetColors *wcol,
static void widget_optionbut(uiWidgetColors *wcol, static void widget_optionbut(uiWidgetColors *wcol,
rcti *rect, rcti *rect,
int state, int state,
int UNUSED(roundboxalign)) int UNUSED(roundboxalign),
const float UNUSED(zoom))
{ {
const bool text_before_widget = (state & UI_STATE_TEXT_BEFORE_WIDGET); const bool text_before_widget = (state & UI_STATE_TEXT_BEFORE_WIDGET);
rcti recttemp = *rect; rcti recttemp = *rect;
@@ -4095,7 +4161,7 @@ static void widget_optionbut(uiWidgetColors *wcol,
/* Keep one edge in place. */ /* Keep one edge in place. */
BLI_rcti_translate(&recttemp, text_before_widget ? delta : -delta, 0); BLI_rcti_translate(&recttemp, text_before_widget ? delta : -delta, 0);
const float rad = wcol->roundness * BLI_rcti_size_y(&recttemp); const float rad = widget_radius_from_rcti(&recttemp, wcol);
round_box_edges(&wtb, UI_CNR_ALL, &recttemp, rad); round_box_edges(&wtb, UI_CNR_ALL, &recttemp, rad);
/* decoration */ /* decoration */
@@ -4142,19 +4208,24 @@ static void widget_state_label(uiWidgetType *wt, int state, int drawflag, eUIEmb
} }
} }
static void widget_radiobut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign) static void widget_radiobut(
uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign, const float zoom)
{ {
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, roundboxalign, rect, rad); round_box_edges(&wtb, roundboxalign, rect, rad);
widgetbase_draw(&wtb, wcol); widgetbase_draw(&wtb, wcol);
} }
static void widget_box( static void widget_box(uiBut *but,
uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign) uiWidgetColors *wcol,
rcti *rect,
int UNUSED(state),
int roundboxalign,
const float zoom)
{ {
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
@@ -4170,7 +4241,7 @@ static void widget_box(
wcol->inner[3] = but->col[3]; wcol->inner[3] = but->col[3];
} }
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, roundboxalign, rect, rad); round_box_edges(&wtb, roundboxalign, rect, rad);
widgetbase_draw(&wtb, wcol); widgetbase_draw(&wtb, wcol);
@@ -4178,12 +4249,13 @@ static void widget_box(
copy_v3_v3_uchar(wcol->inner, old_col); copy_v3_v3_uchar(wcol->inner, old_col);
} }
static void widget_but(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign) static void widget_but(
uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign, const float zoom)
{ {
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
round_box_edges(&wtb, roundboxalign, rect, rad); round_box_edges(&wtb, roundboxalign, rect, rad);
widgetbase_draw(&wtb, wcol); widgetbase_draw(&wtb, wcol);
@@ -4204,10 +4276,9 @@ static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state),
} }
#endif #endif
static void widget_roundbut_exec(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) static void widget_roundbut_exec(
uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, const float zoom)
{ {
const float rad = wcol->roundness * U.widget_unit;
uiWidgetBase wtb; uiWidgetBase wtb;
widget_init(&wtb); widget_init(&wtb);
@@ -4216,15 +4287,18 @@ static void widget_roundbut_exec(uiWidgetColors *wcol, rcti *rect, int state, in
shape_preset_init_hold_action(&wtb.tria1, rect, 0.75f, 'r'); shape_preset_init_hold_action(&wtb.tria1, rect, 0.75f, 'r');
} }
const float rad = widget_radius_from_zoom(zoom, wcol);
/* half rounded */ /* half rounded */
round_box_edges(&wtb, roundboxalign, rect, rad); round_box_edges(&wtb, roundboxalign, rect, rad);
widgetbase_draw(&wtb, wcol); widgetbase_draw(&wtb, wcol);
} }
static void widget_tab(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) static void widget_tab(
uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, const float zoom)
{ {
const float rad = wcol->roundness * U.widget_unit; const float rad = widget_radius_from_zoom(zoom, wcol);
const bool is_active = (state & UI_SELECT); const bool is_active = (state & UI_SELECT);
/* Draw shaded outline - Disabled for now, /* Draw shaded outline - Disabled for now,
@@ -4897,12 +4971,13 @@ void ui_draw_but(const bContext *C, struct ARegion *region, uiStyle *style, uiBu
} }
#endif #endif
const float zoom = 1.0f / but->block->aspect;
wt->state(wt, state, drawflag, but->emboss); wt->state(wt, state, drawflag, but->emboss);
if (wt->custom) { if (wt->custom) {
wt->custom(but, &wt->wcol, rect, state, roundboxalign); wt->custom(but, &wt->wcol, rect, state, roundboxalign, zoom);
} }
else if (wt->draw) { else if (wt->draw) {
wt->draw(&wt->wcol, rect, state, roundboxalign); wt->draw(&wt->wcol, rect, state, roundboxalign, zoom);
} }
if (wt->text) { if (wt->text) {
@@ -4945,10 +5020,11 @@ void ui_draw_menu_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect)
wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED); wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED);
if (block) { if (block) {
wt->draw(&wt->wcol, rect, block->flag, block->direction); const float zoom = 1.0f / block->aspect;
wt->draw(&wt->wcol, rect, block->flag, block->direction, zoom);
} }
else { else {
wt->draw(&wt->wcol, rect, 0, 0); wt->draw(&wt->wcol, rect, 0, 0, 1.0f);
} }
ui_draw_clip_tri(block, rect, wt); ui_draw_clip_tri(block, rect, wt);
@@ -5042,8 +5118,9 @@ void ui_draw_popover_back(struct ARegion *region,
wt->wcol_theme, rect, block->direction, U.widget_unit / block->aspect, mval_origin); wt->wcol_theme, rect, block->direction, U.widget_unit / block->aspect, mval_origin);
} }
else { else {
const float zoom = 1.0f / block->aspect;
wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED); wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED);
wt->draw(&wt->wcol, rect, 0, 0); wt->draw(&wt->wcol, rect, 0, 0, zoom);
} }
ui_draw_clip_tri(block, rect, wt); ui_draw_clip_tri(block, rect, wt);
@@ -5235,7 +5312,7 @@ static void ui_draw_widget_back_color(uiWidgetTypeEnum type,
if (color) { if (color) {
rgba_float_to_uchar(wt->wcol.inner, color); rgba_float_to_uchar(wt->wcol.inner, color);
} }
wt->draw(&wt->wcol, &rect_copy, 0, UI_CNR_ALL); wt->draw(&wt->wcol, &rect_copy, 0, UI_CNR_ALL, 1.0f);
} }
void ui_draw_widget_menu_back_color(const rcti *rect, bool use_shadow, const float color[4]) void ui_draw_widget_menu_back_color(const rcti *rect, bool use_shadow, const float color[4])
{ {
@@ -5252,7 +5329,7 @@ void ui_draw_tooltip_background(const uiStyle *UNUSED(style), uiBlock *UNUSED(bl
uiWidgetType *wt = widget_type(UI_WTYPE_TOOLTIP); uiWidgetType *wt = widget_type(UI_WTYPE_TOOLTIP);
wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED); wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED);
/* wt->draw ends up using same function to draw the tooltip as menu_back */ /* wt->draw ends up using same function to draw the tooltip as menu_back */
wt->draw(&wt->wcol, rect, 0, 0); wt->draw(&wt->wcol, rect, 0, 0, 1.0f);
} }
/** /**
@@ -5280,7 +5357,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
char *cpoin = NULL; char *cpoin = NULL;
wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED); wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED);
wt->draw(&wt->wcol, rect, 0, 0); wt->draw(&wt->wcol, rect, 0, 0, 1.0f);
UI_fontstyle_set(fstyle); UI_fontstyle_set(fstyle);
@@ -5470,7 +5547,7 @@ void ui_draw_preview_item(const uiFontStyle *fstyle,
/* drawing button background */ /* drawing button background */
wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED); wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED);
wt->draw(&wt->wcol, rect, 0, 0); wt->draw(&wt->wcol, rect, 0, 0, 1.0f);
ui_draw_preview_item_stateless(fstyle, rect, name, iconid, wt->wcol.text, text_align); ui_draw_preview_item_stateless(fstyle, rect, name, iconid, wt->wcol.text, text_align);
} }