Started SDL2 migration

master
krzys-h 2015-09-24 21:09:46 +02:00
parent 1440190921
commit 53e4470dbf
36 changed files with 641 additions and 2213 deletions

View File

@ -229,9 +229,9 @@ endif()
##
find_package(OpenGL 1.4 REQUIRED)
find_package(SDL 1.2.10 REQUIRED)
find_package(SDL_image 1.2 REQUIRED)
find_package(SDL_ttf 2.0 REQUIRED)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(PNG 1.2 REQUIRED)
find_package(Gettext REQUIRED)
find_package(PhysFS REQUIRED)
@ -295,21 +295,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(WINGETOPT 1) # use wingetopt library
endif()
##
# Clipboard support needs X11 libraries
##
if(PLATFORM_GNU)
find_package(X11 REQUIRED)
endif()
##
# Clipboard support
##
set(CLIPBOARD_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/clipboard/include)
add_subdirectory(lib/clipboard)
##
# Localename
##

163
cmake/FindSDL2.cmake Normal file
View File

@ -0,0 +1,163 @@
# Locate SDL2 library
# This module defines
# SDL2_LIBRARY, the name of the library to link against
# SDL2_FOUND, if false, do not try to link to SDL2
# SDL2_INCLUDE_DIR, where to find SDL.h
#
# This module responds to the the flag:
# SDL2_BUILDING_LIBRARY
# If this is defined, then no SDL2main will be linked in because
# only applications need main().
# Otherwise, it is assumed you are building an application and this
# module will attempt to locate and set the the proper link flags
# as part of the returned SDL2_LIBRARY variable.
#
# Don't forget to include SDLmain.h and SDLmain.m your project for the
# OS X framework based version. (Other versions link to -lSDL2main which
# this module will try to find on your behalf.) Also for OS X, this
# module will automatically add the -framework Cocoa on your behalf.
#
#
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL2_LIBRARY
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
#
#
# $SDL2DIR is an environment variable that would
# correspond to the ./configure --prefix=$SDL2DIR
# used in building SDL2.
# l.e.galup 9-20-02
#
# Modified by Eric Wing.
# Added code to assist with automated building by using environmental variables
# and providing a more controlled/consistent search behavior.
# Added new modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL guidelines.
# Added a search for SDL2main which is needed by some platforms.
# Added a search for threads which is needed by some platforms.
# Added needed compile switches for MinGW.
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of
# SDL2_LIBRARY to override this selection or set the CMake environment
# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
# This needed to change because "proper" SDL convention
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL2/ (see FreeBSD).
#=============================================================================
# Copyright 2003-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
SET(SDL2_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES include/SDL2 include
PATHS ${SDL2_SEARCH_PATHS}
)
FIND_LIBRARY(SDL2_LIBRARY_TEMP
NAMES SDL2
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES lib64 lib
PATHS ${SDL2_SEARCH_PATHS}
)
IF(NOT SDL2_BUILDING_LIBRARY)
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
# Non-OS X framework versions expect you to also dynamically link to
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
# seem to provide SDL2main for compatibility even though they don't
# necessarily need it.
FIND_LIBRARY(SDL2MAIN_LIBRARY
NAMES SDL2main
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES lib64 lib
PATHS ${SDL2_SEARCH_PATHS}
)
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
ENDIF(NOT SDL2_BUILDING_LIBRARY)
# SDL2 may require threads on your system.
# The Apple build may not need an explicit flag because one of the
# frameworks may already provide it.
# But for non-OSX systems, I will use the CMake Threads package.
IF(NOT APPLE)
FIND_PACKAGE(Threads)
ENDIF(NOT APPLE)
# MinGW needs an additional library, mwindows
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
# (Actually on second look, I think it only needs one of the m* libraries.)
IF(MINGW)
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
ENDIF(MINGW)
IF(SDL2_LIBRARY_TEMP)
# For SDL2main
IF(NOT SDL2_BUILDING_LIBRARY)
IF(SDL2MAIN_LIBRARY)
SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
ENDIF(SDL2MAIN_LIBRARY)
ENDIF(NOT SDL2_BUILDING_LIBRARY)
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
# CMake doesn't display the -framework Cocoa string in the UI even
# though it actually is there if I modify a pre-used variable.
# I think it has something to do with the CACHE STRING.
# So I use a temporary variable until the end so I can set the
# "real" variable in one-shot.
IF(APPLE)
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
ENDIF(APPLE)
# For threads, as mentioned Apple doesn't need this.
# In fact, there seems to be a problem if I used the Threads package
# and try using this line, so I'm just skipping it entirely for OS X.
IF(NOT APPLE)
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
ENDIF(NOT APPLE)
# For MinGW library
IF(MINGW)
SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
ENDIF(MINGW)
# Set the final string here so the GUI reflects the final state.
SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
ENDIF(SDL2_LIBRARY_TEMP)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)

158
cmake/FindSDL2_image.cmake Normal file
View File

@ -0,0 +1,158 @@
# Locate SDL2_image library
# This module defines
# SDL2_IMAGE_LIBRARY, the name of the library to link against
# SDL2_IMAGE_FOUND, if false, do not try to link to SDL2_image
# SDL2_IMAGE_INCLUDE_DIR, where to find SDL_image.h
#
# Additional Note: If you see an empty SDL2_IMAGE_LIBRARY_TEMP in your configuration
# and no SDL2_IMAGE_LIBRARY, it means CMake did not find your SDL2_Image library
# (SDL2_image.dll, libsdl2_image.so, SDL2_image.framework, etc).
# Set SDL2_IMAGE_LIBRARY_TEMP to point to your SDL2 library, and configure again.
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL2_IMAGE_LIBRARY
# variable, but when these values are unset, SDL2_IMAGE_LIBRARY does not get created.
#
# $SDL2 is an environment variable that would
# correspond to the ./configure --prefix=$SDL2
# used in building SDL2.
# l.e.galup 9-20-02
#
# Modified by Eric Wing.
# Added code to assist with automated building by using environmental variables
# and providing a more controlled/consistent search behavior.
# Added new modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL2 guidelines.
# Added a search for SDL2main which is needed by some platforms.
# Added a search for threads which is needed by some platforms.
# Added needed compile switches for MinGW.
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of
# SDL2_IMAGE_LIBRARY to override this selection or set the CMake environment
# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
# This needed to change because "proper" SDL2 convention
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL2/ (see FreeBSD).
#
# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake
# module with the minor edit of changing "SDL" to "SDL2" where necessary. This
# was not created for redistribution, and exists temporarily pending official
# SDL2 CMake modules.
#
# Note that on windows this will only search for the 32bit libraries, to search
# for 64bit change x86/i686-w64 to x64/x86_64-w64
#=============================================================================
# Copyright 2003-2009 Kitware, Inc.
#
# CMake - Cross Platform Makefile Generator
# Copyright 2000-2014 Kitware, Inc.
# Copyright 2000-2011 Insight Software Consortium
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the names of Kitware, Inc., the Insight Software Consortium,
# nor the names of their contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
FIND_PATH(SDL2_IMAGE_INCLUDE_DIR SDL_image.h
HINTS
${SDL2}
$ENV{SDL2}
$ENV{SDL2_IMAGE}
PATH_SUFFIXES include/SDL2 include SDL2
i686-w64-mingw32/include/SDL2
x86_64-w64-mingw32/include/SDL2
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local/include/SDL2
/usr/include/SDL2
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
# Lookup the 64 bit libs on x64
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
FIND_LIBRARY(SDL2_IMAGE_LIBRARY_TEMP
NAMES SDL2_image
HINTS
${SDL2}
$ENV{SDL2}
$ENV{SDL2_IMAGE}
PATH_SUFFIXES lib64 lib
lib/x64
x86_64-w64-mingw32/lib
PATHS
/sw
/opt/local
/opt/csw
/opt
)
# On 32bit build find the 32bit libs
ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8)
FIND_LIBRARY(SDL2_IMAGE_LIBRARY_TEMP
NAMES SDL2_image
HINTS
${SDL2}
$ENV{SDL2}
$ENV{SDL2_IMAGE}
PATH_SUFFIXES lib
lib/x86
i686-w64-mingw32/lib
PATHS
/sw
/opt/local
/opt/csw
/opt
)
ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(SDL2_IMAGE_FOUND "NO")
IF(SDL2_IMAGE_LIBRARY_TEMP)
# Set the final string here so the GUI reflects the final state.
SET(SDL2_IMAGE_LIBRARY ${SDL2_IMAGE_LIBRARY_TEMP} CACHE STRING "Where the SDL2_image Library can be found")
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
SET(SDL2_IMAGE_LIBRARY_TEMP "${SDL2_IMAGE_LIBRARY_TEMP}" CACHE INTERNAL "")
SET(SDL2_IMAGE_FOUND "YES")
ENDIF(SDL2_IMAGE_LIBRARY_TEMP)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_IMAGE REQUIRED_VARS SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)

157
cmake/FindSDL2_ttf.cmake Normal file
View File

@ -0,0 +1,157 @@
# Locate SDL2_ttf library
# This module defines
# SDL2_TTF_LIBRARY, the name of the library to link against
# SDL2_TTF_FOUND, if false, do not try to link to SDL2_ttf
# SDL2_TTF_INCLUDE_DIR, where to find SDL_image.h
#
# Additional Note: If you see an empty SDL2_TTF_LIBRARY_TEMP in your configuration
# and no SDL2_TTF_LIBRARY, it means CMake did not find your SDL2_Image library
# (SDL2_ttf.dll, libsdl2_image.so, SDL2_ttf.framework, etc).
# Set SDL2_TTF_LIBRARY_TEMP to point to your SDL2 library, and configure again.
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL2_TTF_LIBRARY
# variable, but when these values are unset, SDL2_TTF_LIBRARY does not get created.
#
# $SDL2 is an environment variable that would
# correspond to the ./configure --prefix=$SDL2
# used in building SDL2.
# l.e.galup 9-20-02
#
# Modified by Eric Wing.
# Added code to assist with automated building by using environmental variables
# and providing a more controlled/consistent search behavior.
# Added new modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL2 guidelines.
# Added a search for SDL2main which is needed by some platforms.
# Added a search for threads which is needed by some platforms.
# Added needed compile switches for MinGW.
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of
# SDL2_TTF_LIBRARY to override this selection or set the CMake environment
# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
# This needed to change because "proper" SDL2 convention
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL2/ (see FreeBSD).
#
# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake
# module with the minor edit of changing "SDL" to "SDL2" where necessary. This
# was not created for redistribution, and exists temporarily pending official
# SDL2 CMake modules.
#
# Note that on windows this will only search for the 32bit libraries, to search
# for 64bit change x86/i686-w64 to x64/x86_64-w64
#=============================================================================
# Copyright 2003-2009 Kitware, Inc.
#
# CMake - Cross Platform Makefile Generator
# Copyright 2000-2014 Kitware, Inc.
# Copyright 2000-2011 Insight Software Consortium
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the names of Kitware, Inc., the Insight Software Consortium,
# nor the names of their contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
FIND_PATH(SDL2_TTF_INCLUDE_DIR SDL_ttf.h
HINTS
${SDL2}
$ENV{SDL2}
$ENV{SDL2_TTF}
PATH_SUFFIXES include/SDL2 include SDL2
i686-w64-mingw32/include/SDL2
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local/include/SDL2
/usr/include/SDL2
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
# Lookup the 64 bit libs on x64
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
FIND_LIBRARY(SDL2_TTF_LIBRARY_TEMP
NAMES SDL2_ttf
HINTS
${SDL2}
$ENV{SDL2}
$ENV{SDL2_TTF}
PATH_SUFFIXES lib64 lib
lib/x64
x86_64-w64-mingw32/lib
PATHS
/sw
/opt/local
/opt/csw
/opt
)
# On 32bit build find the 32bit libs
ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8)
FIND_LIBRARY(SDL2_TTF_LIBRARY_TEMP
NAMES SDL2_ttf
HINTS
${SDL2}
$ENV{SDL2}
$ENV{SDL2_TTF}
PATH_SUFFIXES lib
lib/x86
i686-w64-mingw32/lib
PATHS
/sw
/opt/local
/opt/csw
/opt
)
ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(SDL2_TTF_FOUND "NO")
IF(SDL2_TTF_LIBRARY_TEMP)
# Set the final string here so the GUI reflects the final state.
SET(SDL2_TTF_LIBRARY ${SDL2_TTF_LIBRARY_TEMP} CACHE STRING "Where the SDL2_ttf Library can be found")
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
SET(SDL2_TTF_LIBRARY_TEMP "${SDL2_TTF_LIBRARY_TEMP}" CACHE INTERNAL "")
SET(SDL2_TTF_FOUND "YES")
ENDIF(SDL2_TTF_LIBRARY_TEMP)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_TTF REQUIRED_VARS SDL2_TTF_LIBRARY SDL2_TTF_INCLUDE_DIR)

View File

