Cleanup: avoid some floating point divisions in drawing code
This commit is contained in:
@@ -2240,12 +2240,12 @@ int UI_idcode_icon_get(const int idcode)
|
||||
/* draws icon with dpi scale factor */
|
||||
void UI_icon_draw(float x, float y, int icon_id)
|
||||
{
|
||||
UI_icon_draw_ex(x, y, icon_id, 1.0f / UI_DPI_FAC, 1.0f, 0.0f, NULL, false);
|
||||
UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, 1.0f, 0.0f, NULL, false);
|
||||
}
|
||||
|
||||
void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha)
|
||||
{
|
||||
UI_icon_draw_ex(x, y, icon_id, 1.0f / UI_DPI_FAC, alpha, 0.0f, NULL, false);
|
||||
UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, alpha, 0.0f, NULL, false);
|
||||
}
|
||||
|
||||
void UI_icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size)
|
||||
|
||||
@@ -768,7 +768,7 @@ void ui_draw_aligned_panel(uiStyle *style,
|
||||
UI_icon_draw_ex(headrect.xmax - ((PNL_ICON * 2.2f) / block->aspect),
|
||||
headrect.ymin + (5.0f / block->aspect),
|
||||
(panel->flag & PNL_PIN) ? ICON_PINNED : ICON_UNPINNED,
|
||||
(block->aspect / UI_DPI_FAC),
|
||||
(block->aspect * U.inv_dpi_fac),
|
||||
1.0f,
|
||||
0.0f,
|
||||
(const char *)col_title,
|
||||
|
||||
@@ -1450,7 +1450,7 @@ static void widget_draw_icon(
|
||||
return;
|
||||
}
|
||||
|
||||
aspect = but->block->aspect / UI_DPI_FAC;
|
||||
aspect = but->block->aspect * U.inv_dpi_fac;
|
||||
height = ICON_DEFAULT_HEIGHT / aspect;
|
||||
|
||||
/* calculate blend color */
|
||||
@@ -1537,7 +1537,7 @@ static void widget_draw_submenu_tria(const uiBut *but,
|
||||
const rcti *rect,
|
||||
const uiWidgetColors *wcol)
|
||||
{
|
||||
const float aspect = but->block->aspect / UI_DPI_FAC;
|
||||
const float aspect = but->block->aspect * U.inv_dpi_fac;
|
||||
const int tria_height = (int)(ICON_DEFAULT_HEIGHT / aspect);
|
||||
const int tria_width = (int)(ICON_DEFAULT_WIDTH / aspect) - 2 * U.pixelsize;
|
||||
const int xs = rect->xmax - tria_width;
|
||||
@@ -2357,7 +2357,7 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle,
|
||||
|
||||
const BIFIconID icon = widget_icon_id(but);
|
||||
int icon_size_init = is_tool ? ICON_DEFAULT_HEIGHT_TOOLBAR : ICON_DEFAULT_HEIGHT;
|
||||
const float icon_size = icon_size_init / (but->block->aspect / UI_DPI_FAC);
|
||||
const float icon_size = icon_size_init / (but->block->aspect * U.inv_dpi_fac);
|
||||
const float icon_padding = 2 * UI_DPI_FAC;
|
||||
|
||||
#ifdef USE_UI_TOOLBAR_HACK
|
||||
|
||||
@@ -203,7 +203,7 @@ static void area_draw_azone_fullscreen(short x1, short y1, short x2, short y2, f
|
||||
|
||||
alpha = min_ff(alpha, 0.75f);
|
||||
|
||||
UI_icon_draw_ex(x, y, ICON_FULLSCREEN_EXIT, 0.7f / UI_DPI_FAC, 0.0f, alpha, NULL, false);
|
||||
UI_icon_draw_ex(x, y, ICON_FULLSCREEN_EXIT, 0.7f * U.inv_dpi_fac, 0.0f, alpha, NULL, false);
|
||||
|
||||
/* debug drawing :
|
||||
* The click_rect is the same as defined in fullscreen_click_rcti_init
|
||||
|
||||
@@ -1803,10 +1803,10 @@ static void tselem_draw_icon(uiBlock *block,
|
||||
* doesn't work for buttons */
|
||||
char color[4];
|
||||
if (UI_icon_get_theme_color(data.icon, (uchar *)color)) {
|
||||
UI_icon_draw_ex(x, y, data.icon, 1.0f / UI_DPI_FAC, alpha, 0.0f, color, true);
|
||||
UI_icon_draw_ex(x, y, data.icon, U.inv_dpi_fac, alpha, 0.0f, color, true);
|
||||
}
|
||||
else {
|
||||
UI_icon_draw_ex(x, y, data.icon, 1.0f / UI_DPI_FAC, alpha, 0.0f, NULL, false);
|
||||
UI_icon_draw_ex(x, y, data.icon, U.inv_dpi_fac, alpha, 0.0f, NULL, false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -602,6 +602,7 @@ typedef struct UserDef {
|
||||
int dpi;
|
||||
/** Runtime, multiplier to scale UI elements based on DPI. */
|
||||
float dpi_fac;
|
||||
float inv_dpi_fac;
|
||||
/** Runtime, line width and point size based on DPI. */
|
||||
float pixelsize;
|
||||
/** Deprecated, for forward compatibility. */
|
||||
@@ -611,7 +612,7 @@ typedef struct UserDef {
|
||||
int scrollback;
|
||||
/** Node insert offset (aka auto-offset) margin, but might be useful for later stuff as well. */
|
||||
char node_margin;
|
||||
char _pad2[5];
|
||||
char _pad2[1];
|
||||
/** #eUserpref_Translation_Flags. */
|
||||
short transopts;
|
||||
short menuthreshold1, menuthreshold2;
|
||||
|
||||
@@ -442,7 +442,7 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
|
||||
drag_rect_minmax(rect, x, y, x + iconsize, y + iconsize);
|
||||
}
|
||||
else {
|
||||
UI_icon_draw_ex(x, y, drag->icon, 1.0f / UI_DPI_FAC, 0.8, 0.0f, text_col, false);
|
||||
UI_icon_draw_ex(x, y, drag->icon, U.inv_dpi_fac, 0.8, 0.0f, text_col, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -672,6 +672,7 @@ void WM_window_set_dpi(wmWindow *win)
|
||||
U.dpi = dpi / pixelsize;
|
||||
U.virtual_pixel = (pixelsize == 1) ? VIRTUAL_PIXEL_NATIVE : VIRTUAL_PIXEL_DOUBLE;
|
||||
U.dpi_fac = ((U.pixelsize * (float)U.dpi) / 72.0f);
|
||||
U.inv_dpi_fac = 1.0f / U.dpi_fac;
|
||||
|
||||
/* Set user preferences globals for drawing, and for forward compatibility. */
|
||||
U.widget_unit = (U.pixelsize * U.dpi * 20 + 36) / 72;
|
||||
|
||||
Reference in New Issue
Block a user