Skip to content

Commit

Permalink
feat(sdl): scaling sdl
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Oct 30, 2019
1 parent 9507580 commit 92808f9
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
if [[ "${{matrix.name}}" == "ubuntu-18-04-emcc-latest-debug" ]]; then
cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=${ANTARA_BUILD_TYPE} -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DUSE_BOX2D_ANTARA_WRAPPER=ON -DCMAKE_TOOLCHAIN_FILE=emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC
else
cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=${ANTARA_BUILD_TYPE} -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DUSE_SFML_ANTARA_WRAPPER=ON -DUSE_BOX2D_ANTARA_WRAPPER=ON
cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=${ANTARA_BUILD_TYPE} -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DUSE_SFML_ANTARA_WRAPPER=ON -DUSE_BOX2D_ANTARA_WRAPPER=ON -DUSE_SDL_ANTARA_WRAPPER=ON
fi
- name: Configure (Windows)
Expand All @@ -189,7 +189,7 @@ jobs:
run: |
dir
echo %GITHUB_WORKSPACE%
cmake -B build -S %GITHUB_WORKSPACE% -G Ninja -DCMAKE_BUILD_TYPE=%ANTARA_BUILD_TYPE% -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DUSE_SFML_ANTARA_WRAPPER=ON -DUSE_BOX2D_ANTARA_WRAPPER=ON
cmake -B build -S %GITHUB_WORKSPACE% -G Ninja -DCMAKE_BUILD_TYPE=%ANTARA_BUILD_TYPE% -DANTARA_BUILD_EXAMPLES=ON -DUSE_LUA_ANTARA_WRAPPER=ON -DANTARA_BUILD_UNIT_TESTS=ON -DUSE_SFML_ANTARA_WRAPPER=ON -DUSE_BOX2D_ANTARA_WRAPPER=ON -DUSE_SDL_ANTARA_WRAPPER=ON
shell: cmd

- name: TSan (Linux)
Expand Down
13 changes: 10 additions & 3 deletions modules/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
##! shared sources between the module and his unit tests
add_library(antara_core_shared_sources STATIC)
target_sources(antara_core_shared_sources PRIVATE antara/gaming/core/real.path.cpp)
target_include_directories(antara_core_shared_sources PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(antara_core_shared_sources PUBLIC antara::default_settings EnTT antara::refl-cpp)
target_sources(antara_core_shared_sources PRIVATE antara/gaming/core/real.path.cpp antara/gaming/core/api.scaling.cpp
$<$<PLATFORM_ID:Darwin>:antara/gaming/core/details/osx/api.scaling.mm>
)
if (APPLE)
find_library(APPLE_FOUNDATION_FRAMEWORK_LIBRARY Foundation)
find_path(APPLE_FOUNDATION_FRAMEWORK_INCLUDE_DIR NAMES NSBundle.h)
mark_as_advanced(APPLE_FOUNDATION_FRAMEWORK_LIBRARY APPLE_FOUNDATION_FRAMEWORK_INCLUDE_DIR)
endif()
target_include_directories(antara_core_shared_sources PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} $<$<PLATFORM_ID:Darwin>:${APPLE_FOUNDATION_FRAMEWORK_INCLUDE_DIR}>)
target_link_libraries(antara_core_shared_sources PUBLIC antara::default_settings EnTT antara::refl-cpp $<$<PLATFORM_ID:Darwin>:${APPLE_FOUNDATION_FRAMEWORK_LIBRARY}>)
add_library(antara::core ALIAS antara_core_shared_sources)

if (ANTARA_BUILD_UNIT_TESTS)
Expand Down
46 changes: 46 additions & 0 deletions modules/core/antara/gaming/core/api.scaling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/******************************************************************************
* Copyright © 2013-2019 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#include "antara/gaming/core/api.scaling.hpp"

#ifdef _WIN32

#include "antara/gaming/core/details/windows/api.scaling.hpp"

#elif __APPLE__

#include "antara/gaming/core/details/osx/api.scaling.hpp"

#elif __linux__

#include "antara/gaming/core/details/linux/api.scaling.hpp"

#elif EMSCRIPTEN
#include "antara/gaming/core/details/emscripten/api.scaling.hpp"
#endif

namespace antara::gaming::core
{
bool is_high_dpi_capable() noexcept
{
return details::is_high_dpi_capable();
}

std::pair<float, float> get_scaling_factor() noexcept
{
return details::get_scaling_factor();
}
}
25 changes: 25 additions & 0 deletions modules/core/antara/gaming/core/api.scaling.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/******************************************************************************
* Copyright © 2013-2019 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#pragma once

#include <utility>

namespace antara::gaming::core
{
bool is_high_dpi_capable() noexcept;
std::pair<float, float> get_scaling_factor() noexcept;
}
32 changes: 32 additions & 0 deletions modules/core/antara/gaming/core/details/emscripten/api.scaling.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/******************************************************************************
* Copyright © 2013-2019 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#pragma once

#include <utility>

namespace antara::gaming::core::details
{
bool is_high_dpi_capable() noexcept
{
return true;
}

std::pair<float, float> get_scaling_factor() noexcept
{
return {1.f, 1.f};
}
}
32 changes: 32 additions & 0 deletions modules/core/antara/gaming/core/details/linux/api.scaling.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/******************************************************************************
* Copyright © 2013-2019 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#pragma once

#include <utility>

namespace antara::gaming::core::details
{
bool is_high_dpi_capable() noexcept
{
return true;
}

std::pair<float, float> get_scaling_factor() noexcept
{
return {1.f, 1.f};
}
}
25 changes: 25 additions & 0 deletions modules/core/antara/gaming/core/details/osx/api.scaling.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/******************************************************************************
* Copyright © 2013-2019 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#pragma once

#include <utility>

namespace antara::gaming::core::details
{
bool is_high_dpi_capable() noexcept;
std::pair<float, float> get_scaling_factor() noexcept;
}
38 changes: 38 additions & 0 deletions modules/core/antara/gaming/core/details/osx/api.scaling.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/******************************************************************************
* Copyright © 2013-2019 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#import <CoreGraphics/CoreGraphics.h>
#import <NSGeometry.h>
#import <AppKit/AppKit.h>

#include "antara/gaming/core/details/osx/api.scaling.hpp"

namespace antara::gaming::core::details
{
bool is_high_dpi_capable() noexcept
{
NSBundle *bundle = [NSBundle mainBundle];
if (!bundle)
return false;
return bool([bundle objectForInfoDictionaryKey:@"NSHighResolutionCapable"]);
}

std::pair<float, float> get_scaling_factor() noexcept
{
auto factor = static_cast<float>([[NSScreen mainScreen] backingScaleFactor]);
return {factor, factor};
}
}
32 changes: 32 additions & 0 deletions modules/core/antara/gaming/core/details/windows/api.scaling.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/******************************************************************************
* Copyright © 2013-2019 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#pragma once

#include <utility>

namespace antara::gaming::core::details
{
bool is_high_dpi_capable() noexcept
{
return true;
}

std::pair<float, float> get_scaling_factor() noexcept
{
return {1.f, 1.f};
}
}
54 changes: 28 additions & 26 deletions modules/graphics/antara/gaming/graphics/component.canvas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,6 @@ namespace antara::gaming::graphics
fill_color background_color{graphics::black};
math::vec2f canvas_texture_scaling{1.0f, 1.0f};

bool operator==(const canvas_2d &rhs) const
{
return window == rhs.window &&
canvas == rhs.canvas &&
current_scaling_mode == rhs.current_scaling_mode &&
view_port == rhs.view_port &&
window_title == rhs.window_title &&
background_color == rhs.background_color;
}

friend inline std::ostream &operator<<(std::ostream &os, const canvas_2d &d)
{
os << "window: " << d.window << " canvas: " << d.canvas << " canvas_texture: " << d.canvas_texture
<< " custom_canvas_width: " << d.custom_canvas_width << " custom_canvas_height: "
<< d.custom_canvas_height << " native_desktop_mode: " << d.native_desktop_mode << " is_fullscreen: "
<< d.is_fullscreen << " current_scaling_mode: " << d.current_scaling_mode << " view_port: "
<< d.view_port << " window_title: " << d.window_title << " background_color: " << d.background_color
<< " canvas_texture_scaling: " << d.canvas_texture_scaling;
return os;
}

bool operator!=(const canvas_2d &rhs) const
{
return !(rhs == *this);
}

void reset_canvas() noexcept
{
auto&&[window_width, window_height] = window.size;
Expand Down Expand Up @@ -139,6 +113,34 @@ namespace antara::gaming::graphics
canvas_texture.position = math::vec2f{window_width * 0.5f, window_height * 0.5f};
}

bool operator==(const canvas_2d &rhs) const
{
return window == rhs.window &&
canvas == rhs.canvas &&
current_scaling_mode == rhs.current_scaling_mode &&
view_port == rhs.view_port &&
window_title == rhs.window_title &&
background_color == rhs.background_color;
}

friend inline std::ostream &operator<<(std::ostream &os, const canvas_2d &d)
{
os << "window: " << d.window << " canvas: " << d.canvas << " canvas_texture: " << d.canvas_texture
<< " custom_canvas_width: " << d.custom_canvas_width << " custom_canvas_height: "
<< d.custom_canvas_height << " native_desktop_mode: " << d.native_desktop_mode << " is_fullscreen: "
<< d.is_fullscreen << " current_scaling_mode: " << d.current_scaling_mode << " view_port: "
<< d.view_port << " window_title: " << d.window_title << " background_color: " << d.background_color
<< " canvas_texture_scaling: " << d.canvas_texture_scaling;
return os;
}

bool operator!=(const canvas_2d &rhs) const
{
return !(rhs == *this);
}



canvas_2d() = default;

canvas_2d(const canvas_2d &other) = default;
Expand Down
2 changes: 1 addition & 1 deletion modules/sdl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library(antara_sdl STATIC)
target_sources(antara_sdl PRIVATE antara/gaming/sdl/graphic.system.cpp antara/gaming/sdl/sdl.error.cpp)
target_include_directories(antara_sdl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(antara_sdl PUBLIC antara::sdl_import antara::ecs antara::event)
target_link_libraries(antara_sdl PUBLIC antara::sdl_import antara::ecs antara::event antara::core)
add_library(antara::sdl ALIAS antara_sdl)
Loading

0 comments on commit 92808f9

Please sign in to comment.