Put the scaling function in a lib
This commit is contained in:
parent
cbd19df739
commit
3966987e2a
7 changed files with 34 additions and 12 deletions
|
@ -28,6 +28,7 @@ project(pacman)
|
|||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_subdirectory(scaling-lib)
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(test)
|
||||
|
|
|
@ -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 ()
|
|
@ -1,11 +1,10 @@
|
|||
#include "Canvas.hpp"
|
||||
#include "Game.hpp"
|
||||
#include "Scaling.hpp"
|
||||
#include <fmt/format.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
double scaling_factor_for_window(sf::WindowHandle);
|
||||
|
||||
namespace pacman {
|
||||
|
||||
Canvas::Canvas()
|
||||
|
|
12
scaling-lib/CMakeLists.txt
Normal file
12
scaling-lib/CMakeLists.txt
Normal file
|
@ -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 ()
|
|
@ -1,5 +1,10 @@
|
|||
#include <SFML/Graphics.hpp>
|
||||
#include "Scaling.hpp"
|
||||
|
||||
namespace pacman {
|
||||
|
||||
double scaling_factor_for_window(sf::WindowHandle) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
|
||||
}
|
6
scaling-lib/Scaling.hpp
Normal file
6
scaling-lib/Scaling.hpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
namespace pacman {
|
||||
double scaling_factor_for_window(sf::WindowHandle);
|
||||
}
|
|
@ -5,10 +5,15 @@ It is not a C++ file and is not part of this course!
|
|||
*/
|
||||
#import "AppKit/NSWindow.h"
|
||||
#include <cassert>
|
||||
#include "Scaling.hpp"
|
||||
|
||||
double scaling_factor_for_window(void* ptr) {
|
||||
namespace pacman {
|
||||
|
||||
double scaling_factor_for_window(sf::WindowHandle) {
|
||||
NSWindow* window = static_cast<NSWindow*>(ptr);
|
||||
assert(window);
|
||||
double d = [window backingScaleFactor];
|
||||
return d;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue