Put the scaling function in a lib

This commit is contained in:
Corentin Jabot 2021-07-08 10:17:05 +02:00
parent cbd19df739
commit 3966987e2a
7 changed files with 34 additions and 12 deletions

View file

@ -28,6 +28,7 @@ project(pacman)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
add_subdirectory(scaling-lib)
add_subdirectory(lib) add_subdirectory(lib)
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(test) add_subdirectory(test)

View file

@ -10,14 +10,8 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp")
add_library(libpacman ${sources}) add_library(libpacman ${sources})
target_include_directories(libpacman PUBLIC include) 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") if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
target_link_libraries(libpacman PUBLIC OpenGL::OpenGL OpenGL::GLX) target_link_libraries(libpacman PUBLIC OpenGL::OpenGL OpenGL::GLX)
endif () endif ()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
target_sources(libpacman PRIVATE Scaling.mm)
else()
target_sources(libpacman PRIVATE Scaling.cpp)
endif ()

View file

@ -1,11 +1,10 @@
#include "Canvas.hpp" #include "Canvas.hpp"
#include "Game.hpp" #include "Game.hpp"
#include "Scaling.hpp"
#include <fmt/format.h> #include <fmt/format.h>
#include <string> #include <string>
#include <vector> #include <vector>
double scaling_factor_for_window(sf::WindowHandle);
namespace pacman { namespace pacman {
Canvas::Canvas() Canvas::Canvas()

View 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 ()

View file

@ -1,5 +1,10 @@
#include <SFML/Graphics.hpp> #include "Scaling.hpp"
namespace pacman {
double scaling_factor_for_window(sf::WindowHandle) { double scaling_factor_for_window(sf::WindowHandle) {
return 1.0; return 1.0;
} }
}

6
scaling-lib/Scaling.hpp Normal file
View file

@ -0,0 +1,6 @@
#pragma once
#include <SFML/Graphics.hpp>
namespace pacman {
double scaling_factor_for_window(sf::WindowHandle);
}

View file

@ -5,10 +5,15 @@ It is not a C++ file and is not part of this course!
*/ */
#import "AppKit/NSWindow.h" #import "AppKit/NSWindow.h"
#include <cassert> #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); NSWindow* window = static_cast<NSWindow*>(ptr);
assert(window); assert(window);
double d = [window backingScaleFactor]; double d = [window backingScaleFactor];
return d; return d;
}
} }