@ -1 +0,0 @@
libclipboard.a

View File

@ -1,18 +0,0 @@
cmake_minimum_required(VERSION 2.8)
include_directories(. include/clipboard)
add_definitions(-DLIB_COMPILE=1)
if(PLATFORM_WINDOWS)
set(CLIPBOARD_SRC src/clipboardWin32.c)
elseif(PLATFORM_MACOSX)
set(CMAKE_CXX_FLAGS "-fobjc-arc")
set(CLIPBOARD_SRC src/clipboardOSX.m)
else()
set(CLIPBOARD_SRC src/clipboardX11.c)
endif()
include_directories(${SDL_INCLUDE_DIR})
add_library(clipboard STATIC src/utf.c ${CLIPBOARD_SRC})

View File

@ -1,72 +0,0 @@
Warzone 2100 Source & Data
--------------------------
This document replaces the file "readme.txt" as present in the Warzone 2100 GPL
release of December 6th 2004.
1) These source and data files are provided as is with no guarantees:
- No assistance or support will be offered or given.
- Everything you will require to make a build of the game should be here. If
it isn't, you'll have to improvise.
- None of us here at Pivotal Games are in a position to be able to offer any
help with making this work.
2) Everything included (source code and data), as well as the not included
videos and music, is released under the terms of the GNU General Public
License, version 2 or (at your option) any later version.
Please be sure to read the entirety of this license, but the summary is that
you're free to do what you want with the source subject to making the full
source code freely available in the event of the distribution of new
binaries.
3) Following exception to the GPL is granted:
------
Linking Warzone 2100 statically or dynamically with other modules is making
a combined work based on Warzone 2100. Thus, the terms and conditions of
the GNU General Public License cover the whole combination.
In addition, as a special exception, the copyright holders of Warzone 2100
give you permission to combine Warzone 2100 with code included in the
standard release of libraries that are accessible, redistributable and
linkable free of charge. You may copy and distribute such a system
following the terms of the GNU GPL for Warzone 2100 and the licenses of the
other code concerned.
Note that people who make modified versions of Warzone 2100 are not
obligated to grant this special exception for their modified versions; it
is their choice whether to do so. The GNU General Public License gives
permission to release a modified version without this exception; this
exception also makes it possible to release a modified version which
carries forward this exception.
------
4) Permission is granted to use the name "Warzone 2100", the logos, stories,
texts and related materials.
5) Permission is granted to copy and distribute unaltered copies and/or images
of the original game discs in any medium, provided that they are distributed
free of charge and retain their original copyright and trademark notices.
Finally, the primary motivation for this release is for entertainment and
educational purposes. On the subject of the latter, don't be surprised to see
some pretty gnarly old-school C code in here; the game was a classic, but large
areas of the code aren't pretty; OO design and C++ evangelists beware! We
haven't spent any time cleaning the code or making it pretty - what you see is
what you're getting, warts n' all.
Thank you to Jonathan Kemp of Eidos Europe for permitting the release. Thanks to
Martin Severn for allowing to use his soundtrack. Thanks to Jason Walker for
helping to facilitate the release of the movies and sound tracks, as well as
clarifying the meaning of this license. Thanks also to Frank Lamboy for
assistance with the release and for campaigning along with many many others
over the years for the source to be made available.
The correspondence, online petitions and persistence made this possible. We were
constantly amazed at the community support for Warzone even after all this
time; it's nice to be able to give something back, assuming you can get it to
compile... ;-)
Original - 6th December 2004
Alex M - ex Pumpkin Studios (Eidos)
Amended - 10th June 2008
Jason W - Eidos

View File

@ -1,55 +0,0 @@
/*
This file is part of Warzone 2100.
Copyright (C) 2008 Freddie Witherden
Copyright (C) 2008-2009 Warzone Resurrection Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CLIPBOARD_H_
#define CLIPBOARD_H_
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Returns a copy of the text in the systems clipboard. Should the clipboard be
* empty, or populated with non-textual data NULL is returned. The character set
* of the returned is guaranteed to be UTF-8.
*
* It remains the responsibility of the caller to free() the string when
* finished with it.
*
* @return The textual contents of the clipboard (if any), otherwise NULL.
*/
char *widgetGetClipboardText(void);
/**
* Attempts to set the contents of the systems clipboard to text. The character
* set of text must be UTF-8.
*
* @param text The UTF-8 text to set the clipboard to.
* @return True if the contents were successfully set, false otherwise.
*/
bool widgetSetClipboardText(const char *text);
#ifdef __cplusplus
}
#endif
#endif /*CLIPBOARD_H_*/

View File

@ -1,100 +0,0 @@
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2009 Warzone Resurrection Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*! \file
* \brief Simple type definitions.
*/
#ifndef __INCLUDED_LIB_FRAMEWORK_TYPES_H__
#define __INCLUDED_LIB_FRAMEWORK_TYPES_H__
#include "wzglobal.h"
#ifdef HAVE_INTTYPES_H // defined WZ_C99
/* Compilers that have support for C99 have all values below defined in stdint.h */
# include <inttypes.h>
#else
// Defines C99 types for C99 incompatible compilers (e.g. MSVC)
#include <SDL_stdinc.h>
#ifndef WZ_CC_MINGW
# define INT8_MIN (-128)
# define INT16_MIN (-32767-1)
# define INT32_MIN (-2147483647-1)
# define INT8_MAX (127)
# define INT16_MAX (32767)
# define INT32_MAX (2147483647)
# define UINT8_MAX (255)
# define UINT16_MAX (65535)
# define UINT32_MAX (4294967295U)
#endif
#ifdef WZ_CC_MSVC
# define PRIu32 "u"
# define PRIu64 "I64u"
typedef SSIZE_T ssize_t;
#endif
#endif // WZ_C99
#include <limits.h>
#include <ctype.h>
/* Basic numeric types */
typedef uint8_t UBYTE;
typedef int8_t SBYTE;
typedef uint16_t UWORD;
typedef int16_t SWORD;
typedef uint32_t UDWORD;
typedef int32_t SDWORD;
/* Numeric size defines */
#define UBYTE_MAX UINT8_MAX
#define SBYTE_MIN INT8_MIN
#define SBYTE_MAX INT8_MAX
#define UWORD_MAX UINT16_MAX
#define SWORD_MIN INT16_MIN
#define SWORD_MAX INT16_MAX
#define UDWORD_MAX UINT32_MAX
#define SDWORD_MIN INT32_MIN
#define SDWORD_MAX INT32_MAX
// If we are C99 compatible, the "bool" macro will be defined in <stdbool.h> (as _Bool)
// C++ comes with an integrated bool type
#if defined(WZ_CXX98)
#elif defined(WZ_C99)
# include <stdbool.h>
#else
// Pretend we are C99 compatible (well, for the bool type then)
# ifndef bool
# define bool BOOL
# endif
# ifndef true
# define true (1)
# endif
# ifndef false
# define false (0)
# endif
# ifndef __bool_true_false_are_defined
# define __bool_true_false_are_defined (1)
# endif
#endif /* WZ_C99 */
#if !defined(WZ_OS_WIN)
typedef int BOOL;
#endif // WZ_OS_WIN
#endif // __INCLUDED_LIB_FRAMEWORK_TYPES_H__

View File

@ -1,115 +0,0 @@
/*
This file is part of Warzone 2100.
Copyright (C) 2007 Giel van Schijndel
Copyright (C) 2007-2009 Warzone Resurrection Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
$Revision: 9336 $
$Id: utf.h 9336 2010-01-18 19:10:17Z cypr $
$HeadURL: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk/lib/framework/utf.h $
*/
#ifndef __INCLUDE_LIB_FRAMEWORK_UTF8_H__
#define __INCLUDE_LIB_FRAMEWORK_UTF8_H__
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include "types.h"
#ifdef __cplusplus
extern "C"
{
#endif //__cplusplus
/** Used to store a UTF-32 character in
*/
typedef uint32_t utf_32_char;
/** Used to store a UTF-16 character in (this is <em>not</em> necessarily a
* full Unicode codepoint)
*/
typedef uint16_t utf_16_char;
/** Decodes a single Unicode character from the given UTF-16 string.
*
* \param utf16_char Points to a character string that should contain at
* least one valid UTF-16 character sequence.
* \param[out] next_char Will be modified to point to the first character
* following the UTF-16 character sequence.
*
* \return The Unicode character encoded as UTF-32 with native endianness.
*/
utf_32_char UTF16DecodeChar(const utf_16_char *utf16_char, const utf_16_char **next_char);
/** Decodes a single Unicode character from the given UTF-8 string.
*
* \param utf8_char Points to a character string that should contain at
* least one valid UTF-8 character sequence.
* \param[out] next_char Will be modified to point to the first character
* following the UTF-8 character sequence.
*
* \return The Unicode character encoded as UTF-32 with native endianness.
*/
utf_32_char UTF8DecodeChar(const char *utf8_char, const char **next_char);
/** Determines the amount of unicode codepoints in a UTF-8 encoded string
* \param utf8_string the UTF-8 encoded string to count
* \return the amount of codepoints found in the UTF-8 string
*/
size_t UTF8CharacterCount(const char *utf8_string);
size_t UTF16CharacterCount(const uint16_t *utf16);
/** Encodes a UTF-16 encoded unicode string to a UTF-8 encoded string
* \param unicode_string the UTF-16 encoded unicode string to encode into UTF-8
* \param[out] nbytes the number of bytes allocated, may be NULL
* \return a UTF-8 encoded unicode nul terminated string (use free() to deallocate it)
*/
char *UTF16toUTF8(const utf_16_char *unicode_string, size_t *nbytes);
/** Decodes a UTF-8 encoded string to a UTF-16 encoded string (native endianess)
* \param utf8_string a UTF-8 encoded nul terminated string
* \param[out] nbytes the number of bytes allocated, may be NULL
* \return a UTF-16 encoded unicode nul terminated string (use free() to deallocate it)
*/
utf_16_char *UTF8toUTF16(const char *utf8_string, size_t *nbytes);
char *UTF8CharacterAtOffset(const char *utf8_string, size_t index);
utf_16_char *UTF16CharacterAtOffset(const utf_16_char *utf16_string, size_t index);
/** Encodes a UTF-32 string to a UTF-8 encoded string
* \param unicode_string the UTF-32 string to encode into UTF-8
* \param[out] nbytes the number of bytes allocated, may be NULL
* \return a UTF-8 encoded unicode nul terminated string (use free() to deallocate it)
*/
char *UTF32toUTF8(const utf_32_char *unicode_string, size_t *nbytes);
/** Decodes a UTF-8 encoded string to a UTF-32 string
* \param utf8_string a UTF-8 encoded nul terminated string
* \param[out] nbytes the number of bytes allocated, may be NULL
* \return a UTF-32 nul terminated string (use free() to deallocate it)
*/
utf_32_char *UTF8toUTF32(const char *utf8_string, size_t *nbytes);
/** Returns number of characters, not including terminating nul. */
size_t utf32len(const utf_32_char *unicode_string);
#ifdef __cplusplus
}
#endif //__cplusplus
#endif // __INCLUDE_LIB_FRAMEWORK_UTF8_H__

View File

