mirror of https://github.com/FreeRDP/FreeRDP
[client,sdl] fix float casts
This commit is contained in:
parent
0f00e37884
commit
2ae0c456b4
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue