[client,sdl] fix float casts

This commit is contained in:
akallabeth 2024-09-11 22:57:21 +02:00
parent 0f00e37884
commit 2ae0c456b4
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
4 changed files with 38 additions and 10 deletions

View File

@ -118,6 +118,15 @@ SDL_Texture* SdlWidget::render_text(SDL_Renderer* renderer, const std::string& t
return texture;
}
static int scale(int w, int h)
{
const double dw = static_cast<double>(w);
const double dh = static_cast<double>(h);
const double scale = dh / dw;
const double dr = dh * scale;
return static_cast<int>(dr);
}
SDL_Texture* SdlWidget::render_text_wrapped(SDL_Renderer* renderer, const std::string& text,
SDL_Color fgcolor, SDL_Rect& src, SDL_Rect& dst)
{
@ -150,8 +159,7 @@ SDL_Texture* SdlWidget::render_text_wrapped(SDL_Renderer* renderer, const std::s
dst = _rect;
dst.x += hpadding;
dst.w -= 2 * hpadding;
const float scale = static_cast<float>(src.h) / static_cast<float>(src.w);
auto dh = src.h * scale;
auto dh = scale(src.w, src.h);
if (dh < dst.h)
dst.h = dh;

View File

@ -175,6 +175,13 @@ static UINT32 sdl_orientaion_to_rdp(SDL_DisplayOrientation orientation)
}
#endif
static Uint32 scale(Uint32 val, float scale)
{
const float dval = static_cast<float>(val);
const float sval = dval / scale;
return static_cast<Uint32>(sval);
}
static BOOL sdl_apply_display_properties(SdlContext* sdl)
{
WINPR_ASSERT(sdl);
@ -264,11 +271,11 @@ static BOOL sdl_apply_display_properties(SdlContext* sdl)
monitor->width = rect.w;
monitor->height = rect.h;
monitor->is_primary = x == 0;
monitor->attributes.desktopScaleFactor = factor;
monitor->attributes.desktopScaleFactor = static_cast<UINT32>(factor);
monitor->attributes.deviceScaleFactor = 100;
monitor->attributes.orientation = rdp_orientation;
monitor->attributes.physicalWidth = rect.w / hdpi;
monitor->attributes.physicalHeight = rect.h / vdpi;
monitor->attributes.physicalWidth = scale(rect.w, hdpi);
monitor->attributes.physicalHeight = scale(rect.h, vdpi);
}
return TRUE;
}

View File

@ -123,6 +123,13 @@ SDL_Texture* SdlWidget::render_text(SDL_Renderer* renderer, const std::string& t
return texture;
}
static float scale(float dw, float dh)
{
const double scale = dh / dw;
const double dr = dh * scale;
return dr;
}
SDL_Texture* SdlWidget::render_text_wrapped(SDL_Renderer* renderer, const std::string& text,
SDL_Color fgcolor, SDL_FRect& src, SDL_FRect& dst)
{
@ -155,8 +162,7 @@ SDL_Texture* SdlWidget::render_text_wrapped(SDL_Renderer* renderer, const std::s
dst = _rect;
dst.x += hpadding;
dst.w -= 2 * hpadding;
const float scale = static_cast<float>(src.h) / static_cast<float>(src.w);
auto dh = src.h * scale;
auto dh = scale(src.w, src.h);
if (dh < dst.h)
dst.h = dh;

View File

@ -176,6 +176,13 @@ static UINT32 sdl_orientaion_to_rdp(SDL_DisplayOrientation orientation)
}
}
static Uint32 scale(Uint32 val, float scale)
{
const float dval = static_cast<float>(val);
const float sval = dval / scale;
return static_cast<Uint32>(sval);
}
static BOOL sdl_apply_display_properties(SdlContext* sdl)
{
WINPR_ASSERT(sdl);
@ -259,11 +266,11 @@ static BOOL sdl_apply_display_properties(SdlContext* sdl)
monitor->width = rect.w;
monitor->height = rect.h;
monitor->is_primary = x == 0;
monitor->attributes.desktopScaleFactor = factor;
monitor->attributes.desktopScaleFactor = static_cast<UINT32>(factor);
monitor->attributes.deviceScaleFactor = 100;
monitor->attributes.orientation = rdp_orientation;
monitor->attributes.physicalWidth = rect.w / hdpi;
monitor->attributes.physicalHeight = rect.h / vdpi;
monitor->attributes.physicalWidth = scale(rect.w, hdpi);
monitor->attributes.physicalHeight = scale(rect.h, vdpi);
}
return TRUE;
}