@ -1,614 +0,0 @@
/*
This file is part of Warzone 2100.
Copyright (C) 1992-2007 Trolltech ASA.
Copyright (C) 2005-2009 Warzone Resurrection Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*! \file wzglobal.h
* \brief Platform detection, workarounds and compat fixes
*
* OS and CC detection code shamelessly stolen from Qt4 (Qt/qglobal.h) by Dennis.
* This has been stripped down, feel free to add checks as you need them.
*/
#ifndef WZGLOBAL_H
#define WZGLOBAL_H
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
#if defined(HAVE_CONFIG_H)
# undef _XOPEN_SOURCE
# include "config.h"
#elif defined(__MACOSX__)
# include "config-macosx.h"
#endif
/* ---- Platform detection ---- */
/*
The operating system, must be one of: (WZ_OS_x)
DARWIN - Darwin OS (synonym for WZ_OS_MAC)
OS2 - OS/2
OS2EMX - XFree86 on OS/2 (not PM)
WIN32 - Win32 (Windows 95/98/ME and Windows NT/2000/XP)
CYGWIN - Cygwin
SOLARIS - Sun Solaris
HPUX - HP-UX
ULTRIX - DEC Ultrix
LINUX - Linux
FREEBSD - FreeBSD
GNU_kFREEBSD - GNU/kFreeBSD
NETBSD - NetBSD
OPENBSD - OpenBSD
BSDI - BSD/OS
IRIX - SGI Irix
OSF - HP Tru64 UNIX
SCO - SCO OpenServer 5
UNIXWARE - UnixWare 7, Open UNIX 8
AIX - AIX
HURD - GNU Hurd
DGUX - DG/UX
RELIANT - Reliant UNIX
DYNIX - DYNIX/ptx
QNX - QNX
QNX6 - QNX RTP 6.1
LYNX - LynxOS
BSD4 - Any BSD 4.4 system
UNIX - Any UNIX BSD/SYSV system
*/
#if defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))
# define WZ_OS_DARWIN
# define WZ_OS_BSD4
# ifdef __LP64__
# define WZ_OS_DARWIN64
# else
# define WZ_OS_DARWIN32
# endif
#elif defined(__CYGWIN__)
# define WZ_OS_CYGWIN
#elif defined(__OS2__)
# if defined(__EMX__)
# define WZ_OS_OS2EMX
# else
# define WZ_OS_OS2
# endif
#elif !defined(SAG_COM) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
# define WZ_OS_WIN32
# define WZ_OS_WIN64
#elif !defined(SAG_COM) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__))
# define WZ_OS_WIN32
#elif defined(__MWERKS__) && defined(__INTEL__)
# define WZ_OS_WIN32
#elif defined(__sun) || defined(sun)
# define WZ_OS_SOLARIS
#elif defined(hpux) || defined(__hpux)
# define WZ_OS_HPUX
#elif defined(__ultrix) || defined(ultrix)
# define WZ_OS_ULTRIX
#elif defined(sinix)
# define WZ_OS_RELIANT
#elif defined(__linux__) || defined(__linux)
# define WZ_OS_LINUX
#elif defined(__FreeBSD__) || defined(__DragonFly__)
# define WZ_OS_FREEBSD
# define WZ_OS_BSD4
#elif defined(__FreeBSD_kernel__) && !defined(__FreeBSD__)
/* We're running a non-FreeBSD system with a FreeBSD kernel. Find out what C
* library we're using to detect the system we're running on. */
# include <stdlib.h>
# if defined(__GLIBC__)
/* We're running GNU/kFreeBSD */
# define WZ_OS_GNU_kFREEBSD
# endif
#elif defined(__NetBSD__)
# define WZ_OS_NETBSD
# define WZ_OS_BSD4
#elif defined(__OpenBSD__)
# define WZ_OS_OPENBSD
# define WZ_OS_BSD4
#elif defined(__bsdi__)
# define WZ_OS_BSDI
# define WZ_OS_BSD4
#elif defined(__sgi)
# define WZ_OS_IRIX
#elif defined(__osf__)
# define WZ_OS_OSF
#elif defined(_AIX)
# define WZ_OS_AIX
#elif defined(__Lynx__)
# define WZ_OS_LYNX
#elif defined(__GNU__)
# define WZ_OS_HURD
#elif defined(__DGUX__)
# define WZ_OS_DGUX
#elif defined(__QNXNTO__)
# define WZ_OS_QNX6
#elif defined(__QNX__)
# define WZ_OS_QNX
#elif defined(_SEQUENT_)
# define WZ_OS_DYNIX
#elif defined(_SCO_DS) /* SCO OpenServer 5 + GCC */
# define WZ_OS_SCO
#elif defined(__USLC__) /* all SCO platforms + UDK or OUDK */
# define WZ_OS_UNIXWARE
#elif defined(__svr4__) && defined(i386) /* Open UNIX 8 + GCC */
# define WZ_OS_UNIXWARE
#elif defined(__INTEGRITY)
# define WZ_OS_INTEGRITY
#elif defined(__MAKEDEPEND__)
#else
# error "Warzone has not been tested on this OS. Please contact warzone-dev@gna.org"
#endif /* WZ_OS_x */
#if defined(WZ_OS_WIN32) || defined(WZ_OS_WIN64)
# define WZ_OS_WIN
#endif /* WZ_OS_WIN32 */
#if defined(WZ_OS_DARWIN)
# define WZ_OS_MAC /* WZ_OS_MAC is mostly for compatibility, but also more clear */
# define WZ_OS_MACX /* WZ_OS_MACX is only for compatibility.*/
# if defined(WZ_OS_DARWIN64)
# define WZ_OS_MAC64
# elif defined(WZ_OS_DARWIN32)
# define WZ_OS_MAC32
# endif
#endif /* WZ_OS_DARWIN */
#if defined(WZ_OS_MSDOS) || defined(WZ_OS_OS2) || defined(WZ_OS_WIN)
# undef WZ_OS_UNIX
#elif !defined(WZ_OS_UNIX)
# define WZ_OS_UNIX
#endif /* WZ_OS_* */
/*
The compiler, must be one of: (WZ_CC_x)
MSVC - Microsoft Visual C/C++, Intel C++ for Windows
GNU - GNU C++
CLANG - Clang LLVM
INTEL - Intel C++ for Linux, Intel C++ for Windows
TINYC - Fabrice Bellard's Tiny C Compiler
Should be sorted most to least authoritative.
*/
#if defined(_MSC_VER)
# define WZ_CC_MSVC
/* All ISO C89 compliant compilers _should_ define the macro __STDC__, MSVC
* however is known _not_ to do this, so work around that here. */
# if !defined(__STDC__)
# define __STDC__ 1
# endif
/* Visual C++.Net issues for _MSC_VER >= 1300 */
# if _MSC_VER >= 1300
# define WZ_CC_MSVC_NET
# endif
/* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */
# if defined(__INTEL_COMPILER)
# define WZ_CC_INTEL
# endif
/* x64 does not support mmx intrinsics on windows */
# if (defined(ZS_OS_WIN64) && defined(_M_X64))
# undef ZS_HAVE_SSE
# undef ZS_HAVE_SSE2
# undef ZS_HAVE_MMX
# undef ZS_HAVE_3DNOW
# endif
#elif defined(__GNUC__)
# define WZ_CC_GNU
# if defined(__MINGW32__)
# define WZ_CC_MINGW
# endif
# if defined(__INTEL_COMPILER)
/* Intel C++ also masquerades as GCC 3.2.0 */
# define WZ_CC_INTEL
# endif
# if defined(__llvm__)
# define WZ_CC_LLVM
# endif
# if defined(__clang__)
# define WZ_CC_CLANG
# endif
/* Clang may not always masquerade as gcc */
#elif defined(__clang__)
# define WZ_CC_CLANG
# define WZ_CC_LLVM
#elif defined(__TINYC__)
# define WZ_CC_TINYC
#else
# error "Warzone has not been tested on this compiler. Please contact warzone-dev@gna.org"
#endif /* WZ_CC_x */
/*
The window system, must be one of: (WZ_WS_x)
MACX - Mac OS X
WIN32 - Windows
X11 - X Window System
QNX - QNX
*/
#if defined(_WIN32_X11_)
# define WZ_WS_X11
#elif defined(WZ_OS_WIN32)
# define WZ_WS_WIN32
# if defined(WZ_OS_WIN64)
# define WZ_WS_WIN64
# endif
#elif defined(WZ_OS_MAC)
# define WZ_WS_MAC
# define WZ_WS_MACX
# if defined(WZ_OS_MAC64)
# define WZ_WS_MAC64
# elif defined(WZ_OS_MAC32)
# define WZ_WS_MAC32
# endif
#elif defined(WZ_OS_QNX)
# define WZ_WS_QNX
#elif defined(WZ_OS_UNIX)
# define WZ_WS_X11
#else
# error "Warzone has not been tested on this window system. Please contact warzone-dev@gna.org"
#endif /* WZ_WS_x */
#if defined(WZ_WS_WIN16) || defined(WZ_WS_WIN32)
# define WZ_WS_WIN
#endif
/*
The supported C standard, must be one of: (WZ_Cxx)
99 - ISO/IEC 9899:1999 / C99
*/
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
# define WZ_C99
#endif /* WZ_Cxx */
/*
The supported C++ standard, must be one of: (WZ_CXXxx)
98 - ISO/IEC 14882:1998 / C++98
*/
#if defined(__cplusplus)
# define WZ_CXX98
#endif /* WZ_CXXxx */
/*
Convenience macros to test the versions of gcc.
Copied from glibc's features.h.
*/
#if defined(WZ_CC_GNU) && defined __GNUC__ && defined __GNUC_MINOR__
# define WZ_CC_GNU_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
# define WZ_CC_GNU_PREREQ(maj, min) 0
#endif
/*
Convenience macros to test the versions of icc.
*/
#if defined(WZ_CC_INTEL) && defined __ICC
# define WZ_CC_INTEL_PREREQ(maj, min) \
((__ICC) >= ((maj) * 100) + (min))
#else
# define WZ_CC_INTEL_PREREQ(maj, min) 0
#endif
/* ---- Declaration attributes ---- */
/*!
* \def WZ_DECL_DEPRECATED
*
* The WZ_DECL_DEPRECATED macro can be used to trigger compile-time warnings
* with newer compilers when deprecated functions are used.
*
* For non-inline functions, the macro gets inserted at front of the
* function declaration, right before the return type:
*
* \code
* WZ_DECL_DEPRECATED void deprecatedFunctionA();
* WZ_DECL_DEPRECATED int deprecatedFunctionB() const;
* \endcode
*
* For functions which are implemented inline,
* the WZ_DECL_DEPRECATED macro is inserted at the front, right before the return
* type, but after "static", "inline" or "virtual":
*
* \code
* WZ_DECL_DEPRECATED void deprecatedInlineFunctionA() { .. }
* virtual WZ_DECL_DEPRECATED int deprecatedInlineFunctionB() { .. }
* static WZ_DECL_DEPRECATED bool deprecatedInlineFunctionC() { .. }
* inline WZ_DECL_DEPRECATED bool deprecatedInlineFunctionD() { .. }
* \endcode
*
* You can also mark whole structs or classes as deprecated, by inserting the
* WZ_DECL_DEPRECATED macro after the struct/class keyword, but before the
* name of the struct/class:
*
* \code
* class WZ_DECL_DEPRECATED DeprecatedClass { };
* struct WZ_DECL_DEPRECATED DeprecatedStruct { };
* \endcode
*
* \note
* Description copied from KDE4, code copied from Qt4.
*
*/
#if WZ_CC_GNU_PREREQ(3,2) || WZ_CC_INTEL_PREREQ(10,0)
# define WZ_DECL_DEPRECATED __attribute__((__deprecated__))
#elif defined(WZ_CC_MSVC) && defined(WZ_CC_MSVC_NET)
# define WZ_DECL_DEPRECATED __declspec(deprecated)
#else
# define WZ_DECL_DEPRECATED
#endif
/*! \def WZ_DECL_FORMAT
* GCC: "The format attribute specifies that a function takes printf, scanf, strftime or strfmon
* style arguments which should be type-checked against a format string."
*/
#if WZ_CC_GNU_PREREQ(2,5) && !defined(WZ_CC_INTEL)
# define WZ_DECL_FORMAT(archetype, string_index, first_to_check) \
__attribute__((__format__(archetype, string_index, first_to_check)))
#else
# define WZ_DECL_FORMAT(archetype, string_index, first_to_check)
#endif
/*!
* \def WZ_DECL_NORETURN
* "A few standard library functions, such as abort and exit, cannot return. GCC knows this
* automatically. Some programs define their own functions that never return.
* You can declare them noreturn to tell the compiler this fact."
*/
#if WZ_CC_GNU_PREREQ(2,5) && !defined(WZ_CC_INTEL)
# define WZ_DECL_NORETURN __attribute__((__noreturn__))
#elif defined(WZ_CC_MSVC)
# define WZ_DECL_NORETURN __declspec(noreturn)
#else
# define WZ_DECL_NORETURN
#endif
/*!
* \def WZ_DECL_CONST
* GCC: "Many functions do not examine any values except their arguments, and have no effects
* except the return value. Basically this is just slightly more strict class than
* the pure attribute below, since function is not allowed to read global memory."
*/
#if WZ_CC_GNU_PREREQ(2,5) && !defined(WZ_CC_INTEL)
# define WZ_DECL_CONST __attribute__((__const__,__warn_unused_result__))
#else
# define WZ_DECL_CONST
#endif
/*!
* \def WZ_DECL_PURE
* GCC: "Many functions have no effects except the return value and their return value depends
* only on the parameters and/or global variables. Such a function can be subject to
* common subexpression elimination and loop optimization just as an arithmetic operator
* would be."
*/
#if WZ_CC_GNU_PREREQ(2,96) && !defined(WZ_CC_INTEL)
# define WZ_DECL_PURE __attribute__((__pure__))
#else
# define WZ_DECL_PURE
#endif
/*!
* \def WZ_DECL_UNUSED
* GCC: "This attribute, attached to a function, means that the function is meant to be possibly
* unused. GCC will not produce a warning for this function."
*/
#if WZ_CC_GNU_PREREQ(3,2) || WZ_CC_INTEL_PREREQ(10,0)
# define WZ_DECL_UNUSED __attribute__((__unused__))
#else
# define WZ_DECL_UNUSED
#endif
/*!
* \def WZ_DECL_WARN_UNUSED_RESULT
* GCC: "The warn_unused_result attribute causes a warning to be emitted if a caller of the
* function with this attribute does not use its return value. This is useful for
* functions where not checking the result is either a security problem or always a bug,
* such as realloc."
*/
#if defined(WZ_CC_GNU) && !defined(WZ_CC_INTEL)
# define WZ_DECL_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
#else
# define WZ_DECL_WARN_UNUSED_RESULT
#endif
/*! \def WZ_DECL_MAY_ALIAS
* GCC: "Accesses to objects with types with this attribute are not subjected to type-based alias
* analysis, but are instead assumed to be able to alias any other type of objects,
* just like the char type. See -fstrict-aliasing for more information on aliasing issues."
*/
#if WZ_CC_GNU_PREREQ(3,3) && !defined(WZ_CC_INTEL)
# define WZ_DECL_MAY_ALIAS __attribute__((__may_alias__))
#else
# define WZ_DECL_MAY_ALIAS
#endif
/*!
* \def WZ_DECL_RESTRICT
* Apply the "restrict" keyword found in the C99 revision of the standard.
* The compiler may assume that the memory referenced by a "restrict" pointer is not aliased
* by any other pointer. Thus this forms the opposite of WZ_DECL_MAY_ALIAS.
*/
#if defined(WZ_C99) && WZ_CC_GNU_PREREQ(4,1) && !defined(WZ_CC_INTEL)
# define WZ_DECL_RESTRICT restrict
#elif defined(WZ_CC_MSVC) && defined(WZ_CC_MSVC_NET)
# define WZ_DECL_RESTRICT __restrict
#else
# define WZ_DECL_RESTRICT
#endif
/*! \def WZ_DECL_THREAD
* Declares a variable to be local to the running thread, and not shared between threads.
*/
#if defined(WZ_CC_GNU) || defined(WZ_CC_INTEL)
# define WZ_DECL_THREAD __thread
#elif defined(WZ_CC_MSVC)
# define WZ_DECL_THREAD __declspec(thread)
#else
# error "Thread local storage attribute required"
#endif
/*! \def WZ_ASSERT_STATIC_STRING
* Asserts that the given string is statically allocated.
*/
#if defined(__cplusplus)
# include <typeinfo>
# define WZ_ASSERT_STATIC_STRING(_var) assert(typeid(_var) == typeid(char[sizeof(_var)]))
#elif defined(WZ_CC_GNU) || defined(WZ_CC_INTEL)
# define WZ_ASSERT_STATIC_STRING(_var) STATIC_ASSERT(__builtin_types_compatible_p(typeof(_var), char[]))
#else
# define WZ_ASSERT_STATIC_STRING(_var) (void)(_var)
#endif
/*! \def WZ_ASSERT_ARRAY
* Asserts that the given variable is a (statically sized) array, not just a pointer.
*/
#if defined(__cplusplus)
# define WZ_ASSERT_ARRAY_EXPR(a) 0
#elif defined(WZ_CC_GNU) || defined(WZ_CC_INTEL)
/* &a[0] degrades to a pointer: a different type from an array */
# define WZ_ASSERT_ARRAY_EXPR(a) STATIC_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(a), typeof(&(a)[0])))
#else
# define WZ_ASSERT_ARRAY_EXPR(a) 0
#endif
#define WZ_ASSERT_ARRAY(a) (void)WZ_ASSERT_ARRAY_EXPR(a)
/* ---- Platform specific setup ---- */
#if defined(WZ_OS_WIN)
# if defined(WZ_CC_MINGW)
# include <unistd.h>
# include <sys/param.h>
# include <w32api.h>
# define _WIN32_IE IE5
// Required for alloca
# include <malloc.h>
# elif defined(WZ_CC_MSVC)
# if defined(_DEBUG)
# define DEBUG
# define _CRTDBG_MAP_ALLOC
# include <stdlib.h>
# include <crtdbg.h>
# endif /* _DEBUG */
# endif /* WZ_CC_* */
# define WIN32_LEAN_AND_MEAN
# define WIN32_EXTRA_LEAN
# undef NOMINMAX
# define NOMINMAX 1 // disable the min / max macros
# include <windows.h>
# if defined(WZ_CC_MSVC)
// notify people we are disabling these warning messages.
# pragma message (" *** Warnings 4018,4100,4127,4204,4244,4267,4389 have been squelched. ***")
# pragma warning (disable : 4018) // Shut up: '>' : signed/unsigned mismatch
# pragma warning (disable : 4100) // Shut up: unreferenced formal parameter (FIXME)
# pragma warning (disable : 4127) // Shut up: conditional expression is constant (eg. "while(0)")
# pragma warning (disable : 4204) // Shut up: non-constant aggregate initializer
# pragma warning (disable : 4244) // Shut up: conversion from 'float' to 'int', possible loss of data
# pragma warning (disable : 4267) // Shut up: conversion from 'size_t' to 'type', possible loss of data
# pragma warning (disable : 4389) // Shut up: '==' : signed/unsigned mismatch
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
# define inline __inline
# define alloca _alloca
# define fileno _fileno
# define isnan _isnan
# define isfinite _finite
# define PATH_MAX MAX_PATH
# endif /* WZ_CC_MSVC */
/* Make sure that PATH_MAX is large enough to use as the size for return
* buffers for Windows API calls
*/
# if (PATH_MAX < MAX_PATH)
# undef PATH_MAX
# define PATH_MAX MAX_PATH
# endif
#elif defined(WZ_OS_UNIX)
# include <unistd.h>
# if defined(HAVE_ALLOCA_H)
# include <alloca.h>
# endif
#endif /* WZ_OS_* */
// Define PATH_MAX for systems that don't have it, like Hurd
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
#if !defined(WZ_C99) && !defined(va_copy)
/**
* Implements the interface of the C99 macro va_copy such that we can use it on
* non-C99 systems as well.
*
* This implementation assumes that va_list is just a pointer to the stack
* frame of the variadic function. This is by far the most common setup, though
* it might not always work.
*/
# define va_copy(dest, src) (void)((dest) = (src))
#endif // !WZ_C99 && !va_copy
#endif /* WZGLOBAL_H */

