Compare commits

...

101 Commits

Author SHA1 Message Date
Dmitry Marakasov
b00d3b9eb9 Update repology url 2025-03-18 17:01:19 +03:00
Dmitry Marakasov
ac53cd10e6 Update urls 2025-03-18 00:30:55 +03:00
Dmitry Marakasov
a05e661aac Handle no doxygen changes case 2025-03-17 23:37:50 +03:00
Dmitry Marakasov
c3ac6407fa Tweak example 2025-03-17 23:29:31 +03:00
Dmitry Marakasov
4815bd386b Drop codecov
We don't need service which uses geoblock
2025-03-17 23:24:01 +03:00
Dmitry Marakasov
4d941b3b31 Update Doxyfile
- Remove HTML_TIMESTAMP: the option was deprecated and replaced with TIMESTAMP, but remove as we're storing docs in git and don't need diff noise.
- Remove input filter, as badges markdown seem to be processed correctly now
2025-03-17 23:23:47 +03:00
Dmitry Marakasov
2c07d9fc64 Add doxygen workflow 2025-03-17 23:23:47 +03:00
xzxzzxzxzca
1447f88546 Do not touch CMAKE_MODULE_PATH
Now that the library does not provide any CMake find-modules, it is useless to alter the global.
Besides, the only way for a higher level integrating project to provide its own dependency resolution mechanism (Conan, local source tree, etc)relies on appending to CMAKE_MODULE_PATH prior to locating packages. Sdl2pp overriding the variable breaks this mechanism and therefore can only locate a globally installed copy of SDL, which is often inconvenient or plain impossible.
2023-12-11 18:52:32 +03:00
Dmitry Marakasov
b44f34a3f6 Specify codecov token 2023-12-11 17:21:42 +03:00
Dmitry Marakasov
6da8c8d4b7 Fix pip in CI 2023-12-11 17:01:42 +03:00
Dmitry Marakasov
01ba3ddfba Update ci action 2023-04-17 18:28:17 +03:00
Dmitry Marakasov
cc198c9a56 Release 0.18.1 2023-04-17 14:54:20 +03:00
Dmitry Marakasov
120635b1a8 Fix sdlmain link order (fixes #139) 2023-04-17 14:52:42 +03:00
Dmitry Marakasov
7ea8feceee Fix condition in CI script 2023-04-17 14:52:18 +03:00
Dmitry Marakasov
a695265d4d Release 0.18.0 2023-03-27 23:43:40 +03:00
Dmitry Marakasov
7cd6255d13 Disable live tests in CI 2023-03-17 21:57:08 +03:00
Dmitry Marakasov
82429858a6 Switch to cmake scripts provided by SDL2_{mixer,image,ttf} libraries 2023-03-17 21:38:56 +03:00
Dmitry Marakasov
77dac76e8c Update github action 2022-10-26 22:54:25 +03:00
Dmitry Marakasov
77a97972b3 Don't mention C++11 in project description
We currently use C++17 and will switch to a newer standards as
needed.

Fixes #137
2022-09-12 18:06:10 +03:00
Dmitry Marakasov
4eae7e69e1 Replace link to source with permalink 2022-06-16 15:00:13 +03:00
Dmitry Marakasov
3254e07577 Fix quoting for inline preformatted text 2022-06-16 14:59:19 +03:00
Dmitry Marakasov
f2cd04bde8 Fix another shell example 2022-06-16 14:58:36 +03:00
Dmitry Marakasov
19a8d3b9f2 Update installation and usage instructions (fixes #136) 2022-06-16 14:56:50 +03:00
Dmitry Marakasov
d50e7365da Release 0.17.0 2022-04-28 21:47:26 +03:00
Dmitry Marakasov
b82c737a76 Add commits badge 2022-04-28 21:44:55 +03:00
Dmitry Marakasov
5e07f7e1a6 Remove appveyor
I don't see a point and don't have resources to resurrect the windows
build. If needed, it can be reimplemented using GitHub actions.
2022-04-28 21:44:15 +03:00
Dmitry Marakasov
ee1f26ee04 Modernize project version handling in CMake 2022-04-28 21:36:11 +03:00
Dmitry Marakasov
5f01e6c557 Fix optional test 2022-04-28 20:35:35 +03:00
Dmitry Marakasov
e5459845ad Simplify CI script 2022-04-28 20:28:22 +03:00
Dmitry Marakasov
61bee086f9 Switch from pulse to disk audiodriver, which always works 2022-04-28 13:56:42 +03:00
Dmitry Marakasov
545f25e74a Switch to container build with newer ubuntu
This allows us to use newer SDL which has native CMake export module
2022-04-28 13:56:42 +03:00
Dmitry Marakasov
af27cd0099 Switch to modern CMake way of defining targets and installing exports 2022-04-28 13:51:55 +03:00
Dmitry Marakasov
87d5e9f930 Fix updating environment in CI 2022-04-27 23:23:28 +03:00
Dmitry Marakasov
1585650143 Fix action name 2022-04-27 22:38:46 +03:00
Dmitry Marakasov
6426c1d4a8 Simplify coverage handling 2022-04-27 22:38:46 +03:00
Dmitry Marakasov
9e97946869 Install graphviz in CI, needed for doxygen 2022-04-27 22:11:01 +03:00
Dmitry Marakasov
f52aea096c pkg-config exttest is now expected to pass 2022-04-27 22:10:15 +03:00
Dmitry Marakasov
96befaf1a0 Update CMake for exttest as well 2022-04-27 22:09:40 +03:00
Dmitry Marakasov
1556216c47 Remove remaining mentions of SDL2PP_WITH_WERROR 2022-04-27 22:07:06 +03:00
Dmitry Marakasov
0b74fbc7fb Switch to C++17
- Use modern CMake way to set C++ standard
- Remove hacks around Optional, as std::optional is now available
2022-04-27 21:57:46 +03:00
Dmitry Marakasov
63485cc354 Explicitly switch to recent CMake 2022-04-27 21:47:51 +03:00
Dmitry Marakasov
1aa7dae69d Update README 2022-04-27 21:46:17 +03:00
Dmitry Marakasov
e2b68b19cd Switch to GitHub actions 2022-04-27 21:44:52 +03:00
Dmitry Marakasov
5faf8b5a88 Make some flaky tests non-fatal 2022-04-27 21:19:25 +03:00
Dmitry Marakasov
34329a72ef Modernize CMake: remove duplicate loop/if args 2022-04-27 21:12:59 +03:00
Dmitry Marakasov
051e2e24fa Modernize CMake: lowercase directives 2022-04-27 21:10:57 +03:00
Dmitry Marakasov
8b1f87acbe Bump to 0.16.2 2022-04-27 18:14:16 +03:00
Dmitry Marakasov
7eda724660 Fix font dimensions test 2022-04-27 18:12:40 +03:00
Dmitry Marakasov
eb165ec664 Disable doxygen email obfuscation
See https://github.com/doxygen/doxygen/pull/8989
2021-12-30 17:45:51 +03:00
Dmitry Marakasov
a02d5a81c3 Bump to 0.16.1 2020-06-18 00:56:38 +03:00
Dmitry Marakasov
25a610a7a3 Remove broken compiler flags detection, specify explicitly based on compiler 2020-06-18 00:45:21 +03:00
Dmitry Marakasov
78136347ce Disable warnings on unsafe std::copy 2020-06-17 19:29:50 +03:00
Dmitry Marakasov
f43e4203eb Cope with unstable font mertrics in font test 2020-06-17 19:29:50 +03:00
Dmitry Marakasov
0f368b10c8 Fix audiodevice test checks 2020-06-17 19:29:50 +03:00
Dmitry Marakasov
c7351716c0 Fix some implicit int to bool conversions 2020-06-17 19:29:50 +03:00
Dmitry Marakasov
e6a42db209 Remove SDL2PP_WITH_WERROR flag 2019-02-13 00:00:21 +03:00
Dmitry Marakasov
70e57a7ec2 Add comment on optional SDLmain 2018-02-15 23:43:08 +03:00
Dmitry Marakasov
7ff0bb58ea Fix changelog markdown 2018-02-15 23:42:09 +03:00
Dmitry Marakasov
1cdfa085ce Mention SDLmain change in the log 2018-02-15 23:41:59 +03:00
Dmitry Marakasov
2247c53668
Merge pull request #124 from whoozle/master
Removed SDL2MAIN_LIBRARY from the list of requred vars.
2018-02-15 23:37:44 +03:00
Vladimir Menshakov
bfa393497f Removed SDL2MAIN_LIBRARY from the list of requred vars for UNIX platforms only 2018-02-15 20:08:25 +00:00
Vladimir Menshakov
1afe3553f3 Removed SDL2MAIN_LIBRARY from the list of requred vars.
Fedora's SDL2 rpm package is lacking main library, and it looks like SDL is not using this approach anymore, and it can be safely ignored
2018-02-15 11:39:05 +00:00
Dmitry Marakasov
9614417b5b Bump version 2018-02-11 22:48:54 +03:00
Dmitry Marakasov
d1e0a0e8be Reword docs a bit 2018-02-11 22:36:28 +03:00
Dmitry Marakasov
96bd99a9a7 Don't use SDLMixer class in examples
It turns out that it should be initialized after Mixer class (SDL_mixer docs say so,
however official examples use it the other way around. But also it doesn't seem to
ne necessary at all, as SDL loads needed libraries automatically anyway
2018-02-04 18:55:23 +03:00
Dmitry Marakasov
3e2acd191b Update .gitignore with newer cmake generated files 2018-01-14 03:42:12 +03:00
Dmitry Marakasov
57d492a629 Fix Travis build 2018-01-14 03:42:00 +03:00
Dmitry Marakasov
7cfc30970b Merge pull request #110 from Vraiment/fix_doc
Added some missing doc info
2017-07-26 19:07:32 +03:00
Vraiment
f840f11eb3 Added missing '\throws...' to Surface documentation 2017-07-25 19:21:13 -07:00
Vraiment
31c05f8739 Added missing '\throws...' to Window documentation 2017-07-25 19:21:11 -07:00
Dmitry Marakasov
29a3736ab8 Website switched to https 2017-07-21 21:09:19 +03:00
Dmitry Marakasov
ebb4f611bd Merge branch 'master' of github.com:libSDL2pp/libSDL2pp 2017-07-20 14:13:10 +03:00
Dmitry Marakasov
be318346e8 Update copyright 2017-07-20 14:12:58 +03:00
Dmitry Marakasov
f3bc4abd17 Implement SDL_SetWindowResizable()
Fixes #83
2017-07-20 14:12:33 +03:00
Dmitry Marakasov
a839c6e087 Merge pull request #104 from Vraiment/xcode_stuff
Added XCode related config
2017-07-14 16:01:29 +03:00
Vraiment
ba0954901e Added XCode related config 2017-07-14 01:21:07 -07:00
Dmitry Marakasov
a53df08ff8 Add returns to constexpr tests
These are needed since main() is actually replaced with SDL_main()
2017-07-11 17:47:40 +03:00
Dmitry Marakasov
aec2186931 Update version and changelog 2017-07-10 22:43:55 +03:00
Dmitry Marakasov
f194ea01cc Add Vraiment to the list of contributors 2017-07-10 22:40:24 +03:00
Dmitry Marakasov
d0ac22a6fd Whitespace fixes 2017-07-07 22:38:22 +03:00
Dmitry Marakasov
41c96ba25b Fix build for ms compiler 2017-07-07 22:36:28 +03:00
Dmitry Marakasov
913b219256 Since this is constexpr test, use static_asserts 2017-07-07 22:36:28 +03:00
Dmitry Marakasov
4e1042c12f Add Color tests 2017-07-07 22:36:26 +03:00
Dmitry Marakasov
68323591e4 Merge pull request #99 from Vraiment/support_sdl_color
Support SDL color
2017-07-07 21:54:16 +03:00
Vraiment
49251c31a8 Addressed comments in pull request #99 2017-07-05 11:02:34 -07:00
Vraiment
2f3d9a9b5e Added Color files to the CMake file 2017-07-05 11:02:34 -07:00
Vraiment
daab479c0f Added Color support for Texture 2017-07-05 11:02:34 -07:00
Vraiment
b1cc4d5711 Added Color support for Surface 2017-07-05 11:02:34 -07:00
Vraiment
ddaee362a1 Added Color support for Renderer 2017-07-05 11:02:34 -07:00
Vraiment
980fe93481 Added Color class 2017-07-05 11:02:34 -07:00
Dmitry Marakasov
6c7338ab25 Merge pull request #100 from Vraiment/doxygen_fix
Fixed the paths in Doxyfile.in to support paths with spaces
2017-07-04 21:46:41 +03:00
Dmitry Marakasov
cf3f9d4040 Merge pull request #101 from Vraiment/osx_gitignore
Added OS X related files to .gitignore
2017-07-04 21:45:57 +03:00
Vraiment
950c841079 Added OS X related files to .gitignore 2017-07-04 10:08:06 -07:00
Vraiment
c708f08db4 Fixed the paths in Doxyfile.in to support paths with spaces 2017-07-03 22:48:41 -07:00
Dmitry Marakasov
867219a0a1 Mark constants as constexpr, capture implicitly 2017-06-30 21:12:53 +03:00
Dmitry Marakasov
310c545722 Bugfix 0.14.1 release 2017-06-28 22:39:10 +03:00
Dmitry Marakasov
dd3f2da31e Comments with doxygen groups should logically be covered by ifdefs too 2017-06-28 22:36:37 +03:00
Dmitry Marakasov
34137f1ec9 Add missing include to SDL2pp.hh
Fixes #98
2017-06-28 22:36:04 +03:00
Dmitry Marakasov
4b6a975770 Ignore .exe and .o files anywhere
Fixes #96
2017-06-28 14:31:54 +03:00
Dmitry Marakasov
79da16ef6f Fix FIND_PACKAGE_HANDLE_STANDARD_ARGS argument order 2017-06-08 20:28:32 +03:00
Dmitry Marakasov
0c5bf61d38 Fix cmake warning 2017-06-08 20:03:07 +03:00
94 changed files with 1244 additions and 1400 deletions

View File

@ -1,107 +0,0 @@
version: '{branch}.{build}'
os: Visual Studio 2015
clone_depth: 1
environment:
matrix:
- CMAKE_ARGS: -DSDL2PP_ENABLE_LIVE_TESTS=OFF -DCMAKE_CXX_FLAGS="/wd4275 /wd4251 /EHsc" -G "Visual Studio 14 2015"
PREFIX: c:\usr_msvc
MSVC:
MINGW32: rem
- CMAKE_ARGS: -DCMAKE_C_COMPILER=mingw32-gcc -DCMAKE_CXX_COMPILER=mingw32-g++ -DCMAKE_MAKE_PROGRAM=mingw32-make.exe -DCMAKE_VERBOSE_MAKEFILE=ON -DSDL2PP_ENABLE_LIVE_TESTS=OFF -DSDL2PP_WITH_WERROR=YES -G "MinGW Makefiles"
PREFIX: c:\usr_mingw32
MINGW32:
MSVC: rem
cache:
- c:\usr_msvc -> appveyor.yml
- c:\usr_mingw32 -> appveyor.yml
before_build:
- |-
set MINGW32_ARCH=i686-w64-mingw32
- if exist %PREFIX% set NEEDDEPENDS=rem
# Depends
- |-
%NEEDDEPENDS% mkdir %PREFIX%\include\SDL2
%NEEDDEPENDS% mkdir %PREFIX%\lib
%NEEDDEPENDS% cd %TEMP%
# Depends for MSVC
- |-
%NEEDDEPENDS% %MSVC% appveyor DownloadFile http://www.libsdl.org/release/SDL2-devel-2.0.4-VC.zip
%NEEDDEPENDS% %MSVC% 7z x SDL2-devel-2.0.4-VC.zip > nul
%NEEDDEPENDS% %MSVC% copy SDL2-2.0.4\include\* %PREFIX%\include > nul
%NEEDDEPENDS% %MSVC% copy SDL2-2.0.4\lib\x86\* %PREFIX%\lib > nul
- |-
%NEEDDEPENDS% %MSVC% appveyor DownloadFile http://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.1-VC.zip
%NEEDDEPENDS% %MSVC% 7z x SDL2_image-devel-2.0.1-VC.zip > nul
%NEEDDEPENDS% %MSVC% copy SDL2_image-2.0.1\include\* %PREFIX%\include > nul
%NEEDDEPENDS% %MSVC% copy SDL2_image-2.0.1\lib\x86\* %PREFIX%\lib > nul
- |-
%NEEDDEPENDS% %MSVC% appveyor DownloadFile http://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-devel-2.0.1-VC.zip
%NEEDDEPENDS% %MSVC% 7z x SDL2_mixer-devel-2.0.1-VC.zip > nul
%NEEDDEPENDS% %MSVC% copy SDL2_mixer-2.0.1\include\* %PREFIX%\include > nul
%NEEDDEPENDS% %MSVC% copy SDL2_mixer-2.0.1\lib\x86\* %PREFIX%\lib > nul
- |-
%NEEDDEPENDS% %MSVC% appveyor DownloadFile https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-2.0.14-VC.zip
%NEEDDEPENDS% %MSVC% 7z x SDL2_ttf-devel-2.0.14-VC.zip > nul
%NEEDDEPENDS% %MSVC% copy SDL2_ttf-2.0.14\include\* %PREFIX%\include > nul
%NEEDDEPENDS% %MSVC% copy SDL2_ttf-2.0.14\lib\x86\* %PREFIX%\lib > nul
# Depends for MinGW32
- |-
%NEEDDEPENDS% %MINGW32% appveyor DownloadFile http://www.libsdl.org/release/SDL2-devel-2.0.4-mingw.tar.gz
%NEEDDEPENDS% %MINGW32% 7z x SDL2-devel-2.0.4-mingw.tar.gz > nul
%NEEDDEPENDS% %MINGW32% 7z x SDL2-devel-2.0.4-mingw.tar > nul
%NEEDDEPENDS% %MINGW32% copy SDL2-2.0.4\%MINGW32_ARCH%\include\SDL2\* %PREFIX%\include\SDL2 > nul
%NEEDDEPENDS% %MINGW32% copy SDL2-2.0.4\%MINGW32_ARCH%\lib\*.a %PREFIX%\lib > nul
%NEEDDEPENDS% %MINGW32% copy SDL2-2.0.4\%MINGW32_ARCH%\bin\*.dll %PREFIX%\lib > nul
- |-
%NEEDDEPENDS% %MINGW32% appveyor DownloadFile http://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.1-mingw.tar.gz
%NEEDDEPENDS% %MINGW32% 7z x SDL2_image-devel-2.0.1-mingw.tar.gz > nul
%NEEDDEPENDS% %MINGW32% 7z x SDL2_image-devel-2.0.1-mingw.tar > nul
%NEEDDEPENDS% %MINGW32% copy SDL2_image-2.0.1\%MINGW32_ARCH%\include\SDL2\* %PREFIX%\include\SDL2 > nul
%NEEDDEPENDS% %MINGW32% copy SDL2_image-2.0.1\%MINGW32_ARCH%\lib\*.a %PREFIX%\lib > nul
%NEEDDEPENDS% %MINGW32% copy SDL2_image-2.0.1\%MINGW32_ARCH%\bin\*.dll %PREFIX%\lib > nul
- |-
%NEEDDEPENDS% %MINGW32% appveyor DownloadFile https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-devel-2.0.1-mingw.tar.gz
%NEEDDEPENDS% %MINGW32% 7z x SDL2_mixer-devel-2.0.1-mingw.tar.gz > nul
%NEEDDEPENDS% %MINGW32% 7z x SDL2_mixer-devel-2.0.1-mingw.tar > nul
%NEEDDEPENDS% %MINGW32% copy SDL2_mixer-2.0.1\%MINGW32_ARCH%\include\SDL2\* %PREFIX%\include\SDL2 > nul
%NEEDDEPENDS% %MINGW32% copy SDL2_mixer-2.0.1\%MINGW32_ARCH%\lib\*.a %PREFIX%\lib > nul
%NEEDDEPENDS% %MINGW32% copy SDL2_mixer-2.0.1\%MINGW32_ARCH%\bin\*.dll %PREFIX%\lib > nul
- |-
%NEEDDEPENDS% %MINGW32% appveyor DownloadFile https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-2.0.14-mingw.tar.gz
%NEEDDEPENDS% %MINGW32% 7z x SDL2_ttf-devel-2.0.14-mingw.tar.gz > nul
%NEEDDEPENDS% %MINGW32% 7z x SDL2_ttf-devel-2.0.14-mingw.tar > nul
%NEEDDEPENDS% %MINGW32% copy SDL2_ttf-2.0.14\%MINGW32_ARCH%\include\SDL2\* %PREFIX%\include\SDL2 > nul
%NEEDDEPENDS% %MINGW32% copy SDL2_ttf-2.0.14\%MINGW32_ARCH%\lib\*.a %PREFIX%\lib > nul
%NEEDDEPENDS% %MINGW32% copy SDL2_ttf-2.0.14\%MINGW32_ARCH%\bin\*.dll %PREFIX%\lib > nul
build_script:
# build
- |-
%MINGW32% set PATH=c:\mingw\bin;%PATH%
cd %APPVEYOR_BUILD_FOLDER%
cmake -DCMAKE_PREFIX_PATH=%PREFIX% %CMAKE_ARGS% .
cmake --build .
%MINGW32% type FindSDL2PP.cmake
%MINGW32% type sdl2pp.pc
# tests; PATH here lists library search paths
- |-
set PATH=%PREFIX%\lib;%PATH%
%MSVC% set PATH=%APPVEYOR_BUILD_FOLDER%\Debug;%PATH%
%MINGW32% set PATH=%APPVEYOR_BUILD_FOLDER%;%PATH%
ctest -V
after_build:
- git status

64
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,64 @@
name: CI
on: [ push, pull_request ]
jobs:
build:
runs-on: ubuntu-latest
container:
image: ubuntu:rolling
strategy:
matrix:
include:
- { cxx: g++ }
- { cxx: clang++, features: "nooptlibs" }
- { cxx: clang++, features: "static" }
name: ${{ matrix.cxx }} ${{ matrix.features }}
steps:
- uses: actions/checkout@v3
- name: Install dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
apt-get update -qq
apt-get install -yqq --no-install-recommends build-essential clang cmake libsdl2-dev cppcheck doxygen graphviz curl ca-certificates
if [ ${{ !contains(matrix.features, 'nooptlibs') }} = true ]; then
apt-get install -qq --no-install-recommends libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev
fi
- name: Set up environment
run: |
curl https://raw.githubusercontent.com/AMDmi3/github_env/c8cc83d/github_env.py > e; chmod 755 e
./e 'CXX=${{ matrix.cxx }}'
./e 'CXXFLAGS=-Wall -Wextra -pedantic' # XXX: Add -Werror
./e 'CMAKE_ARGS=-DSDL2PP_ENABLE_LIVE_TESTS=NO' # no ability to run live tests in CI (SDL_InitSubsystem failed: x11 not available with xvfb)
./e --if ${{ matrix.cxx == 'clang++' }} 'CXXFLAGS+=-Wno-self-assign-overloaded' # explicit self-assignment tests
./e --if ${{ contains(matrix.features, 'nooptlibs') }} 'CMAKE_ARGS+=-DSDL2PP_WITH_IMAGE=NO -DSDL2PP_WITH_MIXER=NO -DSDL2PP_WITH_TTF=NO'
./e --if ${{ contains(matrix.features, 'static') }} 'CMAKE_ARGS+=-DSDL2PP_STATIC=YES'
- name: Configure
run: cmake . -DCMAKE_VERBOSE_MAKEFILE=yes -DCMAKE_INSTALL_PREFIX=/usr ${CMAKE_ARGS}
- name: Build
run: cmake --build .
- name: Run tests
run: ctest -V
- name: Install
run: cmake --install .
- name: Run cppcheck
# `style' gives false positive in cppcheck 1.61 which comes with trusty
run: cppcheck -I . --enable=performance,portability,information,missingInclude,style --error-exitcode=2 SDL2pp || true
- name: Doxygen check
run: |
make doxygen
if git ls-files --others --exclude-standard | grep ''; then echo 'FATAL: incomplete .gitignore'; false; fi
- name: Testing client code with pkg-config detection
run: |
cd $GITHUB_WORKSPACE/exttests/pkg-config
make
- name: Testing client code with CMake detection
run: |
cd $GITHUB_WORKSPACE/exttests/cmake
cmake .
cmake --build .

44
.github/workflows/doxygen.yml vendored Normal file
View File

@ -0,0 +1,44 @@
name: Doxygen
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
container:
image: ubuntu:rolling
steps:
- uses: actions/checkout@v4
- name: Install dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
apt-get update -qq
apt-get install -yqq --no-install-recommends build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev doxygen graphviz curl ca-certificates git openssh-client
- uses: actions/checkout@v4
with:
repository: libSDL2pp/libSDL2pp.github.io
ssh-key: ${{ secrets.PAGES_SSH_KEY }}
path: doxygen/html
- name: Clean up old docs
run: |
cd doxygen/html
git rm -r .
- name: Configure
run: cmake .
- name: Run doxygen
run: make doxygen
- name: Deploy
run: |
cd doxygen/html
touch .nojekyll
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add .
if git diff --cached --quiet; then
echo "No changes, skipping commit"
else
git commit -m "Update for ${{ github.repository }} commit ${{ github.sha }} run_id ${{ github.run_id }}"
git push --force
fi

13
.gitignore vendored
View File

@ -1,5 +1,7 @@
# CMake files
CMakeCache.txt
CMakeDoxyfile.in
CMakeDoxygenDefaults.cmake
CMakeFiles/
CTestTestfile.cmake
Makefile
@ -17,9 +19,13 @@ sdl2pp.pc
*.sln
Debug/
Win32/
CMakeScripts/
*.build
*.xcodeproj
# Binaries
examples/*.exe
*.o
*.exe
examples/audio_sine
examples/audio_wav
examples/fill
@ -37,6 +43,8 @@ libSDL2pp.dll
libSDL2pp.dll.a
libSDL2pp.so
libSDL2pp.so.*
libSDL2pp.dylib
libSDL2pp.*.dylib
tests/live_*
tests/test_*
!tests/live_*.cc
@ -47,3 +55,6 @@ tests/SDL2pp_*_hh_test*
# Doxygen-generated documentation
doxygen/
# OS Specific files
.DS_Store

View File

@ -1,61 +0,0 @@
language: cpp
sudo: required
dist: trusty
matrix:
include:
# Note that we stick some additional variations to some builds
- compiler: gcc
env: CXXSTD=c++11 BUILD_COVERAGE=yes
- compiler: gcc
env: CXXSTD=c++1y
- compiler: clang
env: CXXSTD=c++11
- compiler: clang
env: CXXSTD=c++1y BUILD_NOOPTLIBS=yes
- compiler: clang
env: CXXSTD=c++1y BUILD_STATIC=yes
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq cmake libsdl2-dev cppcheck doxygen pulseaudio
- sudo sed -i -e '/using ::gets/ d' /usr/include/c++/4.8/cstdio # build failure with clang/c++1y
- |-
if [ -n "${BUILD_COVERAGE}" ]; then
export CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Coverage"
pip install --user pyyaml cpp-coveralls
fi
if [ -n "${BUILD_NOOPTLIBS}" ]; then
export CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DSDL2PP_WITH_IMAGE=NO -DSDL2PP_WITH_MIXER=NO -DSDL2PP_WITH_TTF=NO"
else
sudo apt-get install -qq libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev
fi
if [ -n "${BUILD_STATIC}" ]; then
export CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DSDL2PP_STATIC=YES"
fi
# evironment for live tests
- dbus-launch pulseaudio --start
- export SDL_AUDIODRIVER=pulseaudio
- /sbin/start-stop-daemon --start --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 800x600x24 -ac +extension GLX
- export SDL_VIDEODRIVER=x11
- export DISPLAY=:99.0
script:
- export PREFIX=`pwd`.prefix
- cmake . -DCMAKE_INSTALL_PREFIX=${PREFIX} -DSDL2PP_WITH_WERROR=YES -DSDL2PP_CXXSTD=${CXXSTD} ${CMAKE_EXTRA_ARGS}
- VERBOSE=1 make && make ARGS=-V test && make install
- cppcheck -I . --enable=performance,portability,information,missingInclude --error-exitcode=2 SDL2pp # `style' gives false positive in cppcheck 1.61 which comes with trusty
- make doxygen
# - "if make doxygen 2>&1 | grep 'warning:'; then echo 'FATAL: doxygen warnings!'; false; fi"
- "if git ls-files --others --exclude-standard | grep ''; then echo 'FATAL: incomplete .gitignore'; false; fi"
- cat ${TRAVIS_BUILD_DIR}/sdl2pp.pc
- cd ${TRAVIS_BUILD_DIR}/exttests/pkg-config && PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig make
- cat ${TRAVIS_BUILD_DIR}/FindSDL2PP.cmake
- cd ${TRAVIS_BUILD_DIR}/exttests/cmake && cmake -DCMAKE_MODULE_PATH=${PREFIX}/share/cmake/Modules . && make
- cd ${TRAVIS_BUILD_DIR}
after_success:
- if [ -n "${BUILD_COVERAGE}" ]; then coveralls -i SDL2pp; fi

View File

@ -2,13 +2,49 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## 0.18.1 - 2023-04-17
### Fixed
* Fix SDL2main library link order
## 0.18.0 - 2023-03-27
### Changed
* Switch SDL2_{mixer,mixer,ttf} detection to upstream CMake scripts
## 0.17.0 - 2022-04-28
### Changed
* Switch to modern CMake
* Switch to C++17
## 0.16.2 - 2022-04-25
### Fixed
* Fix font dimensions test
## 0.16.1 - 2020-06-18
### Fixed
* Make `SDLmain` library optional in Unix, since some distros seem to drop it
* Fix using unsupported warning flags on some compilers
## 0.16.0 - 2018-02-11
### Added
* New SDL 2.0.5 `Window` method: `Window::SetResizable()`
* Minor documentation improvements
* Example code fixes
## 0.15.0 - 2017-07-10
### Added
* `Color` class wrapping around `SDL_Color`
## 0.14.1 - 2017-06-28
### Fixed
* `Surface.hh` include was missing from `SDL2pp.hh`
## 0.14.0 - 2017-05-29
### Fixed
* Proper ```Size()``` handling for custom ```RWops```
* Proper `Size()` handling for custom `RWops`
### Added
* ```Window::GetOpacity()``` and ```Window()::SetOpacity()``` wrappers for functions appeared in SDL 2.0.5
* ```Music``` RWops constructors based on undocumented SDL_mixer functions
* `Window::GetOpacity()` and `Window()::SetOpacity()` wrappers for functions appeared in SDL 2.0.5
* `Music` RWops constructors based on undocumented SDL_mixer functions
* Static standalone build support
### Changed
@ -16,21 +52,21 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## 0.13.0 - 2016-11-08
### Fixed
* Fixed SDL 2.0.4 specific ```AudioDevice``` methods: ```AudioDevice::QueueAudio()```, ```AudioDevice::GetQueuedAudioSize()```
* Fixed SDL 2.0.4 specific `AudioDevice` methods: `AudioDevice::QueueAudio()`, `AudioDevice::GetQueuedAudioSize()`
* Fixed MSVC compiler support and .dll generation
* Multiple documentation fixes
### Added
* More tests
* Automatic SDL 2.0.4 detection
* ```Texture::Update()``` overload which takes rvalue reference to ```Surface```
* `Texture::Update()` overload which takes rvalue reference to `Surface`
### Changed
* ```Renderer::GetClipRect``` now returns ```Optional<Rect>``` instead of (possibly empty) ```Rect```
* ```Exception``` is now derived from ```std::runtime_error```
* `Renderer::GetClipRect` now returns `Optional<Rect>` instead of (possibly empty) `Rect`
* `Exception` is now derived from `std::runtime_error`
### Removed
* Deprecated ```Renderer::GetInfo()``` variant which takes pointer (use variant which takes reference)
* Deprecated `Renderer::GetInfo()` variant which takes pointer (use variant which takes reference)
## 0.12.0 - 2016-01-23
### Fixed
@ -41,45 +77,45 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## 0.11.0 - 2015-11-30
### Added
* New ```Window``` methods: ```Window::GetDrawableWidth()```, ```Window::GetDrawableHeight()```, ```Window::GetDrawableSize()``` (@csoren)
* ```Point``` and ```Rect``` less-than operators and std::hash support which makes them usable as ```std::map```/```std::unordered_map```/```std::set```/```std::unordered_set``` keys
* More ```Rect``` methods and wider constexpr support
* New `Window` methods: `Window::GetDrawableWidth()`, `Window::GetDrawableHeight()`, `Window::GetDrawableSize()` (@csoren)
* `Point` and `Rect` less-than operators and std::hash support which makes them usable as `std::map`/`std::unordered_map`/`std::set`/`std::unordered_set` keys
* More `Rect` methods and wider constexpr support
### Fixed
* ```Rect``` documentation fixes
* `Rect` documentation fixes
* Unused variable warnings (@vladimirgamalian)
* Incorrect return value handling in ```Surface::SetClipRect()```
* Incorrect return value handling in `Surface::SetClipRect()`
## 0.10.0 - 2015-10-14
### Fixed
* Improved cygwin compatibility
* Missing ```SDL``` method implementations
* Fixed return and argument types for some ```Window```, ```Font``` and ```Mixer``` methods to match upstream API
* Infinite loop in ```StreamRWops```
* Missing `SDL` method implementations
* Fixed return and argument types for some `Window`, `Font` and `Mixer` methods to match upstream API
* Infinite loop in `StreamRWops`
* Documentation improvements
* Build without [SDL_mixer](https://www.libsdl.org/projects/SDL_mixer/) support
## 0.9.0 - 2015-09-07
### Added
* [SDL_mixer](https://www.libsdl.org/projects/SDL_mixer/) support
* More ```Point``` operators: ```*```, ```/```, ```%``` for integer multiplication, division and remainder by a number or another ```Point```
* ```Point``` and ```Rect``` better inlining and constexpr support
* New method: ```Surface::GetFormat()```
* ```Texture::Update()``` overload which takes Surface as pixel source
* More `Point` operators: `*`, `/`, `%` for integer multiplication, division and remainder by a number or another `Point`
* `Point` and `Rect` better inlining and constexpr support
* New method: `Surface::GetFormat()`
* `Texture::Update()` overload which takes Surface as pixel source
## 0.8.2 - 2015-07-28
### Fixed
* Add missing ```Font::IsGlyphProvided()``` implementation (@vladimirgamalian)
* Fix glyph rectangle calculation in ```Font::GetGlyphRect()``` (@vladimirgamalian)
* Add missing `Font::IsGlyphProvided()` implementation (@vladimirgamalian)
* Fix glyph rectangle calculation in `Font::GetGlyphRect()` (@vladimirgamalian)
## 0.8.1 - 2015-06-29
### Fixed
* Use correct type flags in ```RWops::Size()```, fixing MinGW build (@vladimirgamalian)
* Use correct type flags in `RWops::Size()`, fixing MinGW build (@vladimirgamalian)
## 0.8.0 - 2015-06-10
### Added
* ```Render::Copy()``` overload which takes target ```Point``` instead of a ```Rect```
* New method ```Render::FillCopy()``` which fills target rect with repeated texture
* `Render::Copy()` overload which takes target `Point` instead of a `Rect`
* New method `Render::FillCopy()` which fills target rect with repeated texture
* Improved UTF-16 font rendering support
* CMake module file
@ -89,30 +125,30 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## 0.7.0 - 2015-01-22
### Added
* More ```Texture```, ```Renderer``` (both complete now) and ```Window``` methods
* New methods: ```Point::Clamp()```, ```Point::Wrap()```, ```Rect::Extend()```, ```Rect::IntersectLine()```
* STL stream output for ```Point``` and ```Rect``` (as in ```std::cout << Rect(10, 20, 30 40);```)
* More `Texture`, `Renderer` (both complete now) and `Window` methods
* New methods: `Point::Clamp()`, `Point::Wrap()`, `Rect::Extend()`, `Rect::IntersectLine()`
* STL stream output for `Point` and `Rect` (as in `std::cout << Rect(10, 20, 30 40);`)
### Changed
* Most setters now return reference to self to allow method chaining
* Exception now stores both SDL error and name of function which caused it; ```what()``` message now includes these both in a readable way, so SDL2pp exceptions may be conveniently handled with ```catch (std::exception&)```
* Exception now stores both SDL error and name of function which caused it; `what()` message now includes these both in a readable way, so SDL2pp exceptions may be conveniently handled with `catch (std::exception&)`
* pkg-config file now provides SDL libraries along with SDL2pp, so users don't need to care of SDL2 flags in addition to SDL2pp's
### Removed
* Deprecated ```Point``` and ```Rect``` methods: ```Null()```, ```IsNull()```, ```Get()```
* Deprecated `Point` and `Rect` methods: `Null()`, `IsNull()`, `Get()`
### Fixed
* Use move, not copy in constructing ```RWops``` from ```CustomRWops```-derived class
* Use move, not copy in constructing `RWops` from `CustomRWops`-derived class
## 0.6.0 - 2015-01-11
### Added
* [Doxygen](http://doxygen.org/) documentation for the whole library
* Wrapper around [SDL_image](https://www.libsdl.org/projects/SDL_image/) initialization/deinitialization: ```SDLImage``` class
* ```Surface````, a wrapepr for [SDL_Surface](https://wiki.libsdl.org/SDL_Surface) including [SDL_image](https://www.libsdl.org/projects/SDL_image/) support. It's now also possible to construct ```Texture``` from ```Surface```.
* Bunch of constructors from existing SDL objects (e.g. ```Window::Window(SDL_Window*)```) for ```Point```, ```Rect```, ```Window```, ```Renderer```, ```Texture```
* Wrapper around [SDL_image](https://www.libsdl.org/projects/SDL_image/) initialization/deinitialization: `SDLImage` class
* `Surface``, a wrapepr for [SDL_Surface](https://wiki.libsdl.org/SDL_Surface) including [SDL_image](https://www.libsdl.org/projects/SDL_image/) support. It's now also possible to construct `Texture` from `Surface`.
* Bunch of constructors from existing SDL objects (e.g. `Window::Window(SDL_Window*)`) for `Point`, `Rect`, `Window`, `Renderer`, `Texture`
* Complete [SDL_ttf](https://www.libsdl.org/projects/SDL_ttf/) support
* Consistent ```GetWidth()```/```GetHeight()```/```GetSize()``` for ```Texture``` and ```Surface```
* More operators, constructors and methods for ```Point``` and ```Rect```
* Consistent `GetWidth()`/`GetHeight()`/`GetSize()` for `Texture` and `Surface`
* More operators, constructors and methods for `Point` and `Rect`
### Fixed
* Added proper error checking for SDL_image-using Texture constructors
@ -128,34 +164,34 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## 0.5.0 - 2014-12-26
### Added
* ```AudioDevice::LockHandle``` is now copyable
* ```Rect``` now has ```+``` ```-``` ```+=``` ```-=``` operators to offset it by a ```Point```
* ```Optional``` class to pass optional values
* `AudioDevice::LockHandle` is now copyable
* `Rect` now has `+` `-` `+=` `-=` operators to offset it by a `Point`
* `Optional` class to pass optional values
* Possibility to use c++1y standard and detection of available useful c++1y features with c++11
* Default argument for ```Texture::Lock()```
* Bunch of ```Window``` functions: ```Window::Maximize()```, ```Window::Minimize()```, ```Window::Hide()```, ```Window::Restore()```, ```Window::Raise()```, ```Window::Show()```, ```Window::SetFullscreen()```, ```Window::SetSize()```
* Default argument for `Texture::Lock()`
* Bunch of `Window` functions: `Window::Maximize()`, `Window::Minimize()`, `Window::Hide()`, `Window::Restore()`, `Window::Raise()`, `Window::Show()`, `Window::SetFullscreen()`, `Window::SetSize()`
* More granular build options for tests and examples
### Changed
* ```Point``` and ```Rect``` no longer have invalid (null) states and are now directly derived from [SDL_Point](https://wiki.libsdl.org/SDL_Point) and [SDL_Rect](https://wiki.libsdl.org/SDL_Rect) structures. In places where null states were usable (e.g. usually null ```Rect``` would mean "whole area", like in ```Texture::Lock()```), ```Optional``` class is now used. Use ```NullOpt``` instead of ```Point::Null()``` and ```Rect::Null()```
* `Point` and `Rect` no longer have invalid (null) states and are now directly derived from [SDL_Point](https://wiki.libsdl.org/SDL_Point) and [SDL_Rect](https://wiki.libsdl.org/SDL_Rect) structures. In places where null states were usable (e.g. usually null `Rect` would mean "whole area", like in `Texture::Lock()`), `Optional` class is now used. Use `NullOpt` instead of `Point::Null()` and `Rect::Null()`
## 0.4.0 - 2014-12-19
### Added
* ```StreamRWops``` which works with STL streams
* ```AudioDevice``` and ```Texture``` ```LockHandle```s now have empty constructors and may be initialized after construction
* ```RWops``` ```(Read|Write)(LE|BE)(16|32|64)``` methods
* `StreamRWops` which works with STL streams
* `AudioDevice` and `Texture` `LockHandle`s now have empty constructors and may be initialized after construction
* `RWops` `(Read|Write)(LE|BE)(16|32|64)` methods
* pkg-config file
### Changed
* Plain ```ContainerRWops``` is now able to work with both const and mutable containers
* Audio callback is now tied to ```AudioDevice```, not ```AudioSpec```, which is cleaner and easier to use
* Plain `ContainerRWops` is now able to work with both const and mutable containers
* Audio callback is now tied to `AudioDevice`, not `AudioSpec`, which is cleaner and easier to use
### Removed
* ```ConstContainerRWops``` which is no longer needed
* `ConstContainerRWops` which is no longer needed
### Fixed
* Exception safety when changing audio callback
* Made ```-Werror``` flag conditional for user convenience
* Made `-Werror` flag conditional for user convenience
## 0.3.0 - 2014-11-30
### Added
@ -166,9 +202,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## 0.2.0 - 2014-11-25
### Added
* Getters for ```Texture``` properties: ```Texture::GetWidth()```, ```Texture::GetHeight()```, ```Texture::GetFormat()```, ```Texture::GetAccess()```
* ```Texture``` locking
* New ```Rect``` method ```Rect::Contains()``` to check if it contains a ```Point```
* Getters for `Texture` properties: `Texture::GetWidth()`, `Texture::GetHeight()`, `Texture::GetFormat()`, `Texture::GetAccess()`
* `Texture` locking
* New `Rect` method `Rect::Contains()` to check if it contains a `Point`
## 0.1.1 - 2014-09-09
### Added
@ -178,11 +214,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## 0.1.0 - 2014-09-05
### Added
* [SDL2_image](https://www.libsdl.org/projects/SDL_image/) support
* ```RWops``` support
* New ```Renderer``` methods: ```Renderer::SetClipRect()```, ```Renderer::SetScale()```, ```Renderer::SetViewport()```, ```Renderer::TargetSupported()```
* New ```SDL``` methods: ```SDL::WasInit()```, ```SDL::InitSubsystem()```, ```SDL::QuitSubSystem()```
* `RWops` support
* New `Renderer` methods: `Renderer::SetClipRect()`, `Renderer::SetScale()`, `Renderer::SetViewport()`, `Renderer::TargetSupported()`
* New `SDL` methods: `SDL::WasInit()`, `SDL::InitSubsystem()`, `SDL::QuitSubSystem()`
* Basic MSVC support
* Arithmetic operators for ```Point```
* Arithmetic operators for `Point`
### Fixed
* GUI tests which are sensible to OpenGL implementation-specific behavior are no longer fatal
@ -190,10 +226,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## 0.0.2 - 2014-02-11
### Added
* Unit tests
* New ```Window``` methods: ```Window::GetSize()```, ```Window::GetWidth()```, ```Window::GetHeight()```, ```Window::SetTitle()```
* New ```Renderer``` method: ```Renderer::ReadPixels()```
* ```Point``` and ```Rect``` setters and comparison operators
* New `Window` methods: `Window::GetSize()`, `Window::GetWidth()`, `Window::GetHeight()`, `Window::SetTitle()`
* New `Renderer` method: `Renderer::ReadPixels()`
* `Point` and `Rect` setters and comparison operators
## 0.0.1 - 2014-02-01
### Added
* Initial release supporting basic ```Window```, ```Renderer```, ```Texture```, ```Rect``` and ```Point``` handling
* Initial release supporting basic `Window`, `Renderer`, `Texture`, `Rect` and `Point` handling

View File

@ -1,130 +1,92 @@
PROJECT(libSDL2pp)
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
# meta
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
project(libSDL2pp LANGUAGES CXX VERSION 0.18.1)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
SET(SDL2PP_MAJOR_VERSION 0)
SET(SDL2PP_MINOR_VERSION 14)
SET(SDL2PP_PATCH_VERSION 0)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
option(SDL2PP_WITH_IMAGE "Enable SDL2_image support" ON)
option(SDL2PP_WITH_TTF "Enable SDL2_ttf support" ON)
option(SDL2PP_WITH_MIXER "Enable SDL2_mixer support" ON)
SET(SDL2PP_VERSION "${SDL2PP_MAJOR_VERSION}.${SDL2PP_MINOR_VERSION}.${SDL2PP_PATCH_VERSION}")
# there are functions present on wiki, but not yet in stable SDL2 releases;
# we hide these under following options
OPTION(SDL2PP_WITH_WERROR "Make warnings fatal" OFF)
SET(SDL2PP_CXXSTD "c++11" CACHE STRING "Used c++ standard")
IF(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
OPTION(SDL2PP_WITH_IMAGE "Enable SDL2_image support" ON)
OPTION(SDL2PP_WITH_TTF "Enable SDL2_ttf support" ON)
OPTION(SDL2PP_WITH_MIXER "Enable SDL2_mixer support" ON)
ELSE(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
option(SDL2PP_WITH_EXAMPLES "Build examples" ON)
option(SDL2PP_WITH_TESTS "Build tests" ON)
option(SDL2PP_ENABLE_LIVE_TESTS "Enable live tests (require X11 display and audio device)" ON)
option(SDL2PP_STATIC "Build static library instead of shared one" OFF)
else()
# please set SDL2PP_WITH_IMAGE, SDL2PP_WITH_TTF, SDL2PP_WITH_MIXER in parent project as needed
ENDIF(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
endif()
# depends
FIND_PACKAGE(SDL2 REQUIRED)
SET(SDL2_ALL_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
SET(SDL2_ALL_LIBRARIES ${SDL2_LIBRARY})
SET(SDL2_ALL_PKGCONFIG_MODULES sdl2)
SET(SDL2PP_EXTRA_LIBRARIES ${SDL2MAIN_LIBRARY})
SET(SDL2PP_EXTRA_PKGCONFIG_LIBRARIES ${SDL2MAIN_LIBRARY})
find_package(SDL2 REQUIRED)
set(SDL2_ALL_LIBRARIES SDL2::SDL2)
set(SDL2_ALL_PKGCONFIG_MODULES sdl2)
IF(MINGW)
SET(MINGW32_LIBRARY "mingw32" CACHE STRING "mingw32 library")
SET(SDL2PP_EXTRA_LIBRARIES ${MINGW32_LIBRARY} ${SDL2PP_EXTRA_LIBRARIES})
SET(SDL2PP_EXTRA_PKGCONFIG_LIBRARIES "-l${MINGW32_LIBRARY} ${SDL2PP_EXTRA_PKGCONFIG_LIBRARIES}")
ENDIF(MINGW)
if(TARGET SDL2::SDL2main)
set(SDL2_ALL_LIBRARIES SDL2::SDL2main ${SDL2_ALL_LIBRARIES})
endif()
IF(SDL2PP_WITH_IMAGE)
FIND_PACKAGE(SDL2_image REQUIRED)
SET(SDL2_ALL_INCLUDE_DIRS ${SDL2_ALL_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIR})
SET(SDL2_ALL_LIBRARIES ${SDL2_ALL_LIBRARIES} ${SDL2_IMAGE_LIBRARY})
SET(SDL2_ALL_PKGCONFIG_MODULES "${SDL2_ALL_PKGCONFIG_MODULES} SDL2_image")
ELSE(SDL2PP_WITH_IMAGE)
MESSAGE(STATUS "SDL2_image support disabled")
ENDIF(SDL2PP_WITH_IMAGE)
if(MINGW)
set(MINGW32_LIBRARY "mingw32" CACHE STRING "mingw32 library")
set(SDL2PP_EXTRA_LIBRARIES ${MINGW32_LIBRARY} ${SDL2PP_EXTRA_LIBRARIES})
set(SDL2PP_EXTRA_PKGCONFIG_LIBRARIES "-l${MINGW32_LIBRARY} ${SDL2PP_EXTRA_PKGCONFIG_LIBRARIES}")
endif()
IF(SDL2PP_WITH_TTF)
FIND_PACKAGE(SDL2_ttf REQUIRED)
SET(SDL2_ALL_INCLUDE_DIRS ${SDL2_ALL_INCLUDE_DIRS} ${SDL2_TTF_INCLUDE_DIR})
SET(SDL2_ALL_LIBRARIES ${SDL2_ALL_LIBRARIES} ${SDL2_TTF_LIBRARY})
SET(SDL2_ALL_PKGCONFIG_MODULES "${SDL2_ALL_PKGCONFIG_MODULES} SDL2_ttf")
ELSE(SDL2PP_WITH_TTF)
MESSAGE(STATUS "SDL2_ttf support disabled")
ENDIF(SDL2PP_WITH_TTF)
if(SDL2PP_WITH_IMAGE)
find_package(SDL2_image REQUIRED)
set(SDL2_ALL_LIBRARIES ${SDL2_ALL_LIBRARIES} SDL2_image::SDL2_image)
set(SDL2_ALL_PKGCONFIG_MODULES "${SDL2_ALL_PKGCONFIG_MODULES} SDL2_image")
else()
message(STATUS "SDL2_image support disabled")
endif()
IF(SDL2PP_WITH_MIXER)
FIND_PACKAGE(SDL2_mixer REQUIRED)
SET(SDL2_ALL_INCLUDE_DIRS ${SDL2_ALL_INCLUDE_DIRS} ${SDL2_MIXER_INCLUDE_DIR})
SET(SDL2_ALL_LIBRARIES ${SDL2_ALL_LIBRARIES} ${SDL2_MIXER_LIBRARY})
SET(SDL2_ALL_PKGCONFIG_MODULES "${SDL2_ALL_PKGCONFIG_MODULES} SDL2_mixer")
ELSE(SDL2PP_WITH_MIXER)
MESSAGE(STATUS "SDL2_mixer support disabled")
ENDIF(SDL2PP_WITH_MIXER)
if(SDL2PP_WITH_TTF)
find_package(SDL2_ttf REQUIRED)
set(SDL2_ALL_LIBRARIES ${SDL2_ALL_LIBRARIES} SDL2_ttf::SDL2_ttf)
set(SDL2_ALL_PKGCONFIG_MODULES "${SDL2_ALL_PKGCONFIG_MODULES} SDL2_ttf")
else()
message(STATUS "SDL2_ttf support disabled")
endif()
if(SDL2PP_WITH_MIXER)
find_package(SDL2_mixer REQUIRED)
set(SDL2_ALL_LIBRARIES ${SDL2_ALL_LIBRARIES} SDL2_mixer::SDL2_mixer)
set(SDL2_ALL_PKGCONFIG_MODULES "${SDL2_ALL_PKGCONFIG_MODULES} SDL2_mixer")
else()
message(STATUS "SDL2_mixer support disabled")
endif()
# compiler flags & definitions
IF(MSVC)
SET(SDL2PP_WARNINGS "${SDL2PP_WARNINGS} /W3")
SET(SDL2PP_WERROR_FLAG "/WX")
ELSE(MSVC)
SET(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} --coverage")
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage")
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --coverage")
#if(MSVC)
# set(SDL2PP_WARNINGS "${SDL2PP_WARNINGS} /W3")
#else()
# set(SDL2PP_WARNINGS "${SDL2PP_WARNINGS} -Wall -Wextra -pedantic")
#
# if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# set(SDL2PP_WARNINGS "${SDL2PP_WARNINGS} -Wmissing-prototypes -Wtautological-compare -Wshorten-64-to-32")
#
# # For adventurous
# #set(SDL2PP_WARNINGS "${SDL2PP_WARNINGS} -Weverything -Wno-c++98-compat -Wno-padded")
# endif()
#endif()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${SDL2PP_CXXSTD}")
SET(SDL2PP_WARNINGS "${SDL2PP_WARNINGS} -Wall -Wextra -pedantic")
SET(SDL2PP_WERROR_FLAG "-Werror")
INCLUDE(AppendCXXFlagIfSupported)
# enable for more cleanups
#APPEND_CXX_FLAG_IF_SUPPORTED(-Weverything SDL2PP_WARNINGS)
# always enables some -Weverything warnings
APPEND_CXX_FLAG_IF_SUPPORTED(-Wmissing-prototypes SDL2PP_WARNINGS)
APPEND_CXX_FLAG_IF_SUPPORTED(-Wtautological-compare SDL2PP_WARNINGS)
APPEND_CXX_FLAG_IF_SUPPORTED(-Wshorten-64-to-32 SDL2PP_WARNINGS)
# disable some -Weverything warnings
#APPEND_CXX_FLAG_IF_SUPPORTED(-Wno-c++98-compat SDL2PP_WARNINGS)
#APPEND_CXX_FLAG_IF_SUPPORTED(-Wno-padded SDL2PP_WARNINGS)
ENDIF(MSVC)
LIST(REMOVE_DUPLICATES SDL2_ALL_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(BEFORE ${PROJECT_SOURCE_DIR})
INCLUDE_DIRECTORIES(SYSTEM ${SDL2_ALL_INCLUDE_DIRS})
INCLUDE(CheckCompile)
CHECK_COMPILE(
SDL2PP_WITH_EXPERIMENTAL_OPTIONAL
"#include <experimental/optional>\nint main() { std::experimental::optional<int> o; return !o; }"
"experimental/optional header"
)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SDL2PP_WARNINGS}")
IF(SDL2PP_WITH_WERROR)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SDL2PP_WERROR_FLAG}")
ENDIF(SDL2PP_WITH_WERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SDL2PP_WARNINGS}")
# config.h
CONFIGURE_FILE(
configure_file(
SDL2pp/Config.hh.in
SDL2pp/Config.hh
)
INCLUDE_DIRECTORIES(BEFORE ${PROJECT_BINARY_DIR})
# sources
SET(LIBRARY_SOURCES
set(LIBRARY_SOURCES
SDL2pp/AudioDevice.cc
SDL2pp/AudioLock.cc
SDL2pp/AudioSpec.cc
SDL2pp/Color.cc
SDL2pp/Exception.cc
SDL2pp/Point.cc
SDL2pp/RWops.cc
@ -139,9 +101,10 @@ SET(LIBRARY_SOURCES
SDL2pp/Window.cc
)
SET(LIBRARY_HEADERS
set(LIBRARY_HEADERS
SDL2pp/AudioDevice.hh
SDL2pp/AudioSpec.hh
SDL2pp/Color.hh
SDL2pp/ContainerRWops.hh
SDL2pp/Exception.hh
SDL2pp/Optional.hh
@ -158,146 +121,125 @@ SET(LIBRARY_HEADERS
SDL2pp/Window.hh
)
SET(LIBRARY_EXTERNAL_HEADERS
SDL2pp/external/libcpp_optional.hh
)
# optional sources
IF(SDL2PP_WITH_TTF)
SET(LIBRARY_SOURCES
if(SDL2PP_WITH_TTF)
set(LIBRARY_SOURCES
${LIBRARY_SOURCES}
SDL2pp/SDLTTF.cc
SDL2pp/Font.cc
)
SET(LIBRARY_HEADERS
set(LIBRARY_HEADERS
${LIBRARY_HEADERS}
SDL2pp/SDLTTF.hh
SDL2pp/Font.hh
)
ENDIF(SDL2PP_WITH_TTF)
endif()
IF(SDL2PP_WITH_IMAGE)
SET(LIBRARY_SOURCES
if(SDL2PP_WITH_IMAGE)
set(LIBRARY_SOURCES
${LIBRARY_SOURCES}
SDL2pp/SDLImage.cc
)
SET(LIBRARY_HEADERS
set(LIBRARY_HEADERS
${LIBRARY_HEADERS}
SDL2pp/SDLImage.hh
)
ENDIF(SDL2PP_WITH_IMAGE)
endif()
IF(SDL2PP_WITH_MIXER)
SET(LIBRARY_SOURCES
if(SDL2PP_WITH_MIXER)
set(LIBRARY_SOURCES
${LIBRARY_SOURCES}
SDL2pp/Chunk.cc
SDL2pp/Mixer.cc
SDL2pp/Music.cc
SDL2pp/SDLMixer.cc
)
SET(LIBRARY_HEADERS
set(LIBRARY_HEADERS
${LIBRARY_HEADERS}
SDL2pp/Chunk.hh
SDL2pp/Mixer.hh
SDL2pp/Music.hh
SDL2pp/SDLMixer.hh
)
ENDIF(SDL2PP_WITH_MIXER)
endif()
# targets
INCLUDE(GenerateExportHeader)
include(GenerateExportHeader)
IF(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# options
OPTION(SDL2PP_WITH_EXAMPLES "Build examples" ON)
OPTION(SDL2PP_WITH_TESTS "Build tests" ON)
OPTION(SDL2PP_ENABLE_LIVE_TESTS "Enable live tests (require X11 display and audio device)" ON)
OPTION(SDL2PP_STATIC "Build static library instead of shared one" OFF)
if(SDL2PP_STATIC)
add_library(SDL2pp STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
set_target_properties(SDL2pp PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
else()
add_library(SDL2pp SHARED ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
set_target_properties(SDL2pp PROPERTIES
VERSION 8.3.0
SOVERSION 8
C_VISIBILITY_PRESET hidden
)
endif()
target_include_directories(SDL2pp PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(SDL2pp PUBLIC ${SDL2_ALL_LIBRARIES})
generate_export_header(SDL2pp EXPORT_FILE_NAME SDL2pp/Export.hh)
# library
IF(SDL2PP_STATIC)
ADD_LIBRARY(SDL2pp STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
ELSE(SDL2PP_STATIC)
ADD_LIBRARY(SDL2pp SHARED ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
TARGET_LINK_LIBRARIES(SDL2pp ${SDL2_ALL_LIBRARIES})
SET_TARGET_PROPERTIES(SDL2pp PROPERTIES VERSION 8.1.0 SOVERSION 8)
ENDIF(SDL2PP_SHARED)
GENERATE_EXPORT_HEADER(SDL2pp EXPORT_FILE_NAME SDL2pp/Export.hh)
SET(SDL2PP_LIBRARIES ${SDL2PP_EXTRA_LIBRARIES} SDL2pp ${SDL2_ALL_LIBRARIES})
add_library(SDL2pp::SDL2pp ALIAS SDL2pp)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# examples and tests
IF(SDL2PP_WITH_EXAMPLES)
ADD_SUBDIRECTORY(examples)
ENDIF(SDL2PP_WITH_EXAMPLES)
if(SDL2PP_WITH_EXAMPLES)
add_subdirectory(examples)
endif()
IF(SDL2PP_WITH_TESTS)
ENABLE_TESTING()
ADD_SUBDIRECTORY(tests)
ENDIF(SDL2PP_WITH_TESTS)
if(SDL2PP_WITH_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# doxygen
FIND_PACKAGE(Doxygen)
IF(DOXYGEN_FOUND)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
ADD_CUSTOM_TARGET(doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doxygen
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
ENDIF(DOXYGEN_FOUND)
# pkgconfig and cmake modules
SET(CMAKEMODDIR share/cmake/Modules CACHE STRING "directory where to install cmake module")
SET(PKGCONFIGDIR lib/pkgconfig CACHE STRING "directory where to install pkg-config files")
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "DragonFly")
SET(PKGCONFIGDIR libdata/pkgconfig)
ENDIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "DragonFly")
INCLUDE(Join)
JOIN_QUOTED("${SDL2PP_EXTRA_LIBRARIES}" SDL2PP_EXTRA_LIBRARIES_STR)
JOIN_QUOTED("${SDL2_ALL_LIBRARIES}" SDL2_ALL_LIBRARIES_STR)
JOIN_QUOTED("${SDL2_ALL_INCLUDE_DIRS}" SDL2_ALL_INCLUDE_DIRS_STR)
CONFIGURE_FILE(
sdl2pp.pc.in
sdl2pp.pc
@ONLY
)
CONFIGURE_FILE(
FindSDL2PP.cmake.in
FindSDL2PP.cmake
@ONLY
)
endif()
# install
INSTALL(FILES
${LIBRARY_HEADERS}
${PROJECT_BINARY_DIR}/SDL2pp/Config.hh
${PROJECT_BINARY_DIR}/SDL2pp/Export.hh
DESTINATION include/SDL2pp
include(GNUInstallDirs)
install(TARGETS SDL2pp
EXPORT SDL2pp-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
INSTALL(FILES ${LIBRARY_EXTERNAL_HEADERS} DESTINATION include/SDL2pp/external)
INSTALL(TARGETS SDL2pp
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
install(
FILES
${LIBRARY_HEADERS}
${PROJECT_BINARY_DIR}/SDL2pp/Config.hh
${PROJECT_BINARY_DIR}/SDL2pp/Export.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SDL2pp
)
INSTALL(FILES ${PROJECT_BINARY_DIR}/sdl2pp.pc DESTINATION ${PKGCONFIGDIR})
INSTALL(FILES ${PROJECT_BINARY_DIR}/FindSDL2PP.cmake DESTINATION ${CMAKEMODDIR})
MESSAGE(STATUS "libSDL2pp ${SDL2PP_VERSION} standalone build")
ELSE(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# library
ADD_LIBRARY(SDL2pp STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
GENERATE_EXPORT_HEADER(SDL2pp EXPORT_FILE_NAME SDL2pp/Export.hh)
configure_file(sdl2pp.pc.in sdl2pp.pc @ONLY)
install(
FILES
${PROJECT_BINARY_DIR}/sdl2pp.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
# provide variables to parent
SET(SDL2PP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${SDL2_ALL_INCLUDE_DIRS} PARENT_SCOPE)
SET(SDL2PP_LIBRARIES ${SDL2PP_EXTRA_LIBRARIES} SDL2pp ${SDL2_ALL_LIBRARIES} PARENT_SCOPE)
MESSAGE(STATUS "libSDL2pp ${SDL2PP_VERSION} bundled build")
ENDIF(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
configure_file(cmake/SDL2ppConfig.cmake.in cmake/SDL2ppConfig.cmake @ONLY)
install(EXPORT SDL2pp-targets
FILE SDL2ppTargets.cmake
NAMESPACE SDL2pp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SDL2pp
)
install(FILES ${PROJECT_BINARY_DIR}/cmake/SDL2ppConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SDL2pp)
endif()

View File

@ -1,5 +1,5 @@
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -5,7 +5,7 @@ PROJECT_NAME = "libSDL2pp"
PROJECT_NUMBER = @SDL2PP_VERSION@
# Project description
PROJECT_BRIEF = "C++11 bindings/wrapper for SDL2"
PROJECT_BRIEF = "C++ bindings/wrapper for SDL2"
# Where to place generated files
OUTPUT_DIRECTORY = doxygen
@ -14,27 +14,20 @@ OUTPUT_DIRECTORY = doxygen
QUIET = YES
# Process source and README file
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/SDL2pp \
@CMAKE_CURRENT_SOURCE_DIR@/README.md
INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/SDL2pp" \
"@CMAKE_CURRENT_SOURCE_DIR@/README.md"
# Recurse into subdirectories
RECURSIVE = YES
# Exclude foreign files
EXCLUDE = @CMAKE_CURRENT_SOURCE_DIR@/SDL2pp/external
EXCLUDE = "@CMAKE_CURRENT_SOURCE_DIR@/SDL2pp/external"
# Examples (doesn't work atm)
EXAMPLE_PATH = @CMAKE_CURRENT_SOURCE_DIR@/examples
# Filter through sed to remove badges which Doxygen fails to process properly
INPUT_FILTER = "sed -e '/^\[!\[/d'"
FILTER_PATTERNS = *.md
EXAMPLE_PATH = "@CMAKE_CURRENT_SOURCE_DIR@/examples"
# README file is the main page
USE_MDFILE_AS_MAINPAGE = @CMAKE_CURRENT_SOURCE_DIR@/README.md
# Include timestamp
HTML_TIMESTAMP = YES
USE_MDFILE_AS_MAINPAGE = "@CMAKE_CURRENT_SOURCE_DIR@/README.md"
# We target web, no latex needed
GENERATE_LATEX = NO
@ -42,3 +35,6 @@ GENERATE_LATEX = NO
# Assume source preprocessed with all subsystems enable
# Also enable all conditionals based on SDL version
PREDEFINED = SDL2PP_WITH_IMAGE SDL2PP_WITH_MIXER SDL2PP_WITH_TTF SDL_VERSION_ATLEAST(X,Y,Z)=1
# Disable email obfuscation
OBFUSCATE_EMAILS = False

View File

@ -1,28 +0,0 @@
# - Try to find SDL2pp library
#
# Once done this will define
#
# SDL2PP_FOUND
# SDL2PP_INCLUDE_DIRS
# SDL2PP_LIBRARIES
IF(SDL2PP_INCLUDE_DIR AND SDL2PP_LIBRARY)
# in cache already
SET(SDL2PP_FIND_QUIETLY TRUE)
ENDIF(SDL2PP_INCLUDE_DIR AND SDL2PP_LIBRARY)
FIND_PATH(SDL2PP_INCLUDE_DIR SDL2pp/SDL2pp.hh HINTS "@CMAKE_INSTALL_PREFIX@/include")
FIND_LIBRARY(SDL2PP_LIBRARY NAMES SDL2pp HINTS "@CMAKE_INSTALL_PREFIX@/lib")
MARK_AS_ADVANCED(SDL2PP_INCLUDE_DIR SDL2PP_LIBRARY)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2PP
REQUIRED_VARS SDL2PP_INCLUDE_DIR SDL2PP_LIBRARY
)
IF(SDL2PP_FOUND)
SET(SDL2PP_INCLUDE_DIRS ${SDL2PP_INCLUDE_DIR} @SDL2_ALL_INCLUDE_DIRS_STR@)
SET(SDL2PP_LIBRARIES @SDL2PP_EXTRA_LIBRARIES_STR@ ${SDL2PP_LIBRARY} @SDL2_ALL_LIBRARIES_STR@)
ENDIF(SDL2PP_FOUND)

128
README.md
View File

@ -1,14 +1,15 @@
# libSDL2pp #
<a href="https://repology.org/project/libsdl2pp/versions">
<img src="https://repology.org/badge/vertical-allrepos/libsdl2pp.svg" alt="libsdl2pp packaging status" align="right">
</a>
[![Build Status](https://travis-ci.org/libSDL2pp/libSDL2pp.svg?branch=master)](https://travis-ci.org/libSDL2pp/libSDL2pp)
[![Build status](https://ci.appveyor.com/api/projects/status/qhfpa29qd8bt619t/branch/master?svg=true)](https://ci.appveyor.com/project/AMDmi3/libsdl2pp)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/3980/badge.svg)](https://scan.coverity.com/projects/3980)
[![Coverage Status](https://coveralls.io/repos/github/libSDL2pp/libSDL2pp/badge.svg?branch=master)](https://coveralls.io/github/libSDL2pp/libSDL2pp?branch=master)
[![Packaging status](https://repology.org/badge/tiny-repos/libsdl2pp.svg)](https://repology.org/metapackage/libsdl2pp)
[![CI](https://github.com/libSDL2pp/libSDL2pp/actions/workflows/ci.yml/badge.svg)](https://github.com/libSDL2pp/libSDL2pp/actions/workflows/ci.yml)
[![Github commits (since latest release)](https://img.shields.io/github/commits-since/libSDL2pp/libSDL2pp/latest.svg)](https://github.com/libSDL2pp/libSDL2pp)
This library provides C++11 bindings/wrapper for SDL2 and satellite libraries.
# libSDL2pp
## Synopsis ##
This library provides C++ bindings/wrapper for SDL2 and satellite libraries.
## Synopsis
```cpp
try {
@ -71,11 +72,11 @@ try {
SDL_Delay(2000);
// All SDL objects are released at this point or if an error occurs
} catch (SDL2pp::Exception& e) {
} catch (const SDL2pp::Exception& e) {
// Exception stores SDL_GetError() result and name of function which failed
std::cerr << "Error in: " << e.GetSDLFunction() << std::endl;
std::cerr << " Reason: " << e.GetSDLError() << std::endl;
} catch (std::exception& e) {
} catch (const std::exception& e) {
// This also works (e.g. "SDL_Init failed: No available video device")
std::cerr << e.what() << std::endl;
}
@ -83,7 +84,7 @@ try {
There's also more elaborate [tutorial](https://github.com/libSDL2pp/libSDL2pp-tutorial).
## Features ##
## Features
Currently, the library provides wrapper classes for
@ -125,7 +126,7 @@ methods. These classes support:
need to manually check return code after each function call)
* Method overloading, default arguments, method chaining allow shorter
and cleaner code
* C++11 move semantics support, which allow you to store SDL objects
* Move semantics support, which allow you to store SDL objects
in containers and pass/return them by value without noticeable overhead
Set of functional extensions above SDL2 is also available:
@ -135,10 +136,7 @@ Set of functional extensions above SDL2 is also available:
(for which SDL2 usually uses NULL pointers)
* Number of additional methods and operator support for Point and Rect
## Building ##
To build libSDL2pp, you need a compiler with C++11 support, for
example clang 3.4+ or gcc 4.8+.
## Building
Dependencies:
* [cmake](https://cmake.org/)
@ -149,54 +147,51 @@ Dependencies:
To build standalone version:
cmake . && make
```shell
cmake .
cmake --build .
```
Following variables may be supplied to CMake to affect build:
* ```SDL2PP_WITH_IMAGE``` - enable SDL_image support (default ON)
* ```SDL2PP_WITH_MIXER``` - enable SDL_mixer support (default ON)
* ```SDL2PP_WITH_TTF``` - enable SDL_ttf support (default ON)
* ```SDL2PP_WITH_WERROR``` - treat warnings as errors, useful for CI (default OFF)
* ```SDL2PP_CXXSTD``` - override C++ standard (default C++11). With C++1y some additional features are enabled such as usage of [[deprecated]] attribute and using stock experimental/optional from C++ standard library
* ```SDL2PP_WITH_EXAMPLES``` - enable building example programs (only for standalone build, default ON)
* ```SDL2PP_WITH_TESTS``` - enable building tests (only for standalone build, default ON)
* ```SDL2PP_STATIC``` - build static library instead of shared (only for standalone build, default OFF)
* ```SDL2PP_ENABLE_LIVE_TESTS``` - enable tests which require X11 and/or audio device to run (only for standalone build, default ON)
* `SDL2PP_WITH_IMAGE` - enable SDL_image support (default ON)
* `SDL2PP_WITH_MIXER` - enable SDL_mixer support (default ON)
* `SDL2PP_WITH_TTF` - enable SDL_ttf support (default ON)
* `SDL2PP_WITH_EXAMPLES` - enable building example programs (only for standalone build, default ON)
* `SDL2PP_WITH_TESTS` - enable building tests (only for standalone build, default ON)
* `SDL2PP_STATIC` - build static library instead of shared (only for standalone build, default OFF)
* `SDL2PP_ENABLE_LIVE_TESTS` - enable tests which require X11 and/or audio device to run (only for standalone build, default ON)
## Installation ##
## Installation
To install the library system-wide, run:
cmake . && make && make install
```shell
cmake .
cmake --build .
cmake --install .
```
You can change installation prefix with CMAKE_INSTALL_PREFIX cmake
variable:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local . && make && make install
```shell
cmake -DCMAKE_INSTALL_PREFIX=/usr/local .
cmake --build .
cmake --install .
```
SDL2pp installs pkg-config file, so it can be used with any build
system that interacts with pkg-config, including CMake and GNU
Autotools. It also installs CMake module file, which can be used
SDL2pp installs `pkg-config` file, so it can be used with any build
system that interacts with `pkg-config`, including CMake, meson and
GNU Autotools. It also installs CMake module file, which can be used
from CMake directly:
```cmake
FIND_PACKAGE(SDL2PP REQUIRED)
find_package(SDL2pp REQUIRED)
INCLUDE_DIRECTORIES(${SDL2PP_INCLUDE_DIRS})
...
TARGET_LINK_LIBRARIES(... ${SDL2PP_LIBRARIES})
target_link_libraries(mytarget SDL2pp::SDL2pp)
```
SDL2pp is also already available from the following package
repositories:
<a href="https://repology.org/metapackage/libsdl2pp"><img src="https://repology.org/badge/vertical-allrepos/libsdl2pp.svg" alt="Packaging status" align="right"></a>
* [Arch Linux AUR](https://aur.archlinux.org/packages/sdl2pp-git/)
* [DragonflyBSD DPorts](https://github.com/DragonFlyBSD/DPorts/tree/master/devel/sdl2pp)
* [FreeBSD ports](http://www.freshports.org/devel/sdl2pp/)
* [Yet Another Cygwin Ports](https://github.com/fd00/yacp/tree/master/libSDL2pp)
## Bundling ##
The library is easy to integrate into other CMake projects
@ -207,29 +202,25 @@ Just place the library into dedicated directory in your project
(for example, extlib/libSDL2pp) and add
```cmake
SET(SDL2PP_WITH_IMAGE ON) # if you need SDL_image support
SET(SDL2PP_WITH_MIXER ON) # if you need SDL_mixer support
SET(SDL2PP_WITH_TTF ON) # if you need SDL_ttf support
ADD_SUBDIRECTORY(extlib/libSDL2pp)
set(SDL2PP_WITH_IMAGE ON) # if you need SDL_image support
set(SDL2PP_WITH_MIXER ON) # if you need SDL_mixer support
set(SDL2PP_WITH_TTF ON) # if you need SDL_ttf support
add_subdirectory(extlib/libSDL2pp)
```
into your core CMakeLists.txt. This will act similar to how
FIND_PACKAGE usually does, and will provide ${SDL2PP_INCLUDE_DIRS}
and ${SDL2PP_LIBRARIES} variables for your project. You will then
be able to use them as usual:
`find_package` usually does, and will provide `SDL2pp::SDL2pp`
target for your project. You will then be able it as usual:
```cmake
INCLUDE_DIRECTORIES(${SDL2PP_INCLUDE_DIRS})
ADD_EXECUTABLE(mytarget ...)
TARGET_LINK_LIBRARIES(mytarget ${SDL2PP_LIBRARIES})
target_link_libraries(mytarget SDL2pp::SDL2pp)
```
If bundled, libSDL2pp does not build examples and becomes a static
library, providing required SDL2 includes/libs in the mentioned
variables.
library. See [hoverboard](https://github.com/AMDmi3/hoverboard-sdl/blob/5729f9fb6929f6e8147481f5b21772fc1e35562a/CMakeLists.txt#L34-L40)
project as an example of using both bundled and systemwide SDL2pp.
## Completeness ##
## Completeness
The library still doesn't cover all aspects of SDL2, and the development
is generally guided by the author's needs and interest without a goal
@ -242,10 +233,10 @@ any wrappers over non object-oriented SDL2 code, as these will not bring
any benefits over using plain C API. E.g. I see no point in implementing
SDL2pp::Delay() as it won't bring any convenience over SDL_Delay().
The same strongly applies to the SDL2 bits which duplicate C++11
The same strongly applies to the SDL2 bits which duplicate C++17
standard library, e.g. threads and atomic ops.
## Users ##
## Users
Projects using libSDL2pp:
@ -257,16 +248,16 @@ Projects using libSDL2pp:
* [osmview](https://bitbucket.org/ipopov/osmview) - Desktop OpenStreetMap viewer
* [planetonomy](https://github.com/AMDmi3/planetonomy) - Old-school platformer/exploration game with CGA graphics
## WWW ##
## WWW
* [GitHub page](https://github.com/libSDL2pp/libSDL2pp)
* [Online documentation](http://sdl2pp.amdmi3.ru/)
* [GitHub repository](https://github.com/libSDL2pp/libSDL2pp)
* [Doxygen documentation](https://libsdl2pp.github.io/)
## Author ##
## Author
* [Dmitry Marakasov](https://github.com/AMDmi3) <amdmi3@amdmi3.ru>
## Contributors ##
## Contributors
* [Aargonian](https://github.com/Aargonian)
* [Carl Schwope](https://github.com/Lowest0ne)
@ -275,7 +266,8 @@ Projects using libSDL2pp:
* [kumar8600](https://github.com/kumar8600)
* [ooxi](https://github.com/ooxi)
* [Vladimir Gamalian](https://github.com/vladimirgamalian)
* [Vraiment](https://github.com/Vraiment)
## License ##
## License
libSDL2pp comes under zlib license, the same license as SDL2. See COPYING.txt.

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

27
SDL2pp/Color.cc Normal file
View File

@ -0,0 +1,27 @@
/*
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2017 Vraiment <jemc44@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <SDL2pp/Color.hh>
std::ostream& operator<<(std::ostream& stream, const SDL2pp::Color& color) {
stream << "[r:" << static_cast<int>(color.r) << ",g:" << static_cast<int>(color.g) << ",b:" << static_cast<int>(color.b) << ",a:" << static_cast<int>(color.a) << "]";
return stream;
}

278
SDL2pp/Color.hh Normal file
View File

@ -0,0 +1,278 @@
/*
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2017 Vraiment <jemc44@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL2PP_COLOR_HH
#define SDL2PP_COLOR_HH
#include <ostream>
#include <SDL_pixels.h>
#include <SDL2pp/Export.hh>
namespace SDL2pp {
////////////////////////////////////////////////////////////
/// \brief RGB color with Alpha
///
/// \ingroup graphics
///
/// \headerfile SDL2pp/Color.hh
///
/// This class is public-derived from SDL_Color structure,
/// may generally used as it if passed via pointer or
/// reference. It also supports direct access to r, g, b
/// and a members.
///
/// \see http://wiki.libsdl.org/SDL_Color
///
////////////////////////////////////////////////////////////
class SDL2PP_EXPORT Color : public SDL_Color {
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Creates a Color(0, 0, 0, 0)
///
////////////////////////////////////////////////////////////
constexpr Color() : SDL_Color{0, 0, 0, 0} {
}
////////////////////////////////////////////////////////////
/// \brief Construct a color from existing SDL_Color
///
/// \param[in] color Existing SDL_Color
///
////////////////////////////////////////////////////////////
constexpr Color(const SDL_Color& color) : SDL_Color{color.r, color.g, color.b, color.a} {
}
////////////////////////////////////////////////////////////
/// \brief Construct the color from given RGB, alpha is opaque
///
/// \param[in] r Red component in the range 0-255
/// \param[in] g Green component in the range 0-255
/// \param[in] b Blue component in the range 0-255
///
////////////////////////////////////////////////////////////
constexpr Color(Uint8 r, Uint8 g, Uint8 b) : SDL_Color{r, g, b, SDL_ALPHA_OPAQUE} {
}
////////////////////////////////////////////////////////////
/// \brief Construct the color from given RGB and alpha values
///
/// \param[in] r Red component in the range 0-255
/// \param[in] g Green component in the range 0-255
/// \param[in] b Blue component in the range 0-255
/// \param[in] a Alpha component in the range 0-255
///
////////////////////////////////////////////////////////////
constexpr Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a) : SDL_Color{r, g, b, a} {
}
////////////////////////////////////////////////////////////
/// \brief Copy constructor
///
////////////////////////////////////////////////////////////
Color(const Color&) noexcept = default;
////////////////////////////////////////////////////////////
/// \brief Move constructor
///
////////////////////////////////////////////////////////////
Color(Color&&) noexcept = default;
////////////////////////////////////////////////////////////
/// \brief Assignment operator
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
Color& operator=(const Color&) noexcept = default;
////////////////////////////////////////////////////////////
/// \brief Move assignment operator
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
Color& operator=(Color&&) noexcept = default;
////////////////////////////////////////////////////////////
/// \brief Get the red component from the color
///
/// \returns The red component from the color
///
////////////////////////////////////////////////////////////
constexpr Uint8 GetRed() const {
return r;
}
////////////////////////////////////////////////////////////
/// \brief Set the red component from the color
///
/// \param[in] nr New red component value
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
Color& SetRed(int nr) {
r = nr;
return *this;
}
////////////////////////////////////////////////////////////
/// \brief Get the green component from the color
///
/// \returns The green component from the color
///
////////////////////////////////////////////////////////////
constexpr Uint8 GetGreen() const {
return g;
}
////////////////////////////////////////////////////////////
/// \brief Set the green component from the color
///
/// \param[in] ng New green component value
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
Color& SetGreen(int ng) {
g = ng;
return *this;
}
////////////////////////////////////////////////////////////
/// \brief Get the blue component from the color
///
/// \returns The blue component from the color
///
////////////////////////////////////////////////////////////
constexpr Uint8 GetBlue() const {
return b;
}
////////////////////////////////////////////////////////////
/// \brief Set the blue component from the color
///
/// \param[in] nb New blue component value
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
Color& SetBlue(int nb) {
b = nb;
return *this;
}
////////////////////////////////////////////////////////////
/// \brief Get the alpha component from the color
///
/// \returns The alpha component from the color
///
////////////////////////////////////////////////////////////
constexpr Uint8 GetAlpha() const {
return a;
}
////////////////////////////////////////////////////////////
/// \brief Set the alpha component from the color
///
/// \param[in] na New alpha component value
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
Color& SetAlpha(int na) {
a = na;
return *this;
}
};
}
////////////////////////////////////////////////////////////
/// \brief Equality operator for SDL2pp::Color
///
/// \param[in] a First argument for comparison
/// \param[in] b Second argument for comparison
///
/// \returns True if two rectangles are identical
///
////////////////////////////////////////////////////////////
constexpr bool operator==(const SDL2pp::Color& a, const SDL2pp::Color& b) {
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
}
////////////////////////////////////////////////////////////
/// \brief Inequality operator for SDL2pp::Color
///
/// \param[in] a First argument for comparison
/// \param[in] b Second argument for comparison
///
/// \returns True if two rectangles are not identical
///
////////////////////////////////////////////////////////////
constexpr bool operator!=(const SDL2pp::Color& a, const SDL2pp::Color& b) {
return !(a == b);
}
////////////////////////////////////////////////////////////
/// \brief Stream output operator overload for SDL2pp::Color
///
/// \param[in] stream Stream to output to
/// \param[in] color Color to output
///
/// \returns stream
///
////////////////////////////////////////////////////////////
SDL2PP_EXPORT std::ostream& operator<<(std::ostream& stream, const SDL2pp::Color& color);
namespace std {
////////////////////////////////////////////////////////////
/// \brief std::hash specialization for SDL2pp::Color
///
////////////////////////////////////////////////////////////
template<>
struct hash<SDL2pp::Color> {
////////////////////////////////////////////////////////////
/// \brief Hash function for SDL2pp::Color
///
/// \param[in] c Input Color
///
/// \returns Hash value
///
////////////////////////////////////////////////////////////
size_t operator()(const SDL2pp::Color& c) const {
size_t seed = std::hash<int>()(c.r);
seed ^= std::hash<int>()(c.g) + 0x9e3779b9 + (seed<<6) + (seed>>2);
seed ^= std::hash<int>()(c.b) + 0x9e3779b9 + (seed<<6) + (seed>>2);
seed ^= std::hash<int>()(c.a) + 0x9e3779b9 + (seed<<6) + (seed>>2);
return seed;
}
};
}
#endif

View File

@ -1,6 +1,6 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
Copyright (C) 2014-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2016,2022 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -22,15 +22,14 @@
#ifndef SDL2PP_CONFIG_HH
#define SDL2PP_CONFIG_HH
#define SDL2PP_MAJOR_VERSION @SDL2PP_MAJOR_VERSION@
#define SDL2PP_MINOR_VERSION @SDL2PP_MINOR_VERSION@
#define SDL2PP_PATCH_VERSION @SDL2PP_PATCH_VERSION@
#define SDL2PP_MAJOR_VERSION @libSDL2pp_VERSION_MAJOR@
#define SDL2PP_MINOR_VERSION @libSDL2pp_VERSION_MINOR@
#define SDL2PP_PATCH_VERSION @libSDL2pp_VERSION_PATCH@
#define SDL2PP_VERSION "@SDL2PP_VERSION@"
#define SDL2PP_VERSION "@libSDL2pp_VERSION@"
#cmakedefine SDL2PP_WITH_IMAGE
#cmakedefine SDL2PP_WITH_TTF
#cmakedefine SDL2PP_WITH_MIXER
#cmakedefine SDL2PP_WITH_EXPERIMENTAL_OPTIONAL
#endif

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -95,7 +95,7 @@ Font& Font::SetHinting(int hinting) {
}
bool Font::GetKerning() const {
return TTF_GetFontKerning(font_);
return TTF_GetFontKerning(font_) > 0;
}
Font& Font::SetKerning(bool allowed) {
@ -124,7 +124,7 @@ long Font::GetNumFaces() const {
}
bool Font::IsFixedWidth() const {
return TTF_FontFaceIsFixedWidth(font_);
return TTF_FontFaceIsFixedWidth(font_) > 0;
}
Optional<std::string> Font::GetFamilyName() const {

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2015-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -213,15 +213,15 @@ void Mixer::HaltMusic() {
}
bool Mixer::FadeOutMusic(int ms) {
return Mix_FadeOutMusic(ms);
return Mix_FadeOutMusic(ms) > 0;
}
bool Mixer::IsMusicPlaying() const {
return Mix_PlayingMusic();
return Mix_PlayingMusic() > 0;
}
bool Mixer::IsMusicPaused() const {
return Mix_PausedMusic();
return Mix_PausedMusic() > 0;
}
Mix_Fading Mixer::GetMusicFading() const {

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2015-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -43,8 +43,8 @@ class Music;
/// \headerfile SDL2pp/Mixer.hh
///
/// This class represents open SDL_mixer audio device. Object
/// of this class must be constructed before creating any
/// SDL2pp:Chunk's.
/// of this class must be constructed before calling any other
/// mixer functions.
///
////////////////////////////////////////////////////////////
class SDL2PP_EXPORT Mixer {

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2015-2017 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2015-2017 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -66,36 +66,17 @@
///
////////////////////////////////////////////////////////////
#if defined(SDL2PP_WITH_EXPERIMENTAL_OPTIONAL)
# include <experimental/optional>
#include <optional>
namespace SDL2pp {
template<typename T>
using Optional = std::experimental::optional<T>;
using Optional = std::optional<T>;
using BadOptionalAccess = std::experimental::bad_optional_access;
using BadOptionalAccess = std::bad_optional_access;
constexpr std::experimental::nullopt_t NullOpt = std::experimental::nullopt;
}
#else
# include <SDL2pp/external/libcpp_optional.hh>
namespace SDL2pp {
template<typename T>
using Optional = sdl2pp_libcpp_optional::optional<T>;
using BadOptionalAccess = sdl2pp_libcpp_optional::bad_optional_access;
constexpr sdl2pp_libcpp_optional::nullopt_t NullOpt = sdl2pp_libcpp_optional::nullopt;
constexpr std::nullopt_t NullOpt = std::nullopt;
}
#endif
#endif

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -133,7 +133,7 @@ public:
/// works with it), Mem and ConstMem (take memory chunk and work with
/// it like a file) and allow one to write custom RWops.
///
/// SDL2pp::RWops support all this in extended C++11 way.
/// SDL2pp::RWops support all this in extended C++ way.
///
/// Usage example:
/// \code

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -197,6 +197,10 @@ Renderer& Renderer::SetDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
return *this;
}
Renderer& Renderer::SetDrawColor(const Color& color) {
return SetDrawColor(color.r, color.g, color.b, color.a);
}
Renderer& Renderer::SetTarget() {
if (SDL_SetRenderTarget(renderer_, nullptr) != 0)
throw Exception("SDL_SetRenderTarget");
@ -411,6 +415,12 @@ SDL_BlendMode Renderer::GetDrawBlendMode() const {
return mode;
}
Color Renderer::GetDrawColor() const {
Color color;
GetDrawColor(color.r, color.g, color.b, color.a);
return color;
}
void Renderer::GetDrawColor(Uint8& r, Uint8& g, Uint8& b, Uint8& a) const {
if (SDL_GetRenderDrawColor(renderer_, &r, &g, &b, &a) != 0)
throw Exception("SDL_GetRenderDrawColor");

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -30,6 +30,7 @@
#include <SDL2pp/Point.hh>
#include <SDL2pp/Rect.hh>
#include <SDL2pp/Export.hh>
#include <SDL2pp/Color.hh>
struct SDL_RendererInfo;
struct SDL_Renderer;
@ -301,6 +302,20 @@ public:
////////////////////////////////////////////////////////////
Renderer& SetDrawColor(Uint8 r = 0, Uint8 g = 0, Uint8 b = 0, Uint8 a = 255);
////////////////////////////////////////////////////////////
/// \brief Set color user for drawing operations
///
/// \param[in] color Color to draw on the rendering target
///
/// \returns Reference to self
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_SetRenderDrawColor
///
////////////////////////////////////////////////////////////
Renderer& SetDrawColor(const Color& color);
////////////////////////////////////////////////////////////
/// \brief Set current render target to default
///
@ -752,6 +767,18 @@ public:
////////////////////////////////////////////////////////////
SDL_BlendMode GetDrawBlendMode() const;
////////////////////////////////////////////////////////////
/// \brief Get the additional color value multiplied into render copy operations
///
/// \return Color object with the value used to do render copy operations
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_GetRenderDrawColor
///
////////////////////////////////////////////////////////////
Color GetDrawColor() const;
////////////////////////////////////////////////////////////
/// \brief Get the additional color value multiplied into render copy operations
///

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -71,7 +71,9 @@
///
////////////////////////////////////////////////////////////
#include <SDL2pp/Renderer.hh>
#include <SDL2pp/Surface.hh>
#include <SDL2pp/Texture.hh>
#include <SDL2pp/Color.hh>
////////////////////////////////////////////////////////////
/// \defgroup geometry 2D geometry
@ -95,34 +97,34 @@
#include <SDL2pp/ContainerRWops.hh>
#include <SDL2pp/StreamRWops.hh>
#ifdef SDL2PP_WITH_TTF
////////////////////////////////////////////////////////////
/// \defgroup ttf SDL_ttf
///
/// \brief Text rendering through SDL_ttf library
///
////////////////////////////////////////////////////////////
#ifdef SDL2PP_WITH_TTF
# include <SDL2pp/SDLTTF.hh>
# include <SDL2pp/Font.hh>
#endif
#ifdef SDL2PP_WITH_IMAGE
////////////////////////////////////////////////////////////
/// \defgroup image SDL_image
///
/// \brief Functions that are specific to SDL_image library
///
////////////////////////////////////////////////////////////
#ifdef SDL2PP_WITH_IMAGE
# include <SDL2pp/SDLImage.hh>
#endif
#ifdef SDL2PP_WITH_MIXER
////////////////////////////////////////////////////////////
/// \defgroup mixer SDL_mixer
///
/// \brief Functions that are specific to SDL_mixer library
///
////////////////////////////////////////////////////////////
#ifdef SDL2PP_WITH_MIXER
# include <SDL2pp/Chunk.hh>
# include <SDL2pp/Mixer.hh>
# include <SDL2pp/Music.hh>

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -145,6 +145,13 @@ SDL_BlendMode Surface::GetBlendMode() const {
return blendMode;
}
Color Surface::GetColorAndAlphaMod() const {
Color color;
GetColorMod(color.r, color.g, color.b);
color.a = GetAlphaMod();
return color;
}
void Surface::GetColorMod(Uint8& r, Uint8& g, Uint8& b) const {
if (SDL_GetSurfaceColorMod(surface_, &r, &g, &b) != 0)
throw Exception("SDL_GetSurfaceColorMod");
@ -180,6 +187,10 @@ Surface& Surface::SetColorMod(Uint8 r, Uint8 g, Uint8 b) {
return *this;
}
Surface& Surface::SetColorAndAlphaMod(const Color& color) {
return SetColorMod(color.r, color.g, color.b).SetAlphaMod(color.a);
}
Surface& Surface::SetRLE(bool flag) {
if (SDL_SetSurfaceRLE(surface_, flag ? 1 : 0) != 0)
throw Exception("SDL_SetSurfaceRLE");

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -30,6 +30,7 @@
#include <SDL2pp/Rect.hh>
#include <SDL2pp/Point.hh>
#include <SDL2pp/Export.hh>
#include <SDL2pp/Color.hh>
struct SDL_Surface;
struct SDL_PixelFormat;
@ -216,6 +217,8 @@ public:
///
/// \param[in] rwops RWops used to access an image file
///
/// \throws SDL2pp::Exception
///
////////////////////////////////////////////////////////////
explicit Surface(RWops& rwops);
@ -224,6 +227,8 @@ public:
///
/// \param[in] filename Path to an image file
///
/// \throws SDL2pp::Exception
///
////////////////////////////////////////////////////////////
explicit Surface(const std::string& filename);
#endif
@ -390,6 +395,19 @@ public:
////////////////////////////////////////////////////////////
SDL_BlendMode GetBlendMode() const;
////////////////////////////////////////////////////////////
/// \brief Get the additional color value multiplied into blit operations
///
/// \return Color object with the values used to do blit operations
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_GetSurfaceAlphaMod
/// \see http://wiki.libsdl.org/SDL_GetSurfaceColorMod
///
////////////////////////////////////////////////////////////
Color GetColorAndAlphaMod() const;
////////////////////////////////////////////////////////////
/// \brief Get the additional color value multiplied into blit operations
///
@ -477,6 +495,21 @@ public:
////////////////////////////////////////////////////////////
Surface& SetColorMod(Uint8 r = 255, Uint8 g = 255, Uint8 b = 255);
////////////////////////////////////////////////////////////
/// \brief Set an additional color value multiplied into blit operations
///
/// \param[in] color Color to be multiplied into blit operations
///
/// \returns Reference to self
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_SetSurfaceAlphaMod
/// \see http://wiki.libsdl.org/SDL_SetSurfaceColorMod
///
////////////////////////////////////////////////////////////
Surface& SetColorAndAlphaMod(const Color& color);
////////////////////////////////////////////////////////////
/// \brief Set the RLE acceleration hint for a surface
///

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -157,6 +157,10 @@ Texture& Texture::SetColorMod(Uint8 r, Uint8 g, Uint8 b) {
return *this;
}
Texture& Texture::SetColorAndAlphaMod(const Color& color) {
return SetColorMod(color.r, color.g, color.b).SetAlphaMod(color.a);
}
Texture::LockHandle Texture::Lock(const Optional<Rect>& rect) {
return LockHandle(this, rect);
}
@ -215,4 +219,11 @@ void Texture::GetColorMod(Uint8& r, Uint8& g, Uint8& b) const {
throw Exception("SDL_GetTextureColorMod");
}
Color Texture::GetColorAndAlphaMod() const {
Color color;
GetColorMod(color.r, color.g, color.b);
color.a = GetAlphaMod();
return color;
}
}

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -31,6 +31,7 @@
#include <SDL2pp/Rect.hh>
#include <SDL2pp/Config.hh>
#include <SDL2pp/Export.hh>
#include <SDL2pp/Color.hh>
struct SDL_Texture;
@ -421,6 +422,21 @@ public:
////////////////////////////////////////////////////////////
Texture& SetColorMod(Uint8 r = 255, Uint8 g = 255, Uint8 b = 255);
////////////////////////////////////////////////////////////
/// \brief Set an additional color value multiplied into render copy operations
///
/// \param[in] color Color to be used when multiplied into render copy operations
///
/// \returns Reference to self
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_SetTextureAlphaMod
/// \see http://wiki.libsdl.org/SDL_SetTextureColorMod
///
////////////////////////////////////////////////////////////
Texture& SetColorAndAlphaMod(const Color& color = Color{255, 255, 255, SDL_ALPHA_OPAQUE});
////////////////////////////////////////////////////////////
/// \brief Lock texture for write-only pixel access
///
@ -536,6 +552,19 @@ public:
///
////////////////////////////////////////////////////////////
void GetColorMod(Uint8& r, Uint8& g, Uint8 &b) const;
////////////////////////////////////////////////////////////
/// \brief Get the additional color value multiplied into render copy operations
///
/// \return Color object with the values used to do render copy operations
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_GetTextureAlphaMod
/// \see http://wiki.libsdl.org/SDL_GetTextureColorMod
///
////////////////////////////////////////////////////////////
Color GetColorAndAlphaMod() const;
};
}

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,6 +1,6 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2017 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -259,6 +259,11 @@ float Window::GetOpacity() const {
return opacity;
}
Window& Window::SetResizable(bool resizable) {
SDL_SetWindowResizable(window_, resizable ? SDL_TRUE : SDL_FALSE);
return *this;
}
#endif
}

View File

@ -1,6 +1,6 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2017 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -483,6 +483,8 @@ public:
///
/// \returns Index of the display containing the center of the window
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_GetWindowDisplayIndex
///
////////////////////////////////////////////////////////////
@ -495,6 +497,8 @@ public:
/// \param[out] mode SDL_DisplayMode structure filled in with the
/// fullscreen display mode
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_GetWindowDisplayMode
///
////////////////////////////////////////////////////////////
@ -544,6 +548,8 @@ public:
///
/// \returns Reference to self
///
/// \throws SDL2pp::Exception
///
/// \see http://wiki.libsdl.org/SDL_SetWindowOpacity
///
////////////////////////////////////////////////////////////
@ -554,10 +560,24 @@ public:
///
/// \returns Opacity value (0.0f - transparent, 1.0f - opaque)
///
/// \throws SDL2pp:Exception
///
/// \see http://wiki.libsdl.org/SDL_GetWindowOpacity
///
////////////////////////////////////////////////////////////
float GetOpacity() const;
////////////////////////////////////////////////////////////
/// \brief Set user-resizable state of a window
///
/// \param[in] resizable True to allow resizing, false to disallow
///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_SetWindowResizable
///
////////////////////////////////////////////////////////////
Window& SetResizable(bool resizable = true);
#endif
};

View File

@ -1,518 +0,0 @@
// -*- C++ -*-
//===-------------------------- optional ----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef SDL2PP_LIBCPP_OPTIONAL
#define SDL2PP_LIBCPP_OPTIONAL
#include <cassert>
#include <functional>
#include <initializer_list>
#include <new>
#include <stdexcept>
#include <type_traits>
namespace sdl2pp_libcpp_optional {
class bad_optional_access
: public std::logic_error
{
public:
explicit bad_optional_access(const std::string& __arg)
: std::logic_error(__arg) {}
explicit bad_optional_access(const char* __arg)
: std::logic_error(__arg) {}
// Remove explicitly defaulted copy constructor and assignment operator:
// noexcept specification doesn't work well with libstdc++
//bad_optional_access(const bad_optional_access&) noexcept = default;
//bad_optional_access& operator=(const bad_optional_access&) noexcept = default;
// Get the key function ~bad_optional_access() into the dylib even if not compiling for C++1y
virtual ~bad_optional_access() noexcept {}
};
struct in_place_t {};
constexpr in_place_t in_place{};
struct nullopt_t
{
explicit constexpr nullopt_t(int) noexcept {}
};
constexpr nullopt_t nullopt{0};
template <class _Tp, bool = std::is_trivially_destructible<_Tp>::value>
class __optional_storage
{
protected:
typedef _Tp value_type;
union
{
char __null_state_;
value_type __val_;
};
bool __engaged_ = false;
~__optional_storage()
{
if (__engaged_)
__val_.~value_type();
}
constexpr __optional_storage() noexcept
: __null_state_('\0') {}
__optional_storage(const __optional_storage& __x)
: __engaged_(__x.__engaged_)
{
if (__engaged_)
::new(std::addressof(__val_)) value_type(__x.__val_);
}
__optional_storage(__optional_storage&& __x)
noexcept(std::is_nothrow_move_constructible<value_type>::value)
: __engaged_(__x.__engaged_)
{
if (__engaged_)
::new(std::addressof(__val_)) value_type(std::move(__x.__val_));
}
constexpr __optional_storage(const value_type& __v)
: __val_(__v),
__engaged_(true) {}
constexpr __optional_storage(value_type&& __v)
: __val_(std::move(__v)),
__engaged_(true) {}
template <class... _Args>
constexpr
explicit __optional_storage(in_place_t, _Args&&... __args)
: __val_(std::forward<_Args>(__args)...),
__engaged_(true) {}
};
template <class _Tp>
class __optional_storage<_Tp, true>
{
protected:
typedef _Tp value_type;
union
{
char __null_state_;
value_type __val_;
};
bool __engaged_ = false;
constexpr __optional_storage() noexcept
: __null_state_('\0') {}
__optional_storage(const __optional_storage& __x)
: __engaged_(__x.__engaged_)
{
if (__engaged_)
::new(std::addressof(__val_)) value_type(__x.__val_);
}
__optional_storage(__optional_storage&& __x)
noexcept(std::is_nothrow_move_constructible<value_type>::value)
: __engaged_(__x.__engaged_)
{
if (__engaged_)
::new(std::addressof(__val_)) value_type(std::move(__x.__val_));
}
constexpr __optional_storage(const value_type& __v)
: __val_(__v),
__engaged_(true) {}
constexpr __optional_storage(value_type&& __v)
: __val_(std::move(__v)),
__engaged_(true) {}
template <class... _Args>
constexpr
explicit __optional_storage(in_place_t, _Args&&... __args)
: __val_(std::forward<_Args>(__args)...),
__engaged_(true) {}
};
template <class _Tp>
class optional
: private __optional_storage<_Tp>
{
typedef __optional_storage<_Tp> __base;
public:
typedef _Tp value_type;
static_assert(!std::is_reference<value_type>::value,
"Instantiation of optional with a reference type is ill-formed.");
static_assert(!std::is_same<typename std::remove_cv<value_type>::type, in_place_t>::value,
"Instantiation of optional with a in_place_t type is ill-formed.");
static_assert(!std::is_same<typename std::remove_cv<value_type>::type, nullopt_t>::value,
"Instantiation of optional with a nullopt_t type is ill-formed.");
static_assert(std::is_object<value_type>::value,
"Instantiation of optional with a non-object type is undefined behavior.");
static_assert(std::is_nothrow_destructible<value_type>::value,
"Instantiation of optional with an object type that is not noexcept destructible is undefined behavior.");
constexpr optional() noexcept {}
optional(const optional&) = default;
optional(optional&&) = default;
~optional() = default;
constexpr optional(nullopt_t) noexcept {}
constexpr optional(const value_type& __v)
: __base(__v) {}
constexpr optional(value_type&& __v)
: __base(std::move(__v)) {}
template <class... _Args,
class = typename std::enable_if
<
std::is_constructible<value_type, _Args...>::value
>::type
>
constexpr
explicit optional(in_place_t, _Args&&... __args)
: __base(in_place, std::forward<_Args>(__args)...) {}
template <class _Up, class... _Args,
class = typename std::enable_if
<
std::is_constructible<value_type, std::initializer_list<_Up>&, _Args...>::value
>::type
>
constexpr
explicit optional(in_place_t, std::initializer_list<_Up> __il, _Args&&... __args)
: __base(in_place, __il, std::forward<_Args>(__args)...) {}
optional& operator=(nullopt_t) noexcept
{
if (this->__engaged_)
{
this->__val_.~value_type();
this->__engaged_ = false;
}
return *this;
}
optional&
operator=(const optional& __opt)
{
if (this->__engaged_ == __opt.__engaged_)
{
if (this->__engaged_)
this->__val_ = __opt.__val_;
}
else
{
if (this->__engaged_)
this->__val_.~value_type();
else
::new(std::addressof(this->__val_)) value_type(__opt.__val_);
this->__engaged_ = __opt.__engaged_;
}
return *this;
}
optional&
operator=(optional&& __opt)
noexcept(std::is_nothrow_move_assignable<value_type>::value &&
std::is_nothrow_move_constructible<value_type>::value)
{
if (this->__engaged_ == __opt.__engaged_)
{
if (this->__engaged_)
this->__val_ = std::move(__opt.__val_);
}
else
{
if (this->__engaged_)
this->__val_.~value_type();
else
::new(std::addressof(this->__val_)) value_type(std::move(__opt.__val_));
this->__engaged_ = __opt.__engaged_;
}
return *this;
}
template <class _Up,
class = typename std::enable_if
<
std::is_same<typename std::remove_reference<_Up>::type, value_type>::value &&
std::is_constructible<value_type, _Up>::value &&
std::is_assignable<value_type&, _Up>::value
>::type
>
optional&
operator=(_Up&& __v)
{
if (this->__engaged_)
this->__val_ = std::forward<_Up>(__v);
else
{
::new(std::addressof(this->__val_)) value_type(std::forward<_Up>(__v));
this->__engaged_ = true;
}
return *this;
}
template <class... _Args,
class = typename std::enable_if
<
std::is_constructible<value_type, _Args...>::value
>::type
>
void
emplace(_Args&&... __args)
{
*this = nullopt;
::new(std::addressof(this->__val_)) value_type(std::forward<_Args>(__args)...);
this->__engaged_ = true;
}
template <class _Up, class... _Args,
class = typename std::enable_if
<
std::is_constructible<value_type, std::initializer_list<_Up>&, _Args...>::value
>::type
>
void
emplace(std::initializer_list<_Up> __il, _Args&&... __args)
{
*this = nullopt;
::new(std::addressof(this->__val_)) value_type(__il, std::forward<_Args>(__args)...);
this->__engaged_ = true;
}
void
swap(optional& __opt)
noexcept(std::is_nothrow_move_constructible<value_type>::value &&
noexcept(std::swap(std::declval<_Tp&>(), std::declval<_Tp&>())))
{
using std::swap;
if (this->__engaged_ == __opt.__engaged_)
{
if (this->__engaged_)
swap(this->__val_, __opt.__val_);
}
else
{
if (this->__engaged_)
{
::new(std::addressof(__opt.__val_)) value_type(std::move(this->__val_));
this->__val_.~value_type();
}
else
{
::new(std::addressof(this->__val_)) value_type(std::move(__opt.__val_));
__opt.__val_.~value_type();
}
swap(this->__engaged_, __opt.__engaged_);
}
}
value_type const*
operator->() const
{
assert(this->__engaged_); // "optional operator-> called for disengaged value");
return std::addressof(this->__val_);
}
value_type*
operator->()
{
assert(this->__engaged_); // "optional operator-> called for disengaged value");
return std::addressof(this->__val_);
}
const value_type&
operator*() const
{
assert(this->__engaged_); // "optional operator* called for disengaged value");
return this->__val_;
}
value_type&
operator*()
{
assert(this->__engaged_); // "optional operator* called for disengaged value");
return this->__val_;
}
constexpr explicit operator bool() const noexcept {return this->__engaged_;}
value_type const& value() const
{
if (!this->__engaged_)
throw bad_optional_access("optional<T>::value: not engaged");
return this->__val_;
}
value_type& value()
{
if (!this->__engaged_)
throw bad_optional_access("optional<T>::value: not engaged");
return this->__val_;
}
template <class _Up>
constexpr value_type value_or(_Up&& __v) const&
{
static_assert(std::is_copy_constructible<value_type>::value,
"optional<T>::value_or: T must be copy constructible");
static_assert(std::is_convertible<_Up, value_type>::value,
"optional<T>::value_or: U must be convertible to T");
return this->__engaged_ ? this->__val_ :
static_cast<value_type>(std::forward<_Up>(__v));
}
template <class _Up>
value_type value_or(_Up&& __v) &&
{
static_assert(std::is_move_constructible<value_type>::value,
"optional<T>::value_or: T must be move constructible");
static_assert(std::is_convertible<_Up, value_type>::value,
"optional<T>::value_or: U must be convertible to T");
return this->__engaged_ ? std::move(this->__val_) :
static_cast<value_type>(std::forward<_Up>(__v));
}
};
template <class _Tp>
inline
bool
operator==(const optional<_Tp>& __x, const optional<_Tp>& __y)
{
if (static_cast<bool>(__x) != static_cast<bool>(__y))
return false;
if (!static_cast<bool>(__x))
return true;
return *__x == *__y;
}
template <class _Tp>
inline
bool
operator<(const optional<_Tp>& __x, const optional<_Tp>& __y)
{
if (!static_cast<bool>(__y))
return false;
if (!static_cast<bool>(__x))
return true;
return std::less<_Tp>{}(*__x, *__y);
}
template <class _Tp>
inline
constexpr
bool
operator==(const optional<_Tp>& __x, nullopt_t) noexcept
{
return !static_cast<bool>(__x);
}
template <class _Tp>
inline
constexpr
bool
operator==(nullopt_t, const optional<_Tp>& __x) noexcept
{
return !static_cast<bool>(__x);
}
template <class _Tp>
inline
constexpr
bool
operator<(const optional<_Tp>&, nullopt_t) noexcept
{
return false;
}
template <class _Tp>
inline
constexpr
bool
operator<(nullopt_t, const optional<_Tp>& __x) noexcept
{
return static_cast<bool>(__x);
}
template <class _Tp>
inline
constexpr
bool
operator==(const optional<_Tp>& __x, const _Tp& __v)
{
return static_cast<bool>(__x) ? *__x == __v : false;
}
template <class _Tp>
inline
constexpr
bool
operator==(const _Tp& __v, const optional<_Tp>& __x)
{
return static_cast<bool>(__x) ? *__x == __v : false;
}
template <class _Tp>
inline
constexpr
bool
operator<(const optional<_Tp>& __x, const _Tp& __v)
{
return static_cast<bool>(__x) ? std::less<_Tp>{}(*__x, __v) : true;
}
template <class _Tp>
inline
constexpr
bool
operator<(const _Tp& __v, const optional<_Tp>& __x)
{
return static_cast<bool>(__x) ? std::less<_Tp>{}(__v, *__x) : false;
}
template <class _Tp>
inline
void
swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y)))
{
__x.swap(__y);
}
template <class _Tp>
inline
constexpr
optional<typename std::decay<_Tp>::type>
make_optional(_Tp&& __v)
{
return optional<typename std::decay<_Tp>::type>(std::forward<_Tp>(__v));
}
} // namespace sdl2pp_libcpp_optional
namespace std {
template <class _Tp>
struct hash<sdl2pp_libcpp_optional::optional<_Tp> >
{
typedef sdl2pp_libcpp_optional::optional<_Tp> argument_type;
typedef size_t result_type;
result_type operator()(const argument_type& __opt) const noexcept
{
return static_cast<bool>(__opt) ? std::hash<_Tp>()(*__opt) : 0;
}
};
}
#endif // SDL2PP_LIBCPP_OPTIONAL

View File

@ -1,15 +0,0 @@
INCLUDE(CheckCXXCompilerFlag)
MACRO(APPEND_CXX_FLAG_IF_SUPPORTED FLAG VARIABLE)
UNSET(HAS_FLAG CACHE)
SET(SAVED_CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET})
SET(CMAKE_REQUIRED_QUIET YES)
CHECK_CXX_COMPILER_FLAG(${FLAG} HAS_FLAG)
SET(CMAKE_REQUIRED_QUIET ${SAVED_CMAKE_REQUIRED_QUIET})
IF(HAS_FLAG)
SET(${VARIABLE} "${${VARIABLE}} ${FLAG}")
MESSAGE(STATUS "Checking for ${FLAG}: yes")
ELSE(HAS_FLAG)
MESSAGE(STATUS "Checking for ${FLAG}: no")
ENDIF(HAS_FLAG)
ENDMACRO(APPEND_CXX_FLAG_IF_SUPPORTED)

View File

@ -1,16 +0,0 @@
INCLUDE(CheckCXXSourceCompiles)
MACRO(CHECK_COMPILE RESULT_VAR CODE DESCRIPTION)
SET(SAVED_CMAKE_REQUIRED_QUIET "${CMAKE_REQUIRED_QUIET}")
SET(SAVED_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
SET(CMAKE_REQUIRED_QUIET YES)
SET(CMAKE_REQUIRED_FLAGS "${SDL2PP_WERROR_FLAG}")
CHECK_CXX_SOURCE_COMPILES("${CODE}" ${RESULT_VAR})
SET(CMAKE_REQUIRED_QUIET "${SAVED_CMAKE_REQUIRED_QUIET}")
SET(CMAKE_REQUIRED_FLAGS "${SAVED_CMAKE_REQUIRED_FLAGS}")
IF(${RESULT_VAR})
MESSAGE(STATUS "Checking for ${DESCRIPTION}: yes")
ELSE(${RESULT_VAR})
MESSAGE(STATUS "Checking for ${DESCRIPTION}: no")
ENDIF(${RESULT_VAR})
ENDMACRO(CHECK_COMPILE)

View File

@ -1,18 +0,0 @@
# - Try to locate SDL2
# This module defines:
#
# SDL2_INCLUDE_DIR
# SDL2_LIBRARY
# SDL2_FOUND
#
FIND_PATH(SDL2_INCLUDE_DIR NAMES SDL.h PATH_SUFFIXES SDL2)
FIND_LIBRARY(SDL2_LIBRARY NAMES SDL2)
FIND_LIBRARY(SDL2MAIN_LIBRARY NAMES SDL2main)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_INCLUDE_DIR SDL2_LIBRARY)
MARK_AS_ADVANCED(SDL2_INCLUDE_DIR SDL2_LIBRARY SDL2MAIN_LIBRARY)

View File

@ -1,17 +0,0 @@
# - Try to locate SDL2_image
# This module defines:
#
# SDL2_IMAGE_INCLUDE_DIR
# SDL2_IMAGE_LIBRARY
# SDL2_IMAGE_FOUND
#
FIND_PATH(SDL2_IMAGE_INCLUDE_DIR NAMES SDL_image.h PATH_SUFFIXES SDL2)
FIND_LIBRARY(SDL2_IMAGE_LIBRARY NAMES SDL2_image)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image REQUIRED_VARS SDL2_IMAGE_INCLUDE_DIR SDL2_IMAGE_LIBRARY)
MARK_AS_ADVANCED(SDL2_IMAGE_INCLUDE_DIR SDL2_IMAGE_LIBRARY)

View File

@ -1,17 +0,0 @@
# - Try to locate SDL2_mixer
# This module defines:
#
# SDL2_MIXER_INCLUDE_DIR
# SDL2_MIXER_LIBRARY
# SDL2_MIXER_FOUND
#
FIND_PATH(SDL2_MIXER_INCLUDE_DIR NAMES SDL_mixer.h PATH_SUFFIXES SDL2)
FIND_LIBRARY(SDL2_MIXER_LIBRARY NAMES SDL2_mixer)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer REQUIRED_VARS SDL2_MIXER_INCLUDE_DIR SDL2_MIXER_LIBRARY)
MARK_AS_ADVANCED(SDL2_MIXER_INCLUDE_DIR SDL2_MIXER_LIBRARY)

View File

@ -1,17 +0,0 @@
# - Try to locate SDL2_ttf
# This module defines:
#
# SDL2_TTF_INCLUDE_DIR
# SDL2_TTF_LIBRARY
# SDL2_TTF_FOUND
#
FIND_PATH(SDL2_TTF_INCLUDE_DIR NAMES SDL_ttf.h PATH_SUFFIXES SDL2)
FIND_LIBRARY(SDL2_TTF_LIBRARY NAMES SDL2_ttf)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf REQUIRED_VARS SDL2_TTF_INCLUDE_DIR SDL2_TTF_LIBRARY)
MARK_AS_ADVANCED(SDL2_TTF_INCLUDE_DIR SDL2_TTF_LIBRARY)

View File

@ -1,23 +0,0 @@
FUNCTION(JOIN_SIMPLE VALUES OUTPUT)
FOREACH(_VAL ${VALUES})
IF(DEFINED _TMP)
SET(_TMP "${_TMP} ${_VAL}")
ELSE(DEFINED _TMP)
SET(_TMP "${_VAL}")
ENDIF(DEFINED _TMP)
ENDFOREACH(_VAL)
SET(${OUTPUT} "${_TMP}" PARENT_SCOPE)
ENDFUNCTION()
FUNCTION(JOIN_QUOTED VALUES OUTPUT)
FOREACH(_VAL ${VALUES})
STRING(REPLACE "\\" "\\\\" _VAL "${_VAL}")
STRING(REPLACE "\"" "\\\"" _VAL "${_VAL}")
IF(DEFINED _TMP)
SET(_TMP "${_TMP} \"${_VAL}\"")
ELSE(DEFINED _TMP)
SET(_TMP "\"${_VAL}\"")
ENDIF(DEFINED _TMP)
ENDFOREACH(_VAL)
SET(${OUTPUT} "${_TMP}" PARENT_SCOPE)
ENDFUNCTION()

View File

@ -0,0 +1,15 @@
find_package(SDL2 REQUIRED)
if(@SDL2PP_WITH_IMAGE@)
find_package(SDL2_image REQUIRED)
endif()
if(@SDL2PP_WITH_TTF@)
find_package(SDL2_ttf REQUIRED)
endif()
if(@SDL2PP_WITH_MIXER@)
find_package(SDL2_mixer REQUIRED)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/SDL2ppTargets.cmake")

View File

@ -1,6 +1,6 @@
ADD_DEFINITIONS(-DTESTDATA_DIR="${PROJECT_SOURCE_DIR}/testdata")
add_definitions(-DTESTDATA_DIR="${PROJECT_SOURCE_DIR}/testdata")
SET(EXAMPLES
set(EXAMPLES
audio_sine
audio_wav
lines
@ -8,29 +8,29 @@ SET(EXAMPLES
sprites
)
IF(SDL2PP_WITH_IMAGE)
SET(EXAMPLES ${EXAMPLES}
if(SDL2PP_WITH_IMAGE)
set(EXAMPLES ${EXAMPLES}
image
fill
)
ENDIF(SDL2PP_WITH_IMAGE)
endif()
IF(SDL2PP_WITH_MIXER)
SET(EXAMPLES ${EXAMPLES}
if(SDL2PP_WITH_MIXER)
set(EXAMPLES ${EXAMPLES}
mixer
mixer_music
mixer_music_sine
mixer_effects
)
ENDIF(SDL2PP_WITH_MIXER)
endif()
IF(SDL2PP_WITH_TTF)
SET(EXAMPLES ${EXAMPLES}
if(SDL2PP_WITH_TTF)
set(EXAMPLES ${EXAMPLES}
ttf
)
ENDIF(SDL2PP_WITH_TTF)
endif()
FOREACH(EXAMPLE ${EXAMPLES})
ADD_EXECUTABLE(${EXAMPLE} ${EXAMPLE}.cc)
TARGET_LINK_LIBRARIES(${EXAMPLE} ${SDL2PP_LIBRARIES})
ENDFOREACH(EXAMPLE)
foreach(EXAMPLE ${EXAMPLES})
add_executable(${EXAMPLE} ${EXAMPLE}.cc)
target_link_libraries(${EXAMPLE} SDL2pp::SDL2pp)
endforeach()

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -33,7 +33,9 @@ using namespace SDL2pp;
int main(int, char*[]) try {
SDL sdl(SDL_INIT_AUDIO);
const int samplerate = 48000;
// XXX: these should be constexpr and not captured in lambda
// below, but that fails on microsoft crapiler
int samplerate = 48000;
float frequency = 2093.00f; // C7 tone
int64_t nsample = 0;
@ -41,7 +43,7 @@ int main(int, char*[]) try {
AudioSpec spec(samplerate, AUDIO_S16SYS, 1, 4096);
// Open audio device
AudioDevice dev(NullOpt, 0, spec, [&nsample, frequency, samplerate](Uint8* stream, int len) {
AudioDevice dev(NullOpt, 0, spec, [&nsample, samplerate, frequency](Uint8* stream, int len) {
// fill provided buffer with sine wave
for (Uint8* ptr = stream; ptr < stream + len; ptr += 2)
*(Uint16*)ptr = (Uint16)(32766.0f * sin(nsample++ / (float)samplerate * frequency));

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -33,7 +33,6 @@ using namespace SDL2pp;
int main(int, char*[]) try {
SDL sdl(SDL_INIT_AUDIO);
SDLMixer mixerlib(MIX_INIT_OGG);
Mixer mixer(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096);
Chunk sound(TESTDATA_DIR "/test.ogg");

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -33,7 +33,6 @@ using namespace SDL2pp;
int main(int, char*[]) try {
SDL sdl(SDL_INIT_AUDIO);
SDLMixer mixerlib(MIX_INIT_OGG);
Mixer mixer(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096);
Chunk sound(TESTDATA_DIR "/test.ogg");

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -33,7 +33,6 @@ using namespace SDL2pp;
int main(int, char*[]) try {
SDL sdl(SDL_INIT_AUDIO);
SDLMixer mixerlib(MIX_INIT_OGG);
Mixer mixer(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096);
Music music(TESTDATA_DIR "/test.ogg");

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
@ -33,6 +33,8 @@ int main(int, char*[]) try {
SDL sdl(SDL_INIT_AUDIO);
Mixer mixer(MIX_DEFAULT_FREQUENCY, AUDIO_S16SYS, 1, 4096);
// XXX: this should be constexpr and not captured in lambda
// below, but that fails on microsoft crapiler
float frequency = 2093.00f; // C7 tone
int64_t nsample = 0;

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,5 +1,5 @@
/*
libSDL2pp - C++11 bindings/wrapper for SDL2
libSDL2pp - C++ bindings/wrapper for SDL2
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied

View File

@ -1,10 +1,10 @@
PROJECT(libSDL2pp)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
FIND_PACKAGE(SDL2PP REQUIRED)
project(Test)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(SDL2pp REQUIRED)
INCLUDE_DIRECTORIES(${SDL2PP_INCLUDE_DIRS})
ADD_EXECUTABLE(cmake-ext-test ../../examples/sprites.cc)
TARGET_LINK_LIBRARIES(cmake-ext-test ${SDL2PP_LIBRARIES})
set(CMAKE_CXX_STANDARD 17)
add_executable(cmake-ext-test ../../examples/sprites.cc)
target_link_libraries(cmake-ext-test SDL2pp::SDL2pp)

View File

@ -1,6 +1,6 @@
CXX?= g++
CXXFLAGS+= -std=c++11
CXXFLAGS+= -std=c++17
SDL2PP_CFLAGS= `pkg-config --cflags sdl2pp`
SDL2PP_LIBS= `pkg-config --libs sdl2pp`

View File

@ -4,7 +4,7 @@ libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: sdl2pp
Description: C++11 bindings/wrappers for SDL2
Description: C++ bindings/wrappers for SDL2
Version: @SDL2PP_VERSION@
Requires: @SDL2_ALL_PKGCONFIG_MODULES@
Conflicts:

View File

@ -1,5 +1,7 @@
# simple command-line tests
SET(CLI_TESTS
set(CLI_TESTS
test_color
test_color_constexpr
test_error
test_optional
test_pointrect
@ -9,52 +11,52 @@ SET(CLI_TESTS
)
# live tests require X11 display and/or audio output
SET(LIVE_TESTS
set(LIVE_TESTS
live_audiodevice
live_rendering
live_window
)
IF(SDL2PP_WITH_MIXER)
SET(LIVE_TESTS ${LIVE_TESTS}
if(SDL2PP_WITH_MIXER)
set(LIVE_TESTS ${LIVE_TESTS}
live_mixer
)
ENDIF(SDL2PP_WITH_MIXER)
endif()
IF(SDL2PP_WITH_IMAGE)
SET(CLI_TESTS ${CLI_TESTS}
if(SDL2PP_WITH_IMAGE)
set(CLI_TESTS ${CLI_TESTS}
test_surface
)
ENDIF(SDL2PP_WITH_IMAGE)
endif()
IF(SDL2PP_WITH_TTF)
SET(CLI_TESTS ${CLI_TESTS}
if(SDL2PP_WITH_TTF)
set(CLI_TESTS ${CLI_TESTS}
test_font
)
ENDIF(SDL2PP_WITH_TTF)
endif()
ADD_DEFINITIONS(-DTESTDATA_DIR="${PROJECT_SOURCE_DIR}/testdata")
add_definitions(-DTESTDATA_DIR="${PROJECT_SOURCE_DIR}/testdata")
# header tests: these just include specific headers to check if
# they are compilable (e.g., includes and forward declarations are
# complete and do not require extra includes)
FOREACH(HEADER ${LIBRARY_HEADERS})
STRING(REGEX REPLACE [^a-zA-Z0-9] _ HEADER_NORMALIZED ${HEADER})
CONFIGURE_FILE(header_test.cc.in ${HEADER_NORMALIZED}_test.cc)
ADD_EXECUTABLE(${HEADER_NORMALIZED}_test ${HEADER_NORMALIZED}_test.cc)
TARGET_LINK_LIBRARIES(${HEADER_NORMALIZED}_test ${SDL2PP_LIBRARIES})
ENDFOREACH(HEADER ${TESTS})
foreach(HEADER ${LIBRARY_HEADERS})
string(REGEX REPLACE [^a-zA-Z0-9] _ HEADER_NORMALIZED ${HEADER})
configure_file(header_test.cc.in ${HEADER_NORMALIZED}_test.cc)
add_executable(${HEADER_NORMALIZED}_test ${HEADER_NORMALIZED}_test.cc)
target_link_libraries(${HEADER_NORMALIZED}_test SDL2pp::SDL2pp)
endforeach()
FOREACH(TEST ${CLI_TESTS})
ADD_EXECUTABLE(${TEST} ${TEST}.cc)
TARGET_LINK_LIBRARIES(${TEST} ${SDL2PP_LIBRARIES})
ADD_TEST(${TEST} ${TEST})
ENDFOREACH(TEST ${TESTS})
foreach(TEST ${CLI_TESTS})
add_executable(${TEST} ${TEST}.cc)
target_link_libraries(${TEST} SDL2pp::SDL2pp)
add_test(${TEST} ${TEST})
endforeach()
FOREACH(TEST ${LIVE_TESTS})
ADD_EXECUTABLE(${TEST} ${TEST}.cc)
TARGET_LINK_LIBRARIES(${TEST} ${SDL2PP_LIBRARIES})
IF(SDL2PP_ENABLE_LIVE_TESTS)
ADD_TEST(${TEST} ${TEST})
ENDIF(SDL2PP_ENABLE_LIVE_TESTS)
ENDFOREACH(TEST ${TESTS})
foreach(TEST ${LIVE_TESTS})
add_executable(${TEST} ${TEST}.cc)
target_link_libraries(${TEST} SDL2pp::SDL2pp)
if(SDL2PP_ENABLE_LIVE_TESTS)
add_test(${TEST} ${TEST})
endif()
endforeach()

View File

@ -28,21 +28,21 @@ BEGIN_TEST(int, char*[])
{
// Default state
EXPECT_TRUE(device.GetStatus(), SDL_AUDIO_PAUSED);
EXPECT_EQUAL(device.GetStatus(), SDL_AUDIO_PAUSED);
EXPECT_TRUE(callback_requests == 0);
long saved_reqs = callback_requests;
// Unpause
device.Pause(false);
EXPECT_TRUE(device.GetStatus(), SDL_AUDIO_PLAYING);
EXPECT_EQUAL(device.GetStatus(), SDL_AUDIO_PLAYING);
SDL_Delay(1000);
EXPECT_TRUE(callback_requests > saved_reqs);
// Pause
device.Pause(true);
EXPECT_TRUE(device.GetStatus(), SDL_AUDIO_PLAYING);
EXPECT_EQUAL(device.GetStatus(), SDL_AUDIO_PAUSED);
saved_reqs = callback_requests;

View File

@ -32,18 +32,18 @@ BEGIN_TEST(int, char*[])
auto rwops = RWops::FromFile(TESTDATA_DIR "/test.ogg");
Chunk chunk_by_rw(rwops);
EXPECT_TRUE(chunk_by_rw.Get());
EXPECT_TRUE(chunk_by_rw.Get() != nullptr);
rwops.Seek(0, RW_SEEK_SET);
Music music_by_rw1(rwops);
EXPECT_TRUE(music_by_rw1.Get());
EXPECT_TRUE(music_by_rw1.Get() != nullptr);
EXPECT_EQUAL(music_by_rw1.GetType(), MUS_OGG);
rwops.Seek(0, RW_SEEK_SET);
Music music_by_rw2(rwops, MUS_OGG);
EXPECT_TRUE(music_by_rw2.Get());
EXPECT_TRUE(music_by_rw2.Get() != nullptr);
EXPECT_EQUAL(music_by_rw2.GetType(), MUS_OGG);
// bad format

View File

@ -45,8 +45,8 @@ public:
bool Test3x3(int x, int y, int mask, int r, int g, int b, int a = -1) {
for (int dy = -1; dy <= 1; dy++) {
for (int dx = -1; dx <= 1; dx++) {
bool maskbit = mask & (1 << ((1 - dx) + (1 - dy) * 4));
if (Test(x + dx, y + dy, r, g, b, a) != !!maskbit)
bool maskbit = !!(mask & (1 << ((1 - dx) + (1 - dy) * 4)));
if (Test(x + dx, y + dy, r, g, b, a) != maskbit)
return false;
}
}
@ -59,15 +59,15 @@ BEGIN_TEST(int, char*[])
{
// SDL initialization stuff
EXPECT_TRUE(sdl.WasInit(SDL_INIT_VIDEO));
EXPECT_TRUE(sdl.WasInit(SDL_INIT_VIDEO) > 0);
sdl.QuitSubSystem(SDL_INIT_VIDEO);
EXPECT_TRUE(!sdl.WasInit(SDL_INIT_VIDEO));
EXPECT_TRUE(sdl.WasInit(SDL_INIT_VIDEO) == 0);
sdl.InitSubSystem(SDL_INIT_VIDEO);
EXPECT_TRUE(sdl.WasInit(SDL_INIT_VIDEO));
EXPECT_TRUE(sdl.WasInit(SDL_INIT_VIDEO) > 0);
}
Window window("libSDL2pp test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, 0);
@ -180,12 +180,12 @@ BEGIN_TEST(int, char*[])
pixels.Retrieve(renderer);
EXPECT_TRUE(pixels.Test3x3(10, 10, 0x032, 255, 128, 0));
EXPECT_TRUE(pixels.Test3x3(19, 10, 0x062, 255, 128, 0));
EXPECT_TRUE(pixels.Test3x3(19, 10, 0x062, 255, 128, 0), "may fail in CI", NON_FATAL);
EXPECT_TRUE(pixels.Test3x3(10, 19, 0x230, 255, 128, 0));
EXPECT_TRUE(pixels.Test3x3(19, 19, 0x260, 255, 128, 0), "depends on OpenGL implementation, which may or may not draw last pixel of a line", NON_FATAL);
EXPECT_TRUE(pixels.Test3x3(30, 10, 0x032, 0, 255, 128));
EXPECT_TRUE(pixels.Test3x3(39, 10, 0x062, 0, 255, 128));
EXPECT_TRUE(pixels.Test3x3(39, 10, 0x062, 0, 255, 128), "may fail in CI", NON_FATAL);
EXPECT_TRUE(pixels.Test3x3(30, 19, 0x230, 0, 255, 128));
EXPECT_TRUE(pixels.Test3x3(39, 19, 0x260, 0, 255, 128), "depends on OpenGL implementation, which may or may not draw last pixel of a line", NON_FATAL);

View File

@ -120,33 +120,33 @@ BEGIN_TEST(int, char*[])
// Flags
std::cerr << "Window flags: " << std::hex << "0x" << window.GetFlags() << std::dec << std::endl;
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_SHOWN);
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_RESIZABLE);
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_SHOWN, SDL_WINDOW_SHOWN);
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_RESIZABLE, SDL_WINDOW_RESIZABLE);
window.Hide();
EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_SHOWN));
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_SHOWN, 0U);
EventSleep(1000);
window.Show();
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_SHOWN);
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_SHOWN, SDL_WINDOW_SHOWN);
EventSleep(1000);
window.Maximize();
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_MAXIMIZED);
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_MAXIMIZED, SDL_WINDOW_MAXIMIZED);
EventSleep(1000);
window.Restore();
EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_MAXIMIZED));
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_MAXIMIZED, 0U);
EventSleep(1000);
window.Minimize();
EventSleep(1000); // Minimization may take some time, e.g. on Ubuntu due to animations
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_MINIMIZED, "May fail on some WMs", NON_FATAL);
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_MINIMIZED, SDL_WINDOW_MINIMIZED, "May fail on some WMs", NON_FATAL);
EventSleep(1000);
window.Restore();
EventSleep(1000); // Restore from minimized state may take some time, e.g. on Ubuntu due to animations
EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_MINIMIZED));
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_MINIMIZED, 0U);
EventSleep(1000);
// May hang until window is moved (SDL bug?)
@ -183,11 +183,11 @@ BEGIN_TEST(int, char*[])
{
// Fullscreen
window.SetFullscreen(SDL_WINDOW_FULLSCREEN_DESKTOP);
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_FULLSCREEN_DESKTOP);
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_FULLSCREEN_DESKTOP, SDL_WINDOW_FULLSCREEN_DESKTOP);
EventSleep(1000);
window.SetFullscreen(0);
EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_FULLSCREEN_DESKTOP));
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_FULLSCREEN_DESKTOP, 0U);
EventSleep(1000);
}
@ -212,6 +212,29 @@ BEGIN_TEST(int, char*[])
EventSleep(1000);
}
}
{
// Resizable
Uint32 flags = window.GetFlags();
if (flags & SDL_WINDOW_RESIZABLE) {
window.SetResizable(false);
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_RESIZABLE, 0U);
EventSleep(1000);
window.SetResizable(true);
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_RESIZABLE, SDL_WINDOW_RESIZABLE);
EventSleep(1000);
} else {
window.SetResizable(true);
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_RESIZABLE, SDL_WINDOW_RESIZABLE);
EventSleep(1000);
window.SetResizable(false);
EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_RESIZABLE, 0U);
EventSleep(1000);
}
}
#endif
END_TEST()

88
tests/test_color.cc Normal file
View File

@ -0,0 +1,88 @@
#include <SDL_main.h>
#include <SDL2pp/Color.hh>
#include "testing.h"
using namespace SDL2pp;
BEGIN_TEST(int, char*[])
{
EXPECT_TRUE(Color(1, 2, 3, 4) == Color(1, 2, 3, 4));
EXPECT_TRUE(Color(1, 2, 3, 4) != Color(0, 2, 3, 4));
EXPECT_TRUE(Color(1, 2, 3, 4) != Color(1, 0, 3, 4));
EXPECT_TRUE(Color(1, 2, 3, 4) != Color(0, 2, 3, 4));
EXPECT_TRUE(Color(1, 2, 3, 4) != Color(1, 2, 3, 0));
EXPECT_TRUE(SDL_Color{1, 2, 3, 4} == Color(1, 2, 3, 4));
EXPECT_TRUE(Color(1, 2, 3, 4) == SDL_Color{1, 2, 3, 4});
}
{
EXPECT_TRUE(Color() == Color(0, 0, 0, 0));
EXPECT_TRUE(Color(1, 2, 3) == Color(1, 2, 3, 255));
Color c(1,2,3,4);
EXPECT_TRUE(c.r == 1 && c.g == 2 && c.b == 3 && c.a == 4);
EXPECT_TRUE(c.GetRed() == 1 && c.GetGreen() == 2 && c.GetBlue() == 3 && c.GetAlpha() == 4);
c = Color(4, 5, 6, 7);
EXPECT_TRUE(c.r == 4 && c.g == 5 && c.b == 6 && c.a == 7);
EXPECT_TRUE(c.GetRed() == 4 && c.GetGreen() == 5 && c.GetBlue() == 6 && c.GetAlpha() == 7);
c.SetRed(8).SetGreen(9).SetBlue(10).SetAlpha(11);
EXPECT_TRUE(c.r == 8 && c.g == 9 && c.b == 10 && c.a == 11);
c = SDL_Color{12, 13, 14, 15};
EXPECT_TRUE(c.r == 12 && c.g == 13 && c.b == 14 && c.a == 15);
}
{
// Self assignment
Color c(1, 2, 3, 4);
c = c;
EXPECT_TRUE(c == Color(1, 2, 3, 4));
}
{
// Self move-assignment
Color c(1, 2, 3, 4);
Color& cref = c;
c = std::move(cref);
EXPECT_TRUE(c.GetRed() == 1 && c.GetGreen() == 2 && c.GetBlue() == 3 && c.GetAlpha() == 4);
}
{
// Hashes
EXPECT_TRUE(std::hash<Color>()(Color(1, 2, 3, 4)) == std::hash<Color>()(Color(1, 2, 3, 4)));
EXPECT_TRUE(std::hash<Color>()(Color(1, 2, 3, 4)) != std::hash<Color>()(Color(2, 1, 3, 4)));
EXPECT_TRUE(std::hash<Color>()(Color(1, 2, 3, 4)) != std::hash<Color>()(Color(1, 2, 4, 3)));
}
{
// Construction from and comparison with SDL objects
SDL_Color sdlcolor = { 1, 2, 3, 4 };
EXPECT_TRUE(Color(sdlcolor) == Color(1, 2, 3, 4));
EXPECT_TRUE(Color(sdlcolor) != Color(0, 2, 3, 4));
EXPECT_TRUE(Color(1, 2, 3, 4) == sdlcolor);
EXPECT_TRUE(Color(0, 2, 3, 4) != sdlcolor);
}
{
// streams
std::stringstream stream;
stream << Color(1, 2, 3, 4);
EXPECT_EQUAL(stream.str(), "[r:1,g:2,b:3,a:4]");
}
END_TEST()

View File

@ -0,0 +1,29 @@
#include <SDL_main.h>
#include <SDL2pp/Color.hh>
using namespace SDL2pp;
int main(int, char*[]) {
constexpr SDL_Color sc{1, 2, 3, 4};
constexpr Color c1;
constexpr Color c2(sc);
constexpr Color c3(1, 2, 3, 4);
constexpr Color c4(c2);
constexpr Color c5(1, 2, 3);
constexpr bool b1 = c2 == c4;
constexpr bool b2 = c1 != c2;
static_assert(b1, "");
static_assert(b2, "");
constexpr int r = c1.GetRed();
constexpr int g = c1.GetGreen();
constexpr int b = c1.GetBlue();
constexpr int a = c1.GetAlpha();
static_assert(r == 0 && g == 0 && b == 0 && a == 0, "");
return 0;
}

View File

@ -19,7 +19,7 @@ BEGIN_TEST(int, char*[])
auto rwops = RWops::FromFile(TESTDATA_DIR "/Vera.ttf");
Font font_by_rw(rwops, 30);
EXPECT_TRUE(font_by_rw.Get());
EXPECT_TRUE(font_by_rw.Get() != nullptr);
}
MOVE_TEST(Font, font, Get, nullptr);
@ -70,7 +70,7 @@ BEGIN_TEST(int, char*[])
{
// Metrics
EXPECT_EQUAL(font.GetHeight(), 36);
EXPECT_TRUE(font.GetHeight() == 35 || font.GetHeight() == 36);
EXPECT_EQUAL(font.GetAscent(), 28);
EXPECT_EQUAL(font.GetDescent(), -7);
EXPECT_EQUAL(font.GetLineSkip(), 35);
@ -97,14 +97,22 @@ BEGIN_TEST(int, char*[])
{
// Glyphs provided
EXPECT_TRUE(font.IsGlyphProvided(u'A'));
EXPECT_TRUE(font.IsGlyphProvided(u'A') > 0);
#ifndef _MSC_VER // MSVC has problems with unicode literals
EXPECT_TRUE(font.IsGlyphProvided(u'¼'));
EXPECT_TRUE(!font.IsGlyphProvided(u'л'));
EXPECT_TRUE(!font.IsGlyphProvided(u'Ы'));
EXPECT_TRUE(font.IsGlyphProvided(u'¼') > 0);
EXPECT_TRUE(font.IsGlyphProvided(u'л') == 0);
EXPECT_TRUE(font.IsGlyphProvided(u'Ы') == 0);
#endif
}
auto isAllowedARect = [](const Rect& r) {
return r.x == 0 && r.y == 0 && r.w >= 20 && r.w <= 21 && r.h >= 22 && r.h <= 22;
};
auto isAllowedAADims = [](const Point& p) {
return p.x >= 42 && p.x <= 43 && p.y >= 35 && p.y <= 36;
};
{
// Glyph metrics
int minx, maxx, miny, maxy, advance;
@ -115,33 +123,33 @@ BEGIN_TEST(int, char*[])
EXPECT_NO_EXCEPTION(font.GetGlyphMetrics(u'A', minx, maxx, miny, maxy, advance));
EXPECT_EQUAL(minx, 0);
EXPECT_EQUAL(maxx, 20);
EXPECT_TRUE(maxx >= 20 && maxx <= 21);
EXPECT_EQUAL(miny, 0);
EXPECT_EQUAL(maxy, 22);
EXPECT_EQUAL(advance, 21);
EXPECT_EQUAL(font.GetGlyphRect(u'A'), Rect(0, 0, 20, 22));
EXPECT_TRUE(isAllowedARect(font.GetGlyphRect(u'A')));
EXPECT_EQUAL(font.GetGlyphAdvance(u'A'), 21);
// Text size
EXPECT_EQUAL(font.GetSizeText("AA"), Point(43, 36));
EXPECT_EQUAL(font.GetSizeUTF8(u8"AA"), Point(43, 36));
EXPECT_EQUAL(font.GetSizeUNICODE(u"AA"), Point(43, 36));
EXPECT_TRUE(isAllowedAADims(font.GetSizeText("AA")));
EXPECT_TRUE(isAllowedAADims(font.GetSizeUTF8(u8"AA")));
EXPECT_TRUE(isAllowedAADims(font.GetSizeUNICODE(u"AA")));
}
{
// Rendering
// XXX: add real pixel color tests
EXPECT_EQUAL(font.RenderText_Solid("AA", SDL_Color{255, 255, 255, 255}).GetSize(), Point(43, 36));
EXPECT_EQUAL(font.RenderUTF8_Solid(u8"AA", SDL_Color{255, 255, 255, 255}).GetSize(), Point(43, 36));
EXPECT_EQUAL(font.RenderUNICODE_Solid(u"AA", SDL_Color{255, 255, 255, 255}).GetSize(), Point(43, 36));
EXPECT_TRUE(isAllowedAADims(font.RenderText_Solid("AA", SDL_Color{255, 255, 255, 255}).GetSize()));
EXPECT_TRUE(isAllowedAADims(font.RenderUTF8_Solid(u8"AA", SDL_Color{255, 255, 255, 255}).GetSize()));
EXPECT_TRUE(isAllowedAADims(font.RenderUNICODE_Solid(u"AA", SDL_Color{255, 255, 255, 255}).GetSize()));
EXPECT_EQUAL(font.RenderText_Shaded("AA", SDL_Color{255, 255, 255, 255}, SDL_Color{0, 0, 0, 255}).GetSize(), Point(43, 36));
EXPECT_EQUAL(font.RenderUTF8_Shaded(u8"AA", SDL_Color{255, 255, 255, 255}, SDL_Color{0, 0, 0, 255}).GetSize(), Point(43, 36));
EXPECT_EQUAL(font.RenderUNICODE_Shaded(u"AA", SDL_Color{255, 255, 255, 255}, SDL_Color{0, 0, 0, 255}).GetSize(), Point(43, 36));
EXPECT_TRUE(isAllowedAADims(font.RenderText_Shaded("AA", SDL_Color{255, 255, 255, 255}, SDL_Color{0, 0, 0, 255}).GetSize()));
EXPECT_TRUE(isAllowedAADims(font.RenderUTF8_Shaded(u8"AA", SDL_Color{255, 255, 255, 255}, SDL_Color{0, 0, 0, 255}).GetSize()));
EXPECT_TRUE(isAllowedAADims(font.RenderUNICODE_Shaded(u"AA", SDL_Color{255, 255, 255, 255}, SDL_Color{0, 0, 0, 255}).GetSize()));
EXPECT_EQUAL(font.RenderText_Blended("AA", SDL_Color{255, 255, 255, 255}).GetSize(), Point(43, 36));
EXPECT_EQUAL(font.RenderUTF8_Blended(u8"AA", SDL_Color{255, 255, 255, 255}).GetSize(), Point(43, 36));
EXPECT_EQUAL(font.RenderUNICODE_Blended(u"AA", SDL_Color{255, 255, 255, 255}).GetSize(), Point(43, 36));
EXPECT_TRUE(isAllowedAADims(font.RenderText_Blended("AA", SDL_Color{255, 255, 255, 255}).GetSize()));
EXPECT_TRUE(isAllowedAADims(font.RenderUTF8_Blended(u8"AA", SDL_Color{255, 255, 255, 255}).GetSize()));
EXPECT_TRUE(isAllowedAADims(font.RenderUNICODE_Blended(u"AA", SDL_Color{255, 255, 255, 255}).GetSize()));
}
END_TEST()

View File

@ -19,7 +19,6 @@ BEGIN_TEST(int, char*[])
// accessing disengaged fails
EXPECT_EXCEPTION(i = o.value(), BadOptionalAccess);
EXPECT_EXCEPTION(i = o.value(), std::logic_error);
// value_or test
EXPECT_EQUAL(i = o.value_or(234), 234);

View File

@ -3,13 +3,9 @@
#include <SDL2pp/Point.hh>
#include <SDL2pp/Rect.hh>
#include "testing.h"
using namespace SDL2pp;
BEGIN_TEST(int, char*[])
// note that this is merely a compilation test; EXPECT_s are mainly
// used to silence `unused variable' warnings
int main(int, char*[]) {
{
constexpr SDL_Point sp{1, 2};
constexpr Point p1;
@ -20,13 +16,13 @@ BEGIN_TEST(int, char*[])
constexpr bool b1 = p2 == p4;
constexpr bool b2 = p1 != p2;
EXPECT_TRUE(b1);
EXPECT_TRUE(b2);
static_assert(b1, "");
static_assert(b2, "");
constexpr int x = p1.GetX();
constexpr int y = p1.GetY();
EXPECT_TRUE(x == 0 && y == 0);
static_assert(x == 0 && y == 0, "");
constexpr Point neg = -p1;
constexpr Point sum = p1 + p2;
@ -38,7 +34,7 @@ BEGIN_TEST(int, char*[])
constexpr Point rem1 = p1 % p2;
constexpr Point rem2 = p1 % 2;
EXPECT_EQUAL(neg + sum + diff + mul1 + mul2 + div1 + div2 + rem1 + rem2, Point(0, 0));
static_assert(neg + sum + diff + mul1 + mul2 + div1 + div2 + rem1 + rem2 == Point(0, 0), "");
}
{
@ -49,14 +45,14 @@ BEGIN_TEST(int, char*[])
constexpr Rect r4(0, 0, 1, 1);
constexpr Rect r5(r4);
EXPECT_EQUAL(r4, r2);
EXPECT_EQUAL(r5, r3);
static_assert(r4 == r2, "");
static_assert(r5 == r3, "");
constexpr bool b1 = r2 == r3;
constexpr bool b2 = r1 != r3;
EXPECT_TRUE(b1);
EXPECT_TRUE(b2);
static_assert(b1, "");
static_assert(b2, "");
constexpr int x = r5.GetX();
constexpr int y = r5.GetY();
@ -65,20 +61,22 @@ BEGIN_TEST(int, char*[])
constexpr int x2 = r5.GetX2();
constexpr int y2 = r5.GetY2();
EXPECT_TRUE(x == y);
EXPECT_TRUE(w == h);
EXPECT_TRUE(x2 == y2);
static_assert(x == y, "");
static_assert(w == h, "");
static_assert(x2 == y2, "");
constexpr Rect add = r1 + Point(1, 1);
constexpr Rect sub = r1 - Point(1, 1);
EXPECT_EQUAL(add - Point(2, 2), sub);
static_assert(add - Point(2, 2) == sub, "");
constexpr bool b3 = r2.Contains(0, 0);
constexpr bool b4 = r2.Contains(Point(0, 0));
constexpr bool b5 = r2.Contains(Rect(0, 0, 1, 1));
constexpr bool b6 = r2.Intersects(Rect(0, 0, 1, 1));
EXPECT_TRUE(b3 && b4 && b5 && b6);
static_assert(b3 && b4 && b5 && b6, "");
}
END_TEST()
return 0;
}