mirror of
https://github.com/NoelFB/blah.git
synced 2024-11-28 16:58:57 +08:00
remove App::content_scale;App::get_backbuffer_size
This commit is contained in:
parent
4d7f7a993a
commit
c58eb0142e
|
@ -119,13 +119,6 @@ namespace Blah
|
||||||
// Sets the Window Size in Screen Coordinates
|
// Sets the Window Size in Screen Coordinates
|
||||||
void set_size(Point point);
|
void set_size(Point point);
|
||||||
|
|
||||||
// Gets the size of the BackBuffer, in pixels
|
|
||||||
Point get_backbuffer_size();
|
|
||||||
|
|
||||||
// Gets the content scale based on the platform.
|
|
||||||
// macOS is usually 2.0, other platforms vary.
|
|
||||||
float content_scale();
|
|
||||||
|
|
||||||
// If the window is currently focused or has mouse input
|
// If the window is currently focused or has mouse input
|
||||||
bool focused();
|
bool focused();
|
||||||
|
|
||||||
|
|
|
@ -310,7 +310,6 @@ void Internal::app_shutdown()
|
||||||
|
|
||||||
Renderer* Internal::app_renderer()
|
Renderer* Internal::app_renderer()
|
||||||
{
|
{
|
||||||
BLAH_ASSERT_RUNNING();
|
|
||||||
return app_renderer_api;
|
return app_renderer_api;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,20 +378,6 @@ void App::set_size(Point point)
|
||||||
Platform::set_size(point.x, point.y);
|
Platform::set_size(point.x, point.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point App::get_backbuffer_size()
|
|
||||||
{
|
|
||||||
BLAH_ASSERT_RUNNING();
|
|
||||||
if (app_renderer_api)
|
|
||||||
return Point(app_backbuffer->width(), app_backbuffer->height());
|
|
||||||
return Point(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
float App::content_scale()
|
|
||||||
{
|
|
||||||
BLAH_ASSERT_RUNNING();
|
|
||||||
return Platform::get_content_scale();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool App::focused()
|
bool App::focused()
|
||||||
{
|
{
|
||||||
BLAH_ASSERT_RUNNING();
|
BLAH_ASSERT_RUNNING();
|
||||||
|
|
|
@ -58,9 +58,6 @@ namespace Blah
|
||||||
// Gets the Application Window Drawing Size, in Pixels. This may differ from the Window Size on hi-dpi displays.
|
// Gets the Application Window Drawing Size, in Pixels. This may differ from the Window Size on hi-dpi displays.
|
||||||
void get_draw_size(int* width, int* height);
|
void get_draw_size(int* width, int* height);
|
||||||
|
|
||||||
// Gets the Desktop Content Scale. Gui should be scaled by this value
|
|
||||||
float get_content_scale();
|
|
||||||
|
|
||||||
// Returns the absolute path to the directory that the application was started from
|
// Returns the absolute path to the directory that the application was started from
|
||||||
const char* app_path();
|
const char* app_path();
|
||||||
|
|
||||||
|
|
|
@ -457,46 +457,7 @@ void Platform::set_size(int width, int height)
|
||||||
|
|
||||||
void Platform::get_draw_size(int* width, int* height)
|
void Platform::get_draw_size(int* width, int* height)
|
||||||
{
|
{
|
||||||
switch (App::renderer().type)
|
SDL_GetWindowSizeInPixels(sdl2_window, width, height);
|
||||||
{
|
|
||||||
case RendererType::OpenGL:
|
|
||||||
SDL_GL_GetDrawableSize(sdl2_window, width, height);
|
|
||||||
break;
|
|
||||||
case RendererType::None:
|
|
||||||
case RendererType::D3D11:
|
|
||||||
SDL_GetWindowSize(sdl2_window, width, height);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float Platform::get_content_scale()
|
|
||||||
{
|
|
||||||
// TODO:
|
|
||||||
// This is incorrect! but for some reason the scale
|
|
||||||
// is HUGE if I use the Display DPI on macOS :/
|
|
||||||
#if __APPLE__
|
|
||||||
return 2.0f;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// is there a way to get this value properly? My Windows & Linux PC's both seem to thing 96 is correct
|
|
||||||
const float hidpi_res = 96;
|
|
||||||
|
|
||||||
int index = SDL_GetWindowDisplayIndex(sdl2_window);
|
|
||||||
if (index < 0)
|
|
||||||
{
|
|
||||||
Log::error(SDL_GetError());
|
|
||||||
return 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float ddpi, x, y;
|
|
||||||
if (SDL_GetDisplayDPI(index, &ddpi, &x, &y) != 0)
|
|
||||||
{
|
|
||||||
Log::error(SDL_GetError());
|
|
||||||
return 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (ddpi / hidpi_res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Platform::app_path()
|
const char* Platform::app_path()
|
||||||
|
|
|
@ -224,7 +224,12 @@ bool Platform::init(const Config& config)
|
||||||
|
|
||||||
// Setup Window Size based on content scale
|
// Setup Window Size based on content scale
|
||||||
{
|
{
|
||||||
auto scale = get_content_scale();
|
// base value of Windows DPI
|
||||||
|
// as seen here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiforwindow
|
||||||
|
constexpr float base_raw_value = 96.0f;
|
||||||
|
|
||||||
|
UINT raw_value = GetDpiForWindow(win32_hwnd);
|
||||||
|
float scale = (raw_value / base_raw_value);
|
||||||
int sw = (int)(App::config().width * scale);
|
int sw = (int)(App::config().width * scale);
|
||||||
int sh = (int)(App::config().height * scale);
|
int sh = (int)(App::config().height * scale);
|
||||||
set_size(sw, sh);
|
set_size(sw, sh);
|
||||||
|
@ -503,18 +508,6 @@ void Platform::get_draw_size(int* width, int* height)
|
||||||
*height = rect.bottom - rect.top;
|
*height = rect.bottom - rect.top;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float Platform::get_content_scale()
|
|
||||||
{
|
|
||||||
// base value of Windows DPI
|
|
||||||
// as seen here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiforwindow
|
|
||||||
constexpr float base_raw_value = 96.0f;
|
|
||||||
|
|
||||||
UINT raw_value = GetDpiForWindow(win32_hwnd);
|
|
||||||
|
|
||||||
return (raw_value / base_raw_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* Platform::app_path()
|
const char* Platform::app_path()
|
||||||
{
|
{
|
||||||
return win32_working_directory.cstr();
|
return win32_working_directory.cstr();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user