View File

@ -1 +0,0 @@
Source code in this directory was taken from Warzone2100 source. Please read COPING.README for licence or visit https://github.com/cybersphinx/wzgraphicsmods for more information.

View File

@ -1,24 +0,0 @@
#include <stdbool.h>
#include <string.h>
#include <AppKit/AppKit.h>
char *widgetGetClipboardText()
{
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSString *myString = [pasteboard stringForType:NSPasteboardTypeString];
if (myString == nil || [myString length] == 0) return NULL;
return strdup([myString UTF8String]);
}
bool widgetSetClipboardText(const char *text)
{
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
NSString *stringFromUTFString = [[NSString alloc] initWithUTF8String:text];
return [pasteboard setString:stringFromUTFString forType:NSStringPboardType];
}

View File

@ -1,160 +0,0 @@
/*
This file is part of Warzone 2100.
Copyright (C) 2008 Freddie Witherden
Copyright (C) 2008-2009 Warzone Resurrection Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "utf.h"
// Defines most macros and types from <stdbool.h> and <stdint.h>
#include "types.h"
char *widgetGetClipboardText()
{
uint16_t *clipboardText;
char *ourText = NULL;
// If there is any text on the clipboard, open it
if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL))
{
// Get any text on the clipboard
HANDLE hClipboardData = GetClipboardData(CF_UNICODETEXT);
// If the handle is valid, fetch the text
if (hClipboardData)
{
// Get the text
clipboardText = GlobalLock(hClipboardData);
// So long as we got something
if (clipboardText)
{
int i, j;
// Convert it to UTF-8 (from UTF-16)
ourText = UTF16toUTF8(clipboardText, NULL);
// Unlock the text
GlobalUnlock(hClipboardData);
// Strip any '\r' from the text
for (i = j = 0; ourText[i]; i++)
{
if (ourText[i] != '\r')
{
ourText[j++] = ourText[i];
}
}
// NUL terminate
ourText[j] = '\0';
}
}
// Close the clipboard
CloseClipboard();
}
return ourText;
}
bool widgetSetClipboardText(const char *text)
{
bool ret = false;
// Copy of text with \n => \r\n
char *newText;
// UTF-16 version of newText
uint16_t *utf16NewText;
// Number of bytes utf16NewText is in size
size_t nbytes;
int count, i, j;
// Get the number of '\n' characters in the text
for (i = count = 0; text[i]; i++)
{
if (text[i] == '\n')
{
count++;
}
}
// Allocate enough space for the \r\n string
newText = malloc(strlen(text) + count + 1);
// Copy the string, converting \n to \r\n
for (i = j = 0; text[i]; i++, j++)
{
// If the character is a newline prepend a \r
if (text[i] == '\n')
{
newText[j++] = '\r';
}
// Copy the character (\n or otherwise)
newText[j] = text[i];
}
// NUL terminate
newText[j] = '\0';
// Convert to UTF-16
utf16NewText = UTF8toUTF16(newText, &nbytes);
// Open the clipboard
if (OpenClipboard(NULL))
{
HGLOBAL hGlobal;
uint16_t *clipboardText;
// Empty it (which also transfers ownership of it to ourself)
EmptyClipboard();
// Allocate global space for the text
hGlobal = GlobalAlloc(GMEM_MOVEABLE, nbytes);
// Lock the newly allocated memory
clipboardText = GlobalLock(hGlobal);
// Copy the text
memcpy(clipboardText, utf16NewText, nbytes);
// Unlock the memory (must come before CloseClipboard())
GlobalUnlock(hGlobal);
// Place the handle on the clipboard
if (SetClipboardData(CF_UNICODETEXT, hGlobal))
{
// We were successful
ret = true;
}
// Close the clipboard
CloseClipboard();
}
// Release the malloc-ed strings
free(newText);
free(utf16NewText);
return ret;
}

View File

@ -1,293 +0,0 @@
/*
This file is part of Warzone 2100.
Copyright (C) 2008 Freddie Witherden
Copyright (C) 2008-2009 Warzone Resurrection Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Something wicked this way comes...
* Documentation/reference:
* http://svr-www.eng.cam.ac.uk/~er258/code/dist/x_clipboard/paste.cc
*/
#include <stdbool.h>
#include <assert.h>
#include <SDL_syswm.h>
#include <SDL.h>
static SDL_SysWMinfo info;
// Atoms
static Atom XA_CLIPBOARD;
static Atom XA_COMPOUND_TEXT;
static Atom XA_UTF8_STRING;
static Atom XA_TARGETS;
/**
* Filters through SDL_Events searching for clipboard requests from the X
* server.
*
* @param evt The event to filter.
*/
static int widgetClipboardFilterX11(const SDL_Event *evt)
{
// We are only interested in window manager events
if (evt->type == SDL_SYSWMEVENT)
{
XEvent xevent = evt->syswm.msg->event.xevent;
// See if the event is a selection/clipboard request
if (xevent.type == SelectionRequest)
{
// Get the request in question
XSelectionRequestEvent *request = &xevent.xselectionrequest;
// Generate a reply to the selection request
XSelectionEvent reply;
reply.type = SelectionNotify;
reply.serial = xevent.xany.send_event;
reply.send_event = True;
reply.display = info.info.x11.display;
reply.requestor = request->requestor;
reply.selection = request->selection;
reply.property = request->property;
reply.target = None;
reply.time = request->time;
// They want to know what we can provide/offer
if (request->target == XA_TARGETS)
{
Atom possibleTargets[] =
{
XA_STRING,
XA_UTF8_STRING,
XA_COMPOUND_TEXT
};
XChangeProperty(info.info.x11.display, request->requestor,
request->property, XA_ATOM, 32, PropModeReplace,
(unsigned char *) possibleTargets, 3);
}
// They want a string (all we can provide)
else if (request->target == XA_STRING
|| request->target == XA_UTF8_STRING
|| request->target == XA_COMPOUND_TEXT)
{
int len;
char *xdata = XFetchBytes(info.info.x11.display, &len);
XChangeProperty(info.info.x11.display, request->requestor,
request->property, request->target, 8,
PropModeReplace, (unsigned char *) xdata,
len);
XFree(xdata);
}
else
{
// Did not have what they wanted, so no property set
reply.property = None;
}
// Dispatch the event
XSendEvent(request->display, request->requestor, 0, NoEventMask,
(XEvent *) &reply);
XSync(info.info.x11.display, False);
}
}
return 1;
}
static void widgetInitialiseClipboardX11()
{
static bool initialised = false;
if (!initialised)
{
// Get the window manager information
SDL_GetWMInfo(&info);
// Ensure we're running under X11
assert(info.subsystem == SDL_SYSWM_X11);
// Register the event filter
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
SDL_SetEventFilter(widgetClipboardFilterX11);
// Lock the connection to the X server
info.info.x11.lock_func();
// Get the clipboard atom (it is not defined by default)
XA_CLIPBOARD = XInternAtom(info.info.x11.display, "CLIPBOARD", True);
// Get the compound text type atom
XA_COMPOUND_TEXT = XInternAtom(info.info.x11.display, "COMPOUND_TEXT",
True);
// UTF-8 string atom
XA_UTF8_STRING = XInternAtom(info.info.x11.display, "UTF8_STRING",
True);
// TARGETS atom
XA_TARGETS = XInternAtom(info.info.x11.display, "TARGETS", True);
// Unlock the connection
info.info.x11.unlock_func();
// We are initialised
initialised = true;
}
}
char *widgetGetClipboardText()
{
char *text = NULL;
unsigned char *data = NULL;
Atom type;
int format, result;
unsigned long len, bytesLeft, dummy;
Window selectionOwner;
// Make sure we are initialised
widgetInitialiseClipboardX11();
// Lock the connection
info.info.x11.lock_func();
// Get the owner of the clipboard selection
selectionOwner = XGetSelectionOwner(info.info.x11.display, XA_CLIPBOARD);
// If there is a selection (and therefore owner) fetch it
if (selectionOwner != None)
{
SDL_Event event;
bool response = false;
/*
* Ask the window whom current owns the clipboard to convert it to an
* XA_UTF8_STRING and place it into the XA_CLIPBOARD property of our
* window.
*/
XConvertSelection(info.info.x11.display, XA_CLIPBOARD, XA_UTF8_STRING,
XA_CLIPBOARD, info.info.x11.window, CurrentTime);
XFlush(info.info.x11.display);
/*
* We now need to wait for a response from the window that owns the
* clipboard.
*/
// Unlock the connection so that the SDL event loop may function
info.info.x11.unlock_func();
while (!response)
{
// Wait for an event
SDL_WaitEvent(&event);
// If the event is a window manager event
if (event.type == SDL_SYSWMEVENT)
{
XEvent xevent = event.syswm.msg->event.xevent;
// See if it is a response to our request
if (xevent.type == SelectionNotify
&& xevent.xselection.requestor == info.info.x11.window)
{
response = true;
}
}
}
// Lock the connection once again
info.info.x11.lock_func();
// See how much data is there
XGetWindowProperty(info.info.x11.display, info.info.x11.window,
XA_CLIPBOARD, 0, 0, False, AnyPropertyType, &type,
&format, &len, &bytesLeft, &data);
// If any 0-length data was returned, free it
if (data)
{
XFree(data);
data = NULL;
}
// If there is any data
if (bytesLeft)
{
// Fetch the data
result = XGetWindowProperty(info.info.x11.display,
info.info.x11.window, XA_CLIPBOARD, 0,
bytesLeft, False, AnyPropertyType,
&type, &format, &len, &dummy, &data);
// If we got some data, duplicate it
if (result == Success)
{
text = strdup((char *) data);
XFree(data);
}
}
// Delete the property now that we are finished with it
XDeleteProperty(info.info.x11.display, info.info.x11.window,
XA_CLIPBOARD);
}
// Unlock the connection
info.info.x11.unlock_func();
return text;
}
bool widgetSetClipboardText(const char *text)
{
Window selectionOwner;
// Make sure we are initialised
widgetInitialiseClipboardX11();
// Lock the connection
info.info.x11.lock_func();
// Copy the text into the root windows cut buffer (for Xterm compatibility)
XStoreBytes(info.info.x11.display, text, strlen(text) + 1);
// Set ourself as the owner of the CLIPBOARD atom
XSetSelectionOwner(info.info.x11.display, XA_CLIPBOARD,
info.info.x11.window, CurrentTime);
// Check if we acquired ownership or not
selectionOwner = XGetSelectionOwner(info.info.x11.display, XA_CLIPBOARD);
// We got ownership
if (selectionOwner == info.info.x11.window)
{
info.info.x11.unlock_func();
return true;
}
// We did not get ownership
else
{
info.info.x11.unlock_func();
return false;
}
}

