diff --git a/CMakeLists.txt b/CMakeLists.txt index fc82aeb..e3f5fde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ project(pacman) set(CMAKE_CXX_STANDARD 20) +add_subdirectory(scaling-lib) add_subdirectory(lib) add_subdirectory(src) add_subdirectory(test) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 9af7be0..394d3f5 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -10,14 +10,8 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp") add_library(libpacman ${sources}) target_include_directories(libpacman PUBLIC include) -target_link_libraries(libpacman PUBLIC fmt::fmt sfml-graphics) +target_link_libraries(libpacman PUBLIC scaling-lib fmt::fmt sfml-graphics) if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") target_link_libraries(libpacman PUBLIC OpenGL::OpenGL OpenGL::GLX) -endif () - -if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - target_sources(libpacman PRIVATE Scaling.mm) -else() - target_sources(libpacman PRIVATE Scaling.cpp) -endif () +endif () \ No newline at end of file diff --git a/lib/Canvas.cpp b/lib/Canvas.cpp index 2de16fc..92b52f0 100644 --- a/lib/Canvas.cpp +++ b/lib/Canvas.cpp @@ -1,11 +1,10 @@ #include "Canvas.hpp" #include "Game.hpp" +#include "Scaling.hpp" #include #include #include -double scaling_factor_for_window(sf::WindowHandle); - namespace pacman { Canvas::Canvas() diff --git a/scaling-lib/CMakeLists.txt b/scaling-lib/CMakeLists.txt new file mode 100644 index 0000000..ed3ee94 --- /dev/null +++ b/scaling-lib/CMakeLists.txt @@ -0,0 +1,12 @@ +find_package(SFML COMPONENTS COMPONENTS window graphics CONFIG REQUIRED) + +add_library(scaling-lib ${sources}) + +target_include_directories(scaling-lib PUBLIC .) +target_link_libraries(scaling-lib PUBLIC sfml-graphics) + +if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + target_sources(scaling-lib PRIVATE Scaling.mm) +else() + target_sources(scaling-lib PRIVATE Scaling.cpp) +endif () diff --git a/lib/Scaling.cpp b/scaling-lib/Scaling.cpp similarity index 61% rename from lib/Scaling.cpp rename to scaling-lib/Scaling.cpp index 5d9bade..c749fb3 100644 --- a/lib/Scaling.cpp +++ b/scaling-lib/Scaling.cpp @@ -1,5 +1,10 @@ -#include +#include "Scaling.hpp" + +namespace pacman { double scaling_factor_for_window(sf::WindowHandle) { return 1.0; } + + +} \ No newline at end of file diff --git a/scaling-lib/Scaling.hpp b/scaling-lib/Scaling.hpp new file mode 100644 index 0000000..47b7c56 --- /dev/null +++ b/scaling-lib/Scaling.hpp @@ -0,0 +1,6 @@ +#pragma once +#include + +namespace pacman { + double scaling_factor_for_window(sf::WindowHandle); +} \ No newline at end of file diff --git a/lib/Scaling.mm b/scaling-lib/Scaling.mm similarity index 76% rename from lib/Scaling.mm rename to scaling-lib/Scaling.mm index b9c02f0..d0daf01 100644 --- a/lib/Scaling.mm +++ b/scaling-lib/Scaling.mm @@ -5,10 +5,15 @@ It is not a C++ file and is not part of this course! */ #import "AppKit/NSWindow.h" #include +#include "Scaling.hpp" -double scaling_factor_for_window(void* ptr) { +namespace pacman { + +double scaling_factor_for_window(sf::WindowHandle) { NSWindow* window = static_cast(ptr); assert(window); double d = [window backingScaleFactor]; return d; +} + } \ No newline at end of file