View File

@ -1,530 +0,0 @@
/*
This file is part of Warzone 2100.
Copyright (C) 2007 Giel van Schijndel
Copyright (C) 2007-2009 Warzone Resurrection Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
$Revision: 9101 $
$Id: utf.c 9101 2010-01-10 13:11:55Z zarelsl $
$HeadURL: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk/lib/framework/utf.c $
*/
/** \file
* Functions to convert between different Unicode Transformation Formats (UTF for short)
*/
#include "utf.h"
#include <assert.h>
#include <stdlib.h>
#if defined(LIB_COMPILE)
# define ASSERT(expr, ...) (assert(expr))
# define debug(part, ...) ((void)0)
#else
# include "debug.h"
#endif
// Assert that non-starting octets are of the form 10xxxxxx
#define ASSERT_NON_START_OCTET(octet) \
assert((octet & 0xC0) == 0x80 && "invalid non-start UTF-8 octet")
// Assert that starting octets are either of the form 0xxxxxxx (ASCII) or 11xxxxxx
#define ASSERT_START_OCTECT(octet) \
assert((octet & 0x80) == 0x00 || (octet & 0xC0) == 0xC0 || !"invalid starting UTF-8 octet")
// Assert that hexadect (16bit sequence) 1 of UTF-16 surrogate pair sequences are of the form 110110XXXXXXXXXX
#define ASSERT_START_HEXADECT(hexadect) \
assert(((hexadect) & 0xD800) == 0xD800 && "invalid first UTF-16 hexadect")
// Assert that hexadect (16bit sequence) 2 of UTF-16 surrogate pair sequences are of the form 110111XXXXXXXXXX
#define ASSERT_FINAL_HEXADECT(hexadect) \
assert(((hexadect) & 0xDC00) == 0xDC00 && "invalid first UTF-16 hexadect")
utf_32_char UTF8DecodeChar(const char *utf8_char, const char **next_char)
{
utf_32_char decoded = '\0';
*next_char = utf8_char;
ASSERT_START_OCTECT(*utf8_char);
// first octect: 0xxxxxxx: 7 bit (ASCII)
if ((*utf8_char & 0x80) == 0x00)
{
// 1 byte long encoding
decoded = *((*next_char)++);
}
// first octect: 110xxxxx: 11 bit
else if ((*utf8_char & 0xe0) == 0xc0)
{
// 2 byte long encoding
ASSERT_NON_START_OCTET(utf8_char[1]);
decoded = (*((*next_char)++) & 0x1f) << 6;
decoded |= (*((*next_char)++) & 0x3f) << 0;
}
// first octect: 1110xxxx: 16 bit
else if ((*utf8_char & 0xf0) == 0xe0)
{
// 3 byte long encoding
ASSERT_NON_START_OCTET(utf8_char[1]);
ASSERT_NON_START_OCTET(utf8_char[2]);
decoded = (*((*next_char)++) & 0x0f) << 12;
decoded |= (*((*next_char)++) & 0x3f) << 6;
decoded |= (*((*next_char)++) & 0x3f) << 0;
}
// first octect: 11110xxx: 21 bit
else if ((*utf8_char & 0xf8) == 0xf0)
{
// 4 byte long encoding
ASSERT_NON_START_OCTET(utf8_char[1]);
ASSERT_NON_START_OCTET(utf8_char[2]);
ASSERT_NON_START_OCTET(utf8_char[3]);
decoded = (*((*next_char)++) & 0x07) << 18;
decoded |= (*((*next_char)++) & 0x3f) << 12;
decoded |= (*((*next_char)++) & 0x3f) << 6;
decoded |= (*((*next_char)++) & 0x3f) << 0;
}
else
{
// apparently this character uses more than 21 bit
// this decoder is not developed to cope with those
// characters so error out
ASSERT(!"out-of-range UTF-8 character", "this UTF-8 character is too large (> 21bits) for this UTF-8 decoder and too large to be a valid Unicode codepoint");
}
return decoded;
}
size_t UTF8CharacterCount(const char *utf8_string)
{
size_t length = 0;
while (*utf8_string != '\0')
{
UTF8DecodeChar(utf8_string, &utf8_string);
++length;
}
return length;
}
size_t UTF16CharacterCount(const uint16_t *utf16)
{
size_t length = 0;
while (*utf16)
{
UTF16DecodeChar(utf16, &utf16);
++length;
}
return length;
}
static size_t unicode_utf8_char_length(const utf_32_char unicode_char)
{
// an ASCII character, which uses 7 bit at most, which is one byte in UTF-8
if (unicode_char < 0x00000080)
return 1; // stores 7 bits
else if (unicode_char < 0x00000800)
return 2; // stores 11 bits
else if (unicode_char < 0x00010000)
return 3; // stores 16 bits
/* This encoder can deal with < 0x00200000, but Unicode only ranges
* from 0x0 to 0x10FFFF. Thus we don't accept anything else.
*/
else if (unicode_char < 0x00110000)
return 4; // stores 21 bits
/* Apparently this character lies outside the 0x0 - 0x10FFFF
* Unicode range, so don't accept it.
*/
ASSERT(!"out-of-range Unicode codepoint", "This Unicode codepoint is too large (%u > 0x10FFFF) to be a valid Unicode codepoint", (unsigned int)unicode_char);
// Dummy value to prevent warnings about missing return from function
return 0;
}
char *UTF8CharacterAtOffset(const char *utf8_string, size_t index)
{
while (*utf8_string != '\0'
&& index != 0)
{
// Move to the next character
UTF8DecodeChar(utf8_string, &utf8_string);
--index;
}
if (*utf8_string == '\0')
return NULL;
return (char*)utf8_string;
}
/** Encodes a single Unicode character to a UTF-8 encoded string.
*
* \param unicode_char A UTF-32 encoded Unicode codepoint that will be encoded
* into UTF-8. This should be a valid Unicode codepoint
* (i.e. ranging from 0x0 to 0x10FFFF inclusive).
* \param out_char Points to the position in a buffer where the UTF-8
* encoded character can be stored.
*
* \return A pointer pointing to the first byte <em>after</em> the encoded
* UTF-8 sequence. This can be used as the \c out_char parameter for a
* next invocation of encode_utf8_char().
*/
static char *encode_utf8_char(const utf_32_char unicode_char, char *out_char)
{
char *next_char = out_char;
// 7 bits
if (unicode_char < 0x00000080)
{
*(next_char++) = unicode_char;
}
// 11 bits
else if (unicode_char < 0x00000800)
{
// 0xc0 provides the counting bits: 110
// then append the 5 most significant bits
*(next_char++) = 0xc0 | (unicode_char >> 6);
// Put the next 6 bits in a byte of their own
*(next_char++) = 0x80 | (unicode_char & 0x3f);
}
// 16 bits
else if (unicode_char < 0x00010000)
{
// 0xe0 provides the counting bits: 1110
// then append the 4 most significant bits
*(next_char++) = 0xe0 | (unicode_char >> 12);
// Put the next 12 bits in two bytes of their own
*(next_char++) = 0x80 | ((unicode_char >> 6) & 0x3f);
*(next_char++) = 0x80 | (unicode_char & 0x3f);
}
// 21 bits
/* This encoder can deal with < 0x00200000, but Unicode only ranges
* from 0x0 to 0x10FFFF. Thus we don't accept anything else.
*/
else if (unicode_char < 0x00110000)
{
// 0xf0 provides the counting bits: 11110
// then append the 3 most significant bits
*(next_char++) = 0xf0 | (unicode_char >> 18);
// Put the next 18 bits in three bytes of their own
*(next_char++) = 0x80 | ((unicode_char >> 12) & 0x3f);
*(next_char++) = 0x80 | ((unicode_char >> 6) & 0x3f);
*(next_char++) = 0x80 | (unicode_char & 0x3f);
}
else
{
/* Apparently this character lies outside the 0x0 - 0x10FFFF
* Unicode range, so don't accept it.
*/
ASSERT(!"out-of-range Unicode codepoint", "This Unicode codepoint is too large (%u > 0x10FFFF) to be a valid Unicode codepoint", (unsigned int)unicode_char);
}
return next_char;
}
utf_32_char UTF16DecodeChar(const utf_16_char *utf16_char, const utf_16_char **next_char)
{
utf_32_char decoded;
*next_char = utf16_char;
// Are we dealing with a surrogate pair
if (*utf16_char >= 0xD800
&& *utf16_char <= 0xDFFF)
{
ASSERT_START_HEXADECT(utf16_char[0]);
ASSERT_FINAL_HEXADECT(utf16_char[1]);
decoded = (*((*next_char)++) & 0x3ff) << 10;
decoded |= *((*next_char)++) & 0x3ff;
decoded += 0x10000;
}
// Not a surrogate pair, so it's a valid Unicode codepoint right away
else
{
decoded = *((*next_char)++);
}
return decoded;
}
/** Encodes a single Unicode character to a UTF-16 encoded string.
*
* \param unicode_char A UTF-32 encoded Unicode codepoint that will be encoded
* into UTF-16. This should be a valid Unicode codepoint
* (i.e. ranging from 0x0 to 0x10FFFF inclusive).
* \param out_char Points to the position in a buffer where the UTF-16
* encoded character can be stored.
*
* \return A pointer pointing to the first byte <em>after</em> the encoded
* UTF-16 sequence. This can be used as the \c out_char parameter for a
* next invocation of encode_utf16_char().
*/
static utf_16_char *encode_utf16_char(const utf_32_char unicode_char, utf_16_char *out_char)
{
utf_16_char *next_char = out_char;
// 16 bits
if (unicode_char < 0x10000)
{
*(next_char++) = unicode_char;
}
else if (unicode_char < 0x110000)
{
const utf_16_char v = unicode_char - 0x10000;
*(next_char++) = 0xD800 | (v >> 10);
*(next_char++) = 0xDC00 | (v & 0x3ff);
ASSERT_START_HEXADECT(out_char[0]);
ASSERT_FINAL_HEXADECT(out_char[1]);
}
else
{
/* Apparently this character lies outside the 0x0 - 0x10FFFF
* Unicode range, and UTF-16 cannot cope with that, so error
* out.
*/
ASSERT(!"out-of-range Unicode codepoint", "This Unicode codepoint is too large (%u > 0x10FFFF) to be a valid Unicode codepoint", (unsigned int)unicode_char);
}
return next_char;
}
static size_t utf16_utf8_buffer_length(const utf_16_char* unicode_string)
{
const utf_16_char* curChar = unicode_string;
// Determine length of string (in octets) when encoded in UTF-8
size_t length = 0;
while (*curChar)
{
length += unicode_utf8_char_length(UTF16DecodeChar(curChar, &curChar));
}
return length;
}
char *UTF16toUTF8(const utf_16_char *unicode_string, size_t *nbytes)
{
const utf_16_char* curChar;
const size_t utf8_length = utf16_utf8_buffer_length(unicode_string);
// Allocate memory to hold the UTF-8 encoded string (plus a terminating nul char)
char* utf8_string = malloc(utf8_length + 1);
char* curOutPos = utf8_string;
if (utf8_string == NULL)
{
debug(LOG_ERROR, "Out of memory");
return NULL;
}
curChar = unicode_string;
while (*curChar)
{
curOutPos = encode_utf8_char(UTF16DecodeChar(curChar, &curChar), curOutPos);
}
// Terminate the string with a nul character
utf8_string[utf8_length] = '\0';
// Set the number of bytes allocated
if (nbytes)
{
*nbytes = utf8_length + 1;
}
return utf8_string;
}
static size_t utf8_as_utf16_buf_size(const char* utf8_string)
{
const char* curChar = utf8_string;
size_t length = 0;
while (*curChar != '\0')
{
const utf_32_char unicode_char = UTF8DecodeChar(curChar, &curChar);
if (unicode_char < 0x10000)
{
length += 1;
}
else if (unicode_char < 0x110000)
{
length += 2;
}
else
{
/* Apparently this character lies outside the 0x0 - 0x10FFFF
* Unicode range, and UTF-16 cannot cope with that, so error
* out.
*/
ASSERT(!"out-of-range Unicode codepoint", "This Unicode codepoint too large (%u > 0x10FFFF) for the UTF-16 encoding", (unsigned int)unicode_char);
}
}
return length;
}
utf_16_char *UTF8toUTF16(const char* utf8_string, size_t *nbytes)
{
const char* curChar = utf8_string;
const size_t unicode_length = utf8_as_utf16_buf_size(utf8_string);
// Allocate memory to hold the UTF-16 encoded string (plus a terminating nul)
utf_16_char* unicode_string = malloc(sizeof(utf_16_char) * (unicode_length + 1));
utf_16_char* curOutPos = unicode_string;
if (unicode_string == NULL)
{
debug(LOG_ERROR, "Out of memory");
return NULL;
}
while (*curChar != '\0')
{
curOutPos = encode_utf16_char(UTF8DecodeChar(curChar, &curChar), curOutPos);
}
// Terminate the string with a nul
unicode_string[unicode_length] = '\0';
// Set the number of bytes allocated
if (nbytes)
{
*nbytes = sizeof(utf_16_char) * (unicode_length + 1);
}
return unicode_string;
}
utf_16_char *UTF16CharacterAtOffset(const utf_16_char *utf16_string, size_t index)
{
while (*utf16_string != '\0'
&& index != 0)
{
// Move to the next character
UTF16DecodeChar(utf16_string, &utf16_string);
--index;
}
if (*utf16_string == '\0')
return NULL;
return (utf_16_char*)utf16_string;
}
static size_t utf32_utf8_buffer_length(const utf_32_char* unicode_string)
{
const utf_32_char* curChar;
// Determine length of string (in octets) when encoded in UTF-8
size_t length = 0;
for (curChar = unicode_string; *curChar != '\0'; ++curChar)
{
length += unicode_utf8_char_length(*curChar);
}
return length;
}
char *UTF32toUTF8(const utf_32_char *unicode_string, size_t *nbytes)
{
const utf_32_char* curChar;
const size_t utf8_length = utf32_utf8_buffer_length(unicode_string);
// Allocate memory to hold the UTF-8 encoded string (plus a terminating nul char)
char* utf8_string = malloc(utf8_length + 1);
char* curOutPos = utf8_string;
if (utf8_string == NULL)
{
debug(LOG_ERROR, "Out of memory");
return NULL;
}
for (curChar = unicode_string; *curChar != 0; ++curChar)
{
curOutPos = encode_utf8_char(*curChar, curOutPos);
}
// Terminate the string with a nul character
utf8_string[utf8_length] = '\0';
// Set the number of bytes allocated
if (nbytes)
{
*nbytes = utf8_length + 1;
}
return utf8_string;
}
utf_32_char *UTF8toUTF32(const char *utf8_string, size_t *nbytes)
{
const char* curChar = utf8_string;
const size_t unicode_length = UTF8CharacterCount(utf8_string);
// Allocate memory to hold the UTF-32 encoded string (plus a terminating nul)
utf_32_char* unicode_string = malloc(sizeof(utf_32_char) * (unicode_length + 1));
utf_32_char* curOutPos = unicode_string;
if (unicode_string == NULL)
{
debug(LOG_ERROR, "Out of memory");
return NULL;
}
while (*curChar != '\0')
{
*(curOutPos++) = UTF8DecodeChar(curChar, &curChar);
}
// Terminate the string with a nul
unicode_string[unicode_length] = '\0';
// Set the number of bytes allocated
if (nbytes)
{
*nbytes = sizeof(utf_32_char) * (unicode_length + 1);
}
return unicode_string;
}
size_t utf32len(const utf_32_char *unicode_string)
{
size_t ret = 0;
while (*unicode_string++)
++ret;
return ret;
}

View File

@ -41,10 +41,10 @@ elseif(PLATFORM_WINDOWS)
set(PLATFORM_LIBS "-lintl")
endif()
elseif(PLATFORM_GNU)
set(PLATFORM_LIBS "-lX11")
#set(PLATFORM_LIBS "-lX11")
elseif(PLATFORM_LINUX)
# for clock_gettime
set(PLATFORM_LIBS "-lrt -lX11")
set(PLATFORM_LIBS "-lrt") # -lX11")
elseif(PLATFORM_MACOSX)
find_library(LIBINTL_LIBRARY NAMES intl libintl)
find_path(LIBINTL_INCLUDE_PATH NAMES libintl.h)
@ -271,11 +271,10 @@ set(MAIN_SOURCES
# Libraries
set(LIBS
CBot
clipboard
localename
${SDL_LIBRARY}
${SDLIMAGE_LIBRARY}
${SDLTTF_LIBRARY}
${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARY}
${SDL2_TTF_LIBRARY}
${OPENGL_LIBRARY}
${PNG_LIBRARIES}
${GLEW_LIBRARY}
@ -297,15 +296,14 @@ set(LOCAL_INCLUDES
)
set(SYSTEM_INCLUDES
${SDL_INCLUDE_DIR}
${SDLIMAGE_INCLUDE_DIR}
${SDLTTF_INCLUDE_DIR}
${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_TTF_INCLUDE_DIR}
${PNG_INCLUDE_DIRS}
${GLEW_INCLUDE_PATH}
${Boost_INCLUDE_DIRS}
${LIBSNDFILE_INCLUDE_DIR}
${LOCALENAME_INCLUDE_DIR}
${CLIPBOARD_INCLUDE_DIR}
${PHYSFS_INCLUDE_PATH}
${LIBINTL_INCLUDE_PATH}
${OPTIONAL_INCLUDES}

View File

@ -79,8 +79,10 @@ Uint32 JoystickTimerCallback(Uint32 interval, void *);
*/
struct ApplicationPrivate
{
//! Display surface
SDL_Surface *surface;
//! Main game window
SDL_Window *window;
//! Main game OpenGL context
SDL_GLContext glcontext;
//! Currently handled event
SDL_Event currentEvent;
//! Mouse motion event to be handled
@ -94,9 +96,9 @@ struct ApplicationPrivate
{
SDL_memset(&currentEvent, 0, sizeof(SDL_Event));
SDL_memset(&lastMouseMotionEvent, 0, sizeof(SDL_Event));
surface = nullptr;
window = nullptr;
joystick = nullptr;
joystickTimer = nullptr;
joystickTimer = 0;
}
};
@ -203,10 +205,16 @@ CApplication::~CApplication()
m_private->joystick = nullptr;
}
if (m_private->surface != nullptr)
if (m_private->glcontext != nullptr)
{
SDL_FreeSurface(m_private->surface);
m_private->surface = nullptr;
SDL_GL_DeleteContext(m_private->glcontext);
m_private->glcontext = nullptr;
}
if (m_private->window != nullptr)
{
SDL_DestroyWindow(m_private->window);
m_private->window = nullptr;
}
IMG_Quit();
@ -526,7 +534,7 @@ bool CApplication::Create()
// GetVideoResolutionList() has to be called here because it is responsible
// for list of resolutions in options menu, not calling it results in empty list
std::vector<Math::IntPoint> modes;
GetVideoResolutionList(modes, true, true);
GetVideoResolutionList(modes);
if ( GetConfigFile().GetStringProperty("Setup", "Resolution", sValue) && !m_resolutionOverride )
{
@ -560,7 +568,7 @@ bool CApplication::Create()
if (! CreateVideoSurface())
return false; // dialog is in function
if (m_private->surface == nullptr)
if (m_private->window == nullptr)
{
m_errorMessage = std::string("SDL error while setting video mode:\n") +
std::string(SDL_GetError());
@ -568,13 +576,9 @@ bool CApplication::Create()
m_exitCode = 4;
return false;
}
SDL_WM_SetCaption(m_windowTitle.c_str(), m_windowTitle.c_str());
}
// Enable translating key codes of key press events to unicode chars
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); //TODO: ?
// Don't generate joystick events
SDL_JoystickEventState(SDL_IGNORE);
@ -651,7 +655,7 @@ bool CApplication::Create()
bool CApplication::CreateVideoSurface()
{
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
/*const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (videoInfo == nullptr)
{
m_errorMessage = std::string("SDL error while getting video info:\n ") +
@ -659,23 +663,23 @@ bool CApplication::CreateVideoSurface()
GetLogger()->Error(m_errorMessage.c_str());
m_exitCode = 7;
return false;
}
}*/
Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE;
Uint32 videoFlags = SDL_WINDOW_OPENGL; // | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE
// Use hardware surface if available
if (videoInfo->hw_available)
videoFlags |= SDL_HWSURFACE;
/*if (videoInfo->hw_available)
videoFlags |= SDL_HWSURFACE;*/
// Enable hardware blit if available
if (videoInfo->blit_hw)
videoFlags |= SDL_HWACCEL;
/*if (videoInfo->blit_hw)
videoFlags |= SDL_HWACCEL;*/
if (m_deviceConfig.fullScreen)
videoFlags |= SDL_FULLSCREEN;
videoFlags |= SDL_WINDOW_FULLSCREEN;
if (m_deviceConfig.resizeable)
videoFlags |= SDL_RESIZABLE;
videoFlags |= SDL_WINDOW_RESIZABLE;
// Set OpenGL attributes
@ -694,8 +698,12 @@ bool CApplication::CreateVideoSurface()
if (m_deviceConfig.hardwareAccel)
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
m_private->surface = SDL_SetVideoMode(m_deviceConfig.size.x, m_deviceConfig.size.y,
m_deviceConfig.bpp, videoFlags);
m_private->window = SDL_CreateWindow(m_windowTitle.c_str(),
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
m_deviceConfig.size.x, m_deviceConfig.size.y,
videoFlags);
m_private->glcontext = SDL_GL_CreateContext(m_private->window);
return true;
}
@ -707,8 +715,8 @@ bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig)
m_lastDeviceConfig = m_deviceConfig;
m_deviceConfig = newConfig;
SDL_FreeSurface(m_private->surface);
SDL_GL_DeleteContext(m_private->glcontext); //TODO: refactor this
SDL_DestroyWindow(m_private->window); // TODO: ?
if (! CreateVideoSurface())
{
@ -717,7 +725,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig)
return false;
}
if (m_private->surface == nullptr)
if (m_private->window == nullptr)
{
if (! restore)
{
@ -899,14 +907,14 @@ int CApplication::Run()
}
// To be sure no old event remains
m_private->currentEvent.type = SDL_NOEVENT;
m_private->currentEvent.type = SDL_LASTEVENT;
// Call SDL_PumpEvents() only once here
// (SDL_PeepEvents() doesn't call it)
if (m_active)
SDL_PumpEvents();
m_private->lastMouseMotionEvent.type = SDL_NOEVENT;
m_private->lastMouseMotionEvent.type = SDL_LASTEVENT;
bool haveEvent = true;
while (haveEvent)
@ -917,7 +925,7 @@ int CApplication::Run()
// Use SDL_PeepEvents() if the app is active, so we can use idle time to
// render the scene. Else, use SDL_WaitEvent() to avoid eating CPU time.
if (m_active)
count = SDL_PeepEvents(&m_private->currentEvent, 1, SDL_GETEVENT, SDL_ALLEVENTS);
count = SDL_PeepEvents(&m_private->currentEvent, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
else
count = SDL_WaitEvent(&m_private->currentEvent);
@ -949,7 +957,7 @@ int CApplication::Run()
}
// Now, process the last received mouse motion
if (m_private->lastMouseMotionEvent.type != SDL_NOEVENT)
if (m_private->lastMouseMotionEvent.type != SDL_LASTEVENT)
{
m_private->currentEvent = m_private->lastMouseMotionEvent;
@ -1048,13 +1056,32 @@ Event CApplication::ProcessSystemEvent()
{
event.type = EVENT_SYS_QUIT;
}
else if (m_private->currentEvent.type == SDL_VIDEORESIZE)
else if (m_private->currentEvent.type == SDL_WINDOWEVENT)
{
Gfx::DeviceConfig newConfig = m_deviceConfig;
newConfig.size.x = m_private->currentEvent.resize.w;
newConfig.size.y = m_private->currentEvent.resize.h;
if (newConfig.size != m_deviceConfig.size)
ChangeVideoConfig(newConfig);
if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
Gfx::DeviceConfig newConfig = m_deviceConfig;
newConfig.size.x = m_private->currentEvent.window.data1;
newConfig.size.y = m_private->currentEvent.window.data2;
if (newConfig.size != m_deviceConfig.size)
ChangeVideoConfig(newConfig);
}
// TODO: EVENT_ACTIVE
/*{
event.type = EVENT_ACTIVE;
auto data = MakeUnique<ActiveEventData>();
if (m_private->currentEvent.active.type & SDL_APPINPUTFOCUS)
data->flags |= ACTIVE_INPUT;
if (m_private->currentEvent.active.type & SDL_APPMOUSEFOCUS)
data->flags |= ACTIVE_MOUSE;
if (m_private->currentEvent.active.type & SDL_APPACTIVE)
data->flags |= ACTIVE_APP;
data->gain = m_private->currentEvent.active.gain == 1;
event.data = std::move(data);
}*/
}
else if ( (m_private->currentEvent.type == SDL_KEYDOWN) ||
(m_private->currentEvent.type == SDL_KEYUP) )
@ -1068,7 +1095,7 @@ Event CApplication::ProcessSystemEvent()
data->virt = false;
data->key = m_private->currentEvent.key.keysym.sym;
data->unicode = m_private->currentEvent.key.keysym.unicode;
data->unicode = m_private->currentEvent.key.keysym.sym; // TODO: use SDL_TEXTINPUT for this, and remove this field
event.kmodState = m_private->currentEvent.key.keysym.mod;
// Some keyboards return numerical enter keycode instead of normal enter
@ -1079,47 +1106,38 @@ Event CApplication::ProcessSystemEvent()
if (data->key == KEY(TAB) && ((event.kmodState & KEY_MOD(ALT)) != 0))
{
GetLogger()->Debug("Minimize to taskbar\n");
SDL_WM_IconifyWindow();
SDL_MinimizeWindow(m_private->window);
event.type = EVENT_NULL;
}
event.data = std::move(data);
}
else if (m_private->currentEvent.type == SDL_MOUSEWHEEL)
{
event.type = EVENT_MOUSE_WHEEL;
auto data = MakeUnique<MouseWheelEventData>();
if (m_private->currentEvent.wheel.y < 0) // TODO: properly use this value
data->dir = WHEEL_DOWN;
else
data->dir = WHEEL_UP;
event.data = std::move(data);
}
else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) ||
(m_private->currentEvent.type == SDL_MOUSEBUTTONUP) )
{
if ((m_private->currentEvent.button.button == SDL_BUTTON_WHEELUP) ||
(m_private->currentEvent.button.button == SDL_BUTTON_WHEELDOWN))
{
auto data = MakeUnique<MouseButtonEventData>();
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) // ignore the following up event
{
event.type = EVENT_MOUSE_WHEEL;
auto data = MakeUnique<MouseWheelEventData>();
if (m_private->currentEvent.button.button == SDL_BUTTON_WHEELDOWN)
data->dir = WHEEL_DOWN;
else
data->dir = WHEEL_UP;
event.data = std::move(data);
}
}
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN)
event.type = EVENT_MOUSE_BUTTON_DOWN;
else
{
auto data = MakeUnique<MouseButtonEventData>();
event.type = EVENT_MOUSE_BUTTON_UP;
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN)
event.type = EVENT_MOUSE_BUTTON_DOWN;
else
event.type = EVENT_MOUSE_BUTTON_UP;
data->button = static_cast<MouseButton>(1 << m_private->currentEvent.button.button);
data->button = static_cast<MouseButton>(1 << m_private->currentEvent.button.button);
event.data = std::move(data);
}
event.data = std::move(data);
}
else if (m_private->currentEvent.type == SDL_MOUSEMOTION)
{
@ -1148,23 +1166,6 @@ Event CApplication::ProcessSystemEvent()
data->button = m_private->currentEvent.jbutton.button;
event.data = std::move(data);
}
else if (m_private->currentEvent.type == SDL_ACTIVEEVENT)
{
event.type = EVENT_ACTIVE;
auto data = MakeUnique<ActiveEventData>();
if (m_private->currentEvent.active.type & SDL_APPINPUTFOCUS)
data->flags |= ACTIVE_INPUT;
if (m_private->currentEvent.active.type & SDL_APPMOUSEFOCUS)
data->flags |= ACTIVE_MOUSE;
if (m_private->currentEvent.active.type & SDL_APPACTIVE)
data->flags |= ACTIVE_APP;
data->gain = m_private->currentEvent.active.gain == 1;
event.data = std::move(data);
}
return event;
}
@ -1307,7 +1308,7 @@ void CApplication::Render()
StartPerformanceCounter(PCNT_SWAP_BUFFERS);
if (m_deviceConfig.doubleBuf)
SDL_GL_SwapBuffers();
SDL_GL_SwapWindow(m_private->window);
StopPerformanceCounter(PCNT_SWAP_BUFFERS);
}
@ -1447,47 +1448,17 @@ Gfx::DeviceConfig CApplication::GetVideoConfig() const
return m_deviceConfig;
}
VideoQueryResult CApplication::GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions,
bool fullScreen, bool resizeable) const
void CApplication::GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions, int display) const
{
resolutions.clear();
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (videoInfo == nullptr)
return VIDEO_QUERY_ERROR;
for(int i = 0; i < SDL_GetNumDisplayModes(display); i++)
{
SDL_DisplayMode mode;
SDL_GetDisplayMode(display, i, &mode);
Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE;
// Use hardware surface if available
if (videoInfo->hw_available)
videoFlags |= SDL_HWSURFACE;
else
videoFlags |= SDL_SWSURFACE;
// Enable hardware blit if available
if (videoInfo->blit_hw)
videoFlags |= SDL_HWACCEL;
if (resizeable)
videoFlags |= SDL_RESIZABLE;
if (fullScreen)
videoFlags |= SDL_FULLSCREEN;
SDL_Rect **modes = SDL_ListModes(nullptr, videoFlags);
if (modes == reinterpret_cast<SDL_Rect **>(0) )
return VIDEO_QUERY_NONE; // no modes available
if (modes == reinterpret_cast<SDL_Rect **>(-1) )
return VIDEO_QUERY_ALL; // all resolutions are possible
for (int i = 0; modes[i] != nullptr; ++i)
resolutions.push_back(Math::IntPoint(modes[i]->w, modes[i]->h));
return VIDEO_QUERY_OK;
resolutions.push_back(Math::IntPoint(mode.w, mode.h));
}
}
void CApplication::SetDebugModeActive(DebugMode mode, bool active)
@ -1541,17 +1512,6 @@ bool CApplication::ParseDebugModes(const std::string& str, int& debugModes)
return true;
}
void CApplication::SetGrabInput(bool grab)
{
SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF);
}
bool CApplication::GetGrabInput() const
{
int result = SDL_WM_GrabInput(SDL_GRAB_QUERY);
return result == SDL_GRAB_ON;
}
void CApplication::SetMouseMode(MouseMode mode)
{
m_mouseMode = mode;
@ -1570,7 +1530,7 @@ void CApplication::MoveMouse(Math::Point pos)
{
Math::IntPoint windowPos = m_engine->InterfaceToWindowCoords(pos);
m_input->MouseMove(windowPos);
SDL_WarpMouse(windowPos.x, windowPos.y);
SDL_WarpMouseInWindow(m_private->window, windowPos.x, windowPos.y);
}
std::vector<JoystickDevice> CApplication::GetJoystickList() const
@ -1583,7 +1543,7 @@ std::vector<JoystickDevice> CApplication::GetJoystickList() const
{
JoystickDevice device;
device.index = index;
device.name = SDL_JoystickName(index);
device.name = SDL_JoystickNameForIndex(index);
result.push_back(device);
}

View File

@ -71,18 +71,6 @@ struct JoystickDevice
: index(-1), axisCount(0), buttonCount(0) {}
};
/**
* \enum VideoQueryResult
* \brief Result of querying for available video resolutions
*/
enum VideoQueryResult
{
VIDEO_QUERY_ERROR,
VIDEO_QUERY_NONE,
VIDEO_QUERY_ALL,
VIDEO_QUERY_OK
};
/**
* \enum ParseArgsStatus
* \brief State of parsing commandline arguments
@ -215,8 +203,7 @@ public:
const std::string& GetErrorMessage() const;
//! Returns a list of possible video modes
VideoQueryResult GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions,
bool fullScreen, bool resizeable) const;
void GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions, int display = 0) const;
//! Returns the current video mode
Gfx::DeviceConfig GetVideoConfig() const;
@ -277,12 +264,6 @@ public:
//! Updates the mouse position explicitly
void UpdateMouse();
//! Management of the grab mode for input (keyboard & mouse)
//@{
void SetGrabInput(bool grab);
bool GetGrabInput() const;
//@}
//! Management of mouse mode
//@{
void SetMouseMode(MouseMode mode);

View File

@ -135,10 +135,10 @@ void CInput::EventProcess(Event& event)
if (data->slot == INPUT_SLOT_CAMERA_UP ) m_cameraKeyMotion.z = 1.0f;
if (data->slot == INPUT_SLOT_CAMERA_DOWN) m_cameraKeyMotion.z = -1.0f;
if (data->key == KEY(KP4) ) m_cameraKeyMotion.x = -1.0f;
if (data->key == KEY(KP6) ) m_cameraKeyMotion.x = 1.0f;
if (data->key == KEY(KP8) ) m_cameraKeyMotion.y = 1.0f;
if (data->key == KEY(KP2) ) m_cameraKeyMotion.y = -1.0f;
if (data->key == KEY(KP_4) ) m_cameraKeyMotion.x = -1.0f;
if (data->key == KEY(KP_6) ) m_cameraKeyMotion.x = 1.0f;
if (data->key == KEY(KP_8) ) m_cameraKeyMotion.y = 1.0f;
if (data->key == KEY(KP_2) ) m_cameraKeyMotion.y = -1.0f;
}
else if (event.type == EVENT_KEY_UP)
{
@ -153,10 +153,10 @@ void CInput::EventProcess(Event& event)
if (data->slot == INPUT_SLOT_CAMERA_UP ) m_cameraKeyMotion.z = 0.0f;
if (data->slot == INPUT_SLOT_CAMERA_DOWN) m_cameraKeyMotion.z = 0.0f;
if (data->key == KEY(KP4) ) m_cameraKeyMotion.x = 0.0f;
if (data->key == KEY(KP6) ) m_cameraKeyMotion.x = 0.0f;
if (data->key == KEY(KP8) ) m_cameraKeyMotion.y = 0.0f;
if (data->key == KEY(KP2) ) m_cameraKeyMotion.y = 0.0f;
if (data->key == KEY(KP_4) ) m_cameraKeyMotion.x = 0.0f;
if (data->key == KEY(KP_6) ) m_cameraKeyMotion.x = 0.0f;
if (data->key == KEY(KP_8) ) m_cameraKeyMotion.y = 0.0f;
if (data->key == KEY(KP_2) ) m_cameraKeyMotion.y = 0.0f;
}
else if (event.type == EVENT_JOY_AXIS)
{
@ -253,7 +253,7 @@ void CInput::SetDefaultInputBindings()
m_inputBindings[INPUT_SLOT_GUP ].primary = VIRTUAL_KMOD(SHIFT);
m_inputBindings[INPUT_SLOT_GDOWN ].primary = VIRTUAL_KMOD(CTRL);
m_inputBindings[INPUT_SLOT_CAMERA ].primary = KEY(SPACE);
m_inputBindings[INPUT_SLOT_DESEL ].primary = KEY(KP0);
m_inputBindings[INPUT_SLOT_DESEL ].primary = KEY(KP_0);
m_inputBindings[INPUT_SLOT_ACTION ].primary = KEY(RETURN);
m_inputBindings[INPUT_SLOT_ACTION ].secondary = KEY(e);
m_inputBindings[INPUT_SLOT_NEAR ].primary = KEY(KP_PLUS);

View File

@ -238,7 +238,7 @@ void CImage::ConvertToRGBA()
void CImage::BlitToNewRGBASurface(int width, int height)
{
m_data->surface->flags &= (~SDL_SRCALPHA);
//m_data->surface->flags &= (~SDL_SRCALPHA); //TODO: ?
SDL_Surface* convertedSurface = SDL_CreateRGBSurface(0, width, height, 32, 0x00FF0000, 0x0000FF00,
0x000000FF, 0xFF000000);
assert(convertedSurface != nullptr);

View File

@ -27,8 +27,8 @@ unsigned int GetVirtualKey(unsigned int key)
return VIRTUAL_KMOD(SHIFT);
if(key == KEY(LALT) || key == KEY(RALT))
return VIRTUAL_KMOD(ALT);
if(key == KEY(LMETA) || key == KEY(RMETA))
return VIRTUAL_KMOD(META);
if(key == KEY(LGUI) || key == KEY(RGUI))
return VIRTUAL_KMOD(GUI);
if(key == KEY(KP_ENTER))
return KEY(RETURN);

View File

@ -25,7 +25,8 @@
#pragma once
#include <SDL_keysym.h>
#include <SDL_keycode.h>
#define SDLK_LAST (SDLK_SCANCODE_MASK << 1) //TODO
/* Key definitions are specially defined here so that it is clear in other parts of the code
that these are used. It is to avoid having SDL-related enum values or #defines lying around
@ -51,7 +52,7 @@ enum VirtualKmod
VIRTUAL_KMOD_CTRL = SDLK_LAST + 100, //! < control (left or right)
VIRTUAL_KMOD_SHIFT = SDLK_LAST + 101, //! < shift (left or right)
VIRTUAL_KMOD_ALT = SDLK_LAST + 102, //! < alt (left or right)
VIRTUAL_KMOD_META = SDLK_LAST + 103 //! < win key (left or right)
VIRTUAL_KMOD_GUI = SDLK_LAST + 103 //! < windows logo (on windows/linux) or command (on mac os) key (left or right)
};
// Just syntax sugar

View File

@ -52,11 +52,12 @@ CSDLFileWrapper::CSDLFileWrapper(const std::string& filename)
return;
}
m_rwops->type = PHYSFS_RWOPS_TYPE;
m_rwops->type = PHYSFS_RWOPS_TYPE; //TODO: Documentation recommends to leave SDL_RWOPS_UNKNOWN here for application-defined RWops. Did that change in SDL2?
m_rwops->hidden.unknown.data1 = file;
m_rwops->seek = SDLSeek;
m_rwops->read = SDLRead;
m_rwops->write = SDLWrite;
m_rwops->size = SDLSize;
// This is safe because SDL_FreeRW will be called in destructor
m_rwops->close = SDLCloseWithoutFreeRW;
}
@ -117,7 +118,7 @@ bool CSDLFileWrapper::CheckSDLContext(SDL_RWops *context)
return true;
}
int CSDLFileWrapper::SDLSeek(SDL_RWops *context, int offset, int whence)
Sint64 CSDLFileWrapper::SDLSeek(SDL_RWops *context, Sint64 offset, int whence)
{
if (CheckSDLContext(context))
{
@ -151,7 +152,12 @@ int CSDLFileWrapper::SDLSeek(SDL_RWops *context, int offset, int whence)
return -1;
}
int CSDLFileWrapper::SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum)
Sint64 CSDLFileWrapper::SDLSize(SDL_RWops *context)
{
return -1; // Not needed for now
}
size_t CSDLFileWrapper::SDLRead(SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
{
if (CheckSDLContext(context))
{
@ -165,7 +171,8 @@ int CSDLFileWrapper::SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum
return 0;
}
int CSDLFileWrapper::SDLWrite(SDL_RWops *context, const void *ptr, int size, int num)
size_t CSDLFileWrapper::SDLWrite(SDL_RWops *context, const void *ptr, size_t size, size_t num)
{
assert(!!"Writing to CSDLFileWrapper is currently not supported");
return 0;
}

View File

@ -37,9 +37,10 @@ public:
SDL_RWops* GetHandler();
private:
static int SDLSeek(SDL_RWops *context, int offset, int whence);
static int SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum);
static int SDLWrite(SDL_RWops *context, const void *ptr, int size, int num);
static Sint64 SDLSeek(SDL_RWops *context, Sint64 offset, int whence);
static Sint64 SDLSize(SDL_RWops *context);
static size_t SDLRead(SDL_RWops *context, void *ptr, size_t size, size_t maxnum);
static size_t SDLWrite(SDL_RWops *context, const void *ptr, size_t size, size_t num);
static int SDLClose(SDL_RWops *context, bool freeRW);
static int SDLCloseWithoutFreeRW(SDL_RWops *context);
static int SDLCloseWithFreeRW(SDL_RWops *context);

View File

@ -866,6 +866,7 @@ bool GetResource(ResType type, unsigned int num, std::string& text)
}
else
{
// TODO: fix signed/unsigned comparations
if (num == KEY_INVALID)
text.clear();
else if (num == VIRTUAL_KMOD_CTRL)
@ -874,8 +875,8 @@ bool GetResource(ResType type, unsigned int num, std::string& text)
text = "Shift";
else if (num == VIRTUAL_KMOD_ALT)
text = "Alt";
else if (num == VIRTUAL_KMOD_META)
text = "Win";
else if (num == VIRTUAL_KMOD_GUI)
text = "Win"; // TODO: Better description of this key?
else if (num > VIRTUAL_JOY(0))
{
text = gettext("Button %1");
@ -883,7 +884,7 @@ bool GetResource(ResType type, unsigned int num, std::string& text)
}
else
{
text = SDL_GetKeyName(static_cast<SDLKey>(num));
text = SDL_GetKeyName(static_cast<SDL_Keycode>(num));
text = boost::regex_replace(text, boost::regex("\\[(.*)\\]"), "\\1");
text[0] = toupper(text[0]);
}

View File

@ -52,9 +52,10 @@ public:
using ResourceUPtr = std::unique_ptr<Resource>;
using ThreadFunctionPtr = void(*)(ResourceUPtr);
CResourceOwningThread(ThreadFunctionPtr threadFunction, ResourceUPtr resource)
CResourceOwningThread(ThreadFunctionPtr threadFunction, ResourceUPtr resource, std::string name = "")
: m_threadFunction(threadFunction),
m_resource(std::move(resource))
m_resource(std::move(resource)),
m_name(name)
{}
void Start()
@ -72,7 +73,7 @@ public:
SDL_LockMutex(*mutex);
SDL_CreateThread(Run, reinterpret_cast<void*>(&data));
SDL_CreateThread(Run, !m_name.empty() ? m_name.c_str() : nullptr, reinterpret_cast<void*>(&data));
while (!condition)
{
@ -114,4 +115,5 @@ private:
ThreadFunctionPtr m_threadFunction;
ResourceUPtr m_resource;
std::string m_name;
};

View File

@ -500,7 +500,7 @@ void CEngine::WriteScreenShot(const std::string& fileName)
data->fileName = fileName;
CResourceOwningThread<WriteScreenShotData> thread(CEngine::WriteScreenShotThread, std::move(data));
CResourceOwningThread<WriteScreenShotData> thread(CEngine::WriteScreenShotThread, std::move(data), "WriteScreenShot thread");
thread.Start();
}

View File

@ -1014,7 +1014,7 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font)
int w = Math::NextPowerOfTwo(textSurface->w);
int h = Math::NextPowerOfTwo(textSurface->h);
textSurface->flags = textSurface->flags & (~SDL_SRCALPHA);
//textSurface->flags = textSurface->flags & (~SDL_SRCALPHA); //TODO: ?
SDL_Surface* textureSurface = SDL_CreateRGBSurface(0, w, h, 32, 0x00ff0000, 0x0000ff00,
0x000000ff, 0xff000000);
SDL_BlitSurface(textSurface, nullptr, textureSurface, nullptr);

View File

@ -718,8 +718,8 @@ Texture CGL21Device::CreateTexture(ImageData *data, const TextureCreateParams &p
SDL_PixelFormat format;
format.BytesPerPixel = 4;
format.BitsPerPixel = 32;
format.alpha = 0;
format.colorkey = 0;
//format.alpha = 0; //TODO: ?
//format.colorkey = 0; //TODO: ?
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
format.Amask = 0xFF000000;
format.Ashift = 24;

View File

@ -745,8 +745,8 @@ Texture CGL33Device::CreateTexture(ImageData *data, const TextureCreateParams &p
SDL_PixelFormat format;
format.BytesPerPixel = 4;
format.BitsPerPixel = 32;
format.alpha = 0;
format.colorkey = 0;
//format.alpha = 0; //TODO: ?
//format.colorkey = 0; //TODO: ?
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
format.Amask = 0xFF000000;
format.Ashift = 24;

View File

@ -687,8 +687,8 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par
SDL_PixelFormat format;
format.BytesPerPixel = 4;
format.BitsPerPixel = 32;
format.alpha = 0;
format.colorkey = 0;
//format.alpha = 0; //TODO: ?
//format.colorkey = 0; //TODO: ?
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
format.Amask = 0xFF000000;
format.Ashift = 24;

View File

@ -107,7 +107,6 @@
#include <iomanip>
#include <stdexcept>
#include <clipboard/clipboard.h>
#include <boost/lexical_cast.hpp>
@ -931,7 +930,7 @@ bool CRobotMain::ProcessEvent(Event &event)
std::stringstream ss;
ss << line;
widgetSetClipboardText(ss.str().c_str());
SDL_SetClipboardText(ss.str().c_str());
}
}
break;

View File

@ -40,8 +40,7 @@
#include "ui/controls/scroll.h"
#include <clipboard/clipboard.h>
#include <SDL.h>
#include <boost/algorithm/string.hpp>
#include <cstring>
@ -2537,7 +2536,7 @@ bool CEdit::Copy(bool memorize_cursor)
std::vector<char> text(len + 1, '\0');
strncpy(text.data(), m_text.data() + start, len);
text[len] = 0;
widgetSetClipboardText(text.data());
SDL_SetClipboardText(text.data()); //TODO: Move to CApplication
if (memorize_cursor)
{
@ -2560,7 +2559,7 @@ bool CEdit::Paste()
return false;
}
text = widgetGetClipboardText();
text = SDL_GetClipboardText(); // TODO: Move to CApplication
if ( text == nullptr )
{

View File

@ -105,7 +105,7 @@ bool CKey::EventProcess(const Event &event)
bool CKey::TestKey(unsigned int key)
{
if (key == KEY(PAUSE) || key == KEY(PRINT)) return true; // blocked key
if (key == KEY(PAUSE)) return true; // blocked key
for (int i = 0; i < INPUT_SLOT_MAX; i++)
{
@ -210,4 +210,3 @@ InputBinding CKey::GetBinding()
} // namespace Ui

View File

@ -64,7 +64,7 @@ void CScreenSetupDisplay::CreateInterface()
if ( pw == nullptr ) return;
std::vector<Math::IntPoint> modes;
m_app->GetVideoResolutionList(modes, true, true);
m_app->GetVideoResolutionList(modes);
for (auto it = modes.begin(); it != modes.end(); ++it)
{
if (it->x == m_app->GetVideoConfig().size.x && it->y == m_app->GetVideoConfig().size.y)
@ -183,7 +183,7 @@ void CScreenSetupDisplay::UpdateDisplayMode()
pl->Flush();
std::vector<Math::IntPoint> modes;
m_app->GetVideoResolutionList(modes, true, true);
m_app->GetVideoResolutionList(modes);
int i = 0;
std::stringstream mode_text;
for (Math::IntPoint mode : modes)
@ -220,7 +220,7 @@ void CScreenSetupDisplay::ChangeDisplay()
m_setupFull = bFull;
std::vector<Math::IntPoint> modes;
m_app->GetVideoResolutionList(modes, true, true);
m_app->GetVideoResolutionList(modes);
Gfx::DeviceConfig config = m_app->GetVideoConfig();
config.size = modes[m_setupSelMode];