diff --git a/.hgignore b/.hgignore index 2b3ec57ee..1020b75c6 100644 --- a/.hgignore +++ b/.hgignore @@ -19,6 +19,7 @@ build/ debug/ release/ doc/doxygen/html/ +doxygenoutput xcuserdata/ *.xcworkspace/ @@ -34,3 +35,18 @@ cppcheck-output **exposed_decl.pypp.txt glob:CEGUI-DEPS-0.8.x-beta3 + +android/CEGUISampleFramework/AndroidManifest.xml +android/CEGUISampleFramework/ant.properties +android/CEGUISampleFramework/local.properties +android/CEGUISampleFramework/bin +android/CEGUISampleFramework/gen +android/CEGUISampleFramework/libs +android/CEGUISampleFramework/obj +android/CEGUISampleFramework/jni/Android.mk +android/CEGUISampleFramework/jni/Application.mk +android/CEGUISampleFramework/jni/deps/Android.mk +android/CEGUISampleFramework/res/drawable-hdpi/logo.png +android/CEGUISampleFramework/res/drawable-mdpi/logo.png +android/CEGUISampleFramework/res/drawable-xhdpi/logo.png +android/CEGUISampleFramework/res/drawable-xxhdpi/logo.png diff --git a/CMakeLists.txt b/CMakeLists.txt index 758906a22..6e7746494 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ ################################################################################ # Top-level CMakeLists.txt file for Crazy Eddie's GUI System ################################################################################ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8.12) if (POLICY CMP0017) cmake_policy(SET CMP0017 OLD) endif() @@ -10,10 +10,6 @@ if (POLICY CMP0045) cmake_policy(SET CMP0045 OLD) endif() -set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") -include(CEGUIMacros) -include(CMakeDependentOption) - if (APPLE AND NOT CMAKE_OSX_ARCHITECTURES) set( CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING "Build architectures for Mac OS X") endif() @@ -28,12 +24,16 @@ endif() ################################################################################ project(cegui) +set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") +include(CEGUIMacros) +include(CMakeDependentOption) + ################################################################################ # Set up version information ################################################################################ set( CEGUI_VERSION_MAJOR 0) set( CEGUI_VERSION_MINOR 8) -set( CEGUI_VERSION_PATCH 4) +set( CEGUI_VERSION_PATCH 7) set( CEGUI_VERSION ${CEGUI_VERSION_MAJOR}.${CEGUI_VERSION_MINOR}.${CEGUI_VERSION_PATCH} ) # @@ -48,28 +48,37 @@ set( CEGUI_VERSION ${CEGUI_VERSION_MAJOR}.${CEGUI_VERSION_MINOR}.${CEGUI_VERSION # - AGE: Number of previous binary interfaces this library is compatible with. # # Prior to issuing a release, modify the values as follows: -# - If there were any changes in the source, increase REVISION. -# - If the interface changed at all, increase CURRENT and set REVISION to 0 -# - If the interface had binary compabilbe additions only (so no ABI breaking -# changes) increase AGE, else set AGE to 0. +# - If there were no changes to the source, do not change any values. +# - If there were changes to the implementation, but no changes to the ABI at all (that is, nothing was added, removed, or changed that affects ABI), increase REVISION. +# - If there were changes that modified the ABI, but the ABI remains compatible with the previous release, increase CURRENT, increase AGE, and set REVISION to 0. +# - If there were ABI breaking changes, increase CURRENT, set AGE to 0 and set REVISION to 0. # -set( CEGUI_ABI_CURRENT 5) -set( CEGUI_ABI_REVISION 0) -set( CEGUI_ABI_AGE 3) +set( CEGUI_ABI_CURRENT 6) +set( CEGUI_ABI_REVISION 2) +set( CEGUI_ABI_AGE 4) MATH( EXPR CEGUI_SOVERSION ${CEGUI_ABI_CURRENT}-${CEGUI_ABI_AGE} ) set( CEGUI_ABI_VERSION ${CEGUI_SOVERSION}.${CEGUI_ABI_AGE}.${CEGUI_ABI_REVISION} ) +cegui_check_mingw() ################################################################################ # Check for libs and other packages we might use. ################################################################################ # be sure to search the provided dependencies on Win32 and Mac OS X platforms if ((WIN32 OR APPLE) AND NOT CMAKE_PREFIX_PATH) - set (CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/dependencies" CACHE PATH "Path to dependencies") + set (CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/dependencies" CACHE PATH "Path to dependencies") # prefer the dylib deps in the dependencies over some other framework set (CMAKE_FIND_FRAMEWORK LAST) endif() +if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03") +elseif (NOT CMAKE_VERSION VERSION_LESS "3.1") + set (CMAKE_C_STANDARD_REQUIRED TRUE) + set (CMAKE_C_STANDARD "99") +endif () + # Look for packages find_package(PCRE) find_package(Freetype) @@ -83,6 +92,9 @@ find_package(OpenGL) find_package(GLEW) find_package(GLM) find_package(GLFW) +find_package(GLFW3) +find_package(SDL2) +find_package(SDL2_image) find_package(DirectXSDK) find_package(D3DX11Effects) find_package(Irrlicht) @@ -90,6 +102,7 @@ find_package(Ogre) find_package(OIS) find_package(DirectFB) find_package(OpenGLES) +find_package(Epoxy) find_package(EXPAT) find_package(XercesC) @@ -106,7 +119,14 @@ find_package(PVRTools) find_package(Lua51) find_package(TOLUAPP) find_package(PythonInterp) -find_package(PythonLibs) + +## ensure python3 not picked up as default +find_package(PythonVersion) +if (UNIX AND PYTHON_VERSION_FOUND) + find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT) +else() + find_package(PythonLibs) +endif() find_package(Boost 1.36.0 COMPONENTS python unit_test_framework system timer) find_package(Doxygen) @@ -114,6 +134,19 @@ find_package(GTK2 COMPONENTS gtk) # set for consistency with other deps set (GTK2_INCLUDE_DIR ${GTK2_INCLUDE_DIRS}) +## Search for ccache +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set(ENV(CCACHE_CPP2) "yes") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) +endif(CCACHE_FOUND) + +if (GLEW_FOUND OR EPOXY_FOUND) + set (OPENGL_LOADER_FOUND TRUE) +else () + set (OPENGL_LOADER_FOUND FALSE) +endif () ################################################################################ # Define the configurable options @@ -166,9 +199,10 @@ option( CEGUI_BUILD_IMAGECODEC_CORONA "Specifies whether to build the Corona bas option( CEGUI_BUILD_IMAGECODEC_STB "Specifies whether to build the STB based ImageCodec module" FALSE ) option( CEGUI_BUILD_IMAGECODEC_TGA "Specifies whether to build the based TGA only ImageCodec module" FALSE ) option( CEGUI_BUILD_IMAGECODEC_PVR "Specifies whether to build the PVR only ImageCodec module" ${PVRTOOLS_FOUND} ) +cegui_dependent_option( CEGUI_BUILD_IMAGECODEC_SDL2 "Specifies whether to build the SDL2 ImageCodec module" "SDL2_FOUND;SDL2IMAGE_FOUND" ) -cegui_dependent_option( CEGUI_BUILD_RENDERER_OPENGL "Specifies whether to build the OpenGL renderer module" "OPENGL_FOUND;GLM_FOUND;GLEW_FOUND" ) -cegui_dependent_option( CEGUI_BUILD_RENDERER_OPENGL3 "Specifies whether to build the OpenGL 3+ (core profile) renderer module" "OPENGL_FOUND;GLM_FOUND;GLEW_FOUND") +cegui_dependent_option( CEGUI_BUILD_RENDERER_OPENGL "Specifies whether to build the old OpenGL renderer module" "OPENGL_gl_LIBRARY;GLM_FOUND;GLEW_FOUND" ) +cegui_dependent_option( CEGUI_BUILD_RENDERER_OPENGL3 "Specifies whether to build the renderer module that supports OpenGL 3.2 (core profile) and OpenGL ES 2.0." "OPENGL_gl_LIBRARY;GLM_FOUND;OPENGL_LOADER_FOUND") option( CEGUI_BUILD_RENDERER_OGRE "Specifies whether to build the Ogre renderer module" ${OGRE_FOUND} ) option( CEGUI_BUILD_RENDERER_IRRLICHT "Specifies whether to build the Irrlicht renderer module" ${IRRLICHT_FOUND} ) option( CEGUI_BUILD_RENDERER_DIRECTFB "Specifies whether to build the DirectFB renderer module (not supported!)" FALSE ) @@ -176,8 +210,7 @@ cegui_dependent_option( CEGUI_BUILD_RENDERER_DIRECT3D9 "Specifies whether to bui cegui_dependent_option( CEGUI_BUILD_RENDERER_DIRECT3D10 "Specifies whether to build the Direct3D 10 renderer module" "DIRECTXSDK_FOUND;NOT DIRECTXSDK_MAX_D3D LESS 10" ) cegui_dependent_option( CEGUI_BUILD_RENDERER_DIRECT3D11 "Specifies whether to build the Direct3D 11 renderer module" "DIRECTXSDK_FOUND;D3DX11EFFECTS_FOUND;NOT DIRECTXSDK_MAX_D3D LESS 11" ) option( CEGUI_BUILD_RENDERER_NULL "Specifies whether to build the null renderer module" FALSE ) -option( CEGUI_BUILD_RENDERER_OPENGLES "Specifies whether to build the OpenGLES renderer module" ${OPENGLES_FOUND} ) - +option( CEGUI_BUILD_RENDERER_OPENGLES "Specifies whether to build the OpenGL ES 1 renderer module" ${OPENGLES_FOUND} ) cegui_dependent_option( CEGUI_BUILD_LUA_MODULE "Specifies whether to build the Lua based script module" "LUA51_FOUND;TOLUAPP_FOUND" ) cegui_dependent_option( CEGUI_BUILD_LUA_GENERATOR "Specifies whether to build the custom tolua binding generator 'toluappcegui'" "LUA51_FOUND;TOLUAPP_FOUND" ) @@ -193,10 +226,78 @@ if (CEGUI_USE_MINIBIDI AND CEGUI_USE_FRIBIDI) message(SEND_ERROR "You may not enable both CEGUI_USE_FRIBIDI and CEGUI_USE_MINIBIDI. Please choose only one of these options.") endif() +if (CEGUI_BUILD_RENDERER_OPENGL OR CEGUI_BUILD_RENDERER_OPENGL3) + if (GLEW_FOUND AND EPOXY_FOUND) + option (CEGUI_USE_GLEW "Specifies whether to use GLEW as an OpenGL loading library." TRUE) + option (CEGUI_USE_EPOXY "Specifies whether to use Epoxy as an OpenGL loading library." FALSE) + if (CEGUI_USE_GLEW AND CEGUI_USE_EPOXY) + message (FATAL_ERROR "You may not enable both \"CEGUI_USE_GLEW\" and \"CEGUI_USE_EPOXY\". Please choose only one of these options.") + endif () + else () + set (CEGUI_USE_GLEW "${GLEW_FOUND}") + set (CEGUI_USE_EPOXY "${EPOXY_FOUND}") + endif () + if (CEGUI_BUILD_RENDERER_OPENGL AND NOT CEGUI_USE_GLEW) + message (FATAL_ERROR "Building the old OpenGL renderer module is only supported using GLEW.") + endif () + if (NOT ANDROID) + set (CEGUI_GLFW_VER "" CACHE STRING "Specifies which major version of GLFW to use for the samples (2 or 3). The default is to look for both, giving priority to version 2.") + + if (((CEGUI_GLFW_VER STREQUAL "2") OR (CEGUI_GLFW_VER STREQUAL "")) AND GLFW_FOUND) + set (CEGUI_USE_GLFW_VER "2") + elseif (((CEGUI_GLFW_VER STREQUAL "3") OR (CEGUI_GLFW_VER STREQUAL "")) AND GLFW3_FOUND) + set (CEGUI_USE_GLFW_VER "3") + endif () + endif () +endif () + +if (CEGUI_BUILD_RENDERER_OPENGL3 AND CEGUI_USE_EPOXY) + set (CEGUI_SUPPORT_RENDERER_OPENGLES2 TRUE) + set (CEGUI_OPENGL_VER_MAJOR_FORCE "" CACHE STRING "Run the samples as if a specific OpenGL (desktop or ES) major version is used. Useful for testing.") + mark_as_advanced (CEGUI_OPENGL_VER_MAJOR_FORCE) + set (CEGUI_OPENGL_VER_MINOR_FORCE "0" CACHE STRING "Run the samples as if a specific OpenGL (desktop or ES) minor version is used. Useful for testing.") + mark_as_advanced (CEGUI_OPENGL_VER_MINOR_FORCE) +else () + set (CEGUI_SUPPORT_RENDERER_OPENGLES2 FALSE) +endif () + +if (CEGUI_SUPPORT_RENDERER_OPENGLES2 AND ((CEGUI_USE_GLFW_VER STREQUAL "3") OR ANDROID)) + set (CEGUI_SAMPLES_SUPPORT_RENDERER_OPENGLES2 TRUE) +else () + set (CEGUI_SAMPLES_SUPPORT_RENDERER_OPENGLES2 FALSE) +endif () + +option (CEGUI_WARNINGS_AS_ERRORS "Specifies whether to treat warnings as errors. Recommended if you're developing CEGUI itself." OFF) + +set (CEGUI_EXTRA_FLAGS "") + +if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) + set (CEGUI_EXTRA_FLAGS "${CEGUI_EXTRA_FLAGS} -fsigned-char") +endif () + +if (CMAKE_COMPILER_IS_GNUCXX) + set (CEGUI_EXTRA_FLAGS "${CEGUI_EXTRA_FLAGS} -Wall -Wextra -Wundef") +endif () + +if (CEGUI_WARNINGS_AS_ERRORS) + if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) + set (CEGUI_EXTRA_FLAGS "${CEGUI_EXTRA_FLAGS} -Werror") + elseif (MSVC) + set (CEGUI_EXTRA_FLAGS "${CEGUI_EXTRA_FLAGS} /WX") + else () + message (WARNING "You've specified \"CEGUI_WARNINGS_AS_ERRORS\" as \"ON\", but we don't know how to make it for your compiler. If you wish you can specifiy the required flags manually.") + endif () +endif () + +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CEGUI_EXTRA_FLAGS}") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CEGUI_EXTRA_FLAGS}") +set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CEGUI_EXTRA_FLAGS}") +set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${CEGUI_EXTRA_FLAGS}") +set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CEGUI_EXTRA_FLAGS}") + # Here we check if Ogre is built to use boost, and if yes, if the necessary dependencies are available and found by CEGUI set (CEGUI_OGRE_DEPS_AVAILABLE FALSE) set (CEGUI_OGRE_SAMPLES_EXTRALIBS) - if (CEGUI_BUILD_RENDERER_OGRE AND OIS_FOUND) if (NOT Boost_VERSION LESS 105000 AND "${OGRE_THREAD_PROVIDER}" STREQUAL "1") #Check additionally if we use boost as thread provider at all if (Boost_SYSTEM_FOUND) @@ -231,11 +332,9 @@ if (CEGUI_BUILD_RENDERER_OGRE AND NOT CEGUI_OGRE_DEPS_AVAILABLE) set (CEGUI_SAMPLES_RENDERER_OGRE_ACTIVE FALSE) endif() -if (CEGUI_SAMPLES_RENDERER_OPENGL_ACTIVE) - if(NOT GLFW_FOUND) - set (CEGUI_SAMPLES_RENDERER_OPENGL_ACTIVE FALSE) - message(STATUS "Info: The OpenGL- and/or OpenGL3 Renderers are disabled in the SampleBrowser because of missing dependencies (GLFW library). Please add the GFLW dependency and run 'Configure' in CMake again, in case you want to run the SampleBrowser using the OpenGL or OpenGL3 Renderers.") - endif() +if (CEGUI_SAMPLES_RENDERER_OPENGL_ACTIVE AND NOT (CEGUI_USE_GLFW_VER OR ANDROID)) + set (CEGUI_SAMPLES_RENDERER_OPENGL_ACTIVE FALSE) + message(STATUS "Info: The OpenGL-, OpenGL3 and/or OpenGL ES 2 Renderers are disabled in the SampleBrowser because of missing dependencies (GLFW 2/3 library). Please add the GFLW dependency and run 'Configure' in CMake again, in case you want to run the SampleBrowser using the OpenGL, OpenGL3 or OpenGL ES 2 Renderers.") endif() # If we use a Renderer then our samples should be ON by default @@ -252,6 +351,9 @@ if (UNIX AND NOT APPLE AND NOT WIN32) option( CEGUI_SAMPLES_USE_GTK2 "Specifies whether the sample applications will make use of the GTK2 UI for renderer selection." FALSE ) endif() +# Option wether to build application templates; default off +option(CEGUI_BUILD_APPLICATION_TEMPLATES "Specifies whether to build the application templates." TRUE) + if (WIN32 OR APPLE) set (CEGUI_BUILD_SUFFIX "_d" CACHE STRING "String holding a suffix appended to the name of output binaries (under CMake build, only used for debug).") else() @@ -287,6 +389,16 @@ cmake_dependent_option( CEGUI_BUILD_DATAFILES_TEST "Specifies whether to build t option( CEGUI_INSTALL_WITH_RPATH "Specifies whether to install with RPATH set to the install location (TRUE) or with no RPATH set (FALSE)." FALSE ) +# custom install locations +option( CEGUI_LIB_INSTALL_DIR "Specifies custom location for CEGUI_LIB_INSTALL_DIR" ) +option( CEGUI_DATA_INSTALL_DIR "Specifies custom location for CEGUI_DATA_INSTALL_DIR" ) +option( CEGUI_DOC_INSTALL_DIR "Specifies custom location for CEGUI_DOC_INSTALL_DIR" ) +option( CEGUI_PKGCONFIG_INSTALL_DIR "Specifies custom location for CEGUI_PKGCONFIG_INSTALL_DIR" ) +option( CEGUI_MODULE_INSTALL_DIR "Specifies custom location for CEGUI_MODULE_INSTALL_DIR" ) +option( CEGUI_SAMPLE_INSTALL_DIR "Specifies custom location for CEGUI_SAMPLE_INSTALL_DIR" ) # TODO: put into /samples subdir! +option( CEGUI_INCLUDE_INSTALL_DIR "Specifies custom location for CEGUI_INCLUDE_INSTALL_DIR" ) + + ################################################################################ # Define vars holding the names for all the libs we can build for CEGUI. ################################################################################ @@ -295,7 +407,6 @@ cegui_set_library_name( CEGUI_BASE_LIBNAME CEGUIBase ) # Renderer module names. cegui_set_library_name( CEGUI_OPENGL_RENDERER_LIBNAME CEGUIOpenGLRenderer ) -cegui_set_library_name( CEGUI_OPENGL3_RENDERER_LIBNAME CEGUIOpenGL3Renderer ) cegui_set_library_name( CEGUI_OGRE_RENDERER_LIBNAME CEGUIOgreRenderer) cegui_set_library_name( CEGUI_IRRLICHT_RENDERER_LIBNAME CEGUIIrrlichtRenderer ) cegui_set_library_name( CEGUI_DIRECT3D9_RENDERER_LIBNAME CEGUIDirect3D9Renderer ) @@ -320,6 +431,7 @@ cegui_set_module_name( CEGUI_CORONA_IMAGECODEC_LIBNAME CEGUICoronaImageCodec ) cegui_set_module_name( CEGUI_TGA_IMAGECODEC_LIBNAME CEGUITGAImageCodec ) cegui_set_module_name( CEGUI_STB_IMAGECODEC_LIBNAME CEGUISTBImageCodec ) cegui_set_module_name( CEGUI_PVR_IMAGECODEC_LIBNAME CEGUIPVRImageCodec ) +cegui_set_module_name( CEGUI_SDL2_IMAGECODEC_LIBNAME CEGUISDL2ImageCodec ) # WindowRenderer set module names cegui_set_module_name( CEGUI_CORE_WR_LIBNAME CEGUICoreWindowRendererSet ) @@ -397,6 +509,9 @@ elseif (CEGUI_BUILD_IMAGECODEC_STB) elseif (CEGUI_BUILD_IMAGECODEC_CORONA) set( CEGUI_OPTION_DEFAULT_IMAGECODEC "CoronaImageCodec" CACHE STRING "Specifies the ImageCodec module to use as the default" ) set( CEGUI_STATIC_IMAGECODEC_MODULE ${CEGUI_CORONA_IMAGECODEC_LIBNAME} CACHE STRING "Specifies image codec library to link to samples in static builds." ) +elseif (CEGUI_BUILD_IMAGECODEC_SDL2) + set( CEGUI_OPTION_DEFAULT_IMAGECODEC "SDL2ImageCodec" CACHE STRING "Specifies the ImageCodec module to use as the default" ) + set( CEGUI_STATIC_IMAGECODEC_MODULE ${CEGUI_SDL2_IMAGECODEC_LIBNAME} CACHE STRING "Specifies image codec library to link to samples in static builds." ) elseif (CEGUI_BUILD_IMAGECODEC_TGA) set( CEGUI_OPTION_DEFAULT_IMAGECODEC "TGAImageCodec" CACHE STRING "Specifies the ImageCodec module to use as the default" ) set( CEGUI_STATIC_IMAGECODEC_MODULE ${CEGUI_TGA_IMAGECODEC_LIBNAME} CACHE STRING "Specifies image codec library to link to samples in static builds." ) @@ -412,6 +527,7 @@ cegui_defaultmodule_sanity_test(CEGUI_OPTION_DEFAULT_IMAGECODEC "FreeImageImageC cegui_defaultmodule_sanity_test(CEGUI_OPTION_DEFAULT_IMAGECODEC "STBImageCodec" CEGUI_BUILD_IMAGECODEC_STB) cegui_defaultmodule_sanity_test(CEGUI_OPTION_DEFAULT_IMAGECODEC "CoronaImageCodec" CEGUI_BUILD_IMAGECODEC_CORONA) cegui_defaultmodule_sanity_test(CEGUI_OPTION_DEFAULT_IMAGECODEC "TGAImageCodec" CEGUI_BUILD_IMAGECODEC_TGA) +cegui_defaultmodule_sanity_test(CEGUI_OPTION_DEFAULT_IMAGECODEC "SDL2ImageCodec" CEGUI_BUILD_IMAGECODEC_SDL2) if (CEGUI_BUILD_STATIC_CONFIGURATION) cegui_defaultmodule_sanity_test(CEGUI_STATIC_IMAGECODEC_MODULE ${CEGUI_SILLY_IMAGECODEC_LIBNAME} CEGUI_BUILD_IMAGECODEC_SILLY) @@ -420,14 +536,15 @@ if (CEGUI_BUILD_STATIC_CONFIGURATION) cegui_defaultmodule_sanity_test(CEGUI_STATIC_IMAGECODEC_MODULE ${CEGUI_STB_IMAGECODEC_LIBNAME} CEGUI_BUILD_IMAGECODEC_STB) cegui_defaultmodule_sanity_test(CEGUI_STATIC_IMAGECODEC_MODULE ${CEGUI_CORONA_IMAGECODEC_LIBNAME} CEGUI_BUILD_IMAGECODEC_CORONA) cegui_defaultmodule_sanity_test(CEGUI_STATIC_IMAGECODEC_MODULE ${CEGUI_TGA_IMAGECODEC_LIBNAME} CEGUI_BUILD_IMAGECODEC_TGA) + cegui_defaultmodule_sanity_test(CEGUI_STATIC_IMAGECODEC_MODULE ${CEGUI_SDL2_IMAGECODEC_LIBNAME} CEGUI_BUILD_IMAGECODEC_SDL2) endif() ################################################################################ # Add main header locations (for everything we build) ################################################################################ include_directories( - ${CMAKE_CURRENT_BINARY_DIR}/cegui/include - ${CMAKE_CURRENT_SOURCE_DIR}/cegui/include + ${PROJECT_BINARY_DIR}/cegui/include + ${PROJECT_SOURCE_DIR}/cegui/include ) @@ -444,45 +561,64 @@ if (WIN32) endif() # set build output locations -set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") +set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) if (WIN32) - set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") else() - set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") + set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") endif() set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) -set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") +set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) # set up install sub-directories -if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND EXISTS "${CMAKE_INSTALL_PREFIX}/lib64") +if (NOT CEGUI_LIB_INSTALL_DIR) + if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND EXISTS "${CMAKE_INSTALL_PREFIX}/lib64") set( CEGUI_LIB_INSTALL_DIR lib64 ) -elseif (CMAKE_SIZEOF_VOID_P EQUAL 4 AND EXISTS "${CMAKE_INSTALL_PREFIX}/lib32") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4 AND EXISTS "${CMAKE_INSTALL_PREFIX}/lib32") set( CEGUI_LIB_INSTALL_DIR lib32 ) -else() + else() set( CEGUI_LIB_INSTALL_DIR lib ) + endif() endif() set( CEGUI_VER_INSTALL_SUBDIR "/${CMAKE_PROJECT_NAME}-${CEGUI_VERSION_MAJOR}" ) -set( CEGUI_DATA_INSTALL_DIR "share${CEGUI_VER_INSTALL_SUBDIR}" ) -set( CEGUI_DOC_INSTALL_DIR "share/doc${CEGUI_VER_INSTALL_SUBDIR}" ) -set( CEGUI_PKGCONFIG_INSTALL_DIR "${CEGUI_LIB_INSTALL_DIR}/pkgconfig" ) -set( CEGUI_MODULE_INSTALL_DIR "${CEGUI_LIB_INSTALL_DIR}/${CMAKE_PROJECT_NAME}-${CEGUI_VERSION_MAJOR}.${CEGUI_VERSION_MINOR}" ) -set( CEGUI_SAMPLE_INSTALL_DIR "${CEGUI_MODULE_INSTALL_DIR}" ) # TODO: put into /samples subdir! -set( CEGUI_INCLUDE_INSTALL_DIR "include${CEGUI_VER_INSTALL_SUBDIR}" ) +if (NOT CEGUI_DATA_INSTALL_DIR) + set( CEGUI_DATA_INSTALL_DIR "share${CEGUI_VER_INSTALL_SUBDIR}" ) +endif() + +if (NOT CEGUI_DOC_INSTALL_DIR) + set( CEGUI_DOC_INSTALL_DIR "share/doc${CEGUI_VER_INSTALL_SUBDIR}" ) +endif() + +if (NOT CEGUI_PKGCONFIG_INSTALL_DIR) + set( CEGUI_PKGCONFIG_INSTALL_DIR "${CEGUI_LIB_INSTALL_DIR}/pkgconfig" ) +endif() + +if (NOT CEGUI_MODULE_INSTALL_DIR) + set( CEGUI_MODULE_INSTALL_DIR "${CEGUI_LIB_INSTALL_DIR}/${CMAKE_PROJECT_NAME}-${CEGUI_VERSION_MAJOR}.${CEGUI_VERSION_MINOR}" ) +endif() + +if (NOT CEGUI_SAMPLE_INSTALL_DIR) + set( CEGUI_SAMPLE_INSTALL_DIR "${CEGUI_MODULE_INSTALL_DIR}" ) # TODO: put into /samples subdir! +endif() + +if (NOT CEGUI_INCLUDE_INSTALL_DIR) + set( CEGUI_INCLUDE_INSTALL_DIR "include${CEGUI_VER_INSTALL_SUBDIR}" ) +endif() ################################################################################ # Deal with files we generate from template files @@ -495,31 +631,31 @@ configure_file( doc/doxygen/doxyfile.in doc/doxygen/doxyfile ) if (UNIX AND NOT APPLE) configure_file( cegui/CEGUI.pc.in cegui/CEGUI-${CEGUI_VERSION_MAJOR}.pc @ONLY ) - install(FILES ${CMAKE_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR}) + install(FILES ${PROJECT_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR} COMPONENT cegui_devel) if (CEGUI_BUILD_RENDERER_NULL) configure_file( cegui/CEGUI-NULL.pc.in cegui/CEGUI-${CEGUI_VERSION_MAJOR}-NULL.pc @ONLY ) - install(FILES ${CMAKE_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-NULL.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR}) + install(FILES ${PROJECT_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-NULL.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR} COMPONENT cegui_devel) endif() if (CEGUI_BUILD_RENDERER_IRRLICHT) configure_file( cegui/CEGUI-IRRLICHT.pc.in cegui/CEGUI-${CEGUI_VERSION_MAJOR}-IRRLICHT.pc @ONLY ) - install(FILES ${CMAKE_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-IRRLICHT.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR}) + install(FILES ${PROJECT_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-IRRLICHT.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR} COMPONENT cegui_devel) endif() if (CEGUI_BUILD_RENDERER_OGRE) configure_file( cegui/CEGUI-OGRE.pc.in cegui/CEGUI-${CEGUI_VERSION_MAJOR}-OGRE.pc @ONLY ) - install(FILES ${CMAKE_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-OGRE.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR}) + install(FILES ${PROJECT_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-OGRE.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR} COMPONENT cegui_devel) endif() if (CEGUI_BUILD_RENDERER_OPENGL) configure_file( cegui/CEGUI-OPENGL.pc.in cegui/CEGUI-${CEGUI_VERSION_MAJOR}-OPENGL.pc @ONLY ) - install(FILES ${CMAKE_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-OPENGL.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR}) + install(FILES ${PROJECT_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-OPENGL.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR} COMPONENT cegui_devel) endif() if (CEGUI_BUILD_RENDERER_OPENGL3) configure_file( cegui/CEGUI-OPENGL3.pc.in cegui/CEGUI-${CEGUI_VERSION_MAJOR}-OPENGL3.pc @ONLY ) - install(FILES ${CMAKE_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-OPENGL3.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR}) + install(FILES ${PROJECT_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-OPENGL3.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR} COMPONENT cegui_devel) endif() if (CEGUI_BUILD_LUA_MODULE) configure_file( cegui/CEGUI-LUA.pc.in cegui/CEGUI-${CEGUI_VERSION_MAJOR}-LUA.pc @ONLY ) - install(FILES ${CMAKE_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-LUA.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR}) + install(FILES ${PROJECT_BINARY_DIR}/cegui/CEGUI-${CEGUI_VERSION_MAJOR}-LUA.pc DESTINATION ${CEGUI_PKGCONFIG_INSTALL_DIR} COMPONENT cegui_devel) endif() endif() @@ -546,12 +682,16 @@ if (CEGUI_SAMPLES_ENABLED) add_subdirectory(samples) endif() +if (CEGUI_BUILD_APPLICATION_TEMPLATES) + add_subdirectory(application_templates) +endif() + add_subdirectory(datafiles) if (DOXYGEN_FOUND) add_custom_target(html "${DOXYGEN_EXECUTABLE}" - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doc/doxygen" + WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/doc/doxygen" COMMENT "Generating documentation" VERBATIM) endif() @@ -566,8 +706,8 @@ endif() ################################################################################ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Crazy Eddie's Gui System") set(CPACK_PACKAGE_VENDOR "CEGUI team") -set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md") -set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING") +set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md") +set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING") set(CPACK_PACKAGE_VERSION_MAJOR "${CEGUI_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${CEGUI_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${CEGUI_VERSION_PATCH}") diff --git a/README.md b/README.md index a628d17cf..e50c6f580 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,18 @@ [![CEGUI logo](https://bitbucket.org/cegui/cegui-promo/raw/default/logo/ceguilogo.png)](http://www.cegui.org.uk) http://www.cegui.org.uk -Copyright ©2004 - 2014 Paul D Turner, The CEGUI Development Team and Contributing Authors +Copyright ©2004 - 2015 Paul D Turner, The CEGUI Development Team and Contributing Authors -The majority of the auxiliary files for CEGUI, that used to be plain text, are now kept in a "doxygenised" format within the doc/doxygen directory - please see those files, or generate the documentation for a more friendly format. Alternativelly, visit http://static.cegui.org.uk/docs for all your documentation needs! +The majority of the auxiliary files for CEGUI, that used to be plain text, are now kept in a "doxygenised" format within the doc/doxygen directory - please see those files, or generate the documentation for a more friendly format. Alternatively, visit http://static.cegui.org.uk/docs for all your documentation needs! What follows is just a quick-start guide, go to our doxygen docs for more detailed documentation. ## Available branches and versions - The CEGUI repository consists of multiple branches: - - `v0-8` provides the latest stable ABI compatible (to 0.8.X releases) version of CEGUI. This allows you to replace older 0.8.X versions with newer 0.8.X versions and vice-versa, without having to recompile your project. This branch is also the base for new 0.8.X releases. - - `v0` Provides the latest stable API compatible version of CEGUI and contains changes that break the ABI. Versions from this branch will be used for the next minor version release. - - `default` contains changes that will only be used in the next major version. This branch is highly unstable, will introduce fundamental changes and **breaks ABI and API** compatibility. We do not recommend you to use this in production, unless you heavily depend on a feature and discussed this with a developer of CEGUI before: This is recommended so that you are aware of all potential risks. In the general case you are advised to use one of the stable branches, to save you a lot of headache. + - `v0-8` provides the latest stable ABI compatible (to 0.8.X releases) version of CEGUI. Based on the C++03 standard and compatible with most common compilers, including Visual Studio 2008-2015. As this branch is ABI compatible, it is possible to replace CEGUI dynamic libraries of version 0.8.X with newer 0.8.X versions, or vice-versa, without having to recompile project. This branch is also the base for new 0.8.X releases. + - `v0` Provides the latest stable API compatible version of CEGUI and contains changes that break the ABI. Based on the C++03 standard and compatible with most common compilers, including Visual Studio 2008-2015. Versions from this branch will be used for the next minor version release. + - `default` contains changes that will only be used in the next major version. Based on the C++11 standard and compatible with most common up-to date compilers, including Visual Studio 2013 or newer. This branch is highly unstable, will introduce fundamental changes and **breaks ABI and API** compatibility. We do not recommend you to use this in production, unless you heavily depend on a feature and discussed this with a developer of CEGUI before: This is recommended so that you are aware of all potential risks. In the general case you are advised to use one of the stable branches, to save you a lot of headache. The `v0-8` and `v0` branches are considered stable but do undergo bug-fixes and small changes, which do not break ABI and API respectively. These changes of course introduce a small risk that there might be temporary issues for the moment in the branches. If you notice any bugs in those branches, please report them to us as soon as possible - use the [forum](http://cegui.org.uk/forum/index.php) and/or our IRC channels `#cegui` and `#cegui-devel` on `irc.freenode.net` to inform us. Please consider that we are not available on IRC 24 hours per day, but feel free to idle there until we respond. If in doubt which branch to use, also feel free to ask us this way. For production usage we generally recommend to use a stable release version. A list of releases can be found on the [on our website](cegui.org.uk/download). @@ -82,25 +82,28 @@ cd build/bin/ CEGUI_SAMPLE_DATAPATH=../../datafiles ./CEGUISampleFramework-0 ../datafiles/samples/samples.xml ``` -## We want to clarify some common misconceptions about CEGUI: +## We want to answer some questions and misconceptions: -### "It causes a DLL hell" or "Oh no, so many dll files!" -First off, the term "DLL hell" is used wrongly by users in this context. It does not mean "I see many DLL files, this must be hell!". Dynamically linking the CEGUI library is the best way to have things working as they are supposed to and guaranteeing good compatibility and a low chance of issues arising with dependencies. On Windows we heavily recommend to never use static linking with CEGUI and past experience has proven us right. A short summary of static vs dynamic linking can be found here: http://stackoverflow.com/questions/1993390/static-linking-vs-dynamic-linking +### Why are there so many dependencies? +CEGUI has relatively few **required** dependencies (currently only glm) and many **optional** dependencies. The fact that it supports many different rendering libraries and engines, many different image loaders/codecs (with pass through options) and many different xml parsers is a good thing and only an uninformed person would tell you otherwise. -### "It has useless version numbers in the dlls and executables" +### CMake tells me something was not found, is this a problem? +If CMake tells you that **something** was not found, you **shall not panic** ;) ! Most probably it's a harmless message. You should only worry if a dependency you know you need is not found or if no dependencies are found at all. In the latter case, on Windows and Mac OS X, you probably did not put the "dependencies" folder (including the dependencies compiled in Debug/Release/whatever-else-you-need) into the folder containing all CEGUI files and folders. You can also specify another folder in CMake using the variable CMAKE_PREFIX_PATH. + +### What are the version numbers in the dlls and executables good for? How to remove them? This numbering system does actually serve a very important purpose! Please let us keep them. It allows Linux distributions (and others) to install multiple CEGUI API versions alongside which eases migration and speeds up adoption of new CEGUI versions. On Windows this will allow us to provide you with precompiled CEGUI dependencies using Nuget in the future. -### "It has a killion dependencies" -CEGUI has relatively few **required** dependencies (currently only glm) and many optional dependencies. The fact that it supports many different rendering libraries and engines, many different image loaders/codecs (with pass through options) and many different xml parsers is a good thing and only an uninformed person would tell you otherwise. +### In my application, the OS cursors that is shown above the CEGUI cursor is a lot faster, why? +This is expected behaviour. First of all you should always test performance in Release mode, but even there the cursor will be slower. The reason is simply that it is very unlikely any application will have a cursor as fast as the OS cursor. Also remember that the speed is closely tied to your frame rate, so if you run the HelloWorld demo at 5000 FPS, the difference will be less but still noticable. Any game, simulation or other application out there that renders its own cursor via OpenGL/Direct3D functions similarly. However, the cursor speed is not an issue for users if your application runs at rasonable frame rates (>60 FPS) without frame drops and will not be perceived as such. Once you hide the OS cursor then the delay will probably not be noticable to you anymore. -### "CMake tells me something was not found" -If CMake tells you that **something** was not found, you **shall not panic** ;) ! Most probably it's a harmless message. You should only worry if not a single dependency was found. On Windows and Mac OS X, you should however make sure you placed the dependency folder correctly before running Cmake. +### So many DLLs, why does CEGUI cause a "DLL hell"? What about static linking? +First off, the term "DLL hell" is used wrongly in this context. It does not mean "I see many DLL files, this must be hell!". Dynamically linking the CEGUI library is the best way to have things working as they are supposed to and guaranteeing good compatibility and a low chance of issues arising with dependencies. On Windows we recommend to use dynamic linking with CEGUI rather than static linking, as past experience (some of the users ran into technical issues) has shown us that this is safer. However, if you know what you are doing you can definitely use static linking. Be aware though that we only test dynamic linking regularly, so the CMake files might be outdated and you might have to add linked libraries to your IDE yourself etc. On a positive note: in the upcoming 1.0 version we will reduce the amount of DLLs CEGUI creates by merging some of them into the Base library. A short but definitely not complete summary of advantages and disadvantages of static vs dynamic linking can be found here: http://stackoverflow.com/questions/1993390/static-linking-vs-dynamic-linking -### "It is slow" -Whenever users complained in the forums about CEGUI's speed it turned out to be that they either ran the application in Debug configuration (which, clearly, the compiler does not compile with full optimisations) or did something wrong (such as updating CEGUI the wrong way or causing unnecessary amounts of events or creating event handling functions that cause the issues on the user's side). Only occasionally it can be tracked down to a bug, but mostly that is connected to specific usage. +### Is CEGUI slower/faster than other libraries? Why is it slow in my case? +Mostly when users complained in the forums about CEGUI's speed, it turned out to be that they either ran the application in Debug config or did something wrong: It can be slow if you are loading layout resources/files every frame or causing unnecessary updates and events. Or it can be slow if you are unnecessarily updating CEGUI multiple times per frame in your program. If you cannot find the issue then it is best to perform a forum/google search and - if you do not find anything helpful - to describe your setup in detail and what issues you have. When CEGUI gets slow it can also be due to a very specific usage of specific features, which we did not expect or test. In this case we would like you to describe your use-case in the forum so we can find a solution or, if you are capable of solving the issue yourself, create a pull-request on bitbucket. -While no complex library out there will ever be perfectly optimised, CEGUI is still to be considered highly performant. CEGUI can easily compete with other GUI libraries in speed. This is true for the computations done on the CPU as well as those on the GPU and the resulting rendering speed. It still runs optimally when hundreds of windows are opened and rendered at the same time. +In general CEGUI is very fast and can easily compete with other GUI libraries in speed (especially Flash-based ones, since they do not access OpenGL or Direct3D directly). While no complex library out there will ever be perfectly optimised, CEGUI can be considered highly performant. This is true for the computations done on the CPU as well as those on the GPU. It still runs optimally when hundreds of windows are opened and rendered at the same time. -The best proof that CEGUI is fast is that big proprietary games, which displays hundreds of widgets and use complex hierarchies, have been made using CEGUI (Torchlight 1, Torchlight 2, Venetica, etc.). CEGUI is definitely not *too slow to use*. It could be too slow if you are doing something wrong - like loading layout files every frame or causing unnecessary updates and events. In this case it is best to do a forum search and - if you do not find anything helpful - to describe your setup in detail and what issues you have. +The best proof that CEGUI is fast is that big proprietary games, which displays hundreds of widgets and use complex hierarchies, have been made using CEGUI (Torchlight 1, Torchlight 2, Venetica, etc.). -We expect CEGUI to perform very well, and in a lot of cases faster than other libraries. This is epecially true for GUI libraries and toolkits that depend on Flash or similar techniques for rendering and do not access OpenGL or Direct3D directly. Most of our samples, if started in Release mode, will render at speeds above 3000 frames per second on a modern CPU and GPU. As an additional note for people who like to cite or look at benchmarks, we want you to keep in mind that benchmarks are often very situation-dependent and could easily misrepresent a library's actual speed by wrong or unusual usage. +Most of our samples, if started in Release mode, will render at speeds above 3000 frames per second on a modern CPU and GPU. As an additional note for some people who liked to cite dubious benchmarks regarding such speed comparisons: benchmarks are situation-dependent and could easily misrepresent a library's actual speed by wrong, inefficient or unusual usage. If used correctly and inside the bounds of expected usage, CEGUI performs extremely well. \ No newline at end of file diff --git a/android/CEGUISampleFramework/.classpath b/android/CEGUISampleFramework/.classpath new file mode 100644 index 000000000..d9c5f0ee3 --- /dev/null +++ b/android/CEGUISampleFramework/.classpath @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/android/CEGUISampleFramework/AndroidManifest.xml.in b/android/CEGUISampleFramework/AndroidManifest.xml.in new file mode 100644 index 000000000..ebee5ca31 --- /dev/null +++ b/android/CEGUISampleFramework/AndroidManifest.xml.in @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + diff --git a/android/CEGUISampleFramework/ant.properties.in b/android/CEGUISampleFramework/ant.properties.in new file mode 100644 index 000000000..475745ac6 --- /dev/null +++ b/android/CEGUISampleFramework/ant.properties.in @@ -0,0 +1,2 @@ +java.target=$javaVerMajor.$javaVerMinor +java.source=$javaVerMajor.$javaVerMinor diff --git a/android/CEGUISampleFramework/build.xml b/android/CEGUISampleFramework/build.xml new file mode 100644 index 000000000..a10a91491 --- /dev/null +++ b/android/CEGUISampleFramework/build.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/CEGUISampleFramework/jni/Android.mk.in b/android/CEGUISampleFramework/jni/Android.mk.in new file mode 100644 index 000000000..07bbfcea8 --- /dev/null +++ b/android/CEGUISampleFramework/jni/Android.mk.in @@ -0,0 +1,6 @@ +ceguiDepsInstallDir := $ceguiDepsInstallDir +ceguiVerMajor := $ceguiVerMajor +ceguiVerMajorMinor := $ceguiVerMajor.$ceguiVerMinor +ceguiInstallDir := $ceguiInstallDir + +include \$(call all-subdir-makefiles) diff --git a/android/CEGUISampleFramework/jni/Application.mk.in b/android/CEGUISampleFramework/jni/Application.mk.in new file mode 100644 index 000000000..601d667ab --- /dev/null +++ b/android/CEGUISampleFramework/jni/Application.mk.in @@ -0,0 +1,5 @@ +APP_PLATFORM := android-$androidNdkApiLevel +APP_ABI := $androidAbi +NDK_TOOLCHAIN_VERSION := $androidToolchainVer +APP_STL := gnustl_shared +APP_CPPFLAGS := -Wall -Wextra -fexceptions -frtti diff --git a/android/CEGUISampleFramework/jni/CEGUI/Android.mk b/android/CEGUISampleFramework/jni/CEGUI/Android.mk new file mode 100644 index 000000000..675f9050d --- /dev/null +++ b/android/CEGUISampleFramework/jni/CEGUI/Android.mk @@ -0,0 +1,51 @@ +LOCAL_PATH := $(call my-dir) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIBase +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/libCEGUIBase-$(ceguiVerMajor).so +LOCAL_EXPORT_C_INCLUDES := $(ceguiInstallDir)/include/cegui-$(ceguiVerMajor) +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUICommonDialogs +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/libCEGUICommonDialogs-$(ceguiVerMajor).so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUICoreWindowRendererSet +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUICoreWindowRendererSet.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIOpenGLRenderer +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/libCEGUIOpenGLRenderer-$(ceguiVerMajor).so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUISampleFramework +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/libCEGUISampleFramework-$(ceguiVerMajorMinor).so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIFreeImageImageCodec +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIFreeImageImageCodec.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUITinyXMLParser +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUITinyXMLParser.so +include $(PREBUILT_SHARED_LIBRARY) diff --git a/android/CEGUISampleFramework/jni/deps/Android.mk.in b/android/CEGUISampleFramework/jni/deps/Android.mk.in new file mode 100644 index 000000000..71cb8bf71 --- /dev/null +++ b/android/CEGUISampleFramework/jni/deps/Android.mk.in @@ -0,0 +1,56 @@ +LOCAL_PATH := $(call my-dir) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := ndk-missing +LOCAL_SRC_FILES := '"$ndkMissing_libFilePath"' +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := tinyxml +LOCAL_SRC_FILES := '"$tinyxmlLibFilePath"' +LOCAL_EXPORT_C_INCLUDES := '"$tinyxmlIncludePath"' +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := freeimage +LOCAL_SRC_FILES := '"$freeimageLibFilePath"' +LOCAL_EXPORT_C_INCLUDES := '"$freeimageIncludePath"' +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := pcre +LOCAL_SRC_FILES := '"$pcreLibFilePath"' +LOCAL_EXPORT_C_INCLUDES := '"$pcreIncludePath"' +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := freetype +LOCAL_SRC_FILES := '"$freetypeLibFilePath"' +LOCAL_EXPORT_C_INCLUDES := '"$freetypeIncludePath"' +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := epoxy +LOCAL_SRC_FILES := '"$epoxyLibFilePath"' +LOCAL_EXPORT_C_INCLUDES := '"$epoxyIncludePath"' +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := fribidi +LOCAL_SRC_FILES := '"$fribidiLibFilePath"' +LOCAL_EXPORT_C_INCLUDES := '"$fribidiIncludePath"' +include $(PREBUILT_SHARED_LIBRARY) diff --git a/android/CEGUISampleFramework/jni/samples/Android.mk b/android/CEGUISampleFramework/jni/samples/Android.mk new file mode 100644 index 000000000..ae6711cf0 --- /dev/null +++ b/android/CEGUISampleFramework/jni/samples/Android.mk @@ -0,0 +1,120 @@ +LOCAL_PATH := $(call my-dir) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIHelloWorldDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIHelloWorldDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUILookNFeelOverviewDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUILookNFeelOverviewDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIGameMenuDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIGameMenuDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIHUDDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIHUDDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIDragDropDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIDragDropDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIInventoryDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIInventoryDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIEffectsDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIEffectsDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIFontDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIFontDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIDemo6 +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIDemo6.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIEditboxValidationDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIEditboxValidationDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIMinesweeper +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIMinesweeper.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIScrollablePaneDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIScrollablePaneDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUITabControlDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUITabControlDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUICommonDialogsDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUICommonDialogsDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUIWidgetDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUIWidgetDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUITextDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUITextDemo.so +include $(PREBUILT_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) +LOCAL_MODULE := CEGUITreeDemo +LOCAL_SRC_FILES := $(ceguiInstallDir)/lib/cegui-$(ceguiVerMajorMinor)/libCEGUITreeDemo.so +include $(PREBUILT_SHARED_LIBRARY) diff --git a/android/CEGUISampleFramework/jni/unloadLibs/Android.mk b/android/CEGUISampleFramework/jni/unloadLibs/Android.mk new file mode 100644 index 000000000..63ddeda38 --- /dev/null +++ b/android/CEGUISampleFramework/jni/unloadLibs/Android.mk @@ -0,0 +1,7 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := unloadPreloadedConflictingNativeLibs +LOCAL_SRC_FILES := main.cpp +LOCAL_C_INCLUDES := $(ceguiInstallDir)/include/cegui-$(ceguiVerMajor) +include $(BUILD_SHARED_LIBRARY) diff --git a/android/CEGUISampleFramework/jni/unloadLibs/main.cpp b/android/CEGUISampleFramework/jni/unloadLibs/main.cpp new file mode 100644 index 000000000..6342886cb --- /dev/null +++ b/android/CEGUISampleFramework/jni/unloadLibs/main.cpp @@ -0,0 +1,64 @@ +#include "CEGUI/Base.h" + +#include +#include +#include + +extern "C" +{ + +/*! +\brief + A function for unloading a set of native libraries in an Android + application. + + This is useful in the following scenario: say that our application needs to + use a version of e.g. the PCRE library built especially for it. Now say, + that Android already contains a system version of this library (e.g. + "/system/lib/libpcre.so"), and say that this system version is already + loaded by the application. If we don't unload the system version of PCRE, + then our version (which is included in the APK) will not be used. + + So at the beginning of our Android activity we load this helper library (the + one that contains this source file), and use the following function to + unload any version of any native library included in our APK, which is not + the version included in our APK. We can find the set of full paths to the + loaded libraries by examining the file "/proc/self/maps". +*/ + +JNIEXPORT void JNICALL Java_sample_1framework_cegui_MainActivity_unloadLibs + (JNIEnv* env, jclass /*class_*/, jobjectArray libs) +{ + jsize libs_n(env->GetArrayLength(libs)); + for (jsize lib_idx(0); lib_idx < libs_n; ++lib_idx) + { + jstring lib_java(static_cast(env->GetObjectArrayElement(libs, lib_idx))); + const char* lib(env->GetStringUTFChars(lib_java, 0)); + void* lib_handle(0); + + /* You'll probably notice, in the folliwing code, that we call "dlclose" + twice. This is not a mistake. If "lib" is already loaded, "dlopen" + increases its reference count by 1. Therefore, now to eventually + decrease the reference count by 1, we need to decrease it by 2. Each + call to "dlclose" decreases it by 1, so we need to call it twice. */ +#if defined __ANDROID_API__ && __ANDROID_API__ >= 21 + for ( int lib_unload_iteration(0); lib_unload_iteration < 0x100; + ++lib_unload_iteration) + { + if ( !(lib_handle = dlopen(lib, RTLD_LAZY |RTLD_NOLOAD)) + || dlclose(lib_handle) + || dlclose(lib_handle)) + break; + } +#else + // No, this is not a mistake. + (lib_handle = dlopen(lib, RTLD_LAZY)) + && !dlclose(lib_handle) + && !dlclose(lib_handle); +#endif + env->ReleaseStringUTFChars(lib_java, lib); + env->DeleteLocalRef(lib_java); + } +} + +} // extern "C" diff --git a/android/CEGUISampleFramework/proguard-project.txt b/android/CEGUISampleFramework/proguard-project.txt new file mode 100644 index 000000000..f2fe1559a --- /dev/null +++ b/android/CEGUISampleFramework/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/android/CEGUISampleFramework/project.properties b/android/CEGUISampleFramework/project.properties new file mode 100644 index 000000000..6e18427a4 --- /dev/null +++ b/android/CEGUISampleFramework/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-21 diff --git a/android/CEGUISampleFramework/res/layout/activity_main.xml b/android/CEGUISampleFramework/res/layout/activity_main.xml new file mode 100644 index 000000000..eaea07c94 --- /dev/null +++ b/android/CEGUISampleFramework/res/layout/activity_main.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/android/CEGUISampleFramework/res/menu/main.xml b/android/CEGUISampleFramework/res/menu/main.xml new file mode 100644 index 000000000..59fa2a994 --- /dev/null +++ b/android/CEGUISampleFramework/res/menu/main.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/android/CEGUISampleFramework/res/values-v11/styles.xml b/android/CEGUISampleFramework/res/values-v11/styles.xml new file mode 100644 index 000000000..3c02242ad --- /dev/null +++ b/android/CEGUISampleFramework/res/values-v11/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/android/CEGUISampleFramework/res/values-v14/styles.xml b/android/CEGUISampleFramework/res/values-v14/styles.xml new file mode 100644 index 000000000..a91fd0372 --- /dev/null +++ b/android/CEGUISampleFramework/res/values-v14/styles.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/android/CEGUISampleFramework/res/values-w820dp/dimens.xml b/android/CEGUISampleFramework/res/values-w820dp/dimens.xml new file mode 100644 index 000000000..f3e70203b --- /dev/null +++ b/android/CEGUISampleFramework/res/values-w820dp/dimens.xml @@ -0,0 +1,10 @@ + + + + 64dp + + diff --git a/android/CEGUISampleFramework/res/values/dimens.xml b/android/CEGUISampleFramework/res/values/dimens.xml new file mode 100644 index 000000000..55c1e5908 --- /dev/null +++ b/android/CEGUISampleFramework/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + diff --git a/android/CEGUISampleFramework/res/values/strings.xml b/android/CEGUISampleFramework/res/values/strings.xml new file mode 100644 index 000000000..2916c0896 --- /dev/null +++ b/android/CEGUISampleFramework/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + CEGUI Sample Framework + Hello world! + Settings + + diff --git a/android/CEGUISampleFramework/res/values/styles.xml b/android/CEGUISampleFramework/res/values/styles.xml new file mode 100644 index 000000000..6ce89c7ba --- /dev/null +++ b/android/CEGUISampleFramework/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/android/CEGUISampleFramework/src/sample_framework/cegui/MainActivity.java b/android/CEGUISampleFramework/src/sample_framework/cegui/MainActivity.java new file mode 100644 index 000000000..05aa80370 --- /dev/null +++ b/android/CEGUISampleFramework/src/sample_framework/cegui/MainActivity.java @@ -0,0 +1,145 @@ +package sample_framework.cegui; + +import android.app.Activity; +import android.os.Bundle; +import android.util.Log; +import android.opengl.GLSurfaceView; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; +import java.util.HashSet; + +public class MainActivity extends Activity +{ + + public static String extractFileNameFromPath(String path) + { + final int dir_seperator_idx = path.lastIndexOf(File.separator); + return dir_seperator_idx >= 0 + ? path.substring(dir_seperator_idx +File.separator.length()) + : null; + } + + public void exceptionOccured(Throwable throwable) + { + Log.e ("MainActivity", "Exception thrown; aborting."); + Throwable throwableI = throwable; + do + { + Log.e ("MainActivity", "Exception type: " + + throwableI.getClass().getName()); + Log.e ("MainActivity", "Exception Message: " + + throwableI.getMessage()); + throwableI = throwableI.getCause(); + } while (throwableI != null); + finish(); + } + + public static final String s_ceguiVerMajorMinor = "0.8"; + public static final String s_unloadLibsName = + "unloadPreloadedConflictingNativeLibs"; + public static final String s_loadedLibsFilePath = "/proc/self/maps"; + public static final String s_loadedLibsFileEncoding = "UTF-8"; + + @Override + protected void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + try { + unloadLibs(); + System.loadLibrary("CEGUISampleFramework-" +s_ceguiVerMajorMinor); + d_openglSurfaceView = new GLSurfaceView(this); + d_openglSurfaceView.setEGLContextClientVersion(2); + d_openglSurfaceView.setRenderer(new Renderer(this)); + setContentView(d_openglSurfaceView); + } + catch (Throwable throwable) + { + exceptionOccured(throwable); + } + } + + @Override + protected void onDestroy() + { + nativeFinish(this); + super.onDestroy(); + } + + @Override + protected void onPause() + { + d_openglSurfaceView.onPause(); + super.onPause(); + } + + @Override + protected void onResume() + { + super.onResume(); + d_openglSurfaceView.onResume(); + } + + private static native void unloadLibs(String[] libs); + private static native void nativeFinish(Activity activity); + static native void init(Activity activity, String log_file, + String data_path_prefix); + static native void render(Activity activity); + + /* Please refer to "jni/unloadLibs/main.cpp" under the root of the project + directory for an explanation what this function does and why it's + necessary. */ + private void unloadLibs() throws IOException, FileNotFoundException + { + final String native_libs_dir = getApplicationContext() + .getApplicationInfo().nativeLibraryDir; + final File []native_libs_dir_contents = + new File(native_libs_dir).listFiles(); + HashSet native_libs = new HashSet(); + HashSet native_libs_canonical_paths = new HashSet(); + for (File file : native_libs_dir_contents) + { + final String path = file.getCanonicalPath(); + final String file_name = extractFileNameFromPath(path); + if ( file_name != null + && file_name.matches("^lib.*\\.so$") + && !file_name.equals("lib" +s_unloadLibsName +".so")) + { + native_libs.add(file_name); + native_libs_canonical_paths.add(path); + } + } + System.loadLibrary(s_unloadLibsName); + for ( int libs_unload_iteration=0; libs_unload_iteration < 0x100; + ++libs_unload_iteration) + { + HashSet native_libs_loaded = new HashSet(); + Scanner loaded_libs_scanner = new Scanner(new File + (s_loadedLibsFilePath), s_loadedLibsFileEncoding); + while (loaded_libs_scanner.hasNext()) + { + final String full_path = loaded_libs_scanner.next(); + final String canonical_path = + new File(full_path) .getCanonicalPath(); + final String file_name = + extractFileNameFromPath(canonical_path); + if ( file_name != null + && native_libs.contains(file_name) + && !native_libs_canonical_paths + .contains(canonical_path)) + native_libs_loaded.add(canonical_path); + } + loaded_libs_scanner.close(); + if (native_libs_loaded.isEmpty()) + break; + String[] libs = new String[native_libs_loaded.size()]; + native_libs_loaded.toArray(libs); + unloadLibs(libs); + } + } + + private GLSurfaceView d_openglSurfaceView = null; + +} diff --git a/android/CEGUISampleFramework/src/sample_framework/cegui/Renderer.java b/android/CEGUISampleFramework/src/sample_framework/cegui/Renderer.java new file mode 100644 index 000000000..09a6d0c30 --- /dev/null +++ b/android/CEGUISampleFramework/src/sample_framework/cegui/Renderer.java @@ -0,0 +1,41 @@ +package sample_framework.cegui; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; + +import android.opengl.GLSurfaceView; +import android.os.Environment; + +public class Renderer implements GLSurfaceView.Renderer { + private boolean d_isInitialised = false; + private MainActivity d_activity = null; + + public Renderer(MainActivity activity) + { + d_activity = activity; + } + + @Override + public void onSurfaceCreated(GL10 gl, EGLConfig config) + { + } + + @Override + public void onSurfaceChanged(GL10 gl, int width, int height) + { + } + + @Override + public void onDrawFrame(GL10 gl) + { + if (!d_isInitialised) + { + d_isInitialised = true; + final String cegui_dir = Environment.getExternalStorageDirectory() + .getAbsolutePath() +"/CEGUI"; + MainActivity.init(d_activity, cegui_dir +"/CEGUI.log", + cegui_dir +"/datafiles"); + } + MainActivity.render(d_activity); + } +} diff --git a/android/android-ndk-r10e_RELEASE.TXT b/android/android-ndk-r10e_RELEASE.TXT new file mode 100644 index 000000000..39be80140 --- /dev/null +++ b/android/android-ndk-r10e_RELEASE.TXT @@ -0,0 +1 @@ +r10e-rc4 (64-bit) diff --git a/android/android.toolchain.cmake.patch b/android/android.toolchain.cmake.patch new file mode 100644 index 000000000..267eeae66 --- /dev/null +++ b/android/android.toolchain.cmake.patch @@ -0,0 +1,42 @@ +--- android.toolchain.cmake.orig 2015-08-22 10:26:58.827289800 +0300 ++++ android.toolchain.cmake 2015-08-19 17:52:48.594447000 +0300 +@@ -1324,6 +1324,8 @@ + # linker flags + set( ANDROID_LINKER_FLAGS "" ) + ++set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -L${ANDROID_NDK}/sources/crystax/libs/${ANDROID_ABI}" ) ++ + if( ARMEABI_V7A ) + # this is *required* to use the following linker flags that routes around + # a CPU bug in some Cortex-A8 implementations: +@@ -1523,10 +1525,9 @@ + set( BUILD_ANDROID True ) + + # where is the target environment +-set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) ++set( CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) + +-# only search for libraries and includes in the ndk toolchain +-set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) ++set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + +@@ -1547,7 +1548,7 @@ + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) +- set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) ++ set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + endmacro() +@@ -1569,7 +1570,7 @@ + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) +- set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) ++ set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + endmacro() diff --git a/android/android.toolchain.cmake__orig b/android/android.toolchain.cmake__orig new file mode 100644 index 000000000..ffa26126a --- /dev/null +++ b/android/android.toolchain.cmake__orig @@ -0,0 +1,1693 @@ +# Copyright (c) 2010-2011, Ethan Rublee +# Copyright (c) 2011-2014, Andrey Kamaev +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. 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. +# +# 3. Neither the name of the copyright holder nor the names of its +# 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. + +# ------------------------------------------------------------------------------ +# Android CMake toolchain file, for use with the Android NDK r5-r10d +# Requires cmake 2.6.3 or newer (2.8.9 or newer is recommended). +# See home page: https://github.com/taka-no-me/android-cmake +# +# Usage Linux: +# $ export ANDROID_NDK=/absolute/path/to/the/android-ndk +# $ mkdir build && cd build +# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. +# $ make -j8 +# +# Usage Windows: +# You need native port of make to build your project. +# Android NDK r7 (and newer) already has make.exe on board. +# For older NDK you have to install it separately. +# For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm +# +# $ SET ANDROID_NDK=C:\absolute\path\to\the\android-ndk +# $ mkdir build && cd build +# $ cmake.exe -G"MinGW Makefiles" +# -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake +# -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" .. +# $ cmake.exe --build . +# +# +# Options (can be set as cmake parameters: -D=): +# ANDROID_NDK=/opt/android-ndk - path to the NDK root. +# Can be set as environment variable. Can be set only at first cmake run. +# +# ANDROID_ABI=armeabi-v7a - specifies the target Application Binary +# Interface (ABI). This option nearly matches to the APP_ABI variable +# used by ndk-build tool from Android NDK. +# +# Possible targets are: +# "armeabi" - ARMv5TE based CPU with software floating point operations +# "armeabi-v7a" - ARMv7 based devices with hardware FPU instructions +# this ABI target is used by default +# "armeabi-v7a with NEON" - same as armeabi-v7a, but +# sets NEON as floating-point unit +# "armeabi-v7a with VFPV3" - same as armeabi-v7a, but +# sets VFPV3 as floating-point unit (has 32 registers instead of 16) +# "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP +# "x86" - IA-32 instruction set +# "mips" - MIPS32 instruction set +# +# 64-bit ABIs for NDK r10 and newer: +# "arm64-v8a" - ARMv8 AArch64 instruction set +# "x86_64" - Intel64 instruction set (r1) +# "mips64" - MIPS64 instruction set (r6) +# +# ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for. +# Option is read-only when standalone toolchain is used. +# Note: building for "android-L" requires explicit configuration. +# +# ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 - the name of compiler +# toolchain to be used. The list of possible values depends on the NDK +# version. For NDK r10c the possible values are: +# +# * aarch64-linux-android-4.9 +# * aarch64-linux-android-clang3.4 +# * aarch64-linux-android-clang3.5 +# * arm-linux-androideabi-4.6 +# * arm-linux-androideabi-4.8 +# * arm-linux-androideabi-4.9 (default) +# * arm-linux-androideabi-clang3.4 +# * arm-linux-androideabi-clang3.5 +# * mips64el-linux-android-4.9 +# * mips64el-linux-android-clang3.4 +# * mips64el-linux-android-clang3.5 +# * mipsel-linux-android-4.6 +# * mipsel-linux-android-4.8 +# * mipsel-linux-android-4.9 +# * mipsel-linux-android-clang3.4 +# * mipsel-linux-android-clang3.5 +# * x86-4.6 +# * x86-4.8 +# * x86-4.9 +# * x86-clang3.4 +# * x86-clang3.5 +# * x86_64-4.9 +# * x86_64-clang3.4 +# * x86_64-clang3.5 +# +# ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions +# instead of Thumb. Is not available for "armeabi-v6 with VFP" +# (is forced to be ON) ABI. +# +# ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker +# errors even if they are not used. +# +# ANDROID_SO_UNDEFINED=OFF - set ON to allow undefined symbols in shared +# libraries. Automatically turned for NDK r5x and r6x due to GLESv2 +# problems. +# +# ANDROID_STL=gnustl_static - specify the runtime to use. +# +# Possible values are: +# none -> Do not configure the runtime. +# system -> Use the default minimal system C++ runtime library. +# Implies -fno-rtti -fno-exceptions. +# Is not available for standalone toolchain. +# system_re -> Use the default minimal system C++ runtime library. +# Implies -frtti -fexceptions. +# Is not available for standalone toolchain. +# gabi++_static -> Use the GAbi++ runtime as a static library. +# Implies -frtti -fno-exceptions. +# Available for NDK r7 and newer. +# Is not available for standalone toolchain. +# gabi++_shared -> Use the GAbi++ runtime as a shared library. +# Implies -frtti -fno-exceptions. +# Available for NDK r7 and newer. +# Is not available for standalone toolchain. +# stlport_static -> Use the STLport runtime as a static library. +# Implies -fno-rtti -fno-exceptions for NDK before r7. +# Implies -frtti -fno-exceptions for NDK r7 and newer. +# Is not available for standalone toolchain. +# stlport_shared -> Use the STLport runtime as a shared library. +# Implies -fno-rtti -fno-exceptions for NDK before r7. +# Implies -frtti -fno-exceptions for NDK r7 and newer. +# Is not available for standalone toolchain. +# gnustl_static -> Use the GNU STL as a static library. +# Implies -frtti -fexceptions. +# gnustl_shared -> Use the GNU STL as a shared library. +# Implies -frtti -fno-exceptions. +# Available for NDK r7b and newer. +# Silently degrades to gnustl_static if not available. +# +# ANDROID_STL_FORCE_FEATURES=ON - turn rtti and exceptions support based on +# chosen runtime. If disabled, then the user is responsible for settings +# these options. +# +# What?: +# android-cmake toolchain searches for NDK/toolchain in the following order: +# ANDROID_NDK - cmake parameter +# ANDROID_NDK - environment variable +# ANDROID_STANDALONE_TOOLCHAIN - cmake parameter +# ANDROID_STANDALONE_TOOLCHAIN - environment variable +# ANDROID_NDK - default locations +# ANDROID_STANDALONE_TOOLCHAIN - default locations +# +# Make sure to do the following in your scripts: +# SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" ) +# SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" ) +# The flags will be prepopulated with critical flags, so don't loose them. +# Also be aware that toolchain also sets configuration-specific compiler +# flags and linker flags. +# +# ANDROID and BUILD_ANDROID will be set to true, you may test any of these +# variables to make necessary Android-specific configuration changes. +# +# Also ARMEABI or ARMEABI_V7A or X86 or MIPS or ARM64_V8A or X86_64 or MIPS64 +# will be set true, mutually exclusive. NEON option will be set true +# if VFP is set to NEON. +# +# ------------------------------------------------------------------------------ + +cmake_minimum_required( VERSION 2.6.3 ) + +if( DEFINED CMAKE_CROSSCOMPILING ) + # subsequent toolchain loading is not really needed + return() +endif() + +if( CMAKE_TOOLCHAIN_FILE ) + # touch toolchain variable to suppress "unused variable" warning +endif() + +# inherit settings in recursive loads +get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE ) +if( _CMAKE_IN_TRY_COMPILE ) + include( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL ) +endif() + +# this one is important +if( CMAKE_VERSION VERSION_GREATER "3.0.99" ) + set( CMAKE_SYSTEM_NAME Android ) +else() + set( CMAKE_SYSTEM_NAME Linux ) +endif() + +# this one not so much +set( CMAKE_SYSTEM_VERSION 1 ) + +# rpath makes low sense for Android +set( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "" ) +set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." ) + +# NDK search paths +set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r10d -r10c -r10b -r10 -r9d -r9c -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) +if( NOT DEFINED ANDROID_NDK_SEARCH_PATHS ) + if( CMAKE_HOST_WIN32 ) + file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) + set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}" "$ENV{SystemDrive}/NVPACK" ) + else() + file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS ) + set( ANDROID_NDK_SEARCH_PATHS /opt "${ANDROID_NDK_SEARCH_PATHS}/NVPACK" ) + endif() +endif() +if( NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH ) + set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain ) +endif() + +# known ABIs +set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" ) +set( ANDROID_SUPPORTED_ABIS_arm64 "arm64-v8a" ) +set( ANDROID_SUPPORTED_ABIS_x86 "x86" ) +set( ANDROID_SUPPORTED_ABIS_x86_64 "x86_64" ) +set( ANDROID_SUPPORTED_ABIS_mips "mips" ) +set( ANDROID_SUPPORTED_ABIS_mips64 "mips64" ) + +# API level defaults +set( ANDROID_DEFAULT_NDK_API_LEVEL 8 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_arm64 21 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_x86_64 21 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_mips64 21 ) + + +macro( __LIST_FILTER listvar regex ) + if( ${listvar} ) + foreach( __val ${${listvar}} ) + if( __val MATCHES "${regex}" ) + list( REMOVE_ITEM ${listvar} "${__val}" ) + endif() + endforeach() + endif() +endmacro() + +macro( __INIT_VARIABLE var_name ) + set( __test_path 0 ) + foreach( __var ${ARGN} ) + if( __var STREQUAL "PATH" ) + set( __test_path 1 ) + break() + endif() + endforeach() + + if( __test_path AND NOT EXISTS "${${var_name}}" ) + unset( ${var_name} CACHE ) + endif() + + if( " ${${var_name}}" STREQUAL " " ) + set( __values 0 ) + foreach( __var ${ARGN} ) + if( __var STREQUAL "VALUES" ) + set( __values 1 ) + elseif( NOT __var STREQUAL "PATH" ) + if( __var MATCHES "^ENV_.*$" ) + string( REPLACE "ENV_" "" __var "${__var}" ) + set( __value "$ENV{${__var}}" ) + elseif( DEFINED ${__var} ) + set( __value "${${__var}}" ) + elseif( __values ) + set( __value "${__var}" ) + else() + set( __value "" ) + endif() + + if( NOT " ${__value}" STREQUAL " " AND (NOT __test_path OR EXISTS "${__value}") ) + set( ${var_name} "${__value}" ) + break() + endif() + endif() + endforeach() + unset( __value ) + unset( __values ) + endif() + + if( __test_path ) + file( TO_CMAKE_PATH "${${var_name}}" ${var_name} ) + endif() + unset( __test_path ) +endmacro() + +macro( __DETECT_NATIVE_API_LEVEL _var _path ) + set( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*.*$" ) + file( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) + if( NOT __apiFileContent ) + message( SEND_ERROR "Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) + endif() + string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" ) + unset( __apiFileContent ) + unset( __ndkApiLevelRegex ) +endmacro() + +macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) + if( EXISTS "${_root}" ) + file( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) + __LIST_FILTER( __gccExePath "^[.].*" ) + list( LENGTH __gccExePath __gccExePathsCount ) + if( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE ) + message( WARNING "Could not determine machine name for compiler from ${_root}" ) + set( ${_var} "" ) + else() + get_filename_component( __gccExeName "${__gccExePath}" NAME_WE ) + string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" ) + endif() + unset( __gccExePath ) + unset( __gccExePathsCount ) + unset( __gccExeName ) + else() + set( ${_var} "" ) + endif() +endmacro() + + +# fight against cygwin +set( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools") +mark_as_advanced( ANDROID_FORBID_SYGWIN ) +if( ANDROID_FORBID_SYGWIN ) + if( CYGWIN ) + message( FATAL_ERROR "Android NDK and android-cmake toolchain are not welcome Cygwin. It is unlikely that this cmake toolchain will work under cygwin. But if you want to try then you can set cmake variable ANDROID_FORBID_SYGWIN to FALSE and rerun cmake." ) + endif() + + if( CMAKE_HOST_WIN32 ) + # remove cygwin from PATH + set( __new_path "$ENV{PATH}") + __LIST_FILTER( __new_path "cygwin" ) + set(ENV{PATH} "${__new_path}") + unset(__new_path) + endif() +endif() + + +# detect current host platform +if( NOT DEFINED ANDROID_NDK_HOST_X64 AND (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64" OR CMAKE_HOST_APPLE) ) + set( ANDROID_NDK_HOST_X64 1 CACHE BOOL "Try to use 64-bit compiler toolchain" ) + mark_as_advanced( ANDROID_NDK_HOST_X64 ) +endif() + +set( TOOL_OS_SUFFIX "" ) +if( CMAKE_HOST_APPLE ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" ) + set( ANDROID_NDK_HOST_SYSTEM_NAME2 "darwin-x86" ) +elseif( CMAKE_HOST_WIN32 ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" ) + set( ANDROID_NDK_HOST_SYSTEM_NAME2 "windows" ) + set( TOOL_OS_SUFFIX ".exe" ) +elseif( CMAKE_HOST_UNIX ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" ) + set( ANDROID_NDK_HOST_SYSTEM_NAME2 "linux-x86" ) +else() + message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) +endif() + +if( NOT ANDROID_NDK_HOST_X64 ) + set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) +endif() + +# see if we have path to Android NDK +if( NOT ANDROID_NDK AND NOT ANDROID_STANDALONE_TOOLCHAIN ) + __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK ) +endif() +if( NOT ANDROID_NDK ) + # see if we have path to Android standalone toolchain + __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN ) + + if( NOT ANDROID_STANDALONE_TOOLCHAIN ) + #try to find Android NDK in one of the the default locations + set( __ndkSearchPaths ) + foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} ) + foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} ) + list( APPEND __ndkSearchPaths "${__ndkSearchPath}/android-ndk${suffix}" ) + endforeach() + endforeach() + __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} ) + unset( __ndkSearchPaths ) + + if( ANDROID_NDK ) + message( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" ) + message( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" ) + else() + #try to find Android standalone toolchain in one of the the default locations + __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH ) + + if( ANDROID_STANDALONE_TOOLCHAIN ) + message( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" ) + message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" ) + endif( ANDROID_STANDALONE_TOOLCHAIN ) + endif( ANDROID_NDK ) + endif( NOT ANDROID_STANDALONE_TOOLCHAIN ) +endif( NOT ANDROID_NDK ) + +# remember found paths +if( ANDROID_NDK ) + get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE ) + set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" FORCE ) + set( BUILD_WITH_ANDROID_NDK True ) + if( EXISTS "${ANDROID_NDK}/RELEASE.TXT" ) + file( STRINGS "${ANDROID_NDK}/RELEASE.TXT" ANDROID_NDK_RELEASE_FULL LIMIT_COUNT 1 REGEX "r[0-9]+[a-z]?" ) + string( REGEX MATCH "r([0-9]+)([a-z]?)" ANDROID_NDK_RELEASE "${ANDROID_NDK_RELEASE_FULL}" ) + else() + set( ANDROID_NDK_RELEASE "r1x" ) + set( ANDROID_NDK_RELEASE_FULL "unreleased" ) + endif() + string( REGEX REPLACE "r([0-9]+)([a-z]?)" "\\1*1000" ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE}" ) + string( FIND " abcdefghijklmnopqastuvwxyz" "${CMAKE_MATCH_2}" __ndkReleaseLetterNum ) + math( EXPR ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE_NUM}+${__ndkReleaseLetterNum}" ) +elseif( ANDROID_STANDALONE_TOOLCHAIN ) + get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE ) + # try to detect change + if( CMAKE_AR ) + string( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length ) + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidStandaloneToolchainPreviousPath ) + if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN ) + message( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." ) + endif() + unset( __androidStandaloneToolchainPreviousPath ) + unset( __length ) + endif() + set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" FORCE ) + set( BUILD_WITH_STANDALONE_TOOLCHAIN True ) +else() + list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH) + message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolchain. + You should either set an environment variable: + export ANDROID_NDK=~/my-android-ndk + or + export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain + or put the toolchain or NDK in the default path: + sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH}/android-ndk + sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" ) +endif() + +# android NDK layout +if( BUILD_WITH_ANDROID_NDK ) + if( NOT DEFINED ANDROID_NDK_LAYOUT ) + # try to automatically detect the layout + if( EXISTS "${ANDROID_NDK}/RELEASE.TXT") + set( ANDROID_NDK_LAYOUT "RELEASE" ) + elseif( EXISTS "${ANDROID_NDK}/../../linux-x86/toolchain/" ) + set( ANDROID_NDK_LAYOUT "LINARO" ) + elseif( EXISTS "${ANDROID_NDK}/../../gcc/" ) + set( ANDROID_NDK_LAYOUT "ANDROID" ) + endif() + endif() + set( ANDROID_NDK_LAYOUT "${ANDROID_NDK_LAYOUT}" CACHE STRING "The inner layout of NDK" ) + mark_as_advanced( ANDROID_NDK_LAYOUT ) + if( ANDROID_NDK_LAYOUT STREQUAL "LINARO" ) + set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment + set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../${ANDROID_NDK_HOST_SYSTEM_NAME}/toolchain" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" ) + elseif( ANDROID_NDK_LAYOUT STREQUAL "ANDROID" ) + set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment + set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../gcc/${ANDROID_NDK_HOST_SYSTEM_NAME}/arm" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" ) + else() # ANDROID_NDK_LAYOUT STREQUAL "RELEASE" + set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/toolchains" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME2}" ) + endif() + get_filename_component( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK_TOOLCHAINS_PATH}" ABSOLUTE ) + + # try to detect change of NDK + if( CMAKE_AR ) + string( LENGTH "${ANDROID_NDK_TOOLCHAINS_PATH}" __length ) + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath ) + if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK_TOOLCHAINS_PATH ) + message( FATAL_ERROR "It is not possible to change the path to the NDK on subsequent CMake run. You must remove all generated files from your build folder first. + " ) + endif() + unset( __androidNdkPreviousPath ) + unset( __length ) + endif() +endif() + + +# get all the details about standalone toolchain +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" ) + set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) + set( __availableToolchains "standalone" ) + __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" ) + if( NOT __availableToolchainMachines ) + message( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." ) + endif() + if( __availableToolchainMachines MATCHES x86_64 ) + set( __availableToolchainArchs "x86_64" ) + elseif( __availableToolchainMachines MATCHES i686 ) + set( __availableToolchainArchs "x86" ) + elseif( __availableToolchainMachines MATCHES aarch64 ) + set( __availableToolchainArchs "arm64" ) + elseif( __availableToolchainMachines MATCHES arm ) + set( __availableToolchainArchs "arm" ) + elseif( __availableToolchainMachines MATCHES mips64el ) + set( __availableToolchainArchs "mips64" ) + elseif( __availableToolchainMachines MATCHES mipsel ) + set( __availableToolchainArchs "mips" ) + endif() + execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" -dumpversion + OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) + if( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${TOOL_OS_SUFFIX}" ) + list( APPEND __availableToolchains "standalone-clang" ) + list( APPEND __availableToolchainMachines ${__availableToolchainMachines} ) + list( APPEND __availableToolchainArchs ${__availableToolchainArchs} ) + list( APPEND __availableToolchainCompilerVersions ${__availableToolchainCompilerVersions} ) + endif() +endif() + +macro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar __availableToolchainsLst __toolchain_subpath ) + foreach( __toolchain ${${__availableToolchainsLst}} ) + if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" ) + SET( __toolchainVersionRegex "^TOOLCHAIN_VERSION[\t ]+:=[\t ]+(.*)$" ) + FILE( STRINGS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}/setup.mk" __toolchainVersionStr REGEX "${__toolchainVersionRegex}" ) + if( __toolchainVersionStr ) + string( REGEX REPLACE "${__toolchainVersionRegex}" "\\1" __toolchainVersionStr "${__toolchainVersionStr}" ) + string( REGEX REPLACE "-clang3[.][0-9]$" "-${__toolchainVersionStr}" __gcc_toolchain "${__toolchain}" ) + else() + string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" ) + endif() + unset( __toolchainVersionStr ) + unset( __toolchainVersionRegex ) + else() + set( __gcc_toolchain "${__toolchain}" ) + endif() + __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" ) + if( __machine ) + string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" ) + if( __machine MATCHES x86_64 ) + set( __arch "x86_64" ) + elseif( __machine MATCHES i686 ) + set( __arch "x86" ) + elseif( __machine MATCHES aarch64 ) + set( __arch "arm64" ) + elseif( __machine MATCHES arm ) + set( __arch "arm" ) + elseif( __machine MATCHES mips64el ) + set( __arch "mips64" ) + elseif( __machine MATCHES mipsel ) + set( __arch "mips" ) + else() + set( __arch "" ) + endif() + #message("machine: !${__machine}!\narch: !${__arch}!\nversion: !${__version}!\ntoolchain: !${__toolchain}!\n") + if (__arch) + list( APPEND __availableToolchainMachines "${__machine}" ) + list( APPEND __availableToolchainArchs "${__arch}" ) + list( APPEND __availableToolchainCompilerVersions "${__version}" ) + list( APPEND ${__availableToolchainsVar} "${__toolchain}" ) + endif() + endif() + unset( __gcc_toolchain ) + endforeach() +endmacro() + +# get all the details about NDK +if( BUILD_WITH_ANDROID_NDK ) + file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" ) + string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) + set( __availableToolchains "" ) + set( __availableToolchainMachines "" ) + set( __availableToolchainArchs "" ) + set( __availableToolchainCompilerVersions "" ) + if( ANDROID_TOOLCHAIN_NAME AND EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_TOOLCHAIN_NAME}/" ) + # do not go through all toolchains if we know the name + set( __availableToolchainsLst "${ANDROID_TOOLCHAIN_NAME}" ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) + if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" ) + if( __availableToolchains ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} ) + endif() + endif() + endif() + if( NOT __availableToolchains ) + file( GLOB __availableToolchainsLst RELATIVE "${ANDROID_NDK_TOOLCHAINS_PATH}" "${ANDROID_NDK_TOOLCHAINS_PATH}/*" ) + if( __availableToolchainsLst ) + list(SORT __availableToolchainsLst) # we need clang to go after gcc + endif() + __LIST_FILTER( __availableToolchainsLst "^[.]" ) + __LIST_FILTER( __availableToolchainsLst "llvm" ) + __LIST_FILTER( __availableToolchainsLst "renderscript" ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) + if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" ) + if( __availableToolchains ) + set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} ) + endif() + endif() + endif() + if( NOT __availableToolchains ) + message( FATAL_ERROR "Could not find any working toolchain in the NDK. Probably your Android NDK is broken." ) + endif() +endif() + +# build list of available ABIs +set( ANDROID_SUPPORTED_ABIS "" ) +set( __uniqToolchainArchNames ${__availableToolchainArchs} ) +list( REMOVE_DUPLICATES __uniqToolchainArchNames ) +list( SORT __uniqToolchainArchNames ) +foreach( __arch ${__uniqToolchainArchNames} ) + list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) +endforeach() +unset( __uniqToolchainArchNames ) +if( NOT ANDROID_SUPPORTED_ABIS ) + message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) +endif() + +# choose target ABI +__INIT_VARIABLE( ANDROID_ABI VALUES ${ANDROID_SUPPORTED_ABIS} ) +# verify that target ABI is supported +list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx ) +if( __androidAbiIdx EQUAL -1 ) + string( REPLACE ";" "\", \"" PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" ) + message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain. + Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\" + " ) +endif() +unset( __androidAbiIdx ) + +# set target ABI options +if( ANDROID_ABI STREQUAL "x86" ) + set( X86 true ) + set( ANDROID_NDK_ABI_NAME "x86" ) + set( ANDROID_ARCH_NAME "x86" ) + set( ANDROID_LLVM_TRIPLE "i686-none-linux-android" ) + set( CMAKE_SYSTEM_PROCESSOR "i686" ) +elseif( ANDROID_ABI STREQUAL "x86_64" ) + set( X86 true ) + set( X86_64 true ) + set( ANDROID_NDK_ABI_NAME "x86_64" ) + set( ANDROID_ARCH_NAME "x86_64" ) + set( CMAKE_SYSTEM_PROCESSOR "x86_64" ) + set( ANDROID_LLVM_TRIPLE "x86_64-none-linux-android" ) +elseif( ANDROID_ABI STREQUAL "mips64" ) + set( MIPS64 true ) + set( ANDROID_NDK_ABI_NAME "mips64" ) + set( ANDROID_ARCH_NAME "mips64" ) + set( ANDROID_LLVM_TRIPLE "mips64el-none-linux-android" ) + set( CMAKE_SYSTEM_PROCESSOR "mips64" ) +elseif( ANDROID_ABI STREQUAL "mips" ) + set( MIPS true ) + set( ANDROID_NDK_ABI_NAME "mips" ) + set( ANDROID_ARCH_NAME "mips" ) + set( ANDROID_LLVM_TRIPLE "mipsel-none-linux-android" ) + set( CMAKE_SYSTEM_PROCESSOR "mips" ) +elseif( ANDROID_ABI STREQUAL "arm64-v8a" ) + set( ARM64_V8A true ) + set( ANDROID_NDK_ABI_NAME "arm64-v8a" ) + set( ANDROID_ARCH_NAME "arm64" ) + set( ANDROID_LLVM_TRIPLE "aarch64-none-linux-android" ) + set( CMAKE_SYSTEM_PROCESSOR "aarch64" ) + set( VFPV3 true ) + set( NEON true ) +elseif( ANDROID_ABI STREQUAL "armeabi" ) + set( ARMEABI true ) + set( ANDROID_NDK_ABI_NAME "armeabi" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) +elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" ) + set( ARMEABI_V6 true ) + set( ANDROID_NDK_ABI_NAME "armeabi" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv6" ) + # need always fallback to older platform + set( ARMEABI true ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a") + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" ) + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) + set( VFPV3 true ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) + set( VFPV3 true ) + set( NEON true ) +else() + message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." ) +endif() + +if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" ) + # really dirty hack + # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run... + file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" ) +endif() + +if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) + __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD VALUES OFF ) + set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE ) + mark_as_advanced( ANDROID_FORCE_ARM_BUILD ) +else() + unset( ANDROID_FORCE_ARM_BUILD CACHE ) +endif() + +# choose toolchain +if( ANDROID_TOOLCHAIN_NAME ) + list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx ) + if( __toolchainIdx EQUAL -1 ) + list( SORT __availableToolchains ) + string( REPLACE ";" "\n * " toolchains_list "${__availableToolchains}" ) + set( toolchains_list " * ${toolchains_list}") + message( FATAL_ERROR "Specified toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing in your NDK or broken. Please verify that your NDK is working or select another compiler toolchain. +To configure the toolchain set CMake variable ANDROID_TOOLCHAIN_NAME to one of the following values:\n${toolchains_list}\n" ) + endif() + list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch ) + if( NOT __toolchainArch STREQUAL ANDROID_ARCH_NAME ) + message( SEND_ERROR "Selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) + endif() +else() + set( __toolchainIdx -1 ) + set( __applicableToolchains "" ) + set( __toolchainMaxVersion "0.0.0" ) + list( LENGTH __availableToolchains __availableToolchainsCount ) + math( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" ) + foreach( __idx RANGE ${__availableToolchainsCount} ) + list( GET __availableToolchainArchs ${__idx} __toolchainArch ) + if( __toolchainArch STREQUAL ANDROID_ARCH_NAME ) + list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion ) + string( REPLACE "x" "99" __toolchainVersion "${__toolchainVersion}") + if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion ) + set( __toolchainMaxVersion "${__toolchainVersion}" ) + set( __toolchainIdx ${__idx} ) + endif() + endif() + endforeach() + unset( __availableToolchainsCount ) + unset( __toolchainMaxVersion ) + unset( __toolchainVersion ) +endif() +unset( __toolchainArch ) +if( __toolchainIdx EQUAL -1 ) + message( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." ) +endif() +list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME ) +list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME ) +list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION ) + +unset( __toolchainIdx ) +unset( __availableToolchains ) +unset( __availableToolchainMachines ) +unset( __availableToolchainArchs ) +unset( __availableToolchainCompilerVersions ) + +# choose native API level +__INIT_VARIABLE( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL ) +string( REPLACE "android-" "" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" ) +string( STRIP "${ANDROID_NATIVE_API_LEVEL}" ANDROID_NATIVE_API_LEVEL ) +# adjust API level +set( __real_api_level ${ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME}} ) +foreach( __level ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) + if( (__level LESS ANDROID_NATIVE_API_LEVEL OR __level STREQUAL ANDROID_NATIVE_API_LEVEL) AND NOT __level LESS __real_api_level ) + set( __real_api_level ${__level} ) + endif() +endforeach() +if( __real_api_level AND NOT ANDROID_NATIVE_API_LEVEL STREQUAL __real_api_level ) + message( STATUS "Adjusting Android API level 'android-${ANDROID_NATIVE_API_LEVEL}' to 'android-${__real_api_level}'") + set( ANDROID_NATIVE_API_LEVEL ${__real_api_level} ) +endif() +unset(__real_api_level) +# validate +list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) +if( __levelIdx EQUAL -1 ) + message( SEND_ERROR "Specified Android native API level 'android-${ANDROID_NATIVE_API_LEVEL}' is not supported by your NDK/toolchain." ) +else() + if( BUILD_WITH_ANDROID_NDK ) + __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) + if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL AND NOT __realApiLevel GREATER 9000 ) + message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) + endif() + unset( __realApiLevel ) + endif() + set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) + set( CMAKE_ANDROID_API ${ANDROID_NATIVE_API_LEVEL} ) + if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) + set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) + endif() +endif() +unset( __levelIdx ) + + +# remember target ABI +set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) +if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} ) + set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} ) +endif() + + +# runtime choice (STL, rtti, exceptions) +if( NOT ANDROID_STL ) + set( ANDROID_STL gnustl_static ) +endif() +set( ANDROID_STL "${ANDROID_STL}" CACHE STRING "C++ runtime" ) +set( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL "automatically configure rtti and exceptions support based on C++ runtime" ) +mark_as_advanced( ANDROID_STL ANDROID_STL_FORCE_FEATURES ) + +if( BUILD_WITH_ANDROID_NDK ) + if( NOT "${ANDROID_STL}" MATCHES "^(none|system|system_re|gabi\\+\\+_static|gabi\\+\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared)$") + message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\". +The possible values are: + none -> Do not configure the runtime. + system -> Use the default minimal system C++ runtime library. + system_re -> Same as system but with rtti and exceptions. + gabi++_static -> Use the GAbi++ runtime as a static library. + gabi++_shared -> Use the GAbi++ runtime as a shared library. + stlport_static -> Use the STLport runtime as a static library. + stlport_shared -> Use the STLport runtime as a shared library. + gnustl_static -> (default) Use the GNU STL as a static library. + gnustl_shared -> Use the GNU STL as a shared library. +" ) + endif() +elseif( BUILD_WITH_STANDALONE_TOOLCHAIN ) + if( NOT "${ANDROID_STL}" MATCHES "^(none|gnustl_static|gnustl_shared)$") + message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\". +The possible values are: + none -> Do not configure the runtime. + gnustl_static -> (default) Use the GNU STL as a static library. + gnustl_shared -> Use the GNU STL as a shared library. +" ) + endif() +endif() + +unset( ANDROID_RTTI ) +unset( ANDROID_EXCEPTIONS ) +unset( ANDROID_STL_INCLUDE_DIRS ) +unset( __libstl ) +unset( __libsupcxx ) + +if( NOT _CMAKE_IN_TRY_COMPILE AND ANDROID_NDK_RELEASE STREQUAL "r7b" AND ARMEABI_V7A AND NOT VFPV3 AND ANDROID_STL MATCHES "gnustl" ) + message( WARNING "The GNU STL armeabi-v7a binaries from NDK r7b can crash non-NEON devices. The files provided with NDK r7b were not configured properly, resulting in crashes on Tegra2-based devices and others when trying to use certain floating-point functions (e.g., cosf, sinf, expf). +You are strongly recommended to switch to another NDK release. +" ) +endif() + +if( NOT _CMAKE_IN_TRY_COMPILE AND X86 AND ANDROID_STL MATCHES "gnustl" AND ANDROID_NDK_RELEASE STREQUAL "r6" ) + message( WARNING "The x86 system header file from NDK r6 has incorrect definition for ptrdiff_t. You are recommended to upgrade to a newer NDK release or manually patch the header: +See https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc8093df6fee54454b8bcab6c2 + diff --git a/ndk/platforms/android-9/arch-x86/include/machine/_types.h b/ndk/platforms/android-9/arch-x86/include/machine/_types.h + index 5e28c64..65892a1 100644 + --- a/ndk/platforms/android-9/arch-x86/include/machine/_types.h + +++ b/ndk/platforms/android-9/arch-x86/include/machine/_types.h + @@ -51,7 +51,11 @@ typedef long int ssize_t; + #endif + #ifndef _PTRDIFF_T + #define _PTRDIFF_T + -typedef long ptrdiff_t; + +# ifdef __ANDROID__ + + typedef int ptrdiff_t; + +# else + + typedef long ptrdiff_t; + +# endif + #endif +" ) +endif() + + +# setup paths and STL for standalone toolchain +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) + + if( NOT ANDROID_STL STREQUAL "none" ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}" ) + if( NOT EXISTS "${ANDROID_STL_INCLUDE_DIRS}" ) + # old location ( pre r8c ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) + endif() + if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) + else() + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) + endif() + # always search static GNU STL to get the location of libsupc++.a + if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) + elseif( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" ) + elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) + endif() + if( __libstl ) + set( __libsupcxx "${__libstl}/libsupc++.a" ) + set( __libstl "${__libstl}/libstdc++.a" ) + endif() + if( NOT EXISTS "${__libsupcxx}" ) + message( FATAL_ERROR "The required libstdsupc++.a is missing in your standalone toolchain. + Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c. + You need to either upgrade to newer NDK or manually copy + $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a + to + ${__libsupcxx} + " ) + endif() + if( ANDROID_STL STREQUAL "gnustl_shared" ) + if( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) + elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) + endif() + endif() + endif() +endif() + +# clang +if( "${ANDROID_TOOLCHAIN_NAME}" STREQUAL "standalone-clang" ) + set( ANDROID_COMPILER_IS_CLANG 1 ) + execute_process( COMMAND "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/clang${TOOL_OS_SUFFIX}" --version OUTPUT_VARIABLE ANDROID_CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+[.][0-9]+" ANDROID_CLANG_VERSION "${ANDROID_CLANG_VERSION}") +elseif( "${ANDROID_TOOLCHAIN_NAME}" MATCHES "-clang3[.][0-9]?$" ) + string( REGEX MATCH "3[.][0-9]$" ANDROID_CLANG_VERSION "${ANDROID_TOOLCHAIN_NAME}") + string( REGEX REPLACE "-clang${ANDROID_CLANG_VERSION}$" "-${ANDROID_COMPILER_VERSION}" ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) + if( NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}/bin/clang${TOOL_OS_SUFFIX}" ) + message( FATAL_ERROR "Could not find the Clang compiler driver" ) + endif() + set( ANDROID_COMPILER_IS_CLANG 1 ) + set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) +else() + set( ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) + unset( ANDROID_COMPILER_IS_CLANG CACHE ) +endif() + +string( REPLACE "." "" _clang_name "clang${ANDROID_CLANG_VERSION}" ) +if( NOT EXISTS "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" ) + set( _clang_name "clang" ) +endif() + + +# setup paths and STL for NDK +if( BUILD_WITH_ANDROID_NDK ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) + set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) + + if( ANDROID_STL STREQUAL "none" ) + # do nothing + elseif( ANDROID_STL STREQUAL "system" ) + set( ANDROID_RTTI OFF ) + set( ANDROID_EXCEPTIONS OFF ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" ) + elseif( ANDROID_STL STREQUAL "system_re" ) + set( ANDROID_RTTI ON ) + set( ANDROID_EXCEPTIONS ON ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" ) + elseif( ANDROID_STL MATCHES "gabi" ) + if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 + message( FATAL_ERROR "gabi++ is not available in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.") + endif() + set( ANDROID_RTTI ON ) + set( ANDROID_EXCEPTIONS OFF ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/gabi++/include" ) + set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${ANDROID_NDK_ABI_NAME}/libgabi++_static.a" ) + elseif( ANDROID_STL MATCHES "stlport" ) + if( NOT ANDROID_NDK_RELEASE_NUM LESS 8004 ) # before r8d + set( ANDROID_EXCEPTIONS ON ) + else() + set( ANDROID_EXCEPTIONS OFF ) + endif() + if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 + set( ANDROID_RTTI OFF ) + else() + set( ANDROID_RTTI ON ) + endif() + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" ) + set( __libstl "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}/libstlport_static.a" ) + elseif( ANDROID_STL MATCHES "gnustl" ) + set( ANDROID_EXCEPTIONS ON ) + set( ANDROID_RTTI ON ) + if( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) + if( ARMEABI_V7A AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.7" AND ANDROID_NDK_RELEASE STREQUAL "r8d" ) + # gnustl binary for 4.7 compiler is buggy :( + # TODO: look for right fix + set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.6" ) + else() + set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) + endif() + else() + set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" ) + endif() + set( ANDROID_STL_INCLUDE_DIRS "${__libstl}/include" "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/include" "${__libstl}/include/backward" ) + if( EXISTS "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" ) + set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" ) + else() + set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" ) + endif() + else() + message( FATAL_ERROR "Unknown runtime: ${ANDROID_STL}" ) + endif() + # find libsupc++.a - rtti & exceptions + if( ANDROID_STL STREQUAL "system_re" OR ANDROID_STL MATCHES "gnustl" ) + set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r8b or newer + if( NOT EXISTS "${__libsupcxx}" ) + set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r7-r8 + endif() + if( NOT EXISTS "${__libsupcxx}" ) # before r7 + if( ARMEABI_V7A ) + if( ANDROID_FORCE_ARM_BUILD ) + set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" ) + else() + set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" ) + endif() + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD ) + set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" ) + else() + set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" ) + endif() + endif() + if( NOT EXISTS "${__libsupcxx}") + message( ERROR "Could not find libsupc++.a for a chosen platform. Either your NDK is not supported or is broken.") + endif() + endif() +endif() + + +# case of shared STL linkage +if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl ) + string( REPLACE "_static.a" "_shared.so" __libstl "${__libstl}" ) + # TODO: check if .so file exists before the renaming +endif() + + +# ccache support +__INIT_VARIABLE( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE ) +if( _ndk_ccache ) + if( DEFINED NDK_CCACHE AND NOT EXISTS NDK_CCACHE ) + unset( NDK_CCACHE CACHE ) + endif() + find_program( NDK_CCACHE "${_ndk_ccache}" DOC "The path to ccache binary") +else() + unset( NDK_CCACHE CACHE ) +endif() +unset( _ndk_ccache ) + + +# setup the cross-compiler +if( NOT CMAKE_C_COMPILER ) + if( NDK_CCACHE AND NOT ANDROID_SYSROOT MATCHES "[ ;\"]" ) + set( CMAKE_C_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C compiler" ) + set( CMAKE_CXX_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C++ compiler" ) + if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + else() + set( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + endif() + else() + if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + else() + set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" ) + set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" ) + endif() + endif() + set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" ) + set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) + if( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" ) + # Use gcc-ar if we have it for better LTO support. + set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) + else() + set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) + endif() + set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" ) + set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" ) + set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" ) + set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" ) + set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" ) +endif() + +set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" ) +if( CMAKE_VERSION VERSION_LESS 2.8.5 ) + set( CMAKE_ASM_COMPILER_ARG1 "-c" ) +endif() +if( APPLE ) + find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool ) + if( NOT CMAKE_INSTALL_NAME_TOOL ) + message( FATAL_ERROR "Could not find install_name_tool, please check your installation." ) + endif() + mark_as_advanced( CMAKE_INSTALL_NAME_TOOL ) +endif() + +# Force set compilers because standard identification works badly for us +include( CMakeForceCompiler ) +CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU ) +if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER_ID Clang ) +endif() +set( CMAKE_C_PLATFORM_ID Linux ) +if( X86_64 OR MIPS64 OR ARM64_V8A ) + set( CMAKE_C_SIZEOF_DATA_PTR 8 ) +else() + set( CMAKE_C_SIZEOF_DATA_PTR 4 ) +endif() +set( CMAKE_C_HAS_ISYSROOT 1 ) +set( CMAKE_C_COMPILER_ABI ELF ) +CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU ) +if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_CXX_COMPILER_ID Clang) +endif() +set( CMAKE_CXX_PLATFORM_ID Linux ) +set( CMAKE_CXX_SIZEOF_DATA_PTR ${CMAKE_C_SIZEOF_DATA_PTR} ) +set( CMAKE_CXX_HAS_ISYSROOT 1 ) +set( CMAKE_CXX_COMPILER_ABI ELF ) +set( CMAKE_CXX_SOURCE_FILE_EXTENSIONS cc cp cxx cpp CPP c++ C ) +# force ASM compiler (required for CMake < 2.8.5) +set( CMAKE_ASM_COMPILER_ID_RUN TRUE ) +set( CMAKE_ASM_COMPILER_ID GNU ) +set( CMAKE_ASM_COMPILER_WORKS TRUE ) +set( CMAKE_ASM_COMPILER_FORCED TRUE ) +set( CMAKE_COMPILER_IS_GNUASM 1) +set( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s S asm ) + +foreach( lang C CXX ASM ) + if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_${lang}_COMPILER_VERSION ${ANDROID_CLANG_VERSION} ) + else() + set( CMAKE_${lang}_COMPILER_VERSION ${ANDROID_COMPILER_VERSION} ) + endif() +endforeach() + +# flags and definitions +remove_definitions( -DANDROID ) +add_definitions( -DANDROID ) + +if( ANDROID_SYSROOT MATCHES "[ ;\"]" ) + if( CMAKE_HOST_WIN32 ) + # try to convert path to 8.3 form + file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "@echo %~s1" ) + execute_process( COMMAND "$ENV{ComSpec}" /c "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "${ANDROID_SYSROOT}" + OUTPUT_VARIABLE __path OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE __result ERROR_QUIET ) + if( __result EQUAL 0 ) + file( TO_CMAKE_PATH "${__path}" ANDROID_SYSROOT ) + set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) + else() + set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" ) + endif() + else() + set( ANDROID_CXX_FLAGS "'--sysroot=${ANDROID_SYSROOT}'" ) + endif() + if( NOT _CMAKE_IN_TRY_COMPILE ) + # quotes can break try_compile and compiler identification + message(WARNING "Path to your Android NDK (or toolchain) has non-alphanumeric symbols.\nThe build might be broken.\n") + endif() +else() + set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) +endif() + +# NDK flags +if (ARM64_V8A ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" ) + set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" ) + set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" ) + if( NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" ) + endif() +elseif( ARMEABI OR ARMEABI_V7A) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" ) + if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 ) + set( ANDROID_CXX_FLAGS_RELEASE "-mthumb -fomit-frame-pointer -fno-strict-aliasing" ) + set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" ) + if( NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -finline-limit=64" ) + endif() + else() + # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI + set( ANDROID_CXX_FLAGS_RELEASE "-marm -fomit-frame-pointer -fstrict-aliasing" ) + set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" ) + if( NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" ) + endif() + endif() +elseif( X86 OR X86_64 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" ) + if( NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" ) + endif() + set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" ) + set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" ) +elseif( MIPS OR MIPS64 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-strict-aliasing -finline-functions -funwind-tables -fmessage-length=0" ) + set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer" ) + set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer" ) + if( NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" ) + set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" ) + endif() +elseif() + set( ANDROID_CXX_FLAGS_RELEASE "" ) + set( ANDROID_CXX_FLAGS_DEBUG "" ) +endif() + +set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) # good/necessary when porting desktop libraries + +if( NOT X86 AND NOT ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "-Wno-psabi ${ANDROID_CXX_FLAGS}" ) +endif() + +if( NOT ANDROID_COMPILER_VERSION VERSION_LESS "4.6" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -no-canonical-prefixes" ) # see https://android-review.googlesource.com/#/c/47564/ +endif() + +# ABI-specific flags +if( ARMEABI_V7A ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) + if( NEON ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" ) + elseif( VFPV3 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" ) + else() + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" ) + endif() +elseif( ARMEABI_V6 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) # vfp == vfpv2 +elseif( ARMEABI ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) +endif() + +if( ANDROID_STL MATCHES "gnustl" AND (EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}") ) + set( CMAKE_CXX_CREATE_SHARED_LIBRARY " -o " ) + set( CMAKE_CXX_CREATE_SHARED_MODULE " -o " ) + set( CMAKE_CXX_LINK_EXECUTABLE " -o " ) +else() + set( CMAKE_CXX_CREATE_SHARED_LIBRARY " -o " ) + set( CMAKE_CXX_CREATE_SHARED_MODULE " -o " ) + set( CMAKE_CXX_LINK_EXECUTABLE " -o " ) +endif() + +# STL +if( EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}" ) + if( EXISTS "${__libstl}" ) + set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libstl}\"" ) + set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libstl}\"" ) + set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libstl}\"" ) + endif() + if( EXISTS "${__libsupcxx}" ) + set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" ) + set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" ) + set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libsupcxx}\"" ) + # C objects: + set( CMAKE_C_CREATE_SHARED_LIBRARY " -o " ) + set( CMAKE_C_CREATE_SHARED_MODULE " -o " ) + set( CMAKE_C_LINK_EXECUTABLE " -o " ) + set( CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" ) + set( CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" ) + set( CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} \"${__libsupcxx}\"" ) + endif() + if( ANDROID_STL MATCHES "gnustl" ) + if( NOT EXISTS "${ANDROID_LIBM_PATH}" ) + set( ANDROID_LIBM_PATH -lm ) + endif() + set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} ${ANDROID_LIBM_PATH}" ) + set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} ${ANDROID_LIBM_PATH}" ) + set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${ANDROID_LIBM_PATH}" ) + endif() +endif() + +# variables controlling optional build flags +if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 + # libGLESv2.so in NDK's prior to r7 refers to missing external symbols. + # So this flag option is required for all projects using OpenGL from native. + __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES ON ) +else() + __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF ) +endif() +__INIT_VARIABLE( ANDROID_NO_UNDEFINED VALUES ON ) +__INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON ) +__INIT_VARIABLE( ANDROID_GOLD_LINKER VALUES ON ) +__INIT_VARIABLE( ANDROID_NOEXECSTACK VALUES ON ) +__INIT_VARIABLE( ANDROID_RELRO VALUES ON ) + +set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" ) +set( ANDROID_SO_UNDEFINED ${ANDROID_SO_UNDEFINED} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" ) +set( ANDROID_FUNCTION_LEVEL_LINKING ${ANDROID_FUNCTION_LEVEL_LINKING} CACHE BOOL "Put each function in separate section and enable garbage collection of unused input sections at link time" ) +set( ANDROID_GOLD_LINKER ${ANDROID_GOLD_LINKER} CACHE BOOL "Enables gold linker" ) +set( ANDROID_NOEXECSTACK ${ANDROID_NOEXECSTACK} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" ) +set( ANDROID_RELRO ${ANDROID_RELRO} CACHE BOOL "Enables RELRO - a memory corruption mitigation technique" ) +mark_as_advanced( ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_FUNCTION_LEVEL_LINKING ANDROID_GOLD_LINKER ANDROID_NOEXECSTACK ANDROID_RELRO ) + +# linker flags +set( ANDROID_LINKER_FLAGS "" ) + +if( ARMEABI_V7A ) + # this is *required* to use the following linker flags that routes around + # a CPU bug in some Cortex-A8 implementations: + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8" ) +endif() + +if( ANDROID_NO_UNDEFINED ) + if( MIPS ) + # there is some sysroot-related problem in mips linker... + if( NOT ANDROID_SYSROOT MATCHES "[ ;\"]" ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined -Wl,-rpath-link,${ANDROID_SYSROOT}/usr/lib" ) + endif() + else() + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined" ) + endif() +endif() + +if( ANDROID_SO_UNDEFINED ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" ) +endif() + +if( ANDROID_FUNCTION_LEVEL_LINKING ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" ) +endif() + +if( ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" ) + if( ANDROID_GOLD_LINKER AND (CMAKE_HOST_UNIX OR ANDROID_NDK_RELEASE_NUM GREATER 8002) AND (ARMEABI OR ARMEABI_V7A OR X86) ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" ) + elseif( ANDROID_NDK_RELEASE_NUM GREATER 8002 ) # after r8b + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=bfd" ) + elseif( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND NOT _CMAKE_IN_TRY_COMPILE ) + message( WARNING "The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342 + On Linux and OS X host platform you can workaround this problem using gold linker (default). + Rerun cmake with -DANDROID_GOLD_LINKER=ON option in case of problems. +" ) + endif() +endif() # version 4.6 + +if( ANDROID_NOEXECSTACK ) + if( ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Xclang -mnoexecstack" ) + else() + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" ) + endif() + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack" ) +endif() + +if( ANDROID_RELRO ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now" ) +endif() + +if( ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "-target ${ANDROID_LLVM_TRIPLE} -Qunused-arguments ${ANDROID_CXX_FLAGS}" ) + if( BUILD_WITH_ANDROID_NDK ) + set( ANDROID_CXX_FLAGS "-gcc-toolchain ${ANDROID_TOOLCHAIN_ROOT} ${ANDROID_CXX_FLAGS}" ) + endif() +endif() + +# cache flags +set( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" ) +set( CMAKE_C_FLAGS "" CACHE STRING "c flags" ) +set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c++ Release flags" ) +set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c Release flags" ) +set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c++ Debug flags" ) +set( CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c Debug flags" ) +set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags" ) +set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "module linker flags" ) +set( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "executable linker flags" ) + +# put flags to cache (for debug purpose only) +set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Android specific c/c++ flags" ) +set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE}" CACHE INTERNAL "Android specific c/c++ Release flags" ) +set( ANDROID_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG}" CACHE INTERNAL "Android specific c/c++ Debug flags" ) +set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Android specific c/c++ linker flags" ) + +# finish flags +set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" ) +set( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" ) +set( CMAKE_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}" ) +set( CMAKE_C_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}" ) +set( CMAKE_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}" ) +set( CMAKE_C_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}" ) +set( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" ) +set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" ) +set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) + +if( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" ) + set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" ) + set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" ) + set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" ) +endif() + +# pie/pic +if( NOT (ANDROID_NATIVE_API_LEVEL LESS 16) AND (NOT DEFINED ANDROID_APP_PIE OR ANDROID_APP_PIE) AND (CMAKE_VERSION VERSION_GREATER 2.8.8) ) + set( CMAKE_POSITION_INDEPENDENT_CODE TRUE ) + set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie") +else() + set( CMAKE_POSITION_INDEPENDENT_CODE FALSE ) + set( CMAKE_CXX_FLAGS "-fpic ${CMAKE_CXX_FLAGS}" ) + set( CMAKE_C_FLAGS "-fpic ${CMAKE_C_FLAGS}" ) +endif() + +# configure rtti +if( DEFINED ANDROID_RTTI AND ANDROID_STL_FORCE_FEATURES ) + if( ANDROID_RTTI ) + set( CMAKE_CXX_FLAGS "-frtti ${CMAKE_CXX_FLAGS}" ) + else() + set( CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}" ) + endif() +endif() + +# configure exceptios +if( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES ) + if( ANDROID_EXCEPTIONS ) + set( CMAKE_CXX_FLAGS "-fexceptions ${CMAKE_CXX_FLAGS}" ) + set( CMAKE_C_FLAGS "-fexceptions ${CMAKE_C_FLAGS}" ) + else() + set( CMAKE_CXX_FLAGS "-fno-exceptions ${CMAKE_CXX_FLAGS}" ) + set( CMAKE_C_FLAGS "-fno-exceptions ${CMAKE_C_FLAGS}" ) + endif() +endif() + +# global includes and link directories +include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} ) +get_filename_component(__android_install_path "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ABSOLUTE) # avoid CMP0015 policy warning +link_directories( "${__android_install_path}" ) + +# detect if need link crtbegin_so.o explicitly +if( NOT DEFINED ANDROID_EXPLICIT_CRT_LINK ) + set( __cmd "${CMAKE_CXX_CREATE_SHARED_LIBRARY}" ) + string( REPLACE "" "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" __cmd "${__cmd}" ) + string( REPLACE "" "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}" __cmd "${__cmd}" ) + string( REPLACE "" "${CMAKE_CXX_FLAGS}" __cmd "${__cmd}" ) + string( REPLACE "" "" __cmd "${__cmd}" ) + string( REPLACE "" "${CMAKE_SHARED_LINKER_FLAGS}" __cmd "${__cmd}" ) + string( REPLACE "" "-shared" __cmd "${__cmd}" ) + string( REPLACE "" "" __cmd "${__cmd}" ) + string( REPLACE "" "" __cmd "${__cmd}" ) + string( REPLACE "" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toolchain_crtlink_test.so" __cmd "${__cmd}" ) + string( REPLACE "" "\"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" __cmd "${__cmd}" ) + string( REPLACE "" "" __cmd "${__cmd}" ) + separate_arguments( __cmd ) + foreach( __var ANDROID_NDK ANDROID_NDK_TOOLCHAINS_PATH ANDROID_STANDALONE_TOOLCHAIN ) + if( ${__var} ) + set( __tmp "${${__var}}" ) + separate_arguments( __tmp ) + string( REPLACE "${__tmp}" "${${__var}}" __cmd "${__cmd}") + endif() + endforeach() + string( REPLACE "'" "" __cmd "${__cmd}" ) + string( REPLACE "\"" "" __cmd "${__cmd}" ) + execute_process( COMMAND ${__cmd} RESULT_VARIABLE __cmd_result OUTPUT_QUIET ERROR_QUIET ) + if( __cmd_result EQUAL 0 ) + set( ANDROID_EXPLICIT_CRT_LINK ON ) + else() + set( ANDROID_EXPLICIT_CRT_LINK OFF ) + endif() +endif() + +if( ANDROID_EXPLICIT_CRT_LINK ) + set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" ) + set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" ) +endif() + +# setup output directories +set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) + +if( DEFINED LIBRARY_OUTPUT_PATH_ROOT + OR EXISTS "${CMAKE_SOURCE_DIR}/AndroidManifest.xml" + OR (EXISTS "${CMAKE_SOURCE_DIR}/../AndroidManifest.xml" AND EXISTS "${CMAKE_SOURCE_DIR}/../jni/") ) + set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "Root for binaries output, set this to change where Android libs are installed to" ) + if( NOT _CMAKE_IN_TRY_COMPILE ) + if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) + else() + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) + endif() + set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for Android libs" ) + endif() +endif() + +# copy shaed stl library to build directory +if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" AND DEFINED LIBRARY_OUTPUT_PATH ) + get_filename_component( __libstlname "${__libstl}" NAME ) + execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess ) + if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}") + message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" ) + endif() + unset( __fileCopyProcess ) + unset( __libstlname ) +endif() + + +# set these global flags for cmake client scripts to change behavior +set( ANDROID True ) +set( BUILD_ANDROID True ) + +# where is the target environment +set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) + +# only search for libraries and includes in the ndk toolchain +set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + + +# macro to find packages on the host OS +macro( find_host_package ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_package( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endmacro() + + +# macro to find programs on the host OS +macro( find_host_program ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_program( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endmacro() + + +# export toolchain settings for the try_compile() command +if( NOT _CMAKE_IN_TRY_COMPILE ) + set( __toolchain_config "") + foreach( __var NDK_CCACHE LIBRARY_OUTPUT_PATH_ROOT ANDROID_FORBID_SYGWIN + ANDROID_NDK_HOST_X64 + ANDROID_NDK + ANDROID_NDK_LAYOUT + ANDROID_STANDALONE_TOOLCHAIN + ANDROID_TOOLCHAIN_NAME + ANDROID_ABI + ANDROID_NATIVE_API_LEVEL + ANDROID_STL + ANDROID_STL_FORCE_FEATURES + ANDROID_FORCE_ARM_BUILD + ANDROID_NO_UNDEFINED + ANDROID_SO_UNDEFINED + ANDROID_FUNCTION_LEVEL_LINKING + ANDROID_GOLD_LINKER + ANDROID_NOEXECSTACK + ANDROID_RELRO + ANDROID_LIBM_PATH + ANDROID_EXPLICIT_CRT_LINK + ANDROID_APP_PIE + ) + if( DEFINED ${__var} ) + if( ${__var} MATCHES " ") + set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" ) + else() + set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" ) + endif() + endif() + endforeach() + file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" ) + unset( __toolchain_config ) +endif() + + +# force cmake to produce / instead of \ in build commands for Ninja generator +if( CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_HOST_WIN32 ) + # it is a bad hack after all + # CMake generates Ninja makefiles with UNIX paths only if it thinks that we are going to build with MinGW + set( CMAKE_COMPILER_IS_MINGW TRUE ) # tell CMake that we are MinGW + set( CMAKE_CROSSCOMPILING TRUE ) # stop recursion + enable_language( C ) + enable_language( CXX ) + # unset( CMAKE_COMPILER_IS_MINGW ) # can't unset because CMake does not convert back-slashes in response files without it + unset( MINGW ) +endif() + + +# Variables controlling behavior or set by cmake toolchain: +# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips", "arm64-v8a", "x86_64", "mips64" +# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14,15,16,17,18,19,21 (depends on NDK version) +# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none +# ANDROID_FORBID_SYGWIN : ON/OFF +# ANDROID_NO_UNDEFINED : ON/OFF +# ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version) +# ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF +# ANDROID_GOLD_LINKER : ON/OFF +# ANDROID_NOEXECSTACK : ON/OFF +# ANDROID_RELRO : ON/OFF +# ANDROID_FORCE_ARM_BUILD : ON/OFF +# ANDROID_STL_FORCE_FEATURES : ON/OFF +# ANDROID_LIBM_PATH : path to libm.so (set to something like $(TOP)/out/target/product//obj/lib/libm.so) to workaround unresolved `sincos` +# Can be set only at the first run: +# ANDROID_NDK : path to your NDK install +# NDK_CCACHE : path to your ccache executable +# ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain +# ANDROID_NDK_HOST_X64 : try to use x86_64 toolchain (default for x64 host systems) +# ANDROID_NDK_LAYOUT : the inner NDK structure (RELEASE, LINARO, ANDROID) +# LIBRARY_OUTPUT_PATH_ROOT : +# ANDROID_STANDALONE_TOOLCHAIN +# +# Primary read-only variables: +# ANDROID : always TRUE +# ARMEABI : TRUE for arm v6 and older devices +# ARMEABI_V6 : TRUE for arm v6 +# ARMEABI_V7A : TRUE for arm v7a +# ARM64_V8A : TRUE for arm64-v8a +# NEON : TRUE if NEON unit is enabled +# VFPV3 : TRUE if VFP version 3 is enabled +# X86 : TRUE if configured for x86 +# X86_64 : TRUE if configured for x86_64 +# MIPS : TRUE if configured for mips +# MIPS64 : TRUE if configured for mips64 +# BUILD_WITH_ANDROID_NDK : TRUE if NDK is used +# BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used +# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform +# ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86", "mips", "arm64-v8a", "x86_64", "mips64" depending on ANDROID_ABI +# ANDROID_NDK_RELEASE : from r5 to r10d; set only for NDK +# ANDROID_NDK_RELEASE_NUM : numeric ANDROID_NDK_RELEASE version (1000*major+minor) +# ANDROID_ARCH_NAME : "arm", "x86", "mips", "arm64", "x86_64", "mips64" depending on ANDROID_ABI +# ANDROID_SYSROOT : path to the compiler sysroot +# TOOL_OS_SUFFIX : "" or ".exe" depending on host platform +# ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used +# +# Secondary (less stable) read-only variables: +# ANDROID_COMPILER_VERSION : GCC version used (not Clang version) +# ANDROID_CLANG_VERSION : version of clang compiler if clang is used +# ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform +# ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI +# ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux" +# ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK) +# ANDROID_CLANG_TOOLCHAIN_ROOT : path to clang tools +# ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK +# ANDROID_STL_INCLUDE_DIRS : stl include paths +# ANDROID_RTTI : if rtti is enabled by the runtime +# ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime +# ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used +# +# Defaults: +# ANDROID_DEFAULT_NDK_API_LEVEL +# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH} +# ANDROID_NDK_SEARCH_PATHS +# ANDROID_SUPPORTED_ABIS_${ARCH} +# ANDROID_SUPPORTED_NDK_VERSIONS diff --git a/android/build_cegui b/android/build_cegui new file mode 100755 index 000000000..c46fa931d --- /dev/null +++ b/android/build_cegui @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +myScriptsDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +. "$myScriptsDir/common" + +"$myScriptsDir/build_deps" + +if [ $? -eq 0 ]; then + + dirRequiresSudo "$ceguiInstallDir" ceguiInstallDirMaybeSudo + + depsInstallDirsElements=('$tinyxmlInstallDir' \ + '$freeimageInstallDir' \ + '$glmInstallDir' \ + '$pcreInstallDir' \ + '$freetypeInstallDir' \ + '$epoxyInstallDir' \ + '$fribidiInstallDir') + + depsInstallDirs() + { + if [ ${#depsInstallDirsElements[@]} -ne 0 ]; then + declare -i depIndex + depIndex=0 + while true; do + echo -n "${depsInstallDirsElements[$depIndex]}" + depIndex=$(($depIndex+1)) + if [ $depIndex -eq ${#depsInstallDirsElements[@]} ]; then + break; + fi + echo -n \; + done + fi + } + + ceguiCmakeOptionsElements=('-DCEGUI_SAMPLES_ENABLED=ON' \ + '-DCEGUI_BUILD_RENDERER_OPENGL=OFF' \ + '-DCEGUI_BUILD_RENDERER_OPENGL3=ON' \ + '-DCEGUI_USE_EPOXY=ON' \ + '-DCEGUI_USE_GLEW=OFF' \ + '-DCEGUI_TINYXML_HAS_2_6_API=TRUE' \ + '-DCEGUI_USE_MINIBIDI=OFF' \ + '-DCEGUI_USE_FRIBIDI=ON' \ + "-DCMAKE_FIND_ROOT_PATH=\"$(depsInstallDirs)\"") + ceguiCmakeOptions="${ceguiCmakeOptionsElements[*]}" + + ceguiBuild() + { + + if [ ! -d "$ceguiInstallDir" ]; then + + if [ ! -d "$ceguiSrcDir" ]; then + echo "Error: CEGUI source dir \"$ceguiSrcDir\" doesn't exist." + exit -1 + fi + + if [ ! -d "$ceguiBuildDir" ]; then + mkdir -p "$ceguiBuildDir" + cd "$ceguiBuildDir" + eval myCmake '""' $androidCmakeOptions $ceguiCmakeOptions \ + '-DCMAKE_INSTALL_PREFIX="$ceguiInstallDir"' \ + '-DCMAKE_BUILD_TYPE="$ceguiBuildType" "$ceguiSrcDir"' + fi + + cd "$ceguiBuildDir" + myMake "" "-j$buildNumOfProcesses" + + fi + + } + + ceguiInstall() + { + if [ ! -d "$ceguiInstallDir" ]; then + cd "$ceguiBuildDir" + myMake "$ceguiInstallDirMaybeSudo" install + fi + } + + ceguiBuild && ceguiInstall + if [ $? -eq 0 ]; then + echo $'\n'"Building CEGUI succeeded!" + true; + else + echo $'\n'"Building CEGUI failed!" + false; + fi + +fi diff --git a/android/build_deps b/android/build_deps new file mode 100755 index 000000000..bb3bdef7f --- /dev/null +++ b/android/build_deps @@ -0,0 +1,358 @@ +#!/usr/bin/env bash +myScriptsDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +. "$myScriptsDir/common" + +"$myScriptsDir/prepare_ndk" + +if [ $? -eq 0 ]; then + + mkdir -p "$ceguiDepsDownloadsDir" "$ceguiDepsSrcDir" "$ceguiDepsBuildDir" + dirRequiresSudo "$ceguiDepsInstallDir" depsInstallDirMaybeSudo + + buildNdkMissing() + { + + if [ ! -d "$ndkMissing_installDir" ]; then + + if [ ! -d "$ndkMissing_buildDir" ]; then + mkdir -p "$ndkMissing_buildDir" + cd "$ndkMissing_buildDir" + eval myCmake '""' $androidCmakeOptions \ + '-DCMAKE_INSTALL_PREFIX="$ndkMissing_installDir"' \ + '-DCMAKE_BUILD_TYPE="$ceguiDepsBuildType"' \ + '"$ndkMissing_srcDir"' + fi + + cd "$ndkMissing_buildDir" + myMake "" "-j$buildNumOfProcesses" + + fi + + } + + installNdkMissing() + { + if [ ! -d "$ndkMissing_installDir" ]; then + cd "$ndkMissing_buildDir" + myMake "$depsInstallDirMaybeSudo" install + fi + } + + buildTinyxml() + { + + if [ ! -d "$tinyxmlInstallDir" ]; then + + if [ ! -d "$tinyxmlSrcDir" ]; then + cd "$ceguiDepsSrcDir" + if [ ! -f "$ceguiDepsDownloadsDir/$tinyxmlPackageArchive" ]; \ + then + myWget "" "$ceguiDepsDownloadsDir/$tinyxmlPackageArchive" \ + "$tinyxmlPackageUri" + fi + myUnpackTarGz "" "$ceguiDepsDownloadsDir/$tinyxmlPackageArchive" + mv "$tinyxmlPackageDir" "$tinyxmlSrcDir" + cp "$myScriptsDir/tinyxml-CMakeLists.txt" \ + "$tinyxmlSrcDir/CMakeLists.txt" + fi + + if [ ! -d "$tinyxmlBuildDir" ]; then + mkdir -p "$tinyxmlBuildDir" + cd "$tinyxmlBuildDir" + eval myCmake '""' $androidCmakeOptions \ + '-DCMAKE_INSTALL_PREFIX="$tinyxmlInstallDir"' \ + '-DCMAKE_BUILD_TYPE="$ceguiDepsBuildType"' \ + '"$tinyxmlSrcDir"' + fi + + cd "$tinyxmlBuildDir" + myMake "" "-j$buildNumOfProcesses" + + fi + + } + + installTinyxml() + { + if [ ! -d "$tinyxmlInstallDir" ]; then + cd "$tinyxmlBuildDir" + myMake "$depsInstallDirMaybeSudo" install + fi + } + + freeimageMakeParams="-f Makefile.gnu $androidToolchainConfiguration $androidBuildOptions DESTDIR=\"\$freeimageInstallDir\" ndkMissing_dir=\"\$ndkMissing_installDir\"" + + buildFreeimage() + { + + addToolchainToPath + + if [ ! -d "$freeimageInstallDir" ]; then + + if [ ! -d "$freeimageSrcDir" ]; then + cd "$ceguiDepsSrcDir" + if [ ! -f "$ceguiDepsDownloadsDir/$freeimagePackageArchive" ]; \ + then + myWget "" \ + "$ceguiDepsDownloadsDir/$freeimagePackageArchive" \ + "$freeimagePackageUri" + fi + myUnpackZip "" "$ceguiDepsDownloadsDir/$freeimagePackageArchive" + mv "$freeimagePackageDir" "$freeimageSrcDir" + myPatchDir "" "$freeimageSrcDir" "$myScriptsDir/freeimage.patch" + fi + + if [ ! -d "$freeimageBuildDir" ]; then + cp -r "$freeimageSrcDir" "$freeimageBuildDir" + fi + + cd "$freeimageBuildDir" + eval myMake '""' "-j$buildNumOfProcesses" $freeimageMakeParams + + fi + } + + installFreeimage() + { + addToolchainToPath + if [ ! -d "$freeimageInstallDir" ]; then + cd "$freeimageBuildDir" + eval myMake '"$depsInstallDirMaybeSudo"' $freeimageMakeParams \ + install + fi + } + + buildGlm() + { + + if [ ! -d "$glmInstallDir" ]; then + + if [ ! -d "$glmSrcDir" ]; then + cd "$ceguiDepsSrcDir" + if [ ! -f "$ceguiDepsDownloadsDir/$glmPackageArchive" ]; then + myWget "" "$ceguiDepsDownloadsDir/$glmPackageArchive" \ + "$glmPackageUri" + fi + myUnpack7z "" "$ceguiDepsDownloadsDir/$glmPackageArchive" + mv "$glmPackageDir" "$glmSrcDir" + fi + + if [ ! -d "$glmBuildDir" ]; then + mkdir -p "$glmBuildDir" + cd "$glmBuildDir" + eval myCmake '""' $androidCmakeOptions \ + '-DCMAKE_INSTALL_PREFIX="$glmInstallDir"' \ + '-DCMAKE_BUILD_TYPE="$ceguiDepsBuildType"' \ + '"$glmSrcDir"' + fi + + cd "$glmBuildDir" + myMake "" "-j$buildNumOfProcesses" + + fi + + } + + installGlm() + { + if [ ! -d "$glmInstallDir" ]; then + cd "$glmBuildDir" + myMake "$depsInstallDirMaybeSudo" install + fi + } + + buildPcre() + { + + addToolchainToPath + + if [ ! -d "$pcreInstallDir" ]; then + + if [ ! -d "$pcreSrcDir" ]; then + cd "$ceguiDepsSrcDir" + if [ ! -f "$ceguiDepsDownloadsDir/$pcrePackageArchive" ]; then + myWget "" "$ceguiDepsDownloadsDir/$pcrePackageArchive" \ + "$pcrePackageUri" + fi + myUnpackTarBz2 "" "$ceguiDepsDownloadsDir/$pcrePackageArchive" + mv "$pcrePackageDir" "$pcreSrcDir" + fi + + if [ ! -d "$pcreBuildDir" ]; then + mkdir -p "$pcreBuildDir" + cd "$pcreBuildDir" + eval '"$pcreSrcDir/configure" --prefix="$pcreInstallDir"' \ + '--host="$androidToolchainName" --enable-unicode-properties' + '--disable-rebuild-chartables' $androidAutotoolsOptions + fi + + cd "$pcreBuildDir" + myMake "" "-j$buildNumOfProcesses" V=1 + + fi + + } + + installPcre() + { + addToolchainToPath + if [ ! -d "$pcreInstallDir" ]; then + cd "$pcreBuildDir" + myMake "$depsInstallDirMaybeSudo" install V=1 + fi + } + + buildFreetype() + { + + addToolchainToPath + + if [ ! -d "$freetypeInstallDir" ]; then + + if [ ! -d "$freetypeSrcDir" ]; then + cd "$ceguiDepsSrcDir" + if [ ! -f "$ceguiDepsDownloadsDir/$freetypePackageArchive" ]; \ + then + myWget "" "$ceguiDepsDownloadsDir/$freetypePackageArchive" \ + "$freetypePackageUri" + fi + myUnpackTarBz2 "" \ + "$ceguiDepsDownloadsDir/$freetypePackageArchive" + mv "$freetypePackageDir" "$freetypeSrcDir" + fi + + if [ ! -d "$freetypeBuildDir" ]; then + mkdir -p "$freetypeBuildDir" + cd "$freetypeBuildDir" + eval '"$freetypeSrcDir/configure"' \ + '--prefix="$freetypeInstallDir"' \ + '--host="$androidToolchainName" --with-zlib=yes' \ + '--with-bzip2=no --with-png=no --with-harfbuzz=no' \ + $androidAutotoolsOptions + fi + + cd "$freetypeBuildDir" + myMake "" "-j$buildNumOfProcesses" + + fi + + } + + installFreetype() + { + addToolchainToPath + if [ ! -d "$freetypeInstallDir" ]; then + cd "$freetypeBuildDir" + myMake "$depsInstallDirMaybeSudo" install + fi + } + + buildEpoxy() + { + + if [ ! -d "$epoxyInstallDir" ]; then + + if [ ! -d "$epoxySrcDir" ]; then + cd "$ceguiDepsSrcDir" + if [ ! -f "$ceguiDepsDownloadsDir/$epoxyPackageArchive" ]; then + myWget "" "$ceguiDepsDownloadsDir/$epoxyPackageArchive" \ + "$epoxyPackageUri" + fi + myUnpackTarGz "" "$ceguiDepsDownloadsDir/$epoxyPackageArchive" + mv "$epoxyPackageDir" "$epoxySrcDir" + fi + + if [ ! -d "$epoxyBuildDir" ]; then + mkdir -p "$epoxyBuildDir" + cd "$epoxyBuildDir" + eval myCmake '""' $androidCmakeOptions \ + '-DCMAKE_INSTALL_PREFIX="$epoxyInstallDir"' \ + '-DCMAKE_BUILD_TYPE="$ceguiDepsBuildType" "$epoxySrcDir"' + fi + + cd "$epoxyBuildDir" + myMake "" "-j$buildNumOfProcesses" + + fi + } + + installEpoxy() + { + if [ ! -d "$epoxyInstallDir" ]; then + cd "$epoxyBuildDir" + myMake "$depsInstallDirMaybeSudo" install + fi + } + + buildFribidi() + { + + addToolchainToPath + + if [ ! -d "$fribidiInstallDir" ]; then + + if [ ! -d "$fribidiSrcDir" ]; then + cd "$ceguiDepsSrcDir" + if [ ! -f "$ceguiDepsDownloadsDir/$fribidiPackageArchive" ]; \ + then + myWget "" "$ceguiDepsDownloadsDir/$fribidiPackageArchive" \ + "$fribidiPackageUri" + fi + myUnpackTarBz2 "" \ + "$ceguiDepsDownloadsDir/$fribidiPackageArchive" + mv "$fribidiPackageDir" "$fribidiSrcDir" + fi + + if [ ! -d "$fribidiBuildDir" ]; then + mkdir -p "$fribidiBuildDir" + cd "$fribidiBuildDir" + eval '"$fribidiSrcDir/configure"' \ + '--prefix="$fribidiInstallDir"' \ + '--host="$androidToolchainName" --with-glib=no' \ + $androidAutotoolsOptions + fi + + cd "$fribidiBuildDir" + myMake "" "-j$buildNumOfProcesses" + + fi + + } + + installFribidi() + { + addToolchainToPath + if [ ! -d "$fribidiInstallDir" ]; then + cd "$fribidiBuildDir" + myMake "$depsInstallDirMaybeSudo" install + fi + } + + + : \ + && (buildNdkMissing) \ + && (installNdkMissing) \ + && (buildTinyxml) \ + && (buildFreeimage) \ + && (buildGlm) \ + && (buildPcre) \ + && (buildFreetype) \ + && (buildEpoxy) \ + && (buildFribidi) \ + && (installTinyxml) \ + && (installFreeimage) \ + && (installGlm) \ + && (installPcre) \ + && (installFreetype) \ + && (installEpoxy) \ + && (installFribidi) + + if [ $? -eq 0 ]; then + echo $'\n'"Building CEGUI dependencies succeeded!" + true; + else + echo $'\n'"Building CEGUI dependencies failed!" + false; + fi + +fi diff --git a/android/build_sample-framework b/android/build_sample-framework new file mode 100755 index 000000000..1eff3d91a --- /dev/null +++ b/android/build_sample-framework @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +myScriptsDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +. "$myScriptsDir/sample-framework_common" + +cd "$androidSampleFrameworkDir" +eval echo -n "'$(AndroidManifest.xml +eval echo -n "\"$(ant.properties +eval echo -n "\"$(jni/Application.mk +eval echo -n "\"$(jni/Android.mk +eval echo -n "'$(jni/deps/Android.mk +for resolution in h m xh xxh; do + dest="res/drawable-${resolution}dpi" + mkdir -p "$dest" + cp "$ceguiSrcDir/datafiles/imagesets/logo.png" "$dest/" +done +if [ -f project.properties ] && [ -f local.properties ]; then + ant clean + ndk-build clean +fi +: \ + && android update project --path . --target "android-$androidBuildTargetApiLevel" \ + && ndk-build "-j$buildNumOfProcesses" +if [ $? -eq 0 ]; then + case "$sampleFrameworkAndroidProjectBuildType" in + Debug) + ant debug && ant installd + ;; + Release) + ant release && ant installr + ;; + *) + echo 'Error: invalid "$sampleFrameworkAndroidProjectBuildType"' + exit 1 + ;; + esac +fi diff --git a/android/common b/android/common new file mode 100644 index 000000000..01b5542fa --- /dev/null +++ b/android/common @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +. "$myScriptsDir/conf" +androidSampleFrameworkDir="$myScriptsDir/CEGUISampleFramework" +export PKG_CONFIG_SYSROOT_DIR="$androidStandaloneToolchainDir/sysroot" + +maybeSudo() +{ + "$@" 2>/dev/null + if [ $? -ne 0 ]; then + mySudo "$@" + fi +} + +dirRequiresSudo() +{ + myDir="$1" + myMaybeSudo="$2" + declare -i dirExists + [ -d "$myDir" ] + dirExists=$? + maybeSudo mkdir -p "$myDir" + touch "$myDir/file_to_test_permission" 2>/dev/null + eval '{ [ $? -eq 0 ] && '"$myMaybeSudo"'=""; } || '"$myMaybeSudo"'="mySudo "' + rm -f "$myDir/file_to_test_permission" 2>/dev/null + if [ $dirExists -ne 0 ]; then + eval '${'"$myMaybeSudo"'}rmdir "$myDir"' + fi +} + +addToolchainToPath() +{ + export PATH="$androidStandaloneToolchainDir/bin${PATH+:}$PATH" +} + +androidCmakeOptionsElements=('-G "Unix Makefiles"' \ + '-DCMAKE_TOOLCHAIN_FILE="$androidToolchainCmakeFile"' \ + '-DANDROID_NDK="$androidNdkDir"' \ + '-DANDROID_ABI="$androidAbi"' \ + '-DANDROID_NATIVE_API_LEVEL=android-"$androidNdkApiLevel"' \ + '-DANDROID_TOOLCHAIN_NAME="$androidToolchain"' \ + '-DANDROID_STL=gnustl_shared') +androidCmakeOptions="${androidCmakeOptionsElements[*]}" + +declare -A androidBuildFlags +androidBuildFlags=([Debug]="-O0 -g -DDEBUG -D_DEBUG" \ + [Release]="-O3 -DNDEBUG" \ + [RelWithDebInfo]="-O2 -g -DNDEBUG" \ + [MinSizeRel]="-Os -DNDEBUG") +androidAutotoolsOptionsElements=('CFLAGS="${androidBuildFlags[$myBuildType]}"' \ + 'CXXFLAGS="${androidBuildFlags[$myBuildType]}"') +androidAutotoolsOptions="${androidAutotoolsOptionsElements[*]}" +androidBuildOptionsElements=('user_CFLAGS="${androidBuildFlags[$myBuildType]}"' \ + 'user_CXXFLAGS="${androidBuildFlags[$myBuildType]}"') +androidBuildOptions="${androidBuildOptionsElements[*]}" + +androidToolchainConfigurationElements=('CC="$androidToolchainName-gcc"' \ + 'CXX="$androidToolchainName-g++"' \ + 'AR="$androidToolchainName-ar"' \ + 'LD="$androidToolchainName-ld"' \ + 'AS="$androidToolchainName-as"' \ + 'NM="$androidToolchainName-nm"' \ + 'STRIP="$androidToolchainName-strip"' \ + 'RANLIB="$androidToolchainName-ranlib"' \ + 'OBJDUMP="$androidToolchainName-objdump"') +androidToolchainConfiguration="${androidToolchainConfigurationElements[*]}" diff --git a/android/conf b/android/conf new file mode 100644 index 000000000..9182c276b --- /dev/null +++ b/android/conf @@ -0,0 +1,175 @@ +#!/usr/bin/env bash + +################################################################################ +# General Configuration +################################################################################ + +androidSdkDir=/opt/android/android-sdk-linux +buildNumOfProcesses=4 # Number of concurrent processes to use when building. + +################################################################################ +# Java Configuration +################################################################################ + +# The location of the Java installation to use for building the Android sample +# framework project +javaHomeDir=/opt/java/jdk1.7.0_79 + +# The target Java version to build the Android sample framework project for: +# ${javaVerMajor}.${javaVerMinor} +javaVerMajor=1 +javaVerMinor=7 + +################################################################################ +# Android NDK Configuration +################################################################################ + +# E.g. for the official Android NDK version r10e, set "androidNdkType" to +# "Google", "androidNdkVerMajor" to "10", "androidNdkVerMinor" to "e" and +# "androidNdkVerPatch" to "". E.g. For Crystax NDK version 10.2.1 set +# "androidNdkType" to "Crystax", "androidNdkVerMajor" to "10", +# "androidNdkVerMinor" to "2" and "androidNdkVerPatch" to "1". +androidNdkType=Crystax +androidNdkVerMajor=10 +androidNdkVerMinor=2 +androidNdkVerPatch=1 + +androidNdkName=crystax-ndk-10.2.1 +androidNdkDir="/opt/android/$androidNdkName" + +# Value passed to "--system" when running "make-standalone-toolchain.sh". +mySystemName=linux-x86_64 + +# Value passed to "--arch" when running "make-standalone-toolchain.sh". +androidArch=arm + +# The following variable determines 3 things: +# 1) Passed to "--abis" when running "make-standalone-toolchain.sh". +# 2) Determines "APP_ABI" in "Application.mk". +# 3) Determines value of "ANDROID_ABI" passed to CMake. +androidAbi=armeabi-v7a + +androidToolchainAbi=armv7-a +androidToolchainVer=4.9 # Version of GCC to use with the NDK. +androidToolchainName=arm-linux-androideabi +androidToolchain="$androidToolchainName-$androidToolchainVer" + +################################################################################ +# Android Sample Framework Project Version Configuration +################################################################################ + +# Determines "android:minSdkVersion" in "AndroidManifest.xml". +androidMinSdkVersion=21 + +# Determines "android:androidSdkVersion" in "AndroidManifest.xml". +androidTargetSdkVersion=22 + +# Determines the value passed to "--target" when running +# "android update project". +androidBuildTargetApiLevel=21 + +androidNdkApiLevel=21 # Determines the "APP_PLATFORM" in "Android.mk". + +################################################################################ +# CEGUI Specific Configuration +################################################################################ + +# Cegui version: "${ceguiVerMajor}.${ceguiVerMinor}.${ceguiVerPatch}". +ceguiVerMajor=0 +ceguiVerMinor=8 +ceguiVerPatch=5 + +ceguiPackageName="cegui_${ceguiVerMajor}_${ceguiVerMinor}_${ceguiVerPatch}" + +# Directory where the CEGUI source is located. +ceguiSrcDir="$HOME/src/$ceguiPackageName" + +################################################################################ +# Build types +################################################################################ + +# Can be either "Debug" or "Release". Controls whether to build the sample +# framework android project with "ant debug" or "ant release". Note: for +# "Release" to work, the APK must be signed! +sampleFrameworkAndroidProjectBuildType=Debug + +# Each can be each of "Debug", "Release", "RelWithDebInfo" or "MinSizeRel". This +# is equivalent to CMake's variable "CMAKE_BUILD_TYPE". +ceguiBuildType=Debug +ceguiDepsBuildType=Release + +################################################################################ +# Files and Directories Paths +# ---------------------------- +# Note: all the files and directories named by the following variables will be +# automatically created; there's no need to create them manually. +################################################################################ + +# Directory where to download CEGUI dependencies. Remove this directory to force +# re-download of all packages. +ceguiDepsDownloadsDir="$HOME/Downloads/cegui_deps_android" + +# Directory where to store the source code for CEGUI dependencies. Remove this +# directory to force re-retrieval of all CEGUI dependencies source code. +ceguiDepsSrcDir="$HOME/src/cegui_deps_android" + +# Directory where to build the CEGUI dependencies. Remove this directory to +# force a rebuild of all CEGUI dependencies. +ceguiDepsBuildDir="$HOME/build/android/cegui_deps" + +# Directory where to install the CEGUI dependencies. Remove this directory to +# force re-installation of all CEGUI dependencies. +# +# ** Note ** +# Path must not contain any spaces! (Because "Android.mk" doesn't know how to +# handle them right, or at least I don't know how to make it handle them right.) +ceguiDepsInstallDir="/usr/local/android/cegui-deps" + +# Directory where to create the Android NDK standalone toolchain. Remove this +# directory to force a regeneration of the standalone toolchain. +androidStandaloneToolchainDir="/opt/android/${androidNdkName}_${androidAbi}_${androidToolchainVer}_$androidNdkApiLevel" + +# A path where to create the CMake Android toolchain file. +androidToolchainCmakeFile="$HOME/src/android.toolchain.cmake" + +# Directory where CEGUI will be built. Remove this directory to force a rebuild +ceguiBuildDir="$HOME/build/android/$ceguiPackageName" +# of CEGUI. + +# Directory where CEGUI will be installed. Remove this directory to force a +# re-installation of CEGUI. +# +# ** Note ** +# Path must not contain any spaces! (Because "Android.mk" doesn't know how to +# handle them right, or at least I don't know how to make it handle them right.) +ceguiInstallDir="/usr/local/android/$ceguiPackageName" + +################################################################################ +# Helper programs +# ---------------- +# Normally, you wouldn't have to touch these functions. Adjust them in case you +# have some unusual installations of these programs: +################################################################################ + +mySudo() { sudo env PATH="$PATH" "$@"; } +mySymLink() { myArgs=("$@"); ${1}ln -s "${myArgs[@]:1}"; } +myPatchFile() { ${1}patch -o "${3}" -d "${2}" "${4}" "${5}"; } +myPatchDir() { ${1}patch -p1 -d "${2}" -i "${3}"; } +myWget() { ${1}wget -O "$2" "$3"; } +myCmake() { myArgs=("$@"); ${1}cmake "${myArgs[@]:1}"; } +myMake() { myArgs=("$@"); ${1}make "${myArgs[@]:1}"; } +myUnpackTarGz() { ${1}tar -xzf "$2"; } +myUnpackTarBz2() { ${1}tar -xjf "$2"; } +myUnpack7z() { ${1}7z x "$2"; } +myUnpackZip() { ${1}unzip "$2"; } +myBash() { myArgs=("$@"); ${1}bash "${myArgs[@]:1}"; } + +################################################################################ +# Package-Specific Configuration +# ------------------------------- +# For finer tuning of each CEGUI dependency package individually, you might want +# to have a loot at "deps_conf.sh". Normally you wouldn't have to touch it, +# though. +################################################################################ + +. "$myScriptsDir/deps_conf" diff --git a/android/deps_conf b/android/deps_conf new file mode 100644 index 000000000..b18194ca8 --- /dev/null +++ b/android/deps_conf @@ -0,0 +1,104 @@ +#!/usr/bin/env bash + +################################################################################ +# Package-Specific configuration +# ------------------------------- +# For finer tuning of each CEGUI dependency package individually, you might want +# to have a look at this file. Normally you wouldn't have to touch it, +# though. +# +# * The "packageArchive" of each package is the name in which to save its downloaded +# source archive. +# tarball) to be downloaded. +# * The "packageUri" of each package is the URI from which to download its +# source archive. +# * The "packageDir" of each package is the top level directory in its source +# acrhive. +# * The "srcDir" of each package is where to store its source code. Remove this +# directoryTo force re-retrieval of its source code. +# * The "buildDir" of each package is where to build it. Remove this directory +# to force a rebuild of it. +# * The "installDir" of each package is where to install it. Remove this +# directory to force a re-installation of it. +# * The "libFilePath" of each package is a full path to its shared library +# ("lib.so"), including the file name. +# * The "includePath" of each package is a full path to its include directory. +################################################################################ + +# "ndkMissing" is a package that its source is included with the CEGUI source, +# which provides functions of the standard C/C++ library which are absent from +# the Android NDK. +ndkMissing_packageName=ndk-missing_1_0_0 +ndkMissing_srcDir="$myScriptsDir/$ndkMissing_packageName" +ndkMissing_buildDir="$ceguiDepsBuildDir/$ndkMissing_packageName" +ndkMissing_installDir="$ceguiDepsInstallDir/$ndkMissing_packageName" +ndkMissing_libFilePath="$ndkMissing_installDir/lib/libndk-missing_1.so" + +tinyxmlPackageName=tinyxml_2_6_2 +tinyxmlPackageArchive=tinyxml_2_6_2.tar.gz +tinyxmlPackageDir=tinyxml +tinyxmlPackageUri="http://downloads.sourceforge.net/project/tinyxml/tinyxml/2.6.2/$tinyxmlPackageArchive?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Ftinyxml%2Ffiles%2Ftinyxml%2F2.6.2%2F&ts=1439024597&use_mirror=garr" +tinyxmlSrcDir="$ceguiDepsSrcDir/$tinyxmlPackageName" +tinyxmlBuildDir="$ceguiDepsBuildDir/$tinyxmlPackageName" +tinyxmlInstallDir="$ceguiDepsInstallDir/$tinyxmlPackageName" +tinyxmlLibFilePath="$tinyxmlInstallDir/lib/libtinyxml.so" +tinyxmlIncludePath="$tinyxmlInstallDir/include" + +freeimagePackageName=FreeImage_3_17_0 +freeimagePackageArchive=FreeImage3170.zip +freeimagePackageDir=FreeImage +freeimagePackageUri="http://downloads.sourceforge.net/project/freeimage/Source%20Distribution/3.17.0/$freeimagePackageArchive?r=http%3A%2F%2Ffreeimage.sourceforge.net%2Fdownload.html&ts=1439040407&use_mirror=garr" +freeimageSrcDir="$ceguiDepsSrcDir/$freeimagePackageName" +freeimageBuildDir="$ceguiDepsBuildDir/$freeimagePackageName" +freeimageInstallDir="$ceguiDepsInstallDir/$freeimagePackageName" +freeimageLibFilePath="$freeimageInstallDir/lib/libfreeimage_3.so" +freeimageIncludePath="$freeimageInstallDir/include" + +glmPackageName=glm_0_9_7_0 +glmPackageArchive=glm-0.9.7.0.7z +glmPackageDir=glm +glmPackageUri="https://github.com/g-truc/glm/releases/download/0.9.7.0/$glmPackageArchive" +glmSrcDir="$ceguiDepsSrcDir/$glmPackageName" +glmBuildDir="$ceguiDepsBuildDir/$glmPackageName" +glmInstallDir="$ceguiDepsInstallDir/$glmPackageName" +glmIncludePath="$glmInstallDir/include" + +pcrePackageName=pcre_8_37 +pcrePackageArchive=pcre-8.37.tar.bz2 +pcrePackageDir=pcre-8.37 +pcrePackageUri="ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/$pcrePackageArchive" +pcreSrcDir="$ceguiDepsSrcDir/$pcrePackageName" +pcreBuildDir="$ceguiDepsBuildDir/$pcrePackageName" +pcreInstallDir="$ceguiDepsInstallDir/$pcrePackageName" +pcreLibFilePath="$pcreInstallDir/lib/libpcre.so" +pcreIncludePath="$pcreInstallDir/include" + +freetypePackageName=freetype_2_6 +freetypePackageArchive=freetype-2.6.tar.bz2 +freetypePackageDir=freetype-2.6 +freetypePackageUri="http://download.savannah.gnu.org/releases/freetype/$freetypePackageArchive" +freetypeSrcDir="$ceguiDepsSrcDir/$freetypePackageName" +freetypeBuildDir="$ceguiDepsBuildDir/$freetypePackageName" +freetypeInstallDir="$ceguiDepsInstallDir/$freetypePackageName" +freetypeLibFilePath="$freetypeInstallDir/lib/libfreetype.so" +freetypeIncludePath="$freetypeInstallDir/include/freetype2" + +epoxyPackageName=epoxy_1_3_1_yaronct-4 +epoxyPackageArchive=libepoxy-v1.3.1_yaronct-4.tar.gz +epoxyPackageDir=libepoxy-1.3.1_yaronct-4 +epoxyPackageUri=https://github.com/yaronct/libepoxy/archive/v1.3.1_yaronct-4.tar.gz +epoxySrcDir="$ceguiDepsSrcDir/$epoxyPackageName" +epoxyBuildDir="$ceguiDepsBuildDir/$epoxyPackageName" +epoxyInstallDir="$ceguiDepsInstallDir/$epoxyPackageName" +epoxyLibFilePath="$epoxyInstallDir/lib/libepoxy_0.so" +epoxyIncludePath="$epoxyInstallDir/include" + +fribidiPackageName=fribidi_0_19_7 +fribidiPackageArchive=fribidi-0.19.7.tar.bz2 +fribidiPackageDir=fribidi-0.19.7 +fribidiPackageUri="http://fribidi.org/download/$fribidiPackageArchive" +fribidiSrcDir="$ceguiDepsSrcDir/$fribidiPackageName" +fribidiBuildDir="$ceguiDepsBuildDir/$fribidiPackageName" +fribidiInstallDir="$ceguiDepsInstallDir/$fribidiPackageName" +fribidiLibFilePath="$fribidiInstallDir/lib/libfribidi.so" +fribidiIncludePath="$fribidiInstallDir/include/fribidi" diff --git a/android/freeimage.patch b/android/freeimage.patch new file mode 100644 index 000000000..078ac12d4 --- /dev/null +++ b/android/freeimage.patch @@ -0,0 +1,191 @@ +diff -rupN FreeImage_3_17_0_orig/Makefile.gnu FreeImage_3_17_0_new/Makefile.gnu +--- FreeImage_3_17_0_orig/Makefile.gnu 2015-03-08 18:04:00.000000000 +0200 ++++ FreeImage_3_17_0_new/Makefile.gnu 2015-08-22 14:16:36.068525956 +0300 +@@ -5,17 +5,19 @@ include Makefile.srcs + + # General configuration variables: + DESTDIR ?= / +-INCDIR ?= $(DESTDIR)/usr/include +-INSTALLDIR ?= $(DESTDIR)/usr/lib ++INCDIR ?= $(DESTDIR)/include ++INSTALLDIR ?= $(DESTDIR)/lib + + # Converts cr/lf to just lf + DOS2UNIX = dos2unix + +-LIBRARIES = -lstdc++ ++LIBRARIES = -lgnustl_shared -lndk-missing_1 ++LDFLAGS = -L$(ndkMissing_dir)/lib + + MODULES = $(SRCS:.c=.o) + MODULES := $(MODULES:.cpp=.o) +-CFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden ++CFLAGS = $(user_CFLAGS) ++CFLAGS += -fPIC -fexceptions -fvisibility=hidden + # OpenJPEG + CFLAGS += -DOPJ_STATIC + # LibRaw +@@ -23,28 +25,27 @@ CFLAGS += -DNO_LCMS + # LibJXR + CFLAGS += -DDISABLE_PERF_MEASUREMENT -D__ANSI__ + CFLAGS += $(INCLUDE) +-CXXFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy ++CXXFLAGS = $(user_CXXFLAGS) ++CXXFLAGS += -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy + # LibJXR + CXXFLAGS += -D__ANSI__ + CXXFLAGS += $(INCLUDE) + +-ifeq ($(shell sh -c 'uname -m 2>/dev/null || echo not'),x86_64) +- CFLAGS += -fPIC +- CXXFLAGS += -fPIC +-endif +- + TARGET = freeimage + STATICLIB = lib$(TARGET).a + SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).so + LIBNAME = lib$(TARGET).so +-VERLIBNAME = $(LIBNAME).$(VER_MAJOR) ++VERLIBNAME = lib$(TARGET)_$(VER_MAJOR).so + HEADER = Source/FreeImage.h + + + + default: all + +-all: dist ++all: foo dist ++ ++foo: ++ echo "my CFLAGS = " $(CFLAGS) + + dist: FreeImage + mkdir -p Dist +@@ -71,12 +72,11 @@ $(SHAREDLIB): $(MODULES) + + install: + install -d $(INCDIR) $(INSTALLDIR) +- install -m 644 -o root -g root $(HEADER) $(INCDIR) +- install -m 644 -o root -g root $(STATICLIB) $(INSTALLDIR) +- install -m 755 -o root -g root $(SHAREDLIB) $(INSTALLDIR) ++ install -m 644 $(HEADER) $(INCDIR) ++ install -m 644 $(STATICLIB) $(INSTALLDIR) ++ install -m 755 $(SHAREDLIB) $(INSTALLDIR) + ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(VERLIBNAME) +- ln -sf $(VERLIBNAME) $(INSTALLDIR)/$(LIBNAME) +-# ldconfig ++ ln -sf $(VERLIBNAME) $(INSTALLDIR)/$(LIBNAME) + + clean: + rm -f core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME) +diff -rupN FreeImage_3_17_0_orig/Makefile.gnu~ FreeImage_3_17_0_new/Makefile.gnu~ +--- FreeImage_3_17_0_orig/Makefile.gnu~ 1970-01-01 02:00:00.000000000 +0200 ++++ FreeImage_3_17_0_new/Makefile.gnu~ 2015-08-22 14:16:36.068525956 +0300 +@@ -0,0 +1,82 @@ ++# Linux makefile for FreeImage ++ ++# This file can be generated by ./gensrclist.sh ++include Makefile.srcs ++ ++# General configuration variables: ++DESTDIR ?= / ++INCDIR ?= $(DESTDIR)/include ++INSTALLDIR ?= $(DESTDIR)/lib ++ ++# Converts cr/lf to just lf ++DOS2UNIX = dos2unix ++ ++LIBRARIES = -lgnustl_shared -lndk-missing ++LDFLAGS = -L$(ndkMissing_dir)/lib ++ ++MODULES = $(SRCS:.c=.o) ++MODULES := $(MODULES:.cpp=.o) ++CFLAGS = $(user_CFLAGS) ++CFLAGS += -fPIC -fexceptions -fvisibility=hidden ++# OpenJPEG ++CFLAGS += -DOPJ_STATIC ++# LibRaw ++CFLAGS += -DNO_LCMS ++# LibJXR ++CFLAGS += -DDISABLE_PERF_MEASUREMENT -D__ANSI__ ++CFLAGS += $(INCLUDE) ++CXXFLAGS = $(user_CXXFLAGS) ++CXXFLAGS += -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy ++# LibJXR ++CXXFLAGS += -D__ANSI__ ++CXXFLAGS += $(INCLUDE) ++ ++TARGET = freeimage ++STATICLIB = lib$(TARGET).a ++SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).so ++LIBNAME = lib$(TARGET).so ++VERLIBNAME = $(LIBNAME) ++HEADER = Source/FreeImage.h ++ ++ ++ ++default: all ++ ++all: foo dist ++ ++foo: ++ echo "my CFLAGS = " $(CFLAGS) ++ ++dist: FreeImage ++ mkdir -p Dist ++ cp *.a Dist/ ++ cp *.so Dist/ ++ cp Source/FreeImage.h Dist/ ++ ++dos2unix: ++ @$(DOS2UNIX) $(SRCS) $(INCLS) ++ ++FreeImage: $(STATICLIB) $(SHAREDLIB) ++ ++.c.o: ++ $(CC) $(CFLAGS) -c $< -o $@ ++ ++.cpp.o: ++ $(CXX) $(CXXFLAGS) -c $< -o $@ ++ ++$(STATICLIB): $(MODULES) ++ $(AR) r $@ $(MODULES) ++ ++$(SHAREDLIB): $(MODULES) ++ $(CC) -s -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES) ++ ++install: ++ install -d $(INCDIR) $(INSTALLDIR) ++ install -m 644 $(HEADER) $(INCDIR) ++ install -m 644 $(STATICLIB) $(INSTALLDIR) ++ install -m 755 $(SHAREDLIB) $(INSTALLDIR) ++ ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(VERLIBNAME) ++ ++clean: ++ rm -f core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME) ++ +diff -rupN FreeImage_3_17_0_orig/Source/LibJXR/common/include/wmspecstring.h FreeImage_3_17_0_new/Source/LibJXR/common/include/wmspecstring.h +--- FreeImage_3_17_0_orig/Source/LibJXR/common/include/wmspecstring.h 2015-03-02 01:50:58.000000000 +0200 ++++ FreeImage_3_17_0_new/Source/LibJXR/common/include/wmspecstring.h 2015-08-22 14:16:36.084525640 +0300 +@@ -286,7 +286,9 @@ extern "C" { + + #if defined(_WINDOWS_) + /* Windows Internal */ ++#if defined _WIN32 + #define __volatile __$volatile ++#endif + #define __nonvolatile __$nonvolatile + #define __deref_volatile __deref __volatile + #define __deref_nonvolatile __deref __nonvolatile +diff -rupN FreeImage_3_17_0_orig/Source/LibRawLite/internal/libraw_x3f.cpp FreeImage_3_17_0_new/Source/LibRawLite/internal/libraw_x3f.cpp +--- FreeImage_3_17_0_orig/Source/LibRawLite/internal/libraw_x3f.cpp 2014-08-31 23:45:02.000000000 +0300 ++++ FreeImage_3_17_0_new/Source/LibRawLite/internal/libraw_x3f.cpp 2015-08-22 14:16:36.092525482 +0300 +@@ -625,7 +625,7 @@ static x3f_huffman_t *new_huffman(x3f_hu + I->output.file = NULL; + + if (infile == NULL) { +- I->error = "No infile"; ++ I->error = const_cast("No infile"); + return x3f; + } + diff --git a/android/ndk-missing_1_0_0/CMakeLists.txt b/android/ndk-missing_1_0_0/CMakeLists.txt new file mode 100644 index 000000000..35a1f6639 --- /dev/null +++ b/android/ndk-missing_1_0_0/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required (VERSION 3.0) +cmake_policy (VERSION 3.0) +project (NDK-Missing VERSION 1.0.0 LANGUAGES C CXX) +set (TARGET_ABI_VER "${PROJECT_VERSION_MAJOR}") +set (TARGET_NAME "ndk-missing_${TARGET_ABI_VER}") + +set (CMAKE_C_VISIBILITY_PRESET "hidden") + +if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu99 -Wall -Wextra") +endif () + +add_library ("${TARGET_NAME}" SHARED main.cpp) +set_target_properties(${TARGET_NAME} PROPERTIES DEFINE_SYMBOL "NDK_MISSING__EXPORTS") + +install (FILES ${HEADERS} DESTINATION "include") +install (TARGETS "${TARGET_NAME}" RUNTIME DESTINATION bin LIBRARY DESTINATION lib) diff --git a/android/ndk-missing_1_0_0/main.cpp b/android/ndk-missing_1_0_0/main.cpp new file mode 100644 index 000000000..46b0765cd --- /dev/null +++ b/android/ndk-missing_1_0_0/main.cpp @@ -0,0 +1,22 @@ +#include + +extern "C" +{ + +void swab(const void* bfrom, void* bto, ssize_t n) __attribute__((visibility("default"))); + +void swab(const void* bfrom, void* bto, ssize_t n) +{ + const char* from = (const char*)bfrom; + char* to = (char*)bto; + n &= ~((ssize_t)1); + while (n > 1) + { + const char b0 = from[--n]; + const char b1 = from[--n]; + to[n] = b0; + to[n+1] = b1; + } +} + +} // extern "C" diff --git a/android/prepare_ndk b/android/prepare_ndk new file mode 100644 index 000000000..4c2507246 --- /dev/null +++ b/android/prepare_ndk @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +myScriptsDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +. "$myScriptsDir/common" + +maybeSudo cp "$myScriptsDir/android-ndk-r10e_RELEASE.TXT" \ + "$androidNdkDir/RELEASE.TXT" + +if [ ! -d "$androidStandaloneToolchainDir" ]; then + + dirRequiresSudo "$androidStandaloneToolchainDir" toolchainDirMaybeSudo + myBash "$toolchainDirMaybeSudo" \ + "$androidNdkDir/build/tools/make-standalone-toolchain.sh" \ + --platform="android-$androidNdkApiLevel" \ + --system="$mySystemName" \ + --arch="$androidArch" \ + --ndk-dir="$androidNdkDir" \ + --abis="$androidAbi" \ + --toolchain="$androidToolchain" \ + --install-dir="$androidStandaloneToolchainDir" + + myPatchDir "$toolchainDirMaybeSudo" "$androidStandaloneToolchainDir" \ + "$myScriptsDir/standalone_toolchain.patch" + + pushd "$androidStandaloneToolchainDir/include/c++/$androidToolchainVer/bits" + mySymLink "$toolchainDirMaybeSudo" \ + "../$androidToolchainName/$androidToolchainAbi/bits/"* . + popd + + ${toolchainDirMaybeSudo}cp \ + "$androidNdkDir/sources/cpufeatures/cpu-features.h" \ + "$androidStandaloneToolchainDir/sysroot/usr/include" + + pushd "$androidStandaloneToolchainDir/arm-linux-androideabi/lib" + for file in libgnuobjc_shared.so libgnustl_shared.so libobjc.a libstdc++.a \ + libsupc++.a; do + mySymLink "$toolchainDirMaybeSudo" "$androidToolchainAbi/$file" . + done + popd +fi + +if [ ! -f "$androidToolchainCmakeFile" ]; then + myPatchFile "" "$myScriptsDir" "$androidToolchainCmakeFile" \ + "$myScriptsDir/android.toolchain.cmake__orig" \ + "$myScriptsDir/android.toolchain.cmake.patch" +fi diff --git a/android/run_sample-framework_with_logcat b/android/run_sample-framework_with_logcat new file mode 100755 index 000000000..8fad47f94 --- /dev/null +++ b/android/run_sample-framework_with_logcat @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +myScriptsDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +. "$myScriptsDir/sample-framework_common" +cd "$androidSampleFrameworkDir" +adb logcat -c +adb shell am start -a android.intent.action.MAIN -n sample_framework.cegui/.MainActivity +adb logcat CEGUIBase:V MainActivity:V DEBUG:I *:F diff --git a/android/sample-framework_common b/android/sample-framework_common new file mode 100644 index 000000000..b554e2059 --- /dev/null +++ b/android/sample-framework_common @@ -0,0 +1,3 @@ +. "$myScriptsDir/common" +export JAVA_HOME="$javaHomeDir" +export PATH="$androidNdkDir:$androidSdkDir/tools:$androidSdkDir/platform-tools:$javaHomeDir/bin${PATH+:}$PATH" diff --git a/android/standalone_toolchain.patch b/android/standalone_toolchain.patch new file mode 100644 index 000000000..c95ceb29e --- /dev/null +++ b/android/standalone_toolchain.patch @@ -0,0 +1,50 @@ +diff -rupN orig/sysroot/usr/include/crystax/freebsd/include/mangled-string.h new/sysroot/usr/include/crystax/freebsd/include/mangled-string.h +--- orig/sysroot/usr/include/crystax/freebsd/include/mangled-string.h 2015-08-25 21:46:30.670286841 +0300 ++++ new/sysroot/usr/include/crystax/freebsd/include/mangled-string.h 2015-08-25 21:49:25.074987710 +0300 +@@ -123,6 +123,8 @@ char *strtok_r(char *, const char *, cha + size_t strxfrm(char * __restrict, const char * __restrict, size_t); + #if __BSD_VISIBLE + ++#if 0 ++ + #ifndef _SWAB_DECLARED + #define _SWAB_DECLARED + +@@ -134,6 +136,8 @@ typedef __ssize_t ssize_t; + void swab(const void * __restrict, void * __restrict, ssize_t); + #endif /* _SWAB_DECLARED */ + ++#endif ++ + #endif /* __BSD_VISIBLE */ + + #if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) +diff -rupN orig/sysroot/usr/include/crystax/freebsd.h new/sysroot/usr/include/crystax/freebsd.h +--- orig/sysroot/usr/include/crystax/freebsd.h 2015-08-25 21:46:30.670286841 +0300 ++++ new/sysroot/usr/include/crystax/freebsd.h 2015-08-25 21:49:25.074987710 +0300 +@@ -135,11 +135,11 @@ int __crystax_isthreaded(); + #endif + + #ifndef MIN +-#define MIN(a,b) (((a)<(b))?(a):(b)) ++//#define MIN(a,b) (((a)<(b))?(a):(b)) + #endif + + #ifndef MAX +-#define MAX(a,b) (((a)>(b))?(a):(b)) ++//#define MAX(a,b) (((a)>(b))?(a):(b)) + #endif + + #ifndef powerof2 +diff -rupN orig/sysroot/usr/include/crystax/google/unistd.h new/sysroot/usr/include/crystax/google/unistd.h +--- orig/sysroot/usr/include/crystax/google/unistd.h 2015-08-25 21:46:30.670286841 +0300 ++++ new/sysroot/usr/include/crystax/google/unistd.h 2015-08-25 21:49:25.074987710 +0300 +@@ -197,6 +197,8 @@ extern int tcsetpgrp(int fd, pid_t _pi + } while (_rc == -1 && errno == EINTR); \ + _rc; }) + ++extern void swab(const void* bfrom, void* bto, ssize_t n); ++ + #if defined(__BIONIC_FORTIFY) + extern ssize_t __read_chk(int, void*, size_t, size_t); + __errordecl(__read_dest_size_error, "read called with size bigger than destination"); diff --git a/android/tinyxml-CMakeLists.txt b/android/tinyxml-CMakeLists.txt new file mode 100644 index 000000000..76275c9f8 --- /dev/null +++ b/android/tinyxml-CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required (VERSION 3.0) +cmake_policy (VERSION 3.0) +project (Tinyxml VERSION 2.6.2 LANGUAGES C CXX) +set (TARGET_NAME tinyxml) + +if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++03") +endif () + +if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -Wall -Wextra") +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + if (NOT CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} /W4") + endif() + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Dinline=__inline") +endif () + +set (SOURCES tinystr.cpp + tinyxml.cpp + tinyxmlerror.cpp + tinyxmlparser.cpp) +set (HEADERS tinystr.h + tinyxml.h) + +add_library ("${TARGET_NAME}" SHARED ${SOURCES}) +set_target_properties("${TARGET_NAME}" PROPERTIES DEFINE_SYMBOL "TINYXML_EXPORTS") + +install (FILES ${HEADERS} DESTINATION "include") +install (TARGETS "${TARGET_NAME}" RUNTIME DESTINATION bin LIBRARY DESTINATION lib) + diff --git a/application_templates/CMakeLists.txt b/application_templates/CMakeLists.txt new file mode 100644 index 000000000..e07e943a1 --- /dev/null +++ b/application_templates/CMakeLists.txt @@ -0,0 +1,28 @@ +cegui_dependent_option(CEGUI_BUILD_APPLICATION_TEMPLATE_SDL2 "Specifies whether to build the application template for SDL2" "SDL2_FOUND;CEGUI_BUILD_RENDERER_OPENGL") +cegui_dependent_option(CEGUI_BUILD_APPLICATION_TEMPLATE_GLFW3 "Specifies whether to build the application template for GLFW3" "GLFW3_FOUND;CEGUI_BUILD_RENDERER_OPENGL") + +if(CEGUI_BUILD_RENDERER_OPENGL) + if(${CEGUI_BUILD_APPLICATION_TEMPLATE_SDL2}) + add_executable(CEGUITemplate_SDL2 SDL2.cpp) + + cegui_target_link_libraries(CEGUITemplate_SDL2 ${CEGUI_BASE_LIBNAME}) + cegui_target_link_libraries(CEGUITemplate_SDL2 ${CEGUI_OPENGL_RENDERER_LIBNAME}) + cegui_add_dependency(CEGUITemplate_SDL2 SDL2 PRIVATE TRUE) + cegui_add_dependency(CEGUITemplate_SDL2 GLEW PRIVATE TRUE) + if( MINGW ) + cegui_target_link_libraries( CEGUITemplate_SDL2 imm32 version winmm ) + endif() + endif() + + if(${CEGUI_BUILD_APPLICATION_TEMPLATE_GLFW3}) + add_executable(CEGUITemplate_GLFW3 glfw3.cpp) + if (WIN32) + set_property (TARGET CEGUITemplate_GLFW3 PROPERTY WIN32_EXECUTABLE TRUE) + endif () + + cegui_target_link_libraries(CEGUITemplate_GLFW3 ${CEGUI_BASE_LIBNAME}) + cegui_target_link_libraries(CEGUITemplate_GLFW3 ${CEGUI_OPENGL_RENDERER_LIBNAME}) + cegui_add_dependency(CEGUITemplate_GLFW3 GLFW3 PRIVATE TRUE) + + endif() +endif() diff --git a/application_templates/Ogre.cpp b/application_templates/Ogre.cpp new file mode 100644 index 000000000..5ee466d63 --- /dev/null +++ b/application_templates/Ogre.cpp @@ -0,0 +1,336 @@ +/*********************************************************************** +created: Feb 27 2016 +author: Petskull +*************************************************************************/ + +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ + +/************************************************************************** +* The following libs (and corresponding headers) are needed to compile and to link: +* OgreMain +* OIS +* CEGUIBase-0 +* CEGUIOgreRenderer-0 +***************************************************************************/ + +#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 +#define WIN32_LEAN_AND_MEAN +#include "windows.h" +#endif + +// Ogre3D 1.10 cloned on 160226 https://bitbucket.org/sinbad/ogre +#include +#include + +// CEGUI 0.8.4 cloned on 160226 from https://bitbucket.org/cegui/cegui +#include +#include + +typedef struct{ /* For moving data between App and AppListener */ + Ogre::Root* ogre_root; + Ogre::RenderWindow *ogre_win; + OIS::ParamList *ois_pl; + CEGUI::OgreRenderer *cegui_renderer; +} AppPak; + +/* This AppListener class will house all callback from Ogre's rendering and window events, as well as OIS's Keyboard and Mouse events. */ +class AppListener : public Ogre::FrameListener, public Ogre::WindowEventListener, public OIS::KeyListener, public OIS::MouseListener{ +public: + AppListener(AppPak *new_app_pak) :keep_running(true){ + app_pak = new_app_pak; + + ois_input_man = OIS::InputManager::createInputSystem(*app_pak->ois_pl); + ois_kb = static_cast(ois_input_man->createInputObject(OIS::OISKeyboard, true)); + ois_mouse = static_cast(ois_input_man->createInputObject(OIS::OISMouse, true)); + ois_kb->setEventCallback(this); + ois_mouse->setEventCallback(this); + + windowResized(app_pak->ogre_win); + + MAX_BUTTON_NUM = 0; + } + ~AppListener(){ + OIS::InputManager::destroyInputSystem(ois_input_man); + } + + // --- Ogre::FrameListener Callbacks ---------------------------// + bool frameRenderingQueued(const Ogre::FrameEvent& evt){ + Ogre::WindowEventUtilities::messagePump(); + + // For some reason, injectTimePulse(delta_time) currently must be done both + // on the GUIContext and also on CEGUI::System itself everytime. + CEGUI::System::getSingleton().getDefaultGUIContext().injectTimePulse((float)evt.timeSinceLastFrame); + CEGUI::System::getSingleton().injectTimePulse((float)evt.timeSinceLastFrame); + + // If our OIS::Keyboard or our OIS::Mouse has been destroyed (say, by closing the window), end the rendering + if (ois_kb && ois_mouse){ + ois_kb->capture(); + ois_mouse->capture(); + } else { + return false; + } + + //CEGUI::System::getSingleton().renderAllGUIContexts(); // By bootstrapping Ogre directly, we don't have to call this. Ogre does it automatically. + + return keep_running; // Return false ends Ogre's rendering + } + + // --- OIS::KeyListener and OIS::MouseListener Callbacks -------// + bool keyPressed(const OIS::KeyEvent &arg){ + CEGUI::System::getSingleton().getDefaultGUIContext().injectKeyDown((CEGUI::Key::Scan)arg.key); + CEGUI::System::getSingleton().getDefaultGUIContext().injectChar((CEGUI::Key::Scan)arg.text); + + if (arg.key == OIS::KC_ESCAPE){ keep_running = false; } + return true; + } + bool keyReleased(const OIS::KeyEvent &arg){ + CEGUI::System::getSingleton().getDefaultGUIContext().injectKeyUp((CEGUI::Key::Scan)arg.key); + return true; + } + bool mouseMoved(const OIS::MouseEvent &arg){ + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseMove((float)arg.state.X.rel, (float)arg.state.Y.rel); + //CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(200.f, 200.f); // Another way to control the mouse cursor + return true; + } + bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id){ + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(convertButton(id)); + return true; + } + bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id){ + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(convertButton(id)); + return true; + } + + // --- Ogre::WindowEventListener Callbacks ---------------------// + void windowResized(Ogre::RenderWindow* rw){ + unsigned int width, height, depth; + int left, top; + app_pak->ogre_win->getMetrics(width, height, depth, left, top); + + const OIS::MouseState &ms = ois_mouse->getMouseState(); + ms.width = width; + ms.height = height; + + CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef((float)width, (float)height)); + } + void windowClosed(Ogre::RenderWindow* rw){ + if (rw == app_pak->ogre_win){ + if (ois_input_man){ + ois_input_man->destroyInputObject(ois_mouse); + ois_input_man->destroyInputObject(ois_kb); + ois_mouse = NULL; + ois_kb = NULL; + + OIS::InputManager::destroyInputSystem(ois_input_man); + ois_input_man = 0; + } + } + } + + // Convert OIS MouseButton event to CEGUI MouseButton event + CEGUI::MouseButton convertButton(OIS::MouseButtonID buttonID) { + switch (buttonID) { + case OIS::MB_Left: + return CEGUI::LeftButton; + case OIS::MB_Right: + return CEGUI::RightButton; + case OIS::MB_Middle: + return CEGUI::MiddleButton; + default: + return CEGUI::LeftButton; + } + } + +private: + AppPak *app_pak; + bool keep_running; + + OIS::InputManager *ois_input_man; + OIS::Mouse *ois_mouse; + OIS::Keyboard *ois_kb; + + unsigned int MAX_BUTTON_NUM; +}; + +class App{ +public: + void go(){ /* Entry Point Called by main() */ + Setup(); + CreateGUIContext(); + CreateGUIRootWindow(); + app_pak.ogre_root->startRendering(); + DestroyGUIRootWindow(); + Shutdown(); + } +private: + void Setup(){ /* Here we set up the basic libs of Ogre, OIS, and CEGUI */ + // --- Init Ogre --- // + app_pak.ogre_root = new Ogre::Root("", "", "Ogre.log"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./media", "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./media/CEGUI/imagesets/", "FileSystem", "imagesets"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./media/CEGUI/schemes/", "FileSystem", "schemes"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./media/CEGUI/fonts/", "FileSystem", "fonts"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./media/CEGUI/looknfeel/", "FileSystem", "looknfeel"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./media/CEGUI/layouts/", "FileSystem", "layouts"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./media/CEGUI/lua_scripts/", "FileSystem", "lua_scripts"); + +#ifdef _DEBUG + app_pak.ogre_root->loadPlugin(Ogre::String("RenderSystem_GL_d")); + app_pak.ogre_root->loadPlugin(Ogre::String("Plugin_OctreeSceneManager_d")); +#else + app_pak.ogre_root->loadPlugin("RenderSystem_GL"); + app_pak.ogre_root->loadPlugin("Plugin_OctreeSceneManager"); +#endif; + + Ogre::RenderSystem* rs = app_pak.ogre_root->getRenderSystemByName("OpenGL Rendering Subsystem"); + if (!(rs->getName() == "OpenGL Rendering Subsystem")){ return; } + rs->setConfigOption("Full Screen", "No"); + rs->setConfigOption("VSync", "No"); + rs->setConfigOption("Video Mode", "1024 x 768 @ 32-bit"); + app_pak.ogre_root->setRenderSystem(rs); + + app_pak.ogre_win = app_pak.ogre_root->initialise(true, "Clean CEGUI Window"); + + Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); + Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); + + //---------[ CEGUI works fine without these, but the black background does not redraw. ]---------// + // --- Ogre Scene Manager --- // + Ogre::SceneManager *scene_man = app_pak.ogre_root->createSceneManager("OctreeSceneManager", "DefaultSceneManager"); + + // --- Camera --- // + Ogre::Camera *main_cam = scene_man->createCamera("MainCam"); + main_cam->setPosition(Ogre::Vector3(40, 20, 80)); + main_cam->lookAt(Ogre::Vector3(0, 0, 0)); + main_cam->setNearClipDistance(5); + + // --- Viewport --- // + Ogre::Viewport* vp = app_pak.ogre_win->addViewport(main_cam); + vp->setBackgroundColour(Ogre::ColourValue(17.f / 255.f, 17.f / 255.f, 17.f / 255.f)); + main_cam->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); + //----------------------------------------------[|]----------------------------------------------// + + // --- Init OIS --- // + Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); + size_t windowHnd = 0; + std::ostringstream windowHndStr; + app_pak.ogre_win->getCustomAttribute("WINDOW", &windowHnd); + windowHndStr << windowHnd; + app_pak.ois_pl = new OIS::ParamList(); + app_pak.ois_pl->insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); + + // --- Init CEGUI --- // + Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing CEGUI ***"); + app_pak.cegui_renderer = &CEGUI::OgreRenderer::bootstrapSystem(); + CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef(1024.f, 768.f)); + CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative); + + // setup CEGUI default resource groups + CEGUI::ImageManager::setImagesetDefaultResourceGroup("imagesets"); + CEGUI::Scheme::setDefaultResourceGroup("schemes"); + CEGUI::Font::setDefaultResourceGroup("fonts"); + CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeel"); + CEGUI::WindowManager::setDefaultResourceGroup("layouts"); + CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts"); + + // --- Init Ogre/OIS Listeners --- // + app_listener = new AppListener(&app_pak); + app_pak.ogre_root->addFrameListener(app_listener); + Ogre::WindowEventUtilities::addWindowEventListener(app_pak.ogre_win, app_listener); + + } + void Shutdown(){ + // --- Shutdown Ogre, OIS, and CEGUI --- // + app_pak.ogre_root->getAutoCreatedWindow()->removeAllViewports(); + Ogre::WindowEventUtilities::removeWindowEventListener(app_pak.ogre_win, app_listener); + app_listener->windowClosed(app_pak.ogre_win); + app_pak.ogre_root->removeFrameListener( app_listener ); + delete app_listener; + + delete app_pak.ogre_root; + delete app_pak.ois_pl; + } + void CreateGUIContext(){ + // --- Create resources we need --- // + CEGUI::SchemeManager::getSingleton().createFromFile("VanillaSkin.scheme"); + CEGUI::SchemeManager::getSingleton().createFromFile("AlfiskoSkin.scheme"); + CEGUI::FontManager::getSingleton().createFromFile("DejaVuSans-12.font"); + + // --- Create our GUIContext and set its defaults --- // + CEGUI::System::getSingleton().createGUIContext(app_pak.cegui_renderer->getDefaultRenderTarget()); + CEGUI::System::getSingleton().getDefaultGUIContext().setDefaultFont("DejaVuSans-12"); + CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("Vanilla-Images/MouseArrow"); + //CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().show(); // Only important to bring cursor back from hide() + } + void CreateGUIRootWindow(){ + ui_root_win = CEGUI::WindowManager::getSingleton().loadLayoutFromFile("application_templates.layout"); + CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(ui_root_win); + } + void DestroyGUIRootWindow(){ + CEGUI::WindowManager::getSingleton().destroyWindow(ui_root_win); + } + + AppPak app_pak; + AppListener *app_listener; + + CEGUI::Window *ui_root_win; +}; + +//-------------------------------------------------------------------[ Init ]---// +std::wstring s2ws(const std::string& s){ + int len; + int slength = (int)s.length() + 1; + len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); + wchar_t* buf = new wchar_t[len]; + MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); + std::wstring r(buf); + delete[] buf; + return r; +} + +#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 +INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT){ +#else +int main(int argc, char *argv[]){ +#endif + App my_app; + + try { + my_app.go(); + } + catch (Ogre::Exception& e){ +#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 + std::wstring stemp1 = s2ws("Stoopid Ogre exception has occurred!"); + std::wstring stemp2 = s2ws(e.getFullDescription().c_str()); + + LPCWSTR title = stemp1.c_str(); + LPCWSTR error_desc = stemp2.c_str(); + MessageBox(NULL, error_desc, title, MB_OK | MB_ICONERROR | MB_TASKMODAL); +#else + std::cerr << "Stoopid Ogre exception has occurred: " << e.getFullDescription().c_str() << std::endl; +#endif + } + + return 0; +} \ No newline at end of file diff --git a/application_templates/SDL2.cpp b/application_templates/SDL2.cpp new file mode 100644 index 000000000..85c793c8e --- /dev/null +++ b/application_templates/SDL2.cpp @@ -0,0 +1,337 @@ +/*********************************************************************** +created: Sep 11 2014 +author: Luca Ebach +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ + +/************************************************************************** +* The following libs (and corresponding headers) are needed to compile and to link: +* CEGUIBase +* CEGUIOpenGLRenderer +* CEGUICoreWindowRendererSet +* default CEGUI xml parser (and dependencies) +* SDL2main (windows only) +* SDL2 +* OpengGL +* glm headers (as part of CEGUIBase) +***************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "sdl_scancode_to_dinput_mappings.h" + +static SDL_Window* window; +static SDL_GLContext context; + +CEGUI::Key::Scan toCEGUIKey(SDL_Scancode key) +{ + return static_cast(scanCodeToKeyNum[static_cast(key)]); +} + +void injectUTF8Text(const char* utf8str) +{ + static SDL_iconv_t cd = SDL_iconv_t(-1); + + if (cd == SDL_iconv_t(-1)) + { + // note: just "UTF-32" doesn't work as toFormat, because then you get BOMs, which we don't want. + const char* toFormat = "UTF-32LE"; // TODO: what does CEGUI expect on big endian machines? + cd = SDL_iconv_open(toFormat, "UTF-8"); + if (cd == SDL_iconv_t(-1)) + { + std::cerr << "Couldn't initialize SDL_iconv for UTF-8 to UTF-32!" << std::endl; + return; + } + } + + // utf8str has at most SDL_TEXTINPUTEVENT_TEXT_SIZE (32) chars, + // so we won't have have more utf32 chars than that + Uint32 utf32buf[SDL_TEXTINPUTEVENT_TEXT_SIZE] = {0}; + + // we'll convert utf8str to a utf32 string, saved in utf32buf. + // the utf32 chars will be injected into cegui + + size_t len = strlen(utf8str); + + size_t inbytesleft = len; + size_t outbytesleft = 4 * SDL_TEXTINPUTEVENT_TEXT_SIZE; // *4 because utf-32 needs 4x as much space as utf-8 + char* outbuf = (char*)utf32buf; + size_t n = SDL_iconv(cd, &utf8str, &inbytesleft, &outbuf, &outbytesleft); + + if (n == size_t(-1)) // some error occured during iconv + { + std::cerr << "Converting UTF-8 string " << utf8str << " from SDL_TEXTINPUT to UTF-32 failed!" << std::endl; + } + + for (int i = 0; i < SDL_TEXTINPUTEVENT_TEXT_SIZE; ++i) + { + if (utf32buf[i] == 0) + break; // end of string + + CEGUI::System::getSingleton().getDefaultGUIContext().injectChar(utf32buf[i]); + } + + // reset cd so it can be used again + SDL_iconv(cd, NULL, &inbytesleft, NULL, &outbytesleft); +} + +void initSDL() +{ + // init everything from SDL + if (SDL_Init(SDL_INIT_EVERYTHING) != 0) + { + std::cerr << "SDL could not be initialized!" << std::endl + << "Error message: " << SDL_GetError() << std::endl; + exit(1); + } + + // create opengl window with size of 800x600px + window = SDL_CreateWindow("CEGUI + SDL2 window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + if (!window) + { + std::cerr << "Could not create SDL window: " << SDL_GetError() << std::endl; + SDL_Quit(); + exit(1); + } + + // disable native mouse cursor + SDL_ShowCursor(0); + + // setup opengl rendering context + context = SDL_GL_CreateContext(window); +} + +void initCEGUI() +{ + using namespace CEGUI; + + // create renderer and enable extra states + OpenGLRenderer& cegui_renderer = OpenGLRenderer::create(Sizef(800.f, 600.f)); + cegui_renderer.enableExtraStateSettings(true); + + // create CEGUI system object + System::create(cegui_renderer); + + // setup resource directories + DefaultResourceProvider* rp = static_cast(System::getSingleton().getResourceProvider()); + rp->setResourceGroupDirectory("schemes", "datafiles/schemes/"); + rp->setResourceGroupDirectory("imagesets", "datafiles/imagesets/"); + rp->setResourceGroupDirectory("fonts", "datafiles/fonts/"); + rp->setResourceGroupDirectory("layouts", "datafiles/layouts/"); + rp->setResourceGroupDirectory("looknfeels", "datafiles/looknfeel/"); + rp->setResourceGroupDirectory("lua_scripts", "datafiles/lua_scripts/"); + rp->setResourceGroupDirectory("schemas", "datafiles/xml_schemas/"); + + // set default resource groups + ImageManager::setImagesetDefaultResourceGroup("imagesets"); + Font::setDefaultResourceGroup("fonts"); + Scheme::setDefaultResourceGroup("schemes"); + WidgetLookManager::setDefaultResourceGroup("looknfeels"); + WindowManager::setDefaultResourceGroup("layouts"); + ScriptModule::setDefaultResourceGroup("lua_scripts"); + + XMLParser* parser = System::getSingleton().getXMLParser(); + if (parser->isPropertyPresent("SchemaDefaultResourceGroup")) + parser->setProperty("SchemaDefaultResourceGroup", "schemas"); + + // load TaharezLook scheme and DejaVuSans-10 font + SchemeManager::getSingleton().createFromFile("TaharezLook.scheme", "schemes"); + FontManager::getSingleton().createFromFile("DejaVuSans-10.font"); + + // set default font and cursor image and tooltip type + System::getSingleton().getDefaultGUIContext().setDefaultFont("DejaVuSans-10"); + System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow"); + System::getSingleton().getDefaultGUIContext().setDefaultTooltipType("TaharezLook/Tooltip"); +} + +void initWindows() +{ + using namespace CEGUI; + + ///////////////////////////////////////////////////////////// + // Add your gui initialisation code in here. + // You can use the following code as an inspiration for + // creating your own windows. + // But you should preferably use layout loading because you won't + // have to recompile everytime you change the layout. + ///////////////////////////////////////////////////////////// + + // load layout + Window* root = WindowManager::getSingleton().loadLayoutFromFile("application_templates.layout"); + System::getSingleton().getDefaultGUIContext().setRootWindow(root); +} + +// convert SDL mouse button to CEGUI mouse button +CEGUI::MouseButton SDLtoCEGUIMouseButton(const Uint8& button) +{ + using namespace CEGUI; + + switch (button) + { + case SDL_BUTTON_LEFT: + return LeftButton; + + case SDL_BUTTON_MIDDLE: + return MiddleButton; + + case SDL_BUTTON_RIGHT: + return RightButton; + + case SDL_BUTTON_X1: + return X1Button; + + case SDL_BUTTON_X2: + return X2Button; + + default: + return NoButton; + } +} + +int main(int /*argc*/, char* /*argv*/[]) +{ + using namespace CEGUI; + + // init SDL + initSDL(); + + // init cegui + initCEGUI(); + + // notify system of the window size + System::getSingleton().notifyDisplaySizeChanged(Sizef(800.f, 600.f)); + + // initialise windows and setup layout + initWindows(); + + // set gl clear color + glClearColor(0, 0, 0, 255); + + bool quit = false; + SDL_Event event; + float time = SDL_GetTicks() / 1000.f; + + OpenGLRenderer* renderer = static_cast(System::getSingleton().getRenderer()); + + // repeat until a quit is requested + while (!quit && !SDL_QuitRequested()) + { + // query and process events + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + quit = true; + break; + + case SDL_MOUSEMOTION: + CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(static_cast(event.motion.x), + static_cast(event.motion.y)); + break; + + case SDL_MOUSEBUTTONDOWN: + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(SDLtoCEGUIMouseButton(event.button.button)); + break; + + case SDL_MOUSEBUTTONUP: + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(SDLtoCEGUIMouseButton(event.button.button)); + break; + + case SDL_MOUSEWHEEL: + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseWheelChange(static_cast(event.wheel.y)); + break; + + case SDL_KEYDOWN: + CEGUI::System::getSingleton().getDefaultGUIContext().injectKeyDown(toCEGUIKey(event.key.keysym.scancode)); + break; + + case SDL_KEYUP: + CEGUI::System::getSingleton().getDefaultGUIContext().injectKeyUp(toCEGUIKey(event.key.keysym.scancode)); + break; + + case SDL_TEXTINPUT: + injectUTF8Text(event.text.text); + break; + + case SDL_WINDOWEVENT: + if (event.window.event == SDL_WINDOWEVENT_RESIZED) + { + System::getSingleton().notifyDisplaySizeChanged(Sizef(static_cast(event.window.data1), + static_cast(event.window.data2))); + glViewport(0, 0, event.window.data1, event.window.data2); + } + else if (event.window.event == SDL_WINDOWEVENT_LEAVE) + { + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseLeaves(); + } + break; + + default: + break; + + } + } + + glClear(GL_COLOR_BUFFER_BIT); + + // inject time pulses + const float newtime = SDL_GetTicks() / 1000.f; + const float time_elapsed = newtime - time; + System::getSingleton().injectTimePulse(time_elapsed); + System::getSingleton().getDefaultGUIContext().injectTimePulse(time_elapsed); + time = newtime; + + // render gui + renderer->beginRendering(); + System::getSingleton().renderAllGUIContexts(); + renderer->endRendering(); + + // swap buffers + SDL_GL_SwapWindow(window); + } + + // destroy system and renderer + System::destroy(); + OpenGLRenderer::destroy(*renderer); + renderer = 0; + + // delete SDL GL context + SDL_GL_DeleteContext(context); + + // destroy SDL window + SDL_DestroyWindow(window); + + // cleanup SDL + SDL_Quit(); + + return 0; +} diff --git a/application_templates/glfw3.cpp b/application_templates/glfw3.cpp new file mode 100644 index 000000000..39c1c37e9 --- /dev/null +++ b/application_templates/glfw3.cpp @@ -0,0 +1,366 @@ +/*********************************************************************** +created: Sep 15 2014 +author: Luca Ebach +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ + +/************************************************************************** +* The following libs (and corresponding headers) are needed to compile and to link: +* CEGUIBase +* CEGUIOpenGLRenderer +* CEGUICoreWindowRendererSet +* default CEGUI xml parser (and dependencies) +* GLFW3 +* OpengGL +* glm headers (as part of CEGUIBase) +***************************************************************************/ + +#include + +#include +#include + +#include + +static GLFWwindow* window; + +CEGUI::MouseButton toCEGUIButton(int button) +{ + switch (button) + { + case GLFW_MOUSE_BUTTON_LEFT: + return CEGUI::LeftButton; + + case GLFW_MOUSE_BUTTON_MIDDLE: + return CEGUI::MiddleButton; + + case GLFW_MOUSE_BUTTON_RIGHT: + return CEGUI::RightButton; + + default: + return CEGUI::MouseButtonCount; + } +} + +CEGUI::Key::Scan toCEGUIKey(int glfwKey) +{ + switch (glfwKey) + { + case GLFW_KEY_ESCAPE: return CEGUI::Key::Escape; + case GLFW_KEY_F1: return CEGUI::Key::F1; + case GLFW_KEY_F2: return CEGUI::Key::F2; + case GLFW_KEY_F3: return CEGUI::Key::F3; + case GLFW_KEY_F4: return CEGUI::Key::F4; + case GLFW_KEY_F5: return CEGUI::Key::F5; + case GLFW_KEY_F6: return CEGUI::Key::F6; + case GLFW_KEY_F7: return CEGUI::Key::F7; + case GLFW_KEY_F8: return CEGUI::Key::F8; + case GLFW_KEY_F9: return CEGUI::Key::F9; + case GLFW_KEY_F10: return CEGUI::Key::F10; + case GLFW_KEY_F11: return CEGUI::Key::F11; + case GLFW_KEY_F12: return CEGUI::Key::F12; + case GLFW_KEY_F13: return CEGUI::Key::F13; + case GLFW_KEY_F14: return CEGUI::Key::F14; + case GLFW_KEY_F15: return CEGUI::Key::F15; + case GLFW_KEY_UP: return CEGUI::Key::ArrowUp; + case GLFW_KEY_DOWN: return CEGUI::Key::ArrowDown; + case GLFW_KEY_LEFT: return CEGUI::Key::ArrowLeft; + case GLFW_KEY_RIGHT: return CEGUI::Key::ArrowRight; + case GLFW_KEY_LEFT_SHIFT: return CEGUI::Key::LeftShift; + case GLFW_KEY_RIGHT_SHIFT: return CEGUI::Key::RightShift; + case GLFW_KEY_LEFT_CONTROL: return CEGUI::Key::LeftControl; + case GLFW_KEY_RIGHT_CONTROL: return CEGUI::Key::RightControl; + case GLFW_KEY_LEFT_ALT: return CEGUI::Key::LeftAlt; + case GLFW_KEY_RIGHT_ALT: return CEGUI::Key::RightAlt; + case GLFW_KEY_TAB: return CEGUI::Key::Tab; + case GLFW_KEY_ENTER: return CEGUI::Key::Return; + case GLFW_KEY_BACKSPACE: return CEGUI::Key::Backspace; + case GLFW_KEY_INSERT: return CEGUI::Key::Insert; + case GLFW_KEY_DELETE: return CEGUI::Key::Delete; + case GLFW_KEY_PAGE_UP: return CEGUI::Key::PageUp; + case GLFW_KEY_PAGE_DOWN: return CEGUI::Key::PageDown; + case GLFW_KEY_HOME: return CEGUI::Key::Home; + case GLFW_KEY_END: return CEGUI::Key::End; + case GLFW_KEY_KP_ENTER: return CEGUI::Key::NumpadEnter; + case GLFW_KEY_SPACE: return CEGUI::Key::Space; + case 'A': return CEGUI::Key::A; + case 'B': return CEGUI::Key::B; + case 'C': return CEGUI::Key::C; + case 'D': return CEGUI::Key::D; + case 'E': return CEGUI::Key::E; + case 'F': return CEGUI::Key::F; + case 'G': return CEGUI::Key::G; + case 'H': return CEGUI::Key::H; + case 'I': return CEGUI::Key::I; + case 'J': return CEGUI::Key::J; + case 'K': return CEGUI::Key::K; + case 'L': return CEGUI::Key::L; + case 'M': return CEGUI::Key::M; + case 'N': return CEGUI::Key::N; + case 'O': return CEGUI::Key::O; + case 'P': return CEGUI::Key::P; + case 'Q': return CEGUI::Key::Q; + case 'R': return CEGUI::Key::R; + case 'S': return CEGUI::Key::S; + case 'T': return CEGUI::Key::T; + case 'U': return CEGUI::Key::U; + case 'V': return CEGUI::Key::V; + case 'W': return CEGUI::Key::W; + case 'X': return CEGUI::Key::X; + case 'Y': return CEGUI::Key::Y; + case 'Z': return CEGUI::Key::Z; + default: return CEGUI::Key::Unknown; + } +} + +void charCallback(GLFWwindow*, unsigned int char_pressed) +{ + CEGUI::System::getSingleton().getDefaultGUIContext().injectChar(char_pressed); +} + +void cursorPosCallback(GLFWwindow*, double x, double y) +{ + CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(x, y); +} + +void keyCallback(GLFWwindow*, int key, int /*scan*/, int action, int /*mod*/) +{ + CEGUI::Key::Scan cegui_key = toCEGUIKey(key); + if (action == GLFW_PRESS) + { + CEGUI::System::getSingleton().getDefaultGUIContext().injectKeyDown(cegui_key); + } + else + { + CEGUI::System::getSingleton().getDefaultGUIContext().injectKeyUp(cegui_key); + } +} + +void mouseButtonCallback(GLFWwindow*, int button, int state, int /*mod*/) +{ + if (state == GLFW_PRESS) + { + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(toCEGUIButton(button)); + } + else + { + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(toCEGUIButton(button)); + } +} + +void mouseWheelCallback(GLFWwindow*, double /*x*/, double y) +{ + if (y < 0.f) + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseWheelChange(-1.f); + else + CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseWheelChange(+1.f); +} + +void windowResizedCallback(GLFWwindow*, int width, int height) +{ + CEGUI::System::getSingleton().notifyDisplaySizeChanged( + CEGUI::Sizef(static_cast(width), static_cast(height))); + glViewport(0, 0, width, height); +} + +void errorCallback(int /*error*/, const char* message) +{ + CEGUI::Logger::getSingleton().logEvent(message, CEGUI::Errors); +} + +void setupCallbacks() +{ + // input callbacks + glfwSetCharCallback(window, charCallback); + glfwSetCursorPosCallback(window, cursorPosCallback); + glfwSetKeyCallback(window, keyCallback); + glfwSetMouseButtonCallback(window, mouseButtonCallback); + glfwSetScrollCallback(window, mouseWheelCallback); + + // window callback + glfwSetWindowSizeCallback(window, windowResizedCallback); + + // error callback + glfwSetErrorCallback(errorCallback); +} + +void initGLFW() +{ + // init everything from glfw + if (glfwInit() != GL_TRUE) + { + std::cerr << "glfw could not be initialized!" << std::endl; + exit(1); + } + + // create glfw window with size of 800x600px + window = glfwCreateWindow(800, 600, "CEGUI + glfw3 window", NULL, NULL); + if (!window) + { + std::cerr << "Could not create glfw window!" << std::endl; + glfwTerminate(); + exit(1); + } + + // makes this window's gl context the current one + glfwMakeContextCurrent(window); + + // hide native mouse cursor when it is over the window + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + + // disable VSYNC + glfwSwapInterval(0); + + // clear error messages + glGetError(); +} + +void initCEGUI() +{ + using namespace CEGUI; + + // create renderer and enable extra states + OpenGLRenderer& cegui_renderer = OpenGLRenderer::create(Sizef(800.f, 600.f)); + cegui_renderer.enableExtraStateSettings(true); + + // create CEGUI system object + CEGUI::System::create(cegui_renderer); + + // setup resource directories + DefaultResourceProvider* rp = static_cast(System::getSingleton().getResourceProvider()); + rp->setResourceGroupDirectory("schemes", "datafiles/schemes/"); + rp->setResourceGroupDirectory("imagesets", "datafiles/imagesets/"); + rp->setResourceGroupDirectory("fonts", "datafiles/fonts/"); + rp->setResourceGroupDirectory("layouts", "datafiles/layouts/"); + rp->setResourceGroupDirectory("looknfeels", "datafiles/looknfeel/"); + rp->setResourceGroupDirectory("lua_scripts", "datafiles/lua_scripts/"); + rp->setResourceGroupDirectory("schemas", "datafiles/xml_schemas/"); + + // set default resource groups + ImageManager::setImagesetDefaultResourceGroup("imagesets"); + Font::setDefaultResourceGroup("fonts"); + Scheme::setDefaultResourceGroup("schemes"); + WidgetLookManager::setDefaultResourceGroup("looknfeels"); + WindowManager::setDefaultResourceGroup("layouts"); + ScriptModule::setDefaultResourceGroup("lua_scripts"); + + XMLParser* parser = System::getSingleton().getXMLParser(); + if (parser->isPropertyPresent("SchemaDefaultResourceGroup")) + parser->setProperty("SchemaDefaultResourceGroup", "schemas"); + + // load TaharezLook scheme and DejaVuSans-10 font + SchemeManager::getSingleton().createFromFile("TaharezLook.scheme", "schemes"); + FontManager::getSingleton().createFromFile("DejaVuSans-10.font"); + + // set default font and cursor image and tooltip type + System::getSingleton().getDefaultGUIContext().setDefaultFont("DejaVuSans-10"); + System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow"); + System::getSingleton().getDefaultGUIContext().setDefaultTooltipType("TaharezLook/Tooltip"); +} + +void initWindows() +{ + using namespace CEGUI; + + ///////////////////////////////////////////////////////////// + // Add your gui initialisation code in here. + // You should preferably use layout loading because you won't + // have to recompile everytime you change the layout. But you + // can also use static window creation code here, of course. + ///////////////////////////////////////////////////////////// + + // load layout + Window* root = WindowManager::getSingleton().loadLayoutFromFile("application_templates.layout"); + System::getSingleton().getDefaultGUIContext().setRootWindow(root); +} + +#ifdef _MSC_VER +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +#else +int main() +#endif +{ + using namespace CEGUI; + + // init glfw + initGLFW(); + + // init cegui + initCEGUI(); + + // setup glfw callbacks + setupCallbacks(); + + // notify system of the window size + System::getSingleton().notifyDisplaySizeChanged(Sizef(800.f, 600.f)); + glViewport(0, 0, 800, 600); + + // initialise windows and setup layout + initWindows(); + + // set gl clear color + glClearColor(0, 0, 0, 255); + + float time = glfwGetTime(); + + OpenGLRenderer* renderer = static_cast(System::getSingleton().getRenderer()); + + // repeat until a quit is requested + while (glfwWindowShouldClose(window) == GL_FALSE) + { + // clear screen + glClear(GL_COLOR_BUFFER_BIT); + + // inject time pulses + const float newtime = glfwGetTime(); + const float time_elapsed = newtime - time; + System::getSingleton().injectTimePulse(time_elapsed); + System::getSingleton().getDefaultGUIContext().injectTimePulse(time_elapsed); + time = newtime; + + // render gui + renderer->beginRendering(); + System::getSingleton().renderAllGUIContexts(); + renderer->endRendering(); + + // swap buffers + glfwSwapBuffers(window); + + // poll events + glfwPollEvents(); + } + + // destroy system and renderer + System::destroy(); + OpenGLRenderer::destroy(*renderer); + renderer = 0; + + // destroy glfw window + glfwDestroyWindow(window); + + // cleanup glfw + glfwTerminate(); + + return 0; +} diff --git a/application_templates/sdl_scancode_to_dinput_mappings.h b/application_templates/sdl_scancode_to_dinput_mappings.h new file mode 100644 index 000000000..d8d2d24fc --- /dev/null +++ b/application_templates/sdl_scancode_to_dinput_mappings.h @@ -0,0 +1,361 @@ +/* + * Maps SDL2 scancodes to directinput keynums/scancodes. + * Useful if you're porting a game that uses dinput scancodes internally + * (for key bindings etc) or any other lib (like CEGUI) that uses them. + * + * (C) 2015 Daniel Gibson, do whatever you want with this. + * + * No warranty is offered or implied; use this code at your own risk. + * + * Released to the Public Domain, do whatever you want with this: use it, + * modify it, copy it into your own code, ... + * No need to mention me or this "license" in your code or docs, even though + * it would be appreciated, of course. + */ + + +#ifndef _SDL2_SCANCODE_TO_DINPUT_MAPPINGS_H_ +#define _SDL2_SCANCODE_TO_DINPUT_MAPPINGS_H_ + + // TODO: map the following keys, if possible: + // #define DIK_UNDERLINE 0x93 /* (NEC PC98) */ + // #define DIK_KANJI 0x94 /* (Japanese keyboard) */ + // #define DIK_AX 0x96 /* (Japan AX) */ + // #define DIK_UNLABELED 0x97 /* (J3100) */ + // + // #define DIK_WAKE 0xE3 /* System Wake */ + // + // (#define DIK_ABNT_C2 0x7E /* Numpad . on Brazilian keyboard */ - system should map this to KP_COMMA or something, + // according to USB doc, so probably it doesn't need mapping here) + +// maps SDL2 scancodes to directinput keynums/scancodes - dinput_key = scanCodeToKeyNum[(int)your_sdl2_scancode]; +static int scanCodeToKeyNum[SDL_NUM_SCANCODES] = { + 0x0, // SDL_SCANCODE_UNKNOWN = 0, => 0 should also work for dinput codes as "not assigned/unknown" + 0x0, // // 1 (unused) + 0x0, // // 2 (unused) + 0x0, // // 3 (unused) + 0x1E, // SDL_SCANCODE_A = 4, - DIK_A + 0x30, // SDL_SCANCODE_B = 5, - DIK_B + 0x2E, // SDL_SCANCODE_C = 6, - DIK_C + 0x20, // SDL_SCANCODE_D = 7, - DIK_D + 0x12, // SDL_SCANCODE_E = 8, - DIK_E + 0x21, // SDL_SCANCODE_F = 9, - DIK_F + 0x22, // SDL_SCANCODE_G = 10, - DIK_G + 0x23, // SDL_SCANCODE_H = 11, - DIK_H + 0x17, // SDL_SCANCODE_I = 12, - DIK_I + 0x24, // SDL_SCANCODE_J = 13, - DIK_J + 0x25, // SDL_SCANCODE_K = 14, - DIK_K + 0x26, // SDL_SCANCODE_L = 15, - DIK_L + 0x32, // SDL_SCANCODE_M = 16, - DIK_M + 0x31, // SDL_SCANCODE_N = 17, - DIK_N + 0x18, // SDL_SCANCODE_O = 18, - DIK_O + 0x19, // SDL_SCANCODE_P = 19, - DIK_P + 0x10, // SDL_SCANCODE_Q = 20, - DIK_Q + 0x13, // SDL_SCANCODE_R = 21, - DIK_R + 0x1F, // SDL_SCANCODE_S = 22, - DIK_S + 0x14, // SDL_SCANCODE_T = 23, - DIK_T + 0x16, // SDL_SCANCODE_U = 24, - DIK_U + 0x2F, // SDL_SCANCODE_V = 25, - DIK_V + 0x11, // SDL_SCANCODE_W = 26, - DIK_W + 0x2D, // SDL_SCANCODE_X = 27, - DIK_X + 0x15, // SDL_SCANCODE_Y = 28, - DIK_Y + 0x2C, // SDL_SCANCODE_Z = 29, - DIK_Z + + 0x02, // SDL_SCANCODE_1 = 30, - DIK_1 + 0x03, // SDL_SCANCODE_2 = 31, - DIK_2 + 0x04, // SDL_SCANCODE_3 = 32, - DIK_3 + 0x05, // SDL_SCANCODE_4 = 33, - DIK_4 + 0x06, // SDL_SCANCODE_5 = 34, - DIK_5 + 0x07, // SDL_SCANCODE_6 = 35, - DIK_6 + 0x08, // SDL_SCANCODE_7 = 36, - DIK_7 + 0x09, // SDL_SCANCODE_8 = 37, - DIK_8 + 0x0A, // SDL_SCANCODE_9 = 38, - DIK_9 + 0x0B, // SDL_SCANCODE_0 = 39, - DIK_0 + + 0x1C, // SDL_SCANCODE_RETURN = 40, - DIK_RETURN + 0x01, // SDL_SCANCODE_ESCAPE = 41, - DIK_ESCAPE + 0x0E, // SDL_SCANCODE_BACKSPACE = 42, - DIK_BACK + 0x0F, // SDL_SCANCODE_TAB = 43, - DIK_TAB + 0x39, // SDL_SCANCODE_SPACE = 44, - DIK_SPACE + + 0x0C, // SDL_SCANCODE_MINUS = 45, - DIK_MINUS + 0x0D, // SDL_SCANCODE_EQUALS = 46, - DIK_EQUALS + 0x1A, // SDL_SCANCODE_LEFTBRACKET = 47, - DIK_LBRACKET + 0x1B, // SDL_SCANCODE_RIGHTBRACKET = 48, - DIK_RBRACKET + 0x2B, // SDL_SCANCODE_BACKSLASH = 49, // next to enter, US: [\|] DE: [#'] UK: [#~] - DIK_BACKSLASH + 0x2B, // SDL_SCANCODE_NONUSHASH = 50, // same key as before actually on some layouts, systems should map this to SDL_SCANCODE_BACKSLASH - DIK_BACKSLASH + 0x27, // SDL_SCANCODE_SEMICOLON = 51, - DIK_SEMICOLON + 0x28, // SDL_SCANCODE_APOSTROPHE = 52, - DIK_APOSTROPHE + 0x29, // SDL_SCANCODE_GRAVE = 53, // "quake/doom3 console key" - DIK_GRAVE + 0x33, // SDL_SCANCODE_COMMA = 54, - DIK_COMMA + 0x34, // SDL_SCANCODE_PERIOD = 55, - DIK_PERIOD + 0x35, // SDL_SCANCODE_SLASH = 56, - DIK_SLASH + + 0x3A, // SDL_SCANCODE_CAPSLOCK = 57, - DIK_CAPITAL + + 0x3B, // SDL_SCANCODE_F1 = 58, - DIK_F1 + 0x3C, // SDL_SCANCODE_F2 = 59, - DIK_F2 + 0x3D, // SDL_SCANCODE_F3 = 60, - DIK_F3 + 0x3E, // SDL_SCANCODE_F4 = 61, - DIK_F4 + 0x3F, // SDL_SCANCODE_F5 = 62, - DIK_F5 + 0x40, // SDL_SCANCODE_F6 = 63, - DIK_F6 + 0x41, // SDL_SCANCODE_F7 = 64, - DIK_F7 + 0x42, // SDL_SCANCODE_F8 = 65, - DIK_F8 + 0x43, // SDL_SCANCODE_F9 = 66, - DIK_F9 + 0x44, // SDL_SCANCODE_F10 = 67, - DIK_F10 + 0x57, // SDL_SCANCODE_F11 = 68, - DIK_F11 + 0x58, // SDL_SCANCODE_F12 = 69, - DIK_F12 + + 0xB7, // SDL_SCANCODE_PRINTSCREEN = 70, // - DIK_SYSRQ; SDL_SCANCODE_SYSREQ also maps to this! + + 0x46, // SDL_SCANCODE_SCROLLLOCK = 71, - DIK_SCROLL + 0xC5, // SDL_SCANCODE_PAUSE = 72, - DIK_PAUSE + 0xD2, // SDL_SCANCODE_INSERT = 73, // insert on PC, help on some Mac keyboards (but does send code 73, not 117) - DIK_INSERT + 0xC7, // SDL_SCANCODE_HOME = 74, - DIK_HOME + 0xC9, // SDL_SCANCODE_PAGEUP = 75, - DIK_PRIOR + 0xD3, // SDL_SCANCODE_DELETE = 76, - DIK_DELETE + 0xCF, // SDL_SCANCODE_END = 77, - DIK_END + 0xD1, // SDL_SCANCODE_PAGEDOWN = 78, - DIK_NEXT + 0xCD, // SDL_SCANCODE_RIGHT = 79, - DIK_RIGHT + 0xCB, // SDL_SCANCODE_LEFT = 80, - DIK_LEFT + 0xD0, // SDL_SCANCODE_DOWN = 81, - DIK_DOWN + 0xC8, // SDL_SCANCODE_UP = 82, - DIK_UP + + 0x45, // SDL_SCANCODE_NUMLOCKCLEAR = 83, // num lock on PC, clear on Mac keyboards - DIK_NUMLOCK + + 0xB5, // SDL_SCANCODE_KP_DIVIDE = 84, - DIK_DIVIDE + 0x37, // SDL_SCANCODE_KP_MULTIPLY = 85, - DIK_MULTIPLY + 0x4A, // SDL_SCANCODE_KP_MINUS = 86, - DIK_SUBTRACT + 0x4E, // SDL_SCANCODE_KP_PLUS = 87, - DIK_ADD + 0x9C, // SDL_SCANCODE_KP_ENTER = 88, - DIK_NUMPADENTER + 0x4F, // SDL_SCANCODE_KP_1 = 89, - DIK_NUMPAD1 + 0x50, // SDL_SCANCODE_KP_2 = 90, - DIK_NUMPAD2 + 0x51, // SDL_SCANCODE_KP_3 = 91, - DIK_NUMPAD3 + 0x4B, // SDL_SCANCODE_KP_4 = 92, - DIK_NUMPAD4 + 0x4C, // SDL_SCANCODE_KP_5 = 93, - DIK_NUMPAD5 + 0x4D, // SDL_SCANCODE_KP_6 = 94, - DIK_NUMPAD6 + 0x47, // SDL_SCANCODE_KP_7 = 95, - DIK_NUMPAD7 + 0x48, // SDL_SCANCODE_KP_8 = 96, - DIK_NUMPAD8 + 0x49, // SDL_SCANCODE_KP_9 = 97, - DIK_NUMPAD9 + 0x52, // SDL_SCANCODE_KP_0 = 98, - DIK_NUMPAD0 + 0x53, // SDL_SCANCODE_KP_PERIOD = 99, - DIK_DECIMAL + + 0x56, // SDL_SCANCODE_NONUSBACKSLASH = 100, // [<>|] on german keyboard, next to left shift - DIK_OEM_102 + 0xDD, // SDL_SCANCODE_APPLICATION = 101, // windows contextual menu, compose - DIK_APPS + 0xDE, // SDL_SCANCODE_POWER = 102, // should be a status flag, but some mac keyboards have a power key - DIK_POWER + + 0x8D, // SDL_SCANCODE_KP_EQUALS = 103, - DIK_NUMPADEQUALS + 0x64, // SDL_SCANCODE_F13 = 104, - DIK_F13 + 0x65, // SDL_SCANCODE_F14 = 105, - DIK_F14 + 0x66, // SDL_SCANCODE_F15 = 106, - DIK_F15 + 0x67, // SDL_SCANCODE_F16 = 107, // TODO: F16 and up don't have DIK_ constants! is this right? + 0x68, // SDL_SCANCODE_F17 = 108, // (at least 0x67-0x6F have no DIK_constants at all) + 0x69, // SDL_SCANCODE_F18 = 109, + 0x6A, // SDL_SCANCODE_F19 = 110, + 0x6B, // SDL_SCANCODE_F20 = 111, + 0x6C, // SDL_SCANCODE_F21 = 112, + 0x6D, // SDL_SCANCODE_F22 = 113, + 0x6E, // SDL_SCANCODE_F23 = 114, + 0x6F, // SDL_SCANCODE_F24 = 115, + + 0x0, // SDL_SCANCODE_EXECUTE = 116, + 0x0, // SDL_SCANCODE_HELP = 117, + 0x0, // SDL_SCANCODE_MENU = 118, + 0x0, // SDL_SCANCODE_SELECT = 119, + + 0x95, // SDL_SCANCODE_STOP = 120, - DIK_STOP + + 0x0, // SDL_SCANCODE_AGAIN = 121, // redo + 0x0, // SDL_SCANCODE_UNDO = 122, + 0x0, // SDL_SCANCODE_CUT = 123, + 0x0, // SDL_SCANCODE_COPY = 124, + 0x0, // SDL_SCANCODE_PASTE = 125, + 0x0, // SDL_SCANCODE_FIND = 126, + 0x0, // SDL_SCANCODE_MUTE = 127, + + 0xB0, // SDL_SCANCODE_VOLUMEUP = 128, - DIK_VOLUMEUP + 0xAE, // SDL_SCANCODE_VOLUMEDOWN = 129, - DIK_VOLUMEDOWN + + // /* not sure whether there's a reason to enable these */ + 0x0, // /* SDL_SCANCODE_LOCKINGCAPSLOCK = 130, */ + 0x0, // /* SDL_SCANCODE_LOCKINGNUMLOCK = 131, */ + 0x0, // /* SDL_SCANCODE_LOCKINGSCROLLLOCK = 132, */ + + 0xB3, // SDL_SCANCODE_KP_COMMA = 133, - DIK_NUMPADCOMMA + + 0x0, // SDL_SCANCODE_KP_EQUALSAS400 = 134, + + 0x73, // SDL_SCANCODE_INTERNATIONAL1 = 135, // this is really brazilian / and ? - DIK_ABNT_C1 + 0x0, // SDL_SCANCODE_INTERNATIONAL2 = 136, // TODO: Hut1_12v2.pdf page 60, footnote 16 + 0x7D, // SDL_SCANCODE_INTERNATIONAL3 = 137, - DIK_YEN + 0x79, // SDL_SCANCODE_INTERNATIONAL4 = 138, // Japan: XFER/"convert kana -> kanji", right of space - DIK_CONVERT + 0x7B, // SDL_SCANCODE_INTERNATIONAL5 = 139, // Japan: NFER/"don't convert kana -> kanji", left of space - DIK_NOCONVERT + 0x0, // SDL_SCANCODE_INTERNATIONAL6 = 140, // TODO: Hut1_12v2.pdf page 60, footnote 20 + 0x0, // SDL_SCANCODE_INTERNATIONAL7 = 141, // Toggle Double-Byte/Single-Byte mode. + 0x0, // SDL_SCANCODE_INTERNATIONAL8 = 142, // Undefined, available for other Front End Language Processors + 0x0, // SDL_SCANCODE_INTERNATIONAL9 = 143, // Undefined, available for other Front End Language Processors + 0x0, // SDL_SCANCODE_LANG1 = 144, // Hangul/English toggle (Korea) + 0x0, // SDL_SCANCODE_LANG2 = 145, // Hanja conversion (Korea) + 0x70, // SDL_SCANCODE_LANG3 = 146, // Katakana (Japan) - DIK_KANA + 0x0, // SDL_SCANCODE_LANG4 = 147, // Hiragana (Japan) + 0x0, // SDL_SCANCODE_LANG5 = 148, // Zenkaku/Hankaku (Japan) + 0x0, // SDL_SCANCODE_LANG6 = 149, // reserved + 0x0, // SDL_SCANCODE_LANG7 = 150, // reserved + 0x0, // SDL_SCANCODE_LANG8 = 151, // reserved + 0x0, // SDL_SCANCODE_LANG9 = 152, // reserved + + 0x0, // SDL_SCANCODE_ALTERASE = 153, // Erase-Eaze + + 0xB7, // SDL_SCANCODE_SYSREQ = 154, - DIK_SYSRQ; SDL_SCANCODE_PRINTSCREEN also maps to this! + + 0x0, // SDL_SCANCODE_CANCEL = 155, + 0x0, // SDL_SCANCODE_CLEAR = 156, + 0x0, // SDL_SCANCODE_PRIOR = 157, + 0x0, // SDL_SCANCODE_RETURN2 = 158, + 0x0, // SDL_SCANCODE_SEPARATOR = 159, + 0x0, // SDL_SCANCODE_OUT = 160, + 0x0, // SDL_SCANCODE_OPER = 161, + 0x0, // SDL_SCANCODE_CLEARAGAIN = 162, + 0x0, // SDL_SCANCODE_CRSEL = 163, + 0x0, // SDL_SCANCODE_EXSEL = 164, + + 0x0, // 165 (unused) + 0x0, // 166 (unused) + 0x0, // 167 (unused) + 0x0, // 168 (unused) + 0x0, // 169 (unused) + 0x0, // 170 (unused) + 0x0, // 171 (unused) + 0x0, // 172 (unused) + 0x0, // 173 (unused) + 0x0, // 174 (unused) + 0x0, // 175 (unused) + + 0x0, // SDL_SCANCODE_KP_00 = 176, + 0x0, // SDL_SCANCODE_KP_000 = 177, + 0x0, // SDL_SCANCODE_THOUSANDSSEPARATOR = 178, + 0x0, // SDL_SCANCODE_DECIMALSEPARATOR = 179, + 0x0, // SDL_SCANCODE_CURRENCYUNIT = 180, + 0x0, // SDL_SCANCODE_CURRENCYSUBUNIT = 181, + 0x0, // SDL_SCANCODE_KP_LEFTPAREN = 182, + 0x0, // SDL_SCANCODE_KP_RIGHTPAREN = 183, + 0x0, // SDL_SCANCODE_KP_LEFTBRACE = 184, + 0x0, // SDL_SCANCODE_KP_RIGHTBRACE = 185, + 0x0, // SDL_SCANCODE_KP_TAB = 186, + 0x0, // SDL_SCANCODE_KP_BACKSPACE = 187, + 0x0, // SDL_SCANCODE_KP_A = 188, + 0x0, // SDL_SCANCODE_KP_B = 189, + 0x0, // SDL_SCANCODE_KP_C = 190, + 0x0, // SDL_SCANCODE_KP_D = 191, + 0x0, // SDL_SCANCODE_KP_E = 192, + 0x0, // SDL_SCANCODE_KP_F = 193, + 0x0, // SDL_SCANCODE_KP_XOR = 194, + 0x0, // SDL_SCANCODE_KP_POWER = 195, + 0x0, // SDL_SCANCODE_KP_PERCENT = 196, + 0x0, // SDL_SCANCODE_KP_LESS = 197, + 0x0, // SDL_SCANCODE_KP_GREATER = 198, + 0x0, // SDL_SCANCODE_KP_AMPERSAND = 199, + 0x0, // SDL_SCANCODE_KP_DBLAMPERSAND = 200, + 0x0, // SDL_SCANCODE_KP_VERTICALBAR = 201, + 0x0, // SDL_SCANCODE_KP_DBLVERTICALBAR = 202, + + 0x92, // SDL_SCANCODE_KP_COLON = 203, - DIK_COLON + + 0x0, // SDL_SCANCODE_KP_HASH = 204, + 0x0, // SDL_SCANCODE_KP_SPACE = 205, + + 0x91, // SDL_SCANCODE_KP_AT = 206, - DIK_AT + + 0x0, // SDL_SCANCODE_KP_EXCLAM = 207, + 0x0, // SDL_SCANCODE_KP_MEMSTORE = 208, + 0x0, // SDL_SCANCODE_KP_MEMRECALL = 209, + 0x0, // SDL_SCANCODE_KP_MEMCLEAR = 210, + 0x0, // SDL_SCANCODE_KP_MEMADD = 211, + 0x0, // SDL_SCANCODE_KP_MEMSUBTRACT = 212, + 0x0, // SDL_SCANCODE_KP_MEMMULTIPLY = 213, + 0x0, // SDL_SCANCODE_KP_MEMDIVIDE = 214, + 0x0, // SDL_SCANCODE_KP_PLUSMINUS = 215, + 0x0, // SDL_SCANCODE_KP_CLEAR = 216, + 0x0, // SDL_SCANCODE_KP_CLEARENTRY = 217, + 0x0, // SDL_SCANCODE_KP_BINARY = 218, + 0x0, // SDL_SCANCODE_KP_OCTAL = 219, + 0x0, // SDL_SCANCODE_KP_DECIMAL = 220, + 0x0, // SDL_SCANCODE_KP_HEXADECIMAL = 221, + + 0x0, // 222 (unused) + 0x0, // 223 (unused) + + 0x1D, // SDL_SCANCODE_LCTRL = 224, - DIK_LCONTROL + 0x2A, // SDL_SCANCODE_LSHIFT = 225, - DIK_LSHIFT + 0x38, // SDL_SCANCODE_LALT = 226, // left Alt, option - DIK_LMENU + 0xDB, // SDL_SCANCODE_LGUI = 227, // left windows, command (apple), meta - DIK_LWIN + 0x9D, // SDL_SCANCODE_RCTRL = 228, - DIK_RCONTROL + 0x36, // SDL_SCANCODE_RSHIFT = 229, - DIK_RSHIFT + 0xB8, // SDL_SCANCODE_RALT = 230, // right Alt/AltGr, option - DIK_RMENU, also used for SDL_SCANCODE_MODE! + 0xDC, // SDL_SCANCODE_RGUI = 231, // left windows, command (apple), meta - DIK_RWIN + + // 232 - 256 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, // 232 - 240 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 241-250 unused + 0, 0, 0, 0, 0, 0, // 251-256 unused + + 0xB8, // SDL_SCANCODE_MODE = 257, // this seems to be the AltGr Key? - DIK_RMENU (right alt) + + // These values are mapped from usage page 0x0C (USB consumer page). + 0x99, // SDL_SCANCODE_AUDIONEXT = 258, - DIK_NEXTTRACK + 0x90, // SDL_SCANCODE_AUDIOPREV = 259, - DIK_PREVTRACK, which is DIK_CIRCUMFLEX on japanese keyboards + 0xA4, // SDL_SCANCODE_AUDIOSTOP = 260, - DIK_MEDIASTOP + 0xA2, // SDL_SCANCODE_AUDIOPLAY = 261, - DIK_PLAYPAUSE + 0xA0, // SDL_SCANCODE_AUDIOMUTE = 262, - DIK_MUTE + 0xED, // SDL_SCANCODE_MEDIASELECT = 263, - DIK_MEDIASELECT + + 0x0, // SDL_SCANCODE_WWW = 264, + + 0xEC, // SDL_SCANCODE_MAIL = 265, - DIK_MAIL + 0xA1, // SDL_SCANCODE_CALCULATOR = 266, - DIK_CALCULATOR + 0xEB, // SDL_SCANCODE_COMPUTER = 267, - DIK_MYCOMPUTER + 0xE5, // SDL_SCANCODE_AC_SEARCH = 268, - DIK_WEBSEARCH + 0xB2, // SDL_SCANCODE_AC_HOME = 269, - DIK_WEBHOME + 0xEA, // SDL_SCANCODE_AC_BACK = 270, - DIK_WEBBACK + 0xE9, // SDL_SCANCODE_AC_FORWARD = 271, - DIK_WEBFORWARD + 0xE8, // SDL_SCANCODE_AC_STOP = 272, - DIK_WEBSTOP + 0xE7, // SDL_SCANCODE_AC_REFRESH = 273, - DIK_WEBREFRESH + 0xE6, // SDL_SCANCODE_AC_BOOKMARKS = 274, - DIK_WEBFAVORITES + + // These are values that Christian Walther added (for mac keyboard?). + 0x0, // SDL_SCANCODE_BRIGHTNESSDOWN = 275, + 0x0, // SDL_SCANCODE_BRIGHTNESSUP = 276, + 0x0, // SDL_SCANCODE_DISPLAYSWITCH = 277, // display mirroring/dual display switch, video mode switch + 0x0, // SDL_SCANCODE_KBDILLUMTOGGLE = 278, + 0x0, // SDL_SCANCODE_KBDILLUMDOWN = 279, + 0x0, // SDL_SCANCODE_KBDILLUMUP = 280, + 0x0, // SDL_SCANCODE_EJECT = 281, + + 0xDF, // SDL_SCANCODE_SLEEP = 282, - DIK_SLEEP + + 0x0, // SDL_SCANCODE_APP1 = 283, + 0x0, // SDL_SCANCODE_APP2 = 284, + // end of Walther-keys + + // the rest up to 511 are currently not named in SDL + + 0, 0, 0, 0, 0, 0, // 285-290 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 291-300 unused + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 301-320 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 321-340 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 341-360 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 361-380 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 381-400 unused + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 401-420 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 421-440 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 441-460 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 461-480 unused + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 481-500 unused + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // 501-511 unused +}; + + +#endif /* _SDL2_SCANCODE_TO_DINPUT_MAPPINGS_H_ */ diff --git a/cegui/include/CEGUI/Base.h b/cegui/include/CEGUI/Base.h index 43dfaf44c..daa24b564 100644 --- a/cegui/include/CEGUI/Base.h +++ b/cegui/include/CEGUI/Base.h @@ -131,12 +131,15 @@ # define CEGUI_FUNCTION_NAME CEGUI::String(__FUNCSIG__) #elif defined(__GNUC__) # define CEGUI_FUNCTION_NAME CEGUI::String(__PRETTY_FUNCTION__) -#elif __STDC_VERSION__ >= 199901L +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L # define CEGUI_FUNCTION_NAME CEGUI::String(__func__) #else # define CEGUI_FUNCTION_NAME CEGUI::String("[Function name unavailable]") #endif +//! Prevent an "unused parameter/variable" warning. +#define CEGUI_UNUSED(var) (static_cast(var)) + /************************************************************************* Documentation for the CEGUI namespace itself *************************************************************************/ @@ -158,10 +161,10 @@ typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned char uchar; -typedef long long int64; -typedef int int32; -typedef short int16; -typedef char int8; +typedef long long int64; +typedef int int32; +typedef short int16; +typedef signed char int8; typedef unsigned long long uint64; typedef unsigned int uint32; diff --git a/cegui/include/CEGUI/BasicRenderedStringParser.h b/cegui/include/CEGUI/BasicRenderedStringParser.h index 1dbe4a4e0..c39354a97 100644 --- a/cegui/include/CEGUI/BasicRenderedStringParser.h +++ b/cegui/include/CEGUI/BasicRenderedStringParser.h @@ -96,6 +96,7 @@ class CEGUIEXPORT BasicRenderedStringParser : public RenderedStringParser \param initial_colours Reference to a ColourRect describing the initial colours to be used. */ + //! \deprecated This constructor is deprecated and will be removed in the next major version */ BasicRenderedStringParser(const String& initial_font, const ColourRect& initial_colours); //! Destructor. @@ -108,6 +109,7 @@ class CEGUIEXPORT BasicRenderedStringParser : public RenderedStringParser \param font_name String object holding the name of the font. */ + //! \deprecated This function is deprecated and will be removed in the next major version */ void setInitialFontName(const String& font_name); /*! @@ -117,24 +119,27 @@ class CEGUIEXPORT BasicRenderedStringParser : public RenderedStringParser \param colours ColourRect object holding the colours. */ + //! \deprecated This function is deprecated and will be removed in the next major version */ void setInitialColours(const ColourRect& colours); /*! \brief Return the name of the initial font used in each parse. */ + //! \deprecated This function is deprecated and will be removed in the next major version */ const String& getInitialFontName() const; /*! \brief Return a ColourRect describing the initial colours used in each parse. */ + //! \deprecated This function is deprecated and will be removed in the next major version */ const ColourRect& getInitialColours() const; // implement required interface from RenderedStringParser RenderedString parse(const String& input_string, - const Font* initial_font, - const ColourRect* initial_colours); + const Font* active_font, + const ColourRect* active_colours); protected: //! append the text string \a text to the RenderedString \a rs. @@ -165,9 +170,9 @@ class CEGUIEXPORT BasicRenderedStringParser : public RenderedStringParser void handleImageWidth(RenderedString& rs, const String& value); void handleImageHeight(RenderedString& rs, const String& value); - //! initial font name + //! \deprecated This variable is deprecated and will removed in the next major version */ String d_initialFontName; - //! initial colours + //! \deprecated This variable is deprecated and will removed in the next major version */ ColourRect d_initialColours; //! active padding values. Rectf d_padding; diff --git a/cegui/include/CEGUI/Config.h.in b/cegui/include/CEGUI/Config.h.in index 11b2533cc..e2f683896 100644 --- a/cegui/include/CEGUI/Config.h.in +++ b/cegui/include/CEGUI/Config.h.in @@ -175,6 +175,12 @@ setting CMake options and regenerating, rather than editing directly. // Uncomment this to use an external fribidi library. #cmakedefine CEGUI_USE_FRIBIDI +// Controls whether to use GLEW as an OpenGL loading library. +#cmakedefine CEGUI_USE_GLEW + +// Controls whether to use Epoxy as an OpenGL loading library. +#cmakedefine CEGUI_USE_EPOXY + ////////////////////////////////////////////////////////////////////////// // The following controls whether the MinizipResourceProvider will be // built into the CEGUIBase library. You can uncomment the following line @@ -189,7 +195,7 @@ setting CMake options and regenerating, rather than editing directly. // this can be changed at runtime via the CEGUI_MODULE_DIR environment var. #if defined(_WIN32) || defined(__WIN32__) # define CEGUI_MODULE_DIR "${CMAKE_BINARY_DIR}/bin/" -#else +#elif !defined(__ANDROID__) # define CEGUI_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/${CEGUI_MODULE_INSTALL_DIR}/" #endif diff --git a/cegui/include/CEGUI/EventSet.h b/cegui/include/CEGUI/EventSet.h index abdde3f9c..f20ea54af 100644 --- a/cegui/include/CEGUI/EventSet.h +++ b/cegui/include/CEGUI/EventSet.h @@ -37,7 +37,7 @@ #if defined (_MSC_VER) # pragma warning(push) -# pragma warning(disable : 4251) +# pragma warning(disable : 4251 4521 4522) #endif // Start of CEGUI namespace section @@ -427,11 +427,10 @@ class CEGUIEXPORT EventSet ScriptModule* getScriptModule() const; // Do not allow copying, assignment, or any other usage than simple creation. - EventSet(EventSet&) {} - EventSet& operator=(EventSet&) - { - return *this; - } + EventSet(EventSet&) {} //! \deprecated + EventSet(const EventSet&) {} + EventSet& operator=(EventSet&) { return *this; } //! \deprecated + EventSet& operator=(const EventSet&) { return *this; } typedef std::map EventMap; diff --git a/cegui/include/CEGUI/Exceptions.h b/cegui/include/CEGUI/Exceptions.h index 9cf464904..d26832339 100644 --- a/cegui/include/CEGUI/Exceptions.h +++ b/cegui/include/CEGUI/Exceptions.h @@ -33,6 +33,12 @@ #include "CEGUI/String.h" #include +#if defined(_MSC_VER) +# pragma warning(push) +# pragma warning(disable : 4275) +#endif + + // Start of CEGUI namespace section namespace CEGUI { @@ -464,7 +470,7 @@ class CEGUIEXPORT RendererException : public Exception VS2003. */ #define RendererException(message) \ - RendererException(message, __FILE__, __LINE__, CEGUI_FUNCTION_NAME) + ::CEGUI::RendererException(message, __FILE__, __LINE__, CEGUI_FUNCTION_NAME) //----------------------------------------------------------------------------// @@ -770,5 +776,8 @@ class CEGUIEXPORT ScriptException : public Exception } // End of CEGUI namespace section +#if defined(_MSC_VER) +# pragma warning(pop) +#endif #endif // end of guard _CEGUIExceptions_h_ diff --git a/cegui/include/CEGUI/FreeFunctionSlot.h b/cegui/include/CEGUI/FreeFunctionSlot.h index 90adf04bc..ff6a0775a 100644 --- a/cegui/include/CEGUI/FreeFunctionSlot.h +++ b/cegui/include/CEGUI/FreeFunctionSlot.h @@ -3,7 +3,7 @@ author: Paul D Turner *************************************************************************/ /*************************************************************************** - * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team + * Copyright (C) 2004 - 2014 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -32,6 +32,7 @@ // Start of CEGUI namespace section namespace CEGUI { + /*! \brief Slot functor class that calls back via a free function pointer. @@ -55,6 +56,90 @@ class FreeFunctionSlot : public SlotFunctorBase SlotFunction* d_function; }; +/*! +\brief + Slot functor class that calls back via a free function pointer. + This variant doesn't require a handler that returns bool. + +\note + This functor always returns true to CEGUI, which means the event was + handled. +*/ +class FreeFunctionSlotVoid : public SlotFunctorBase +{ +public: + //! Slot function type. + typedef void (SlotFunction)(const EventArgs&); + + FreeFunctionSlotVoid(SlotFunction* func) : + d_function(func) + {} + + virtual bool operator()(const EventArgs& args) + { + d_function(args); + + return true; + } + +private: + SlotFunction* d_function; +}; + +/*! +\brief + Slot functor class that calls back via a free function pointer. + This variant ignores passed EventArgs. +*/ +class FreeFunctionSlotNoArgs : public SlotFunctorBase +{ +public: + //! Slot function type. + typedef bool (SlotFunction)(); + + FreeFunctionSlotNoArgs(SlotFunction* func) : + d_function(func) + {} + + virtual bool operator()(const EventArgs& /*args*/) + { + return d_function(); + } + +private: + SlotFunction* d_function; +}; + +/*! +\brief + Slot functor class that calls back via a free function pointer. + This variant ignores passed EventArgs and the handler + doesn't have to return a bool. + +\note + This functor always returns true to CEGUI, which means the event was + handled. +*/ +class FreeFunctionSlotVoidNoArgs : public SlotFunctorBase +{ +public: + //! Slot function type. + typedef void (SlotFunction)(); + + FreeFunctionSlotVoidNoArgs(SlotFunction* func) : + d_function(func) + {} + + virtual bool operator()(const EventArgs&) + { + d_function(); + + return true; + } + +private: + SlotFunction* d_function; +}; } // End of CEGUI namespace section diff --git a/cegui/include/CEGUI/FunctorCopySlot.h b/cegui/include/CEGUI/FunctorCopySlot.h index 42b82793e..a80b551ab 100644 --- a/cegui/include/CEGUI/FunctorCopySlot.h +++ b/cegui/include/CEGUI/FunctorCopySlot.h @@ -1,9 +1,10 @@ /************************************************************************ created: Tue Feb 28 2006 - author: Paul D Turner + authors: Paul D Turner + Martin Preisler *************************************************************************/ /*************************************************************************** - * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team + * Copyright (C) 2004 - 2014 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -32,6 +33,223 @@ // Start of CEGUI namespace section namespace CEGUI { + +namespace FunctorCopySlot_detail +{ + typedef char Yes; + typedef int No; + + template + struct HasBoolEventArgsConstOp + { + template struct SFINAE {}; + template static Yes Test(SFINAE*); + template static No Test(...); + static const bool Value = sizeof(Test(0)) == sizeof(Yes); + }; + + template + struct HasBoolEventArgsOp + { + template struct SFINAE {}; + template static Yes Test(SFINAE*); + template static No Test(...); + static const bool Value = sizeof(Test(0)) == sizeof(Yes); + }; + + template + struct HasVoidEventArgsConstOp + { + template struct SFINAE {}; + template static Yes Test(SFINAE*); + template static No Test(...); + static const bool Value = sizeof(Test(0)) == sizeof(Yes); + }; + + template + struct HasVoidEventArgsOp + { + template struct SFINAE {}; + template static Yes Test(SFINAE*); + template static No Test(...); + static const bool Value = sizeof(Test(0)) == sizeof(Yes); + }; + + template + struct HasBoolNoArgsConstOp + { + template struct SFINAE {}; + template static Yes Test(SFINAE*); + template static No Test(...); + static const bool Value = sizeof(Test(0)) == sizeof(Yes); + }; + + template + struct HasBoolNoArgsOp + { + template struct SFINAE {}; + template static Yes Test(SFINAE*); + template static No Test(...); + static const bool Value = sizeof(Test(0)) == sizeof(Yes); + }; + + template + struct HasVoidNoArgsConstOp + { + template struct SFINAE {}; + template static Yes Test(SFINAE*); + template static No Test(...); + static const bool Value = sizeof(Test(0)) == sizeof(Yes); + }; + + // The following 3 templates use the same idea as boost::disable_if + template + struct DisableIfC + { + typedef T Type; + }; + + template + struct DisableIfC + {}; + + template + struct DisableIf : public DisableIfC + {}; + + + // The following is just overload trickery to accommodate 8 allowed + // operator() signatures: + // + // 1) bool (const EventArgs&) const = BoolEventArgsConstOp + // 2) bool (const EventArgs&) = BoolEventArgsOp + // 3) void (const EventArgs&) const = VoidEventArgsConstOp + // 4) void (const EventArgs&) = VoidEventArgsOp + // 5) bool () const = BoolNoArgsConstOp + // 6) bool () = BoolNoArgsOp + // 7) void () const = VoidNoArgsConstOp + // 8) void () = VoidNoArgsOp + // + // The calls are priorised as outlined above, if call 1) is possible, no + // other variants are tried, ... + + template + inline bool call(const T& functor, bool(T::*member_fn)(const EventArgs&) const, const EventArgs& args, + void* = 0, + void* = 0, + void* = 0, + void* = 0, + void* = 0, + void* = 0, + void* = 0 + ) + { + return CEGUI_CALL_MEMBER_FN(functor, member_fn)(args); + } + + template + inline bool call(T& functor, bool(T::*member_fn)(const EventArgs&), const EventArgs& args, + typename DisableIf >::Type* = 0, + void* = 0, + void* = 0, + void* = 0, + void* = 0, + void* = 0, + void* = 0 + ) + { + return CEGUI_CALL_MEMBER_FN(functor, member_fn)(args); + } + + template + inline bool call(const T& functor, void(T::*member_fn)(const EventArgs&) const, const EventArgs& args, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + void* = 0, + void* = 0, + void* = 0, + void* = 0, + void* = 0 + ) + { + CEGUI_CALL_MEMBER_FN(functor, member_fn)(args); + return true; + } + + template + inline bool call(T& functor, void(T::*member_fn)(const EventArgs&), const EventArgs& args, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + void* = 0, + void* = 0, + void* = 0, + void* = 0 + ) + { + CEGUI_CALL_MEMBER_FN(functor, member_fn)(args); + return true; + } + + template + inline bool call(const T& functor, bool(T::*member_fn)() const, const EventArgs& /*args*/, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + void* = 0, + void* = 0, + void* = 0 + ) + { + return CEGUI_CALL_MEMBER_FN(functor, member_fn)(); + } + + template + inline bool call(T& functor, bool(T::*member_fn)(), const EventArgs& /*args*/, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + void* = 0, + void* = 0 + ) + { + return CEGUI_CALL_MEMBER_FN(functor, member_fn)(); + } + + template + inline bool call(const T& functor, void(T::*member_fn)() const, const EventArgs& /*args*/, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + void* = 0 + ) + { + CEGUI_CALL_MEMBER_FN(functor, member_fn)(); + return true; + } + + template + inline bool call(T& functor, void(T::*member_fn)(), const EventArgs& /*args*/, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0, + typename DisableIf >::Type* = 0 + ) + { + CEGUI_CALL_MEMBER_FN(functor, member_fn)(); + return true; + } +} + /*! \brief Slot template class that creates a functor that calls back via a copy of a @@ -41,19 +259,19 @@ template class FunctorCopySlot : public SlotFunctorBase { public: - FunctorCopySlot(const T& functor) : + FunctorCopySlot(const T& functor): d_functor(functor) {} virtual bool operator()(const EventArgs& args) { - return d_functor(args); + return FunctorCopySlot_detail::call(d_functor, &T::operator(), args); } private: T d_functor; }; -} // End of CEGUI namespace section +} #endif // end of guard _CEGUIFunctorCopySlot_h_ diff --git a/cegui/include/CEGUI/ImageCodecModules/SDL2/ImageCodec.h b/cegui/include/CEGUI/ImageCodecModules/SDL2/ImageCodec.h new file mode 100644 index 000000000..07085b1be --- /dev/null +++ b/cegui/include/CEGUI/ImageCodecModules/SDL2/ImageCodec.h @@ -0,0 +1,64 @@ +/*********************************************************************** + created: 04/07/2014 + author: Luca Ebach + with code by John Norman + + purpose: This codec provides SDL2 based image loading +*************************************************************************/ +/*************************************************************************** + * Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + ***************************************************************************/ + +#ifndef _SDL2_IMAGE_CODEC_H_ +#define _SDL2_IMAGE_CODEC_H_ + +#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC) +# ifdef CEGUISDL2IMAGECODEC_EXPORTS +# define CEGUISDL2IMAGECODEC_API __declspec(dllexport) +# else +# define CEGUISDL2IMAGECODEC_API __declspec(dllimport) +# endif +#else +# define CEGUISDL2IMAGECODEC_API +#endif + +#include +#include + +#include + +namespace CEGUI +{ + +class CEGUISDL2IMAGECODEC_API SDL2ImageCodec : public ImageCodec +{ +public: + SDL2ImageCodec(); + ~SDL2ImageCodec(); + + Texture* load(const RawDataContainer& data, Texture* result); +}; + +} // End namespace + +#endif /* IMAGECODEC_H */ + diff --git a/cegui/include/CEGUI/ImageCodecModules/SDL2/ImageCodecModule.h b/cegui/include/CEGUI/ImageCodecModules/SDL2/ImageCodecModule.h new file mode 100644 index 000000000..fde97f5ed --- /dev/null +++ b/cegui/include/CEGUI/ImageCodecModules/SDL2/ImageCodecModule.h @@ -0,0 +1,53 @@ +/*********************************************************************** + created: 04/07/2014 + author: Luca Ebach + with code by John Norman + + purpose: This codec provides SDL2 based image loading +*************************************************************************/ +/*************************************************************************** + * Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + ***************************************************************************/ + +#ifndef _SDL2_IMAGE_CODEC_MODULE_H_ +#define _SDL2_IMAGE_CODEC_MODULE_H_ + +#include + + +/*! + \brief + exported function that creates the ImageCodec based object and + returns a pointer to that object. +*/ +extern "C" CEGUISDL2IMAGECODEC_API CEGUI::ImageCodec* createImageCodec(void); + +/*! + \brief + exported function that deletes an ImageCodec based object previously + created by this module. +*/ +extern "C" CEGUISDL2IMAGECODEC_API void destroyImageCodec(CEGUI::ImageCodec* imageCodec); + + +#endif /* _SDL2_IMAGE_CODEC_MODULE_H_ */ + diff --git a/cegui/include/CEGUI/MemberFunctionSlot.h b/cegui/include/CEGUI/MemberFunctionSlot.h index 6ab481922..5e72ff163 100644 --- a/cegui/include/CEGUI/MemberFunctionSlot.h +++ b/cegui/include/CEGUI/MemberFunctionSlot.h @@ -3,7 +3,7 @@ author: Paul D Turner *************************************************************************/ /*************************************************************************** - * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team + * Copyright (C) 2004 - 2014 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -59,6 +59,100 @@ class MemberFunctionSlot : public SlotFunctorBase T* d_object; }; -} // End of CEGUI namespace section +/*! +\brief + Slot template class that creates a functor that calls back via a class + member function. This variant doesn't require a handler that returns bool. + +\note + This functor always returns true to CEGUI, which means the event was + handled. +*/ +template +class MemberFunctionSlotVoid : public SlotFunctorBase +{ +public: + //! Member function slot type. + typedef void(T::*MemberFunctionType)(const EventArgs&); + + MemberFunctionSlotVoid(MemberFunctionType func, T* obj) : + d_function(func), + d_object(obj) + {} + + virtual bool operator()(const EventArgs& args) + { + (d_object->*d_function)(args); + + return true; + } + +private: + MemberFunctionType d_function; + T* d_object; +}; + +/*! +\brief + Slot template class that creates a functor that calls back via a class + member function. This variant ignores passed EventArgs. +*/ +template +class MemberFunctionSlotNoArgs : public SlotFunctorBase +{ +public: + //! Member function slot type. + typedef bool(T::*MemberFunctionType)(); + + MemberFunctionSlotNoArgs(MemberFunctionType func, T* obj) : + d_function(func), + d_object(obj) + {} + + virtual bool operator()(const EventArgs& /*args*/) + { + return (d_object->*d_function)(); + } + +private: + MemberFunctionType d_function; + T* d_object; +}; + +/*! +\brief + Slot template class that creates a functor that calls back via a class + member function. This variant ignores passed EventArgs and the handler + doesn't have to return a bool. + +\note + This functor always returns true to CEGUI, which means the event was + handled. +*/ +template +class MemberFunctionSlotVoidNoArgs : public SlotFunctorBase +{ +public: + //! Member function slot type. + typedef void(T::*MemberFunctionType)(); + + MemberFunctionSlotVoidNoArgs(MemberFunctionType func, T* obj) : + d_function(func), + d_object(obj) + {} + + virtual bool operator()(const EventArgs& /*args*/) + { + (d_object->*d_function)(); + + return true; + } + +private: + MemberFunctionType d_function; + T* d_object; +}; + +} #endif // end of guard _CEGUIMemberFunctionSlot_h_ diff --git a/cegui/include/CEGUI/PropertyHelper.h b/cegui/include/CEGUI/PropertyHelper.h index 74a33970f..0b0408b28 100644 --- a/cegui/include/CEGUI/PropertyHelper.h +++ b/cegui/include/CEGUI/PropertyHelper.h @@ -49,9 +49,23 @@ #endif #ifdef _MSC_VER -#define snprintf _snprintf + #define snprintf _snprintf #endif +#ifdef __MINGW32__ + + #if __USE_MINGW_ANSI_STDIO != 1 + #warning __USE_MINGW_ANSI_STDIO must be set to 1 for sscanf and snprintf to work with 64bit integers + #endif + + #pragma GCC diagnostic push + + /* Due to a bug in MinGW-w64, a false warning is sometimes issued when using + "%llu" format with the "printf"/"scanf" family of functions. */ + #pragma GCC diagnostic ignored "-Wformat" + #pragma GCC diagnostic ignored "-Wformat-extra-args" + +#endif namespace CEGUI { @@ -979,8 +993,12 @@ class CEGUIEXPORT PropertyHelper } +#ifdef __MINGW32__ + #pragma GCC diagnostic pop +#endif + #if defined(_MSC_VER) -# pragma warning(pop) + #pragma warning(pop) #endif -#endif \ No newline at end of file +#endif diff --git a/cegui/include/CEGUI/RendererModules/Direct3D10/GeometryBuffer.h b/cegui/include/CEGUI/RendererModules/Direct3D10/GeometryBuffer.h index d4a3f08ac..3b07c7fc4 100644 --- a/cegui/include/CEGUI/RendererModules/Direct3D10/GeometryBuffer.h +++ b/cegui/include/CEGUI/RendererModules/Direct3D10/GeometryBuffer.h @@ -32,7 +32,13 @@ #include "../../Rect.h" #include "../../Quaternion.h" -#include +// Unfortunately, MinGW-w64 doesn't have +#ifdef __MINGW32__ + #include + #include +#else + #include +#endif #if defined(_MSC_VER) # pragma warning(push) diff --git a/cegui/include/CEGUI/RendererModules/Direct3D10/RenderTarget.h b/cegui/include/CEGUI/RendererModules/Direct3D10/RenderTarget.h index 985e31a9a..a8d4fd01f 100644 --- a/cegui/include/CEGUI/RendererModules/Direct3D10/RenderTarget.h +++ b/cegui/include/CEGUI/RendererModules/Direct3D10/RenderTarget.h @@ -30,7 +30,14 @@ #include "../../RenderTarget.h" #include "CEGUI/RendererModules/Direct3D10/Renderer.h" #include "../../Rect.h" -#include + +// Unfortunately, MinGW-w64 doesn't have +#ifdef __MINGW32__ + #include + #include +#else + #include +#endif #if defined(_MSC_VER) # pragma warning(push) diff --git a/cegui/include/CEGUI/RendererModules/Direct3D10/Renderer.h b/cegui/include/CEGUI/RendererModules/Direct3D10/Renderer.h index 4732574e2..eb9a39bee 100644 --- a/cegui/include/CEGUI/RendererModules/Direct3D10/Renderer.h +++ b/cegui/include/CEGUI/RendererModules/Direct3D10/Renderer.h @@ -123,6 +123,23 @@ class D3D10_GUIRENDERER_API Direct3D10Renderer : public Renderer The Direct3D10Renderer object to be destroyed. */ static void destroy(Direct3D10Renderer& renderer); + + /*! + \brief + Returns if the texture coordinate system is vertically flipped or not. The original of a + texture coordinate system is typically located either at the the top-left or the bottom-left. + CEGUI, Direct3D and most rendering engines assume it to be on the top-left. OpenGL assumes it to + be at the bottom left. + + This function is intended to be used when generating geometry for rendering the TextureTarget + onto another surface. It is also intended to be used when trying to use a custom texture (RTT) + inside CEGUI using the Image class, in order to determine the Image coordinates correctly. + + \return + - true if flipping is required: the texture coordinate origin is at the bottom left + - false if flipping is not required: the texture coordinate origin is at the top left + */ + bool isTexCoordSystemFlipped() const { return false; } //! return the ID3D10Device used by this renderer object. ID3D10Device& getDirect3DDevice() const; diff --git a/cegui/include/CEGUI/RendererModules/Direct3D11/RenderTarget.h b/cegui/include/CEGUI/RendererModules/Direct3D11/RenderTarget.h index ce04ce866..4dca78b71 100644 --- a/cegui/include/CEGUI/RendererModules/Direct3D11/RenderTarget.h +++ b/cegui/include/CEGUI/RendererModules/Direct3D11/RenderTarget.h @@ -29,7 +29,14 @@ #include "../../RenderTarget.h" #include "CEGUI/RendererModules/Direct3D11/Renderer.h" #include "../../Rect.h" -#include + +// Unfortunately, MinGW-w64 doesn't have +#ifdef __MINGW32__ + #include + #include +#else + #include +#endif #if defined(_MSC_VER) diff --git a/cegui/include/CEGUI/RendererModules/Direct3D11/Renderer.h b/cegui/include/CEGUI/RendererModules/Direct3D11/Renderer.h old mode 100644 new mode 100755 index da1523d9f..475854431 --- a/cegui/include/CEGUI/RendererModules/Direct3D11/Renderer.h +++ b/cegui/include/CEGUI/RendererModules/Direct3D11/Renderer.h @@ -59,9 +59,14 @@ struct ID3D11ShaderResourceView;//D3DXEffect11 in dependences struct D3DXMATRIX; #include -#include -#include +// Unfortunately, MinGW-w64 doesn't have or +#ifdef __MINGW32__ + #include +#else + #include + #include +#endif struct IDevice11//little structure that keeps both device, in order to reduce copy & paste around module { @@ -151,6 +156,23 @@ class D3D11_GUIRENDERER_API Direct3D11Renderer : public Renderer //returns d3d11 container for further rendering and creating IDevice11& getDirect3DDevice(); + + /*! + \brief + Returns if the texture coordinate system is vertically flipped or not. The original of a + texture coordinate system is typically located either at the the top-left or the bottom-left. + CEGUI, Direct3D and most rendering engines assume it to be on the top-left. OpenGL assumes it to + be at the bottom left. + + This function is intended to be used when generating geometry for rendering the TextureTarget + onto another surface. It is also intended to be used when trying to use a custom texture (RTT) + inside CEGUI using the Image class, in order to determine the Image coordinates correctly. + + \return + - true if flipping is required: the texture coordinate origin is at the bottom left + - false if flipping is not required: the texture coordinate origin is at the top left + */ + bool isTexCoordSystemFlipped() const { return false; } //! low-level function that binds the technique pass ready for use void bindTechniquePass(const BlendMode mode, const bool clipped); diff --git a/cegui/include/CEGUI/RendererModules/Direct3D9/Renderer.h b/cegui/include/CEGUI/RendererModules/Direct3D9/Renderer.h index f7222f7cf..4ebef97f9 100644 --- a/cegui/include/CEGUI/RendererModules/Direct3D9/Renderer.h +++ b/cegui/include/CEGUI/RendererModules/Direct3D9/Renderer.h @@ -119,6 +119,23 @@ class DIRECT3D9_GUIRENDERER_API Direct3D9Renderer : public Renderer The Direct3D9Renderer object to be destroyed. */ static void destroy(Direct3D9Renderer& renderer); + + /*! + \brief + Returns if the texture coordinate system is vertically flipped or not. The original of a + texture coordinate system is typically located either at the the top-left or the bottom-left. + CEGUI, Direct3D and most rendering engines assume it to be on the top-left. OpenGL assumes it to + be at the bottom left. + + This function is intended to be used when generating geometry for rendering the TextureTarget + onto another surface. It is also intended to be used when trying to use a custom texture (RTT) + inside CEGUI using the Image class, in order to determine the Image coordinates correctly. + + \return + - true if flipping is required: the texture coordinate origin is at the bottom left + - false if flipping is not required: the texture coordinate origin is at the top left + */ + bool isTexCoordSystemFlipped() const { return false; } //! support function to be called prior to a Reset on the Direct3DDevice9. void preD3DReset(); diff --git a/cegui/include/CEGUI/RendererModules/DirectFB/Renderer.h b/cegui/include/CEGUI/RendererModules/DirectFB/Renderer.h index 83d738561..84bd999b5 100644 --- a/cegui/include/CEGUI/RendererModules/DirectFB/Renderer.h +++ b/cegui/include/CEGUI/RendererModules/DirectFB/Renderer.h @@ -56,6 +56,23 @@ class DirectFBRenderer : public Renderer //! Set the target DirectFB surface. void setTargetSurface(IDirectFBSurface& surface); + + /*! + \brief + Returns if the texture coordinate system is vertically flipped or not. The original of a + texture coordinate system is typically located either at the the top-left or the bottom-left. + CEGUI, Direct3D and most rendering engines assume it to be on the top-left. OpenGL assumes it to + be at the bottom left. + + This function is intended to be used when generating geometry for rendering the TextureTarget + onto another surface. It is also intended to be used when trying to use a custom texture (RTT) + inside CEGUI using the Image class, in order to determine the Image coordinates correctly. + + \return + - true if flipping is required: the texture coordinate origin is at the bottom left + - false if flipping is not required: the texture coordinate origin is at the top left + */ + bool isTexCoordSystemFlipped() const { return false; } // Implementation of Renderer interface. RenderTarget& getDefaultRenderTarget(); diff --git a/cegui/include/CEGUI/RendererModules/Irrlicht/Renderer.h b/cegui/include/CEGUI/RendererModules/Irrlicht/Renderer.h index 43c338ce8..f71e01be5 100644 --- a/cegui/include/CEGUI/RendererModules/Irrlicht/Renderer.h +++ b/cegui/include/CEGUI/RendererModules/Irrlicht/Renderer.h @@ -155,6 +155,23 @@ class IRR_GUIRENDERER_API IrrlichtRenderer : public Renderer next power of two up from \a f if it's not. */ static float getNextPOTSize(const float f); + + /*! + \brief + Returns if the texture coordinate system is vertically flipped or not. The original of a + texture coordinate system is typically located either at the the top-left or the bottom-left. + CEGUI, Direct3D and most rendering engines assume it to be on the top-left. OpenGL assumes it to + be at the bottom left. + + This function is intended to be used when generating geometry for rendering the TextureTarget + onto another surface. It is also intended to be used when trying to use a custom texture (RTT) + inside CEGUI using the Image class, in order to determine the Image coordinates correctly. + + \return + - true if flipping is required: the texture coordinate origin is at the bottom left + - false if flipping is not required: the texture coordinate origin is at the top left + */ + bool isTexCoordSystemFlipped() const { return false; } // implement Renderer interface RenderTarget& getDefaultRenderTarget(); diff --git a/cegui/include/CEGUI/RendererModules/Null/Renderer.h b/cegui/include/CEGUI/RendererModules/Null/Renderer.h index 212209881..9b26c5e99 100644 --- a/cegui/include/CEGUI/RendererModules/Null/Renderer.h +++ b/cegui/include/CEGUI/RendererModules/Null/Renderer.h @@ -104,6 +104,23 @@ class NULL_GUIRENDERER_API NullRenderer : public Renderer //! destory an NullRenderer object. static void destroy(NullRenderer& renderer); + + /*! + \brief + Returns if the texture coordinate system is vertically flipped or not. The original of a + texture coordinate system is typically located either at the the top-left or the bottom-left. + CEGUI, Direct3D and most rendering engines assume it to be on the top-left. OpenGL assumes it to + be at the bottom left. + + This function is intended to be used when generating geometry for rendering the TextureTarget + onto another surface. It is also intended to be used when trying to use a custom texture (RTT) + inside CEGUI using the Image class, in order to determine the Image coordinates correctly. + + \return + - true if flipping is required: the texture coordinate origin is at the bottom left + - false if flipping is not required: the texture coordinate origin is at the top left + */ + bool isTexCoordSystemFlipped() const { return false; } // implement CEGUI::Renderer interface RenderTarget& getDefaultRenderTarget(); diff --git a/cegui/include/CEGUI/RendererModules/Ogre/GeometryBuffer.h b/cegui/include/CEGUI/RendererModules/Ogre/GeometryBuffer.h index e867ab759..c1b1b14a0 100644 --- a/cegui/include/CEGUI/RendererModules/Ogre/GeometryBuffer.h +++ b/cegui/include/CEGUI/RendererModules/Ogre/GeometryBuffer.h @@ -40,6 +40,10 @@ #include #include +#ifdef CEGUI_USE_OGRE_HLMS +#include +#endif + // Ogre forward refs namespace Ogre { @@ -129,10 +133,17 @@ class OGRE_GUIRENDERER_API OgreGeometryBuffer : public GeometryBuffer mutable Ogre::Matrix4 d_matrix; //! true when d_matrix is valid and up to date mutable bool d_matrixValid; +#ifdef CEGUI_USE_OGRE_HLMS + //! Render operation for this buffer. + mutable Ogre::v1::RenderOperation d_renderOp; + //! H/W buffer where the vertices are rendered from. + mutable Ogre::v1::HardwareVertexBufferSharedPtr d_hwBuffer; +#else //! Render operation for this buffer. mutable Ogre::RenderOperation d_renderOp; //! H/W buffer where the vertices are rendered from. mutable Ogre::HardwareVertexBufferSharedPtr d_hwBuffer; +#endif //! whether the h/w buffer is in sync with the added geometry mutable bool d_sync; //! type of container that tracks BatchInfos. diff --git a/cegui/include/CEGUI/RendererModules/Ogre/RenderTarget.h b/cegui/include/CEGUI/RendererModules/Ogre/RenderTarget.h index e4d567095..07b6fca49 100644 --- a/cegui/include/CEGUI/RendererModules/Ogre/RenderTarget.h +++ b/cegui/include/CEGUI/RendererModules/Ogre/RenderTarget.h @@ -46,6 +46,7 @@ class OGRE_GUIRENDERER_API OgreRenderTarget : public T //! Destructor virtual ~OgreRenderTarget(); +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) /*! \brief Set the underlying viewport area directly - bypassing what the @@ -60,6 +61,7 @@ class OGRE_GUIRENDERER_API OgreRenderTarget : public T in future releases. */ void setOgreViewportDimensions(const Rectf& area); +#endif // implement parts of CEGUI::RenderTarget interface void draw(const GeometryBuffer& buffer); @@ -76,8 +78,10 @@ class OGRE_GUIRENDERER_API OgreRenderTarget : public T void updateMatrix() const; //! helper that initialises the viewport void updateViewport(); +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) //! helper to update the actual Ogre viewport dimensions void updateOgreViewportDimensions(const Ogre::RenderTarget* const rt); +#endif //! OgreRenderer object that owns this RenderTarget OgreRenderer& d_owner; @@ -87,8 +91,16 @@ class OGRE_GUIRENDERER_API OgreRenderTarget : public T Rectf d_area; //! Ogre render target that we are effectively wrapping Ogre::RenderTarget* d_renderTarget; +#ifdef CEGUI_USE_OGRE_COMPOSITOR2 + + //! Set when the workspace needs to switch render targets + bool d_renderTargetUpdated; + +#else //! Ogre viewport used for this target. Ogre::Viewport* d_viewport; +#endif // CEGUI_USE_OGRE_COMPOSITOR2 + //! projection / view matrix cache mutable Ogre::Matrix4 d_matrix; //! true when d_matrix is valid and up to date @@ -96,9 +108,13 @@ class OGRE_GUIRENDERER_API OgreRenderTarget : public T //! tracks viewing distance (this is set up at the same time as d_matrix) mutable float d_viewDistance; //! true when d_viewport is up to date and valid. + //! \version Beginning from Ogre 2.0 this indicates whether the workspace is + //! up to date bool d_viewportValid; +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) //! holds set Ogre viewport dimensions Rectf d_ogreViewportDimensions; +#endif }; } // End of CEGUI namespace section diff --git a/cegui/include/CEGUI/RendererModules/Ogre/Renderer.h b/cegui/include/CEGUI/RendererModules/Ogre/Renderer.h index ae5e2664f..094962af7 100644 --- a/cegui/include/CEGUI/RendererModules/Ogre/Renderer.h +++ b/cegui/include/CEGUI/RendererModules/Ogre/Renderer.h @@ -64,6 +64,19 @@ typedef SharedPtr TexturePtr; class Matrix4; } +#if (CEGUI_OGRE_VERSION >= (2 << 16)) +// The new Ogre Compositor2 system has to be used since ViewPorts +// no longer have the required functionality +#define CEGUI_USE_OGRE_COMPOSITOR2 +#endif + +#if (CEGUI_OGRE_VERSION >= ((2 << 16) | (1 << 8) | 0)) +// The HLMS has to be used since fixed pipeline is disabled +#define CEGUI_USE_OGRE_HLMS +#include +#include +#endif + // Start of CEGUI namespace section namespace CEGUI { @@ -78,6 +91,7 @@ struct OgreRenderer_impl; class OGRE_GUIRENDERER_API OgreRenderer : public Renderer { public: +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) /*! \brief Convenience function that creates all the Ogre specific objects and @@ -104,7 +118,7 @@ class OGRE_GUIRENDERER_API OgreRenderer : public Renderer use the overload that takes an Ogre::RenderTarget as input. */ static OgreRenderer& bootstrapSystem(const int abi = CEGUI_VERSION_ABI); - +#endif /*! \brief Convenience function that creates all the Ogre specific objects and @@ -150,6 +164,7 @@ class OGRE_GUIRENDERER_API OgreRenderer : public Renderer */ static void destroySystem(); +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) /*! \brief Create an OgreRenderer object that uses the default Ogre rendering @@ -161,6 +176,7 @@ class OGRE_GUIRENDERER_API OgreRenderer : public Renderer use the overload that takes an Ogre::RenderTarget as input. */ static OgreRenderer& create(const int abi = CEGUI_VERSION_ABI); +#endif /*! \brief @@ -349,6 +365,28 @@ class OGRE_GUIRENDERER_API OgreRenderer : public Renderer to be flipped (i.e it does the right thing for both D3D and OpenGL). */ const Ogre::Matrix4& getWorldViewProjMatrix() const; + + /*! + \brief + Returns if the texture coordinate system is vertically flipped or not. The original of a + texture coordinate system is typically located either at the the top-left or the bottom-left. + CEGUI, Direct3D and most rendering engines assume it to be on the top-left. OpenGL assumes it to + be at the bottom left. + + This function is intended to be used when generating geometry for rendering the TextureTarget + onto another surface. It is also intended to be used when trying to use a custom texture (RTT) + inside CEGUI using the Image class, in order to determine the Image coordinates correctly. + + \return + - true if flipping is required: the texture coordinate origin is at the bottom left + - false if flipping is not required: the texture coordinate origin is at the top left + */ + bool isTexCoordSystemFlipped() const { return false; } + +#ifdef CEGUI_USE_OGRE_HLMS + Ogre::RenderTarget* getOgreRenderTarget(); + const Ogre::HlmsSamplerblock* getHlmsSamplerblock(); +#endif // implement CEGUI::Renderer interface RenderTarget& getDefaultRenderTarget(); diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/GL.h b/cegui/include/CEGUI/RendererModules/OpenGL/GL.h index 3a952f0de..831b24078 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/GL.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/GL.h @@ -27,16 +27,194 @@ #ifndef _CEGUIOpenGL_h_ #define _CEGUIOpenGL_h_ +#include "CEGUI/Config.h" + +#if defined CEGUI_USE_EPOXY + +#include + +#elif defined CEGUI_USE_GLEW + +#include + +// When using GLEW, there's no need to "#include" the OpenGL headers. #ifndef __APPLE__ # if (defined( __WIN32__ ) || defined( _WIN32 )) # include # endif -# include # include #else -# include # include #endif +#else +#error Either "CEGUI_USE_EPOXY" or "CEGUI_USE_GLEW" must be defined. Defining both or none is invalid. +#endif + +#ifndef GL_RGB565 +#define GL_RGB565 0x8D62 +#endif + +#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC) +# if defined(CEGUIOPENGLRENDERER_EXPORTS) || defined(CEGUIOPENGLES2RENDERER_EXPORTS) +# define OPENGL_GUIRENDERER_API __declspec(dllexport) +# else +# define OPENGL_GUIRENDERER_API __declspec(dllimport) +# endif +#else +# define OPENGL_GUIRENDERER_API +#endif + +namespace CEGUI { + +/*! +\brief + Provides information about the type of OpenGL used by an OpenGL context + (desktop OpenGL or OpenGL ES), the OpenGL version, and the OpenGL + extensions. +*/ +class OPENGL_GUIRENDERER_API OpenGLInfo +{ + +public: + /*! + \brief + Type of the OpenGL (desktop or ES) context + */ + enum Type + { + TYPE_NONE, /*!< Not initalized yet */ + TYPE_DESKTOP, /*!< Desktop OpenGL */ + TYPE_ES /*!< OpenGL ES */ + }; + + static OpenGLInfo& getSingleton() { return s_instance; } + + /*! + \brief + Must be called before any other method. + + Note that the information returned by other methods is with respect to + the OpenGL (desktop or ES) context that was current when this method was called. + */ + void init(); + + /*! + \brief + Type of the OpenGL (desktop or ES) context + */ + Type type() const { return d_type; } + + /*! + \brief + Returns true if using Desktop OpenGL. + */ + bool isUsingDesktopOpengl() const { return type() == TYPE_DESKTOP; } + + /*! + \brief + Returns true if using OpenGL ES. + */ + bool isUsingOpenglEs() const { return type() == TYPE_ES; } + + /*! + \brief + Returns OpenGL (desktop or ES) major version. Only supports Epoxy! + Otherwise returns -1; + */ + GLint verMajor() const { return d_verMajor; } + + /*! + \brief + Returns OpenGL (desktop or ES) minor version. Only supports Epoxy! + Otherwise returns -1; + */ + GLint verMinor() const { return d_verMinor; } + + /*! + \brief + Returns true if the OpenGL (desktop or ES) version is at least "major.minor". + Only supports Epoxy! Otherwise returns false. + */ + bool verAtLeast(GLint major, GLint minor) { + return verMajor() > major || (verMajor() == major && verMinor() >= minor); } + + /*! + \brief + Returns true if "S3TC" texture compression is supported. + + Note: Works only with Epoxy OR with desktop OpenGL >= 3.0. Otherwise + returns false. + */ + bool isS3tcSupported() const { return d_isS3tcSupported; } + + /*! + \brief + Returns true if NPOT (non-power-of-two) textures are supported. + */ + bool isNpotTextureSupported() const { return d_isNpotTextureSupported; } + + /*! + \brief + Returns true if "glReadBuffer" is supported. + */ + bool isReadBufferSupported() const + { return d_isReadBufferSupported; } + + /*! + \brief + Returns true if "glPolygonMode" is supported. + */ + bool isPolygonModeSupported() const + { return d_isPolygonModeSupported; } + + /*! + \brief + Returns true if VAO-s (Vertex Array Objects) are supported. + */ + bool isVaoSupported() const { return d_isVaoSupported; } + + /*! + \brief + Returns true if working with the read/draw framebuffers seperately is + supported. + */ + bool isSeperateReadAndDrawFramebufferSupported() const + { return d_isSeperateReadAndDrawFramebufferSupported; } + + bool isSizedInternalFormatSupported() const + { return d_isSizedInternalFormatSupported; } + + /* For internal use. Used to force the object to act is if we're using a + context of the specificed "verMajor_.verMinor_". This is useful to + check that an OpenGL (desktop/ES) version lower than the actual one + works correctly. Of course, this should work only if the actual + version is compatible with the forced version. For example this can be + used to check OpenGL ES 2.0 when the context is actually OpenGL ES 3.0 + (which is compatible with OpenGL ES 2.0). */ + void verForce(GLint verMajor_, GLint verMinor_); + +private: + + static OpenGLInfo s_instance; + OpenGLInfo(); + void initTypeAndVer(); + void initSupportedFeatures(); + + Type d_type; + GLint d_verMajor; + GLint d_verMinor; + GLint d_verMajorForce; + GLint d_verMinorForce; + bool d_isS3tcSupported; + bool d_isNpotTextureSupported; + bool d_isReadBufferSupported; + bool d_isPolygonModeSupported; + bool d_isSeperateReadAndDrawFramebufferSupported; + bool d_isVaoSupported; + bool d_isSizedInternalFormatSupported; +}; + +} // namespace CEGUI #endif // end of guard _CEGUIOpenGL_h_ diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/GL3GeometryBuffer.h b/cegui/include/CEGUI/RendererModules/OpenGL/GL3GeometryBuffer.h index 120f5273e..d03cf2ed4 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/GL3GeometryBuffer.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/GL3GeometryBuffer.h @@ -44,6 +44,8 @@ class OPENGL_GUIRENDERER_API OpenGL3GeometryBuffer : public OpenGLGeometryBuffer virtual ~OpenGL3GeometryBuffer(); void initialiseOpenGLBuffers(); + //! The functions first binds the vbo and then sets it up for rendering. + void configureVertexArray() const; void deinitialiseOpenGLBuffers(); void updateOpenGLBuffers(); diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/GL3Renderer.h b/cegui/include/CEGUI/RendererModules/OpenGL/GL3Renderer.h index d6eac407f..4fb99c2f8 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/GL3Renderer.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/GL3Renderer.h @@ -37,7 +37,19 @@ namespace CEGUI /*! \brief - Renderer class to interface with OpenGL + Renderer class to interface with desktop OpenGL version >= 3.2 or OpenGL ES + version >= 2. + + Note: to use this renderer with OpenGL ES 2.0, the Epoxy OpenGL loading + library (https://github.com/yaronct/libepoxy, major version 1) + must first be installed, and CEGUI must be configured with + "-DCEGUI_BUILD_RENDERER_OPENGL=OFF -DCEGUI_BUILD_RENDERER_OPENGL3=ON + -DCEGUI_USE_EPOXY=ON -DCEGUI_USE_GLEW=OFF". + + Note: Your OpenGL context must already be initialised when you call this; + CEGUI will not create the OpenGL context itself. Nothing special has to be + done to choose between desktop OpenGL and OpenGL ES: the type is + automatically determined by the type of the current OpenGL context. */ class OPENGL_GUIRENDERER_API OpenGL3Renderer : public OpenGLRendererBase { @@ -216,6 +228,7 @@ class OPENGL_GUIRENDERER_API OpenGL3Renderer : public OpenGLRendererBase const bool force = false); private: + //! Overrides OpenGLGeometryBufferBase* createGeometryBuffer_impl(); TextureTarget* createTextureTarget_impl(); @@ -224,10 +237,6 @@ class OPENGL_GUIRENDERER_API OpenGL3Renderer : public OpenGLRendererBase /*! \brief Constructor for OpenGL Renderer objects - - \param tt_type - Specifies one of the TextureTargetType enumerated values indicating the - desired TextureTarget type to be used. */ OpenGL3Renderer(); @@ -237,22 +246,21 @@ class OPENGL_GUIRENDERER_API OpenGL3Renderer : public OpenGLRendererBase \param display_size Size object describing the initial display resolution. - - \param tt_type - Specifies one of the TextureTargetType enumerated values indicating the - desired TextureTarget type to be used. */ OpenGL3Renderer(const Sizef& display_size); + void init(); + void initialiseOpenGLShaders(); - void initialiseGLExtensions(); +protected: /*! \brief Destructor for OpenGL3Renderer objects */ virtual ~OpenGL3Renderer(); +private: //! initialise OGL3TextureTargetFactory that will generate TextureTargets void initialiseTextureTargetFactory(); @@ -271,8 +279,9 @@ class OPENGL_GUIRENDERER_API OpenGL3Renderer : public OpenGLRendererBase GLint d_shaderStandardMatrixLoc; //! The wrapper we use for OpenGL calls, to detect redundant state changes and prevent them OpenGL3StateChangeWrapper* d_openGLStateChanger; + //! Wrapper for creating and handling shaders OpenGL3ShaderManager* d_shaderManager; - //! whether S3TC texture compression is supported by the context + //! \deprecated This attribute and associated functionality has been moved/replaced to/by the OpenGLInfo class bool d_s3tcSupported; //! pointer to a helper that creates TextureTargets supported by the system. OGLTextureTargetFactory* d_textureTargetFactory; diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/GLRenderer.h b/cegui/include/CEGUI/RendererModules/OpenGL/GLRenderer.h index cbc7d6f21..b745543bd 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/GLRenderer.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/GLRenderer.h @@ -34,7 +34,7 @@ namespace CEGUI { /*! \brief - Renderer class to interface with OpenGL + Renderer class to interface with desktop OpenGL */ class OPENGL_GUIRENDERER_API OpenGLRenderer : public OpenGLRendererBase { @@ -176,10 +176,10 @@ class OPENGL_GUIRENDERER_API OpenGLRenderer : public OpenGLRendererBase void setViewProjectionMatrix(const mat4Pimpl* viewProjectionMatrix); protected: + //! Overrides OpenGLGeometryBufferBase* createGeometryBuffer_impl(); TextureTarget* createTextureTarget_impl(); - //! set up renderer id string. void initialiseRendererIDString(); /*! diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/RendererBase.h b/cegui/include/CEGUI/RendererModules/OpenGL/RendererBase.h index e82d783a6..31add6013 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/RendererBase.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/RendererBase.h @@ -38,16 +38,6 @@ #include #include -#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC) -# ifdef CEGUIOPENGLRENDERER_EXPORTS -# define OPENGL_GUIRENDERER_API __declspec(dllexport) -# else -# define OPENGL_GUIRENDERER_API __declspec(dllimport) -# endif -#else -# define OPENGL_GUIRENDERER_API -#endif - #if defined(_MSC_VER) # pragma warning(push) # pragma warning(disable : 4251) @@ -59,7 +49,7 @@ class OpenGLTexture; class OpenGLGeometryBufferBase; struct mat4Pimpl; -//! Common base class used for other OpenGL based renderer modules. +//! Common base class used for other OpenGL (desktop or ES) based renderer modules. class OPENGL_GUIRENDERER_API OpenGLRendererBase : public Renderer { public: @@ -164,7 +154,7 @@ class OPENGL_GUIRENDERER_API OpenGLRendererBase : public Renderer virtual void setupRenderingBlendMode(const BlendMode mode, const bool force = false) = 0; - //! Return whether EXT_texture_compression_s3tc is supported + //! \deprecated - the OpenGL Info class should be used in the future for this purpose virtual bool isS3TCSupported() const = 0; /*! @@ -212,6 +202,23 @@ class OPENGL_GUIRENDERER_API OpenGLRendererBase : public Renderer */ RenderTarget* getActiveRenderTarget(); + /*! + \brief + Returns if the texture coordinate system is vertically flipped or not. The original of a + texture coordinate system is typically located either at the the top-left or the bottom-left. + CEGUI, Direct3D and most rendering engines assume it to be on the top-left. OpenGL assumes it to + be at the bottom left. + + This function is intended to be used when generating geometry for rendering the TextureTarget + onto another surface. It is also intended to be used when trying to use a custom texture (RTT) + inside CEGUI using the Image class, in order to determine the Image coordinates correctly. + + \return + - true if flipping is required: the texture coordinate origin is at the bottom left + - false if flipping is not required: the texture coordinate origin is at the top left + */ + bool isTexCoordSystemFlipped() const { return true; } + protected: OpenGLRendererBase(); @@ -223,6 +230,21 @@ class OPENGL_GUIRENDERER_API OpenGLRendererBase : public Renderer Size object describing the initial display resolution. */ OpenGLRendererBase(const Sizef& display_size); + + OpenGLRendererBase(bool set_glew_experimental); + + /*! + \brief + Constructor. + + \param display_size + Size object describing the initial display resolution. + \param set_glew_experimental + If true, set "glewExperimental = GL_TRUE" before calling "glewInit". + */ + OpenGLRendererBase(const Sizef& display_size, bool set_glew_experimental); + + void init (bool init_glew=false, bool set_glew_experimental=false); //! Destructor! virtual ~OpenGLRendererBase(); diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/Shader.h b/cegui/include/CEGUI/RendererModules/OpenGL/Shader.h index 91904bc9b..82c54cba9 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/Shader.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/Shader.h @@ -39,6 +39,7 @@ author: Lukas E Meindl // Start of CEGUI namespace section namespace CEGUI { + class OPENGL_GUIRENDERER_API OpenGL3Shader : public AllocatedObject { diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/StandardShaderFrag.h b/cegui/include/CEGUI/RendererModules/OpenGL/StandardShaderFrag.h index e1c9df11f..8192f3142 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/StandardShaderFrag.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/StandardShaderFrag.h @@ -30,20 +30,46 @@ namespace CEGUI { -const char StandardShaderFrag[] = - "#version 150 core\n" - "uniform sampler2D texture0;\n" +const char + StandardShaderFrag_Opengl3[] = + "#version 150 core\n" + + "uniform sampler2D texture0;\n" + "in vec2 exTexCoord;\n" + "in vec4 exColour;\n" + "out vec4 out0;\n" + + "void main(void)\n" + "{\n" + "out0 = texture(texture0, exTexCoord) * exColour;\n" + "}", + StandardShaderFrag_OpenglEs2[] = + "#version 100\n" - "in vec2 exTexCoord;\n" - "in vec4 exColour;\n" + "uniform sampler2D texture0;\n" + "precision mediump float;\n" + "varying vec2 exTexCoord;\n" + "varying vec4 exColour;\n" - "out vec4 out0;\n" + "void main(void)\n" + "{\n" + "gl_FragColor = texture2D(texture0, exTexCoord) * exColour;\n" + "}", + StandardShaderFrag_OpenglEs3[] = + "#version 300 es\n" - "void main(void)\n" - "{\n" - "out0 = texture(texture0, exTexCoord) * exColour;\n" - "}" - ; + "uniform sampler2D texture0;\n" + "precision highp float;\n" + "in vec2 exTexCoord;\n" + "in vec4 exColour;\n" + "layout(location = 0) out vec4 out0;\n" + + "void main(void)\n" + "{\n" + "out0 = texture(texture0, exTexCoord) * exColour;\n" + "}"; + } -#endif \ No newline at end of file + +#endif diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/StandardShaderVert.h b/cegui/include/CEGUI/RendererModules/OpenGL/StandardShaderVert.h index 1916d0d4b..65881230b 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/StandardShaderVert.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/StandardShaderVert.h @@ -30,26 +30,56 @@ namespace CEGUI { - const char StandardShaderVert[] = - "#version 150 core\n" - "uniform mat4 modelViewPerspMatrix;\n" +const char + StandardShaderVert_Opengl3[] = + "#version 150 core\n" - "in vec3 inPosition;\n" - "in vec2 inTexCoord;\n" - "in vec4 inColour;\n" + "uniform mat4 modelViewPerspMatrix;\n" + "in vec3 inPosition;\n" + "in vec2 inTexCoord;\n" + "in vec4 inColour;\n" + "out vec2 exTexCoord;\n" + "out vec4 exColour;\n" - "out vec2 exTexCoord;\n" - "out vec4 exColour;\n" + "void main(void)\n" + "{\n" + "exTexCoord = inTexCoord;\n" + "exColour = inColour;\n" + "gl_Position = modelViewPerspMatrix * vec4(inPosition, 1.0);\n" + "}", + StandardShaderVert_OpenglEs2[] = + "#version 100\n" + "uniform mat4 modelViewPerspMatrix;\n" + "attribute vec3 inPosition;\n" + "attribute vec2 inTexCoord;\n" + "attribute vec4 inColour;\n" + "varying vec2 exTexCoord;\n" + "varying vec4 exColour;\n" - "void main(void)\n" - "{\n" - " exTexCoord = inTexCoord;\n" - " exColour = inColour;\n" + "void main(void)\n" + "{\n" + "exTexCoord = inTexCoord;\n" + "exColour = inColour;\n" + "gl_Position = modelViewPerspMatrix * vec4(inPosition, 1.0);\n" + "}", + StandardShaderVert_OpenglEs3[] = + "#version 300 es\n" + + "uniform mat4 modelViewPerspMatrix;\n" + "in vec3 inPosition;\n" + "in vec2 inTexCoord;\n" + "in vec4 inColour;\n" + "out vec2 exTexCoord;\n" + "out vec4 exColour;\n" + + "void main(void)\n" + "{\n" + "exTexCoord = inTexCoord;\n" + "exColour = inColour;\n" + "gl_Position = modelViewPerspMatrix * vec4(inPosition, 1.0);\n" + "}"; - "gl_Position = modelViewPerspMatrix * vec4(inPosition, 1.0);\n" - "}" - ; } -#endif \ No newline at end of file +#endif diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/StateChangeWrapper.h b/cegui/include/CEGUI/RendererModules/OpenGL/StateChangeWrapper.h index 72f55e37a..0227e32cd 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/StateChangeWrapper.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/StateChangeWrapper.h @@ -79,10 +79,10 @@ namespace CEGUI GLuint d_buffer; }; - public: - //! constructor. +public: + + OpenGL3StateChangeWrapper(); OpenGL3StateChangeWrapper(OpenGL3Renderer& owner); - //! destructor virtual ~OpenGL3StateChangeWrapper(); void reset(); diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/Texture.h b/cegui/include/CEGUI/RendererModules/OpenGL/Texture.h index 92ec8f4b2..3655e305a 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/Texture.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/Texture.h @@ -142,6 +142,8 @@ class OPENGL_GUIRENDERER_API OpenGLTexture : public Texture //! clean up the GL texture, or the grab buffer if it had been grabbed void cleanupOpenGLTexture(); + GLint internalFormat() const; + //! initialise the internal format flags for the given CEGUI::PixelFormat. void initInternalPixelFormatFields(const PixelFormat fmt); @@ -162,7 +164,7 @@ class OPENGL_GUIRENDERER_API OpenGLTexture : public Texture Sizef d_size; //! cached image data for restoring the texture. uint8* d_grabBuffer; - //! original pixel of size data loaded into texture + //! original size of pixel data loaded into texture Sizef d_dataSize; //! cached pixel to texel mapping scale values. Vector2f d_texelScaling; diff --git a/cegui/include/CEGUI/RendererModules/OpenGL/WGLPBTextureTarget.h b/cegui/include/CEGUI/RendererModules/OpenGL/WGLPBTextureTarget.h index e1f35d431..de6802721 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGL/WGLPBTextureTarget.h +++ b/cegui/include/CEGUI/RendererModules/OpenGL/WGLPBTextureTarget.h @@ -28,7 +28,7 @@ #define _CEGUIOpenGLWGLPBTextureTarget_h_ //#include -#include +#include "CEGUI/RendererModules/OpenGL/GL.h" #include #include "CEGUI/RendererModules/OpenGL/TextureTarget.h" diff --git a/cegui/include/CEGUI/RendererModules/OpenGLES/Renderer.h b/cegui/include/CEGUI/RendererModules/OpenGLES/Renderer.h index 7cb074f33..a15962c5b 100644 --- a/cegui/include/CEGUI/RendererModules/OpenGLES/Renderer.h +++ b/cegui/include/CEGUI/RendererModules/OpenGLES/Renderer.h @@ -295,6 +295,23 @@ class OPENGLES_GUIRENDERER_API OpenGLESRenderer : public Renderer next power of two up from \a f if it's not. */ static float getNextPOTSize(const float f); + + /*! + \brief + Returns if the texture coordinate system is vertically flipped or not. The original of a + texture coordinate system is typically located either at the the top-left or the bottom-left. + CEGUI, Direct3D and most rendering engines assume it to be on the top-left. OpenGL assumes it to + be at the bottom left. + + This function is intended to be used when generating geometry for rendering the TextureTarget + onto another surface. It is also intended to be used when trying to use a custom texture (RTT) + inside CEGUI using the Image class, in order to determine the Image coordinates correctly. + + \return + - true if flipping is required: the texture coordinate origin is at the bottom left + - false if flipping is not required: the texture coordinate origin is at the top left + */ + bool isTexCoordSystemFlipped() const { return true; } private: /*! diff --git a/cegui/include/CEGUI/Singleton.h b/cegui/include/CEGUI/Singleton.h index 2105d2ebc..bae406b82 100644 --- a/cegui/include/CEGUI/Singleton.h +++ b/cegui/include/CEGUI/Singleton.h @@ -80,7 +80,7 @@ template class CEGUIEXPORT Singleton { return ( ms_Singleton ); } private: - Singleton& operator=(const Singleton&) { return this; } + Singleton& operator=(const Singleton&) { return *this; } Singleton(const Singleton&) {} }; diff --git a/cegui/include/CEGUI/SubscriberSlot.h b/cegui/include/CEGUI/SubscriberSlot.h index 67b3b9970..744bb475e 100644 --- a/cegui/include/CEGUI/SubscriberSlot.h +++ b/cegui/include/CEGUI/SubscriberSlot.h @@ -64,6 +64,39 @@ class CEGUIEXPORT SubscriberSlot : */ SubscriberSlot(FreeFunctionSlot::SlotFunction* func); + /*! + \brief + Creates a SubscriberSlot that is bound to a free function. + + \note + The handler doesn't have to return bool. True is always returned. + */ + inline SubscriberSlot(FreeFunctionSlotVoid::SlotFunction* func): + d_functor_impl(CEGUI_NEW_AO FreeFunctionSlotVoid(func)) + {} + + /*! + \brief + Creates a SubscriberSlot that is bound to a free function. + + \note + The handler doesn't have to take EventArgs. EventArgs are ignored. + */ + inline SubscriberSlot(FreeFunctionSlotNoArgs::SlotFunction* func): + d_functor_impl(CEGUI_NEW_AO FreeFunctionSlotNoArgs(func)) + {} + + /*! + \brief + Creates a SubscriberSlot that is bound to a free function. + + \note + The handler doesn't have to take EventArgs or return bool. + */ + inline SubscriberSlot(FreeFunctionSlotVoidNoArgs::SlotFunction* func): + d_functor_impl(CEGUI_NEW_AO FreeFunctionSlotVoidNoArgs(func)) + {} + /*! \brief Destructor. Note this is non-virtual, which should be telling you not @@ -108,6 +141,33 @@ class CEGUIEXPORT SubscriberSlot : d_functor_impl(new MemberFunctionSlot(function, obj)) {} + /*! + \brief + Creates a SubscriberSlot that is bound to a member function. + */ + template + SubscriberSlot(void (T::*function)(const EventArgs&), T* obj) : + d_functor_impl(new MemberFunctionSlotVoid(function, obj)) + {} + + /*! + \brief + Creates a SubscriberSlot that is bound to a member function. + */ + template + SubscriberSlot(bool (T::*function)(), T* obj) : + d_functor_impl(new MemberFunctionSlotNoArgs(function, obj)) + {} + + /*! + \brief + Creates a SubscriberSlot that is bound to a member function. + */ + template + SubscriberSlot(void (T::*function)(), T* obj) : + d_functor_impl(new MemberFunctionSlotVoidNoArgs(function, obj)) + {} + /*! \brief Creates a SubscriberSlot that is bound to a functor object reference. diff --git a/cegui/include/CEGUI/TextureTarget.h b/cegui/include/CEGUI/TextureTarget.h index 3e400ffba..9c059b25d 100644 --- a/cegui/include/CEGUI/TextureTarget.h +++ b/cegui/include/CEGUI/TextureTarget.h @@ -88,6 +88,9 @@ class CEGUIEXPORT TextureTarget : public RenderTarget vertically in comparison with other regular textures. - false if the texture content has the same orientation as regular textures. + + \deprecated + This function is deprecated. */ virtual bool isRenderingInverted() const = 0; }; diff --git a/cegui/include/CEGUI/Vector.h b/cegui/include/CEGUI/Vector.h index 9d8580ea6..427e0ac9c 100644 --- a/cegui/include/CEGUI/Vector.h +++ b/cegui/include/CEGUI/Vector.h @@ -57,8 +57,10 @@ class Vector2: typedef T value_type; inline Vector2() + :d_x(T()) + ,d_y(T()) {} - + inline Vector2(const T x, const T y): d_x(x), d_y(y) diff --git a/cegui/include/CEGUI/Window.h b/cegui/include/CEGUI/Window.h index ecfbdc7d5..4241bbfe3 100644 --- a/cegui/include/CEGUI/Window.h +++ b/cegui/include/CEGUI/Window.h @@ -55,7 +55,7 @@ # pragma warning(disable : 4251) #endif -// Start of CEGUI namespace section + namespace CEGUI { @@ -150,6 +150,72 @@ class CEGUIEXPORT Window : public NamedElement { public: + /************************************************************************* + Property name constants + *************************************************************************/ + //! Name of property to access for the alpha value of the Window. + static const String AlphaPropertyName; + //! Name of property to access for the 'always on top' setting for the Window + static const String AlwaysOnTopPropertyName; + //! Name of property to access for the 'clipped by parent' setting for the Window + static const String ClippedByParentPropertyName; + //! Name of property to access for the 'destroyed by parent' setting for the Window + static const String DestroyedByParentPropertyName; + //! Name of property to access for the 'disabled state' setting for the Window + static const String DisabledPropertyName; + //! Name of property to access for the font for the Window. + static const String FontPropertyName; + //! Name of property to access for the ID value of the Window. + static const String IDPropertyName; + //! Name of property to access for the get/set the 'inherits alpha' setting for the Window. + static const String InheritsAlphaPropertyName; + //! Name of property to access for the the mouse cursor image for the Window. + static const String MouseCursorImagePropertyName; + //! Name of property to access for the the 'visible state' setting for the Window. + static const String VisiblePropertyName; + //! Name of property to access for the the 'active state' setting for the Window. + static const String ActivePropertyName; + //! Name of property to access for the 'restore old capture' setting for the Window. + static const String RestoreOldCapturePropertyName; + //! Name of property to access for the text / caption for the Window. + static const String TextPropertyName; + //! Name of property to access for the 'z-order changing enabled' setting for the Window. + static const String ZOrderingEnabledPropertyName; + //! Name of property to access for whether the window will receive double-click and triple-click events. + static const String WantsMultiClickEventsPropertyName; + //! Name of property to access for whether the window will receive autorepeat mouse button down events. + static const String MouseAutoRepeatEnabledPropertyName; + //! Name of property to access for the autorepeat delay. + static const String AutoRepeatDelayPropertyName; + //! Name of property to access for the autorepeat rate. + static const String AutoRepeatRatePropertyName; + //! Name of property to access for the whether captured inputs are passed to child windows. + static const String DistributeCapturedInputsPropertyName; + //! Name of property to access for the custom tooltip for the window. + static const String TooltipTypePropertyName; + //! Name of property to access for the tooltip text for the window. + static const String TooltipTextPropertyName; + //! Name of property to access for the window inherits its parents tooltip text when it has none of its own. + static const String InheritsTooltipTextPropertyName; + //! Name of property to access for the window will come to the top of the Z-order when clicked. + static const String RiseOnClickEnabledPropertyName; + //! Name of property to access for the window ignores mouse events and pass them through to any windows behind it. + static const String MousePassThroughEnabledPropertyName; + //! Name of property to access for the Window will receive drag and drop related notifications. + static const String DragDropTargetPropertyName; + //! Name of property to access for the Window will automatically attempt to use a full imagery caching RenderingSurface (if supported by the renderer). + static const String AutoRenderingSurfacePropertyName; + //! Name of property to access for the text parsing setting for the Window. + static const String TextParsingEnabledPropertyName; + //! Name of property to access for the margin for the Window. + static const String MarginPropertyName; + //! Name of property to access for the window update mode setting. + static const String UpdateModePropertyName; + //! Name of property to access whether unhandled mouse inputs should be propagated back to the Window's parent. + static const String MouseInputPropagationEnabledPropertyName; + //! Name of property to access whether the system considers this window to be an automatically created sub-component window. + static const String AutoWindowPropertyName; + /************************************************************************* Event name constants *************************************************************************/ @@ -798,13 +864,19 @@ class CEGUIEXPORT Window : \param useDefault Specifies whether to return the default font if this Window has no - preferred font set. + preferred font set. This is typically set to true but whenever we + want to know if a default font would be used, this will be set to + false, and if the returned Font is a zero pointer we know that this + means a default font would be used otherwise. \return Pointer to the Font being used by this Window. If the window has no assigned font, and \a useDefault is true, then the default system font is returned. */ + /*! \deprecated This function is deprecated, as the parameter will be removed in the next major version. Separate functions + will be added with proper function names to replicate the functionality for useDefault=false. + */ const Font* getFont(bool useDefault = true) const; /*! @@ -1192,6 +1264,18 @@ class CEGUIEXPORT Window : */ const String& getTooltipText(void) const; + /*! + \brief + Return the current tooltip text set for this Window or the inherited one. + If the tooltip text of this window is empty then the inherited value will + be used instead. + + \return + String object holding the current tooltip text of this window or the + tooltip text this window inherited. + */ + const String& getTooltipTextIncludingInheritance(void) const; + /*! \brief Return whether this window inherits Tooltip text from its parent when @@ -1522,6 +1606,26 @@ class CEGUIEXPORT Window : */ void hide(void) {setVisible(false);} + /*! + \brief + Set whether the Window is active or inactive. + + \param setting + - true to make the Window active. + - false to make the Window inactive (deactivate). + + \note + Activating the window will call to move the window to the front if the + window is not already active. The window must be already visible in + order to activate it otherwise it will have no effect. + When deactivating, all active children will also be deactivated. + + \return + Nothing + */ + + void setActive(bool setting); + /*! \brief Activate the Window giving it input focus and bringing it to the top of @@ -2540,21 +2644,60 @@ class CEGUIEXPORT Window : {return d_bidiVisualMapping;} /*! - \brief Add the named property to the XML ban list for this window. - - \param property_name Name of the property you want to ban + \brief + Adds the named property to the XML ban list for this window + Essentially a property that is banned from XML will never end up being saved to it. + This is very useful if 2 properties overlap (XPosition and Position for example). - Essentially a property that is banned from XML will never end up being saved to it. - This is very useful if 2 properties overlap (XPosition and Position for example). + Please note that properties that are not writable (read-only properties) are + implicitly/automatically banned from XML, no need to ban them manually. - Please note that properties that are not writable (read-only properties) are - implicitly/automatically banned from XML, no need to ban them manually. + \param property_name + Name of the property you want to ban */ void banPropertyFromXML(const String& property_name); - //! Remove the named property from the XML ban list for this window. + /*! + \brief + Adds the named property to the XML ban list for this window and all of its child windows. + Essentially a property that is banned from XML will never end up being saved to it. + This is very useful if 2 properties overlap (XPosition and Position for example). + + Please note that properties that are not writable (read-only properties) are + implicitly/automatically banned from XML, no need to ban them manually. + + \param property_name + Name of the property you want to ban + */ + void banPropertyFromXMLRecursive(const String& property_name); + + /*! + \brief + Removes the named property from the XML ban list for this window. + Essentially a property that is banned from XML will never end up being saved to it. + + Please note that properties that are not writable (read-only properties) are + implicitly/automatically banned from XML. + + \param property_name + Name of the property you want to unban + */ void unbanPropertyFromXML(const String& property_name); + /*! + \brief + Removes the named property from the XML ban list for this window and all of its child windows. + Essentially a property that is banned from XML will never end up being saved to it. + + Please note that properties that are not writable (read-only properties) are + implicitly/automatically banned from XML. + + \param property_name + Name of the property you want to unban + */ + void unbanPropertyFromXMLRecursive(const String& property_name); + + /*! \brief Return whether the named property is banned from XML diff --git a/cegui/include/CEGUI/WindowRendererSets/Core/Editbox.h b/cegui/include/CEGUI/WindowRendererSets/Core/Editbox.h index aaff04088..8bef17201 100644 --- a/cegui/include/CEGUI/WindowRendererSets/Core/Editbox.h +++ b/cegui/include/CEGUI/WindowRendererSets/Core/Editbox.h @@ -78,10 +78,14 @@ class COREWRSET_API FalagardEditbox : public EditboxWindowRenderer //! type name for this widget. static const String TypeName; - //! Name of property to access for unselected text colour. + //! Name of the optional property to access for the unselected text colour. static const String UnselectedTextColourPropertyName; - //! Name of property to access for selected text colour. + //! Name of the optional property to access for the selected text colour. static const String SelectedTextColourPropertyName; + //! Name of the optional property to access to obtain active selection rendering colour. + static const String ActiveSelectionColourPropertyName; + //! Name of the optional property to access to obtain inactive selection rendering colour. + static const String InactiveSelectionColourPropertyName; //! The default timeout (in seconds) used when blinking the caret. static const float DefaultCaretBlinkTimeout; @@ -156,7 +160,7 @@ class COREWRSET_API FalagardEditbox : public EditboxWindowRenderer void renderBaseImagery(const WidgetLookFeel& wlf) const; //! helper to set 'visual' to the string we will render (part of) void setupVisualString(String& visual) const; - size_t getCaretIndex(const String& visual_string) const; + size_t getCaretIndex(const String& visual_text) const; float calculateTextOffset(const Rectf& text_area, const float text_extent, const float caret_width, diff --git a/cegui/include/CEGUI/WindowRendererSets/Core/MultiLineEditbox.h b/cegui/include/CEGUI/WindowRendererSets/Core/MultiLineEditbox.h index d9518ae6b..e6ce9c217 100644 --- a/cegui/include/CEGUI/WindowRendererSets/Core/MultiLineEditbox.h +++ b/cegui/include/CEGUI/WindowRendererSets/Core/MultiLineEditbox.h @@ -74,13 +74,13 @@ class COREWRSET_API FalagardMultiLineEditbox : public MultiLineEditboxWindowRend public: static const String TypeName; //! type name for this widget. - //! Name of property to use to obtain unselected text rendering colour. + //! Name of the optional property to access for the unselected text colour. static const String UnselectedTextColourPropertyName; - //! Name of property to use to obtain selected text rendering colour. + //! Name of the optional property to access for the selected text colour. static const String SelectedTextColourPropertyName; - //! Name of property to use to obtain active selection rendering colour. + //! Name of the optional property to access to obtain active selection rendering colour. static const String ActiveSelectionColourPropertyName; - //! Name of property to use to obtain inactive selection rendering colour. + //! Name of the optional property to access to obtain inactive selection rendering colour. static const String InactiveSelectionColourPropertyName; //! The default timeout (in seconds) used when blinking the caret. static const float DefaultCaretBlinkTimeout; diff --git a/cegui/include/CEGUI/WindowRendererSets/Core/StaticText.h b/cegui/include/CEGUI/WindowRendererSets/Core/StaticText.h index c4555ee7c..b4a6ad23e 100644 --- a/cegui/include/CEGUI/WindowRendererSets/Core/StaticText.h +++ b/cegui/include/CEGUI/WindowRendererSets/Core/StaticText.h @@ -163,11 +163,119 @@ namespace CEGUI bool handleFontRenderSizeChange(const Font* const font); void render(void); + /*! + \brief + Get the current position of the horizontal scrollbar within the + text. + + The range of the scrollbar is from 0 to the width of the text minus + the width of a page + (0 <= position <= (textSize - pageSize)). + + \param position + Float value specifying the position of the scrollbar within the + text. + */ + float getHorizontalScrollPosition() const; + + /*! + \brief + Get the current position of the vertical scrollbar within the text. + + The range of the scrollbar is from 0 to the height of the text minus + the height of a page + (0 <= position <= (textSize - pageSize)). + + \param position + Float value specifying the position of the scrollbar within the + text. + */ + float getVerticalScrollPosition() const; + + /*! + \brief + return the current horizontal scrollbar position as a value in the + interval [0, 1]. + */ + float getUnitIntervalHorizontalScrollPosition() const; + + /*! + \brief + return the current vertical scrollbar position as a value in the + interval [0, 1]. + */ + float getUnitIntervalVerticalScrollPosition() const; + + /*! + \brief + Set the current position of the horizontal scrollbar within the + text. + + The range of the scrollbar is from 0 to the width of the text minus + the width of a page + (0 <= position <= (textSize - pageSize)), any attempt to set the + position outside this range will be adjusted so that it falls within + the legal range. + + \param position + Float value specifying the position of the scrollbar within the + text. + */ + void setHorizontalScrollPosition(float position); + + /*! + \brief + Set the current position of the vertical scrollbar within the text. + + The range of the scrollbar is from 0 to the height of the text minus + the height of a page + (0 <= position <= (textSize - pageSize)), any attempt to set the + position outside this range will be adjusted so that it falls within + the legal range. + + \param position + Float value specifying the position of the scrollbar within the + text. + */ + void setVerticalScrollPosition(float position); + + /*! + \brief + set the current horizontal scrollbar position as a value in the + interval [0, 1]. + */ + void setUnitIntervalHorizontalScrollPosition(float position); + + /*! + \brief + set the current vertical scrollbar position as a value in the + interval [0, 1]. + */ + void setUnitIntervalVerticalScrollPosition(float position); + + /*! + \brief + Invalidate string formatting and scrollbars visibility. + + This sets a "dirty" flag which causes "updateFormatting" to actually + perform an update. + \see updateFormatting + */ + void invalidateFormatting(); + protected: - //! update string formatting (gets area size to use from looknfeel) + /*! + \brief + Update string formatting and scrollbars visibility. + + This only happens if a "dirty" flag is set. The flag is set by + "invalidateFormatting". + \see invalidateFormatting + */ void updateFormatting() const; - //! update string formatting using given area size. - void updateFormatting(const Sizef& sz) const; + + //! \deprecated + void updateFormatting(const Sizef&) const; // overridden from FalagardStatic base class void onLookNFeelAssigned(); @@ -175,11 +283,20 @@ namespace CEGUI // text field with scrollbars methods void renderScrolledText(void); + + void configureScrollbars() const; + + //! \deprecated void configureScrollbars(void); - Scrollbar* getVertScrollbar(void) const; - Scrollbar* getHorzScrollbar(void) const; - Rectf getTextRenderArea(void) const; + + Scrollbar* getVertScrollbar() const; + Scrollbar* getHorzScrollbar() const; + Rectf getTextRenderArea() const; + Sizef getDocumentSize() const; + + //! \deprecated Sizef getDocumentSize(const Rectf& renderArea) const; + void setupStringFormatter() const; // overridden event handlers @@ -206,8 +323,18 @@ namespace CEGUI typedef std::vector ConnectionList; ConnectionList d_connections; - //! true when string formatting is up to date. + /*! + \brief + True when string formatting and scrollbars visibility are up to + date. + */ mutable bool d_formatValid; + + private: + Scrollbar* getVertScrollbarWithoutUpdate() const; + Scrollbar* getHorzScrollbarWithoutUpdate() const; + Rectf getTextRenderAreaWithoutUpdate() const; + Sizef getDocumentSizeWithoutUpdate() const; }; } // End of CEGUI namespace section diff --git a/cegui/include/CEGUI/falagard/FormattingSetting.h b/cegui/include/CEGUI/falagard/FormattingSetting.h index f53f974fb..55d028dda 100644 --- a/cegui/include/CEGUI/falagard/FormattingSetting.h +++ b/cegui/include/CEGUI/falagard/FormattingSetting.h @@ -103,13 +103,13 @@ class FormattingSetting } //------------------------------------------------------------------------// - virtual void writeXMLTagToStream(XMLSerializer& xml_stream) const + virtual void writeXMLTagToStream(XMLSerializer& /*xml_stream*/) const { // This does nothing and needs to be specialised or overridden } //------------------------------------------------------------------------// - virtual void writeXMLAttributesToStream(XMLSerializer& xml_stream) const + virtual void writeXMLAttributesToStream(XMLSerializer& /*xml_stream*/) const { // This does nothing and needs to be specialised or overridden } diff --git a/cegui/include/CEGUI/falagard/PropertyLinkDefinition.h b/cegui/include/CEGUI/falagard/PropertyLinkDefinition.h index 466056ae4..45871bb20 100644 --- a/cegui/include/CEGUI/falagard/PropertyLinkDefinition.h +++ b/cegui/include/CEGUI/falagard/PropertyLinkDefinition.h @@ -157,8 +157,12 @@ class PropertyLinkDefinition : public FalagardPropertyBase // only try to set property if target is currently valid. if (target_wnd) - target_wnd->setProperty(i->second.empty() ? - TypedProperty::d_name : i->second, Helper::toString(value)); + { + const CEGUI::String& propertyName = i->second.empty() ? TypedProperty::d_name : i->second; + CEGUI::String propertyValue = Helper::toString(value); + target_wnd->setProperty(propertyName, propertyValue); + target_wnd->banPropertyFromXML(propertyName); + } } } diff --git a/cegui/include/CEGUI/falagard/TextComponent.h b/cegui/include/CEGUI/falagard/TextComponent.h index 5d62217cb..25f6217aa 100644 --- a/cegui/include/CEGUI/falagard/TextComponent.h +++ b/cegui/include/CEGUI/falagard/TextComponent.h @@ -332,6 +332,19 @@ namespace CEGUI // overridden from ComponentBase. bool handleFontRenderSizeChange(Window& window, const Font* font) const; + + //! Update string formatting. + void updateFormatting(const Window& srcWindow) const; + + /*! + \brief + Update string formatting. + + \param size + The pixel size of the component. + */ + void updateFormatting(const Window& srcWindow, const Sizef& size) const; + protected: // implemets abstract from base void render_impl(Window& srcWindow, Rectf& destRect, const CEGUI::ColourRect* modColours, const Rectf* clipper, bool clipToDisplay) const; diff --git a/cegui/include/CEGUI/widgets/Listbox.h b/cegui/include/CEGUI/widgets/Listbox.h index bf8aad1c2..b763f26ef 100644 --- a/cegui/include/CEGUI/widgets/Listbox.h +++ b/cegui/include/CEGUI/widgets/Listbox.h @@ -96,7 +96,7 @@ class CEGUIEXPORT Listbox : public Window /** Event fired when there is a change to the currently selected item(s) * within the list. * Handlers are passed a const WindowEventArgs reference with - * WindowEventArgs::window set to the Litbox that has had a change in the + * WindowEventArgs::window set to the Listbox that has had a change in the * selected items. */ static const String EventSelectionChanged; diff --git a/cegui/include/CEGUI/widgets/ScrollablePane.h b/cegui/include/CEGUI/widgets/ScrollablePane.h index 78e249f6a..5d9a88028 100644 --- a/cegui/include/CEGUI/widgets/ScrollablePane.h +++ b/cegui/include/CEGUI/widgets/ScrollablePane.h @@ -3,7 +3,7 @@ author: Paul D Turner *************************************************************************/ /*************************************************************************** - * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team + * Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -63,6 +63,13 @@ class CEGUIEXPORT ScrollablePaneWindowRenderer : public WindowRenderer The ScrollablePane widget allows child windows to be attached which cover an area larger than the ScrollablePane itself and these child windows can be scrolled into view using the scrollbars of the scrollable pane. + + Note: If the content pane is set to be auto-sized, and not both (horizontal + and vertical) scrollbars are set to be always visible, and any of the + children's size is not set to be an absolute dimension (i.e. its relative + component is non-zero), this creates a circular dependency which may lead to + a crash. Please don't use such a combination. It'll probably not be allowed + in future versions of CEGUI. */ class CEGUIEXPORT ScrollablePane : public Window { @@ -113,6 +120,8 @@ class CEGUIEXPORT ScrollablePane : public Window //! Destructor for the ScrollablePane base class. ~ScrollablePane(void); + virtual int writeChildWindowsXML(XMLSerializer& xml_stream) const; + /*! \brief Returns a pointer to the window holding the pane contents. @@ -141,6 +150,13 @@ class CEGUIEXPORT ScrollablePane : public Window \brief Set whether the vertical scroll bar should always be shown. + Note: If the content pane is set to be auto-sized, and not both + (horizontal and vertical) scrollbars are set to be always visible, and + any of the children's size is not set to be an absolute dimension (i.e. + its relative component is non-zero), this creates a circular dependency + which may lead to a crash. Please don't use such a combination. It'll + probably not be allowed in future versions of CEGUI. + \param setting - true if the vertical scroll bar should be shown even when it is not required. @@ -166,6 +182,13 @@ class CEGUIEXPORT ScrollablePane : public Window \brief Set whether the horizontal scroll bar should always be shown. + Note: If the content pane is set to be auto-sized, and not both + (horizontal and vertical) scrollbars are set to be always visible, and + any of the children's size is not set to be an absolute dimension (i.e. + its relative component is non-zero), this creates a circular dependency + which may lead to a crash. Please don't use such a combination. It'll + probably not be allowed in future versions of CEGUI. + \param setting - true if the horizontal scroll bar should be shown even when it is not required. @@ -192,6 +215,13 @@ class CEGUIEXPORT ScrollablePane : public Window \brief Set whether the content pane should be auto-sized. + Note: If the content pane is set to be auto-sized, and not both + (horizontal and vertical) scrollbars are set to be always visible, and + any of the children's size is not set to be an absolute dimension (i.e. + its relative component is non-zero), this creates a circular dependency + which may lead to a crash. Please don't use such a combination. It'll + probably not be allowed in future versions of CEGUI. + \param setting - true to indicate the content pane should automatically resize itself. - false to indicate the content pane should not automatically resize diff --git a/cegui/include/CEGUI/widgets/Scrollbar.h b/cegui/include/CEGUI/widgets/Scrollbar.h index a3bb1e48d..32365b2f2 100644 --- a/cegui/include/CEGUI/widgets/Scrollbar.h +++ b/cegui/include/CEGUI/widgets/Scrollbar.h @@ -318,11 +318,6 @@ class CEGUIEXPORT Scrollbar : public Window attempt to set the position outside this range will be adjusted so that it falls within the legal range. - \note - The returned value has no meaning within the Gui system, it is left up - to the application to assign appropriate values for the application - specific use of the scroll bar. - \param position float value specifying the position of the scroll bar within its document. diff --git a/cegui/src/BasicRenderedStringParser.cpp b/cegui/src/BasicRenderedStringParser.cpp index 72d78e6e4..671de2726 100644 --- a/cegui/src/BasicRenderedStringParser.cpp +++ b/cegui/src/BasicRenderedStringParser.cpp @@ -94,8 +94,8 @@ BasicRenderedStringParser::~BasicRenderedStringParser() //----------------------------------------------------------------------------// RenderedString BasicRenderedStringParser::parse(const String& input_string, - const Font* initial_font, - const ColourRect* initial_colours) + const Font* active_font, + const ColourRect* active_colours) { // first-time initialisation (due to issues with static creation order) if (!d_initialised) @@ -103,13 +103,13 @@ RenderedString BasicRenderedStringParser::parse(const String& input_string, initialiseDefaultState(); - // maybe override initial font. - if (initial_font) - d_fontName = initial_font->getName(); + // Override active font if necessary + if (active_font) + d_fontName = active_font->getName(); - // maybe override initial colours. - if (initial_colours) - d_colours = *initial_colours; + // Override active font if necessary + if (active_colours) + d_colours = *active_colours; RenderedString rs; String curr_section, tag_string; @@ -219,16 +219,26 @@ void BasicRenderedStringParser::processControlString(RenderedString& rs, char var_buf[128]; char val_buf[128]; - sscanf(ctrl_str.c_str(), " %127[^ =] = '%127[^']", var_buf, val_buf); + int successfullyFilledItems = sscanf(ctrl_str.c_str(), " %127[^ =] = '%127[^']", var_buf, val_buf); const String var_str(var_buf); - const String val_str(val_buf); - // look up handler function TagHandlerMap::iterator i = d_tagHandlers.find(var_str); - // despatch handler, or log error - if (i != d_tagHandlers.end()) - (this->*(*i).second)(rs, val_str); + // dispatch handler, or log error + if (successfullyFilledItems >= 1 && i != d_tagHandlers.end()) + { + // If both variables were read correctly, proceed as usual + if(successfullyFilledItems == 2) + { + const String val_str(val_buf); + (this->*(*i).second)(rs, val_str); + } + // Otherwise, since the handler was found, we are sure that the + // second variable couldn't be read, meaning it was empty. We will supply + // and empty string + else + (this->*(*i).second)(rs, ""); + } else Logger::getSingleton().logEvent( "BasicRenderedStringParser::processControlString: unknown " @@ -239,7 +249,9 @@ void BasicRenderedStringParser::processControlString(RenderedString& rs, void BasicRenderedStringParser::initialiseDefaultState() { d_padding = Rectf(0, 0, 0, 0); + //! \deprecated This assignment is deprecated and will be replaced by assignment to "" in the next major version */ d_colours = d_initialColours; + //! \deprecated This assignment is deprecated and will be replaced by assignment Colour 0xFFFFFFFF in the next major version */ d_fontName = d_initialFontName; d_imageSize.d_width = d_imageSize.d_height = 0.0f; d_vertAlignment = VF_BOTTOM_ALIGNED; diff --git a/cegui/src/CMakeLists.txt b/cegui/src/CMakeLists.txt index d1bbfbc15..d313eab46 100644 --- a/cegui/src/CMakeLists.txt +++ b/cegui/src/CMakeLists.txt @@ -57,6 +57,9 @@ endif() # we do not use the common header install function since we need to install to # multiple sub-dirs. cegui_add_library_impl(${CEGUI_TARGET_NAME} FALSE CORE_SOURCE_FILES ALL_HEADER_FILES TRUE FALSE) +if (ANDROID) + target_link_libraries (${CEGUI_TARGET_NAME} log) +endif () source_group("Source Files\\widget" FILES ${WIDGET_SOURCE_FILES}) source_group("Source Files\\falagard" FILES ${FALAGARD_SOURCE_FILES}) @@ -64,24 +67,27 @@ source_group("Source Files\\falagard" FILES ${FALAGARD_SOURCE_FILES}) source_group("Header Files\\widget" FILES ${WIDGET_HEADER_FILES}) source_group("Header Files\\falagard" FILES ${FALAGARD_HEADER_FILES}) -if (NOT WIN32) - cegui_add_dependency(${CEGUI_TARGET_NAME} ICONV) +if (NOT WIN32 AND NOT ANDROID) + cegui_add_dependency(${CEGUI_TARGET_NAME} ICONV PRIVATE TRUE) endif() if (CEGUI_HAS_FREETYPE) - cegui_add_dependency(${CEGUI_TARGET_NAME} FREETYPE) + cegui_add_dependency(${CEGUI_TARGET_NAME} FREETYPE PRIVATE TRUE) endif () if (CEGUI_HAS_PCRE_REGEX) - cegui_add_dependency(${CEGUI_TARGET_NAME} PCRE) + cegui_add_dependency(${CEGUI_TARGET_NAME} PCRE PRIVATE TRUE) endif () if (CEGUI_USE_FRIBIDI) - cegui_add_dependency(${CEGUI_TARGET_NAME} FRIBIDI) + cegui_add_dependency(${CEGUI_TARGET_NAME} FRIBIDI PRIVATE TRUE) endif () if (CEGUI_HAS_MINIZIP_RESOURCE_PROVIDER) - cegui_add_dependency(${CEGUI_TARGET_NAME} MINIZIP) + cegui_add_dependency(${CEGUI_TARGET_NAME} MINIZIP PRIVATE TRUE) + if (MINGW) + target_link_libraries(${CEGUI_TARGET_NAME} shlwapi) + endif () endif () if (WIN32 AND NOT MINGW) @@ -97,7 +103,7 @@ if (APPLE AND CEGUI_BUILD_SHARED_LIBS_WITH_STATIC_DEPENDENCIES) set_property(TARGET ${CEGUI_TARGET_NAME} APPEND PROPERTY LINK_FLAGS "-framework Carbon") endif() -install(FILES ${CORE_HEADER_FILES} DESTINATION ${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI) -install(FILES ${WIDGET_HEADER_FILES} DESTINATION ${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI/widgets) -install(FILES ${FALAGARD_HEADER_FILES} DESTINATION ${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI/falagard) +install(FILES ${CORE_HEADER_FILES} DESTINATION ${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI COMPONENT cegui_devel) +install(FILES ${WIDGET_HEADER_FILES} DESTINATION ${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI/widgets COMPONENT cegui_devel) +install(FILES ${FALAGARD_HEADER_FILES} DESTINATION ${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI/falagard COMPONENT cegui_devel) diff --git a/cegui/src/Colour.cpp b/cegui/src/Colour.cpp index f59793332..fcbd63251 100644 --- a/cegui/src/Colour.cpp +++ b/cegui/src/Colour.cpp @@ -57,6 +57,7 @@ Colour::Colour(float red, float green, float blue, float alpha) : d_red(red), d_green(green), d_blue(blue), + d_argb(0x00000000), d_argbValid(false) { } diff --git a/cegui/src/CommonDialogs/CMakeLists.txt b/cegui/src/CommonDialogs/CMakeLists.txt index b1f98fdfa..571062680 100644 --- a/cegui/src/CommonDialogs/CMakeLists.txt +++ b/cegui/src/CommonDialogs/CMakeLists.txt @@ -13,6 +13,6 @@ set (CORE_HEADER_FILES ${MODULE_HEADER_FILES} ${COLOUR_PICKER_HEADER_FILES}) cegui_add_library_impl(${CEGUI_TARGET_NAME} FALSE CORE_SOURCE_FILES CORE_HEADER_FILES TRUE FALSE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) -install(FILES ${MODULE_HEADER_FILES} DESTINATION ${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI/CommonDialogs) -install(FILES ${COLOUR_PICKER_HEADER_FILES} DESTINATION ${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI/CommonDialogs/ColourPicker) +install(FILES ${MODULE_HEADER_FILES} DESTINATION ${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI/CommonDialogs COMPONENT cegui_devel) +install(FILES ${COLOUR_PICKER_HEADER_FILES} DESTINATION ${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI/CommonDialogs/ColourPicker COMPONENT cegui_devel) diff --git a/cegui/src/CommonDialogs/ColourPicker/ColourPicker.cpp b/cegui/src/CommonDialogs/ColourPicker/ColourPicker.cpp index e370a369e..6f1f63157 100644 --- a/cegui/src/CommonDialogs/ColourPicker/ColourPicker.cpp +++ b/cegui/src/CommonDialogs/ColourPicker/ColourPicker.cpp @@ -76,8 +76,6 @@ ColourPicker::~ColourPicker(void) if (iter != s_colourPickerWindows.end()) { - iter->second; - if (iter->second <= 0) WindowManager::getSingleton().destroyWindow(iter->first); } diff --git a/cegui/src/CommonDialogs/ColourPicker/Conversions.cpp b/cegui/src/CommonDialogs/ColourPicker/Conversions.cpp index 411cebf95..b6c507965 100644 --- a/cegui/src/CommonDialogs/ColourPicker/Conversions.cpp +++ b/cegui/src/CommonDialogs/ColourPicker/Conversions.cpp @@ -375,13 +375,17 @@ HSV_Colour ColourPickerConversions::toHSV(RGB_Colour colour) else { if (maxCompRed) + { h = (g - b) / diff + (g < b ? 6.0f : 0.0f); - - if (maxCompGreen) + } + else if (maxCompGreen) + { h = (b - r) / diff + 2.0f; - + } else + { h = (r - g) / diff + 4.0f; + } h /= 6.0f; } diff --git a/cegui/src/DynamicModule.cpp b/cegui/src/DynamicModule.cpp index 4b4a60294..0d6649c28 100644 --- a/cegui/src/DynamicModule.cpp +++ b/cegui/src/DynamicModule.cpp @@ -68,7 +68,7 @@ struct DynamicModule::Impl : ~Impl() { - DYNLIB_UNLOAD(d_handle); + CEGUI_UNUSED(DYNLIB_UNLOAD(d_handle)); } //! Holds the name of the loaded module. @@ -169,19 +169,21 @@ static DYNLIB_HANDLE DynLibLoad(const String& name) if (!envModuleDir.empty()) handle = DYNLIB_LOAD(envModuleDir + '/' + name); - if (!handle) #ifdef __APPLE__ + if (!handle) // on apple, look in the app bundle frameworks directory handle = DYNLIB_LOAD("@executable_path/../Frameworks/" + name); - - if (!handle) #endif + + if (!handle) // try loading without any explicit location (i.e. use OS search path) handle = DYNLIB_LOAD(name); // finally, try using the compiled-in module directory + #if defined(CEGUI_MODULE_DIR) if (!handle) handle = DYNLIB_LOAD(CEGUI_MODULE_DIR + name); + #endif return handle; } diff --git a/cegui/src/Element.cpp b/cegui/src/Element.cpp index daa415adc..d473eac69 100644 --- a/cegui/src/Element.cpp +++ b/cegui/src/Element.cpp @@ -88,7 +88,8 @@ Element::~Element() {} //----------------------------------------------------------------------------// -Element::Element(const Element&): +Element::Element(const Element& other): + EventSet(other), d_unclippedOuterRect(this, &Element::getUnclippedOuterRect_impl), d_unclippedInnerRect(this, &Element::getUnclippedInnerRect_impl) {} diff --git a/cegui/src/Exceptions.cpp b/cegui/src/Exceptions.cpp index b2ad11391..138081ae2 100644 --- a/cegui/src/Exceptions.cpp +++ b/cegui/src/Exceptions.cpp @@ -32,16 +32,20 @@ #include #if defined( __WIN32__ ) || defined( _WIN32) -#include +# include #endif #if defined(_MSC_VER) -#include -#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__HAIKU__) -#include -#include -#include -#include +# include +#elif defined(__ANDROID__) +# include +#elif (defined(__linux__) && !defined(__ANDROID__)) \ + || defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) \ + || defined(__HAIKU__) +# include +# include +# include +# include #endif // Start of CEGUI namespace section @@ -53,6 +57,14 @@ bool Exception::d_stdErrEnabled(true); //----------------------------------------------------------------------------// static void dumpBacktrace(size_t frames) { + +#if defined(__ANDROID__) + + // Not implemented yet. + CEGUI_UNUSED(frames); + +#else + #if defined(_DEBUG) || defined(DEBUG) #if defined(_MSC_VER) SymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_INCLUDE_32BIT_MODULES); @@ -104,7 +116,7 @@ static void dumpBacktrace(size_t frames) if (SymFromAddr(GetCurrentProcess(), symbol->Address, &displacement, symbol)) UnDecorateSymbolName(symbol->Name, signature, sizeof(signature), UNDNAME_COMPLETE); else - sprintf_s(signature, sizeof(signature), "%p", symbol->Address); + sprintf_s(signature, sizeof(signature), "%p", ULongToPtr(symbol->Address)); IMAGEHLP_MODULE64 modinfo; modinfo.SizeOfStruct = sizeof(modinfo); @@ -164,7 +176,19 @@ static void dumpBacktrace(size_t frames) } logger.logEvent("========== End of Backtrace ==========", Errors); + +#else + + CEGUI_UNUSED(frames); + #endif + +#else + + CEGUI_UNUSED(frames); + +#endif + #endif } @@ -193,6 +217,9 @@ Exception::Exception(const String& message, const String& name, // nobody seems to look in their log file! std::cerr << what() << std::endl; } +#ifdef __ANDROID__ + __android_log_print(ANDROID_LOG_ERROR, "CEGUIBase", "Exception thrown: %s", what()); +#endif } //----------------------------------------------------------------------------// diff --git a/cegui/src/Font.cpp b/cegui/src/Font.cpp index f9a3ce47b..d05420ebc 100644 --- a/cegui/src/Font.cpp +++ b/cegui/src/Font.cpp @@ -77,7 +77,9 @@ Font::~Font() { const uint old_size = (((d_maxCodepoint + GLYPHS_PER_PAGE) / GLYPHS_PER_PAGE) + BITS_PER_UINT - 1) / BITS_PER_UINT; - + #ifndef CEGUI_CUSTOM_ALLOCATORS + CEGUI_UNUSED(old_size); + #endif CEGUI_DELETE_ARRAY_PT(d_glyphPageLoaded, uint, old_size, Font); } } @@ -130,7 +132,9 @@ void Font::setMaxCodepoint(utf32 codepoint) { const uint old_size = (((d_maxCodepoint + GLYPHS_PER_PAGE) / GLYPHS_PER_PAGE) + BITS_PER_UINT - 1) / BITS_PER_UINT; - + #ifndef CEGUI_CUSTOM_ALLOCATORS + CEGUI_UNUSED(old_size); + #endif CEGUI_DELETE_ARRAY_PT(d_glyphPageLoaded, uint, old_size, Font); } diff --git a/cegui/src/FreeTypeFont.cpp b/cegui/src/FreeTypeFont.cpp index ee5c48cbd..10da95aeb 100644 --- a/cegui/src/FreeTypeFont.cpp +++ b/cegui/src/FreeTypeFont.cpp @@ -58,11 +58,24 @@ static int ft_usage_count = 0; static FT_Library ft_lib; //----------------------------------------------------------------------------// -#undef __FTERRORS_H__ -#define FT_ERRORDEF( e, v, s ) s, -#define FT_ERROR_START_LIST static const char* ft_errors[] = { -#define FT_ERROR_END_LIST 0}; -#include FT_ERRORS_H + +#undef __FTERRORS_H__ +#define FT_ERRORDEF( e, v, s ) { e, s }, +#define FT_ERROR_START_LIST { +#define FT_ERROR_END_LIST { 0, 0 } }; + +struct FreeTypeErrorDescription +{ +int err_code; +const char* err_msg; +}; + +static const FreeTypeErrorDescription ftErrorDescs[] = +#include FT_ERRORS_H + +static const std::vector freeTypeErrorDescriptions + (ftErrorDescs, ftErrorDescs + sizeof(ftErrorDescs) / sizeof(FreeTypeErrorDescription) ); + //----------------------------------------------------------------------------// FreeTypeFont::FreeTypeFont(const String& font_name, const float point_size, @@ -316,7 +329,11 @@ void FreeTypeFont::drawGlyphToBuffer(argb_t *buffer, uint buf_width) const { FT_Bitmap *glyph_bitmap = &d_fontFace->glyph->bitmap; - for (int i = 0; i < glyph_bitmap->rows; ++i) + unsigned int glyph_bitmap_height = + static_cast(glyph_bitmap->rows); + unsigned int glyph_bitmap_width = + static_cast(glyph_bitmap->width); + for (unsigned int i = 0; i < glyph_bitmap_height; ++i) { uchar *src = glyph_bitmap->buffer + (i * glyph_bitmap->pitch); switch (glyph_bitmap->pixel_mode) @@ -324,7 +341,7 @@ void FreeTypeFont::drawGlyphToBuffer(argb_t *buffer, uint buf_width) const case FT_PIXEL_MODE_GRAY: { uchar *dst = reinterpret_cast(buffer); - for (int j = 0; j < glyph_bitmap->width; ++j) + for (unsigned int j = 0; j < glyph_bitmap_width; ++j) { // RGBA *dst++ = 0xFF; @@ -336,7 +353,7 @@ void FreeTypeFont::drawGlyphToBuffer(argb_t *buffer, uint buf_width) const break; case FT_PIXEL_MODE_MONO: - for (int j = 0; j < glyph_bitmap->width; ++j) + for (unsigned int j = 0; j < glyph_bitmap_width; ++j) buffer [j] = (src [j / 8] & (0x80 >> (j & 7))) ? 0xFFFFFFFF : 0x00000000; break; @@ -387,9 +404,24 @@ void FreeTypeFont::updateFont() if ((error = FT_New_Memory_Face(ft_lib, d_fontData.getDataPtr(), static_cast(d_fontData.getSize()), 0, &d_fontFace)) != 0) + { + String errorMsg = "Unknown freetype error occurred: " + error; + + for(size_t i = 0; i < freeTypeErrorDescriptions.size(); ++i) + { + const FreeTypeErrorDescription& currentFreetypeError = freeTypeErrorDescriptions[i]; + + if(currentFreetypeError.err_code == error) + { + errorMsg = currentFreetypeError.err_msg; + } + } + + + CEGUI_THROW(GenericException("Failed to create face from font file '" + - d_filename + "' error was: " + - ((error < FT_Err_Max) ? ft_errors[error] : "unknown error"))); + d_filename + "' error was: " + errorMsg)); + } // check that default Unicode character map is available if (!d_fontFace->charmap) diff --git a/cegui/src/ImageCodecModules/CMakeLists.txt b/cegui/src/ImageCodecModules/CMakeLists.txt index 0ed025aa7..dd98133f5 100644 --- a/cegui/src/ImageCodecModules/CMakeLists.txt +++ b/cegui/src/ImageCodecModules/CMakeLists.txt @@ -26,3 +26,6 @@ if (CEGUI_BUILD_IMAGECODEC_PVR) add_subdirectory(PVR) endif() +if (CEGUI_BUILD_IMAGECODEC_SDL2) + add_subdirectory(SDL2) +endif() \ No newline at end of file diff --git a/cegui/src/ImageCodecModules/Corona/CMakeLists.txt b/cegui/src/ImageCodecModules/Corona/CMakeLists.txt index d228b70fd..e1eec4bcf 100644 --- a/cegui/src/ImageCodecModules/Corona/CMakeLists.txt +++ b/cegui/src/ImageCodecModules/Corona/CMakeLists.txt @@ -2,7 +2,7 @@ set( CEGUI_TARGET_NAME ${CEGUI_CORONA_IMAGECODEC_LIBNAME} ) cegui_gather_files() cegui_add_loadable_module(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} CORONA) +cegui_add_dependency(${CEGUI_TARGET_NAME} CORONA PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/ImageCodecModules/DevIL/CMakeLists.txt b/cegui/src/ImageCodecModules/DevIL/CMakeLists.txt index ee5fd893e..7ea4b656c 100644 --- a/cegui/src/ImageCodecModules/DevIL/CMakeLists.txt +++ b/cegui/src/ImageCodecModules/DevIL/CMakeLists.txt @@ -3,7 +3,7 @@ set (CEGUI_TARGET_NAME ${CEGUI_DEVIL_IMAGECODEC_LIBNAME}) cegui_gather_files() cegui_add_loadable_module(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} IL) +cegui_add_dependency(${CEGUI_TARGET_NAME} IL PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/ImageCodecModules/FreeImage/CMakeLists.txt b/cegui/src/ImageCodecModules/FreeImage/CMakeLists.txt index b5900ccfc..f0fce7302 100644 --- a/cegui/src/ImageCodecModules/FreeImage/CMakeLists.txt +++ b/cegui/src/ImageCodecModules/FreeImage/CMakeLists.txt @@ -2,7 +2,7 @@ set (CEGUI_TARGET_NAME ${CEGUI_FREEIMAGE_IMAGECODEC_LIBNAME}) cegui_gather_files() cegui_add_loadable_module(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} FREEIMAGE) +cegui_add_dependency(${CEGUI_TARGET_NAME} FREEIMAGE PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/ImageCodecModules/PVR/CMakeLists.txt b/cegui/src/ImageCodecModules/PVR/CMakeLists.txt index 3d9b56572..cff0bf92d 100644 --- a/cegui/src/ImageCodecModules/PVR/CMakeLists.txt +++ b/cegui/src/ImageCodecModules/PVR/CMakeLists.txt @@ -2,7 +2,7 @@ set (CEGUI_TARGET_NAME ${CEGUI_PVR_IMAGECODEC_LIBNAME}) cegui_gather_files() cegui_add_loadable_module(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} PVRTOOLS) +cegui_add_dependency(${CEGUI_TARGET_NAME} PVRTOOLS PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/ImageCodecModules/SDL2/CMakeLists.txt b/cegui/src/ImageCodecModules/SDL2/CMakeLists.txt new file mode 100644 index 000000000..c60a9e0a4 --- /dev/null +++ b/cegui/src/ImageCodecModules/SDL2/CMakeLists.txt @@ -0,0 +1,8 @@ +set( CEGUI_TARGET_NAME ${CEGUI_SDL2_IMAGECODEC_LIBNAME} ) + +cegui_gather_files() +cegui_add_loadable_module(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) +cegui_add_dependency(${CEGUI_TARGET_NAME} SDL2 PRIVATE TRUE) +cegui_add_dependency(${CEGUI_TARGET_NAME} SDL2IMAGE PRIVATE TRUE) + +cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/ImageCodecModules/SDL2/ImageCodec.cpp b/cegui/src/ImageCodecModules/SDL2/ImageCodec.cpp new file mode 100644 index 000000000..3dcb35813 --- /dev/null +++ b/cegui/src/ImageCodecModules/SDL2/ImageCodec.cpp @@ -0,0 +1,113 @@ +/************************************************************************ + created: 04/07/2014 + author: Luca Ebach + with code by John Norman + + purpose: This codec provides SDL2 based image loading +*************************************************************************/ +/*************************************************************************** + * Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + ***************************************************************************/ + +#include "CEGUI/ImageCodecModules/SDL2/ImageCodec.h" + +#include "CEGUI/DataContainer.h" +#include "CEGUI/Exceptions.h" +#include "CEGUI/Texture.h" +#include "CEGUI/Singleton.h" +#include "CEGUI/Logger.h" + +#include +#include + +#include + +namespace CEGUI +{ + +SDL2ImageCodec::SDL2ImageCodec() + : ImageCodec("CEGUI::SDL2ImageCodec - Official SDL2 based image codec") +{ + IMG_Init(~0); + + d_supportedFormat = "BMP GIF JPEG LBM PCX PNG PNM TGA TIFF WEBP XCF XPM XV"; +} + +SDL2ImageCodec::~SDL2ImageCodec() +{ + IMG_Quit(); +} + +Texture* SDL2ImageCodec::load(const RawDataContainer& data, Texture* result) +{ + SDL_RWops* ops = SDL_RWFromConstMem(static_cast(data.getDataPtr()), data.getSize()); + + if (ops) + { + Texture::PixelFormat pixel_fmt; + + SDL_Surface* img = IMG_Load_RW(ops, 0); + + if (!img) + img = IMG_LoadTGA_RW(ops); + + if (!img) + { + Logger::getSingletonPtr()->logEvent("Cannot load image! SDL2_image returned an error in IMG_Load_RW", Errors); + return 0; + } + + switch (img->format->BitsPerPixel) + { + case 24: + pixel_fmt = Texture::PF_RGB; + break; + + case 32: + pixel_fmt = Texture::PF_RGBA; + break; + + default: + Logger::getSingletonPtr()->logEvent("Unsupported pixel format in SDL2 image codec", Errors); + return 0; + } + + Sizef size; + size.d_width = static_cast(img->w); + size.d_height = static_cast(img->h); + + SDL_LockSurface(img); + result->loadFromMemory(img->pixels, size, pixel_fmt); + SDL_UnlockSurface(img); + + SDL_FreeRW(ops); + SDL_FreeSurface(img); + } + else + { + CEGUI_THROW(FileIOException("Could not load image from memory.")); + } + + return result; +} + +} diff --git a/cegui/src/ImageCodecModules/SDL2/ImageCodecModule.cpp b/cegui/src/ImageCodecModules/SDL2/ImageCodecModule.cpp new file mode 100644 index 000000000..456d75e52 --- /dev/null +++ b/cegui/src/ImageCodecModules/SDL2/ImageCodecModule.cpp @@ -0,0 +1,41 @@ +/*********************************************************************** + created: 04/07/2014 + author: Luca Ebach + with code by John Norman + + purpose: This codec provides SDL2 based image loading +*************************************************************************/ +/*************************************************************************** + * Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + ***************************************************************************/ + +#include + +CEGUI::ImageCodec* createImageCodec(void) +{ + return CEGUI_NEW_AO CEGUI::SDL2ImageCodec(); +} + +void destroyImageCodec(CEGUI::ImageCodec* imageCodec) +{ + CEGUI_DELETE_AO imageCodec; +} \ No newline at end of file diff --git a/cegui/src/ImageCodecModules/SILLY/CMakeLists.txt b/cegui/src/ImageCodecModules/SILLY/CMakeLists.txt index 5bf1d684b..e81337002 100644 --- a/cegui/src/ImageCodecModules/SILLY/CMakeLists.txt +++ b/cegui/src/ImageCodecModules/SILLY/CMakeLists.txt @@ -2,7 +2,7 @@ set (CEGUI_TARGET_NAME ${CEGUI_SILLY_IMAGECODEC_LIBNAME}) cegui_gather_files() cegui_add_loadable_module(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} SILLY) +cegui_add_dependency(${CEGUI_TARGET_NAME} SILLY PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/ImageManager.cpp b/cegui/src/ImageManager.cpp index b84f9a9f2..15c9e0ace 100644 --- a/cegui/src/ImageManager.cpp +++ b/cegui/src/ImageManager.cpp @@ -172,8 +172,8 @@ Image& ImageManager::create(const XMLAttributes& attributes) { static const String type_default("BasicImage"); - const String& type(attributes.getValueAsString(ImageTypeAttribute, type_default)); - const String& name(attributes.getValueAsString(ImageNameAttribute)); + const String type = attributes.getValueAsString(ImageTypeAttribute, type_default); + const String name = attributes.getValueAsString(ImageNameAttribute); if (name.empty()) CEGUI_THROW(InvalidRequestException( diff --git a/cegui/src/MinizipResourceProvider.cpp b/cegui/src/MinizipResourceProvider.cpp index 1d2cf8e09..ac5e2162e 100644 --- a/cegui/src/MinizipResourceProvider.cpp +++ b/cegui/src/MinizipResourceProvider.cpp @@ -38,7 +38,7 @@ #include #if defined (__WIN32__) || defined(_WIN32) -# include +# include # define FNMATCH(p, s) PathMatchSpec(s, p) # ifdef _MSC_VER # pragma comment(lib, "shlwapi.lib") diff --git a/cegui/src/RenderedStringTextComponent.cpp b/cegui/src/RenderedStringTextComponent.cpp index bcb782794..e672305e9 100644 --- a/cegui/src/RenderedStringTextComponent.cpp +++ b/cegui/src/RenderedStringTextComponent.cpp @@ -149,9 +149,10 @@ const Font* RenderedStringTextComponent::getEffectiveFont( if (d_font) return d_font; - return (window ? window->getGUIContext() : - System::getSingleton().getDefaultGUIContext()). - getDefaultFont(); + if (window) + return window->getFont(); + + return 0; } //----------------------------------------------------------------------------// diff --git a/cegui/src/RendererModules/Direct3D10/CMakeLists.txt b/cegui/src/RendererModules/Direct3D10/CMakeLists.txt index d6b0a74d9..a4fcad6cf 100644 --- a/cegui/src/RendererModules/Direct3D10/CMakeLists.txt +++ b/cegui/src/RendererModules/Direct3D10/CMakeLists.txt @@ -1,11 +1,17 @@ set (CEGUI_TARGET_NAME ${CEGUI_DIRECT3D10_RENDERER_LIBNAME}) -include_directories(${DIRECTXSDK_INCLUDE_DIR}) -link_directories(${DIRECTXSDK_LIBRARY_DIR}) +if (NOT MINGW) + include_directories(${DIRECTXSDK_INCLUDE_DIR}) + link_directories(${DIRECTXSDK_LIBRARY_DIR}) +endif () cegui_gather_files() cegui_add_library(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME} d3d10) -cegui_target_link_libraries(${CEGUI_TARGET_NAME} optimized d3dx10 debug d3dx10d) - +cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) +if (MINGW) + cegui_target_link_libraries(${CEGUI_TARGET_NAME} d3dx10_43) +else () + cegui_target_link_libraries(${CEGUI_TARGET_NAME} d3d10) + cegui_target_link_libraries(${CEGUI_TARGET_NAME} optimized d3dx10 debug d3dx10d) +endif () diff --git a/cegui/src/RendererModules/Direct3D10/RenderTarget.inl b/cegui/src/RendererModules/Direct3D10/RenderTarget.inl index 2be308c48..cba7fe4bf 100644 --- a/cegui/src/RendererModules/Direct3D10/RenderTarget.inl +++ b/cegui/src/RendererModules/Direct3D10/RenderTarget.inl @@ -28,6 +28,19 @@ #include "CEGUI/RendererModules/Direct3D10/GeometryBuffer.h" #include "CEGUI/RenderQueue.h" +/* Unfortunately, MinGW-w64 doesn't have . Instead we use , + which is almost similar. However, "D3DXVec3Project" is declared in + a bit different than in . We can't just declare it with the right prototype, + because it's already declared (in , which we still need), with the wrong + prototype. So we use a nasty trick of casting the function pointer to the + right prototype in order to use it. Same for "D3DXVec3Unproject". */ +#ifdef __MINGW32__ +extern "C" typedef D3DXVECTOR3* WINAPI D3DXVec3Project_func (D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3D10_VIEWPORT *pViewport, CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld); +#define D3DXVec3Project (reinterpret_cast(D3DXVec3Project)) +extern "C" typedef D3DXVECTOR3* WINAPI D3DXVec3Unproject_func (D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3D10_VIEWPORT *pViewport, CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld); +#define D3DXVec3Unproject (reinterpret_cast(D3DXVec3Unproject)) +#endif + // Start of CEGUI namespace section namespace CEGUI { @@ -37,8 +50,8 @@ Direct3D10RenderTarget::Direct3D10RenderTarget(Direct3D10Renderer& owner) : d_owner(owner), d_device(d_owner.getDirect3DDevice()), d_area(0, 0, 0, 0), - d_viewDistance(0), - d_matrixValid(false) + d_matrixValid(false), + d_viewDistance(0) { } diff --git a/cegui/src/RendererModules/Direct3D10/Renderer.cpp b/cegui/src/RendererModules/Direct3D10/Renderer.cpp index 490f723e1..d9a8f2c8c 100644 --- a/cegui/src/RendererModules/Direct3D10/Renderer.cpp +++ b/cegui/src/RendererModules/Direct3D10/Renderer.cpp @@ -35,6 +35,33 @@ #include "CEGUI/Logger.h" #include +#ifdef __MINGW32__ + +extern "C" +{ + +struct ID3DX10ThreadPump; + +HRESULT WINAPI D3DX10CreateEffectFromMemory( + LPCVOID pData, + SIZE_T DataLength, + LPCSTR pSrcFileName, + CONST D3D10_SHADER_MACRO* pDefines, + ID3D10Include* pInclude, + LPCSTR pProfile, + UINT HLSLFlags, + UINT FXFlags, + ID3D10Device* pDevice, + ID3D10EffectPool* pEffectPool, + ID3DX10ThreadPump* pPump, + ID3D10Effect** ppEffect, + ID3D10Blob** ppErrors, + HRESULT* pHResult); + +} + +#endif + #include "shader.txt" // Start of CEGUI namespace section diff --git a/cegui/src/RendererModules/Direct3D10/Texture.cpp b/cegui/src/RendererModules/Direct3D10/Texture.cpp index 02ce0598f..8916d377c 100644 --- a/cegui/src/RendererModules/Direct3D10/Texture.cpp +++ b/cegui/src/RendererModules/Direct3D10/Texture.cpp @@ -70,26 +70,6 @@ static size_t calculateDataWidth(const size_t width, Texture::PixelFormat fmt) } } -//----------------------------------------------------------------------------// -// Helper utility function that copies an RGBA buffer into a region of a second -// buffer as D3DCOLOR data values -static void blitToSurface(const uint32* src, uint32* dst, - const Sizef& sz, size_t dest_pitch) -{ - for (uint i = 0; i < sz.d_height; ++i) - { - for (uint j = 0; j < sz.d_width; ++j) - { - const uint32 pixel = src[j]; - const uint32 tmp = pixel & 0x00FF00FF; - dst[j] = pixel & 0xFF00FF00 | (tmp << 16) | (tmp >> 16); - } - - dst += dest_pitch / sizeof(uint32); - src += static_cast(sz.d_width); - } -} - //----------------------------------------------------------------------------// // Helper utility function that copies a region of a buffer containing D3DCOLOR // values into a second buffer as RGBA values. @@ -102,7 +82,7 @@ static void blitFromSurface(const uint32* src, uint32* dst, { const uint32 pixel = src[j]; const uint32 tmp = pixel & 0x00FF00FF; - dst[j] = pixel & 0xFF00FF00 | (tmp << 16) | (tmp >> 16); + dst[j] = (pixel & 0xFF00FF00) | (tmp << 16) | (tmp >> 16); } src += source_pitch / sizeof(uint32); @@ -212,10 +192,11 @@ void Direct3D10Texture::loadFromMemory(const void* buffer, cleanupDirect3D10Texture(); const void* img_src = buffer; + unsigned char* dest(0); if (pixel_format == PF_RGB) { const unsigned char* src = static_cast(buffer); - unsigned char* dest = new unsigned char[static_cast( buffer_size.d_width * buffer_size.d_height * 4 )]; + dest = new unsigned char[static_cast( buffer_size.d_width * buffer_size.d_height * 4 )]; for (int i = 0; i < buffer_size.d_width * buffer_size.d_height; ++i) { @@ -249,8 +230,7 @@ void Direct3D10Texture::loadFromMemory(const void* buffer, HRESULT hr = d_device.CreateTexture2D(&tex_desc, &data, &d_texture); - if (pixel_format == PF_RGB) - delete[] img_src; + delete[] dest; if (FAILED(hr)) CEGUI_THROW(RendererException( diff --git a/cegui/src/RendererModules/Direct3D11/CMakeLists.txt b/cegui/src/RendererModules/Direct3D11/CMakeLists.txt index dc47400c4..06f34cc78 100644 --- a/cegui/src/RendererModules/Direct3D11/CMakeLists.txt +++ b/cegui/src/RendererModules/Direct3D11/CMakeLists.txt @@ -1,13 +1,18 @@ set (CEGUI_TARGET_NAME ${CEGUI_DIRECT3D11_RENDERER_LIBNAME}) -include_directories(${DIRECTXSDK_INCLUDE_DIR}) -link_directories(${DIRECTXSDK_LIBRARY_DIR}) +if (NOT MINGW) + include_directories(${DIRECTXSDK_INCLUDE_DIR}) + link_directories(${DIRECTXSDK_LIBRARY_DIR}) +endif () cegui_gather_files() cegui_add_library(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME} d3d11 d3dcompiler) -cegui_target_link_libraries(${CEGUI_TARGET_NAME} optimized d3dx11 d3dx10 debug d3dx11d d3dx10d) - -cegui_add_dependency(${CEGUI_TARGET_NAME} D3DX11EFFECTS) - +cegui_add_dependency( ${CEGUI_TARGET_NAME} D3DX11EFFECTS PRIVATE TRUE) +cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME} d3d11 ) +if (MINGW) + cegui_target_link_libraries(${CEGUI_TARGET_NAME} d3dx11_43 d3dx10_43 d3dcompiler_43 ) +else () + cegui_target_link_libraries(${CEGUI_TARGET_NAME} d3dcompiler ) + cegui_target_link_libraries(${CEGUI_TARGET_NAME} optimized d3dx11 d3dx10 debug d3dx11d d3dx10d) +endif () \ No newline at end of file diff --git a/cegui/src/RendererModules/Direct3D11/RenderTarget.inl b/cegui/src/RendererModules/Direct3D11/RenderTarget.inl old mode 100644 new mode 100755 index 2b1f0fc49..40b7c4216 --- a/cegui/src/RendererModules/Direct3D11/RenderTarget.inl +++ b/cegui/src/RendererModules/Direct3D11/RenderTarget.inl @@ -27,6 +27,19 @@ #include "CEGUI/RendererModules/Direct3D11/GeometryBuffer.h" #include "CEGUI/RenderQueue.h" +/* Unfortunately, MinGW-w64 doesn't have . Instead we use , + which is almost similar. However, "D3DXVec3Project" is declared in + a bit different than in . We can't just declare it with the right prototype, + because it's already declared (in , which we still need), with the wrong + prototype. So we use a nasty trick of casting the function pointer to the + right prototype in order to use it. Same for "D3DXVec3Unproject". */ +#ifdef __MINGW32__ +extern "C" typedef D3DXVECTOR3* WINAPI D3DXVec3Project_func (D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3D10_VIEWPORT *pViewport, CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld); +#define D3DXVec3Project (reinterpret_cast(D3DXVec3Project)) +extern "C" typedef D3DXVECTOR3* WINAPI D3DXVec3Unproject_func (D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3D10_VIEWPORT *pViewport, CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld); +#define D3DXVec3Unproject (reinterpret_cast(D3DXVec3Unproject)) +#endif + // Start of CEGUI namespace section namespace CEGUI { @@ -36,8 +49,8 @@ Direct3D11RenderTarget::Direct3D11RenderTarget(Direct3D11Renderer& owner) : d_owner(owner), d_device(d_owner.getDirect3DDevice()), d_area(0, 0, 0, 0), - d_viewDistance(0), - d_matrixValid(false) + d_matrixValid(false), + d_viewDistance(0) { } diff --git a/cegui/src/RendererModules/Direct3D11/Renderer.cpp b/cegui/src/RendererModules/Direct3D11/Renderer.cpp old mode 100644 new mode 100755 index ec07f783c..520baa97f --- a/cegui/src/RendererModules/Direct3D11/Renderer.cpp +++ b/cegui/src/RendererModules/Direct3D11/Renderer.cpp @@ -356,13 +356,13 @@ Direct3D11Renderer::Direct3D11Renderer(ID3D11Device* device,ID3D11DeviceContext // create the main effect from the shader source. ID3D10Blob* errors = 0; - DWORD DefaultOptions=NULL;//D3D10_SHADER_PACK_MATRIX_ROW_MAJOR|D3D10_SHADER_PARTIAL_PRECISION|D3D10_SHADER_SKIP_VALIDATION; + UINT DefaultOptions=0;//D3D10_SHADER_PACK_MATRIX_ROW_MAJOR|D3D10_SHADER_PARTIAL_PRECISION|D3D10_SHADER_SKIP_VALIDATION; ID3D10Blob* ShaderBlob=NULL;//first we compile shader, then create effect from it if (FAILED(D3DX11CompileFromMemory(shaderSource,sizeof(shaderSource), "shaderSource",NULL,NULL,NULL,"fx_5_0", - DefaultOptions,NULL,NULL,&ShaderBlob,&errors,NULL))) + DefaultOptions,0,NULL,&ShaderBlob,&errors,NULL))) { std::string msg(static_cast(errors->GetBufferPointer()), errors->GetBufferSize()); diff --git a/cegui/src/RendererModules/Direct3D11/Texture.cpp b/cegui/src/RendererModules/Direct3D11/Texture.cpp index f32244719..6cc3e0278 100644 --- a/cegui/src/RendererModules/Direct3D11/Texture.cpp +++ b/cegui/src/RendererModules/Direct3D11/Texture.cpp @@ -28,8 +28,6 @@ #include "CEGUI/Exceptions.h" #include "CEGUI/ImageCodec.h" #include -#include - // Start of CEGUI namespace section namespace CEGUI @@ -71,26 +69,6 @@ static size_t calculateDataWidth(const size_t width, Texture::PixelFormat fmt) } } -//----------------------------------------------------------------------------// -// Helper utility function that copies an RGBA buffer into a region of a second -// buffer as D3DCOLOR data values -static void blitToSurface(const uint32* src, uint32* dst, - const Sizef& sz, size_t dest_pitch) -{ - for (uint i = 0; i < sz.d_height; ++i) - { - for (uint j = 0; j < sz.d_width; ++j) - { - const uint32 pixel = src[j]; - const uint32 tmp = pixel & 0x00FF00FF; - dst[j] = pixel & 0xFF00FF00 | (tmp << 16) | (tmp >> 16); - } - - dst += dest_pitch / sizeof(uint32); - src += static_cast(sz.d_width); - } -} - //----------------------------------------------------------------------------// // Helper utility function that copies a region of a buffer containing D3DCOLOR // values into a second buffer as RGBA values. @@ -103,7 +81,7 @@ static void blitFromSurface(const uint32* src, uint32* dst, { const uint32 pixel = src[j]; const uint32 tmp = pixel & 0x00FF00FF; - dst[j] = pixel & 0xFF00FF00 | (tmp << 16) | (tmp >> 16); + dst[j] = (pixel & 0xFF00FF00) | (tmp << 16) | (tmp >> 16); } src += source_pitch / sizeof(uint32); @@ -213,10 +191,11 @@ void Direct3D11Texture::loadFromMemory(const void* buffer, cleanupDirect3D11Texture(); const void* img_src = buffer; + unsigned char* dest(0); if (pixel_format == PF_RGB) { const unsigned char* src = static_cast(buffer); - unsigned char* dest = new unsigned char[static_cast( buffer_size.d_width * buffer_size.d_height * 4 )]; + dest = new unsigned char[static_cast( buffer_size.d_width * buffer_size.d_height * 4 )]; for (int i = 0; i < buffer_size.d_width * buffer_size.d_height; ++i) { @@ -250,8 +229,7 @@ void Direct3D11Texture::loadFromMemory(const void* buffer, HRESULT hr = d_device.d_device->CreateTexture2D(&tex_desc, &data, &d_texture); - if (pixel_format == PF_RGB) - delete[] img_src; + delete[] dest; if (FAILED(hr)) CEGUI_THROW(RendererException( diff --git a/cegui/src/RendererModules/Direct3D9/CMakeLists.txt b/cegui/src/RendererModules/Direct3D9/CMakeLists.txt index 46c03b505..fa7e69649 100644 --- a/cegui/src/RendererModules/Direct3D9/CMakeLists.txt +++ b/cegui/src/RendererModules/Direct3D9/CMakeLists.txt @@ -1,11 +1,16 @@ set (CEGUI_TARGET_NAME ${CEGUI_DIRECT3D9_RENDERER_LIBNAME}) -include_directories(${DIRECTXSDK_INCLUDE_DIR}) -link_directories(${DIRECTXSDK_LIBRARY_DIR}) +if (NOT MINGW) + include_directories(${DIRECTXSDK_INCLUDE_DIR}) + link_directories(${DIRECTXSDK_LIBRARY_DIR}) +endif () cegui_gather_files() cegui_add_library(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME} d3d9) -cegui_target_link_libraries(${CEGUI_TARGET_NAME} optimized d3dx9 debug d3dx9d) - +if (MINGW) + cegui_target_link_libraries(${CEGUI_TARGET_NAME} d3dx9_43) +else () + cegui_target_link_libraries(${CEGUI_TARGET_NAME} optimized d3dx9 debug d3dx9d) +endif () diff --git a/cegui/src/RendererModules/Direct3D9/RenderTarget.inl b/cegui/src/RendererModules/Direct3D9/RenderTarget.inl index 796492d54..7d688c77b 100644 --- a/cegui/src/RendererModules/Direct3D9/RenderTarget.inl +++ b/cegui/src/RendererModules/Direct3D9/RenderTarget.inl @@ -39,8 +39,8 @@ Direct3D9RenderTarget::Direct3D9RenderTarget(Direct3D9Renderer& owner) : d_owner(owner), d_device(owner.getDevice()), d_area(0, 0, 0, 0), - d_viewDistance(0), - d_matrixValid(false) + d_matrixValid(false), + d_viewDistance(0) { } diff --git a/cegui/src/RendererModules/Direct3D9/Texture.cpp b/cegui/src/RendererModules/Direct3D9/Texture.cpp index 98aa72e78..6b20e4dd3 100644 --- a/cegui/src/RendererModules/Direct3D9/Texture.cpp +++ b/cegui/src/RendererModules/Direct3D9/Texture.cpp @@ -107,7 +107,7 @@ static void blitRGBAToD3DCOLORSurface(const uint32* src, uint32* dst, { const uint32 pixel = src[j]; const uint32 tmp = pixel & 0x00FF00FF; - dst[j] = pixel & 0xFF00FF00 | (tmp << 16) | (tmp >> 16); + dst[j] = (pixel & 0xFF00FF00) | (tmp << 16) | (tmp >> 16); } dst += dest_pitch / sizeof(uint32); @@ -127,7 +127,7 @@ static void blitD3DCOLORSurfaceToRGBA(const uint32* src, uint32* dst, { const uint32 pixel = src[j]; const uint32 tmp = pixel & 0x00FF00FF; - dst[j] = pixel & 0xFF00FF00 | (tmp << 16) | (tmp >> 16); + dst[j] = (pixel & 0xFF00FF00) | (tmp << 16) | (tmp >> 16); } src += source_pitch / sizeof(uint32); diff --git a/cegui/src/RendererModules/DirectFB/CMakeLists.txt b/cegui/src/RendererModules/DirectFB/CMakeLists.txt index ecfdfbb58..376c3a5c2 100644 --- a/cegui/src/RendererModules/DirectFB/CMakeLists.txt +++ b/cegui/src/RendererModules/DirectFB/CMakeLists.txt @@ -2,7 +2,7 @@ set (CEGUI_TARGET_NAME ${CEGUI_DIRECTFB_RENDERER_LIBNAME}) cegui_gather_files() cegui_add_library(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} DIRECTFB) +cegui_add_dependency(${CEGUI_TARGET_NAME} DIRECTFB PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/RendererModules/Irrlicht/CMakeLists.txt b/cegui/src/RendererModules/Irrlicht/CMakeLists.txt index 3fd3fcd6e..7e7dbdb02 100644 --- a/cegui/src/RendererModules/Irrlicht/CMakeLists.txt +++ b/cegui/src/RendererModules/Irrlicht/CMakeLists.txt @@ -2,7 +2,7 @@ set (CEGUI_TARGET_NAME ${CEGUI_IRRLICHT_RENDERER_LIBNAME}) cegui_gather_files() cegui_add_library(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} IRRLICHT) +cegui_add_dependency(${CEGUI_TARGET_NAME} IRRLICHT PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/RendererModules/Irrlicht/ImageCodec.cpp b/cegui/src/RendererModules/Irrlicht/ImageCodec.cpp index 7aed97848..7977f3b9e 100644 --- a/cegui/src/RendererModules/Irrlicht/ImageCodec.cpp +++ b/cegui/src/RendererModules/Irrlicht/ImageCodec.cpp @@ -86,9 +86,9 @@ Texture* IrrlichtImageCodec::load(const RawDataContainer& data, Texture* result) // (we should probably check the R and B masks and decide based on those) if (format == Texture::PF_RGBA) { - for (uint j = 0; j < sz.Height; ++j) + for (s32 j = 0; j < sz.Height; ++j) { - for (uint i = 0; i < sz.Width; ++i) + for (s32 i = 0; i < sz.Width; ++i) { const uchar tmp = dat[i * components + 0]; dat[i * components + 0] = dat[i * components + 2]; diff --git a/cegui/src/RendererModules/Irrlicht/RenderTarget.inl b/cegui/src/RendererModules/Irrlicht/RenderTarget.inl index d7ad50f9c..18049c0dc 100644 --- a/cegui/src/RendererModules/Irrlicht/RenderTarget.inl +++ b/cegui/src/RendererModules/Irrlicht/RenderTarget.inl @@ -39,8 +39,8 @@ IrrlichtRenderTarget::IrrlichtRenderTarget(IrrlichtRenderer& owner, d_owner(owner), d_driver(driver), d_area(0, 0, 0, 0), - d_viewDistance(0), d_matrixValid(false), + d_viewDistance(0), #if IRRLICHT_VERSION_MAJOR > 1 || (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR >= 8) d_xViewDir(1.0f) #else diff --git a/cegui/src/RendererModules/Ogre/CMakeLists.txt b/cegui/src/RendererModules/Ogre/CMakeLists.txt index 8bda46c55..f4f751cc4 100644 --- a/cegui/src/RendererModules/Ogre/CMakeLists.txt +++ b/cegui/src/RendererModules/Ogre/CMakeLists.txt @@ -5,7 +5,7 @@ add_definitions(-DBOOST_ALL_NO_LIB) cegui_gather_files() cegui_add_library(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} OGRE) +cegui_add_dependency(${CEGUI_TARGET_NAME} OGRE PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/RendererModules/Ogre/GeometryBuffer.cpp b/cegui/src/RendererModules/Ogre/GeometryBuffer.cpp index 93ffdfe3b..6ac3d34ec 100644 --- a/cegui/src/RendererModules/Ogre/GeometryBuffer.cpp +++ b/cegui/src/RendererModules/Ogre/GeometryBuffer.cpp @@ -33,6 +33,12 @@ #include #include +#ifdef CEGUI_USE_OGRE_HLMS +#include +#include +#include +#endif + // Start of CEGUI namespace section namespace CEGUI { @@ -61,21 +67,33 @@ static const Ogre::LayerBlendModeEx S_alphaBlendMode = }; //----------------------------------------------------------------------------// +#ifndef CEGUI_USE_OGRE_HLMS static const Ogre::TextureUnitState::UVWAddressingMode S_textureAddressMode = { Ogre::TextureUnitState::TAM_CLAMP, Ogre::TextureUnitState::TAM_CLAMP, Ogre::TextureUnitState::TAM_CLAMP }; +#endif //----------------------------------------------------------------------------// // Helper to allocate a vertex buffer and initialse a Ogre::RenderOperation -static void initialiseRenderOp(Ogre::RenderOperation& rop, - Ogre::HardwareVertexBufferSharedPtr& vb, - size_t count) +static void initialiseRenderOp( +#ifdef CEGUI_USE_OGRE_HLMS + Ogre::v1::RenderOperation& rop, + Ogre::v1::HardwareVertexBufferSharedPtr& vb, +#else + Ogre::RenderOperation& rop, + Ogre::HardwareVertexBufferSharedPtr& vb, +#endif + size_t count) { using namespace Ogre; +#ifdef CEGUI_USE_OGRE_HLMS + using namespace Ogre::v1; +#endif + // basic initialisation of render op rop.vertexData = OGRE_NEW VertexData(); rop.operationType = RenderOperation::OT_TRIANGLE_LIST; @@ -102,8 +120,15 @@ static void initialiseRenderOp(Ogre::RenderOperation& rop, //----------------------------------------------------------------------------// // Helper to cleanup what initialiseRenderOp did. -static void cleanupRenderOp(Ogre::RenderOperation& rop, - Ogre::HardwareVertexBufferSharedPtr& vb) +static void cleanupRenderOp( +#ifdef CEGUI_USE_OGRE_HLMS + Ogre::v1::RenderOperation& rop, + Ogre::v1::HardwareVertexBufferSharedPtr& vb +#else + Ogre::RenderOperation& rop, + Ogre::HardwareVertexBufferSharedPtr& vb +#endif + ) { OGRE_DELETE rop.vertexData; rop.vertexData = 0; @@ -145,6 +170,17 @@ void OgreGeometryBuffer::draw() const d_owner.setupRenderingBlendMode(d_blendMode); d_owner.updateShaderParams(); +#ifdef CEGUI_USE_OGRE_HLMS + Ogre::Viewport* previousViewport = d_renderSystem._getViewport(); + Ogre::Viewport* currentViewport = d_owner.getOgreRenderTarget()->getViewport(0); + + Rectf previousClipRect; + previousClipRect.left(currentViewport->getScissorLeft()); + previousClipRect.top(currentViewport->getScissorTop()); + previousClipRect.right(currentViewport->getScissorWidth()); + previousClipRect.bottom(currentViewport->getScissorHeight()); +#endif + const int pass_count = d_effect ? d_effect->getPassCount() : 1; for (int pass = 0; pass < pass_count; ++pass) { @@ -158,19 +194,49 @@ void OgreGeometryBuffer::draw() const for ( ; i != d_batches.end(); ++i) { // Set up clipping for this buffer +#ifdef CEGUI_USE_OGRE_HLMS + if (i->clip) + { + int actualWidth = currentViewport->getActualWidth(); + int actualHeight = currentViewport->getActualHeight(); + float scissorsLeft = d_clipRect.left() / actualWidth; + float scissorsTop = d_clipRect.top() / actualHeight; + float scissorsWidth = (d_clipRect.right() - d_clipRect.left()) / actualWidth; + float scissorsHeight = (d_clipRect.bottom() - d_clipRect.top()) / actualHeight; + currentViewport->setScissors(scissorsLeft, scissorsTop, scissorsWidth, scissorsHeight); + } + else + { + currentViewport->setScissors(previousClipRect.left(), previousClipRect.top(), + previousClipRect.right(), previousClipRect.bottom()); + } + + d_renderSystem._setViewport(currentViewport); +#else d_renderSystem.setScissorTest( i->clip, d_clipRect.left(), d_clipRect.top(), d_clipRect.right(), d_clipRect.bottom()); +#endif d_renderOp.vertexData->vertexStart = pos; d_renderOp.vertexData->vertexCount = i->vertexCount; +#ifdef CEGUI_USE_OGRE_HLMS + d_renderSystem._setTexture(0, true, i->texture.get()); +#else d_renderSystem._setTexture(0, true, i->texture); +#endif initialiseTextureStates(); d_renderSystem._render(d_renderOp); pos += i->vertexCount; } } +#ifdef CEGUI_USE_OGRE_HLMS + currentViewport->setScissors(previousClipRect.left(), previousClipRect.top(), + previousClipRect.right(), previousClipRect.bottom()); + d_renderSystem._setViewport(previousViewport); +#endif + // clean up RenderEffect if (d_effect) d_effect->performPostRenderFunctions(); @@ -353,8 +419,13 @@ void OgreGeometryBuffer::syncHardwareBuffer() const // copy vertex data into hw buffer if (required_size > 0) { +#ifdef CEGUI_USE_OGRE_HLMS + std::memcpy(d_hwBuffer->lock(Ogre::v1::HardwareVertexBuffer::HBL_DISCARD), + &d_vertices[0], sizeof(OgreVertex) * d_vertices.size()); +#else std::memcpy(d_hwBuffer->lock(Ogre::HardwareVertexBuffer::HBL_DISCARD), &d_vertices[0], sizeof(OgreVertex) * d_vertices.size()); +#endif d_hwBuffer->unlock(); } @@ -377,6 +448,14 @@ void OgreGeometryBuffer::initialiseTextureStates() const using namespace Ogre; d_renderSystem._setTextureCoordCalculation(0, TEXCALC_NONE); d_renderSystem._setTextureCoordSet(0, 0); +#ifdef CEGUI_USE_OGRE_HLMS + d_renderSystem._setTextureMatrix(0, Matrix4::IDENTITY); + d_renderSystem._setTextureBlendMode(0, S_colourBlendMode); + d_renderSystem._setTextureBlendMode(0, S_alphaBlendMode); + d_renderSystem._disableTextureUnitsFrom(1); + + d_renderSystem._setHlmsSamplerblock(0, d_owner.getHlmsSamplerblock()); +#else d_renderSystem._setTextureUnitFiltering(0, FO_LINEAR, FO_LINEAR, FO_POINT); d_renderSystem._setTextureAddressingMode(0, S_textureAddressMode); d_renderSystem._setTextureMatrix(0, Matrix4::IDENTITY); @@ -384,6 +463,7 @@ void OgreGeometryBuffer::initialiseTextureStates() const d_renderSystem._setTextureBlendMode(0, S_colourBlendMode); d_renderSystem._setTextureBlendMode(0, S_alphaBlendMode); d_renderSystem._disableTextureUnitsFrom(1); +#endif } //----------------------------------------------------------------------------// diff --git a/cegui/src/RendererModules/Ogre/RenderTarget.inl b/cegui/src/RendererModules/Ogre/RenderTarget.inl index 5e62d5eda..0c81c22ea 100644 --- a/cegui/src/RendererModules/Ogre/RenderTarget.inl +++ b/cegui/src/RendererModules/Ogre/RenderTarget.inl @@ -44,12 +44,18 @@ OgreRenderTarget::OgreRenderTarget(OgreRenderer& owner, d_renderSystem(rs), d_area(0, 0, 0, 0), d_renderTarget(0), +#ifdef CEGUI_USE_OGRE_COMPOSITOR2 + d_renderTargetUpdated(false), +#else d_viewport(0), +#endif d_matrix(Ogre::Matrix3::ZERO), d_matrixValid(false), - d_viewportValid(false), d_viewDistance(0), - d_ogreViewportDimensions(0, 0, 0, 0) + d_viewportValid(false) +#ifndef CEGUI_USE_OGRE_COMPOSITOR2 + , d_ogreViewportDimensions(0, 0, 0, 0) +#endif { } @@ -57,7 +63,9 @@ OgreRenderTarget::OgreRenderTarget(OgreRenderer& owner, template OgreRenderTarget::~OgreRenderTarget() { +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) delete d_viewport; +#endif } //----------------------------------------------------------------------------// @@ -79,8 +87,10 @@ template void OgreRenderTarget::setArea(const Rectf& area) { d_area = area; +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) setOgreViewportDimensions(area); - +#endif + d_matrixValid = false; RenderTargetEventArgs args(this); @@ -88,6 +98,7 @@ void OgreRenderTarget::setArea(const Rectf& area) } //----------------------------------------------------------------------------// +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) template void OgreRenderTarget::setOgreViewportDimensions(const Rectf& area) { @@ -98,8 +109,10 @@ void OgreRenderTarget::setOgreViewportDimensions(const Rectf& area) d_viewportValid = false; } +#endif //----------------------------------------------------------------------------// +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) template void OgreRenderTarget::updateOgreViewportDimensions( const Ogre::RenderTarget* const rt) @@ -113,6 +126,7 @@ void OgreRenderTarget::updateOgreViewportDimensions( d_ogreViewportDimensions.getHeight() / rt->getHeight()); } } +#endif //----------------------------------------------------------------------------// template @@ -131,9 +145,13 @@ void OgreRenderTarget::activate() if (!d_viewportValid) updateViewport(); +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) d_renderSystem._setViewport(d_viewport); +#endif + d_owner.setProjectionMatrix(d_matrix); d_owner.setViewMatrix(Ogre::Matrix4::IDENTITY); + d_owner.initialiseRenderStateSettings(); } //----------------------------------------------------------------------------// @@ -242,6 +260,7 @@ void OgreRenderTarget::updateMatrix() const template void OgreRenderTarget::updateViewport() { +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) if (!d_viewport) { d_viewport = OGRE_NEW Ogre::Viewport(0, d_renderTarget, 0, 0, 1, 1, 0); @@ -249,6 +268,8 @@ void OgreRenderTarget::updateViewport() } d_viewport->_updateDimensions(); +#endif + d_viewportValid = true; } diff --git a/cegui/src/RendererModules/Ogre/Renderer.cpp b/cegui/src/RendererModules/Ogre/Renderer.cpp index b17e5d03b..d8880c883 100644 --- a/cegui/src/RendererModules/Ogre/Renderer.cpp +++ b/cegui/src/RendererModules/Ogre/Renderer.cpp @@ -47,6 +47,21 @@ #include #include +#ifdef CEGUI_USE_OGRE_COMPOSITOR2 +#include +#include +#include +#include +#include +#include +#include +#endif + +#ifdef CEGUI_USE_OGRE_HLMS +#include +#include +#endif + // Start of CEGUI namespace section namespace CEGUI { @@ -80,6 +95,53 @@ static Ogre::String S_hlsl_ps_source( "}" ); +#ifdef CEGUI_USE_OGRE_HLMS +static Ogre::String S_hlsl_d3d11_vs_source( + "cbuffer MatrixBuffer\n" + "{\n" + " matrix worldViewProjMatrix;\n" + "};\n" + "\n" + "struct VertOut\n" + "{\n" + " float4 pos : SV_Position;\n" + " float4 colour : COLOR;\n" + " float2 texcoord0 : TEXCOORD;\n" + "};\n" + "\n" + "// Vertex shader\n" + "VertOut main(float3 inPos : POSITION, float4 inColour : COLOR, float2 inTexCoord0 : TEXCOORD)\n" + "{\n" + " VertOut output;\n" + "\n" + " output.pos = mul(worldViewProjMatrix, float4(inPos, 1.0));\n" + " output.texcoord0 = inTexCoord0;\n" + " output.colour = inColour;\n" + "\n" + " return output;\n" + "}\n" +); + +static Ogre::String S_hlsl_d3d11_ps_source( + "Texture2D texture0 : register(t0);\n" + "SamplerState textureSamplerState : register(s0);\n" + "\n" + "struct VertOut\n" + "{\n" + " float4 pos : SV_Position;\n" + " float4 colour : COLOR;\n" + " float2 texcoord0 : TEXCOORD;\n" + "};\n" + "\n" + "float4 main(VertOut input) : SV_Target\n" + "{\n" + " float4 colour = texture0.Sample(textureSamplerState, input.texcoord0) * input.colour;\n" + " return colour;\n" + "}\n" + "\n" +); +#endif + static Ogre::String S_glsl_compat_vs_source( "void main(void)" "{" @@ -134,6 +196,25 @@ static Ogre::String S_glsl_core_ps_source( ); //----------------------------------------------------------------------------// +#ifdef CEGUI_USE_OGRE_COMPOSITOR2 +// The new method will be used +// Internal Ogre::RenderQueueListener. This is how the renderer gets notified +// of workspaces that need rendering +static class OgreGUIRenderQueueListener +{ +public: + OgreGUIRenderQueueListener(); + + void setCEGUIRenderEnabled(bool enabled); + bool isCEGUIRenderEnabled() const; + +private: + bool d_enabled; + +} S_frameListener; + + +#else // Use the old method // Internal Ogre::FrameListener based class. This is how we noew hook into the // rendering process (as opposed to render queues previously) static class OgreGUIFrameListener : public Ogre::FrameListener @@ -151,6 +232,7 @@ static class OgreGUIFrameListener : public Ogre::FrameListener } S_frameListener; +#endif //----------------------------------------------------------------------------// //! container type used to hold TextureTargets we create. typedef std::vector TextureTargetList; @@ -170,17 +252,25 @@ struct OgreRenderer_impl : // TODO: should be set to correct value d_maxTextureSize(2048), d_ogreRoot(Ogre::Root::getSingletonPtr()), +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) d_previousVP(0), +#endif +#ifdef CEGUI_USE_OGRE_HLMS + d_renderTarget(0), + d_hlmsMacroblock(0), + d_hlmsBlendblock(0), + d_hlmsSamplerblock(0), +#endif d_activeBlendMode(BM_INVALID), d_makeFrameControlCalls(true), d_useShaders(false), + d_useGLSL(false), + d_useGLSLCore(false), d_worldMatrix(Ogre::Matrix4::IDENTITY), d_viewMatrix(Ogre::Matrix4::IDENTITY), d_projectionMatrix(Ogre::Matrix4::IDENTITY), d_worldViewProjMatrix(Ogre::Matrix4::IDENTITY), - d_combinedMatrixValid(true), - d_useGLSL(false), - d_useGLSLCore(false) + d_combinedMatrixValid(true) {} //! String holding the renderer identification text. @@ -203,10 +293,22 @@ struct OgreRenderer_impl : Ogre::Root* d_ogreRoot; //! Pointer to the render system for Ogre. Ogre::RenderSystem* d_renderSystem; +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) //! Pointer to the previous viewport set in render system. Ogre::Viewport* d_previousVP; //! Previous projection matrix set on render system. Ogre::Matrix4 d_previousProjMatrix; +#endif +#ifdef CEGUI_USE_OGRE_HLMS + //! OGRE render target + Ogre::RenderTarget* d_renderTarget; + //! HLMS block used to set macro parameters + const Ogre::HlmsMacroblock* d_hlmsMacroblock; + //! HLMS block used to set blending parameters + const Ogre::HlmsBlendblock* d_hlmsBlendblock; + //! HLMS block used to set sampling parameters + const Ogre::HlmsSamplerblock* d_hlmsSamplerblock; +#endif //! What we think is the current blend mode to use BlendMode d_activeBlendMode; //! Whether _beginFrame and _endFrame will be called. @@ -235,6 +337,7 @@ String OgreRenderer_impl::d_rendererID( "CEGUI::OgreRenderer - Official OGRE based 2nd generation renderer module."); //----------------------------------------------------------------------------// +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) OgreRenderer& OgreRenderer::bootstrapSystem(const int abi) { System::performVersionTest(CEGUI_VERSION_ABI, abi, CEGUI_FUNCTION_NAME); @@ -250,7 +353,7 @@ OgreRenderer& OgreRenderer::bootstrapSystem(const int abi) return renderer; } - +#endif //----------------------------------------------------------------------------// OgreRenderer& OgreRenderer::bootstrapSystem(Ogre::RenderTarget& target, const int abi) @@ -290,13 +393,14 @@ void OgreRenderer::destroySystem() } //----------------------------------------------------------------------------// +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) OgreRenderer& OgreRenderer::create(const int abi) { System::performVersionTest(CEGUI_VERSION_ABI, abi, CEGUI_FUNCTION_NAME); return *CEGUI_NEW_AO OgreRenderer(); } - +#endif //----------------------------------------------------------------------------// OgreRenderer& OgreRenderer::create(Ogre::RenderTarget& target, const int abi) @@ -538,17 +642,15 @@ bool OgreRenderer::isTextureDefined(const String& name) const //----------------------------------------------------------------------------// void OgreRenderer::beginRendering() { - if ( !d_pimpl->d_previousVP ) - { - d_pimpl->d_previousVP = d_pimpl->d_renderSystem->_getViewport(); - if ( d_pimpl->d_previousVP && d_pimpl->d_previousVP->getCamera() ) - d_pimpl->d_previousProjMatrix = - d_pimpl->d_previousVP->getCamera()->getProjectionMatrixRS(); - } - - //FIXME: ??? - System::getSingleton().getDefaultGUIContext().getRenderTarget().activate(); - initialiseRenderStateSettings(); + #if !defined(CEGUI_USE_OGRE_COMPOSITOR2) + if ( !d_pimpl->d_previousVP ) + { + d_pimpl->d_previousVP = d_pimpl->d_renderSystem->_getViewport(); + if ( d_pimpl->d_previousVP && d_pimpl->d_previousVP->getCamera() ) + d_pimpl->d_previousProjMatrix = + d_pimpl->d_previousVP->getCamera()->getProjectionMatrixRS(); + } + #endif if (d_pimpl->d_makeFrameControlCalls) d_pimpl->d_renderSystem->_beginFrame(); @@ -560,23 +662,22 @@ void OgreRenderer::endRendering() if (d_pimpl->d_makeFrameControlCalls) d_pimpl->d_renderSystem->_endFrame(); - //FIXME: ??? - System::getSingleton().getDefaultGUIContext().getRenderTarget().deactivate(); - - if ( d_pimpl->d_previousVP ) - { - d_pimpl->d_renderSystem->_setViewport(d_pimpl->d_previousVP); - - if ( d_pimpl->d_previousVP->getCamera() ) + #if !defined(CEGUI_USE_OGRE_COMPOSITOR2) + if ( d_pimpl->d_previousVP ) { - d_pimpl->d_renderSystem->_setProjectionMatrix( - d_pimpl->d_previousProjMatrix); - d_pimpl->d_renderSystem->_setViewMatrix( - d_pimpl->d_previousVP->getCamera()->getViewMatrix()); + d_pimpl->d_renderSystem->_setViewport(d_pimpl->d_previousVP); + + if ( d_pimpl->d_previousVP->getCamera() ) + { + d_pimpl->d_renderSystem->_setProjectionMatrix( + d_pimpl->d_previousProjMatrix); + d_pimpl->d_renderSystem->_setViewMatrix( + d_pimpl->d_previousVP->getCamera()->getViewMatrix()); + } + d_pimpl->d_previousVP = 0; + d_pimpl->d_previousProjMatrix = Ogre::Matrix4::IDENTITY; } - d_pimpl->d_previousVP = 0; - d_pimpl->d_previousProjMatrix = Ogre::Matrix4::IDENTITY; - } + #endif } //----------------------------------------------------------------------------// @@ -604,6 +705,7 @@ const String& OgreRenderer::getIdentifierString() const } //----------------------------------------------------------------------------// +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) OgreRenderer::OgreRenderer() : d_pimpl(CEGUI_NEW_AO OgreRenderer_impl()) { @@ -619,6 +721,7 @@ OgreRenderer::OgreRenderer() : constructor_impl(*rwnd); } +#endif //----------------------------------------------------------------------------// OgreRenderer::OgreRenderer(Ogre::RenderTarget& target) : @@ -632,7 +735,9 @@ OgreRenderer::OgreRenderer(Ogre::RenderTarget& target) : //----------------------------------------------------------------------------// OgreRenderer::~OgreRenderer() { +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) d_pimpl->d_ogreRoot->removeFrameListener(&S_frameListener); +#endif cleanupShaders(); @@ -670,18 +775,26 @@ void OgreRenderer::constructor_impl(Ogre::RenderTarget& target) d_pimpl->d_defaultTarget = CEGUI_NEW_AO OgreWindowTarget(*this, *d_pimpl->d_renderSystem, target); +#ifdef CEGUI_USE_OGRE_HLMS + d_pimpl->d_renderTarget = ⌖ +#endif + #if OGRE_VERSION >= 0x10800 + #ifdef CEGUI_USE_OGRE_HLMS + bool isFixedFunctionEnabled = false; // Check if built with RT Shader System and if it is: Check if fixed function pipeline is enabled - #if defined RTSHADER_SYSTEM_BUILD_CORE_SHADERS - bool isFixedFunctionEnabled = d_pimpl->d_renderSystem->getFixedPipelineEnabled(); #else - bool isFixedFunctionEnabled = true; - #endif - - #ifndef RTSHADER_SYSTEM_BUILD_CORE_SHADERS - if (d_pimpl->d_useGLSLCore) - CEGUI_THROW(RendererException("RT Shader System not available but trying to render using OpenGL 3.X+ Core." - "When GLSL shaders are necessary, the RT Shader System component of Ogre is required for rendering CEGUI.")); + #if defined RTSHADER_SYSTEM_BUILD_CORE_SHADERS + bool isFixedFunctionEnabled = d_pimpl->d_renderSystem->getFixedPipelineEnabled(); + #else + bool isFixedFunctionEnabled = true; + #endif + + #ifndef RTSHADER_SYSTEM_BUILD_CORE_SHADERS + if (d_pimpl->d_useGLSLCore) + CEGUI_THROW(RendererException("RT Shader System not available but trying to render using OpenGL 3.X+ Core." + "When GLSL shaders are necessary, the RT Shader System component of Ogre is required for rendering CEGUI.")); + #endif #endif // Default to using shaders when that is the sane thing to do. @@ -691,12 +804,59 @@ void OgreRenderer::constructor_impl(Ogre::RenderTarget& target) #endif // hook into the rendering process +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) d_pimpl->d_ogreRoot->addFrameListener(&S_frameListener); +#endif + } //----------------------------------------------------------------------------// void OgreRenderer::initialiseShaders() { +#ifdef CEGUI_USE_OGRE_HLMS + Ogre::HlmsManager* hlmsManager = d_pimpl->d_ogreRoot->getHlmsManager(); + + // Macro block + Ogre::HlmsMacroblock macroblock; + macroblock.mDepthCheck = false; + macroblock.mDepthWrite = false; + macroblock.mDepthBiasConstant = 0; + macroblock.mDepthBiasSlopeScale = 0; + macroblock.mCullMode = Ogre::CULL_NONE; + macroblock.mPolygonMode = Ogre::PM_SOLID; + macroblock.mScissorTestEnabled = true; + d_pimpl->d_hlmsMacroblock = hlmsManager->getMacroblock(macroblock); + + // Blend block + Ogre::HlmsBlendblock blendblock; + blendblock.mAlphaToCoverageEnabled = false; + if (d_pimpl->d_activeBlendMode == BM_RTT_PREMULTIPLIED) + { + blendblock.mSourceBlendFactor = Ogre::SBF_ONE; + blendblock.mDestBlendFactor = Ogre::SBF_ONE_MINUS_SOURCE_ALPHA; + } + else + { + blendblock.mSeparateBlend = true; + blendblock.mSourceBlendFactor = Ogre::SBF_SOURCE_ALPHA; + blendblock.mDestBlendFactor = Ogre::SBF_ONE_MINUS_SOURCE_ALPHA; + blendblock.mSourceBlendFactorAlpha = Ogre::SBF_ONE_MINUS_DEST_ALPHA; + blendblock.mDestBlendFactorAlpha = Ogre::SBF_ONE; + } + d_pimpl->d_hlmsBlendblock = hlmsManager->getBlendblock(blendblock); + + // Sampler block + Ogre::HlmsSamplerblock samplerblock; + samplerblock.mMinFilter = Ogre::FO_LINEAR; + samplerblock.mMagFilter = Ogre::FO_LINEAR; + samplerblock.mMipFilter = Ogre::FO_POINT; + samplerblock.mU = Ogre::TAM_CLAMP; + samplerblock.mV = Ogre::TAM_CLAMP; + samplerblock.mW = Ogre::TAM_CLAMP; + samplerblock.mCompareFunction = Ogre::NUM_COMPARE_FUNCTIONS; + d_pimpl->d_hlmsSamplerblock = hlmsManager->getSamplerblock(samplerblock); +#endif + d_pimpl->d_useGLSL = Ogre::HighLevelGpuProgramManager::getSingleton(). isLanguageSupported("glsl"); @@ -737,6 +897,10 @@ void OgreRenderer::initialiseShaders() } else // else we use a hlsl shader with an available syntax code { +#ifdef CEGUI_USE_OGRE_HLMS + d_pimpl->d_vertexShader->setParameter("target", "vs_4_1"); + d_pimpl->d_vertexShader->setSource(S_hlsl_d3d11_vs_source); +#else if (Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("vs_4_0")) { d_pimpl->d_vertexShader->setParameter("target", "vs_4_0"); @@ -754,6 +918,7 @@ void OgreRenderer::initialiseShaders() "OgreRenderer::initialiseShaders: No supported syntax - " "unable to compile '__cegui_internal_vs__'")); } +#endif } d_pimpl->d_vertexShader->load(); @@ -783,6 +948,10 @@ void OgreRenderer::initialiseShaders() else { // D3D shaders +#ifdef CEGUI_USE_OGRE_HLMS + d_pimpl->d_pixelShader->setParameter("target", "ps_4_1"); + d_pimpl->d_pixelShader->setSource(S_hlsl_d3d11_ps_source); +#else if (Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("ps_4_0")) { d_pimpl->d_pixelShader->setParameter("target", "ps_4_0"); @@ -802,6 +971,7 @@ void OgreRenderer::initialiseShaders() "OgreRenderer::initialiseShaders: No supported syntax - " "unable to compile '__cegui_internal_ps__'")); } +#endif } d_pimpl->d_pixelShader->load(); @@ -816,6 +986,16 @@ void OgreRenderer::initialiseShaders() //----------------------------------------------------------------------------// void OgreRenderer::cleanupShaders() { +#ifdef CEGUI_USE_OGRE_HLMS + Ogre::HlmsManager* hlmsManager = d_pimpl->d_ogreRoot->getHlmsManager(); + + if (d_pimpl->d_hlmsBlendblock != NULL) + hlmsManager->destroyBlendblock(d_pimpl->d_hlmsBlendblock); + if (d_pimpl->d_hlmsMacroblock != NULL) + hlmsManager->destroyMacroblock(d_pimpl->d_hlmsMacroblock); + if (d_pimpl->d_hlmsSamplerblock != NULL) + hlmsManager->destroySamplerblock(d_pimpl->d_hlmsSamplerblock); +#endif d_pimpl->d_pixelShaderParameters.setNull(); d_pimpl->d_vertexShaderParameters.setNull(); d_pimpl->d_pixelShader.setNull(); @@ -849,6 +1029,10 @@ void OgreRenderer::setupRenderingBlendMode(const BlendMode mode, d_pimpl->d_activeBlendMode = mode; +#ifdef CEGUI_USE_OGRE_HLMS + // Apply the HLMS blend block to the render system + d_pimpl->d_renderSystem->_setHlmsBlendblock(d_pimpl->d_hlmsBlendblock); +#else if (d_pimpl->d_activeBlendMode == BM_RTT_PREMULTIPLIED) d_pimpl->d_renderSystem->_setSceneBlending(SBF_ONE, SBF_ONE_MINUS_SOURCE_ALPHA); @@ -858,6 +1042,7 @@ void OgreRenderer::setupRenderingBlendMode(const BlendMode mode, SBF_ONE_MINUS_SOURCE_ALPHA, SBF_ONE_MINUS_DEST_ALPHA, SBF_ONE); +#endif } @@ -884,6 +1069,10 @@ void OgreRenderer::initialiseRenderStateSettings() using namespace Ogre; // initialise render settings +#ifdef CEGUI_USE_OGRE_HLMS + // Apply the HLMS macro block to the render system + d_pimpl->d_renderSystem->_setHlmsMacroblock(d_pimpl->d_hlmsMacroblock); +#else d_pimpl->d_renderSystem->setLightingEnabled(false); d_pimpl->d_renderSystem->_setDepthBufferParams(false, false); d_pimpl->d_renderSystem->_setDepthBias(0, 0); @@ -892,6 +1081,7 @@ void OgreRenderer::initialiseRenderStateSettings() d_pimpl->d_renderSystem->_setColourBufferWriteEnabled(true, true, true, true); d_pimpl->d_renderSystem->setShadingType(SO_GOURAUD); d_pimpl->d_renderSystem->_setPolygonMode(PM_SOLID); +#endif bindShaders(); @@ -910,11 +1100,18 @@ void OgreRenderer::bindShaders() { if (isUsingShaders()) { +#ifdef CEGUI_USE_OGRE_HLMS + Ogre::HlmsCache hlmsCache; + hlmsCache.vertexShader = d_pimpl->d_vertexShader; + hlmsCache.pixelShader = d_pimpl->d_pixelShader; + d_pimpl->d_renderSystem->_setProgramsFromHlms(&hlmsCache); +#else if (Ogre::GpuProgram* prog = d_pimpl->d_vertexShader->_getBindingDelegate()) d_pimpl->d_renderSystem->bindGpuProgram(prog); if (Ogre::GpuProgram* prog = d_pimpl->d_pixelShader->_getBindingDelegate()) d_pimpl->d_renderSystem->bindGpuProgram(prog); +#endif } else { @@ -989,8 +1186,12 @@ const Ogre::Matrix4& OgreRenderer::getWorldViewProjMatrix() const { Ogre::Matrix4 final_prj(d_pimpl->d_projectionMatrix); +#ifdef CEGUI_USE_OGRE_HLMS + if (d_pimpl->d_renderTarget->requiresTextureFlipping()) +#else if (d_pimpl->d_renderSystem->_getViewport()->getTarget()-> requiresTextureFlipping()) +#endif { final_prj[1][0] = -final_prj[1][0]; final_prj[1][1] = -final_prj[1][1]; @@ -1053,6 +1254,41 @@ void OgreRenderer::setProjectionMatrix(const Ogre::Matrix4& m) } //----------------------------------------------------------------------------// +#ifdef CEGUI_USE_OGRE_HLMS +Ogre::RenderTarget* OgreRenderer::getOgreRenderTarget() +{ + return d_pimpl->d_renderTarget; +} + +//----------------------------------------------------------------------------// +const Ogre::HlmsSamplerblock* OgreRenderer::getHlmsSamplerblock() +{ + return d_pimpl->d_hlmsSamplerblock; +} +#endif + +//----------------------------------------------------------------------------// +#ifdef CEGUI_USE_OGRE_COMPOSITOR2 +OgreGUIRenderQueueListener::OgreGUIRenderQueueListener() : d_enabled(true) +{ + +} + +//----------------------------------------------------------------------------// +void OgreGUIRenderQueueListener::setCEGUIRenderEnabled(bool enabled) +{ + d_enabled = enabled; +} + +//----------------------------------------------------------------------------// +bool OgreGUIRenderQueueListener::isCEGUIRenderEnabled() const +{ + return d_enabled; +} + +//----------------------------------------------------------------------------// + +#else OgreGUIFrameListener::OgreGUIFrameListener() : d_enabled(true) { @@ -1078,5 +1314,6 @@ bool OgreGUIFrameListener::frameRenderingQueued(const Ogre::FrameEvent&) return true; } +#endif } // End of CEGUI namespace section diff --git a/cegui/src/RendererModules/Ogre/TextureTarget.cpp b/cegui/src/RendererModules/Ogre/TextureTarget.cpp index 0387baaa4..2bae391f2 100644 --- a/cegui/src/RendererModules/Ogre/TextureTarget.cpp +++ b/cegui/src/RendererModules/Ogre/TextureTarget.cpp @@ -72,7 +72,7 @@ void OgreTextureTarget::clear() { if (!d_viewportValid) updateViewport(); - +#if !defined(CEGUI_USE_OGRE_COMPOSITOR2) Ogre::Viewport* const saved_vp = d_renderSystem._getViewport(); d_renderSystem._setViewport(d_viewport); @@ -85,6 +85,8 @@ void OgreTextureTarget::clear() #else d_renderSystem._setViewport(saved_vp); #endif +#endif + } //----------------------------------------------------------------------------// @@ -115,10 +117,17 @@ void OgreTextureTarget::declareRenderSize(const Sizef& sz) setArea(init_area); +#ifdef CEGUI_USE_OGRE_COMPOSITOR2 + // Setting this should properly change everything + d_renderTargetUpdated = true; +#else // delete viewport and reset ptr so a new one is generated. This is // required because we have changed d_renderTarget so need a new VP also. OGRE_DELETE d_viewport; d_viewport = 0; +#endif + + // because Texture takes ownership, the act of setting the new ogre texture // also ensures any previous ogre texture is released. diff --git a/cegui/src/RendererModules/Ogre/WindowTarget.cpp b/cegui/src/RendererModules/Ogre/WindowTarget.cpp index d2aaa375f..c262f58ad 100644 --- a/cegui/src/RendererModules/Ogre/WindowTarget.cpp +++ b/cegui/src/RendererModules/Ogre/WindowTarget.cpp @@ -49,10 +49,16 @@ OgreWindowTarget::~OgreWindowTarget() //----------------------------------------------------------------------------// void OgreWindowTarget::setOgreRenderTarget(Ogre::RenderTarget& target) { +#ifdef CEGUI_USE_OGRE_COMPOSITOR2 + // Setting this should properly change everything + d_renderTargetUpdated = true; +#else // cleanup viewport since it's RT dependent. OGRE_DELETE d_viewport; d_viewport = 0; d_viewportValid = false; +#endif + initRenderTarget(target); } diff --git a/cegui/src/RendererModules/OpenGL/ApplePBTextureTarget.cpp b/cegui/src/RendererModules/OpenGL/ApplePBTextureTarget.cpp index 1d5f1ff54..1a1d00b8a 100644 --- a/cegui/src/RendererModules/OpenGL/ApplePBTextureTarget.cpp +++ b/cegui/src/RendererModules/OpenGL/ApplePBTextureTarget.cpp @@ -24,7 +24,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include "GL/glew.h" +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "CEGUI/RendererModules/OpenGL/ApplePBTextureTarget.h" #include "CEGUI/Exceptions.h" #include "CEGUI/RenderQueue.h" diff --git a/cegui/src/RendererModules/OpenGL/CMakeLists.txt b/cegui/src/RendererModules/OpenGL/CMakeLists.txt index 7440caf0a..518e263ca 100644 --- a/cegui/src/RendererModules/OpenGL/CMakeLists.txt +++ b/cegui/src/RendererModules/OpenGL/CMakeLists.txt @@ -2,6 +2,10 @@ set (CEGUI_TARGET_NAME ${CEGUI_OPENGL_RENDERER_LIBNAME}) cegui_gather_files() +if (CEGUI_BUILD_SHARED_LIBS_WITH_STATIC_DEPENDENCIES AND CEGUI_USE_GLEW) + add_definitions( -DGLEW_STATIC ) +endif() + if (NOT APPLE OR NOT CEGUI_BUILD_RENDERER_OPENGL) list (REMOVE_ITEM CORE_SOURCE_FILES ApplePBTextureTarget.cpp) list (REMOVE_ITEM CORE_HEADER_FILES ${CMAKE_SOURCE_DIR}/cegui/include/CEGUI/RendererModules/OpenGL/ApplePBTextureTarget.h) @@ -44,9 +48,14 @@ if (NOT CEGUI_BUILD_RENDERER_OPENGL3) endif() cegui_add_library(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} OPENGL) -cegui_add_dependency(${CEGUI_TARGET_NAME} GLM) -cegui_add_dependency(${CEGUI_TARGET_NAME} GLEW) +if (${CEGUI_USE_EPOXY}) + cegui_add_dependency(${CEGUI_TARGET_NAME} GLM PRIVATE TRUE) + cegui_add_dependency(${CEGUI_TARGET_NAME} EPOXY PRIVATE TRUE) +elseif (${CEGUI_USE_GLEW}) + cegui_add_dependency(${CEGUI_TARGET_NAME} OPENGL PRIVATE TRUE) + cegui_add_dependency(${CEGUI_TARGET_NAME} GLM PRIVATE TRUE) + cegui_add_dependency(${CEGUI_TARGET_NAME} GLEW PRIVATE TRUE) +endif () cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/RendererModules/OpenGL/GL.cpp b/cegui/src/RendererModules/OpenGL/GL.cpp new file mode 100644 index 000000000..4b34716d0 --- /dev/null +++ b/cegui/src/RendererModules/OpenGL/GL.cpp @@ -0,0 +1,163 @@ +/*********************************************************************** + created: 21/7/2015 + author: Yaron Cohen-Tal +*************************************************************************/ +/*************************************************************************** + * Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + ***************************************************************************/ +#include "CEGUI/RendererModules/OpenGL/GL.h" +#include "CEGUI/String.h" +#include "CEGUI/Exceptions.h" + +#if defined CEGUI_USE_GLEW +#include +#include +#endif + +namespace CEGUI +{ + +OpenGLInfo OpenGLInfo::s_instance; + +//----------------------------------------------------------------------------// +OpenGLInfo::OpenGLInfo() : + d_type(TYPE_NONE), + d_verMajor(-1), + d_verMinor(-1), + d_verMajorForce(-1), + d_verMinorForce(-1), + d_isS3tcSupported(false), + d_isNpotTextureSupported(false), + d_isReadBufferSupported(false), + d_isPolygonModeSupported(false), + d_isSeperateReadAndDrawFramebufferSupported(false), + d_isVaoSupported(false), + d_isSizedInternalFormatSupported(false) +{ +} + +//----------------------------------------------------------------------------// +void OpenGLInfo::init() +{ + initTypeAndVer(); + initSupportedFeatures(); +} + +void OpenGLInfo::verForce(GLint verMajor_, GLint verMinor_) +{ + d_verMajorForce = verMajor_; + d_verMinorForce = verMinor_; +} + +//----------------------------------------------------------------------------// +void OpenGLInfo::initTypeAndVer() +{ +#if defined CEGUI_USE_EPOXY + d_type = epoxy_is_desktop_gl() ? TYPE_DESKTOP : TYPE_ES; + if (d_verMajorForce >= 0) + { + d_verMajor = d_verMajorForce; + d_verMinor = d_verMinorForce; + } + else + { + int ver(epoxy_gl_version()); + if (!ver) + { + if (isUsingDesktopOpengl()) + CEGUI_THROW(RendererException + ("Failed to obtain desktop OpenGL version.")); + else + CEGUI_THROW(RendererException + ("Failed to obtain OpenGL ES version.")); + } + d_verMajor = ver / 10; + d_verMinor = ver % 10; + } +#elif defined CEGUI_USE_GLEW + d_type = TYPE_DESKTOP; + glGetError (); + d_verMajor = d_verMinor = -1; +#endif +} + +//----------------------------------------------------------------------------// +void OpenGLInfo::initSupportedFeatures() +{ + +#if defined CEGUI_USE_EPOXY + + d_isS3tcSupported = epoxy_has_gl_extension("GL_EXT_texture_compression_s3tc"); + d_isNpotTextureSupported = + (isUsingDesktopOpengl() && verMajor() >= 2) + || (isUsingOpenglEs() && verMajor() >= 3) + || epoxy_has_gl_extension("GL_ARB_texture_non_power_of_two"); + d_isReadBufferSupported = d_isSizedInternalFormatSupported = + (isUsingDesktopOpengl() && verAtLeast(1, 3)) + || (isUsingOpenglEs() && verMajor() >= 3); + d_isPolygonModeSupported = isUsingDesktopOpengl() && verAtLeast(1, 3); + d_isSeperateReadAndDrawFramebufferSupported = + (isUsingDesktopOpengl() && verAtLeast(3, 1)) + || (isUsingOpenglEs() && verMajor() >= 3); + d_isVaoSupported = (isUsingDesktopOpengl() && verAtLeast(3, 2)) + || (isUsingOpenglEs() && verMajor() >= 3); + +#elif defined CEGUI_USE_GLEW + + d_isS3tcSupported = false; + glGetError(); + + // Why do we do this and not use GLEW_EXT_texture_compression_s3tc? + // Because of glewExperimental, of course! + int ext_count; + glGetIntegerv(GL_NUM_EXTENSIONS, &ext_count); + if ((glGetError() == GL_NO_ERROR) && + (ext_count >= 0) && + glGetStringi) + { + for (int i = 0; i < ext_count; ++i) + { + const char* extension + (reinterpret_cast(glGetStringi(GL_EXTENSIONS, i))); + if ((glGetError() == GL_NO_ERROR) && + extension && + !std::strcmp(extension, "GL_EXT_texture_compression_s3tc")) + { + d_isS3tcSupported = true; + break; + } + } + } + + d_isNpotTextureSupported = + (GLEW_VERSION_2_0 == GL_TRUE) + || (GLEW_ARB_texture_non_power_of_two == GL_TRUE); + d_isPolygonModeSupported = d_isSizedInternalFormatSupported + = (GLEW_VERSION_1_3 == GL_TRUE); + d_isSeperateReadAndDrawFramebufferSupported = (GLEW_VERSION_3_1 == GL_TRUE); + d_isVaoSupported = (GLEW_VERSION_3_2 == GL_TRUE); + +#endif + +} + +} // namespace CEGUI diff --git a/cegui/src/RendererModules/OpenGL/GL3FBOTextureTarget.cpp b/cegui/src/RendererModules/OpenGL/GL3FBOTextureTarget.cpp index 9bbf05b8e..f0777b05c 100644 --- a/cegui/src/RendererModules/OpenGL/GL3FBOTextureTarget.cpp +++ b/cegui/src/RendererModules/OpenGL/GL3FBOTextureTarget.cpp @@ -24,8 +24,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include - +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "CEGUI/RendererModules/OpenGL/GL3FBOTextureTarget.h" #include "CEGUI/Exceptions.h" #include "CEGUI/RenderQueue.h" @@ -134,10 +133,17 @@ void OpenGL3FBOTextureTarget::initialiseRenderTexture() // create FBO glGenFramebuffers(1, &d_frameBuffer); - // remember previously bound FBO to make sure we set it back - GLuint previousFBO = 0; - glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, - reinterpret_cast(&previousFBO)); + // remember previously bound FBO-s to make sure we set them back + GLint previousFBO_read(-1), previousFBO_draw(-1), previousFBO(-1); + if (OpenGLInfo::getSingleton().isSeperateReadAndDrawFramebufferSupported()) + { + glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &previousFBO_read); + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &previousFBO_draw); + } + else + glGetIntegerv(OpenGLInfo::getSingleton().isUsingOpenglEs() ? + GL_FRAMEBUFFER_BINDING : GL_FRAMEBUFFER_BINDING_EXT, + &previousFBO); glBindFramebuffer(GL_FRAMEBUFFER, d_frameBuffer); @@ -146,7 +152,12 @@ void OpenGL3FBOTextureTarget::initialiseRenderTexture() glBindTexture(GL_TEXTURE_2D, d_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glTexImage2D(GL_TEXTURE_2D, 0, + OpenGLInfo::getSingleton().isSizedInternalFormatSupported() ? + GL_RGBA8 : GL_RGBA, static_cast(DEFAULT_SIZE), static_cast(DEFAULT_SIZE), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); @@ -156,8 +167,14 @@ void OpenGL3FBOTextureTarget::initialiseRenderTexture() //Check for framebuffer completeness checkFramebufferStatus(); - // switch from our frame buffer back to the previously bound buffer. - glBindFramebuffer(GL_FRAMEBUFFER, previousFBO); + // switch from our frame buffers back to the previously bound buffers. + if (OpenGLInfo::getSingleton().isSeperateReadAndDrawFramebufferSupported()) + { + glBindFramebuffer(GL_READ_FRAMEBUFFER, static_cast(previousFBO_read)); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, static_cast(previousFBO_draw)); + } + else + glBindFramebuffer(GL_FRAMEBUFFER, static_cast(previousFBO)); // ensure the CEGUI::Texture is wrapping the gl texture and has correct size d_CEGUITexture->setOpenGLTexture(d_texture, d_area.getSize()); @@ -186,7 +203,10 @@ void OpenGL3FBOTextureTarget::resizeRenderTexture() // set the texture to the required size glBindTexture(GL_TEXTURE_2D, d_texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, + + glTexImage2D(GL_TEXTURE_2D, 0, + OpenGLInfo::getSingleton().isSizedInternalFormatSupported() ? + GL_RGBA8 : GL_RGBA, static_cast(sz.d_width), static_cast(sz.d_height), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); diff --git a/cegui/src/RendererModules/OpenGL/GL3GeometryBuffer.cpp b/cegui/src/RendererModules/OpenGL/GL3GeometryBuffer.cpp index 5688d877b..646909d65 100644 --- a/cegui/src/RendererModules/OpenGL/GL3GeometryBuffer.cpp +++ b/cegui/src/RendererModules/OpenGL/GL3GeometryBuffer.cpp @@ -24,8 +24,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include - +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "glm/glm.hpp" #include "glm/gtc/quaternion.hpp" #include "glm/gtc/type_ptr.hpp" @@ -86,8 +85,17 @@ void OpenGL3GeometryBuffer::draw() const // activate desired blending mode d_owner->setupRenderingBlendMode(d_blendMode); - // Bind our vao - d_glStateChanger->bindVertexArray(d_verticesVAO); + if (OpenGLInfo::getSingleton().isVaoSupported()) + { + // Bind our vao + d_glStateChanger->bindVertexArray(d_verticesVAO); + } + else + { + // We need to emulate a VAO. + // This binds and sets up a vbo for rendering + configureVertexArray(); + } const int pass_count = d_effect ? d_effect->getPassCount() : 1; size_t pos = 0; @@ -142,41 +150,50 @@ void OpenGL3GeometryBuffer::reset() //----------------------------------------------------------------------------// void OpenGL3GeometryBuffer::initialiseOpenGLBuffers() { - glGenVertexArrays(1, &d_verticesVAO); - glBindVertexArray(d_verticesVAO); + if (OpenGLInfo::getSingleton().isVaoSupported()) + { + glGenVertexArrays(1, &d_verticesVAO); + glBindVertexArray(d_verticesVAO); + } - // Generate and bind position vbo + // Generate position vbo glGenBuffers(1, &d_verticesVBO); - glBindBuffer(GL_ARRAY_BUFFER, d_verticesVBO); + // This binds and sets up a vbo. The + configureVertexArray(); glBufferData(GL_ARRAY_BUFFER, 0, 0, GL_DYNAMIC_DRAW); - d_shader->bind(); - - GLsizei stride = 9 * sizeof(GL_FLOAT); + if (OpenGLInfo::getSingleton().isVaoSupported()) + { + // Unbind Vertex Attribute Array (VAO) + glBindVertexArray(0); + } + + // Unbind array and element array buffers + glBindBuffer(GL_ARRAY_BUFFER, 0); +} + +//----------------------------------------------------------------------------// +void OpenGL3GeometryBuffer::configureVertexArray() const +{ + glBindBuffer(GL_ARRAY_BUFFER, d_verticesVBO); + GLsizei stride = 9 * sizeof(GLfloat); glVertexAttribPointer(d_shaderTexCoordLoc, 2, GL_FLOAT, GL_FALSE, stride, 0); glEnableVertexAttribArray(d_shaderTexCoordLoc); - glVertexAttribPointer(d_shaderColourLoc, 4, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(2 * sizeof(GL_FLOAT))); + glVertexAttribPointer(d_shaderColourLoc, 4, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(2 * sizeof(GLfloat))); glEnableVertexAttribArray(d_shaderColourLoc); - glVertexAttribPointer(d_shaderPosLoc, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(6 * sizeof(GL_FLOAT))); + glVertexAttribPointer(d_shaderPosLoc, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(6 * sizeof(GLfloat))); glEnableVertexAttribArray(d_shaderPosLoc); - - d_shader->unbind(); - - // Unbind Vertex Attribute Array (VAO) - glBindVertexArray(0); - - // Unbind array and element array buffers - glBindBuffer(GL_ARRAY_BUFFER, 0); } //----------------------------------------------------------------------------// void OpenGL3GeometryBuffer::deinitialiseOpenGLBuffers() { - glDeleteVertexArrays(1, &d_verticesVAO); + if (OpenGLInfo::getSingleton().isVaoSupported()) + glDeleteVertexArrays(1, &d_verticesVAO); glDeleteBuffers(1, &d_verticesVBO); } diff --git a/cegui/src/RendererModules/OpenGL/GL3Renderer.cpp b/cegui/src/RendererModules/OpenGL/GL3Renderer.cpp index 8197518ba..9b607253a 100644 --- a/cegui/src/RendererModules/OpenGL/GL3Renderer.cpp +++ b/cegui/src/RendererModules/OpenGL/GL3Renderer.cpp @@ -24,8 +24,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include - +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "CEGUI/RendererModules/OpenGL/ShaderManager.h" #include "CEGUI/RendererModules/OpenGL/GL3Renderer.h" #include "CEGUI/RendererModules/OpenGL/Texture.h" @@ -42,9 +41,7 @@ #include "CEGUI/Logger.h" #include "CEGUI/RendererModules/OpenGL/StateChangeWrapper.h" -#include #include -#include // Start of CEGUI namespace section namespace CEGUI @@ -60,8 +57,6 @@ namespace CEGUI #ifndef APIENTRY # define APIENTRY #endif -//! Dummy function for if real ones are not present (saves testing each render) -static void APIENTRY activeTextureDummy(GLenum) {} //----------------------------------------------------------------------------// // template specialised class that does the real work for us @@ -147,31 +142,37 @@ void OpenGL3Renderer::destroy(OpenGL3Renderer& renderer) //----------------------------------------------------------------------------// OpenGL3Renderer::OpenGL3Renderer() : + OpenGLRendererBase(true), d_shaderStandard(0), d_openGLStateChanger(0), d_shaderManager(0) { - initialiseRendererIDString(); - initialiseGLExtensions(); - initialiseTextureTargetFactory(); - initialiseOpenGLShaders(); - - d_openGLStateChanger = CEGUI_NEW_AO OpenGL3StateChangeWrapper(*this); + init(); + CEGUI_UNUSED(d_s3tcSupported); + // d_s3tcSupported is unused, but must be preserved to avoid breaking ABI } //----------------------------------------------------------------------------// OpenGL3Renderer::OpenGL3Renderer(const Sizef& display_size) : - OpenGLRendererBase(display_size), + OpenGLRendererBase(display_size, true), d_shaderStandard(0), d_openGLStateChanger(0), d_shaderManager(0) { + init(); +} + +//----------------------------------------------------------------------------// +void OpenGL3Renderer::init() +{ + if ( OpenGLInfo::getSingleton().isUsingOpenglEs() + && OpenGLInfo::getSingleton().verMajor() < 2) + CEGUI_THROW(RendererException("Only version 2 and up of OpenGL ES is " + "supported by this type of renderer.")); initialiseRendererIDString(); - initialiseGLExtensions(); initialiseTextureTargetFactory(); initialiseOpenGLShaders(); - - d_openGLStateChanger = CEGUI_NEW_AO OpenGL3StateChangeWrapper(*this); + d_openGLStateChanger = CEGUI_NEW_AO OpenGL3StateChangeWrapper(); } //----------------------------------------------------------------------------// @@ -185,9 +186,10 @@ OpenGL3Renderer::~OpenGL3Renderer() //----------------------------------------------------------------------------// void OpenGL3Renderer::initialiseRendererIDString() { - d_rendererID = - "CEGUI::OpenGL3Renderer - Official OpenGL 3.2 core based " - "renderer module."; + d_rendererID = OpenGLInfo::getSingleton().isUsingDesktopOpengl() + ? "CEGUI::OpenGL3Renderer - Official OpenGL 3.2 core based " + "renderer module." + : "CEGUI::OpenGL3Renderer - OpenGL ES 2 renderer module."; } //----------------------------------------------------------------------------// OpenGLGeometryBufferBase* OpenGL3Renderer::createGeometryBuffer_impl() @@ -204,41 +206,57 @@ TextureTarget* OpenGL3Renderer::createTextureTarget_impl() //----------------------------------------------------------------------------// void OpenGL3Renderer::beginRendering() { - // do required set-up. yes, it really is this minimal ;) - glEnable(GL_SCISSOR_TEST); - glEnable(GL_BLEND); + // Deprecated OpenGL 2 client states may mess up rendering. They are not added here + // since they are deprecated and thus do not fit in a OpenGL Core renderer. However + // this information may be relevant for people combining deprecated and modern + // functions. In that case disable client states like this: glDisableClientState(GL_VERTEX_ARRAY); - // force set blending ops to get to a known state. - setupRenderingBlendMode(BM_NORMAL, true); + d_openGLStateChanger->reset(); // if enabled, restores a subset of the GL state back to default values. if (d_initExtraStates) setupExtraStates(); - d_shaderStandard->bind(); + glEnable(GL_SCISSOR_TEST); + glEnable(GL_BLEND); - d_openGLStateChanger->reset(); + // force set blending ops to get to a known state. + setupRenderingBlendMode(BM_NORMAL, true); + + d_shaderStandard->bind(); } //----------------------------------------------------------------------------// void OpenGL3Renderer::endRendering() { - d_shaderStandard->unbind(); + glUseProgram(0); + + if (d_initExtraStates) + setupExtraStates(); + + glDisable(GL_BLEND); + glDisable(GL_SCISSOR_TEST); } //----------------------------------------------------------------------------// void OpenGL3Renderer::setupExtraStates() { glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, 0); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + if (OpenGLInfo::getSingleton().isPolygonModeSupported()) + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); + + d_openGLStateChanger->blendFunc(GL_ONE, GL_ZERO); + if (OpenGLInfo::getSingleton().isVaoSupported()) + d_openGLStateChanger->bindVertexArray(0); glUseProgram(0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glBindBuffer(GL_ARRAY_BUFFER, 0); + d_openGLStateChanger->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + d_openGLStateChanger->bindBuffer(GL_ARRAY_BUFFER, 0); } //----------------------------------------------------------------------------// @@ -330,44 +348,10 @@ void OpenGL3Renderer::initialiseOpenGLShaders() d_shaderStandardMatrixLoc = d_shaderStandard->getUniformLocation("modelViewPerspMatrix"); } -//----------------------------------------------------------------------------// -void OpenGL3Renderer::initialiseGLExtensions() -{ - glewExperimental = GL_TRUE; - - GLenum err = glewInit(); - if(err != GLEW_OK) - { - std::ostringstream err_string; - //Problem: glewInit failed, something is seriously wrong. - err_string << "failed to initialise the GLEW library. " - << glewGetErrorString(err); - - CEGUI_THROW(RendererException(err_string.str().c_str())); - } - //Clear the useless error glew produces as of version 1.7.0, when using OGL3.2 Core Profile - glGetError(); - - // Why do we do this and not use GLEW_EXT_texture_compression_s3tc? - // Because of glewExperimental, of course! - int ext_count; - glGetIntegerv(GL_NUM_EXTENSIONS, &ext_count); - for(int i = 0; i < ext_count; ++i) - { - if (!std::strcmp( - reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)), - "GL_EXT_texture_compression_s3tc")) - { - d_s3tcSupported = true; - break; - } - } -} - //----------------------------------------------------------------------------// bool OpenGL3Renderer::isS3TCSupported() const { - return d_s3tcSupported; + return OpenGLInfo::getSingleton().isS3tcSupported(); } //----------------------------------------------------------------------------// diff --git a/cegui/src/RendererModules/OpenGL/GLFBOTextureTarget.cpp b/cegui/src/RendererModules/OpenGL/GLFBOTextureTarget.cpp index df6d530bd..3e2e74348 100644 --- a/cegui/src/RendererModules/OpenGL/GLFBOTextureTarget.cpp +++ b/cegui/src/RendererModules/OpenGL/GLFBOTextureTarget.cpp @@ -24,7 +24,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "CEGUI/RendererModules/OpenGL/GLFBOTextureTarget.h" #include "CEGUI/Exceptions.h" #include "CEGUI/RenderQueue.h" diff --git a/cegui/src/RendererModules/OpenGL/GLGeometryBuffer.cpp b/cegui/src/RendererModules/OpenGL/GLGeometryBuffer.cpp index 5bb32284c..437042deb 100644 --- a/cegui/src/RendererModules/OpenGL/GLGeometryBuffer.cpp +++ b/cegui/src/RendererModules/OpenGL/GLGeometryBuffer.cpp @@ -25,7 +25,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "CEGUI/RendererModules/OpenGL/GLGeometryBuffer.h" #include "CEGUI/RendererModules/OpenGL/GLRenderer.h" #include "CEGUI/RenderEffect.h" diff --git a/cegui/src/RendererModules/OpenGL/GLRenderer.cpp b/cegui/src/RendererModules/OpenGL/GLRenderer.cpp index aa488f83d..fa48a1bc0 100644 --- a/cegui/src/RendererModules/OpenGL/GLRenderer.cpp +++ b/cegui/src/RendererModules/OpenGL/GLRenderer.cpp @@ -25,8 +25,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include - +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "CEGUI/RendererModules/OpenGL/GLRenderer.h" #include "CEGUI/RendererModules/OpenGL/Texture.h" #include "CEGUI/Exceptions.h" @@ -163,7 +162,8 @@ void OpenGLRenderer::destroy(OpenGLRenderer& renderer) } //----------------------------------------------------------------------------// -OpenGLRenderer::OpenGLRenderer(const TextureTargetType tt_type) +OpenGLRenderer::OpenGLRenderer(const TextureTargetType tt_type) : + OpenGLRendererBase(false) { initialiseRendererIDString(); initialiseGLExtensions(); @@ -179,7 +179,7 @@ OpenGLRenderer::OpenGLRenderer(const TextureTargetType tt_type) //----------------------------------------------------------------------------// OpenGLRenderer::OpenGLRenderer(const Sizef& display_size, const TextureTargetType tt_type) : - OpenGLRendererBase(display_size) + OpenGLRendererBase(display_size, false) { initialiseRendererIDString(); initialiseGLExtensions(); @@ -386,17 +386,6 @@ void OpenGLRenderer::setupRenderingBlendMode(const BlendMode mode, //----------------------------------------------------------------------------// void OpenGLRenderer::initialiseGLExtensions() { - // initialise GLEW - GLenum err = glewInit(); - if (GLEW_OK != err) - { - std::ostringstream err_string; - err_string << "OpenGLRenderer failed to initialise the GLEW library. " - << glewGetErrorString(err); - - CEGUI_THROW(RendererException(err_string.str().c_str())); - } - // GL 1.3 has multi-texture support natively if (GLEW_VERSION_1_3) { @@ -420,7 +409,7 @@ void OpenGLRenderer::initialiseGLExtensions() //----------------------------------------------------------------------------// bool OpenGLRenderer::isS3TCSupported() const { - return GLEW_EXT_texture_compression_s3tc > 0; + return OpenGLInfo::getSingleton().isS3tcSupported(); } //----------------------------------------------------------------------------// diff --git a/cegui/src/RendererModules/OpenGL/GLXPBTextureTarget.cpp b/cegui/src/RendererModules/OpenGL/GLXPBTextureTarget.cpp index cd9f36127..23e6b3683 100644 --- a/cegui/src/RendererModules/OpenGL/GLXPBTextureTarget.cpp +++ b/cegui/src/RendererModules/OpenGL/GLXPBTextureTarget.cpp @@ -157,8 +157,8 @@ void OpenGLGLXPBTextureTarget::initialisePBuffer() { int creation_attrs[] = { - GLX_PBUFFER_WIDTH, d_area.getWidth(), - GLX_PBUFFER_HEIGHT, d_area.getHeight(), + GLX_PBUFFER_WIDTH, static_cast(d_area.getWidth()), + GLX_PBUFFER_HEIGHT, static_cast(d_area.getHeight()), GLX_LARGEST_PBUFFER, True, GLX_PRESERVED_CONTENTS, True, None diff --git a/cegui/src/RendererModules/OpenGL/GeometryBufferBase.cpp b/cegui/src/RendererModules/OpenGL/GeometryBufferBase.cpp index 1fafc98cb..0dfce3204 100644 --- a/cegui/src/RendererModules/OpenGL/GeometryBufferBase.cpp +++ b/cegui/src/RendererModules/OpenGL/GeometryBufferBase.cpp @@ -25,8 +25,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include - +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "glm/glm.hpp" #include "glm/gtc/quaternion.hpp" #include "glm/gtc/type_ptr.hpp" diff --git a/cegui/src/RendererModules/OpenGL/RenderTarget.inl b/cegui/src/RendererModules/OpenGL/RenderTarget.inl index d49c954e6..0c240f1d7 100644 --- a/cegui/src/RendererModules/OpenGL/RenderTarget.inl +++ b/cegui/src/RendererModules/OpenGL/RenderTarget.inl @@ -133,7 +133,7 @@ void OpenGLRenderTarget::unprojectPoint(const GeometryBuffer& buff, static_cast(d_area.getHeight()) }; - GLdouble in_x, in_y, in_z = 0.0; + GLdouble in_x = 0.0, in_y = 0.0, in_z = 0.0; glm::ivec4 viewPort = glm::ivec4(vp[0], vp[1], vp[2], vp[3]); const glm::mat4& projMatrix = d_matrix->d_matrix; @@ -209,7 +209,13 @@ void OpenGLRenderTarget::updateMatrix() const glm::vec3 center = glm::vec3(midx, midy, 1); glm::vec3 up = glm::vec3(0, -1, 0); + //Older glm versions use degrees as parameter here by default (Unless radians are forced via GLM_FORCE_RADIANS). Newer versions of glm exlusively use radians. +#if (GLM_VERSION_MAJOR == 0 && GLM_VERSION_MINOR <= 9 && GLM_VERSION_PATCH < 6) && (!defined(GLM_FORCE_RADIANS)) glm::mat4 projectionMatrix = glm::perspective(30.f, aspect, float(d_viewDistance * 0.5), float(d_viewDistance * 2.0)); +#else + glm::mat4 projectionMatrix = glm::perspective(glm::radians(30.f), aspect, float(d_viewDistance * 0.5), float(d_viewDistance * 2.0)); +#endif + // Projection matrix abuse! glm::mat4 viewMatrix = glm::lookAt(eye, center, up); diff --git a/cegui/src/RendererModules/OpenGL/RendererBase.cpp b/cegui/src/RendererModules/OpenGL/RendererBase.cpp index fe51abc0f..ff6cd31bf 100644 --- a/cegui/src/RendererModules/OpenGL/RendererBase.cpp +++ b/cegui/src/RendererModules/OpenGL/RendererBase.cpp @@ -25,8 +25,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include - +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "CEGUI/RendererModules/OpenGL/RendererBase.h" #include "CEGUI/RendererModules/OpenGL/Texture.h" #include "CEGUI/RendererModules/OpenGL/TextureTarget.h" @@ -49,32 +48,78 @@ String OpenGLRendererBase::d_rendererID("--- subclass did not set ID: Fix this!" //----------------------------------------------------------------------------// OpenGLRendererBase::OpenGLRendererBase() : - d_displayDPI(96, 96), - d_initExtraStates(false), - d_activeBlendMode(BM_INVALID), - d_viewProjectionMatrix(new mat4Pimpl()), + d_viewProjectionMatrix(0), d_activeRenderTarget(0) { - initialiseMaxTextureSize(); + init(); initialiseDisplaySizeWithViewportSize(); - d_defaultTarget = CEGUI_NEW_AO OpenGLViewportTarget(*this); } //----------------------------------------------------------------------------// OpenGLRendererBase::OpenGLRendererBase(const Sizef& display_size) : d_displaySize(display_size), - d_displayDPI(96, 96), - d_initExtraStates(false), - d_activeBlendMode(BM_INVALID), - d_viewProjectionMatrix(new mat4Pimpl()), + d_viewProjectionMatrix(0), d_activeRenderTarget(0) { - initialiseMaxTextureSize(); + init(); + d_defaultTarget = CEGUI_NEW_AO OpenGLViewportTarget(*this); +} + +//----------------------------------------------------------------------------// +OpenGLRendererBase::OpenGLRendererBase(bool set_glew_experimental) : + d_viewProjectionMatrix(0), + d_activeRenderTarget(0) +{ + init(true, set_glew_experimental); + initialiseDisplaySizeWithViewportSize(); + d_defaultTarget = CEGUI_NEW_AO OpenGLViewportTarget(*this); +} +//----------------------------------------------------------------------------// +OpenGLRendererBase::OpenGLRendererBase(const Sizef& display_size, + bool set_glew_experimental) : + d_displaySize(display_size), + d_viewProjectionMatrix(0), + d_activeRenderTarget(0) +{ + init(true, set_glew_experimental); d_defaultTarget = CEGUI_NEW_AO OpenGLViewportTarget(*this); } +//----------------------------------------------------------------------------// +void OpenGLRendererBase::init(bool init_glew, bool set_glew_experimental) +{ + d_displayDPI.d_x = d_displayDPI.d_y = 96; + d_initExtraStates = false; + d_activeBlendMode = BM_INVALID; + d_viewProjectionMatrix = new mat4Pimpl(); +#if defined CEGUI_USE_GLEW + if (init_glew) + { + if (set_glew_experimental) + glewExperimental = GL_TRUE; + GLenum err = glewInit(); + if(err != GLEW_OK) + { + std::ostringstream err_string; + //Problem: glewInit failed, something is seriously wrong. + err_string << "failed to initialise the GLEW library. " + << glewGetErrorString(err); + + CEGUI_THROW(RendererException(err_string.str().c_str())); + } + //Clear the useless error glew produces as of version 1.7.0, when using OGL3.2 Core Profile + glGetError(); + } +#else + CEGUI_UNUSED(init_glew); + CEGUI_UNUSED(set_glew_experimental); +#endif + OpenGLInfo::getSingleton().init(); + initialiseMaxTextureSize(); +} + //----------------------------------------------------------------------------// OpenGLRendererBase::~OpenGLRendererBase() { @@ -371,7 +416,7 @@ Sizef OpenGLRendererBase::getAdjustedTextureSize(const Sizef& sz) const Sizef out(sz); // if we can't support non power of two sizes, get appropriate POT values. - if (!GLEW_ARB_texture_non_power_of_two) + if (!OpenGLInfo::getSingleton().isNpotTextureSupported()) { out.d_width = getNextPOTSize(out.d_width); out.d_height = getNextPOTSize(out.d_height); diff --git a/cegui/src/RendererModules/OpenGL/Shader.cpp b/cegui/src/RendererModules/OpenGL/Shader.cpp index 39db1d2dc..345c6a0e0 100644 --- a/cegui/src/RendererModules/OpenGL/Shader.cpp +++ b/cegui/src/RendererModules/OpenGL/Shader.cpp @@ -24,13 +24,11 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include - +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "CEGUI/RendererModules/OpenGL/Shader.h" #include "CEGUI/Logger.h" #include "CEGUI/Exceptions.h" - #include #include @@ -111,7 +109,7 @@ void OpenGL3Shader::bindFragDataLocation(const std::string &name) { if(d_program > 0) { - glBindFragDataLocation(d_program, 0, name.c_str() ); + glBindFragDataLocation(d_program, 0, name.c_str()); link(); } } @@ -199,15 +197,17 @@ void OpenGL3Shader::link() d_createdSucessfully = true; checkGLErrors(); - - glBindFragDataLocation(d_program, 0, "out0"); // GL_COLOR_ATTACHMENT0 - glBindFragDataLocation(d_program, 1, "out1"); // GL_COLOR_ATTACHMENT1 - glBindFragDataLocation(d_program, 2, "out2"); // ... - glBindFragDataLocation(d_program, 3, "out3"); - glBindFragDataLocation(d_program, 4, "out4"); - glBindFragDataLocation(d_program, 5, "out5"); - glBindFragDataLocation(d_program, 6, "out6"); - glBindFragDataLocation(d_program, 7, "out7"); + if (OpenGLInfo::getSingleton().isUsingDesktopOpengl()) + { + glBindFragDataLocation(d_program, 0, "out0"); // GL_COLOR_ATTACHMENT0 + glBindFragDataLocation(d_program, 1, "out1"); // GL_COLOR_ATTACHMENT1 + glBindFragDataLocation(d_program, 2, "out2"); // ... + glBindFragDataLocation(d_program, 3, "out3"); + glBindFragDataLocation(d_program, 4, "out4"); + glBindFragDataLocation(d_program, 5, "out5"); + glBindFragDataLocation(d_program, 6, "out6"); + glBindFragDataLocation(d_program, 7, "out7"); + } checkGLErrors(); } @@ -226,7 +226,7 @@ void OpenGL3Shader::outputProgramLog(GLuint program) sstream << "OpenGL3Shader linking has failed.\n" << logBuffer; CEGUI_THROW(RendererException(sstream.str().c_str())); } -}; +} //----------------------------------------------------------------------------// void OpenGL3Shader::outputShaderLog(GLuint shader) @@ -243,7 +243,7 @@ void OpenGL3Shader::outputShaderLog(GLuint shader) ss << "OpenGL3Shader compilation has failed.\n" << logBuffer; CEGUI_THROW(RendererException(ss.str().c_str())); } -}; +} //----------------------------------------------------------------------------// void getGLErrors(const char *location) diff --git a/cegui/src/RendererModules/OpenGL/ShaderManager.cpp b/cegui/src/RendererModules/OpenGL/ShaderManager.cpp index 2b3e0e1fa..d87cd9cd4 100644 --- a/cegui/src/RendererModules/OpenGL/ShaderManager.cpp +++ b/cegui/src/RendererModules/OpenGL/ShaderManager.cpp @@ -31,6 +31,7 @@ #include "CEGUI/RendererModules/OpenGL/StandardShaderVert.h" #include "CEGUI/RendererModules/OpenGL/StandardShaderFrag.h" +#include "CEGUI/RendererModules/OpenGL/GL3Renderer.h" #include "CEGUI/Logger.h" #include "CEGUI/Exceptions.h" @@ -71,18 +72,29 @@ namespace CEGUI { if(!d_shadersInitialised) { - loadShader(SHADER_ID_STANDARDSHADER, StandardShaderVert, StandardShaderFrag); - - + if (OpenGLInfo::getSingleton().isUsingDesktopOpengl()) + loadShader(SHADER_ID_STANDARDSHADER, StandardShaderVert_Opengl3, + StandardShaderFrag_Opengl3); + else // OpenGL ES + { + if (OpenGLInfo::getSingleton().verMajor() <= 2) + loadShader(SHADER_ID_STANDARDSHADER, StandardShaderVert_OpenglEs2, + StandardShaderFrag_OpenglEs2); + else + loadShader(SHADER_ID_STANDARDSHADER, StandardShaderVert_OpenglEs3, + StandardShaderFrag_OpenglEs3); + } if(!getShader(SHADER_ID_STANDARDSHADER)->isCreatedSuccessfully()) { - const CEGUI::String errorString("Critical Error - One or multiple shader programs weren't created successfully"); + const CEGUI::String errorString("Critical Error - One or " + "multiple shader programs weren't created successfully"); CEGUI_THROW(RendererException(errorString)); return; } - const CEGUI::String notify("OpenGL3Renderer: Notification - Successfully initialised OpenGL3Renderer shader programs."); + const CEGUI::String notify("OpenGL3Renderer: Notification - " + "Successfully initialised OpenGL3Renderer shader programs."); if (CEGUI::Logger* logger = CEGUI::Logger::getSingletonPtr()) logger->logEvent(notify); diff --git a/cegui/src/RendererModules/OpenGL/StateChangeWrapper.cpp b/cegui/src/RendererModules/OpenGL/StateChangeWrapper.cpp index e2048292a..bc0bb5129 100644 --- a/cegui/src/RendererModules/OpenGL/StateChangeWrapper.cpp +++ b/cegui/src/RendererModules/OpenGL/StateChangeWrapper.cpp @@ -24,9 +24,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ - -#include - +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "CEGUI/RendererModules/OpenGL/StateChangeWrapper.h" namespace CEGUI @@ -126,16 +124,16 @@ namespace CEGUI return equal; } +OpenGL3StateChangeWrapper::OpenGL3StateChangeWrapper() +{ + reset(); +} - - - -//! constructor. -OpenGL3StateChangeWrapper::OpenGL3StateChangeWrapper(OpenGL3Renderer& owner) +OpenGL3StateChangeWrapper::OpenGL3StateChangeWrapper(OpenGL3Renderer& /*owner*/) { reset(); } -//! destructor + OpenGL3StateChangeWrapper::~OpenGL3StateChangeWrapper() { } @@ -157,8 +155,8 @@ void OpenGL3StateChangeWrapper::bindVertexArray(GLuint vertexArray) glBindVertexArray(vertexArray); d_vertexArrayObject = vertexArray; } - } + void OpenGL3StateChangeWrapper::blendFunc(GLenum sfactor, GLenum dfactor) { bool callIsRedundant = d_blendFuncParams.equal(sfactor, dfactor); diff --git a/cegui/src/RendererModules/OpenGL/Texture.cpp b/cegui/src/RendererModules/OpenGL/Texture.cpp index dbe97a4e2..e1ea0bf49 100644 --- a/cegui/src/RendererModules/OpenGL/Texture.cpp +++ b/cegui/src/RendererModules/OpenGL/Texture.cpp @@ -24,7 +24,7 @@ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#include +#include "CEGUI/RendererModules/OpenGL/GL.h" #include "CEGUI/RendererModules/OpenGL/Texture.h" #include "CEGUI/Exceptions.h" #include "CEGUI/System.h" @@ -89,6 +89,40 @@ OpenGLTexture::OpenGLTexture(OpenGLRendererBase& owner, const String& name, initInternalPixelFormatFields(PF_RGBA); updateCachedScaleValues(); } +//----------------------------------------------------------------------------// +GLint OpenGLTexture::internalFormat() const +{ + if (OpenGLInfo::getSingleton().isSizedInternalFormatSupported()) + { + const char* err = "Invalid or unsupported OpenGL pixel format."; + switch (d_format) + { + case GL_RGBA: + switch (d_subpixelFormat) + { + case GL_UNSIGNED_BYTE: + return GL_RGBA8; + case GL_UNSIGNED_SHORT_4_4_4_4: + return GL_RGBA4; + default: + CEGUI_THROW(RendererException(err)); + } + case GL_RGB: + switch (d_subpixelFormat) + { + case GL_UNSIGNED_BYTE: + return GL_RGB8; + case GL_UNSIGNED_SHORT_5_6_5: + return GL_RGB565; + default: + CEGUI_THROW(RendererException(err)); + } + default: CEGUI_THROW(RendererException(err)); + } + } + else + return d_format; +} //----------------------------------------------------------------------------// void OpenGLTexture::initInternalPixelFormatFields(const PixelFormat fmt) @@ -313,17 +347,17 @@ void OpenGLTexture::setTextureSize_impl(const Sizef& sz) if (d_isCompressed) { const GLsizei image_size = getCompressedTextureSize(size); - glCompressedTexImage2D(GL_TEXTURE_2D, 0, d_format, + glCompressedTexImage2D(GL_TEXTURE_2D, 0, d_format, static_cast(size.d_width), static_cast(size.d_height), 0, image_size, 0); } else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, + glTexImage2D(GL_TEXTURE_2D, 0, internalFormat(), static_cast(size.d_width), static_cast(size.d_height), - 0, GL_RGBA , GL_UNSIGNED_BYTE, 0); + 0, d_format, d_subpixelFormat, 0); } // restore previous texture binding. @@ -337,7 +371,23 @@ void OpenGLTexture::grabTexture() if (d_grabBuffer) return; - d_grabBuffer = new uint8[static_cast(4*d_size.d_width*d_size.d_height)]; + std::size_t buffer_size(0); + if (OpenGLInfo::getSingleton().isUsingOpenglEs()) + { + /* OpenGL ES 3.1 or below doesn't support + "glGetTexImage"/"glGetCompressedTexImage", so we need to emulate it + with "glReadPixels", which will return the data in (umcompressed) + format (GL_RGBA, GL_UNSIGNED_BYTE). */ + buffer_size = static_cast(d_dataSize.d_width) + *static_cast(d_dataSize.d_height) *4; + d_isCompressed = false; + d_format = GL_RGBA; + d_subpixelFormat = GL_UNSIGNED_BYTE; + } + else // Desktop OpenGL + buffer_size = static_cast(d_size.d_width) + *static_cast(d_size.d_height) *4; + d_grabBuffer = new uint8[buffer_size]; blitToMemory(d_grabBuffer); @@ -353,7 +403,11 @@ void OpenGLTexture::restoreTexture() generateOpenGLTexture(); setTextureSize_impl(d_size); - blitFromMemory(d_grabBuffer, Rectf(Vector2f(0, 0), d_size)); + Sizef blit_size; + /* In OpenGL ES we used "glReadPixels" to grab the texture, reading just the + relevant rectangle. */ + blit_size = OpenGLInfo::getSingleton().isUsingOpenglEs() ? d_dataSize : d_size; + blitFromMemory(d_grabBuffer, Rectf(Vector2f(0, 0), blit_size)); // free the grabbuffer delete [] d_grabBuffer; @@ -382,63 +436,89 @@ void OpenGLTexture::blitFromMemory(const void* sourceData, const Rectf& area) //----------------------------------------------------------------------------// void OpenGLTexture::blitToMemory(void* targetData) { - // save existing config - GLuint old_tex; - glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast(&old_tex)); - - glBindTexture(GL_TEXTURE_2D, d_ogltexture); - - if (d_isCompressed) - { - glGetCompressedTexImage(GL_TEXTURE_2D, 0, targetData); - } - else + if (OpenGLInfo::getSingleton().isUsingOpenglEs()) { + /* OpenGL ES 3.1 or below doesn't support + "glGetTexImage"/"glGetCompressedTexImage", so we need to emulate it + using "glReadPixels". */ + GLint old_pack; glGetIntegerv(GL_PACK_ALIGNMENT, &old_pack); - + GLuint texture_framebuffer(0); + GLint framebuffer_old(0), pack_alignment_old(0); + glGenFramebuffers(1, &texture_framebuffer); + GLenum framebuffer_target(0), framebuffer_param(0); + if (OpenGLInfo::getSingleton() + .isSeperateReadAndDrawFramebufferSupported()) + { + framebuffer_param = GL_READ_FRAMEBUFFER_BINDING; + framebuffer_target = GL_READ_FRAMEBUFFER; + } + else + { + framebuffer_param = GL_FRAMEBUFFER_BINDING; + framebuffer_target = GL_FRAMEBUFFER; + } + glGetIntegerv(framebuffer_param, &framebuffer_old); + glBindFramebuffer(framebuffer_target, texture_framebuffer); + glFramebufferTexture2D(framebuffer_target, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, d_ogltexture, 0); + GLint read_buffer_old(0), pixel_pack_buffer_old(0); + if (OpenGLInfo::getSingleton().isReadBufferSupported()) + { + glGetIntegerv(GL_READ_BUFFER, &read_buffer_old); + glReadBuffer(GL_COLOR_ATTACHMENT0); + glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &pixel_pack_buffer_old); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + } + glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment_old); glPixelStorei(GL_PACK_ALIGNMENT, 1); - glGetTexImage(GL_TEXTURE_2D, 0, d_format, d_subpixelFormat, targetData); - - glPixelStorei(GL_PACK_ALIGNMENT, old_pack); + glReadPixels(0, 0, static_cast(d_dataSize.d_width), + static_cast(d_dataSize.d_height), GL_RGBA, GL_UNSIGNED_BYTE, targetData); + glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment_old); + if (OpenGLInfo::getSingleton().isReadBufferSupported()) + { + glBindBuffer(GL_PIXEL_PACK_BUFFER, pixel_pack_buffer_old); + glReadBuffer(read_buffer_old); + } + glBindFramebuffer(framebuffer_target, framebuffer_old); + glDeleteFramebuffers(1, &texture_framebuffer); + } + else // Desktop OpenGL + { - // restore previous config. - glBindTexture(GL_TEXTURE_2D, old_tex); + // save existing config + GLuint old_tex; + glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast(&old_tex)); + + glBindTexture(GL_TEXTURE_2D, d_ogltexture); + + if (d_isCompressed) + { + glGetCompressedTexImage(GL_TEXTURE_2D, 0, targetData); + } + else + { + GLint old_pack; + glGetIntegerv(GL_PACK_ALIGNMENT, &old_pack); + + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glGetTexImage(GL_TEXTURE_2D, 0, d_format, d_subpixelFormat, targetData); + + glPixelStorei(GL_PACK_ALIGNMENT, old_pack); + } + + // restore previous config. + glBindTexture(GL_TEXTURE_2D, old_tex); + + } } //----------------------------------------------------------------------------// void OpenGLTexture::updateCachedScaleValues() { - // - // calculate what to use for x scale - // - const float orgW = d_dataSize.d_width; - const float texW = d_size.d_width; - - // if texture and original data width are the same, scale is based - // on the original size. - // if texture is wider (and source data was not stretched), scale - // is based on the size of the resulting texture. - if(orgW == texW && orgW == 0.0f) - d_texelScaling.d_x = 0.0f; - else - d_texelScaling.d_x = 1.0f / ((orgW == texW) ? orgW : texW); - - // - // calculate what to use for y scale - // - const float orgH = d_dataSize.d_height; - const float texH = d_size.d_height; - - // if texture and original data height are the same, scale is based - // on the original size. - // if texture is taller (and source data was not stretched), scale - // is based on the size of the resulting texture. - if(orgH == texH && orgH == 0.0f) - d_texelScaling.d_x = 0.0f; - else - d_texelScaling.d_y = 1.0f / ((orgH == texH) ? orgH : texH); + d_texelScaling.d_x = d_size.d_width == 0.f ? 0.f : 1.f / d_size.d_width; + d_texelScaling.d_y = d_size.d_height == 0.f ? 0.f : 1.f / d_size.d_height; } //----------------------------------------------------------------------------// @@ -454,8 +534,8 @@ void OpenGLTexture::generateOpenGLTexture() glBindTexture(GL_TEXTURE_2D, d_ogltexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 0x812F); // GL_CLAMP_TO_EDGE - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 0x812F); // GL_CLAMP_TO_EDGE + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // FIXME: This hack was needed to fix #980 in a way that maintains binary // compatibility in v0-8 branch. diff --git a/cegui/src/RendererModules/OpenGLES/CMakeLists.txt b/cegui/src/RendererModules/OpenGLES/CMakeLists.txt index 6fa846497..e7090ff3a 100644 --- a/cegui/src/RendererModules/OpenGLES/CMakeLists.txt +++ b/cegui/src/RendererModules/OpenGLES/CMakeLists.txt @@ -3,7 +3,7 @@ set (CEGUI_TARGET_NAME ${CEGUI_OPENGLES_RENDERER_LIBNAME}) cegui_gather_files() cegui_add_library(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} OPENGLES) +cegui_add_dependency(${CEGUI_TARGET_NAME} OPENGLES PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/ScriptModules/Lua/CMakeLists.txt b/cegui/src/ScriptModules/Lua/CMakeLists.txt index 8dbc19a00..ac2c32756 100644 --- a/cegui/src/ScriptModules/Lua/CMakeLists.txt +++ b/cegui/src/ScriptModules/Lua/CMakeLists.txt @@ -2,8 +2,8 @@ set( CEGUI_TARGET_NAME ${CEGUI_LUA_SCRIPTMODULE_LIBNAME} ) cegui_gather_files() cegui_add_library(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} TOLUAPP) -cegui_add_dependency(${CEGUI_TARGET_NAME} LUA51) +cegui_add_dependency(${CEGUI_TARGET_NAME} TOLUAPP PRIVATE TRUE) +cegui_add_dependency(${CEGUI_TARGET_NAME} LUA51 PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/ScriptModules/Lua/support/tolua++bin/CMakeLists.txt b/cegui/src/ScriptModules/Lua/support/tolua++bin/CMakeLists.txt index 3abc38280..e0e1ca60c 100644 --- a/cegui/src/ScriptModules/Lua/support/tolua++bin/CMakeLists.txt +++ b/cegui/src/ScriptModules/Lua/support/tolua++bin/CMakeLists.txt @@ -5,6 +5,10 @@ set( CORE_SOURCE_FILES tolua.c ) +if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter") +endif () + add_executable(${CEGUI_TARGET_NAME} ${CORE_SOURCE_FILES}) if (CEGUI_HAS_BUILD_SUFFIX AND CEGUI_BUILD_SUFFIX) @@ -22,20 +26,20 @@ if (CEGUI_BUILD_STATIC_CONFIGURATION) endif() endif() -cegui_add_dependency(${CEGUI_TARGET_NAME} TOLUAPP) -cegui_add_dependency(${CEGUI_TARGET_NAME} LUA51) +cegui_add_dependency(${CEGUI_TARGET_NAME} TOLUAPP PRIVATE TRUE) +cegui_add_dependency(${CEGUI_TARGET_NAME} LUA51 PRIVATE TRUE) install(TARGETS ${CEGUI_TARGET_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} -) + RUNTIME DESTINATION bin COMPONENT cegui_lua + LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_lua + ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_lua + ) if (CEGUI_BUILD_STATIC_CONFIGURATION) install(TARGETS ${CEGUI_TARGET_NAME}_Static - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} - ) + RUNTIME DESTINATION bin COMPONENT cegui_lua + LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_lua + ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_lua + ) endif() diff --git a/cegui/src/ScriptModules/Python/bindings/CMakeLists.txt b/cegui/src/ScriptModules/Python/bindings/CMakeLists.txt index bba24a1e4..8cd5728cd 100644 --- a/cegui/src/ScriptModules/Python/bindings/CMakeLists.txt +++ b/cegui/src/ScriptModules/Python/bindings/CMakeLists.txt @@ -6,9 +6,13 @@ execute_process( set( CEGUI_PYTHON_INSTALL_DIR "${CEGUI_PYTHON_INSTALL_DIR}/${CMAKE_PROJECT_NAME}-${CEGUI_VERSION_MAJOR}.${CEGUI_VERSION_MINOR}" ) -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${PYTHON_INCLUDE_DIR} - ${Boost_INCLUDE_DIR}) +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs -Wno-unused-parameter") + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +include_directories(SYSTEM + ${PYTHON_INCLUDE_DIR} + ${Boost_INCLUDE_DIR}) cegui_add_python_module( ${CEGUI_PYCEGUI_CORE_LIBNAME} "output/CEGUI" "" ) diff --git a/cegui/src/SimpleTimer.cpp b/cegui/src/SimpleTimer.cpp index 8b3e1f101..a7b45fc30 100644 --- a/cegui/src/SimpleTimer.cpp +++ b/cegui/src/SimpleTimer.cpp @@ -27,7 +27,12 @@ #include "CEGUI/SimpleTimer.h" #if (defined(__WIN32__) || defined(_WIN32) ) && (!defined __MINGW32__) + +#ifdef WIN32_LEAN_AND_MEAN + #undef WIN32_LEAN_AND_MEAN +#endif #include + double CEGUI::SimpleTimer::currentTime() { return timeGetTime() / 1000.0; diff --git a/cegui/src/System.cpp b/cegui/src/System.cpp index ee962c706..b30dc21dc 100644 --- a/cegui/src/System.cpp +++ b/cegui/src/System.cpp @@ -378,15 +378,17 @@ const String& System::getVerboseVersion() #if _MSC_VER < 1500 ret += "(Note: Compiler version is old and not officially supported)"; #elif _MSC_VER == 1500 - ret += "9.0"; + ret += "9.0 (2008)"; #elif _MSC_VER == 1600 - ret += "10.0"; + ret += "10.0 (2010)"; #elif _MSC_VER == 1700 - ret += "11.0"; + ret += "11.0 (2012)"; #elif _MSC_VER == 1800 - ret += "12.0"; -#elif _MSC_VER > 1800 - ret += "Great Scott!"; + ret += "12.0 (2013)"; +#elif _MSC_VER == 1900 + ret += "14.0 (2015)"; +#elif _MSC_VER > 1900 + ret += "Unknown MSVC++ version"; #endif #ifdef _WIN64 @@ -474,9 +476,9 @@ void System::executeScriptFile(const String& filename, const String& resourceGro d_scriptModule->executeScriptFile(filename, resourceGroup); } // Forward script exceptions with line number and file info - CEGUI_CATCH(ScriptException& e) + CEGUI_CATCH(ScriptException&) { - CEGUI_THROW(e); + CEGUI_RETHROW; } CEGUI_CATCH(...) { @@ -506,9 +508,9 @@ int System::executeScriptGlobal(const String& function_name) const return d_scriptModule->executeScriptGlobal(function_name); } // Forward script exceptions with line number and file info - CEGUI_CATCH(ScriptException& e) + CEGUI_CATCH(ScriptException&) { - CEGUI_THROW(e); + CEGUI_RETHROW; } CEGUI_CATCH(...) { @@ -539,9 +541,9 @@ void System::executeScriptString(const String& str) const d_scriptModule->executeString(str); } // Forward script exceptions with line number and file info - CEGUI_CATCH(ScriptException& e) + CEGUI_CATCH(ScriptException&) { - CEGUI_THROW(e); + CEGUI_RETHROW; } CEGUI_CATCH(...) { @@ -769,6 +771,7 @@ void System::setXMLParser(const String& parserName) // perform initialisation of XML parser. d_xmlParser->initialise(); #else + CEGUI_UNUSED(parserName); Logger::getSingleton().logEvent( "System::setXMLParser(const String& parserName) called from statically " "linked CEGUI library - unable to load dynamic module!", Errors); @@ -825,6 +828,7 @@ void System::setupImageCodec(const String& codecName) # if defined(CEGUI_STATIC) // for static build use static createImageCodec to create codec object d_imageCodec = createImageCodec(); + CEGUI_UNUSED(codecName); # else // load the appropriate image codec module d_imageCodecModule = codecName.empty() ? @@ -971,6 +975,10 @@ void System::destroyRegexMatcher(RegexMatcher* rm) const //----------------------------------------------------------------------------// GUIContext& System::getDefaultGUIContext() const { + if (d_guiContexts.empty()) + CEGUI_THROW(InvalidRequestException("Requesting the DefaultGUIContext, but no DefaultGUIContext is available. " + "The list of GUIContexts is empty.")); + return *d_guiContexts.front(); } diff --git a/cegui/src/SystemKeys.cpp b/cegui/src/SystemKeys.cpp index 2459b0fb5..9e1f3ec94 100644 --- a/cegui/src/SystemKeys.cpp +++ b/cegui/src/SystemKeys.cpp @@ -135,6 +135,7 @@ void SystemKeys::updatePressedStateForKey(Key::Scan key, bool state) case Key::RightControl: d_rightCtrl = state; + break; case Key::LeftAlt: d_leftAlt = state; diff --git a/cegui/src/Window.cpp b/cegui/src/Window.cpp index aa8a1d115..80d7dc1e6 100644 --- a/cegui/src/Window.cpp +++ b/cegui/src/Window.cpp @@ -68,6 +68,38 @@ namespace CEGUI { //----------------------------------------------------------------------------// +const String Window::AlphaPropertyName("Alpha"); +const String Window::AlwaysOnTopPropertyName("AlwaysOnTop"); +const String Window::ClippedByParentPropertyName("ClippedByParent"); +const String Window::DestroyedByParentPropertyName("DestroyedByParent"); +const String Window::DisabledPropertyName("Disabled"); +const String Window::FontPropertyName("Font"); +const String Window::IDPropertyName("ID"); +const String Window::InheritsAlphaPropertyName("InheritsAlpha"); +const String Window::MouseCursorImagePropertyName("MouseCursorImage"); +const String Window::VisiblePropertyName("Visible"); +const String Window::ActivePropertyName("Active"); +const String Window::RestoreOldCapturePropertyName("RestoreOldCapture"); +const String Window::TextPropertyName("Text"); +const String Window::ZOrderingEnabledPropertyName("ZOrderingEnabled"); +const String Window::WantsMultiClickEventsPropertyName("WantsMultiClickEvents"); +const String Window::MouseAutoRepeatEnabledPropertyName("MouseAutoRepeatEnabled"); +const String Window::AutoRepeatDelayPropertyName("AutoRepeatDelay"); +const String Window::AutoRepeatRatePropertyName("AutoRepeatRate"); +const String Window::DistributeCapturedInputsPropertyName("DistributeCapturedInputs"); +const String Window::TooltipTypePropertyName("TooltipType"); +const String Window::TooltipTextPropertyName("TooltipText"); +const String Window::InheritsTooltipTextPropertyName("InheritsTooltipText"); +const String Window::RiseOnClickEnabledPropertyName("RiseOnClickEnabled"); +const String Window::MousePassThroughEnabledPropertyName("MousePassThroughEnabled"); +const String Window::DragDropTargetPropertyName("DragDropTarget"); +const String Window::AutoRenderingSurfacePropertyName("AutoRenderingSurface"); +const String Window::TextParsingEnabledPropertyName("TextParsingEnabled"); +const String Window::MarginPropertyName("MarginProperty"); +const String Window::UpdateModePropertyName("UpdateMode"); +const String Window::MouseInputPropagationEnabledPropertyName("MouseInputPropagationEnabled"); +const String Window::AutoWindowPropertyName("AutoWindow"); +//----------------------------------------------------------------------------// const String Window::EventNamespace("Window"); const String Window::EventUpdated ("Updated"); const String Window::EventTextChanged("TextChanged"); @@ -711,6 +743,18 @@ void Window::setVisible(bool setting) getGUIContext().updateWindowContainingMouse(); } +//----------------------------------------------------------------------------// +void Window::setActive(bool setting) +{ + if (isActive() == setting) + return; + + if (setting) + activate(); + else + deactivate(); +} + //----------------------------------------------------------------------------// void Window::activate(void) { @@ -1221,10 +1265,17 @@ void Window::removeChild_impl(Element* element) if (position != d_children.end()) { // unban properties window could write as a root window - wnd->unbanPropertyFromXML("RestoreOldCapture"); + wnd->unbanPropertyFromXML(RestoreOldCapturePropertyName); } wnd->onZChange_impl(); + + // Removed windows should not be active anymore (they are not attached + // to anything so this would not make sense) + if(wnd->isActive()) + { + wnd->deactivate(); + } } //----------------------------------------------------------------------------// @@ -1318,117 +1369,122 @@ void Window::addWindowProperties(void) const String propertyOrigin("Window"); CEGUI_DEFINE_PROPERTY(Window, float, - "Alpha", "Property to get/set the alpha value of the Window. Value is floating point number.", + AlphaPropertyName, "Property to get/set the alpha value of the Window. Value is floating point number.", &Window::setAlpha, &Window::getAlpha, 1.0f ); CEGUI_DEFINE_PROPERTY(Window, bool, - "AlwaysOnTop", "Property to get/set the 'always on top' setting for the Window. Value is either \"true\" or \"false\".", + AlwaysOnTopPropertyName, "Property to get/set the 'always on top' setting for the Window. Value is either \"true\" or \"false\".", &Window::setAlwaysOnTop, &Window::isAlwaysOnTop, false ); CEGUI_DEFINE_PROPERTY(Window, bool, - "ClippedByParent", "Property to get/set the 'clipped by parent' setting for the Window. Value is either \"true\" or \"false\".", + ClippedByParentPropertyName, "Property to get/set the 'clipped by parent' setting for the Window. Value is either \"true\" or \"false\".", &Window::setClippedByParent, &Window::isClippedByParent, true ); CEGUI_DEFINE_PROPERTY(Window, bool, - "DestroyedByParent", "Property to get/set the 'destroyed by parent' setting for the Window. Value is either \"true\" or \"false\".", + DestroyedByParentPropertyName, "Property to get/set the 'destroyed by parent' setting for the Window. Value is either \"true\" or \"false\".", &Window::setDestroyedByParent, &Window::isDestroyedByParent, true ); CEGUI_DEFINE_PROPERTY(Window, bool, - "Disabled", "Property to get/set the 'disabled state' setting for the Window. Value is either \"true\" or \"false\".", + DisabledPropertyName, "Property to get/set the 'disabled state' setting for the Window. Value is either \"true\" or \"false\".", &Window::setDisabled, &Window::isDisabled, false ); CEGUI_DEFINE_PROPERTY(Window, Font*, - "Font","Property to get/set the font for the Window. Value is the name of the font to use (must be loaded already).", + FontPropertyName,"Property to get/set the font for the Window. Value is the name of the font to use (must be loaded already).", &Window::setFont, &Window::property_getFont, 0 ); CEGUI_DEFINE_PROPERTY(Window, uint, - "ID", "Property to get/set the ID value of the Window. Value is an unsigned integer number.", + IDPropertyName, "Property to get/set the ID value of the Window. Value is an unsigned integer number.", &Window::setID, &Window::getID, 0 ); CEGUI_DEFINE_PROPERTY(Window, bool, - "InheritsAlpha", "Property to get/set the 'inherits alpha' setting for the Window. Value is either \"true\" or \"false\".", + InheritsAlphaPropertyName, "Property to get/set the 'inherits alpha' setting for the Window. Value is either \"true\" or \"false\".", &Window::setInheritsAlpha, &Window::inheritsAlpha, true ); CEGUI_DEFINE_PROPERTY(Window, Image*, - "MouseCursorImage","Property to get/set the mouse cursor image for the Window. Value should be \"\".", + MouseCursorImagePropertyName,"Property to get/set the mouse cursor image for the Window. Value should be \"\".", &Window::setMouseCursor, &Window::property_getMouseCursor, 0 ); CEGUI_DEFINE_PROPERTY(Window, bool, - "Visible", "Property to get/set the 'visible state' setting for the Window. Value is either \"true\" or \"false\".", + VisiblePropertyName, "Property to get/set the 'visible state' setting for the Window. Value is either \"true\" or \"false\".", &Window::setVisible, &Window::isVisible, true ); CEGUI_DEFINE_PROPERTY(Window, bool, - "RestoreOldCapture", "Property to get/set the 'restore old capture' setting for the Window. Value is either \"true\" or \"false\".", + ActivePropertyName, "Property to get/set the 'active' setting for the Window. Value is either \"true\" or \"false\".", + &Window::setActive, &Window::isActive, false + ); + + CEGUI_DEFINE_PROPERTY(Window, bool, + RestoreOldCapturePropertyName, "Property to get/set the 'restore old capture' setting for the Window. Value is either \"true\" or \"false\".", &Window::setRestoreOldCapture, &Window::restoresOldCapture, false ); CEGUI_DEFINE_PROPERTY(Window, String, - "Text", "Property to get/set the text / caption for the Window. Value is the text string to use. Meaning of this property heavily depends on the type of the Window.", + TextPropertyName, "Property to get/set the text / caption for the Window. Value is the text string to use. Meaning of this property heavily depends on the type of the Window.", &Window::setText, &Window::getText, "" ); CEGUI_DEFINE_PROPERTY(Window, bool, - "ZOrderingEnabled", "Property to get/set the 'z-order changing enabled' setting for the Window. Value is either \"true\" or \"false\".", + ZOrderingEnabledPropertyName, "Property to get/set the 'z-order changing enabled' setting for the Window. Value is either \"true\" or \"false\".", &Window::setZOrderingEnabled, &Window::isZOrderingEnabled, true ); CEGUI_DEFINE_PROPERTY(Window, bool, - "WantsMultiClickEvents", "Property to get/set whether the window will receive double-click and triple-click events. Value is either \"true\" or \"false\".", + WantsMultiClickEventsPropertyName, "Property to get/set whether the window will receive double-click and triple-click events. Value is either \"true\" or \"false\".", &Window::setWantsMultiClickEvents, &Window::wantsMultiClickEvents, true ); CEGUI_DEFINE_PROPERTY(Window, bool, - "MouseAutoRepeatEnabled", "Property to get/set whether the window will receive autorepeat mouse button down events. Value is either \"true\" or \"false\".", + MouseAutoRepeatEnabledPropertyName, "Property to get/set whether the window will receive autorepeat mouse button down events. Value is either \"true\" or \"false\".", &Window::setMouseAutoRepeatEnabled, &Window::isMouseAutoRepeatEnabled, false ); CEGUI_DEFINE_PROPERTY(Window, float, - "AutoRepeatDelay", "Property to get/set the autorepeat delay. Value is a floating point number indicating the delay required in seconds.", + AutoRepeatDelayPropertyName, "Property to get/set the autorepeat delay. Value is a floating point number indicating the delay required in seconds.", &Window::setAutoRepeatDelay, &Window::getAutoRepeatDelay, 0.3f ); CEGUI_DEFINE_PROPERTY(Window, float, - "AutoRepeatRate", "Property to get/set the autorepeat rate. Value is a floating point number indicating the rate required in seconds.", + AutoRepeatRatePropertyName, "Property to get/set the autorepeat rate. Value is a floating point number indicating the rate required in seconds.", &Window::setAutoRepeatRate, &Window::getAutoRepeatRate, 0.06f ); CEGUI_DEFINE_PROPERTY(Window, bool, - "DistributeCapturedInputs", "Property to get/set whether captured inputs are passed to child windows. Value is either \"true\" or \"false\".", + DistributeCapturedInputsPropertyName, "Property to get/set whether captured inputs are passed to child windows. Value is either \"true\" or \"false\".", &Window::setDistributesCapturedInputs, &Window::distributesCapturedInputs, false ); CEGUI_DEFINE_PROPERTY(Window, String, - "TooltipType", "Property to get/set the custom tooltip for the window. Value is the type name of the custom tooltip. If \"\", the default System tooltip is used.", + TooltipTypePropertyName, "Property to get/set the custom tooltip for the window. Value is the type name of the custom tooltip. If \"\", the default System tooltip is used.", &Window::setTooltipType, &Window::getTooltipType, "" ); CEGUI_DEFINE_PROPERTY(Window, String, - "TooltipText", "Property to get/set the tooltip text for the window. Value is the tooltip text for the window.", + TooltipTextPropertyName, "Property to get/set the tooltip text for the window. Value is the tooltip text for the window.", &Window::setTooltipText, &Window::getTooltipText, "" ); CEGUI_DEFINE_PROPERTY(Window, bool, - "InheritsTooltipText", "Property to get/set whether the window inherits its parents tooltip text when it has none of its own. Value is either \"true\" or \"false\".", + InheritsTooltipTextPropertyName, "Property to get/set whether the window inherits its parents tooltip text when it has none of its own. Value is either \"true\" or \"false\".", &Window::setInheritsTooltipText, &Window::inheritsTooltipText, true ); CEGUI_DEFINE_PROPERTY(Window, bool, - "RiseOnClickEnabled", "Property to get/set whether the window will come to the top of the Z-order when clicked. Value is either \"true\" or \"false\".", + RiseOnClickEnabledPropertyName, "Property to get/set whether the window will come to the top of the Z-order when clicked. Value is either \"true\" or \"false\".", &Window::setRiseOnClickEnabled, &Window::isRiseOnClickEnabled, true ); CEGUI_DEFINE_PROPERTY(Window, bool, - "MousePassThroughEnabled", "Property to get/set whether the window ignores mouse events and pass them through to any windows behind it. Value is either \"true\" or \"false\".", + MousePassThroughEnabledPropertyName, "Property to get/set whether the window ignores mouse events and pass them through to any windows behind it. Value is either \"true\" or \"false\".", &Window::setMousePassThroughEnabled, &Window::isMousePassThroughEnabled, false ); @@ -1436,12 +1492,12 @@ void Window::addWindowProperties(void) addProperty(&d_lookNFeelProperty); CEGUI_DEFINE_PROPERTY(Window, bool, - "DragDropTarget", "Property to get/set whether the Window will receive drag and drop related notifications. Value is either \"true\" or \"false\".", + DragDropTargetPropertyName, "Property to get/set whether the Window will receive drag and drop related notifications. Value is either \"true\" or \"false\".", &Window::setDragDropTarget, &Window::isDragDropTarget, true ); CEGUI_DEFINE_PROPERTY(Window, bool, - "AutoRenderingSurface", "Property to get/set whether the Window will automatically attempt to " + AutoRenderingSurfacePropertyName, "Property to get/set whether the Window will automatically attempt to " "use a full imagery caching RenderingSurface (if supported by the " "renderer). Here, full imagery caching usually will mean caching a " "window's representation onto a texture (although no such " @@ -1451,33 +1507,32 @@ void Window::addWindowProperties(void) ); CEGUI_DEFINE_PROPERTY(Window, bool, - "TextParsingEnabled", "Property to get/set the text parsing setting for the Window. " + TextParsingEnabledPropertyName, "Property to get/set the text parsing setting for the Window. " "Value is either \"true\" or \"false\".", &Window::setTextParsingEnabled, &Window::isTextParsingEnabled, true ); CEGUI_DEFINE_PROPERTY(Window, UBox, - "Margin", "Property to get/set margin for the Window. Value format:" + MarginPropertyName, "Property to get/set margin for the Window. Value format:" "{top:{[tops],[topo]},left:{[lefts],[lefto]},bottom:{[bottoms],[bottomo]},right:{[rights],[righto]}}.", &Window::setMargin, &Window::getMargin, UBox(UDim(0, 0)) ); CEGUI_DEFINE_PROPERTY(Window, WindowUpdateMode, - "UpdateMode", "Property to get/set the window update mode setting. " + UpdateModePropertyName, "Property to get/set the window update mode setting. " "Value is one of \"Always\", \"Never\" or \"Visible\".", &Window::setUpdateMode,&Window::getUpdateMode, WUM_VISIBLE ); CEGUI_DEFINE_PROPERTY(Window, bool, - "MouseInputPropagationEnabled", "Property to get/set whether unhandled mouse inputs should be " + MouseInputPropagationEnabledPropertyName, "Property to get/set whether unhandled mouse inputs should be " "propagated back to the Window's parent. " "Value is either \"true\" or \"false\".", &Window::setMouseInputPropagationEnabled, &Window::isMouseInputPropagationEnabled, false ); CEGUI_DEFINE_PROPERTY(Window, bool, - "AutoWindow", - "Property to access whether the system considers this window to be an " + AutoWindowPropertyName, "Property to get/set whether the system considers this window to be an " "automatically created sub-component window." "Value is either \"true\" or \"false\".", &Window::setAutoWindow, &Window::isAutoWindow, false @@ -1705,6 +1760,10 @@ void Window::destroy(void) WindowEventArgs args(this); onDestructionStarted(args); + // Check we are detached from parent + if (d_parent) + d_parent->removeChild(this); + releaseInput(); // let go of the tooltip if we have it @@ -1714,6 +1773,8 @@ void Window::destroy(void) // ensure custom tooltip is cleaned up setTooltip(static_cast(0)); + + // clean up looknfeel related things if (!d_lookName.empty()) @@ -1732,10 +1793,6 @@ void Window::destroy(void) d_windowRenderer = 0; } - // double check we are detached from parent - if (d_parent) - d_parent->removeChild(this); - cleanupChildren(); releaseRenderingWindow(); @@ -1816,6 +1873,12 @@ void Window::setTooltipText(const String& tip) //----------------------------------------------------------------------------// const String& Window::getTooltipText(void) const +{ + return d_tooltipText; +} + +//----------------------------------------------------------------------------// +const String& Window::getTooltipTextIncludingInheritance(void) const { if (d_inheritsTipText && d_parent && d_tooltipText.empty()) return getParent()->getTooltipText(); @@ -2858,12 +2921,36 @@ void Window::banPropertyFromXML(const String& property_name) property_name + "' is already banned in window '" + d_name + "'"); } +//----------------------------------------------------------------------------// +void Window::banPropertyFromXMLRecursive(const String& property_name) +{ + banPropertyFromXML(property_name); + + const size_t childCount = getChildCount(); + for(size_t i = 0; i < childCount; ++i) + { + getChildAtIdx(i)->banPropertyFromXMLRecursive(property_name); + } +} + //----------------------------------------------------------------------------// void Window::unbanPropertyFromXML(const String& property_name) { d_bannedXMLProperties.erase(property_name); } +//----------------------------------------------------------------------------// +void Window::unbanPropertyFromXMLRecursive(const String& property_name) +{ + unbanPropertyFromXML(property_name); + + const size_t childCount = getChildCount(); + for(size_t i = 0; i < childCount; ++i) + { + getChildAtIdx(i)->unbanPropertyFromXMLRecursive(property_name); + } +} + //----------------------------------------------------------------------------// bool Window::isPropertyBannedFromXML(const String& property_name) const { @@ -3326,10 +3413,14 @@ void Window::initialiseClippers(const RenderingContext& ctx) void Window::onRotated(ElementEventArgs& e) { Element::onRotated(e); - - // if we have no surface set, enable the auto surface - if (!d_surface) + + // TODO: Checking quaternion for equality with IDENTITY is stupid, + // change this to something else, checking with tolerance. + if (d_rotation != Quaternion::IDENTITY && !d_surface) { + // if we have no surface set and the rotation differs from identity, + // enable the auto surface + Logger::getSingleton().logEvent("Window::setRotation - " "Activating AutoRenderingSurface on Window '" + d_name + "' to enable rotation support."); @@ -3348,20 +3439,23 @@ void Window::onRotated(ElementEventArgs& e) } } - // ensure surface we have is the right type - if (!d_surface->isRenderingWindow()) + if (d_surface) { - Logger::getSingleton().logEvent("Window::setRotation - " - "Window '" + d_name + "' has a manual RenderingSurface that is not " - "a RenderingWindow. Rotation will not be available.", Errors); + // ensure surface we have is the right type + if (!d_surface->isRenderingWindow()) + { + Logger::getSingleton().logEvent("Window::setRotation - " + "Window '" + d_name + "' has a manual RenderingSurface that is not " + "a RenderingWindow. Rotation will not be available.", Errors); - return; - } + return; + } - // Checks / setup complete! Now we can finally set the rotation. - static_cast(d_surface)->setRotation(d_rotation); - static_cast(d_surface)->setPivot( - Vector3f(d_pixelSize.d_width / 2.0f, d_pixelSize.d_height / 2.0f, 0.0f)); + // Checks / setup complete! Now we can finally set the rotation. + static_cast(d_surface)->setRotation(d_rotation); + static_cast(d_surface)->setPivot( + Vector3f(d_pixelSize.d_width / 2.0f, d_pixelSize.d_height / 2.0f, 0.0f)); + } } //----------------------------------------------------------------------------// @@ -3369,9 +3463,8 @@ const RenderedString& Window::getRenderedString() const { if (!d_renderedStringValid) { - // FIXME: Evil const cast! d_renderedString = getRenderedStringParser().parse( - getTextVisual(), const_cast(getFont()), 0); + getTextVisual(), 0, 0); d_renderedStringValid = true; } @@ -3755,14 +3848,22 @@ const Image* Window::property_getMouseCursor() const GUIContext& Window::getGUIContext() const { // GUIContext is always the one on the root window, we do not allow parts - // of a hierarchy to be drawn to seperate contexts (which is not much of + // of a hierarchy to be drawn to separate contexts (which is not much of // a limitation). // // ISSUE: if root has no GUIContext set for it, should we return 0 or // System::getDefaultGUIContext? Come to IRC and argue about it! - return getParent() ? getParent()->getGUIContext() : - d_guiContext ? *d_guiContext : - System::getSingleton().getDefaultGUIContext(); + if (getParent() != 0) + { + return getParent()->getGUIContext(); + } + else + { + if (d_guiContext) + return *d_guiContext; + else + return System::getSingleton().getDefaultGUIContext(); + } } //----------------------------------------------------------------------------// diff --git a/cegui/src/WindowRendererSets/Core/Editbox.cpp b/cegui/src/WindowRendererSets/Core/Editbox.cpp index 55e986ac7..6bf89e018 100644 --- a/cegui/src/WindowRendererSets/Core/Editbox.cpp +++ b/cegui/src/WindowRendererSets/Core/Editbox.cpp @@ -42,8 +42,11 @@ namespace CEGUI //----------------------------------------------------------------------------// const String FalagardEditbox::TypeName("Core/Editbox"); -const String FalagardEditbox::UnselectedTextColourPropertyName("NormalTextColour"); -const String FalagardEditbox::SelectedTextColourPropertyName("SelectedTextColour"); +const String FalagardEditbox::UnselectedTextColourPropertyName( "NormalTextColour" ); +const String FalagardEditbox::SelectedTextColourPropertyName( "SelectedTextColour" ); +const String FalagardEditbox::ActiveSelectionColourPropertyName( "ActiveSelectionColour" ); +const String FalagardEditbox::InactiveSelectionColourPropertyName( "InactiveSelectionColour" ); + const float FalagardEditbox::DefaultCaretBlinkTimeout(0.66f); //----------------------------------------------------------------------------// @@ -184,6 +187,8 @@ size_t FalagardEditbox::getCaretIndex(const String& visual_text) const if (!firstCharRtl) caretIndex--; } +#else + CEGUI_UNUSED(visual_text); #endif return caretIndex; @@ -376,6 +381,11 @@ void FalagardEditbox::renderTextBidi(const WidgetLookFeel& wlf, } } +#else + CEGUI_UNUSED(wlf); + CEGUI_UNUSED(text); + CEGUI_UNUSED(text_area); + CEGUI_UNUSED(text_offset); #endif } diff --git a/cegui/src/WindowRendererSets/Core/StaticImage.cpp b/cegui/src/WindowRendererSets/Core/StaticImage.cpp index 2137b4fc7..5870ca8f5 100644 --- a/cegui/src/WindowRendererSets/Core/StaticImage.cpp +++ b/cegui/src/WindowRendererSets/Core/StaticImage.cpp @@ -40,7 +40,7 @@ namespace CEGUI { CEGUI_DEFINE_WINDOW_RENDERER_PROPERTY(FalagardStaticImage, Image*, "Image", "Property to get/set the image for the FalagardStaticImage widget." - " Value should be \"set:[imageset name] image:[image name]\".", + " Value is \"ImagesetName/ImageName\".", &FalagardStaticImage::setImage, &FalagardStaticImage::getImage, 0); } diff --git a/cegui/src/WindowRendererSets/Core/StaticText.cpp b/cegui/src/WindowRendererSets/Core/StaticText.cpp index fba03bb97..d9887ed92 100644 --- a/cegui/src/WindowRendererSets/Core/StaticText.cpp +++ b/cegui/src/WindowRendererSets/Core/StaticText.cpp @@ -129,18 +129,23 @@ namespace CEGUI renderScrolledText(); } + void FalagardStaticText::invalidateFormatting() + { + d_formatValid = false; + d_window->invalidate(); + } + /************************************************************************ Caches the text according to scrollbar positions *************************************************************************/ void FalagardStaticText::renderScrolledText() { + updateFormatting(); + // get destination area for the text. const Rectf clipper(getTextRenderArea()); Rectf absarea(clipper); - if (!d_formatValid) - updateFormatting(clipper.getSize()); - // see if we may need to adjust horizontal position const Scrollbar* const horzScrollbar = getHorzScrollbar(); if (horzScrollbar->isEffectiveVisible()) @@ -188,6 +193,13 @@ namespace CEGUI case VTF_BOTTOM_ALIGNED: absarea.d_min.d_y = absarea.d_max.d_y - textHeight; break; + + case VTF_TOP_ALIGNED: + break; + + default: + CEGUI_THROW(InvalidRequestException( + "Invalid vertical formatting.")); } // calculate final colours @@ -202,69 +214,45 @@ namespace CEGUI /************************************************************************ Returns the vertical scrollbar component *************************************************************************/ - Scrollbar* FalagardStaticText::getVertScrollbar(void) const + Scrollbar* FalagardStaticText::getVertScrollbar() const { - // return component created by look'n'feel assignment. - return static_cast(d_window->getChild(VertScrollbarName)); + updateFormatting(); + return getVertScrollbarWithoutUpdate(); } /************************************************************************ Returns the horizontal scrollbar component *************************************************************************/ - Scrollbar* FalagardStaticText::getHorzScrollbar(void) const + Scrollbar* FalagardStaticText::getHorzScrollbar() const { - // return component created by look'n'feel assignment. - return static_cast(d_window->getChild(HorzScrollbarName)); + updateFormatting(); + return getHorzScrollbarWithoutUpdate(); } /************************************************************************ Gets the text rendering area *************************************************************************/ - Rectf FalagardStaticText::getTextRenderArea(void) const + Rectf FalagardStaticText::getTextRenderArea() const { - Scrollbar* vertScrollbar = getVertScrollbar(); - Scrollbar* horzScrollbar = getHorzScrollbar(); - bool v_visible = vertScrollbar->isVisible(); - bool h_visible = horzScrollbar->isVisible(); - - // get WidgetLookFeel for the assigned look. - const WidgetLookFeel& wlf = getLookNFeel(); - - String area_name(d_frameEnabled ? "WithFrameTextRenderArea" : "NoFrameTextRenderArea"); - - // if either of the scrollbars are visible, we might want to use a special rendering area - if (v_visible || h_visible) - { - if (h_visible) - { - area_name += "H"; - } - if (v_visible) - { - area_name += "V"; - } - area_name += "Scroll"; - } - - if (wlf.isNamedAreaDefined(area_name)) - { - return wlf.getNamedArea(area_name).getArea().getPixelRect(*d_window); - } - - // default to plain WithFrameTextRenderArea - return wlf.getNamedArea("WithFrameTextRenderArea").getArea().getPixelRect(*d_window); + updateFormatting(); + return getTextRenderAreaWithoutUpdate(); } /************************************************************************ Gets the pixel size of the document *************************************************************************/ - Sizef FalagardStaticText::getDocumentSize(const Rectf& renderArea) const + Sizef FalagardStaticText::getDocumentSize() const { - if (!d_formatValid) - updateFormatting(renderArea.getSize()); + updateFormatting(); + return getDocumentSizeWithoutUpdate(); + } - return Sizef(d_formattedRenderedString->getHorizontalExtent(d_window), - d_formattedRenderedString->getVerticalExtent(d_window)); + /************************************************************************ + Gets the pixel size of the document + *************************************************************************/ + Sizef FalagardStaticText::getDocumentSize(const Rectf& /*renderArea*/) const + { + return getDocumentSize(); } /************************************************************************* @@ -282,8 +270,7 @@ namespace CEGUI void FalagardStaticText::setVerticalFormatting(VerticalTextFormatting v_fmt) { d_vertFormatting = v_fmt; - configureScrollbars(); - d_window->invalidate(); + invalidateFormatting(); } /************************************************************************* @@ -296,8 +283,7 @@ namespace CEGUI d_horzFormatting = h_fmt; setupStringFormatter(); - configureScrollbars(); - d_window->invalidate(); + invalidateFormatting(); } /************************************************************************* @@ -305,11 +291,10 @@ namespace CEGUI *************************************************************************/ void FalagardStaticText::setVerticalScrollbarEnabled(bool setting) { + if (d_enableVertScrollbar == setting) + return; d_enableVertScrollbar = setting; - configureScrollbars(); - d_window->performChildWindowLayout(); - d_formatValid = false; - d_window->invalidate(); + invalidateFormatting(); } /************************************************************************* @@ -317,64 +302,82 @@ namespace CEGUI *************************************************************************/ void FalagardStaticText::setHorizontalScrollbarEnabled(bool setting) { + if (d_enableHorzScrollbar == setting) + return; d_enableHorzScrollbar = setting; - configureScrollbars(); - d_window->performChildWindowLayout(); - d_formatValid = false; - d_window->invalidate(); + invalidateFormatting(); } /************************************************************************* - display required integrated scroll bars according to current state - of the edit box and update their values. + Display required integrated scroll bars according to current state of + the text and update their values. We may need to repeat the process + twice because showing one of the scrollbars shrinks the area reserved + for the text, and thus may cause the 2nd scrollbar to also be required. *************************************************************************/ - void FalagardStaticText::configureScrollbars(void) + void FalagardStaticText::configureScrollbars() const { - // get the scrollbars - Scrollbar* vertScrollbar = getVertScrollbar(); - Scrollbar* horzScrollbar = getHorzScrollbar(); + Scrollbar* vertScrollbar = getVertScrollbarWithoutUpdate(); + Scrollbar* horzScrollbar = getHorzScrollbarWithoutUpdate(); + vertScrollbar->hide(); + horzScrollbar->hide(); - // get the sizes we need - Rectf renderArea(getTextRenderArea()); + Rectf renderArea(getTextRenderAreaWithoutUpdate()); Sizef renderAreaSize(renderArea.getSize()); - Sizef documentSize(getDocumentSize(renderArea)); - - // show or hide vertical scroll bar as required (or as specified by option) - const bool showVert = ((documentSize.d_height > renderAreaSize.d_height) && d_enableVertScrollbar); - const bool showHorz = ((documentSize.d_width > renderAreaSize.d_width) && d_enableHorzScrollbar); - + d_formattedRenderedString->format(getWindow(), renderAreaSize); + Sizef documentSize(getDocumentSizeWithoutUpdate()); + bool showVert = (documentSize.d_height > renderAreaSize.d_height) && + d_enableVertScrollbar; + bool showHorz = (documentSize.d_width > renderAreaSize.d_width) && + d_enableHorzScrollbar; vertScrollbar->setVisible(showVert); horzScrollbar->setVisible(showHorz); - // if scrollbar visibility just changed we have might have a better TextRenderArea - // if so we go with that instead - const Rectf updatedRenderArea = getTextRenderArea(); - if (renderArea!=updatedRenderArea) + Rectf updatedRenderArea = getTextRenderAreaWithoutUpdate(); + if (renderArea != updatedRenderArea) { - d_formatValid = false; renderArea = updatedRenderArea; renderAreaSize = renderArea.getSize(); - documentSize = getDocumentSize(renderArea); + d_formattedRenderedString->format(getWindow(), renderAreaSize); + documentSize = getDocumentSizeWithoutUpdate(); + + showVert = (documentSize.d_height > renderAreaSize.d_height) && + d_enableVertScrollbar; + showHorz = (documentSize.d_width > renderAreaSize.d_width) && + d_enableHorzScrollbar; + vertScrollbar->setVisible(showVert); + horzScrollbar->setVisible(showHorz); + + updatedRenderArea = getTextRenderAreaWithoutUpdate(); + if (renderArea != updatedRenderArea) + { + renderArea = updatedRenderArea; + renderAreaSize = renderArea.getSize(); + d_formattedRenderedString->format(getWindow(), renderAreaSize); + documentSize = getDocumentSizeWithoutUpdate(); + } } - // Set up scroll bar values + getWindow()->performChildWindowLayout(); + vertScrollbar->setDocumentSize(documentSize.d_height); vertScrollbar->setPageSize(renderAreaSize.d_height); vertScrollbar->setStepSize(ceguimax(1.0f, renderAreaSize.d_height / 10.0f)); - horzScrollbar->setDocumentSize(documentSize.d_width); horzScrollbar->setPageSize(renderAreaSize.d_width); horzScrollbar->setStepSize(ceguimax(1.0f, renderAreaSize.d_width / 10.0f)); } + + void FalagardStaticText::configureScrollbars(void) + { + static_cast(this)->configureScrollbars(); + } /************************************************************************* Handler called when text is changed. *************************************************************************/ bool FalagardStaticText::onTextChanged(const EventArgs&) { - d_formatValid = false; - configureScrollbars(); - d_window->invalidate(); + invalidateFormatting(); return true; } @@ -384,8 +387,7 @@ namespace CEGUI *************************************************************************/ bool FalagardStaticText::onSized(const EventArgs&) { - d_formatValid = false; - configureScrollbars(); + invalidateFormatting(); return true; } @@ -395,9 +397,7 @@ namespace CEGUI *************************************************************************/ bool FalagardStaticText::onFontChanged(const EventArgs&) { - d_formatValid = false; - configureScrollbars(); - d_window->invalidate(); + invalidateFormatting(); return true; } @@ -443,8 +443,8 @@ namespace CEGUI void FalagardStaticText::onLookNFeelAssigned() { // do initial scrollbar setup - Scrollbar* vertScrollbar = getVertScrollbar(); - Scrollbar* horzScrollbar = getHorzScrollbar(); + Scrollbar* vertScrollbar = getVertScrollbarWithoutUpdate(); + Scrollbar* horzScrollbar = getHorzScrollbarWithoutUpdate(); vertScrollbar->hide(); horzScrollbar->hide(); @@ -473,6 +473,8 @@ namespace CEGUI d_connections.push_back( d_window->subscribeEvent(Window::EventMouseWheel, Event::Subscriber(&FalagardStaticText::onMouseWheel, this))); + + invalidateFormatting(); } void FalagardStaticText::onLookNFeelUnassigned() @@ -547,47 +549,84 @@ namespace CEGUI //----------------------------------------------------------------------------// float FalagardStaticText::getHorizontalTextExtent() const { - if (!d_formatValid) - updateFormatting(); - - return d_formattedRenderedString ? - d_formattedRenderedString->getHorizontalExtent(d_window) : - 0.0f; + updateFormatting(); + return d_formattedRenderedString->getHorizontalExtent(d_window); } //----------------------------------------------------------------------------// float FalagardStaticText::getVerticalTextExtent() const { - if (!d_formatValid) - updateFormatting(); + updateFormatting(); + return d_formattedRenderedString->getVerticalExtent(d_window); +} + +//----------------------------------------------------------------------------// +float FalagardStaticText::getHorizontalScrollPosition() const +{ + return getHorzScrollbar()->getScrollPosition(); +} - return d_formattedRenderedString ? - d_formattedRenderedString->getVerticalExtent(d_window) : - 0.0f; +//----------------------------------------------------------------------------// +float FalagardStaticText::getVerticalScrollPosition() const +{ + return getVertScrollbar()->getScrollPosition(); } //----------------------------------------------------------------------------// -void FalagardStaticText::updateFormatting() const +float FalagardStaticText::getUnitIntervalHorizontalScrollPosition() const { - updateFormatting(getTextRenderArea().getSize()); + return getHorzScrollbar()->getUnitIntervalScrollPosition(); } //----------------------------------------------------------------------------// -void FalagardStaticText::updateFormatting(const Sizef& sz) const +float FalagardStaticText::getUnitIntervalVerticalScrollPosition() const { - if (!d_window) - return; + return getVertScrollbar()->getUnitIntervalScrollPosition(); +} + +//----------------------------------------------------------------------------// +void FalagardStaticText::setHorizontalScrollPosition(float position) +{ + getHorzScrollbar()->setScrollPosition(position); +} + +//----------------------------------------------------------------------------// +void FalagardStaticText::setVerticalScrollPosition(float position) +{ + getVertScrollbar()->setScrollPosition(position); +} + +//----------------------------------------------------------------------------// +void FalagardStaticText::setUnitIntervalHorizontalScrollPosition(float position) +{ + getHorzScrollbar()->setUnitIntervalScrollPosition(position); +} + +//----------------------------------------------------------------------------// +void FalagardStaticText::setUnitIntervalVerticalScrollPosition(float position) +{ + getVertScrollbar()->setUnitIntervalScrollPosition(position); +} +//----------------------------------------------------------------------------// +void FalagardStaticText::updateFormatting() const +{ + if (d_formatValid) + return; if (!d_formattedRenderedString) setupStringFormatter(); - - // 'touch' the window's rendered string to ensure it's re-parsed if needed. + // "Touch" the window's rendered string to ensure it's re-parsed if needed. d_window->getRenderedString(); - - d_formattedRenderedString->format(d_window, sz); + configureScrollbars(); d_formatValid = true; } +//----------------------------------------------------------------------------// +void FalagardStaticText::updateFormatting(const Sizef&) const +{ + updateFormatting(); +} + //----------------------------------------------------------------------------// bool FalagardStaticText::handleFontRenderSizeChange(const Font* const font) { @@ -595,14 +634,78 @@ bool FalagardStaticText::handleFontRenderSizeChange(const Font* const font) if (d_window->getFont() == font) { - d_window->invalidate(); - d_formatValid = false; + invalidateFormatting(); return true; } return res; } + /************************************************************************ + Returns the vertical scrollbar component + *************************************************************************/ + Scrollbar* FalagardStaticText::getVertScrollbarWithoutUpdate() const + { + // return component created by look'n'feel assignment. + return static_cast(d_window->getChild(VertScrollbarName)); + } + + /************************************************************************ + Returns the horizontal scrollbar component + *************************************************************************/ + Scrollbar* FalagardStaticText::getHorzScrollbarWithoutUpdate() const + { + // return component created by look'n'feel assignment. + return static_cast(d_window->getChild(HorzScrollbarName)); + } + + /************************************************************************ + Gets the text rendering area + *************************************************************************/ + Rectf FalagardStaticText::getTextRenderAreaWithoutUpdate() const + { + Scrollbar* vertScrollbar = getVertScrollbarWithoutUpdate(); + Scrollbar* horzScrollbar = getHorzScrollbarWithoutUpdate(); + bool v_visible = vertScrollbar->isVisible(); + bool h_visible = horzScrollbar->isVisible(); + + // get WidgetLookFeel for the assigned look. + const WidgetLookFeel& wlf = getLookNFeel(); + + String area_name(d_frameEnabled ? "WithFrameTextRenderArea" : "NoFrameTextRenderArea"); + + // if either of the scrollbars are visible, we might want to use a special rendering area + if (v_visible || h_visible) + { + if (h_visible) + { + area_name += "H"; + } + if (v_visible) + { + area_name += "V"; + } + area_name += "Scroll"; + } + + if (wlf.isNamedAreaDefined(area_name)) + { + return wlf.getNamedArea(area_name).getArea().getPixelRect(*d_window); + } + + // default to plain WithFrameTextRenderArea + return wlf.getNamedArea("WithFrameTextRenderArea").getArea().getPixelRect(*d_window); + } + + /************************************************************************ + Gets the pixel size of the document + *************************************************************************/ + Sizef FalagardStaticText::getDocumentSizeWithoutUpdate() const + { + return Sizef(d_formattedRenderedString->getHorizontalExtent(d_window), + d_formattedRenderedString->getVerticalExtent(d_window)); + } + //----------------------------------------------------------------------------// } // End of CEGUI namespace section diff --git a/cegui/src/XMLParser.cpp b/cegui/src/XMLParser.cpp index dee88a17b..d71ec47fe 100644 --- a/cegui/src/XMLParser.cpp +++ b/cegui/src/XMLParser.cpp @@ -30,6 +30,8 @@ #include "CEGUI/ResourceProvider.h" #include "CEGUI/Logger.h" +#include + // Start of CEGUI namespace section namespace CEGUI { @@ -55,16 +57,34 @@ namespace CEGUI void XMLParser::parseXMLFile(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup) { + //TODO: Once we replace all C parsing functions (sscanf and whatever is used) by the superiour std::regex and std's streams, + // this locale-check becomes redundant and needs to be removed as well. + char* localeAll = setlocale(LC_ALL, NULL); + char* localeNumeric = setlocale(LC_NUMERIC, NULL); + + if( (*localeAll != 'C') || (*localeNumeric != 'C') ) + { + // Only throw this if only numeric locale is "wrong" + Logger::getSingleton().logEvent( + "The C locale for LC_NUMERIC and/or LC_ALL is not set to \"C\". However, CEGUI is only ensured to parse strings and numbers correctly under the condition that the " + "locale is set to \"C\". This is required, for example, when parsing files or converting from a (property-) value to a String (or vice-versa). If your code or one of your libraries change " + "the locale (typically, by using the function \"setlocale\"), please set the locale back to the default everytime before a relevant call to CEGUI is issued to ensure " + "that the parsing will be functional and correct. " + "If you know what you are doing and there are no issues whatsoever, you may ignore this error message." + , Errors); + } + + // Acquire resource using CEGUI ResourceProvider RawDataContainer rawXMLData; System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup); - try + CEGUI_TRY { // The actual parsing action (this is overridden and depends on the specific parser) parseXML(handler, rawXMLData, schemaName); } - catch (const Exception&) + CEGUI_CATCH (const Exception&) { // hint the related file name in the log Logger::getSingleton().logEvent("The last thrown exception was related to XML file '" + @@ -89,12 +109,12 @@ namespace CEGUI rawXMLData.setData((uint8*)c_str); rawXMLData.setSize(strlen(c_str)); - try + CEGUI_TRY { // The actual parsing action (this is overridden and depends on the specific parser) parseXML(handler, rawXMLData, schemaName); } - catch(...) + CEGUI_CATCH(...) { // make sure we don't allow rawXMLData to release String owned data no matter what! rawXMLData.setData(0); diff --git a/cegui/src/XMLParserModules/Expat/CMakeLists.txt b/cegui/src/XMLParserModules/Expat/CMakeLists.txt index 839672e0c..b7f35ec52 100644 --- a/cegui/src/XMLParserModules/Expat/CMakeLists.txt +++ b/cegui/src/XMLParserModules/Expat/CMakeLists.txt @@ -2,7 +2,7 @@ set (CEGUI_TARGET_NAME ${CEGUI_EXPAT_PARSER_LIBNAME}) cegui_gather_files() cegui_add_loadable_module(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} EXPAT) +cegui_add_dependency(${CEGUI_TARGET_NAME} EXPAT PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/XMLParserModules/Libxml2/CMakeLists.txt b/cegui/src/XMLParserModules/Libxml2/CMakeLists.txt index 5cceb7cd1..6c53da191 100644 --- a/cegui/src/XMLParserModules/Libxml2/CMakeLists.txt +++ b/cegui/src/XMLParserModules/Libxml2/CMakeLists.txt @@ -2,7 +2,7 @@ set (CEGUI_TARGET_NAME ${CEGUI_LIBXML2_PARSER_LIBNAME}) cegui_gather_files() cegui_add_loadable_module(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} LIBXML2) +cegui_add_dependency(${CEGUI_TARGET_NAME} LIBXML2 PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/XMLParserModules/TinyXML/CMakeLists.txt b/cegui/src/XMLParserModules/TinyXML/CMakeLists.txt index cf4b446e5..4852cdab4 100644 --- a/cegui/src/XMLParserModules/TinyXML/CMakeLists.txt +++ b/cegui/src/XMLParserModules/TinyXML/CMakeLists.txt @@ -4,7 +4,7 @@ cegui_gather_files() cegui_add_loadable_module(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} TINYXML) +cegui_add_dependency(${CEGUI_TARGET_NAME} TINYXML PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/XMLParserModules/Xerces/CMakeLists.txt b/cegui/src/XMLParserModules/Xerces/CMakeLists.txt index ea89d4270..02b1f9047 100644 --- a/cegui/src/XMLParserModules/Xerces/CMakeLists.txt +++ b/cegui/src/XMLParserModules/Xerces/CMakeLists.txt @@ -2,7 +2,7 @@ set (CEGUI_TARGET_NAME ${CEGUI_XERCES_PARSER_LIBNAME}) cegui_gather_files() cegui_add_loadable_module(${CEGUI_TARGET_NAME} CORE_SOURCE_FILES CORE_HEADER_FILES) -cegui_add_dependency(${CEGUI_TARGET_NAME} XERCESC) +cegui_add_dependency(${CEGUI_TARGET_NAME} XERCESC PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_BASE_LIBNAME}) diff --git a/cegui/src/falagard/EventAction.cpp b/cegui/src/falagard/EventAction.cpp index 7402feaef..78f5590c3 100644 --- a/cegui/src/falagard/EventAction.cpp +++ b/cegui/src/falagard/EventAction.cpp @@ -145,7 +145,7 @@ void EventAction::writeXMLToStream(XMLSerializer& xml_stream) const String EventAction::makeConnectionKeyName(const Window& widget) const { char addr[32]; - std::sprintf(addr, "%p", &widget); + std::sprintf(addr, "%p", static_cast(&widget)); return String(addr) + d_eventName + diff --git a/cegui/src/falagard/TextComponent.cpp b/cegui/src/falagard/TextComponent.cpp index c9de5ebcc..d8c5907eb 100644 --- a/cegui/src/falagard/TextComponent.cpp +++ b/cegui/src/falagard/TextComponent.cpp @@ -252,46 +252,19 @@ namespace CEGUI } } - void TextComponent::render_impl(Window& srcWindow, Rectf& destRect, const CEGUI::ColourRect* modColours, const Rectf* clipper, bool /*clipToDisplay*/) const + void TextComponent::render_impl(Window& srcWindow, Rectf& destRect, + const CEGUI::ColourRect* modColours, const Rectf* clipper, + bool /*clipToDisplay*/) const { - const Font* font = getFontObject(srcWindow); - - // exit if we have no font to use. - if (!font) - return; - - const RenderedString* rs = &d_renderedString; - // do we fetch text from a property - if (!d_textPropertyName.empty()) + + CEGUI_TRY { - // fetch text & do bi-directional reordering as needed - String vis; - #ifdef CEGUI_BIDI_SUPPORT - BidiVisualMapping::StrIndexList l2v, v2l; - d_bidiVisualMapping->reorderFromLogicalToVisual( - srcWindow.getProperty(d_textPropertyName), vis, l2v, v2l); - #else - vis = srcWindow.getProperty(d_textPropertyName); - #endif - // parse string using parser from Window. - d_renderedString = - srcWindow.getRenderedStringParser().parse(vis, font, 0); + updateFormatting(srcWindow, destRect.getSize()); + } + CEGUI_CATCH(...) + { + return; } - // do we use a static text string from the looknfeel - else if (!getTextVisual().empty()) - // parse string using parser from Window. - d_renderedString = srcWindow.getRenderedStringParser(). - parse(getTextVisual(), font, 0); - // do we have to override the font? - else if (font != srcWindow.getFont()) - d_renderedString = srcWindow.getRenderedStringParser(). - parse(srcWindow.getTextVisual(), font, 0); - // use ready-made RenderedString from the Window itself - else - rs = &srcWindow.getRenderedString(); - - setupStringFormatter(srcWindow, *rs); - d_formattedRenderedString->format(&srcWindow, destRect.getSize()); // Get total formatted height. const float textHeight = d_formattedRenderedString->getVerticalExtent(&srcWindow); @@ -429,11 +402,13 @@ namespace CEGUI float TextComponent::getHorizontalTextExtent(const Window& window) const { + updateFormatting(window); return d_formattedRenderedString->getHorizontalExtent(&window); } float TextComponent::getVerticalTextExtent(const Window& window) const { + updateFormatting(window); return d_formattedRenderedString->getVerticalExtent(&window); } @@ -452,6 +427,58 @@ namespace CEGUI return res; } + //------------------------------------------------------------------------// + void TextComponent::updateFormatting(const Window& srcWindow) const + { + updateFormatting(srcWindow, d_area.getPixelRect(srcWindow).getSize()); + } + + //------------------------------------------------------------------------// + void TextComponent::updateFormatting( + const Window& srcWindow, const Sizef& size) const + { + + const Font* font = getFontObject(srcWindow); + + // exit if we have no font to use. + if (!font) + CEGUI_THROW(InvalidRequestException("Window doesn't have a font.")); + + const RenderedString* rs = &d_renderedString; + // do we fetch text from a property + if (!d_textPropertyName.empty()) + { + // fetch text & do bi-directional reordering as needed + String vis; + #ifdef CEGUI_BIDI_SUPPORT + BidiVisualMapping::StrIndexList l2v, v2l; + d_bidiVisualMapping->reorderFromLogicalToVisual( + srcWindow.getProperty(d_textPropertyName), vis, l2v, v2l); + #else + vis = srcWindow.getProperty(d_textPropertyName); + #endif + // parse string using parser from Window. + d_renderedString = + srcWindow.getRenderedStringParser().parse(vis, font, 0); + } + // do we use a static text string from the looknfeel + else if (!getTextVisual().empty()) + // parse string using parser from Window. + d_renderedString = srcWindow.getRenderedStringParser(). + parse(getTextVisual(), font, 0); + // do we have to override the font? + else if (font != srcWindow.getFont()) + d_renderedString = srcWindow.getRenderedStringParser(). + parse(srcWindow.getTextVisual(), font, 0); + // use ready-made RenderedString from the Window itself + else + rs = &srcWindow.getRenderedString(); + + setupStringFormatter(srcWindow, *rs); + d_formattedRenderedString->format(&srcWindow, size); + + } + //----------------------------------------------------------------------------// String TextComponent::getEffectiveText(const Window& wnd) const { diff --git a/cegui/src/falagard/XMLHandler.cpp b/cegui/src/falagard/XMLHandler.cpp index aac177708..9bdc198e4 100644 --- a/cegui/src/falagard/XMLHandler.cpp +++ b/cegui/src/falagard/XMLHandler.cpp @@ -3,7 +3,7 @@ author: Paul D Turner *************************************************************************/ /*************************************************************************** - * Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team + * Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -151,6 +151,67 @@ namespace CEGUI "defined on one or more child windows, or " "the parent window."); + + //! Helper function for throwing exception strings. Adds introductory text andi s attempting to specify where the issue occured. + CEGUI::String getStartTextForException(const WidgetLookFeel* widgetLook) + { + CEGUI::String widgetLookInfo; + if (widgetLook != 0) + { + widgetLookInfo = "Occurrence inside " + Falagard_xmlHandler::WidgetLookElement + " : \"" + widgetLook->getName() + "\".\n"; + } + else + { + widgetLookInfo = "Occurrence outside of any " + Falagard_xmlHandler::WidgetLookElement + " elements.\n"; + } + + return "Exception occured while parsing a Look N' Feel file. " + widgetLookInfo + "Exception: "; + + } + + //! Throws an exception message for a node added as a child of a node of same type + void throwExceptionChildOfSameNode(const WidgetLookFeel* widgetLook, const String& nodeType, const String& elementNameOrValue) + { + CEGUI_THROW(InvalidRequestException( + getStartTextForException(widgetLook) + + nodeType + " nodes may not be children of other " + nodeType + + " nodes. This was not the case for a " + nodeType + " with name or value \"" + + elementNameOrValue + "\"." + )); + } + + //! Throws an exception message for a node added as a child of a node of same type + void throwExceptionChildOfSameNode(const WidgetLookFeel* widgetLook, const String& nodeType) + { + CEGUI_THROW(InvalidRequestException( + getStartTextForException(widgetLook) + + nodeType + " nodes may not be children of other " + nodeType + + " nodes. This was not the case for a " + nodeType + " node." + )); + } + + //! Throws an exception message for a node which is not part of the required parent node + void throwExceptionNotChildOfNode(const WidgetLookFeel* widgetLook, const String& childNodeType, const String& childElementName, const String& parentNodeType) + { + CEGUI_THROW(InvalidRequestException( + getStartTextForException(widgetLook) + + childNodeType + " nodes must be part of a " + parentNodeType + + " node. This was not the case for a " + childNodeType + " with name or value \"" + + childElementName + "\"." + )); + } + + //! Throws an exception message for a node which is not part of the required parent node + void throwExceptionNotChildOfNode(const WidgetLookFeel* widgetLook, const String& childNodeType, const String& parentNodeType) + { + CEGUI_THROW(InvalidRequestException( + getStartTextForException(widgetLook) + + childNodeType + " nodes must be part of a " + parentNodeType + + " node. This was not the case for a " + childNodeType + " node." + )); + } + + // Specific attribute values const String Falagard_xmlHandler::GenericDataType("Generic"); const String Falagard_xmlHandler::ParentIdentifier("__parent__"); @@ -392,7 +453,11 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementWidgetLookStart(const XMLAttributes& attributes) { - assert(d_widgetlook == 0); + if (d_widgetlook != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, WidgetLookElement, attributes.getValueAsString(NameAttribute)); + } + d_widgetlook = CEGUI_NEW_AO WidgetLookFeel(attributes.getValueAsString(NameAttribute), attributes.getValueAsString(InheritsAttribute)); @@ -404,7 +469,11 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementChildStart(const XMLAttributes& attributes) { - assert(d_childcomponent == 0); + if (d_childcomponent != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, ChildElement, attributes.getValueAsString(NameAttribute)); + } + d_childcomponent = CEGUI_NEW_AO WidgetComponent( attributes.getValueAsString(TypeAttribute), attributes.getValueAsString(LookAttribute), @@ -424,7 +493,11 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementImagerySectionStart(const XMLAttributes& attributes) { - assert(d_imagerysection == 0); + if (d_imagerysection != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, ImagerySectionElement, attributes.getValueAsString(NameAttribute)); + } + d_imagerysection = CEGUI_NEW_AO ImagerySection(attributes.getValueAsString(NameAttribute)); CEGUI_LOGINSANE("-----> Start of definition for imagery section '" + d_imagerysection->getName() + "'."); @@ -435,7 +508,11 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementStateImageryStart(const XMLAttributes& attributes) { - assert(d_stateimagery == 0); + if (d_stateimagery != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, StateImageryElement, attributes.getValueAsString(NameAttribute)); + } + d_stateimagery = CEGUI_NEW_AO StateImagery(attributes.getValueAsString(NameAttribute)); d_stateimagery->setClippedToDisplay(!attributes.getValueAsBool(ClippedAttribute, true)); @@ -447,7 +524,15 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementLayerStart(const XMLAttributes& attributes) { - assert(d_layer == 0); + if (d_layer != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, LayerElement, CEGUI::String("Priority: ") + attributes.getValueAsString(PriorityAttribute, "0")); + } + if (d_stateimagery == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, LayerElement, CEGUI::String("Priority: ") + attributes.getValueAsString(PriorityAttribute, "0"), StateImageryElement); + } + d_layer = CEGUI_NEW_AO LayerSpecification(attributes.getValueAsInteger(PriorityAttribute, 0)); CEGUI_LOGINSANE("-------> Start of definition of new imagery layer, priority: " + attributes.getValueAsString(PriorityAttribute, "0")); @@ -458,8 +543,21 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementSectionStart(const XMLAttributes& attributes) { - assert(d_section == 0); - assert(d_widgetlook != 0); + if (d_section != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, SectionElement, attributes.getValueAsString(SectionNameAttribute)); + } + + if (d_widgetlook == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, SectionElement, attributes.getValueAsString(SectionNameAttribute), WidgetLookElement); + } + + if (d_layer == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, SectionElement, d_section->getSectionName(), LayerElement); + } + String owner(attributes.getValueAsString(LookAttribute)); d_section = CEGUI_NEW_AO SectionSpecification(owner.empty() ? d_widgetlook->getName() : owner, @@ -476,7 +574,16 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementImageryComponentStart(const XMLAttributes&) { - assert(d_imagerycomponent == 0); + if (d_imagerycomponent != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, ImageryComponentElement); + } + + if (d_imagerysection == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, ImageryComponentElement, ImagerySectionElement); + } + d_imagerycomponent = CEGUI_NEW_AO ImageryComponent(); CEGUI_LOGINSANE("-------> Image component definition..."); @@ -487,7 +594,16 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementTextComponentStart(const XMLAttributes&) { - assert(d_textcomponent == 0); + if (d_textcomponent != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, TextComponentElement); + } + + if (d_imagerysection == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, TextComponentElement, ImagerySectionElement); + } + d_textcomponent = CEGUI_NEW_AO TextComponent(); CEGUI_LOGINSANE("-------> Text component definition..."); @@ -498,7 +614,16 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementFrameComponentStart(const XMLAttributes&) { - assert(d_framecomponent == 0); + if (d_framecomponent != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, FrameComponentElement); + } + + if (d_imagerysection == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, FrameComponentElement, ImagerySectionElement); + } + d_framecomponent = CEGUI_NEW_AO FrameComponent(); CEGUI_LOGINSANE("-------> Frame component definition..."); @@ -509,7 +634,17 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementAreaStart(const XMLAttributes&) { - assert(d_area == 0); + if (d_area != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, AreaElement); + } + + if ((d_childcomponent == 0) && (d_imagerycomponent == 0) && (d_textcomponent == 0) && d_namedArea == 0 && d_framecomponent == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, AreaElement, ChildElement + " or " + ImageryComponentElement + " or " + + TextComponentElement + " or " + NamedAreaElement + " or " + FrameComponentElement); + } + d_area = CEGUI_NEW_AO ComponentArea(); } @@ -651,7 +786,11 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementVertAlignmentStart(const XMLAttributes& attributes) { - assert(d_childcomponent != 0); + if (d_childcomponent == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, VertAlignmentElement, ChildElement); + } + d_childcomponent->setVerticalWidgetAlignment( FalagardXMLHelper::fromString( attributes.getValueAsString(TypeAttribute))); @@ -662,7 +801,11 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementHorzAlignmentStart(const XMLAttributes& attributes) { - assert(d_childcomponent != 0); + if (d_childcomponent == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, HorzAlignmentElement, ChildElement); + } + d_childcomponent->setHorizontalWidgetAlignment( FalagardXMLHelper::fromString( attributes.getValueAsString(TypeAttribute))); @@ -673,7 +816,11 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementPropertyStart(const XMLAttributes& attributes) { - assert(d_widgetlook != 0); + if (d_widgetlook == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, PropertyElement, attributes.getValueAsString(NameAttribute), WidgetLookElement); + } + PropertyInitialiser prop(attributes.getValueAsString(NameAttribute), attributes.getValueAsString(ValueAttribute)); if (d_childcomponent) @@ -796,7 +943,11 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementTextStart(const XMLAttributes& attributes) { - assert (d_textcomponent != 0); + if (d_textcomponent == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, TextElement, attributes.getValueAsString(NameAttribute), TextComponentElement); + } + d_textcomponent->setText(attributes.getValueAsString(StringAttribute)); d_textcomponent->setFont(attributes.getValueAsString(FontAttribute)); } @@ -835,7 +986,11 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementNamedAreaStart(const XMLAttributes& attributes) { - assert(d_namedArea == 0); + if (d_namedArea != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, NamedAreaElement, attributes.getValueAsString(NameAttribute)); + } + d_namedArea = CEGUI_NEW_AO NamedArea(attributes.getValueAsString(NameAttribute)); CEGUI_LOGINSANE("-----> Creating named area: " + d_namedArea->getName()); @@ -846,7 +1001,12 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementPropertyDefinitionStart(const XMLAttributes& attributes) { - assert(d_widgetlook); + if (d_widgetlook == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, PropertyDefinitionElement, attributes.getValueAsString(NameAttribute), WidgetLookElement); + } + + PropertyDefinitionBase* prop; const String name(attributes.getValueAsString(NameAttribute)); @@ -948,8 +1108,16 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementPropertyLinkDefinitionStart(const XMLAttributes& attributes) { - assert(d_widgetlook); - assert(d_propertyLink == 0); + if (d_widgetlook == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, PropertyLinkDefinitionElement, attributes.getValueAsString(NameAttribute), WidgetLookElement); + } + + if (d_propertyLink != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, PropertyLinkDefinitionElement); + } + const String widget(attributes.getValueAsString(WidgetAttribute)); const String target(attributes.getValueAsString(TargetPropertyAttribute)); @@ -1192,7 +1360,10 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementAreaPropertyStart(const XMLAttributes& attributes) { - assert (d_area != 0); + if (d_area != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, AreaPropertyElement); + } d_area->setAreaPropertySource(attributes.getValueAsString(NameAttribute)); } @@ -1202,7 +1373,11 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementImagePropertyStart(const XMLAttributes& attributes) { - assert(d_imagerycomponent != 0 || d_framecomponent != 0); + if (d_imagerycomponent == 0 && d_framecomponent == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, ImagePropertyElement, attributes.getValueAsString(NameAttribute), + ImageryComponentElement + " or " + FrameComponentElement); + } if (d_imagerycomponent) { @@ -1230,7 +1405,10 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementTextPropertyStart(const XMLAttributes& attributes) { - assert(d_textcomponent != 0); + if (d_textcomponent == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, FontPropertyElement, attributes.getValueAsString(NameAttribute), TextComponentElement); + } d_textcomponent->setTextPropertySource(attributes.getValueAsString(NameAttribute)); } @@ -1240,7 +1418,10 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementFontPropertyStart(const XMLAttributes& attributes) { - assert(d_textcomponent != 0); + if (d_textcomponent == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, FontPropertyElement, attributes.getValueAsString(NameAttribute), TextComponentElement); + } d_textcomponent->setFontPropertySource(attributes.getValueAsString(NameAttribute)); } @@ -1267,13 +1448,12 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementWidgetLookEnd() { - if (d_widgetlook) - { - Logger::getSingleton().logEvent("---< End of definition for widget look '" + d_widgetlook->getName() + "'.", Informative); - d_manager->addWidgetLook(*d_widgetlook); - CEGUI_DELETE_AO d_widgetlook; - d_widgetlook = 0; - } + assert(d_widgetlook != 0); + + Logger::getSingleton().logEvent("---< End of definition for widget look '" + d_widgetlook->getName() + "'.", Informative); + d_manager->addWidgetLook(*d_widgetlook); + CEGUI_DELETE_AO d_widgetlook; + d_widgetlook = 0; } /************************************************************************* @@ -1281,15 +1461,17 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementChildEnd() { - assert(d_widgetlook != 0); + assert(d_childcomponent != 0); - if (d_childcomponent) + if (d_widgetlook == 0) { - CEGUI_LOGINSANE("-----< End of definition for child widget. Type: " + d_childcomponent->getBaseWidgetType() + "."); - d_widgetlook->addWidgetComponent(*d_childcomponent); - CEGUI_DELETE_AO d_childcomponent; - d_childcomponent = 0; + throwExceptionNotChildOfNode(d_widgetlook, ChildElement, d_childcomponent->getWidgetName(), WidgetLookElement); } + + CEGUI_LOGINSANE("-----< End of definition for child widget. Type: " + d_childcomponent->getBaseWidgetType() + "."); + d_widgetlook->addWidgetComponent(*d_childcomponent); + CEGUI_DELETE_AO d_childcomponent; + d_childcomponent = 0; } /************************************************************************* @@ -1297,15 +1479,17 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementImagerySectionEnd() { - assert(d_widgetlook != 0); + assert(d_imagerysection != 0); - if (d_imagerysection) + if (d_widgetlook == 0) { - CEGUI_LOGINSANE("-----< End of definition for imagery section '" + d_imagerysection->getName() + "'."); - d_widgetlook->addImagerySection(*d_imagerysection); - CEGUI_DELETE_AO d_imagerysection; - d_imagerysection = 0; + throwExceptionNotChildOfNode(d_widgetlook, ImagerySectionElement, d_imagerysection->getName(), WidgetLookElement); } + + CEGUI_LOGINSANE("-----< End of definition for imagery section '" + d_imagerysection->getName() + "'."); + d_widgetlook->addImagerySection(*d_imagerysection); + CEGUI_DELETE_AO d_imagerysection; + d_imagerysection = 0; } /************************************************************************* @@ -1313,7 +1497,10 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementStateImageryEnd() { - assert(d_widgetlook != 0); + if (d_widgetlook == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, StateImageryElement, d_stateimagery->getName(), WidgetLookElement); + } if (d_stateimagery) { @@ -1329,15 +1516,17 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementLayerEnd() { - assert(d_stateimagery != 0); + assert(d_layer != 0); - if (d_layer) + if (d_stateimagery == 0) { - CEGUI_LOGINSANE("-------< End of definition of imagery layer."); - d_stateimagery->addLayer(*d_layer); - CEGUI_DELETE_AO d_layer; - d_layer = 0; + throwExceptionNotChildOfNode(d_widgetlook, LayerElement, StateImageryElement); } + + CEGUI_LOGINSANE("-------< End of definition of imagery layer."); + d_stateimagery->addLayer(*d_layer); + CEGUI_DELETE_AO d_layer; + d_layer = 0; } /************************************************************************* @@ -1345,14 +1534,16 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementSectionEnd() { - assert(d_layer != 0); + assert(d_section != 0); - if (d_section) + if (d_layer == 0) { - d_layer->addSectionSpecification(*d_section); - CEGUI_DELETE_AO d_section; - d_section = 0; + throwExceptionNotChildOfNode(d_widgetlook, SectionElement, d_section->getSectionName(), LayerElement); } + + d_layer->addSectionSpecification(*d_section); + CEGUI_DELETE_AO d_section; + d_section = 0; } /************************************************************************* @@ -1360,14 +1551,16 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementImageryComponentEnd() { - assert(d_imagerysection != 0); + assert(d_imagerycomponent != 0); - if (d_imagerycomponent) + if (d_imagerysection == 0) { - d_imagerysection->addImageryComponent(*d_imagerycomponent); - CEGUI_DELETE_AO d_imagerycomponent; - d_imagerycomponent = 0; + throwExceptionNotChildOfNode(d_widgetlook, ImageryComponentElement, ImagerySectionElement); } + + d_imagerysection->addImageryComponent(*d_imagerycomponent); + CEGUI_DELETE_AO d_imagerycomponent; + d_imagerycomponent = 0; } /************************************************************************* @@ -1375,14 +1568,16 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementTextComponentEnd() { - assert(d_imagerysection != 0); + assert(d_textcomponent != 0); - if (d_textcomponent) + if (d_imagerysection == 0) { - d_imagerysection->addTextComponent(*d_textcomponent); - CEGUI_DELETE_AO d_textcomponent; - d_textcomponent = 0; + throwExceptionNotChildOfNode(d_widgetlook, TextComponentElement, ImagerySectionElement); } + + d_imagerysection->addTextComponent(*d_textcomponent); + CEGUI_DELETE_AO d_textcomponent; + d_textcomponent = 0; } /************************************************************************* @@ -1390,14 +1585,16 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementFrameComponentEnd() { - assert(d_imagerysection != 0); + assert(d_framecomponent != 0); - if (d_framecomponent) + if (d_imagerysection == 0) { - d_imagerysection->addFrameComponent(*d_framecomponent); - CEGUI_DELETE_AO d_framecomponent; - d_framecomponent = 0; + throwExceptionNotChildOfNode(d_widgetlook, FrameComponentElement, ImagerySectionElement); } + + d_imagerysection->addFrameComponent(*d_framecomponent); + CEGUI_DELETE_AO d_framecomponent; + d_framecomponent = 0; } /************************************************************************* @@ -1405,9 +1602,14 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementAreaEnd() { - assert((d_childcomponent != 0) || (d_imagerycomponent != 0) || (d_textcomponent != 0) || d_namedArea != 0 || d_framecomponent != 0); assert(d_area != 0); + if ((d_childcomponent == 0) && (d_imagerycomponent == 0) && (d_textcomponent == 0) && d_namedArea == 0 && d_framecomponent == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, AreaElement, ChildElement + " or " + ImageryComponentElement + " or " + + TextComponentElement + " or " + NamedAreaElement + " or " + FrameComponentElement); + } + if (d_childcomponent) { d_childcomponent->setComponentArea(*d_area); @@ -1438,14 +1640,16 @@ namespace CEGUI *************************************************************************/ void Falagard_xmlHandler::elementNamedAreaEnd() { - assert(d_widgetlook != 0); + assert(d_namedArea != 0); - if (d_namedArea) + if (d_widgetlook == 0) { - d_widgetlook->addNamedArea(*d_namedArea); - CEGUI_DELETE_AO d_namedArea; - d_namedArea = 0; + throwExceptionNotChildOfNode(d_widgetlook, NamedAreaElement, d_namedArea->getName(), WidgetLookElement); } + + d_widgetlook->addNamedArea(*d_namedArea); + CEGUI_DELETE_AO d_namedArea; + d_namedArea = 0; } /************************************************************************* @@ -1477,6 +1681,7 @@ namespace CEGUI void Falagard_xmlHandler::elementPropertyLinkDefinitionEnd() { assert(d_propertyLink); + d_widgetlook->addPropertyLinkDefinition(d_propertyLink); CEGUI_LOGINSANE("<----- End of PropertyLinkDefiniton. Name: " + @@ -1486,7 +1691,10 @@ namespace CEGUI void Falagard_xmlHandler::elementPropertyLinkTargetStart(const XMLAttributes& attributes) { - assert(d_propertyLink); + if (d_propertyLink == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, PropertyLinkTargetElement, attributes.getValueAsString(PropertyAttribute), PropertyLinkDefinitionElement); + } const String w(attributes.getValueAsString(WidgetAttribute)); const String p(attributes.getValueAsString(PropertyAttribute)); @@ -1578,7 +1786,10 @@ namespace CEGUI void Falagard_xmlHandler::elementAnimationDefinitionStart( const XMLAttributes& attributes) { - assert(d_widgetlook != 0); + if (d_widgetlook == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, AnimationDefinitionHandler::ElementName, attributes.getValueAsString(NameAttribute), WidgetLookElement); + } String anim_name_prefix(d_widgetlook->getName()); anim_name_prefix.append("/"); @@ -1609,8 +1820,15 @@ namespace CEGUI void Falagard_xmlHandler::elementEventLinkDefinitionStart( const XMLAttributes& attributes) { - assert(d_widgetlook); - assert(d_eventLink == 0); + if (d_widgetlook == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, EventLinkDefinitionElement, attributes.getValueAsString(NameAttribute), WidgetLookElement); + } + + if (d_eventLink != 0) + { + throwExceptionChildOfSameNode(d_widgetlook, EventLinkDefinitionElement); + } const String widget(attributes.getValueAsString(WidgetAttribute)); const String event(attributes.getValueAsString(EventAttribute)); @@ -1626,7 +1844,10 @@ namespace CEGUI void Falagard_xmlHandler::processEventLinkTarget(const String& widget, const String& event) { - assert(d_eventLink); + if (d_eventLink == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, EventLinkTargetElement, EventLinkDefinitionElement); + } if (!widget.empty() || !event.empty()) { @@ -1648,6 +1869,7 @@ namespace CEGUI void Falagard_xmlHandler::elementEventLinkDefinitionEnd() { assert(d_eventLink); + d_widgetlook->addEventLinkDefinition(*d_eventLink); CEGUI_LOGINSANE("<----- End of EventLinkDefiniton. Name: " + @@ -1659,7 +1881,10 @@ namespace CEGUI void Falagard_xmlHandler::elementNamedAreaSourceStart(const XMLAttributes& attributes) { - assert (d_area != 0); + if (d_area == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, NamedAreaElement, AreaElement); + } const String look(attributes.getValueAsString(LookAttribute)); @@ -1669,7 +1894,10 @@ namespace CEGUI void Falagard_xmlHandler::elementEventActionStart(const XMLAttributes& attributes) { - assert(d_childcomponent != 0); + if (d_childcomponent == 0) + { + throwExceptionNotChildOfNode(d_widgetlook, EventActionElement, ChildElement); + } const EventAction action( attributes.getValueAsString(EventAttribute), diff --git a/cegui/src/minibidi.cpp b/cegui/src/minibidi.cpp index 8170e636d..48af1d9ef 100644 --- a/cegui/src/minibidi.cpp +++ b/cegui/src/minibidi.cpp @@ -85,8 +85,8 @@ enum #define leastGreaterEven(x) odd(x) ? (x+1) : (x+2) /* Shaping Helpers */ -#define STYPE(xh) ((xh >= SHAPE_FIRST) && (xh <= SHAPE_LAST)) ? \ - shapetypes[xh-SHAPE_FIRST].type : SU +#define STYPE(xh) ((xh >= SHAPE_FIRST) && (xh <= SHAPE_LAST) ? \ + shapetypes[xh-SHAPE_FIRST].type : static_cast(SU)) #define SISOLATED(xh) shapetypes[xh-SHAPE_FIRST].form_b #define SFINAL(xh) xh+1 #define SINITIAL(xh) xh+2 @@ -1118,7 +1118,7 @@ int doBidi(BLOCKTYPE line, int count, int applyShape, int reorderCombining, int unsigned char* levels; unsigned char paragraphLevel; unsigned char tempType, tempTypeSec; - int i, j, imax, fX, fAL, fET, fNSM, tempInt; + int i, j, fX, fAL, fET, fNSM, tempInt; CHARTYPE* shapeTo; if (v2l) @@ -1589,7 +1589,6 @@ int doBidi(BLOCKTYPE line, int count, int applyShape, int reorderCombining, int * level or higher */ /* we flip the character string and leave the level array */ - imax = 0; i=0; tempType = levels[0]; while(i < count) @@ -1597,11 +1596,10 @@ int doBidi(BLOCKTYPE line, int count, int applyShape, int reorderCombining, int if(levels[i] > tempType) { tempType = levels[i]; - imax=i; } i++; } - /* maximum level in tempType, its index in imax. */ + /* maximum level in tempType */ while(tempType > 0) /* loop from highest level to the least odd, */ { /* which i assume is 1 */ flipThisRun(line, levels, tempType, count, v2l); diff --git a/cegui/src/widgets/ComboDropList.cpp b/cegui/src/widgets/ComboDropList.cpp index 7dc17cbe0..b313e09a1 100644 --- a/cegui/src/widgets/ComboDropList.cpp +++ b/cegui/src/widgets/ComboDropList.cpp @@ -83,8 +83,8 @@ void ComboDropList::initialiseComponents(void) getHorzScrollbar()->setRestoreOldCapture(true); // ban these properties from being written - getVertScrollbar()->banPropertyFromXML("RestoreOldCapture"); - getHorzScrollbar()->banPropertyFromXML("RestoreOldCapture"); + getVertScrollbar()->banPropertyFromXMLRecursive(Window::RestoreOldCapturePropertyName); + getHorzScrollbar()->banPropertyFromXMLRecursive(Window::RestoreOldCapturePropertyName); } //----------------------------------------------------------------------------// diff --git a/cegui/src/widgets/Combobox.cpp b/cegui/src/widgets/Combobox.cpp index 254a588ab..2560cfa90 100644 --- a/cegui/src/widgets/Combobox.cpp +++ b/cegui/src/widgets/Combobox.cpp @@ -113,8 +113,9 @@ void Combobox::initialiseComponents(void) editbox->setFont(d_font); // ban properties forwarded from here - droplist->banPropertyFromXML("Visible"); + droplist->banPropertyFromXML(Window::VisiblePropertyName); editbox->banPropertyFromXML("MaxTextLength"); + editbox->banPropertyFromXML("ReadOnly"); // internal event wiring button->subscribeEvent(PushButton::EventMouseButtonDown, Event::Subscriber(&CEGUI::Combobox::button_PressHandler, this)); diff --git a/cegui/src/widgets/GridLayoutContainer.cpp b/cegui/src/widgets/GridLayoutContainer.cpp index a91705ae7..6aaf383fd 100644 --- a/cegui/src/widgets/GridLayoutContainer.cpp +++ b/cegui/src/widgets/GridLayoutContainer.cpp @@ -30,6 +30,15 @@ #include "CEGUI/CoordConverter.h" #include +#ifdef __MINGW32__ + + /* Due to a bug in MinGW-w64, a false warning is sometimes issued when using + "%llu" format with the "printf"/"scanf" family of functions. */ + #pragma GCC diagnostic ignored "-Wformat" + #pragma GCC diagnostic ignored "-Wformat-extra-args" + +#endif + // Start of CEGUI namespace section namespace CEGUI { @@ -371,6 +380,7 @@ size_t GridLayoutContainer::mapFromGridToIdx(size_t gridX, assert(gridX < gridWidth); assert(gridY < gridHeight); + CEGUI_UNUSED(gridHeight); // silence warning in release builds return gridY * gridWidth + gridX; } @@ -392,6 +402,7 @@ void GridLayoutContainer::mapFromIdxToGrid(size_t idx, } assert(gridY < gridHeight); + CEGUI_UNUSED(gridHeight); // silence warning in release builds gridX = idx; } @@ -459,7 +470,8 @@ size_t GridLayoutContainer::translateAPToGridIdx(size_t APIdx) const // 1 3 5 // 2 4 6 - size_t x, y; + size_t x = 0; + size_t y = 0; bool done = false; for (x = 0; x < d_gridWidth; ++x) @@ -494,7 +506,7 @@ size_t GridLayoutContainer::translateAPToGridIdx(size_t APIdx) const Window* GridLayoutContainer::createDummy() { char i_buff[32]; - sprintf(i_buff, "%lu", d_nextDummyIdx); + sprintf(i_buff, "%llu", static_cast(d_nextDummyIdx)); ++d_nextDummyIdx; Window* dummy = WindowManager::getSingleton().createWindow("DefaultWindow", @@ -620,3 +632,7 @@ void GridLayoutContainer::addGridLayoutContainerProperties(void) //----------------------------------------------------------------------------// } // End of CEGUI namespace section + +#ifdef __MINGW32__ + #pragma GCC diagnostic pop +#endif diff --git a/cegui/src/widgets/ListboxTextItem.cpp b/cegui/src/widgets/ListboxTextItem.cpp index 9b6c69801..0343f8987 100644 --- a/cegui/src/widgets/ListboxTextItem.cpp +++ b/cegui/src/widgets/ListboxTextItem.cpp @@ -74,12 +74,9 @@ const Font* ListboxTextItem::getFont(void) const { return d_owner->getFont(); } - // no owner, just use the default (which may be NULL anyway) - else - { - return System::getSingleton().getDefaultGUIContext().getDefaultFont(); - } - + // no owner, so the default font is ambiguous (it could be of any context) + else + return 0; } @@ -191,10 +188,10 @@ void ListboxTextItem::parseTextString() const { if (d_textParsingEnabled) d_renderedString = - d_stringParser.parse(getTextVisual(), const_cast(getFont()), &d_textCols); + d_stringParser.parse(getTextVisual(), 0, &d_textCols); else d_renderedString = - d_noTagsStringParser.parse(getTextVisual(), const_cast(getFont()), &d_textCols); + d_noTagsStringParser.parse(getTextVisual(), 0, &d_textCols); d_renderedStringValid = true; } diff --git a/cegui/src/widgets/MultiLineEditbox.cpp b/cegui/src/widgets/MultiLineEditbox.cpp index 940abf3cc..5138308ce 100644 --- a/cegui/src/widgets/MultiLineEditbox.cpp +++ b/cegui/src/widgets/MultiLineEditbox.cpp @@ -751,7 +751,7 @@ bool MultiLineEditbox::performPaste(Clipboard& clipboard) eraseSelectedText(); // if there is room - if (getText().length() - clipboardText.length() < d_maxTextLen) + if (getText().length() + clipboardText.length() < d_maxTextLen) { String newText = getText(); newText.insert(getCaretIndex(), clipboardText); diff --git a/cegui/src/widgets/ScrollablePane.cpp b/cegui/src/widgets/ScrollablePane.cpp index 772d91a25..cae88828e 100644 --- a/cegui/src/widgets/ScrollablePane.cpp +++ b/cegui/src/widgets/ScrollablePane.cpp @@ -3,7 +3,7 @@ author: Paul D Turner *************************************************************************/ /*************************************************************************** - * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team + * Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -235,6 +235,13 @@ void ScrollablePane::initialiseComponents(void) // get scrolled container widget ScrolledContainer* container = getScrolledContainer(); + // ban properties forwarded from here + container->banPropertyFromXML(Window::MouseInputPropagationEnabledPropertyName); + container->banPropertyFromXML("ContentArea"); + container->banPropertyFromXML("ContentPaneAutoSized"); + horzScrollbar->banPropertyFromXML(Window::AlwaysOnTopPropertyName); + vertScrollbar->banPropertyFromXML(Window::AlwaysOnTopPropertyName); + // do a bit of initialisation horzScrollbar->setAlwaysOnTop(true); vertScrollbar->setAlwaysOnTop(true); @@ -620,4 +627,32 @@ NamedElement* ScrollablePane::getChildByNamePath_impl(const String& name_path) c } //----------------------------------------------------------------------------// -} // End of CEGUI namespace section +int ScrollablePane::writeChildWindowsXML(XMLSerializer& xml_stream) const +{ + // This is an easy and safe workaround for not writing out the buttonPane and contentPane. While in fact + // we would eventually want to write these two to XML themselves, we do not want to write out their children + // but there is no way to control this from inside these windows and currently there is also no way to do it + // from the outside. This was determined to be the best solution, others would break ABI or are too hacky + // Negative side-effects: any changes to AutoWindows (properties etc) will be lost in the output + bool wasContentPaneWritingAllowed = getScrolledContainer()->isWritingXMLAllowed(); + + getScrolledContainer()->setWritingXMLAllowed(false); + + int childOutputCount = Window::writeChildWindowsXML(xml_stream); + + getScrolledContainer()->setWritingXMLAllowed(wasContentPaneWritingAllowed); + + // since TabControl content is actually added to the component tab + // content pane window, this overridden function exists to dump those + // out as if they were our own children. + const size_t childCount = getContentPane()->getChildCount(); + for (size_t i = 0; i < childCount; ++i) + { + getScrolledContainer()->getChildAtIdx(i)->writeXMLToStream(xml_stream); + ++childOutputCount; + } + + return childOutputCount; +} + +} diff --git a/cegui/src/widgets/Spinner.cpp b/cegui/src/widgets/Spinner.cpp index 4d6958d89..79dd4e56c 100644 --- a/cegui/src/widgets/Spinner.cpp +++ b/cegui/src/widgets/Spinner.cpp @@ -81,6 +81,14 @@ namespace CEGUI PushButton* decreaseButton = getDecreaseButton(); Editbox* editbox = getEditbox(); + // ban properties forwarded from here + editbox->banPropertyFromXML(Window::TextPropertyName); + editbox->banPropertyFromXML("ValidationString"); + increaseButton->banPropertyFromXML(Window::WantsMultiClickEventsPropertyName); + increaseButton->banPropertyFromXML(Window::MouseAutoRepeatEnabledPropertyName); + decreaseButton->banPropertyFromXML(Window::WantsMultiClickEventsPropertyName); + decreaseButton->banPropertyFromXML(Window::MouseAutoRepeatEnabledPropertyName); + // setup component controls increaseButton->setWantsMultiClickEvents(false); increaseButton->setMouseAutoRepeatEnabled(true); diff --git a/cegui/src/widgets/TabControl.cpp b/cegui/src/widgets/TabControl.cpp index 80540031e..ae1ce5070 100644 --- a/cegui/src/widgets/TabControl.cpp +++ b/cegui/src/widgets/TabControl.cpp @@ -5,7 +5,7 @@ purpose: Implementation of Tab Control widget base class *************************************************************************/ /*************************************************************************** - * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team + * Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -100,6 +100,20 @@ TabControl::~TabControl(void) *************************************************************************/ void TabControl::initialiseComponents(void) { + // ban properties forwarded from here + if (isChild(ButtonScrollLeft)) + { + CEGUI::Window* buttonScrollLeft = getChild(ButtonScrollLeft); + buttonScrollLeft->banPropertyFromXML(Window::VisiblePropertyName); + buttonScrollLeft->banPropertyFromXML(Window::WantsMultiClickEventsPropertyName); + } + if (isChild(ButtonScrollRight)) + { + CEGUI::Window* buttonScrollRight = getChild(ButtonScrollRight); + buttonScrollRight->banPropertyFromXML(Window::VisiblePropertyName); + buttonScrollRight->banPropertyFromXML(Window::WantsMultiClickEventsPropertyName); + } + performChildWindowLayout(); if (isChild(ButtonScrollLeft)) @@ -671,8 +685,22 @@ Window* TabControl::getTabPane() const int TabControl::writeChildWindowsXML(XMLSerializer& xml_stream) const { + // This is an easy and safe workaround for not writing out the buttonPane and contentPane. While in fact + // we would eventually want to write these two to XML themselves, we do not want to write out their children + // but there is no way to control this from inside these windows and currently there is also no way to do it + // from the outside. This was determined to be the best solution, others would break ABI or are too hacky + // Negative side-effects: any changes to AutoWindows (properties etc) will be lost in the output + bool wasButtonPaneWritingAllowed = getTabButtonPane()->isWritingXMLAllowed(); + bool wasContentPaneWritingAllowed = getTabPane()->isWritingXMLAllowed(); + + getTabButtonPane()->setWritingXMLAllowed(false); + getTabPane()->setWritingXMLAllowed(false); + int childOutputCount = Window::writeChildWindowsXML(xml_stream); + getTabButtonPane()->setWritingXMLAllowed(wasButtonPaneWritingAllowed); + getTabPane()->setWritingXMLAllowed(wasContentPaneWritingAllowed); + // since TabControl content is actually added to the component tab // content pane window, this overridden function exists to dump those // out as if they were our own children. diff --git a/cegui/src/widgets/Tooltip.cpp b/cegui/src/widgets/Tooltip.cpp index 676112975..f95113f1b 100644 --- a/cegui/src/widgets/Tooltip.cpp +++ b/cegui/src/widgets/Tooltip.cpp @@ -66,6 +66,7 @@ namespace CEGUI setClippedByParent(false); setDestroyedByParent(false); setAlwaysOnTop(true); + setMousePassThroughEnabled(true); // we need updates even when not visible setUpdateMode(WUM_ALWAYS); @@ -146,7 +147,7 @@ namespace CEGUI } // set text to that of the tooltip text of the target - setText(wnd->getTooltipText()); + setText(wnd->getTooltipTextIncludingInheritance()); // set size and position of the tooltip window. sizeSelf(); @@ -237,7 +238,7 @@ namespace CEGUI void Tooltip::doActiveState(float elapsed) { // if no target, switch immediately to inactive state. - if (!d_target || d_target->getTooltipText().empty()) + if (!d_target || d_target->getTooltipTextIncludingInheritance().empty()) { // hide immediately since the text is empty hide(); @@ -254,7 +255,7 @@ namespace CEGUI void Tooltip::doInactiveState(float elapsed) { - if (d_target && !d_target->getTooltipText().empty() && ((d_elapsed += elapsed) >= d_hoverTime)) + if (d_target && !d_target->getTooltipTextIncludingInheritance().empty() && ((d_elapsed += elapsed) >= d_hoverTime)) { switchToActiveState(); } diff --git a/cegui/src/widgets/TreeItem.cpp b/cegui/src/widgets/TreeItem.cpp index adf433efb..a5d690e99 100644 --- a/cegui/src/widgets/TreeItem.cpp +++ b/cegui/src/widgets/TreeItem.cpp @@ -158,9 +158,9 @@ const Font* TreeItem::getFont(void) const // (may be null if owner uses non existant default font) else if (d_owner != 0) return d_owner->getFont(); - // no owner, just use the default (which may be NULL anyway) + // no owner, so the default font is ambiguous (it could be of any context) else - return System::getSingleton().getDefaultGUIContext().getDefaultFont(); + return 0; } /************************************************************************* @@ -361,7 +361,7 @@ void TreeItem::setText( const String& text ) void TreeItem::parseTextString() const { d_renderedString = - d_stringParser.parse(getTextVisual(), const_cast(getFont()), &d_textCols); + d_stringParser.parse(getTextVisual(), 0, &d_textCols); d_renderedStringValid = true; } diff --git a/cmake/CEGUIMacros.cmake b/cmake/CEGUIMacros.cmake index 09bd74c32..d2d3ffc42 100644 --- a/cmake/CEGUIMacros.cmake +++ b/cmake/CEGUIMacros.cmake @@ -87,6 +87,8 @@ macro (cegui_add_dependency_dynamic_libs _TARGET_NAME _DEP_NAME) else() target_link_libraries(${_TARGET_NAME} ${${_DEP_NAME}_LIBRARIES}) endif() + elseif (${_DEP_NAME}_LIBRARIES_DBG) + target_link_libraries(${_TARGET_NAME} ${${_DEP_NAME}_LIBRARIES_DBG}) endif() endif() endmacro() @@ -110,6 +112,8 @@ macro (cegui_add_dependency_static_libs _TARGET_NAME _DEP_NAME) else() target_link_libraries(${_TARGET_NAME} ${${_DEP_NAME}_LIBRARIES_STATIC}) endif() + elseif (${_DEP_NAME}_LIBRARIES_STATIC_DBG) + target_link_libraries(${_TARGET_NAME} ${${_DEP_NAME}_LIBRARIES_STATIC_DBG}) else() cegui_add_dependency_dynamic_libs(${_TARGET_NAME} ${_DEP_NAME}) endif() @@ -117,10 +121,48 @@ macro (cegui_add_dependency_static_libs _TARGET_NAME _DEP_NAME) endmacro() # -# add a dependency to a target (and it's static equivalent, if it exists) +# add a dependency to a target (and it's static equivalent, if it exists). +# +# An optional "SCOPE" 3rd argument can be specified to determine the "scope" +# argument passed to "target_include_directories". This argument can be one of +# "INTERFACE", "PUBLIC" and "PRIVATE", the default being "PRIVATE". In general, +# u should use "PUBLIC" if every target that depends on "_TARGET_NAME" should also +# compile with "_DEP_NAME"'s include directories. Please refer to the +# documentation of "target_include_directories" for more details. +# +# An optional "IS_SYSTEM" 4th argument can be specified to determine whether to +# treat the headers of the dependency as system headers. This usually means that +# the compiler won't generate warnings for these headers. The default is +# "FALSE". # macro (cegui_add_dependency _TARGET_NAME _DEP_NAME) - include_directories(${${_DEP_NAME}_INCLUDE_DIR}) +# Optional additional arguments: "SCOPE" "IS_SYSTEM" + get_target_property(_DYNAMIC_EXISTS ${_TARGET_NAME} TYPE) + get_target_property(_STATIC_EXISTS ${_TARGET_NAME}_Static TYPE) + if ("${ARGC}" GREATER 2) + if (("${ARGC}" GREATER 3) AND "${ARGV3}") + if (_DYNAMIC_EXISTS) + target_include_directories(${_TARGET_NAME} SYSTEM "${ARGV2}" ${${_DEP_NAME}_INCLUDE_DIR}) + endif() + if (_STATIC_EXISTS) + target_include_directories(${_TARGET_NAME}_Static SYSTEM "${ARGV2}" ${${_DEP_NAME}_INCLUDE_DIR}) + endif() + else () + if (_DYNAMIC_EXISTS) + target_include_directories(${_TARGET_NAME} "${ARGV2}" ${${_DEP_NAME}_INCLUDE_DIR}) + endif() + if (_STATIC_EXISTS) + target_include_directories(${_TARGET_NAME}_Static "${ARGV2}" ${${_DEP_NAME}_INCLUDE_DIR}) + endif() + endif () + else () + if (_DYNAMIC_EXISTS) + target_include_directories(${_TARGET_NAME} PRIVATE ${${_DEP_NAME}_INCLUDE_DIR}) + endif() + if (_STATIC_EXISTS) + target_include_directories(${_TARGET_NAME}_Static PRIVATE ${${_DEP_NAME}_INCLUDE_DIR}) + endif() + endif () ########################################################################### # NON-STATIC VERSION OF TARGET @@ -147,8 +189,6 @@ macro (cegui_add_dependency _TARGET_NAME _DEP_NAME) ########################################################################### # ADD DEPENDENCY DEFS TO STATIC VERSION OF TARGET (if it exists) ########################################################################### - get_target_property(_STATIC_EXISTS ${_TARGET_NAME}_Static TYPE) - if (_STATIC_EXISTS) if (${_DEP_NAME}_DEFINITIONS) set_property( TARGET ${_TARGET_NAME}_Static APPEND PROPERTY COMPILE_DEFINITIONS ${${_DEP_NAME}_DEFINITIONS} ) @@ -240,7 +280,7 @@ macro (cegui_add_library_impl _LIB_NAME _IS_MODULE _SOURCE_FILES_VAR _HEADER_FIL # Do not version modules, since we dlopen these directly and need to know # the name is what we think it will be (and not rely on symlinks which will # not be installed always, but usually only as part of *-dev packages). - if (NOT ${_IS_MODULE}) + if (NOT ${_IS_MODULE} AND NOT ANDROID) if (NOT APPLE OR CEGUI_APPLE_DYLIB_SET_VERSION_INFO) set_target_properties(${_LIB_NAME} PROPERTIES VERSION ${CEGUI_ABI_VERSION} @@ -260,23 +300,23 @@ macro (cegui_add_library_impl _LIB_NAME _IS_MODULE _SOURCE_FILES_VAR _HEADER_FIL endif() install(TARGETS ${_LIB_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${_CEGUI_LIB_DEST} - ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} + RUNTIME DESTINATION bin COMPONENT cegui_bin + LIBRARY DESTINATION ${_CEGUI_LIB_DEST} COMPONENT cegui_lib + ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_devel ) if (CEGUI_BUILD_STATIC_CONFIGURATION) install(TARGETS ${_LIB_NAME}_Static - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} + RUNTIME DESTINATION bin COMPONENT cegui_bin + LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_lib + ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_devel ) endif() endif() if (${_INSTALL_HEADERS}) string (REPLACE "cegui/src/" "" _REL_HEADER_DIR ${_REL_SRC_DIR}) - install(FILES ${${_HEADER_FILES_VAR}} DESTINATION "${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI/${_REL_HEADER_DIR}") + install(FILES ${${_HEADER_FILES_VAR}} DESTINATION "${CEGUI_INCLUDE_INSTALL_DIR}/CEGUI/${_REL_HEADER_DIR}" COMPONENT cegui_devel) endif() endmacro() @@ -377,16 +417,16 @@ macro (cegui_add_sample _NAME) # Setup custom install location install(TARGETS ${CEGUI_TARGET_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR} - ARCHIVE DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR} + RUNTIME DESTINATION bin COMPONENT cegui_samples + LIBRARY DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR} COMPONENT cegui_samples + ARCHIVE DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR} COMPONENT cegui_samples ) if (CEGUI_BUILD_STATIC_CONFIGURATION) install(TARGETS ${CEGUI_TARGET_NAME}_Static - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR} - ARCHIVE DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR} + RUNTIME DESTINATION bin COMPONENT cegui_samples + LIBRARY DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR} COMPONENT cegui_samples + ARCHIVE DESTINATION ${CEGUI_SAMPLE_INSTALL_DIR} COMPONENT cegui_samples ) endif() @@ -410,7 +450,7 @@ endmacro() macro( cegui_add_python_module PYTHON_MODULE_NAME SOURCE_DIR EXTRA_LIBS ) file( GLOB ${PYTHON_MODULE_NAME}_SOURCE_FILES ${SOURCE_DIR}/*.cpp ) - include_directories(BEFORE ${SOURCE_DIR}) + include_directories(BEFORE SYSTEM ${SOURCE_DIR}) add_library(${PYTHON_MODULE_NAME} MODULE ${${PYTHON_MODULE_NAME}_SOURCE_FILES}) target_link_libraries(${PYTHON_MODULE_NAME} ${CEGUI_BASE_LIBNAME} ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES} ${EXTRA_LIBS} ) @@ -430,7 +470,7 @@ macro( cegui_add_python_module PYTHON_MODULE_NAME SOURCE_DIR EXTRA_LIBS ) set_target_properties(${PYTHON_MODULE_NAME} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") endif() - install(TARGETS ${PYTHON_MODULE_NAME} LIBRARY DESTINATION "${CEGUI_PYTHON_INSTALL_DIR}") + install(TARGETS ${PYTHON_MODULE_NAME} LIBRARY DESTINATION "${CEGUI_PYTHON_INSTALL_DIR}" COMPONENT cegui_python) endmacro() # @@ -441,7 +481,7 @@ macro (cegui_add_test_executable _NAME) cegui_gather_files() - include_directories(${Boost_INCLUDE_DIR}) + include_directories(SYSTEM ${Boost_INCLUDE_DIR}) ########################################################################### # Statically Linked Executable @@ -515,16 +555,16 @@ macro (cegui_add_test_executable _NAME) # INSTALLATION ########################################################################### install(TARGETS ${CEGUI_TARGET_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} + RUNTIME DESTINATION bin COMPONENT cegui_bin + LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_lib + ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_devel ) if (CEGUI_BUILD_STATIC_CONFIGURATION) install(TARGETS ${CEGUI_TARGET_NAME}_Static - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} + RUNTIME DESTINATION bin COMPONENT cegui_bin + LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_lib + ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_devel ) endif() @@ -564,7 +604,10 @@ endmacro() # # NOTE: On platforms where the dependency pack is not intended to be used, the # extra library configurations are NOT checked, on those platforms we will use -# the base library only. +# the base library only. Also note that on those platforms, if only release +# libraries are available we'll always use them (regardless of +# "CMAKE_CONFIGURATION_TYPES" and "CMAKE_BUILD_TYPE"), and if only debug +# libraries are available we'll always use them. # # _PKGNAME: The name of package we're checking for. # _LIBBASENAMEVAR: name of the library base name variable. This name will be @@ -597,28 +640,21 @@ macro (cegui_find_package_handle_standard_args _PKGNAME _LIBBASENAMEVAR) unset (_WANT_REL_LIBS) endif() - if (CEGUI_BUILD_SHARED_LIBS_WITH_STATIC_DEPENDENCIES) - if (_WANT_REL_LIBS) + if (CEGUI_BUILD_SHARED_LIBS_WITH_STATIC_DEPENDENCIES OR CEGUI_BUILD_STATIC_CONFIGURATION) + if ((_WANT_REL_LIBS AND ${_LIBBASENAMEVAR}_STATIC) OR NOT ${_LIBBASENAMEVAR}_STATIC_DBG) list(APPEND _FPHSA_LIBS ${_LIBBASENAMEVAR}_STATIC) endif() - if (_WANT_DBG_LIBS) + if ((_WANT_DBG_LIBS AND ${_LIBBASENAMEVAR}_STATIC_DBG) OR NOT ${_LIBBASENAMEVAR}_STATIC) list(APPEND _FPHSA_LIBS ${_LIBBASENAMEVAR}_STATIC_DBG) endif() - else() - if (_WANT_REL_LIBS) + endif () + if (NOT CEGUI_BUILD_SHARED_LIBS_WITH_STATIC_DEPENDENCIES) + if ((_WANT_REL_LIBS AND ${_LIBBASENAMEVAR}) OR NOT ${_LIBBASENAMEVAR}_DBG) list(APPEND _FPHSA_LIBS ${_LIBBASENAMEVAR}) endif() - if (_WANT_DBG_LIBS) + if ((_WANT_DBG_LIBS AND ${_LIBBASENAMEVAR}_DBG) OR NOT ${_LIBBASENAMEVAR}) list(APPEND _FPHSA_LIBS ${_LIBBASENAMEVAR}_DBG) endif() - if (CEGUI_BUILD_STATIC_CONFIGURATION) - if (_WANT_REL_LIBS) - list(APPEND _FPHSA_LIBS ${_LIBBASENAMEVAR}_STATIC) - endif() - if (_WANT_DBG_LIBS) - list(APPEND _FPHSA_LIBS ${_LIBBASENAMEVAR}_STATIC_DBG) - endif() - endif() endif() else() set(_FPHSA_LIBS ${_LIBBASENAMEVAR}) @@ -669,3 +705,54 @@ macro(cegui_defaultmodule_sanity_test _DEFAULTVAR _MODNAME _BUILDVAR) endif() endmacro() +set( _TMP_C_PLUS_PLUS_SRC_FILE_NAME "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx" ) + +macro( cegui_check_mingw ) + set( CEGUI_MINGW_W64_FOUND FALSE ) + if( MINGW ) + if( CMAKE_CROSSCOMPILING ) + file( WRITE "${_TMP_C_PLUS_PLUS_SRC_FILE_NAME}" " + #include + #ifndef __MINGW64_VERSION_MAJOR + #error \"The compiler isn't MinGW-w64.\" + #endif + __MINGW64_VERSION_MAJOR.__MINGW64_VERSION_MINOR" ) + execute_process( + COMMAND /usr/bin/env bash -c -o pipefail "''${CMAKE_CXX_COMPILER} -E ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}} \"${_TMP_C_PLUS_PLUS_SRC_FILE_NAME}\" | tail -1''" + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE _FIND_MINGW_W64_VER__RUN_RESULT + OUTPUT_VARIABLE _FIND_MINGW_W64_VER__RESULT + TIMEOUT 60 ) + if( _FIND_MINGW_W64_VER__RUN_RESULT EQUAL 0 ) + set( CEGUI_MINGW_W64_FOUND TRUE ) + endif() + else() + file( WRITE "${_TMP_C_PLUS_PLUS_SRC_FILE_NAME}" " + #include + #ifndef __MINGW64_VERSION_MAJOR + #error \"The compiler isn't MinGW-w64.\" + #endif + #include + int main() + { + std::cout << __MINGW64_VERSION_MAJOR << \".\" << __MINGW64_VERSION_MINOR << std::flush; + }" ) + try_run( _FIND_MINGW_W64_VER__RUN_RESULT + _FIND_MINGW_W64_VER__BUILD_RESULT + "${PROJECT_BINARY_DIR}" + "${_TMP_C_PLUS_PLUS_SRC_FILE_NAME}" + RUN_OUTPUT_VARIABLE _FIND_MINGW_W64_VER__RESULT ) + if( _FIND_MINGW_W64_VER__BUILD_RESULT AND (_FIND_MINGW_W64_VER__RUN_RESULT EQUAL 0) ) + set( CEGUI_MINGW_W64_FOUND TRUE ) + endif() + endif() + if( CEGUI_MINGW_W64_FOUND ) + string( REPLACE " " "" CEGUI_MINGW_W64_VER "${_FIND_MINGW_W64_VER__RESULT}" ) + if( CEGUI_MINGW_W64_VER VERSION_LESS 3.1 ) + message( WARNING "If you use MinGW-w64, only version 3.1 and up is officially supported. Note: that's MinGW-w64's version, *not* GCC's version!" ) + endif() + else() + message( WARNING "If you use MinGW, only the MinGW-w64 flavour (version 3.1 and up) is officially supported. Note: that's MinGW-w64's version, *not* GCC's version! " ) + endif() + endif() +endmacro() diff --git a/cmake/FindDirectXSDK.cmake b/cmake/FindDirectXSDK.cmake index 35b36c79e..7f601d887 100644 --- a/cmake/FindDirectXSDK.cmake +++ b/cmake/FindDirectXSDK.cmake @@ -3,39 +3,51 @@ ################################################################################ include(FindPackageHandleStandardArgs) -if (CMAKE_SIZEOF_VOID_P EQUAL 4) - set (DIRECTXSDK_ARCH x86) -else() - set (DIRECTXSDK_ARCH x64) -endif() - -find_path(DIRECTXSDK_H_PATH NAMES d3d10.h PATHS ENV DXSDK_DIR PATH_SUFFIXES Include NO_DEFAULT_PATH) -find_path(DIRECTXSDK_LIB_PATH NAMES d3dx10d.lib PATHS ENV DXSDK_DIR PATH_SUFFIXES "Lib/${DIRECTXSDK_ARCH}") - -# now test for the specific d3d lib versions and set MAX_D3D accordingly -if (EXISTS "${DIRECTXSDK_LIB_PATH}/d3d11.lib") - set (DIRECTXSDK_MAX_D3D 11) -elseif (EXISTS "${DIRECTXSDK_LIB_PATH}/d3d10.lib") - set (DIRECTXSDK_MAX_D3D 10) -elseif (EXISTS "${DIRECTXSDK_LIB_PATH}/d39.lib") - set (DIRECTXSDK_MAX_D3D 9) -else() - set (DIRECTXSDK_MAX_D3D) -endif() - -find_package_handle_standard_args(DIRECTXSDK DEFAULT_MSG DIRECTXSDK_LIB_PATH DIRECTXSDK_H_PATH DIRECTXSDK_MAX_D3D) - -mark_as_advanced(DIRECTXSDK_H_PATH DIRECTXSDK_LIB_PATH DIRECTXSDK_ARCH) - -# set up output vars -if (DIRECTXSDK_FOUND) - set (DIRECTXSDK_INCLUDE_DIR ${DIRECTXSDK_H_PATH}) - set (DIRECTXSDK_LIBRARY_DIR ${DIRECTXSDK_LIB_PATH}) -else() - set (DIRECTXSDK_INCLUDE_DIR) - set (DIRECTXSDK_LIBRARY_DIR) - set (DIRECTXSDK_MAX_D3D) -endif() - - - +# MinGW comes with its own DirectX SDK. Therefore, there's no need to look for +# it, or use any include or library directories for it to build. +if (MINGW) + + set (DIRECTXSDK_FOUND TRUE) + if( CEGUI_MINGW_W64_FOUND AND (CEGUI_MINGW_W64_VER VERSION_LESS 4) ) + set( DIRECTXSDK_MAX_D3D 10 ) + else() + set (DIRECTXSDK_MAX_D3D 11) + endif() + +else () + + if (CMAKE_SIZEOF_VOID_P EQUAL 4) + set (DIRECTXSDK_ARCH x86) + else() + set (DIRECTXSDK_ARCH x64) + endif() + + find_path(DIRECTXSDK_H_PATH NAMES d3d10.h PATHS ENV DXSDK_DIR PATH_SUFFIXES Include NO_DEFAULT_PATH) + find_path(DIRECTXSDK_LIB_PATH NAMES d3dx10d.lib PATHS ENV DXSDK_DIR PATH_SUFFIXES "Lib/${DIRECTXSDK_ARCH}") + + # now test for the specific d3d lib versions and set MAX_D3D accordingly + if (EXISTS "${DIRECTXSDK_LIB_PATH}/d3d11.lib") + set (DIRECTXSDK_MAX_D3D 11) + elseif (EXISTS "${DIRECTXSDK_LIB_PATH}/d3d10.lib") + set (DIRECTXSDK_MAX_D3D 10) + elseif (EXISTS "${DIRECTXSDK_LIB_PATH}/d3d9.lib") + set (DIRECTXSDK_MAX_D3D 9) + else() + set (DIRECTXSDK_MAX_D3D) + endif() + + find_package_handle_standard_args(DIRECTXSDK DEFAULT_MSG DIRECTXSDK_LIB_PATH DIRECTXSDK_H_PATH DIRECTXSDK_MAX_D3D) + + mark_as_advanced(DIRECTXSDK_H_PATH DIRECTXSDK_LIB_PATH DIRECTXSDK_ARCH) + + # set up output vars + if (DIRECTXSDK_FOUND) + set (DIRECTXSDK_INCLUDE_DIR ${DIRECTXSDK_H_PATH}) + set (DIRECTXSDK_LIBRARY_DIR ${DIRECTXSDK_LIB_PATH}) + else() + set (DIRECTXSDK_INCLUDE_DIR) + set (DIRECTXSDK_LIBRARY_DIR) + set (DIRECTXSDK_MAX_D3D) + endif() + +endif () diff --git a/cmake/FindEpoxy.cmake b/cmake/FindEpoxy.cmake new file mode 100644 index 000000000..b39b42461 --- /dev/null +++ b/cmake/FindEpoxy.cmake @@ -0,0 +1,23 @@ +################################################################################ +# Custom cmake module for CEGUI to find Epoxy. +################################################################################ +include(FindPackageHandleStandardArgs) + +find_path(EPOXY_H_PATH NAMES epoxy/gl.h) +find_library(EPOXY_LIB NAMES epoxy epoxy_0) +mark_as_advanced(EPOXY_H_PATH EPOXY_LIB EPOXY_LIB_DBG) + +find_package_handle_standard_args(EPOXY DEFAULT_MSG EPOXY_LIB EPOXY_H_PATH) + +# set up output vars +if (EPOXY_FOUND) + set (EPOXY_INCLUDE_DIR ${EPOXY_H_PATH}) + set (EPOXY_LIBRARIES ${EPOXY_LIB}) + if (EPOXY_LIB_DBG) + set (EPOXY_LIBRARIES_DBG ${EPOXY_LIB_DBG}) + endif() +else() + set (EPOXY_INCLUDE_DIR) + set (EPOXY_LIBRARIES) + set (EPOXY_LIBRARIES_DBG) +endif() diff --git a/cmake/FindFreetype.cmake b/cmake/FindFreetype.cmake index 3cbff63aa..974d752ac 100644 --- a/cmake/FindFreetype.cmake +++ b/cmake/FindFreetype.cmake @@ -3,10 +3,10 @@ ################################################################################ include(FindPackageHandleStandardArgs) -find_path(FREETYPE_H_PATH_ft2build NAMES ft2build.h PATH_SUFFIXES include/freetype2 include) +find_path(FREETYPE_H_PATH_ft2build NAMES ft2build.h PATH_SUFFIXES include/freetype2 include freetype2) find_path(FREETYPE_H_PATH_ftconfig NAMES freetype/config/ftconfig.h PATH_SUFFIXES freetype2) if (NOT FREETYPE_H_PATH_ftconfig) - find_path(FREETYPE_H_PATH_ftconfig NAMES config/ftconfig.h PATH_SUFFIXES include/freetype2 include) + find_path(FREETYPE_H_PATH_ftconfig NAMES config/ftconfig.h PATH_SUFFIXES include/freetype2 include freetype2) endif() find_library(FREETYPE_LIB NAMES freetype2 freetype libfreetype PATH_SUFFIXES dynamic) diff --git a/cmake/FindGLEW.cmake b/cmake/FindGLEW.cmake index e603ebf68..6b6979a7f 100644 --- a/cmake/FindGLEW.cmake +++ b/cmake/FindGLEW.cmake @@ -4,13 +4,13 @@ include(FindPackageHandleStandardArgs) find_path(GLEW_H_PATH NAMES GL/glew.h) -find_library(GLEW_LIB NAMES GLEW libGLEW PATH_SUFFIXES dynamic) -find_library(GLEW_LIB_DBG NAMES GLEW_d libGLEW_d PATH_SUFFIXES dynamic) +find_library(GLEW_LIB NAMES GLEW libGLEW glew libglew PATH_SUFFIXES dynamic) +find_library(GLEW_LIB_DBG NAMES GLEW_d libGLEW_d glew_d libglew_d PATH_SUFFIXES dynamic) mark_as_advanced(GLEW_H_PATH GLEW_LIB GLEW_LIB_DBG) if (WIN32 OR APPLE) - find_library(GLEW_LIB_STATIC NAMES GLEW libGLEW PATH_SUFFIXES static) - find_library(GLEW_LIB_STATIC_DBG NAMES GLEW_d libGLEW_d PATH_SUFFIXES static) + find_library(GLEW_LIB_STATIC NAMES GLEW libGLEW glew libglew PATH_SUFFIXES static) + find_library(GLEW_LIB_STATIC_DBG NAMES GLEW_d libGLEW_d glew_d libglew_d PATH_SUFFIXES static) mark_as_advanced(GLEW_LIB_STATIC GLEW_LIB_STATIC_DBG) endif() diff --git a/cmake/FindGLFW3.cmake b/cmake/FindGLFW3.cmake new file mode 100644 index 000000000..55b853386 --- /dev/null +++ b/cmake/FindGLFW3.cmake @@ -0,0 +1,49 @@ +################################################################################ +# Custom cmake module for CEGUI to find glfw3 +################################################################################ +include(FindPackageHandleStandardArgs) + +find_path(GLFW3_H_PATH NAMES GLFW/glfw3.h) +find_library(GLFW3_LIB NAMES glfw3 glfw3dll.a PATH_SUFFIXES dynamic) +find_library(GLFW3_LIB_DBG NAMES glfw3_d glfw3_ddll.a PATH_SUFFIXES dynamic) +if (NOT (GLFW3_LIB OR GLFW3_LIB_DBG)) + find_library(GLFW3_LIB NAMES glfw glfwdll.a PATH_SUFFIXES dynamic) + find_library(GLFW3_LIB_DBG NAMES glfw_d glfw_ddll.a PATH_SUFFIXES dynamic) +endif () +mark_as_advanced(GLFW3_H_PATH GLFW3_LIB GLFW3_LIB_DBG) + +if (WIN32) + set(GLFW3_DEFINITIONS_DYNAMIC "GLFW3_DLL" CACHE STRING "preprocessor definitions" ) + mark_as_advanced(GLFW3_DEFINITIONS_DYNAMIC) +endif() + +if (WIN32 OR APPLE) + find_library(GLFW3_LIB_STATIC NAMES glfw3 glfw PATH_SUFFIXES static) + find_library(GLFW3_LIB_STATIC_DBG NAMES glfw3_d glfw_d PATH_SUFFIXES static) + mark_as_advanced(GLFW3_LIB_STATIC GLFW3_LIB_STATIC_DBG) +endif() + +cegui_find_package_handle_standard_args(GLFW3 GLFW3_LIB GLFW3_H_PATH) + + +# set up output vars +if (GLFW3_FOUND) + set (GLFW3_INCLUDE_DIR ${GLFW3_H_PATH}) + set (GLFW3_LIBRARIES ${GLFW3_LIB}) + if (GLFW3_LIB_DBG) + set (GLFW3_LIBRARIES_DBG ${GLFW3_LIB_DBG}) + endif() + if (GLFW3_LIB_STATIC) + set (GLFW3_LIBRARIES_STATIC ${GLFW3_LIB_STATIC}) + endif() + if (GLFW3_LIB_STATIC_DBG) + set (GLFW3_LIBRARIES_STATIC_DBG ${GLFW3_LIB_STATIC_DBG}) + endif() +else() + set (GLFW3_INCLUDE_DIR) + set (GLFW3_LIBRARIES) + set (GLFW3_LIBRARIES_DBG) + set (GLFW3_LIBRARIES_STATIC) + set (GLFW3_LIBRARIES_STATIC_DBG) +endif() + diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake index 2ca139bbe..8fe3f01dd 100644 --- a/cmake/FindIconv.cmake +++ b/cmake/FindIconv.cmake @@ -1,44 +1,92 @@ +# taken from: +# http://code.google.com/p/tinygettext/source/browse/trunk/FindICONV.cmake?spec=svn183&r=183 + +# +# Copyright (c) 2006, Peter Kmmel, +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. +# + ################################################################################ -# Custom cmake module for CEGUI to see if iconv exists +# Adapted for CEGUI ################################################################################ -include(FindPackageHandleStandardArgs) -include(CheckCXXSourceCompiles) - -find_path(ICONV_H_PATH NAMES iconv.h) -find_library(ICONV_LIB NAMES iconv) +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) +include(CheckFunctionExists) if (ICONV_H_PATH) - check_cxx_source_compiles(" - #include - int main() { - iconv(0, 0, 0, 0, 0); - return 0; - }" - - ICONV_LIB_GLIBC) - - if (NOT ICONV_LIB_GLIBC) - find_package_handle_standard_args(Iconv DEFAULT_MSG ICONV_LIB ICONV_H_PATH) - else() - set(ICONV_FOUND TRUE) - unset(ICONV_LIB) - endif() - - # This compiles a test to determine whether iconv API takes ptr to const or - # non-const as the input buffer - set (CMAKE_REQUIRED_LIBRARIES ${ICONV_LIB}) - check_cxx_source_compiles(" - #include - int main() { - const char* inbuf = 0; - iconv(0, &inbuf, 0, 0, 0); - return 0; - }" - - CEGUI_ICONV_USES_CONST_INBUF) + # Already in cache, be silent + set(ICONV_FIND_QUIETLY TRUE) +endif() + +find_path(ICONV_H_PATH iconv.h + /usr/include + /usr/local/include) + +set(POTENTIAL_ICONV_LIBS iconv libiconv libiconv2) + +find_library(ICONV_LIB NAMES ${POTENTIAL_ICONV_LIBS} + PATHS /usr/lib /usr/local/lib) + +if(WIN32) + set(ICONV_DLL_NAMES iconv.dll libiconv.dll libiconv2.dll) + find_file(ICONV_DLL + NAMES ${ICONV_DLL_NAMES} + PATHS ENV PATH + NO_DEFAULT_PATH) + find_file(ICONV_DLL_HELP + NAMES ${ICONV_DLL_NAMES} + PATHS ENV PATH + ${ICONV_H_PATH}/../bin) + if(ICONV_FIND_REQUIRED) + if(NOT ICONV_DLL AND NOT ICONV_DLL_HELP) + message(FATAL_ERROR "Could not find iconv.dll, please add correct your PATH environment variable") + endif() + if(NOT ICONV_DLL AND ICONV_DLL_HELP) + get_filename_component(ICONV_DLL_HELP ${ICONV_DLL_HELP} PATH) + message(STATUS) + message(STATUS "Could not find iconv.dll in standard search path, please add ") + message(STATUS "${ICONV_DLL_HELP}") + message(STATUS "to your PATH environment variable.") + message(STATUS) + message(FATAL_ERROR "exit cmake") + endif() + endif() + if(ICONV_H_PATH AND ICONV_LIB AND ICONV_DLL) + set(ICONV_FOUND TRUE) + endif() +else() + check_function_exists(iconv HAVE_ICONV_IN_LIBC) + if(ICONV_H_PATH AND HAVE_ICONV_IN_LIBC) + set(ICONV_FOUND TRUE) + set(ICONV_LIB CACHE TYPE STRING FORCE) + endif() + if(ICONV_H_PATH AND ICONV_LIB) + set(ICONV_FOUND TRUE) + endif() endif() -mark_as_advanced(ICONV_H_PATH ICONV_LIB ICONV_LIB_GLIBC) +mark_as_advanced(ICONV_H_PATH ICONV_LIB) # set up output vars if (ICONV_FOUND) diff --git a/cmake/FindOIS.cmake b/cmake/FindOIS.cmake index f2452a0df..7a4d015b4 100644 --- a/cmake/FindOIS.cmake +++ b/cmake/FindOIS.cmake @@ -33,8 +33,7 @@ find_library(OIS_LIB_DBG NAMES OIS_d libOIS_d mark_as_advanced(OIS_H_PATH OIS_LIB OIS_LIB_DBG) -find_package_handle_standard_args(OIS DEFAULT_MSG OIS_LIB OIS_H_PATH) - +cegui_find_package_handle_standard_args(OIS OIS_LIB OIS_H_PATH) # set up output vars if (OIS_FOUND) diff --git a/cmake/FindOgre.cmake b/cmake/FindOgre.cmake index 93b0b522a..c30a3b6c5 100644 --- a/cmake/FindOgre.cmake +++ b/cmake/FindOgre.cmake @@ -142,11 +142,15 @@ endif() # Find the release and debug libraries. find_library(OGRE_LIB NAMES ${OGRE_LIBRARY_NAMES} PATHS ${OGRE_PREFIX_PATH} - PATH_SUFFIXES Release lib/Release) + PATH_SUFFIXES Release lib/Release release lib/release) find_library(OGRE_LIB_DBG NAMES ${OGRE_LIBRARY_NAMES}_d PATHS ${OGRE_PREFIX_PATH} - PATH_SUFFIXES Debug lib/Debug) + PATH_SUFFIXES Debug lib/Debug debug lib/debug) + +if (NOT OGRE_LIB AND OGRE_LIB_DBG) + set(OGRE_LIB OGRE_LIB_DBG) +endif() mark_as_advanced(OGRE_H_PATH OGRE_H_BUILD_SETTINGS_PATH OGRE_LIB OGRE_LIB_DBG) @@ -212,8 +216,14 @@ if (OGRE_FOUND) endif () endif () set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${ZZIP_LIBRARIES} ${ZLIB_LIBRARIES} ${FREEIMAGE_LIBRARIES} ${FREETYPE_LIBRARIES}) + if (OGRE_LIBRARIES_DBG) + set(OGRE_LIBRARIES_DBG ${OGRE_LIBRARIES_DBG} ${ZZIP_LIBRARIES} ${ZLIB_LIBRARIES} ${FREEIMAGE_LIBRARIES} ${FREETYPE_LIBRARIES}) + endif() if (APPLE) set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${X11_LIBRARIES} ${X11_Xt_LIBRARIES} ${XAW_LIBRARY} ${X11_Xrandr_LIB} ${Carbon_LIBRARIES} ${Cocoa_LIBRARIES}) + if (OGRE_LIBRARIES_DBG) + set(OGRE_LIBRARIES_DBG ${OGRE_LIBRARIES_DBG} ${X11_LIBRARIES} ${X11_Xt_LIBRARIES} ${XAW_LIBRARY} ${X11_Xrandr_LIB} ${Carbon_LIBRARIES} ${Cocoa_LIBRARIES}) + endif() endif() if (NOT ZLIB_FOUND OR NOT ZZIP_FOUND) set(OGRE_DEPS_FOUND FALSE) @@ -229,6 +239,9 @@ if (OGRE_FOUND) set(OGRE_DEPS_FOUND FALSE) endif () set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${X11_LIBRARIES} ${X11_Xt_LIB} ${XAW_LIBRARY} ${X11_Xrandr_LIB} pthread dl) + if (OGRE_LIBRARIES_DBG) + set(OGRE_LIBRARIES_DBG ${OGRE_LIBRARIES_DBG} ${X11_LIBRARIES} ${X11_Xt_LIB} ${XAW_LIBRARY} ${X11_Xrandr_LIB} pthread dl) + endif() endif () if (NOT OGRE_DEPS_FOUND) message(status "Could not find all required dependencies for the Ogre package.") diff --git a/cmake/FindPythonVersion.cmake b/cmake/FindPythonVersion.cmake new file mode 100644 index 000000000..f7d437be1 --- /dev/null +++ b/cmake/FindPythonVersion.cmake @@ -0,0 +1,24 @@ + execute_process( + COMMAND + ${PYTHON_EXECUTABLE} -c "import sys;print (str(sys.version_info[0]) + '.' + str(sys.version_info[1]) + '.' + str(sys.version_info[2]))" + OUTPUT_VARIABLE PYTHON_VERSION_STRING + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RUN_RESULT + ) +set( PYTHON_VERSION_FOUND FALSE) +string(COMPARE EQUAL ${RUN_RESULT} "0" RUN_SUCCESS) +if (RUN_SUCCESS) + set( PYTHON_VERSION_FOUND TRUE) + string(REPLACE "." " " _PY_LIST ${PYTHON_VERSION_STRING} ) + list(LENGTH _PY_LIST _PY_LIST_LEN) + if ( _PY_LIST_LEN GREATER 0) + list(GET _PY_LIST 0 PYTHON_VERSION_STRING_MAJOR) + endif() + if ( _PY_LIST_LEN GREATER 1) + list(GET _PY_LIST 0 PYTHON_VERSION_STRING_MINOR) + endif() + if ( _PY_LIST_LEN GREATER 2) + list(GET _PY_LIST 0 PYTHON_VERSION_STRING_MICRO) + endif() +endif() + diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake new file mode 100644 index 000000000..6a13f8819 --- /dev/null +++ b/cmake/FindSDL2.cmake @@ -0,0 +1,204 @@ +# 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 SDL2_main 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 SDL2main.h and SDL2main.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" 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_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 . 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. + +#============================================================================= +# 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.) +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PATH(SDL2_H_PATH + NAMES SDL.h + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES include/SDL2 include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL2 + /usr/include/SDL2 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +FIND_LIBRARY(SDL2_LIB + NAMES SDL2 + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS + /sw + /opt/local + /opt/csw + /opt +) + +FIND_LIBRARY(SDL2_LIB_DBG + NAMES SDL2_d + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS + /sw + /opt/local + /opt/csw + /opt +) + +mark_as_advanced(SDL2_H_PATH SDL2_LIB SDL2_LIB_DBG) + +IF(NOT SDL2_BUILDING_LIBRARY) + IF(NOT ${SDL2_H_PATH} 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_LIB + NAMES SDL2main + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) + mark_as_advanced(SDL2MAIN_LIB) + ENDIF(NOT ${SDL2_H_PATH} 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_LIB) + # For SDL2main + IF(NOT SDL2_BUILDING_LIBRARY) + IF(SDL2MAIN_LIB) + SET(SDL2_LIB ${SDL2_LIB} ${SDL2MAIN_LIB}) + ENDIF(SDL2MAIN_LIB) + 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_LIB ${SDL2_LIB} "-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_LIB ${SDL2_LIB} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF(NOT APPLE) + + # For MinGW library + IF(MINGW) + SET(SDL2_LIB ${MINGW32_LIBRARY} ${SDL2_LIB}) + ENDIF(MINGW) +ENDIF(SDL2_LIB) + +cegui_find_package_handle_standard_args(SDL2 SDL2_LIB SDL2_H_PATH) + +# set up output vars +if (SDL2_FOUND) + set (SDL2_INCLUDE_DIR ${SDL2_H_PATH}) + set (SDL2_LIBRARIES ${SDL2_LIB}) + if (SDL2_LIB_DBG) + set (SDL2_LIBRARIES_DBG ${SDL2_LIB_DBG}) + endif() + if (SDL2_LIB_STATIC) + set (SDL2_LIBRARIES_STATIC ${SDL2_LIB_STATIC}) + endif() + if (SDL2_LIB_STATIC_DBG) + set (SDL2_LIBRARIES_STATIC_DBG ${SDL2_LIB_STATIC_DBG}) + endif() +else() + set (SDL2_INCLUDE_DIR) + set (SDL2_LIBRARIES) + set (SDL2_LIBRARIES_DBG) + set (SDL2_LIBRARIES_STATIC) + set (SDL2_LIBRARIES_STATIC_DBG) +endif() \ No newline at end of file diff --git a/cmake/FindSDL2_image.cmake b/cmake/FindSDL2_image.cmake new file mode 100644 index 000000000..36495e7dd --- /dev/null +++ b/cmake/FindSDL2_image.cmake @@ -0,0 +1,105 @@ +# Locate the SDL2_image library. This CMake module is a modified version +# of the original FindSDL_image.cmake file +# ########################################################################### +# Locate SDL_image library +# This module defines +# SDL2IMAGE_LIBRARY, the name of the library to link against +# SDLIMAGE_FOUND, if false, do not try to link to SDL +# SDL2IMAGE_INCLUDE_DIR, where to find SDL/SDL.h +# +# $SDLDIR is an environment variable that would +# correspond to the ./configure --prefix=$SDLDIR +# used in building SDL. +# +# Created by Eric Wing. This was influenced by the FindSDL.cmake +# module, but with modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). + +#============================================================================= +# Copyright 2005-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 distributed this file outside of CMake, substitute the full +# License text for the above reference.) + +FIND_PATH(SDL2IMAGE_H_PATH + NAMES SDL_image.h + HINTS + $ENV{SDL2IMAGEDIR} + $ENV{SDL2DIR} + PATH_SUFFIXES include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL2 + /usr/include/SDL2 + /sw/include/SDL2 # Fink + /opt/local/include/SDL2 # DarwinPorts + /opt/csw/include/SDL2 # Blastwave + /opt/include/SDL2 +) + +FIND_LIBRARY(SDL2IMAGE_LIB + NAMES SDL2_image + HINTS + $ENV{SDL2IMAGEDIR} + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt +) + +FIND_LIBRARY(SDL2IMAGE_LIB_DBG + NAMES SDL2_image_d + HINTS + $ENV{SDL2IMAGEDIR} + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt +) + +mark_as_advanced(SDL2IMAGE_LIB SDL2IMAGE_LIB_DBG SDL2IMAGE_H_PATH) + +cegui_find_package_handle_standard_args(SDL2IMAGE SDL2IMAGE_LIB SDL2IMAGE_H_PATH) + +# set up output vars +if (SDL2IMAGE_FOUND) + set (SDL2IMAGE_INCLUDE_DIR ${SDL2IMAGE_H_PATH}) + set (SDL2IMAGE_LIBRARIES ${SDL2IMAGE_LIB}) + if (SDL2IMAGE_LIB_DBG) + set (SDL2IMAGE_LIBRARIES_DBG ${SDL2IMAGE_LIB_DBG}) + endif() + if (SDL2IMAGE_LIB_STATIC) + set (SDL2IMAGE_LIBRARIES_STATIC ${SDL2IMAGE_LIB_STATIC}) + endif() + if (SDL2IMAGE_LIB_STATIC_DBG) + set (SDL2IMAGE_LIBRARIES_STATIC_DBG ${SDL2IMAGE_LIB_STATIC_DBG}) + endif() +else() + set (SDL2IMAGE_INCLUDE_DIR) + set (SDL2IMAGE_LIBRARIES) + set (SDL2IMAGE_LIBRARIES_DBG) + set (SDL2IMAGE_LIBRARIES_STATIC) + set (SDL2IMAGE_LIBRARIES_STATIC_DBG) +endif() \ No newline at end of file diff --git a/cmake/FindSILLY.cmake b/cmake/FindSILLY.cmake index f31edaf87..727f486e4 100644 --- a/cmake/FindSILLY.cmake +++ b/cmake/FindSILLY.cmake @@ -12,8 +12,8 @@ if (WIN32 OR APPLE) find_library(SILLY_LIB_STATIC NAMES SILLY libSILLY PATH_SUFFIXES static) find_library(SILLY_LIB_STATIC_DBG NAMES SILLY_d libSILLY_d PATH_SUFFIXES static) - cegui_find_libraries(SILLY_LIB_STATIC "libpng;jpeg" static) - cegui_find_libraries(SILLY_LIB_STATIC_DBG "libpng_d;jpeg_d" static) + cegui_find_libraries(SILLY_LIB_STATIC "libpng;jpeg;zlib" static) + cegui_find_libraries(SILLY_LIB_STATIC_DBG "libpng_d;jpeg_d;zlib_d" static) set( SILLY_DEFINITIONS_STATIC "SILLY_STATIC" CACHE STRING "preprocessor definitions" ) mark_as_advanced(SILLY_DEFINITIONS_STATIC SILLY_LIB_STATIC SILLY_LIB_STATIC_DBG) diff --git a/cmake/templates/VisualStudioUserFile.vcproj.user.in b/cmake/templates/VisualStudioUserFile.vcproj.user.in index c032175f6..76a09cf91 100644 --- a/cmake/templates/VisualStudioUserFile.vcproj.user.in +++ b/cmake/templates/VisualStudioUserFile.vcproj.user.in @@ -117,5 +117,117 @@ MPIAcceptFilter="" /> + + + + + + + + + + + + diff --git a/cmake/templates/VisualStudioUserFile.vcxproj.user.in b/cmake/templates/VisualStudioUserFile.vcxproj.user.in index 6fda6d61e..924e9e5d3 100644 --- a/cmake/templates/VisualStudioUserFile.vcxproj.user.in +++ b/cmake/templates/VisualStudioUserFile.vcxproj.user.in @@ -1,23 +1,43 @@  - - $(TargetPath) - $(OutDir) - WindowsLocalDebugger - - - $(TargetPath) - $(OutDir) - WindowsLocalDebugger - - - $(TargetPath) - $(OutDir) - WindowsLocalDebugger - - - $(TargetPath) - $(OutDir) - WindowsLocalDebugger - + + $(TargetPath) + $(OutDir) + WindowsLocalDebugger + + + $(TargetPath) + $(OutDir) + WindowsLocalDebugger + + + $(TargetPath) + $(OutDir) + WindowsLocalDebugger + + + $(TargetPath) + $(OutDir) + WindowsLocalDebugger + + + $(TargetPath) + $(OutDir) + WindowsLocalDebugger + + + $(TargetPath) + $(OutDir) + WindowsLocalDebugger + + + $(TargetPath) + $(OutDir) + WindowsLocalDebugger + + + $(TargetPath) + $(OutDir) + WindowsLocalDebugger + \ No newline at end of file diff --git a/datafiles/CMakeLists.txt b/datafiles/CMakeLists.txt index bd1d8d88c..91839c70a 100644 --- a/datafiles/CMakeLists.txt +++ b/datafiles/CMakeLists.txt @@ -1,10 +1,10 @@ -install(DIRECTORY animations DESTINATION ${CEGUI_DATA_INSTALL_DIR}) -#install(DIRECTORY configs DESTINATION ${CEGUI_DATA_INSTALL_SUBDIR}) -install(DIRECTORY fonts DESTINATION ${CEGUI_DATA_INSTALL_DIR}) -install(DIRECTORY imagesets DESTINATION ${CEGUI_DATA_INSTALL_DIR}) -install(DIRECTORY layouts DESTINATION ${CEGUI_DATA_INSTALL_DIR}) -install(DIRECTORY looknfeel DESTINATION ${CEGUI_DATA_INSTALL_DIR}) -install(DIRECTORY lua_scripts DESTINATION ${CEGUI_DATA_INSTALL_DIR}) -install(DIRECTORY schemes DESTINATION ${CEGUI_DATA_INSTALL_DIR}) -install(DIRECTORY xml_schemas DESTINATION ${CEGUI_DATA_INSTALL_DIR}) +install(DIRECTORY animations DESTINATION ${CEGUI_DATA_INSTALL_DIR} COMPONENT cegui_samples) +#install(DIRECTORY configs DESTINATION ${CEGUI_DATA_INSTALL_SUBDIR} COMPONENT cegui_samples) +install(DIRECTORY fonts DESTINATION ${CEGUI_DATA_INSTALL_DIR} COMPONENT cegui_samples) +install(DIRECTORY imagesets DESTINATION ${CEGUI_DATA_INSTALL_DIR} COMPONENT cegui_samples) +install(DIRECTORY layouts DESTINATION ${CEGUI_DATA_INSTALL_DIR} COMPONENT cegui_samples) +install(DIRECTORY looknfeel DESTINATION ${CEGUI_DATA_INSTALL_DIR} COMPONENT cegui_samples) +install(DIRECTORY lua_scripts DESTINATION ${CEGUI_DATA_INSTALL_DIR} COMPONENT cegui_samples) +install(DIRECTORY schemes DESTINATION ${CEGUI_DATA_INSTALL_DIR} COMPONENT cegui_samples) +install(DIRECTORY xml_schemas DESTINATION ${CEGUI_DATA_INSTALL_DIR} COMPONENT cegui_samples) diff --git a/datafiles/imagesets/TaharezLook.imageset b/datafiles/imagesets/TaharezLook.imageset index cff0b0677..225d5470c 100644 --- a/datafiles/imagesets/TaharezLook.imageset +++ b/datafiles/imagesets/TaharezLook.imageset @@ -241,4 +241,5 @@ + \ No newline at end of file diff --git a/datafiles/layouts/TaharezLookOverview.layout b/datafiles/layouts/TaharezLookOverview.layout new file mode 100644 index 000000000..d780d9114 --- /dev/null +++ b/datafiles/layouts/TaharezLookOverview.layout @@ -0,0 +1,408 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. + + + + + + + Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/datafiles/layouts/VanillaLookOverview.layout b/datafiles/layouts/VanillaLookOverview.layout new file mode 100644 index 000000000..ff7d3156c --- /dev/null +++ b/datafiles/layouts/VanillaLookOverview.layout @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. + + + + + + + Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/datafiles/layouts/application_templates.layout b/datafiles/layouts/application_templates.layout new file mode 100644 index 000000000..9af94e659 --- /dev/null +++ b/datafiles/layouts/application_templates.layout @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/datafiles/looknfeel/Generic.looknfeel b/datafiles/looknfeel/Generic.looknfeel index 90542c886..98073848a 100644 --- a/datafiles/looknfeel/Generic.looknfeel +++ b/datafiles/looknfeel/Generic.looknfeel @@ -50,6 +50,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+
+ + +
+ +
+
+ +
+
+
+
+ diff --git a/datafiles/looknfeel/TaharezLook.looknfeel b/datafiles/looknfeel/TaharezLook.looknfeel index 60f53eeb1..6975b511c 100644 --- a/datafiles/looknfeel/TaharezLook.looknfeel +++ b/datafiles/looknfeel/TaharezLook.looknfeel @@ -380,10 +380,10 @@ - - - - + + + + @@ -2080,35 +2080,20 @@ - - - - - - - - - - - - - - + + + + - - - - - - - - + + + - + @@ -2116,17 +2101,17 @@ - - + + - + - + @@ -2134,17 +2119,17 @@ - - + + - + - + diff --git a/datafiles/schemes/Generic.scheme b/datafiles/schemes/Generic.scheme index 579cb1116..bb89c8e75 100644 --- a/datafiles/schemes/Generic.scheme +++ b/datafiles/schemes/Generic.scheme @@ -4,7 +4,8 @@ + - \ No newline at end of file + diff --git a/doc/doxygen/authors.dox b/doc/doxygen/authors.dox index 3b1b67c5a..657ba46d0 100644 --- a/doc/doxygen/authors.dox +++ b/doc/doxygen/authors.dox @@ -7,6 +7,7 @@ The following is a list of primary authors and contributors for Crazy Eddie's GU - Martin Preisler (Kulik) - Lukas Meindl (Ident) - Timotei Dolean (timootei) +- Yaron Cohen-Tal @section authors_sec_2 Retired or Semi-retired CEGUI Team Members - Patrick Kooman (scriptkid) diff --git a/doc/doxygen/build_options.dox b/doc/doxygen/build_options.dox index 42317ed19..9e6e6960f 100644 --- a/doc/doxygen/build_options.dox +++ b/doc/doxygen/build_options.dox @@ -29,6 +29,21 @@ Specifies whether bi-directional text will be supported via the embedded minibidi. @note You may not enable both CEGUI_USE_FRIBIDI and CEGUI_USE_MINIBIDI. Please choose only one of these options. +@subsection build_options_use_glew CEGUI_USE_GLEW +Specifies whether to use GLEW as an OpenGL loading library. +@note You may not enable both "CEGUI_USE_GLEW" and "CEGUI_USE_EPOXY". Please +choose only one of these options. +@subsection build_options_use_epoxy CEGUI_USE_EPOXY +Specifies whether to use Epoxy as an OpenGL loading library. +@note You may not enable both "CEGUI_USE_GLEW" and "CEGUI_USE_EPOXY". Please +choose only one of these options. +@subsection build_options_glfw_ver CEGUI_GLFW_VER +Specifies which major version of GLFW to use for the samples (2 or 3). The +default is to look for both, giving priority to version 2. +@note For desktop OpenGL rendering, either version 2 or 3 is required. For +OpenGL ES 2.0 renderering, version 3 is required. To use OpenGL ES 2.0 with EGL, +GLFW 3 must be used, and GLFW 3 must be built configured with +"-DGLFW_USE_EGL=ON -DGLFW_CLIENT_LIBRARY=glesv2". @subsection build_options_string_class CEGUI_STRING_CLASS Which string class should CEGUI use: - 1 - utf8 and utf32 aware inbuilt string, @@ -70,10 +85,10 @@ Specifies whether to build the regression and performance tests. @section build_options_renderers Renderer Modules @subsection build_options_gl_renderer CEGUI_BUILD_RENDERER_OPENGL Specifies whether to include OpenGLRenderer (supports older fixed function -pipeline) in the OpenGL renderer module +pipeline desktop OpenGL 1.2) in the OpenGL renderer module @subsection build_options_gl3_renderer CEGUI_BUILD_RENDERER_OPENGL3 -Specifies whether to include OpenGL3Renderer OpenGL 3+ (core profile) in -the OpenGL renderer module +Specifies whether to include OpenGL3Renderer (supports desktop OpenGL 3.2 (core +profile) and OpenGL ES 2.0) in the OpenGL renderer module @subsection build_options_ogre_renderer CEGUI_BUILD_RENDERER_OGRE Specifies whether to build the Ogre renderer module @subsection build_options_irr_renderer CEGUI_BUILD_RENDERER_IRRLICHT @@ -151,23 +166,6 @@ Specifies whether to build the Python extension module(s) @section build_options_samples Sample Framework and Samples @subsection build_options_samples_enabled CEGUI_SAMPLES_ENABLED -Specifies whether to build the CEGUI sample applications -@subsection build_options_samples_use_gl CEGUI_SAMPLES_USE_OPENGL -Specifies whether the sample applications will use OpenGLRenderer -@subsection build_options_samples_use_gl3 CEGUI_SAMPLES_USE_OPENGL3 -Specifies whether the sample applications will use OpenGL3Renderer. -@subsection build_options_samples_use_ogre CEGUI_SAMPLES_USE_OGRE -Specifies whether the sample applications will use the Ogre renderer -@subsection build_options_samples_use_irr CEGUI_SAMPLES_USE_IRRLICHT -Specifies whether the sample applications will use the Irrlicht renderer -@subsection build_options_samples_use_dfb CEGUI_SAMPLES_USE_DIRECTFB -Specifies whether the sample applications will use the DirectFB renderer -@subsection build_options_samples_use_d3d9 CEGUI_SAMPLES_USE_DIRECT3D9 -Specifies whether the sample applications will use the Direct3D 9 renderer -@subsection build_options_samples_use_d3d10 CEGUI_SAMPLES_USE_DIRECT3D10 -Specifies whether the sample applications will use the Direct3D 10 renderer -@subsection build_options_samples_use_d3d11 CEGUI_SAMPLES_USE_DIRECT3D11 -Specifies whether the sample applications will use the Direct3D 11 renderer @subsection build_options_samples_use_gtk2 CEGUI_SAMPLES_USE_GTK2 Specifies whether the sample applications will make use of the GTK2 UI for renderer selection. diff --git a/doc/doxygen/changelog.dox b/doc/doxygen/changelog.dox index 3df27d95d..da647102a 100644 --- a/doc/doxygen/changelog.dox +++ b/doc/doxygen/changelog.dox @@ -3,12 +3,38 @@ namespace CEGUI{ @page change_log Change Log The following is a high-level view of changes made to Crazy Eddie's GUI System for each release. -@note From the 0.8.0 release items are taken from our mantis ticket tracking -system and not from the commit logs themsevles - this means that releases will -likely contain additions, fixes and other changes that do not get mentioned in -this change log. If you're looking for a 100% complete record of all changes -please consult the commit logs! - +@note Starting with the 0.8.5 release, a list of resolved issues from our bitbucket bug-tracker +will be used as change log. The list might be incomplete, as some (especially smaller) changes often are +not mentioned in the issue tracker. Therefore, if you want more in-depth information about all changes and +a definitely complete list, please read the commit logs of the v0-8 branch up to the point of this release! + +Release 0.8.7 (taken from bitbucket issue-tracker based on the respective milestone. To read the full issue go to [https://bitbucket.org/cegui/cegui/issue/](https://bitbucket.org/cegui/cegui/issue/ "Issue tracker") and append the ID - e.g. https://bitbucket.org/cegui/cegui/issue/998 +- #1123: Library soname was changed from 2 to 1 in 0.8.6 + +Release 0.8.6 (taken from bitbucket issue-tracker based on the respective milestone. To read the full issue go to [https://bitbucket.org/cegui/cegui/issue/](https://bitbucket.org/cegui/cegui/issue/ "Issue tracker") and append the ID - e.g. https://bitbucket.org/cegui/cegui/issue/998 +- #1120: Bug regarding order of destruction : Element object referenced by '__auto_titlebar__' is not attached to Element at (...) +- #1111: Add official support for MinGW (32 and 64 bit targets) +- Child removal (e.g. on destruction) always triggered a deactivation event due to a change in a fix for 0.8.5, now the deactivation event is only triggered when the element was actually active. + +Release 0.8.5 (taken from bitbucket issue-tracker, milestone 0.8.5. To read the full issue go to [https://bitbucket.org/cegui/cegui/issue/](https://bitbucket.org/cegui/cegui/issue/ "Issue tracker") and append the ID - e.g. [https://bitbucket.org/cegui/cegui/issue/998](http://example.net/) +- Some changes around the Cmake for the OgreRenderer were done, both fixes and enhancements +- #998: SimpleTimer.cpp includes headers into namespace +- #1019: Docu lacks info on deinitialisation of CEGUI +- #1034: Doxygen docs use GIF images +- #1063: OpenGLRenderer on Linux renders CEGUI samples upside-down +- #1065: The 0.7->0.8 porting tips should either be added to the API Docu or referenced from there +- #1072: Docu: Replace CEGUIFalagardWRBase with CEGUICoreWindowRendererSet in Docu +- #1076: TabControl XML printing prints children twice +- #1077: ComboDropList output to XML shows RestoreOldCapture for Scrollbar's autowindow children +- #1078: Properties that are forwarded via PropertyLinkDefinitions are printed to XML +- #1079: Tooltips behave glitchy, take away focus from underlying windows, affect move-events +- #1080: Tooltips are wrongly printed to XML, inheritance affects the printing and uses wrong values +- #1081: Numerous windows XML-print some redundant (because forwarded) AutoWindow properties +- #1082: Scrollable panes print their children inside their autowindow instead of directly inside them +- #1087: StaticText uses incorrect Font when DefaultFont of a GUIContext is changed +- #1097: Window font ignored in RenderStringTextComponents +- #1104: Issue an exception if the locale is unexpected, before parsing anything with sscanf +- #1110: Support building CEGUI and its deps on Windows with MSVC for 64-bit. Release 0.8.4 (taken from commit logs, since there were no mantis entries) - Package 'promo' dir, people might want to use logo in their products. diff --git a/doc/doxygen/code_standards.dox b/doc/doxygen/code_standards.dox index 8ceaa2ae2..20bcf351b 100644 --- a/doc/doxygen/code_standards.dox +++ b/doc/doxygen/code_standards.dox @@ -30,7 +30,7 @@ This section contains some general guidelines on naming and arranging files. Author: *******************************************************************************/ /*************************************************************************** - * Copyright (C) 2004 - 2013 Paul D Turner & The CEGUI Development Team + * Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -57,15 +57,12 @@ This section contains some general guidelines on naming and arranging files. - Please ensure that all files have a newline at the end of them. Depending upon the layout of included files and various other things, not having a newline has the potential to cause code not to compile correctly - especially in relation to headers. Plus it gives loads of annoying warnings on some compilers :) +- Please use the UNIX newline - LF. A good way to accomplish this is to enable the eol extension, we have .hgeol in the repository that will set it up. + - Wherever possible preprocessor macros should not be used. Always prefer the use of an actual language construct (such as typedef or enum) over a preprocessor @c \#define. - Wherever possible header files should contain Doxygen documentation for all classes, data and functions. There will be very few, if any, exceptions to this rule. -- In source files, definitions of the various data groups and each member function should be separated by a line, thus: -@code -//----------------------------------------------------------------------------// -@endcode - - Implementation code belongs in the implementation .cpp files, not in the header files. There are very few cases, such as for template implementation, where c++ code should appear in header files. - The general content of a header file should be in the following order: @@ -96,26 +93,50 @@ The following details the general code style and layout that should be used. - Constants should be all upper case with words separated by an underscore, such as in @b THIS_IS_CONSTANT. Please note that this rule does also apply to class member constants and enumeration values. -- Global variables should use camel case; where each word in the name is capitalised except the first word. Globals should be prefixed with @b G_. So if we had a global we want to call 'nastyVariable' it should be named @b G_nastyVariable - yes, it looks horrible, and hopefully it's horrible enough that you find another way! +- Don't use global variables. Exception: Sample code for platforms where we don't have a main function, e.g. Android. - Class member variables should be camel case; where each word in the name is capitalised except the first word, such as in @b thisVariable. Normal members should have the prefix @b d_ (for data, don't ask!), such as in @b d_thisVariable, while static members should have the prefix @b s_, such as in @b s_anotherVariable. - Class member functions should be camel case; where each word in the name is capitalised except the first word, such as in @b theFunction. Member functions do not use prefixes. -- Local variables in functions should be all lower case with an underscore between words, such as in @b word_count. +- When using camel case on a member function or variable with words in it that are typically fully capitalised (e.g. "OpenGL ES"), camel case them anyways, do not ever use underscores here! For example call the method isUsingOpenglEs instead of isUsingOpenGLES. The latter would be read more like "Open GLES", and the reader might end up wondering what "GLES" is. -- Parameter names are treated the same as other local variables, so should be named all lower case with an underscore between words, such as in @b char_count. +- In %CEGUI version 0.8.X local variables and function parameters should all be lower case with an underscore between words, such as in @b word_count and @b new_size. + +- Starting with CEGUI version 1.X and in %CEGUI default branch the local variables and function parameters should all be written in camel case, such as in @b wordCount and @b newSize. + +- Boolean getter functions should always start with "is". Please think of meaningful names in that context, e.g. for plural, instead of "areCatsFuzzy" do NOT use "isCatsFuzzy" but use "isEachCatFuzzy" or "isEveryCatFuzzy", instead of "areVaosSupported" you could use "isVaoSupported", etc. Whatever you choose, make it both readable and grammatically correct. Sometimes opening a thesaurus may help you find the right words. @subsection code_standards_sec_2_2 Code Formatting Style and Other Tips -- Generally speaking no line in any file - whether code or just plain -text - should be more than 80 characters long. Long lines are really hard to -read and lead to general bad programming practice. +- Code in general should be no more than 80 characters long per line. Long lines are more difficult to read and may lead to general bad programming practice. However there are cases when lines longer than 80 characters are appropriate, and in such cases it's allowed. However, no code line, ever, should be longer than 120 characters. Comments in code files should be split to lines at 80-character boundary. Here's an example where it's appropriate to exceed 80 characters in code lines. This is how it looks when split to 2 lines so as not to break the 80-character limit: +\code{.cpp} + unsigned int glyph_bitmap_height = + static_cast(glyph_bitmap->rows); +\endcode +And this is how it looks without splitting to 2 lines: +\code{.cpp} + unsigned int glyph_bitmap_height = static_cast(glyph_bitmap->rows); +\endcode +... (though it still doesn't break the 120-character hard limit) - Tab spacing size should be 4. But... - Do not use actual tabs, have your editor insert spaces instead. This is very important. +- In CEGUI default branch and CEGUI version 1.X or higher: When you override a function in a subclass, you must use the override keyword (without virtual) for its declaration, e.g.: +\code{.cpp} +class BaseClass +{ + virtual int overriddenFunction() = 0; +} + +class SubClass +{ + int overriddenFunction() override; +} +\endcode + - Code within functions should be split into logical groups by the use of blank lines where appropriate. Generally any control structure (if, while, case, do and so on) should be both preceded and followed by a blank line. - Regarding comments, we prefer well written, self documenting code that @@ -311,13 +332,48 @@ a_ptr = &an_object; - Magic numbers should not appear in production code; use constant definitions instead. In general the only number that may appear in production code is \c 0. -- Use of \c NULL is not allowed; use \c 0 instead. \c NULL is just a macro definition and does not exist in any other form in the C++ language, so it should not be used. +- In %CEGUI default branch and %CEGUI version 1.X or higher: For pointer comparisons and for setting pointers use only \c nullptr. Do not use 0 and especially not NULL. + +- In %CEGUI 0.X: Only use \c 0 (not \c NULL) for pointer comparisons. - When defining class constructors, use of member initialiser lists is to be strongly preferred over the use of assignments in the constructor body. -- Only use C++ style casts. C style casts should not be used. Or better yet, find a way not to use the cast at all! +- Only use C++ style casts (primarily static_cast). C style casts should not be used. Or better yet, use a type consistently if possible so you do not need to cast in the first place! + +- In %CEGUI default branch and %CEGUI version 1.X or higher: Only use enum class for enums. + +- In %CEGUI 0.X: Only use regular \c enum. + +- In %CEGUI default branch and %CEGUI version 1.X or higher: You are encouraged to use C++11 features. However, be careful since some features are not available or not functional on all compilers that %CEGUI supports. Known unsupported features are: string literals, thread_local and std::codecvt. -- Do not use any language or STL constructs from C++11. We intend to support -non-c++11 compilers for the forseeable future. +- In %CEGUI default branch and %CEGUI version 1.X or higher: We currently do not target C++14, so try not to use C++14 features unless they are available in all compilers that %CEGUI supports (mind the minimum version we support). + +- In %CEGUI 0.X: Do not use any C++11 or C++14 features. + +- When including files, such as headers, always use quotation marks for our internal files and always use the pointy brackets ("<" and ">") for all dependencies and the standard library includes. +@code +#include "CEGUI/SomeClass.h" + +#include +#include +@endcode + +- When including files, such as headers, always use the following order: If applicable, first include the header corresponding to the cpp file. Then include all headers belonging to CEGUI. Then all headers from external dependencies. Last include the standard library and OS headers. For SomeClass.cpp it would look like this: +@code +#include "CEGUI/SomeClass.h" + +#include "CEGUI/Window.h" + +#include + +#include +@endcode + +@subsection code_standards_sec_2_3 astyle - Artistic Style +The following parameters for astyle may be used to get a subset of all the code standards outlined in this document. It is by no means enough to just run this on dirty source code but it will get you closer. + +@code +$ astyle -s4A1wKfxpcUz2 $FILE +@endcode */ diff --git a/doc/doxygen/compiling.dox b/doc/doxygen/compiling.dox index 9a4f24ba8..67ea7676d 100644 --- a/doc/doxygen/compiling.dox +++ b/doc/doxygen/compiling.dox @@ -7,15 +7,16 @@ CEGUI uses CMake build generation system (http://www.cmake.org/) to configure the build and generate makefiles or project files of whatever kind you choose – basically this means that if cmake can spit out build files for it, -then you should be able to successfully use it to build CEGUI. +then you should be able to successfully use it to build CEGUI. CMake 2.8.12 or later is required. The CEGUI developers have personally tested the build of CEGUI on a variety systems, and can say the CEGUI is known to build using the following in both 32bit and 64bit configurations: - GNU/Linux using recent versions of either GCC (http://gcc.gnu.org/) or clang (http://clang.llvm.org/) -- Microsoft Windows using MSVC++ 2008 or above (including express editions) -- Apple OS X using Xcode 4 or above. +- Microsoft Windows using MSVC++ 2008 or above (including express editions) or +MinGW-w64 +- Apple OS X using Xcode 4 or above @section compiling_dependencies Dependencies You may have already noticed that CEGUI has a lot of dependencies. Don't be diff --git a/doc/doxygen/dependencies.dox b/doc/doxygen/dependencies.dox index 20efaaadd..b8f67ebf8 100644 --- a/doc/doxygen/dependencies.dox +++ b/doc/doxygen/dependencies.dox @@ -19,10 +19,12 @@ The following is a list of all libraries that CEGUI can make use of: - Required for minizip based resource provider. @subsection dependencies_rendering Rendering -- OpenGL (http://www.opengl.org/) - - Required for GL and GL3 renderer modules. -- GLEW (http://glew.sourceforge.net/) - - Required for GL and GL3 renderer modules +- OpenGL loading libraries: + - GLEW (http://glew.sourceforge.net/) + - Epoxy (https://github.com/yaronct/libepoxy), major version 1. + - Either GLEW or Epoxy is required for the desktop OpenGL 3.2 renderer module. + - Epoxy is required for the OpenGL ES 2.0 renderer module. + - GLEW is required for the old desktop OpenGL 1.2 renderer module. - GLM (http://glm.g-truc.net/) - Required for GL and GL3 renderer modules. - DirectXSDK (http://www.microsoft.com/en-us/download/details.aspx?id=6812) @@ -35,8 +37,11 @@ The following is a list of all libraries that CEGUI can make use of: - Required for Ogre renderer module. - DirectFB (http://directfb.org/) - Required for DirectFB support (broken - do not use) -- OpenGLES (http://www.opengl.org/) - - Required for GLES 1.1 renderer module. (work in progress) +- OpenGL ES emulators: + - PowerVR's (http://community.imgtec.com/developers/powervr/graphics-sdk/) + - There are others, but PowerVR's seems to be the best. + - An OpenGL ES emulator is recommended (and on some platforms, necessary) to + use OpenGL ES 2.0 together with EGL on a desktop OS. @subsection dependencies_parsers XML Parsers - EXPAT (http://expat.sourceforge.net/) @@ -76,7 +81,9 @@ The following is a list of all libraries that CEGUI can make use of: @subsection dependencies_samples Samples Framework - GLFW (http://www.glfw.org/) - - Required for GL/GL3 support in samples + - Required for OpenGL support in samples. + - For desktop OpenGL rendering, either version 2 or 3 is required. + - For OpenGL ES 2.0 rendering, version 3 is required. - OIS (http://sourceforge.net/projects/wgois/) - Required for Ogre support in samples - GTK2 (http://www.gtk.org/) diff --git a/doc/doxygen/doxyfile.in b/doc/doxygen/doxyfile.in index e8b08d72c..238e1464d 100644 --- a/doc/doxygen/doxyfile.in +++ b/doc/doxygen/doxyfile.in @@ -197,7 +197,7 @@ INCLUDE_GRAPH = YES INCLUDED_BY_GRAPH = YES CALL_GRAPH = NO GRAPHICAL_HIERARCHY = YES -DOT_IMAGE_FORMAT = gif +DOT_IMAGE_FORMAT = png DOT_PATH = DOTFILE_DIRS = MAX_DOT_GRAPH_WIDTH = 1036 diff --git a/doc/doxygen/falagard/fal_intro.dox b/doc/doxygen/falagard/fal_intro.dox index 7d432958a..d3ad4520d 100644 --- a/doc/doxygen/falagard/fal_intro.dox +++ b/doc/doxygen/falagard/fal_intro.dox @@ -2,7 +2,7 @@ @page fal_intro Introduction and overview @section fal_whatis What is the Falagard Skinning System? -The Falagard skinning system for CEGUI consists partly of a set of enhancements to the CEGUI base library, and partly of a window renderer module called "CEGUIFalagardWRBase". Combined, these elements are intended to make it easier to create custom skins or 'looks' for CEGUI window and widget elements. +The Falagard skinning system for CEGUI consists partly of a set of enhancements to the CEGUI base library, and partly of a window renderer module called "CEGUICoreWindowRendererSet". Combined, these elements are intended to make it easier to create custom skins or 'looks' for CEGUI window and widget elements. The Falagard system is designed to allow widget imagery specification, sub-widget layout, and default property initialisers to be specified via XML files rather than in C++ or scripted code (which, before now, was the only way to do these things). @@ -237,18 +237,18 @@ Where these setting values correspond to the similar values in the HorizontalAli @section fal_schemes Falagard in Schemes The CEGUI scheme system is the means by which you to specify how the system is to load your XML skin definition files, known as 'looknfeel' files, and how these skins are to be mapped to window renderers and widget base classes to create new concrete widget types. -@subsection fal_wr_modules The CEGUIFalagardWRBase module -One of the main parts of the Falagard system is the window renderer module known as CEGUIFalagardWRBase -(which will be named libCEGUIFalagardWRBase.so on linux style systems and CEGUIFalagardWRBase.dll on Win32 systems). This module contains a set of predefined window renderer classes that take actions to transform skinning data loaded from skin definition XML files into the rendering operations and layout adjustments required to output the widget visual representation to the display. +@subsection fal_wr_modules The CEGUICoreWindowRendererSet module +One of the main parts of the Falagard system is the window renderer module known as CEGUICoreWindowRendererSet +(which will be named libCEGUICoreWindowRendererSet.so on linux style systems and CEGUICoreWindowRendererSet.dll on Win32 systems). This module contains a set of predefined window renderer classes that take actions to transform skinning data loaded from skin definition XML files into the rendering operations and layout adjustments required to output the widget visual representation to the display. -Before you can make use of the CEGUIFalagardWRBase module it must be loaded into the system. To achieve this, you will usually specify it in one of your scheme XML files so that it's available to the system. This can be done with a single line of XML in a scheme file, such as: +Before you can make use of the CEGUICoreWindowRendererSet module it must be loaded into the system. To achieve this, you will usually specify it in one of your scheme XML files so that it's available to the system. This can be done with a single line of XML in a scheme file, such as: @code - + @endcode Some users, having previously employed the WindowSet 'look' modules, may be used to specifying a list of widgets which are to be made available from the module, this is not required when loading a WindowRenderer module (actually, such lists of widgets are no longer needed for the old style 'look' modules either, as long as the module has been updated to provide the required entry point); by employing XML such as that shown above, the module will register all widget types it has available. -The key thing about the CEGUIFalagardWRBase module is that for each widget base type, it defines various required elements and states. These required items need to be defined within the widget look definitions of your looknfeel XML files; they enable the system to make use of your skin imagery and related data in a logical fashion. All of the required elements for each widget can be found in the reference sections @ref fal_baseclass_ref "CEGUI Widget Base Type Requirements" and @ref fal_wr_ref "Falagard Window Renderer Requirements". +The key thing about the CEGUICoreWindowRendererSet module is that for each widget base type, it defines various required elements and states. These required items need to be defined within the widget look definitions of your looknfeel XML files; they enable the system to make use of your skin imagery and related data in a logical fashion. All of the required elements for each widget can be found in the reference sections @ref fal_baseclass_ref "CEGUI Widget Base Type Requirements" and @ref fal_wr_ref "Falagard Window Renderer Requirements". @subsection fal_looknfeel_elements LookNFeel Elements The @c \ XML element for schemes is the means by which you will usually get CEGUI to load the XML 'looknfeel' files containing your widget skin definitions. It is possible to load these files manually via code, but it is expected that the majority of users will be using the scheme system. The LookNFeel element should appear after any Font or Imageset elements, but before any WindowSet elements. @@ -263,7 +263,7 @@ Here we can see a single 'Filename' attribute which specifies the name the file It is acceptable to specify as many LookNFeel elements as is required. This allows you to configure your XML files in the way that best suits your application. This might mean that all skin definitions for all widget elements will go into a single file, it might mean that you have multiple files with a single widget skin definition in each, or it could be any place in between the two extremes - it's up to you. @subsection fal_mappings FalagardMapping Elements -The CEGUI scheme system supports a @c \ element that creates a new concrete window or widget type within the system. This is achieved by creating a named alias that ties together a base widget type, a window renderer type, and a named widget 'LookNFeel'. Here, 'LookNFeel' refers to an individual widget skin as opposed to an entire 'looknfeel' XML file. The base widget type will generally be one of the core system widgets provided by the CEGUI library, although any window type that has a concrete WindowFactory registered in the system is a candidate, which allows the system to be extended with custom widgets. The window renderer type will usually be the name of one of the window renderers registered when the CEGUIFalagardWRBase module was loaded, again this is not a requirement - the window renderer used could just as easily be one you have written yourself. The named 'LookNFeel' is what you specify in your XML looknfeel files (via WidgetLook elements). +The CEGUI scheme system supports a @c \ element that creates a new concrete window or widget type within the system. This is achieved by creating a named alias that ties together a base widget type, a window renderer type, and a named widget 'LookNFeel'. Here, 'LookNFeel' refers to an individual widget skin as opposed to an entire 'looknfeel' XML file. The base widget type will generally be one of the core system widgets provided by the CEGUI library, although any window type that has a concrete WindowFactory registered in the system is a candidate, which allows the system to be extended with custom widgets. The window renderer type will usually be the name of one of the window renderers registered when the CEGUICoreWindowRendererSet module was loaded, again this is not a requirement - the window renderer used could just as easily be one you have written yourself. The named 'LookNFeel' is what you specify in your XML looknfeel files (via WidgetLook elements). An example mapping: @code diff --git a/doc/doxygen/falagard/fal_tut1.dox b/doc/doxygen/falagard/fal_tut1.dox index cac2655f2..adeff8a0b 100644 --- a/doc/doxygen/falagard/fal_tut1.dox +++ b/doc/doxygen/falagard/fal_tut1.dox @@ -41,6 +41,9 @@ Since we now know what states are required for the widget, it's a good idea to a + + + @@ -71,6 +74,9 @@ For our button, we will have an imagery section for each of the button states. W + + + @@ -496,6 +502,6 @@ And for Disabled we again specify some additional colours: @endcode -This concludes the introduction tutorial. For full examples of this, and all the other WidgetLook specifications, see the example 'looknfeel' files in the CEGUI distribution, in the directory: @e cegui_mk2/datafiles/looknfeel/ +This concludes the introduction tutorial. For full examples of this, and all the other WidgetLook specifications, see the example 'looknfeel' files in the CEGUI distribution, in the directory: @e cegui/datafiles/looknfeel/ */ diff --git a/doc/doxygen/mainpage.dox b/doc/doxygen/mainpage.dox index 0b819cffa..4ae95f949 100644 --- a/doc/doxygen/mainpage.dox +++ b/doc/doxygen/mainpage.dox @@ -2,7 +2,7 @@ @mainpage Crazy Eddie's GUI System Mk-2: Developer Documentation http://www.cegui.org.uk -Copyright (c) 2004 - 2013 Paul D Turner & The CEGUI Development Team +Copyright (c) 2004 - 2015 Paul D Turner & The CEGUI Development Team This is Crazy Eddie's GUI System Mk-2; a free library providing windowing and widgets for graphics APIs and engines where such functionality is not natively @@ -37,6 +37,7 @@ The documentation for CEGUI is split into the following sections: - @ref input_tutorial - Porting Guides + - @ref porting7to8 - @ref porting6to7 - Additional reference material diff --git a/doc/doxygen/porting7to8.dox b/doc/doxygen/porting7to8.dox new file mode 100644 index 000000000..fcffb0b05 --- /dev/null +++ b/doc/doxygen/porting7to8.dox @@ -0,0 +1,126 @@ +namespace CEGUI { +/** +@page porting7to8 Porting from CEGUI 0.7.x to CEGUI 0.8.x +@author Lukas Meindl + +This page lists the major breaking changes, and other related changes, made to +the library for the 0.8.x series of releases. + + +@note Note that while attempts have been made to see that most of the major +changes are listed on this page, it's entirely possible - even likely - that +somewhere along the line some things have been missed out. In those cases, +please visit the CEGUI forums. Also +consider looking at AND editing the wiki page for these porting tips: http://cegui.org.uk/wiki/Porting_tips_and_changes_from_0.7.X_to_0.8.X + + +@note Also note that f you build your own version of ceed (see this guide for Windows: http://cegui.org.uk/wiki/Building_CEED_for_Windows and this for other OS: http://cegui.org.uk/wiki/CEED), you can then use the ceed-migrate tool to automate and batch all of the changes discussed in this section. See here for a quick guide to using ceed-migrate - http://cegui.org.uk/wiki/Using_CEED-Migrate + + + + Major renames/API changes +- FalagardWRBase was renamed to CoreWindowRendererSet +- Windows now don't have absolute names! Every window's name only has to be unique in it's parent window. Therefore WindowManager::getSingleton().getWindow no longer made sense and was removed. If root's name was "Root" and your the window name was "Root/Stuff/After/Root/Name", you can emulate its behaviour with root->getChild("Stuff/After/Root/Name"). It's recommended to migrate to a more encapsulated model. +- CEGUI::GUIContext class has been created that is responsible for injecting input and event handling, setting the default font, setting the root window, setting a default tooltip object and type, and manipulating the mouse cursor. +- CEGUI::GUIContext needs time impulses injected separately! You should also inject time pulses into CEGUI::System. This API "wart" may disappear in future versions. +- CEGUI::MouseCursor is no longer a singleton, and can be accessed and manipulated from CEGUI::GUIContext. + + General +- All XML attributes must now be in lowercase, e.g. must be +- PropertyHelper has been turned into a template class, instead of PropertyHelper::uintToString you do PropertyHelper::toString, instead of PropertyHelper::stringToUint you do PropertyHelper::fromString +- All instances of the word caret that were incorrectly spelt 'carat' have been corrected. This affects all APIs, properties, events and datafiles. +- Window::EventWindowUpdated renamed to Window::EventUpdated and the associated string is changed from "WindowUpdate" to "Updated" +- ListHeader::SegmentNameSuffix changed type from character array to CEGUI::String +- BiDiVisualMapping renamed to BidiVisualMapping. Also renamed the files, so CEGUIBiDiVisualMapping.h is now CEGUIBidiVisualMapping.h +- class colour renamed to Colour, as a side effect the "colour" interpolator is now "Colour" interpolator, this breaks animation definitions! +- Point typedef removed, please use Vector2 instead +- Many event string values changed to match the C++ name (but without the Event prefix). A list of which strings changed value will appear here soon. +- Window::setRestoreCapture renamed to Window::setRestoreOldCapture +- CEGUI now supports custom memory allocation, see [[Memory Allocation]] to check if this concerns you or not. +- Window::addChildWindow renamed to Window::addChild, Window::removeChildWindow renamed to Window::removeChild, several other methods (mostly in layout containers) changed from *ChildWindow- to *Child* +- CEGUI::String can now be just a typedef or a class, depending on String configuration (CEGUI can now use std::string as CEGUI::String for apps not requiring unicode) +- Window::getChild_impl method completely removed, it was only used by Window::getParentPixelSize, shouldn't be hard to replace +- Vector2, Vector3, Size and Rect are now templated, you should use Vector2 (or just Vector2<> as a shortcut since float is the default type) instead of Vector2, UVector2 class was removed, UVector2 is now just a typedef to Vector2. Same with Vector3, Size and Rect. +- Texture::saveToMemory is renamed Texture::blitToMemory. +- Renderer and Texture interfaces changed in order to support named textures. +- Window::isDisabled(localOnly) is now split into Window::isDisabled (= old isDisabled(true) and Window::isEffectiveDisabled (= old isDisabled(false)) +- Window::isVisible(localOnly) is now split into Window::isVisible (= old isDisabled(true) and Window::isEffectiveVisible (= old isVisible(false)) +- WindowManager::loadWindowLayout is renamed to WindowManager::loadLayoutFromFile +- NamedXMLResourceManager::create is renamed to NamedXMLResourceManager::createFromFile (Ex. CEGUI::SchemeManager::createFromFile) +- CEGUI::DefaultLogger no longer throws const char- but a real exception in setLogFilename - http://www.cegui.org.uk/mantis/view.php?id=443 +- CEGUI now has inbuilt copy, cut, paste support, if you used a custom solution, you might want to check CEGUI::Clipboard and System::inject{Copy,Cut,Paste}Request +- CEGUI::ProgressBar::getStep renamed to getStepSize for consistency with setStepSize +- CEGUI::WidgetLookManager::parseLookNFeelSpecification is now called parseLookNFeelSpecificationFromFile, variants for loading from string and raw data container have been added +- XRotation, YRotation, ZRotation properties merged into the new Rotation property, which is a Quaternion. + + Property Name Changes +- Property from Window called "ZOrderChangeEnabled" renamed to "ZOrderingEnabled" +- Property from Window called "MouseButtonDownAutoRepeat" renamed to "MouseAutoRepeatEnabled" +- Property from Window called "CustomTooltipType" renamed to "TooltipType" +- Property from Window called "Tooltip" renamed to "TooltipText" +- Property from Window called "RiseOnClick" renamed to "RiseOnClickEnabled" +- Property from Window called "UnifiedAreaRect" renamed to "Area", "UnifiedSize" renamed to "Size", etc... +- Property "MaxEditTextLength" renamed to "MaxTextLength" + +Event Name Changes +- EventMouseEnters renamed to EventMouseEntersSurface (old name removed) +- EventMouseLeaves renamed to EventMouseLeavesSurface (old name removed) +- CheckStateChanged renamed to SelectStateChanged (for ToggleButton (old Checkbox)) + +Image and ImageManager +- Image::draw renamed to Image::render +- Image class is now an abstract interface. BasicImage implementation is provided, and used for internally created Image objects. +- Imageset class is removed. It remains a CEGUI format that allows to conveniently define multiple images on one texture but the data is no longer stored in any class. When Imageset is loaded, the ImageManager creates a new BasicImage for each of the images in the imageset. Only the images themselves will remain after imageset is loaded. You now use the new ImageManager to access defined images. +- ImagesetManager class is removed. You now use the new ImageManager. +- Images belonging to a certain imageset can be accessed like so: "ImageSetName/ImageName" (ex. "AlfiskoSkin/MouseArrow"). + +GUIContext + +A lot of API has been moved from CEGUI::System to CEGUI::GUIContext. CEGUI now allows you to create multiple independent GUI contexts with their own input injection. + +As a rule of thumb, whenever you see "There is no CEGUI::System::some_foobar_method method", it is likely that you can replace the call with CEGUI::System::getSingleton().getDefaultGUIContext().someFoobarMethod(). This holds for all the System::inject- methods for example. + +Exceptions from the rule: +- CEGUI::System::getSingleton().renderGUI() → CEGUI::System::getSingleton().renderAllGUIContexts() +- CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow") ? CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow") +- CEGUI::System::getSingleton().setGUISheet(root) → CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(root) + +WindowManager::getSingleton().getWindow() was removed. You can emulate its behaviour with root->getChild("Stuff/After/Root/Name"). +To get Root Window you can call GUIContext::getRootWindow(); + +SIDE NOTE: The chain call of methods CEGUI::System::getSingleton().getDefaultGUIContext() should be called as rarely as possible, instead one should keep it's result in appropriate variable. + + PyCEGUI +- EventSet.subscribeEvent now has a different, more pythonic syntax, any python callable (bound member function, free function, lambda, functor, ...) is allowed (EventSet.subscribeEvent("EventName", instance, "someMethodInIt") is now EventSet.subscribeEvent("EventName", instance.someMethodInIt) + + Datafiles +- All XML datafiles must specify a version attribute. Example: +- All attributes in datafiles must begin with a lower-case letter. Example: +- See '''Property Name Changes''' and '''Event Name Changes''' above +- .looknfeel: + - + - old:
new: + - Change: MaxEditTextLength → MaxTextLength + - Change: MouseButtonDownAutoRepeat → MouseAutoRepeatEnabled + - Change: DimOperator → OperatorDim. Please compare [http://static.cegui.org.uk/docs/0.7.9/fal_element_ref.html#fal_elem_ref_sec_10 0.7.9] with [http://static.cegui.org.uk/docs/current/fal_element_ref.html#fal_elem_ref_sec_operatordim latest] for functional change description + - old formatting: VALUE1 { DIMOPERATOR() { VALUE2 } }
new formatting: OPERATORDIM() { VALUE1, VALUE2 } +- .scheme: + - + - Change: + - Change: renderer="Falagard/... → renderer="Core/... + - Change: "Core/SystemButton" → "Core/Button" + - Change: "CEGUI/Checkbox" → "CEGUI/ToggleButton" +- .layout: + - + - UnifiedPosition, UnifiedAreaRect, UnifiedSize, UnifiedMinSize, UnifiedMaxSize → Position, Area, Size, MinSize, MaxSize + - Tooltip → TooltipText + - old:
new: +- .imageset: + - +- .font: + - + + + +*/ +} diff --git a/doc/doxygen/tutorials/ce_guide_1.dox b/doc/doxygen/tutorials/ce_guide_1.dox index f91a378c3..00ccb88a1 100644 --- a/doc/doxygen/tutorials/ce_guide_1.dox +++ b/doc/doxygen/tutorials/ce_guide_1.dox @@ -25,6 +25,7 @@ Renderer class for your chosen API or engine. Unless you're doing something adv otherwise unusual, these are the fuctions you'll want to use, since they enable the creation of all the initial CEGUI objects in a single call. + Note that the Renderers also have destroySystem functions for cleaning up afterwards. The Ogre3D and Irrlicht engines each have their own intergrated file loading and @@ -40,7 +41,7 @@ automatically. As stated above, when using the boostrapSystem functions, initialising CEGUI is as simple as a single function call: -@subsection rendering_tutorial_bootstrap_opengl OpenGL (Fixed Function) +@subsection rendering_tutorial_bootstrap_opengl Old desktop OpenGL 1.2 (Fixed Function) - Header: - Library: CEGUIOpenGLRenderer-0 @code @@ -54,16 +55,23 @@ CEGUI::OpenGLRenderer& myRenderer = CEGUI::OpenGLRenderer::bootstrapSystem(); @endcode -@subsection rendering_tutorial_bootstrap_opengl3 OpenGL 3 +@subsection rendering_tutorial_bootstrap_opengl3 Desktop OpenGL 3.2 or OpenGL ES 2.0 - Header: - Library: CEGUIOpenGLRenderer-0 +- Note: to use this renderer with OpenGL ES 2.0, the Epoxy OpenGL loading library + (https://github.com/yaronct/libepoxy, major version 1) + must first be installed, and CEGUI must be configured with + "-DCEGUI_BUILD_RENDERER_OPENGL=OFF -DCEGUI_BUILD_RENDERER_OPENGL3=ON + -DCEGUI_USE_EPOXY=ON -DCEGUI_USE_GLEW=OFF". @code // Bootstrap CEGUI::System with an OpenGL3Renderer object that uses the // current GL viewport, the DefaultResourceProvider, and the default // ImageCodec. // // NB: Your OpenGL context must already be initialised when you call this; CEGUI -// will not create the OpenGL context itself. +// will not create the OpenGL context itself. Nothing special has to be done to +// choose between desktop OpenGL and OpenGL ES: the type is automatically +// determined by the type of the current OpenGL context. CEGUI::OpenGL3Renderer& myRenderer = CEGUI::OpenGL3Renderer::bootstrapSystem(); @endcode @@ -132,7 +140,7 @@ CEGUI::Direct3D10Renderer& myRenderer = CEGUI::Direct3D10Renderer::create( myD3D10Device ); @endcode -@subsubsection rendering_tutorial_renderer_ogl OpenGL (Fixed Function) +@subsubsection rendering_tutorial_renderer_ogl old Desktop OpenGL 1.2 (Fixed Function) - Header: - Library: CEGUIOpenGLRenderer-0 @code @@ -142,7 +150,7 @@ CEGUI::OpenGLRenderer& myRenderer = CEGUI::OpenGLRenderer::create(); @endcode -@subsubsection rendering_tutorial_renderer_ogl3 OpenGL 3 +@subsubsection rendering_tutorial_renderer_ogl3 Desktop OpenGL 3.2 or OpenGL ES 2.0 - Header: - Library: CEGUIOpenGL3Renderer-0 @code @@ -180,6 +188,20 @@ core CEGUI system to initialise itself. CEGUI::System::create( myRenderer ); @endcode + +
+@section Deinitialisation +Don't forget to deinitialise your CEGUI System and your CEGUI Renderer. This must be done in the following order: +1. Call @code CEGUI::System::destroy(); @endcode to destroy the CEGUI System. +2. Then destroy your CEGUI renderer (which you should store in a pointer, such as d_renderer) , e.g.: + @code CEGUI::OpenGL3Renderer::destroy(static_cast(*d_renderer)); @endcode + +The above expression inside the call casts the pointer, which is of type Renderer*, to the specific subtype Renderer class - in this case OpenGL3Renderer. You can of course store the reference to the Renderer using the correct subtype (here: OpenGL3Renderer) from the beginning. + +In order to prevent leaks you will also need to destroy any GUIContexts, Textures and GeometryBuffers that you manually created. Windows, Images and other regularly created parts of CEGUI will be destroyed following the above two destruction calls automatically. In case you dynamically create a large amount of CEGUI windows or other objects in your application during run-time, you are advised to destroy them to reduce memory usage. + + +
@section rendering_tutorial_draw Call the function to render the GUI This is the only step that, depending upon your target engine, can be done @@ -223,7 +245,7 @@ draw3DScene(); mySwapChain->Present(0, 0); @endcode -@subsection rendering_tutorial_draw_ogl OpenGL +@subsection rendering_tutorial_draw_ogl OpenGL (desktop or ES) @code // user function to draw 3D scene draw3DScene(); @@ -234,8 +256,8 @@ draw3DScene(); // glActiveTexture(GL_TEXTURE_0) // draw GUI - // NB: When not using >=3.2 core profile, this call should not occur - // between glBegin/glEnd calls. + // NB: When using the old desktop OpenGL 1.2 renderer, this call should not + // occur between glBegin/glEnd calls. CEGUI::System::getSingleton().renderAllGUIContexts(); @endcode diff --git a/doc/doxygen/tutorials/ce_guide_3.dox b/doc/doxygen/tutorials/ce_guide_3.dox index ee45882fe..9b6a509a1 100644 --- a/doc/doxygen/tutorials/ce_guide_3.dox +++ b/doc/doxygen/tutorials/ce_guide_3.dox @@ -174,6 +174,10 @@ In the above code (and in the CEGUI samples) it is assumed that the resource group locations and the default groups have all been set up as described in @ref resprov_tutorial. +The `TaharezLook.scheme` file used as an example in this tutorial, as well as the corresponding imageset, font and looknfeel files (including `DejaVuSans-10.font`), are shipped with CEGUI's source package, SDK and other forms of distribution by default. Depending on how you installed CEGUI, these files might therefore already be available on your system (e.g., in `/usr/share/cegui/datafiles` on a Linux system). If you downloaded the source package or got CEGUI from the repository, then the files should be in the folder `datafiles/` of your CEGUI folder, which is the default folder and the structure that the CEGUI SampleBrowser uses on Windows for the samples. + +If you do not have the files, download the CEGUI source tarball or zip corresponding to your version of CEGUI from the download page (http://cegui.org.uk/download) and extract it. Inside it you will find a directory `datafiles/` whose inner structure corresponds to the structure recommended in the previous tutorial: @ref resprov_tutorial. Copy the files from there into the directories you set up (or simply copy the entire `datafiles/`directory if you are lazy). If you dont do this, CEGUI will complain about these files being not found and will crash your program with an exception. +
@section datafile_tutorial_setup_defaults System Defaults Initialisation Finally, you need to specify some default options for the System. This ensures diff --git a/doc/doxygen/tutorials/ce_guide_4.dox b/doc/doxygen/tutorials/ce_guide_4.dox index f751af59e..7fea24201 100644 --- a/doc/doxygen/tutorials/ce_guide_4.dox +++ b/doc/doxygen/tutorials/ce_guide_4.dox @@ -54,10 +54,19 @@ WindowManager& wmgr = WindowManager::getSingleton(); @endcode In general, you will be using what is known as a DefaultWindow as the 'root' -window in your GUI layouts. This is not required, but has a couple of useful -benefits as regards to input handling, is the accepted pattern of usage for -CEGUI and, once you start adding more top-level windows, helps simplify laying -things out. +window in your GUI layouts. This is not required, but heavily recommended as +it has a couple of useful +benefits regarding input handling and fits the generally accepted pattern of usage for +CEGUI. Also, once you start adding more top-level windows, it helps simplify laying +things out. + +The recommended root window for any CEGUI application (and also for your layout files) is +a DefaultWindow that covers the entire application window. You can make it cover the entire +window simply by setting the window's size to 1.0 relative width and height and setting the +position to the origin (0,0). This is the default for newly created DefaultWindows and therefore +does not have to be set specifically such a window. The window can be set as root window anytime +once it has been created. There can always only be one root window. All other windows should be +attached to this window. So, to get the ball rolling, we'll create a DefaultWindow as set it as the root window for the initial, default GUIContext: diff --git a/doc/doxygen/xml_animation.dox b/doc/doxygen/xml_animation.dox index 9a5e68d27..fd708dcf1 100644 --- a/doc/doxygen/xml_animation.dox +++ b/doc/doxygen/xml_animation.dox @@ -56,7 +56,7 @@ The reference for each element is arranged into sections, as described below: be registered with the system. Stock interpolators are provided for the following: - @c "bool" - - @c "colour" + - @c "Colour" - @c "ColourRect" - @c "float" - @c "int" diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 91d189faa..335eb2d88 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -5,22 +5,24 @@ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/common/SamplesXmlHeader.xml DEMO_META_DATA file(APPEND ${CMAKE_BINARY_DIR}/datafiles/samples/samples.xml ${DEMO_META_DATA}) add_subdirectory(HelloWorld) -add_subdirectory(WidgetDemo) -add_subdirectory(EffectsDemo) -add_subdirectory(FontDemo) +add_subdirectory(LookNFeelOverview) -add_subdirectory(Demo6) -add_subdirectory(DragDropDemo) -add_subdirectory(EditboxValidationDemo) add_subdirectory(GameMenu) add_subdirectory(HUDDemo) +add_subdirectory(DragDropDemo) add_subdirectory(InventoryDemo) +add_subdirectory(EffectsDemo) +add_subdirectory(FontDemo) +add_subdirectory(Demo6) + +add_subdirectory(EditboxValidationDemo) add_subdirectory(Minesweeper) add_subdirectory(ScrollablePaneDemo) add_subdirectory(TabControlDemo) +add_subdirectory(CommonDialogsDemo) +add_subdirectory(WidgetDemo) add_subdirectory(TextDemo) add_subdirectory(TreeDemo) -add_subdirectory(CommonDialogsDemo) if (CEGUI_BUILD_LUA_MODULE) # add_subdirectory(Demo8) @@ -42,4 +44,4 @@ file(APPEND ${CMAKE_BINARY_DIR}/datafiles/samples/samples.xml ${DEMO_META_DATA}) # And add it to the install install(FILES ${CMAKE_BINARY_DIR}/datafiles/samples/samples.xml - DESTINATION ${CEGUI_DATA_INSTALL_DIR}/samples/) + DESTINATION ${CEGUI_DATA_INSTALL_DIR}/samples/ COMPONENT cegui_samples) diff --git a/samples/EditboxValidationDemo/EditboxValidation.cpp b/samples/EditboxValidationDemo/EditboxValidation.cpp index 8717f9c94..35f07b540 100644 --- a/samples/EditboxValidationDemo/EditboxValidation.cpp +++ b/samples/EditboxValidationDemo/EditboxValidation.cpp @@ -99,7 +99,7 @@ bool EditboxValidation::validationChangeHandler(const CEGUI::EventArgs& args) } //----------------------------------------------------------------------------// -bool EditboxValidation::quitButtonHandler(const CEGUI::EventArgs& args) +bool EditboxValidation::quitButtonHandler(const CEGUI::EventArgs&) { return true; } diff --git a/samples/EffectsDemo/EffectsDemo.cpp b/samples/EffectsDemo/EffectsDemo.cpp index 294b824fd..ac2824161 100644 --- a/samples/EffectsDemo/EffectsDemo.cpp +++ b/samples/EffectsDemo/EffectsDemo.cpp @@ -62,9 +62,9 @@ void WobblyWindowEffect::syncPivots(CEGUI::RenderingWindow& window) { const CEGUI::Rectf pixelRect = CEGUI::Rectf(window.getPosition(), window.getSize()); - for (size_t y = 0; y < ds_yPivotCount; ++y) + for (int y = 0; y < ds_yPivotCount; ++y) { - for (size_t x = 0; x < ds_xPivotCount; ++x) + for (int x = 0; x < ds_xPivotCount; ++x) { const float factorMinX = static_cast(ds_xPivotCount - x) / (ds_xPivotCount - 1); const float factorMaxX = static_cast(x) / (ds_xPivotCount - 1); @@ -167,13 +167,12 @@ bool WobblyWindowEffect::update(const float elapsed, CEGUI::RenderingWindow& win const CEGUI::Rectf pixelRect = CEGUI::Rectf(window.getPosition(), window.getSize()); - const CEGUI::MouseCursor& cursor = d_window->getGUIContext().getMouseCursor(); - bool changed = false; - for (size_t y = 0; y < ds_yPivotCount; ++y) + for (int y = 0; y < ds_yPivotCount; ++y) { - for (size_t x = 0; x < ds_xPivotCount; ++x) + for (int + x = 0; x < ds_xPivotCount; ++x) { const float factorMinX = static_cast(ds_xPivotCount - 1- x) / (ds_xPivotCount - 1); const float factorMaxX = static_cast(x) / (ds_xPivotCount - 1); diff --git a/samples/FontDemo/LanguageStrings.h b/samples/FontDemo/LanguageStrings.h new file mode 100644 index 000000000..65c7684cc --- /dev/null +++ b/samples/FontDemo/LanguageStrings.h @@ -0,0 +1,199 @@ +/*********************************************************************** +created: 24/11/2015 +author: Lukas Meindl +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ + +#ifndef _LanguageStrings_h_ +#define _LanguageStrings_h_ + +#include "CEGUI/String.h" + +using namespace CEGUI; + +namespace LanguageStrings +{ + +static const unsigned int LangListSize = 12; + +static struct +{ + encoded_char* Language; + encoded_char* Font; + encoded_char* Text; +} LangList[LangListSize] = +{ + // A list of strings in different languages stored as hexadecimal UTF-8 code units + // Feel free to add your own language here. + // Since this is part of the source code we escape the characters to ensure greater + // support and so that we do not have to encode the file itself. Normally you would load + // the text from an UTF-8 encoded file, where you could regular unescaped unicode characters. + // So do not be afraid by the looks of this ;) We just want to avoid having to extra load any + // files in the samples to keep it simple. + { + (encoded_char*)"Sandbox", + (encoded_char*)"DejaVuSans-12", + (encoded_char*)"Try out writing text in any language here. The used font can be changed on the right.\n" + "You can create new fonts if needed. The new font will be set as font for the selected text/language...\n" + "You can also edit the fonts that are part of this demo or the ones you created here (however, this demo won't allow to change the fonts of the other Samples)\n" + "Important: When you switch to a font the FIRST time, it takes some time to load it. Especially for fonts with a lot of non-ASCII characters this load time might be noticeable.!" + }, + { + (encoded_char*)"European characters using DejaVuSans font", + (encoded_char*)"DejaVuSans-12", + (encoded_char*)"Try Catching The Brown Fox While It's Jumping Over The Lazy Dog\n\n" + "Supports most European unicode characters, but for example no cyrillic:\n" + "\x62\x6F\x6B\x6D\xC3\xA5\x6C\x2C\x20\xC4\x8D\x65\x73\x6B\x79\x2C\x20\x73" + "\x6C\x6F\x76\x65\x6E\xC5\xA1\xC4\x8D\x69\x6E\x61\x2C\x20\x6C\x61\x74\x76" + "\x69\x65\xC5\xA1\x75\x2C\x20\x54\x69\xE1\xBA\xBF\x6E\x67\x20\x56\x69\xE1" + "\xBB\x87\x74\x2C\x20\x65\x74\x63\x2E" + "\xC2\xA5\xC2\xA4\xC2\xA3\xC2\xA2\xC2\xA9\xC2\xAE\xC3\x90\xC3\x86\x5C" + "\x6E\xC3\x84\xC3\x9C\xC3\x96\xC3\xA4\xC3\xBC\xC3\xB6\xC3\x9F\x5C\x6E" + "\xC4\x93\xC4\x92\xC5\x97\xC5\x96\xC5\xAB\xC5\xAA\xC4\xAB\xC4\xAA\xC4" + "\x81\xC4\x80\xC5\xA1\xC5\xA0\xC4\xA3\xC4\xA2\xC4\xB7\xC4\xB6\xC4\xBC" + "\xC4\xBB\xC5\xBE\xC5\xBD\xC4\x8D\xC4\x8C\xC5\x86\xC5\x85\x5C\x6E\xC3" + "\xB8\xC3\x98\xC3\xA6\xC3\x86\xC3\xA5\xC3\x85\xC3\xA8\xC3\xA2\xC3\xAF" + "\xC3\x80\xC3\x81\xC3\x82\xC6\x92\xC3\xA9\xC3\xAD\xC3\xB3\xC3\xBA\xC3" + "\x89\xC3\x8D\xC3\x93\xC3\x9A\xC3\xB5\xC3\xA7\xC2\xBF\xC3\xB1\xC3\x91" + }, + { + (encoded_char*)"European characters using Junicode font", + (encoded_char*)"Junicode-14", + (encoded_char*)"Try Catching The Brown Fox While It's Jumping Over The Lazy Dog\n\n" + "Supports most European unicode characters, but for example no cyrillic:\n" + "\x62\x6F\x6B\x6D\xC3\xA5\x6C\x2C\x20\xC4\x8D\x65\x73\x6B\x79\x2C\x20\x73" + "\x6C\x6F\x76\x65\x6E\xC5\xA1\xC4\x8D\x69\x6E\x61\x2C\x20\x6C\x61\x74\x76" + "\x69\x65\xC5\xA1\x75\x2C\x20\x54\x69\xE1\xBA\xBF\x6E\x67\x20\x56\x69\xE1" + "\xBB\x87\x74\x2C\x20\x65\x74\x63\x2E" + "\xC2\xA5\xC2\xA4\xC2\xA3\xC2\xA2\xC2\xA9\xC2\xAE\xC3\x90\xC3\x86\x5C" + "\x6E\xC3\x84\xC3\x9C\xC3\x96\xC3\xA4\xC3\xBC\xC3\xB6\xC3\x9F\x5C\x6E" + "\xC4\x93\xC4\x92\xC5\x97\xC5\x96\xC5\xAB\xC5\xAA\xC4\xAB\xC4\xAA\xC4" + "\x81\xC4\x80\xC5\xA1\xC5\xA0\xC4\xA3\xC4\xA2\xC4\xB7\xC4\xB6\xC4\xBC" + "\xC4\xBB\xC5\xBE\xC5\xBD\xC4\x8D\xC4\x8C\xC5\x86\xC5\x85\x5C\x6E\xC3" + "\xB8\xC3\x98\xC3\xA6\xC3\x86\xC3\xA5\xC3\x85\xC3\xA8\xC3\xA2\xC3\xAF" + "\xC3\x80\xC3\x81\xC3\x82\xC6\x92\xC3\xA9\xC3\xAD\xC3\xB3\xC3\xBA\xC3" + "\x89\xC3\x8D\xC3\x93\xC3\x9A\xC3\xB5\xC3\xA7\xC2\xBF\xC3\xB1\xC3\x91" + }, + { + (encoded_char*)"Korean/Chinese/Japanese using Batang font", + (encoded_char*)"Batang-18", + + //Japanese + (encoded_char*)"\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E\xE3\x82\x92\xE9\x81\xB8\xE6\x8A\x9E\n" + "\xE3\x83\x88\xE3\x83\xAA\xE3\x82\xAC\xE3\x83\xBC\xE6\xA4\x9C\xE7\x9F\xA5\n" + "\xE9\x89\xB1\xE7\x9F\xB3\xE5\x82\x99\xE8\x93\x84\xE4\xB8\x8D\xE8\xB6\xB3\n\n\n\n\n" + + //Chinese + "\xE6\x97\xA9\xE7\x99\xBC\xE7\x99\xBD\xE5\xB8\x9D\xE5\x9F\x8E\x20\x28\xE6\x9D\x8E\xE7\x99\xBD\x29\n\n" + + "\xE6\x9C\x9D\xE8\xBE\xAD\xE7\x99\xBD\xE5\xB8\x9D\xE5\xBD\xA9\xE9\x9B\xB2\xE9\x96\x93\xEF\xBC\x8C\n" + "\xE5\x8D\x83\xE9\x87\x8C\xE6\xB1\x9F\xE9\x99\xB5\xE4\xB8\x80\xE6\x97\xA5\xE9\x82\x84\xE3\x80\x82\n" + "\xE5\x85\xA9\xE5\xB2\xB8\xE7\x8C\xBF\xE8\x81\xB2\xE5\x95\xBC\xE4\xB8\x8D\xE4\xBD\x8F\xEF\xBC\x8C\n" + "\xE8\xBC\x95\xE8\x88\x9F\xE5\xB7\xB1\xE9\x81\x8E\xE8\x90\xAC\xE9\x87\x8D\xE5\xB1\xB1\xE3\x80\x82\n\n\n\n\n" + + //Korean + "\xEC\x9D\xB4\xEB\xAA\xB8\xEC\x9D\xB4\x2F\xEC\xA3\xBD\xEA\xB3\xA0\xEC\xA3\xBD\xEC\x96\xB4\x2F\xEC\x9D" + "\xBC\xEB\xB0\xB1\xEB\xB2\x88\x2F\xEA\xB3\xA0\xEC\xB3\x90\xEC\xA3\xBD\xEC\x96\xB4\x2F\n" + "\xEB\xB0\xB1\xEA\xB3\xA8\xEC\x9D\xB4\x2F\xEC\xA7\x84\xED\x87\xB4\xEB\x90\x98\xEC\x96\xB4" + "\x2F\xEB\x84\x8B\xEC\x9D\xB4\xEB\x9D\xBC\xEB\x8F\x84\x2F\xEC\x9E\x88\xEA\xB3\xA0\xEC\x97\x86\xEA\xB3\xA0\x2F\n" + "\xEC\x9E\x84\x20\xED\x96\xA5\xED\x95\x9C\x2F\xEC\x9D\xBC\xED\x8E\xB8\xEB\x8B\xA8\xEC\x8B\xAC\xEC" + "\x9D\xB4\xEC\x95\xBC\x2F\xEA\xB0\x80\xEC\x8B\xA4\x20\xEC\xA4" + "\x84\xEC\x9D\xB4\x2F\xEC\x9E\x88\xEC\x9C\xBC\xEB\x9E\xB4/" + }, + { + (encoded_char*)"Hebrew using TnuaLibre font", + (encoded_char*)"TnuaLibre-12", + (encoded_char*)"\xD7\xAA\xD7\xA0\xD7\x95\xD7\xA2\xD7\x94\n" + "\xD7\x97\xD7\x95\xD7\xA4\xD7\xA9\xD7\x99 **\xD7\x90\xD7\x91\xD7\x92\xD7\x93 \n" + "1234" + }, + { + (encoded_char*)"Old German using Fette UNZ Fraktur font", + (encoded_char*)"FetteUNZFraktur-20", + (encoded_char*)"Heute back ich, morgen brau ich,\n" + "\xC3\x9C bermorgen hol ich mir der K\xC3\xB6 nigin ihr Kind;\n" + "Ach, wie gut, dass niemand wei\xC3\x9F ,\n" + "dass ich Rumpelstilzchen hei\xC3\x9F" + }, + { + (encoded_char*)"Latin using Old Fell Type font", + (encoded_char*)"FellType-12.5", + (encoded_char*)"\xE2\x98\x9E Non nobis, non nobis, Domine\n" + "Sed nomini tuo da gloriam.\xE2\x98\x9C\n" + "\xEE\x80\x9C\x20\xEE\x81\x87\x20\xEE\x81\x80\x20\xEE\x81\x81\x20\xC3\x90" + }, + { + (encoded_char*)"Handwriting font", + (encoded_char*)"GreatVibes-22", + (encoded_char*)"Dear Gooby,\n\n" + "Handwriting is nice when you don't have to do it yourself.\n\n" + "Regards, Uncle Dolan." + }, + { + (encoded_char*)"RichStyle Icons font", + (encoded_char*)"RichStyle-22", + (encoded_char*)"\x2B\x20\x2D\x20\x3F\x20\x42\x20\x49\x20\x57\x20\x59\x20\x66\x20\x6E\x20\x74\x20\xE2" + "\x84\xB9\x20\xE2\x87\xA6\x20\xE2\x87\xA7\x20\xE2\x87\xA8\x20\xE2\x87\xA9\x20\xE2\x8C" + "\x98\x20\xE2\x98\x8E\x20\xE2\x98\x90\x20\xE2\x98\x91\x20\xE2\x9A\x96\x20\xE2\x9A\x99" + "\x20\xE2\x9A\xA0\x20\xE2\x9B\x8F\x20\xE2\x9C\x8E\x20\xE2\x9C\x91\x20\xE2\x9C\x93\x20" + "\xE2\x9C\x94\x20\xE2\x9C\x95\x20\xE2\x9C\x96\x20\xE2\x9D\x9D\x20\xE2\x9D\x9E\x20\xE2" + "\x9E\xA1\x20\xE2\xAC\x80\x20\xE2\xAC\x81\x20\xE2\xAC\x82\x20\xE2\xAC\x83\x20\xE2\xAC" + "\x85\x20\xE2\xAC\x86\x20\xE2\xAC\x87\x20\xE2\xAC\x88\x20\xE2\xAC\x89\x20\xE2\xAC\x8A" + "\x20\xE2\xAC\x8B\x20\xEE\x80\x80\x20\xEE\x80\x81\x20\xEE\x80\x82\x20\xEE\x80\x83\x20" + "\xEE\x80\x84\x20\xEE\x80\x85\x20\xEE\x80\x86\x20\xEE\x80\x87\x20\xEE\x80\x88\x20\xEE" + "\x80\x89\x20\xEE\x80\x90\x20\xEE\x80\x91\x20\xEE\x80\x92\x20\xEE\x80\x93\x20\xEE\x80" + "\x94\x20\xEE\x80\x95\x20\xEE\x80\x96\x20\xEE\x80\x97\x20\xEE\x80\x98\x20\xEE\x80\x99" + "\x20\xEE\x80\xA0\x20\xEE\x80\xA1\x20\xEE\x80\xA2" + }, + { + (encoded_char*)"Old Runic writing using Futhark Adapted font", + (encoded_char*)"FutharkAdapted-18", + (encoded_char*)"Somehow, although he is the smallest office boy around the place, none of the other" + "lads pick on him. Scuffling and fighting almost has ceased since Kerensky came to work." + "That's only one of the nicknames of Leo Kobreen, and was assigned to him because of a" + "considerable facial resemblance to the perpetually fleeing Russian statesman, and, " + "too, because both wore quite formal standing collars." + }, + { + (encoded_char*)"Klingon using pIqaD HaSta font", + (encoded_char*)"Klingon-pIqaD-HaSta-24", + (encoded_char*)"\xEF\xA3\xA3\xEF\xA3\x9D\xEF\xA3\x93\xEF\xA3\xA5\xEF\xA3\x98\x20\xEF\xA3\xA9\xEF\xA3\x9D\xEF\xA3\xA2\x20\xEF\xA3\xA1\xEF\xA3\x9D\xEF\xA3\x99\xEF\xA3\xBE\n\n\n" + "\xEF\xA3\xA0\x20\xEF\xA3\xA1\x20\xEF\xA3\xA2\x20\xEF\xA3\xA3\x20\xEF\xA3\xA4\x20\xEF\xA3\xA5\x20\xEF\xA3\xA6\x20\xEF\xA3\xA7\x20\xEF\xA3\xA8\x20\xEF\xA3\xA9\n" + "\xEF\xA3\xB0\x20\xEF\xA3\xB1\x20\xEF\xA3\xB2\x20\xEF\xA3\xB3\x20\xEF\xA3\xB4\x20\xEF\xA3\xB5\x20\xEF\xA3\xB6\x20\xEF\xA3\xB7\x20\xEF\xA3\xB8\x20\xEF\xA3\xB9\n" + "\xEF\xA3\xBD\x20\xEF\xA3\xBE\x20\xEF\xA3\xBF" + }, + { + (encoded_char*)"Pixel style font using Mizufalp font", + (encoded_char*)"mizufalp-12", + (encoded_char*)"Mechanic: Somebody set up us the bomb.\n" + "Operator: Main screen turn on.\n" + "CATS: All your base are belong to us.\n" + "CATS: You have no chance to survive make your time." + } +}; + +} + + +#endif \ No newline at end of file diff --git a/samples/FontDemo/Sample_FontDemo.cpp b/samples/FontDemo/Sample_FontDemo.cpp index aa6d7c9eb..fbf506ba3 100644 --- a/samples/FontDemo/Sample_FontDemo.cpp +++ b/samples/FontDemo/Sample_FontDemo.cpp @@ -3,7 +3,7 @@ created: 17/6/2006 author: Paul D Turner *************************************************************************/ /*************************************************************************** -* Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -30,11 +30,11 @@ author: Paul D Turner // should look okay though when running. #include "Sample_FontDemo.h" +#include "LanguageStrings.h" #include "CEGUI/CEGUI.h" using namespace CEGUI; - -static const unsigned int LangListSize = 12; +using namespace LanguageStrings; struct FontOption { @@ -42,119 +42,6 @@ struct FontOption bool d_isEditable; }; -static struct -{ - encoded_char* Language; - encoded_char* Font; - encoded_char* Text; -} LangList [LangListSize] = -{ - // A list of strings in different languages - // Feel free to add your own language here (UTF-8 ONLY!)... - { - (encoded_char*)"Sandbox", - (encoded_char*)"DejaVuSans-12", - (encoded_char*)"Try out writing text in any language here. The used font can be changed on the right.\n" - "You can create new fonts if needed. The new font will be set as font for the selected text/language...\n" - "You can also edit the fonts that are part of this demo or the ones you created here (however, this demo won't allow to change the fonts of the other demos)\n" - "Important: When you switch to a font the FIRST time, it takes some time to load it. Especially for fonts with asian characters this load time might be noticable.!" - }, - { - (encoded_char*)"European characters using DejaVuSans font", - (encoded_char*)"DejaVuSans-12", - (encoded_char*)"Try Catching The Brown Fox While It's Jumping Over The Lazy Dog\n\n" - "Supports nearly all European unicode characters, including cyrillic:\n" - "bokmål, česky, русский, српски / srpski, slovenščina, latviešu, Tiếng Việt, etc.\n" - "¥¤£¢©®ÐÆ\nÄÜÖäüöß\nēĒŗŖūŪīĪāĀšŠģĢķĶļĻžŽčČņŅ\nøØæÆåÅèâïÀÁƒéíóúÉÍÓÚõç¿ñÑ\nускоряющпризв" - }, - { - (encoded_char*)"European characters using Junicode font", - (encoded_char*)"Junicode-14", - (encoded_char*)"Try Catching The Brown Fox While It's Jumping Over The Lazy Dog\n\n" - "Supports most European unicode characters, but for example no cyrillic:\n" - "bokmål, česky, slovenščina, latviešu, Tiếng Việt, etc.\n" - "¥¤£¢©®ÐÆ\nÄÜÖäüöß\nēĒŗŖūŪīĪāĀšŠģĢķĶļĻžŽčČņŅ\nøØæÆåÅèâïÀÁƒéíóúÉÍÓÚõç¿ñÑ" - }, - - { - (encoded_char*)"Korean/Chinese/Japanese using Batang font", - (encoded_char*)"Batang-18", - (encoded_char*) - //Japanese - "日本語を選択\n" - "トリガー検知\n" - "鉱石備蓄不足\n\n\n\n\n" - - //Chinese - "早發白帝城 (李白)\n\n" - - "朝辭白帝彩雲間,\n" - "千里江陵一日還。\n" - "兩岸猿聲啼不住,\n" - "輕舟己過萬重山。\n\n\n\n\n" - - //Korean - "이몸이/죽고죽어/일백번/고쳐죽어/\n" - "백골이/진퇴되어/넋이라도/있고없고/\n" - "임 향한/일편단심이야/가실 줄이/있으랴/" - }, - { - (encoded_char*)"Hebrew using TnuaLibre font", - (encoded_char*)"TnuaLibre-12", - (encoded_char*)"תנועה \n" - "חופשי ** אבגד \n" - "1234" - }, - { - (encoded_char*)"Old German using Fette UNZ Fraktur font", - (encoded_char*)"FetteUNZFraktur-20", - (encoded_char*)"Heute back ich, morgen brau ich,\n" - "Übermorgen hol ich mir der Königin ihr Kind;\n" - "Ach, wie gut, dass niemand weiß,\n" - "dass ich Rumpelstilzchen heiß" - }, - { - (encoded_char*)"Latin using Old Fell Type font", - (encoded_char*)"FellType-12.5", - (encoded_char*)"☞Non nobis, non nobis, Domine\n" - "Sed nomini tuo da gloriam.☜\n" - "    Ð" - }, - { - (encoded_char*)"Handwriting font", - (encoded_char*)"GreatVibes-22", - (encoded_char*)"Dear Gooby,\n\n" - "Handwriting is nice when you don't have to do it yourself.\n\n" - "Regards, Uncle Dolan." - }, - { - (encoded_char*)"RichStyle Icons font", - (encoded_char*)"RichStyle-22", - (encoded_char*)"+ - ? B I W Y f n t ℹ ⇦ ⇧ ⇨ ⇩ ⌘ ☎ ☐ ☑ ⚖ ⚙ ⚠ ⛏ ✎ ✑ ✓ ✔ ✕ ✖ ❝ ❞ ➡ ⬀ ⬁ ⬂ ⬃ ⬅ ⬆ ⬇ ⬈ ⬉ ⬊ ⬋                       " - }, - { - (encoded_char*)"Old Runic writing using Futhark Adapted font", - (encoded_char*)"FutharkAdapted-18", - (encoded_char*)"Somehow, although he is the smallest office boy around the place, none of the other lads pick on him. Scuffling and fighting almost has ceased since Kerensky came to work. That's only one of the nicknames of Leo Kobreen, and was assigned to him because of a considerable facial resemblance to the perpetually fleeing Russian statesman, and, too, because both wore quite formal standing collars." - }, - { - (encoded_char*)"Klingon using pIqaD HaSta font", - (encoded_char*)"Klingon-pIqaD-HaSta-24", - (encoded_char*)"  \n\n\n" - "         \n" - "         \n" - "  " - }, - { - (encoded_char*)"Pixel style font using Mizufalp font", - (encoded_char*)"mizufalp-12", - (encoded_char*)"Mechanic: Somebody set up us the bomb.\n" - "Operator: Main screen turn on.\n" - "CATS: All your base are belong to us.\n" - "CATS: You have no chance to survive make your time." - } -}; - // Sample sub-class for ListboxTextItem that auto-sets the selection brush // image. This saves doing it manually every time in the code. class MyListItem : public ListboxTextItem @@ -257,7 +144,7 @@ void FontDemo::deinitialise() { } -bool FontDemo::handleFontCreationButtonClicked(const EventArgs& e) +bool FontDemo::handleFontCreationButtonClicked(const EventArgs&) { FontManager& fontMgr(FontManager::getSingleton()); @@ -283,14 +170,14 @@ bool FontDemo::handleFontCreationButtonClicked(const EventArgs& e) String::size_type pos = fontFileName.rfind(".imageset"); - if(pos != -1) + if(pos != String::npos) { - CEGUI::Font& createdFont = fontMgr.createPixmapFont(fontName, fontFileName, Font::getDefaultResourceGroup(), autoScaleMode, + fontMgr.createPixmapFont(fontName, fontFileName, Font::getDefaultResourceGroup(), autoScaleMode, CEGUI::Sizef(1280.0f, 720.0f), XREA_THROW); } else { - CEGUI::Font& createdFont = fontMgr.createFreeTypeFont(fontName, fontSize, antiAlias, fontFileName, Font::getDefaultResourceGroup(), autoScaleMode, + fontMgr.createFreeTypeFont(fontName, fontSize, antiAlias, fontFileName, Font::getDefaultResourceGroup(), autoScaleMode, CEGUI::Sizef(1280.0f, 720.0f), XREA_THROW); } @@ -302,7 +189,7 @@ bool FontDemo::handleFontCreationButtonClicked(const EventArgs& e) } -bool FontDemo::handleFontEditButtonClicked(const EventArgs& e) +bool FontDemo::handleFontEditButtonClicked(const EventArgs&) { FontManager& fontMgr(FontManager::getSingleton()); @@ -338,7 +225,7 @@ bool FontDemo::handleFontEditButtonClicked(const EventArgs& e) return true; } -bool FontDemo::handleFontSelectionChanged(const EventArgs& e) +bool FontDemo::handleFontSelectionChanged(const EventArgs&) { //Change font of the selected language/text sample if(d_textSelector->getFirstSelectedItem() && d_fontSelector->getFirstSelectedItem()) @@ -405,7 +292,7 @@ bool FontDemo::handleFontSelectionChanged(const EventArgs& e) return true; } -bool FontDemo::handleTextSelectionChanged(const EventArgs& e) +bool FontDemo::handleTextSelectionChanged(const EventArgs&) { if(d_textSelector->getFirstSelectedItem()) { @@ -419,7 +306,7 @@ bool FontDemo::handleTextSelectionChanged(const EventArgs& e) return true; } -bool FontDemo::handleTextMultiLineEditboxTextChanged(const EventArgs& e) +bool FontDemo::handleTextMultiLineEditboxTextChanged(const EventArgs&) { if(d_textSelector->getFirstSelectedItem()) { @@ -431,14 +318,14 @@ bool FontDemo::handleTextMultiLineEditboxTextChanged(const EventArgs& e) return true; } -bool FontDemo::handleFontFileNameSelectionChanged(const EventArgs& e) +bool FontDemo::handleFontFileNameSelectionChanged(const EventArgs&) { generateNewFontName(); return true; } -bool FontDemo::handleRenewFontNameButtonClicked(const EventArgs& e) +bool FontDemo::handleRenewFontNameButtonClicked(const EventArgs&) { generateNewFontName(); diff --git a/samples/GLESTest/CMakeLists.txt b/samples/GLESTest/CMakeLists.txt index e252bd78a..45547cda1 100644 --- a/samples/GLESTest/CMakeLists.txt +++ b/samples/GLESTest/CMakeLists.txt @@ -1,4 +1,4 @@ cegui_add_sample(CEGUIGLESTest) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_OPENGLES_RENDERER_LIBNAME}) -cegui_add_dependency(${CEGUI_TARGET_NAME} OPENGLES) +cegui_add_dependency(${CEGUI_TARGET_NAME} OPENGLES PRIVATE TRUE) diff --git a/samples/GameMenu/GameMenu.cpp b/samples/GameMenu/GameMenu.cpp index f78396794..f3b8ffedd 100644 --- a/samples/GameMenu/GameMenu.cpp +++ b/samples/GameMenu/GameMenu.cpp @@ -34,6 +34,9 @@ author: Lukas E Meindl #define _USE_MATH_DEFINES #include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif using namespace CEGUI; @@ -291,8 +294,8 @@ void GameMenuDemo::update(float timeSinceLastUpdate) { d_timeSinceLoginAccepted += timeSinceLastUpdate; - updateLoginWelcomeText(timeSinceLastUpdate); - updateLoginStartButtonText(timeSinceLastUpdate); + updateLoginWelcomeText(); + updateLoginStartButtonText(); } if(d_timeSinceStart >= s_loginDisplayStartDelay && !d_loginContainer->isVisible()) @@ -305,7 +308,7 @@ void GameMenuDemo::update(float timeSinceLastUpdate) } } -bool GameMenuDemo::handleLoginAcceptButtonClicked(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleLoginAcceptButtonClicked(const CEGUI::EventArgs&) { d_startButtonClickArea->setAlpha(0.0f); d_startButtonBlendInAnimInst->start(); @@ -327,7 +330,7 @@ bool GameMenuDemo::handleLoginAcceptButtonClicked(const CEGUI::EventArgs& args) return false; } -bool GameMenuDemo::handleInnerPartStartClickAreaClick(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleInnerPartStartClickAreaClick(const CEGUI::EventArgs&) { if(!d_interactivePlanetElementsAreEnabled) enableInteractivePlanetElements(); @@ -341,7 +344,7 @@ bool GameMenuDemo::handleInnerPartStartClickAreaClick(const CEGUI::EventArgs& ar } -bool GameMenuDemo::handleCheckIfNaviIconAnimationNeedsChange(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleCheckIfNaviIconAnimationNeedsChange(const CEGUI::EventArgs&) { if(!d_loginWasAccepted) return false; @@ -405,7 +408,7 @@ bool GameMenuDemo::handleNaviSelectionIconAnimStart(const CEGUI::EventArgs& args return false; } -bool GameMenuDemo::handleMouseEntersLeftArrowArea(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleMouseEntersLeftArrowArea(const CEGUI::EventArgs&) { CEGUI::EventArgs fireArgs; if(d_loginWasAccepted) @@ -414,7 +417,7 @@ bool GameMenuDemo::handleMouseEntersLeftArrowArea(const CEGUI::EventArgs& args) return false; } -bool GameMenuDemo::handleMouseLeavesLeftArrowArea(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleMouseLeavesLeftArrowArea(const CEGUI::EventArgs&) { CEGUI::EventArgs fireArgs; if(d_loginWasAccepted) @@ -423,7 +426,7 @@ bool GameMenuDemo::handleMouseLeavesLeftArrowArea(const CEGUI::EventArgs& args) return false; } -bool GameMenuDemo::handleMouseEntersRightArrowArea(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleMouseEntersRightArrowArea(const CEGUI::EventArgs&) { CEGUI::EventArgs fireArgs; if(d_loginWasAccepted) @@ -432,7 +435,7 @@ bool GameMenuDemo::handleMouseEntersRightArrowArea(const CEGUI::EventArgs& args) return false; } -bool GameMenuDemo::handleMouseLeavesRightArrowArea(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleMouseLeavesRightArrowArea(const CEGUI::EventArgs&) { CEGUI::EventArgs fireArgs; if(d_loginWasAccepted) @@ -442,7 +445,7 @@ bool GameMenuDemo::handleMouseLeavesRightArrowArea(const CEGUI::EventArgs& args) } -bool GameMenuDemo::handleStartPopupLinesSaveDisplay(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleStartPopupLinesSaveDisplay(const CEGUI::EventArgs&) { if(!d_startButtonClicked) return false; @@ -457,7 +460,7 @@ bool GameMenuDemo::handleStartPopupLinesSaveDisplay(const CEGUI::EventArgs& args return false; } -bool GameMenuDemo::handleStartPopupLinesLoadDisplay(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleStartPopupLinesLoadDisplay(const CEGUI::EventArgs&) { if(!d_startButtonClicked) return false; @@ -472,7 +475,7 @@ bool GameMenuDemo::handleStartPopupLinesLoadDisplay(const CEGUI::EventArgs& args return false; } -bool GameMenuDemo::handleStartPopupLinesCharactersDisplay(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleStartPopupLinesCharactersDisplay(const CEGUI::EventArgs&) { if(!d_startButtonClicked) return false; @@ -491,7 +494,7 @@ bool GameMenuDemo::handleStartPopupLinesCharactersDisplay(const CEGUI::EventArgs } -bool GameMenuDemo::handleStartPopupLinesOptionsDisplay(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleStartPopupLinesOptionsDisplay(const CEGUI::EventArgs&) { if(!d_startButtonClicked) return false; @@ -509,7 +512,7 @@ bool GameMenuDemo::handleStartPopupLinesOptionsDisplay(const CEGUI::EventArgs& a } -bool GameMenuDemo::handleStartPopupLinesQuitDisplay(const CEGUI::EventArgs& args) +bool GameMenuDemo::handleStartPopupLinesQuitDisplay(const CEGUI::EventArgs&) { if(!d_startButtonClicked) return false; @@ -693,7 +696,7 @@ void GameMenuDemo::updateIntroText() d_botBarLabel->setText(finalText); } -void GameMenuDemo::updateLoginWelcomeText(float passedTime) +void GameMenuDemo::updateLoginWelcomeText() { if(d_timeSinceLoginAccepted <= 0.0f) return; @@ -719,7 +722,7 @@ void GameMenuDemo::updateLoginWelcomeText(float passedTime) } -void GameMenuDemo::updateLoginStartButtonText(float passedTime) +void GameMenuDemo::updateLoginStartButtonText() { if(d_timeSinceLoginAccepted <= 0.0f) return; @@ -983,4 +986,4 @@ extern "C" SAMPLE_EXPORT Sample& getSampleInstance() { static GameMenuDemo sample; return sample; -} \ No newline at end of file +} diff --git a/samples/GameMenu/GameMenu.h b/samples/GameMenu/GameMenu.h index 198208436..1ead8f24d 100644 --- a/samples/GameMenu/GameMenu.h +++ b/samples/GameMenu/GameMenu.h @@ -73,8 +73,8 @@ class GameMenuDemo : public Sample void startEntranceAnimations(); void updateIntroText(); - void updateLoginWelcomeText(float passedTime); - void updateLoginStartButtonText(float passedTime); + void updateLoginWelcomeText(); + void updateLoginStartButtonText(); void disableInteractivePlanetElements(); void enableInteractivePlanetElements(); void enableNavigationBarElements(); diff --git a/samples/HUDDemo/HUDemo.cpp b/samples/HUDDemo/HUDemo.cpp index 9d5951569..2d6281967 100644 --- a/samples/HUDDemo/HUDemo.cpp +++ b/samples/HUDDemo/HUDemo.cpp @@ -481,7 +481,7 @@ void HUDDemo::selectedWeapon(SelectedWeapon weapon) } } -bool HUDDemo::handleWeaponRightArrowClicked(const CEGUI::EventArgs& args) +bool HUDDemo::handleWeaponRightArrowClicked(const CEGUI::EventArgs&) { int weaponIndex = static_cast(d_selectedWeapon); weaponIndex = (weaponIndex - 1) % 3; @@ -492,7 +492,7 @@ bool HUDDemo::handleWeaponRightArrowClicked(const CEGUI::EventArgs& args) return false; } -bool HUDDemo::handleRestartButtonClicked(const CEGUI::EventArgs& args) +bool HUDDemo::handleRestartButtonClicked(const CEGUI::EventArgs&) { d_root->removeChild(d_rootGameOver); d_rootIngame->addChild(d_mouseCursorWnd); @@ -502,7 +502,7 @@ bool HUDDemo::handleRestartButtonClicked(const CEGUI::EventArgs& args) return false; } -bool HUDDemo::handleWeaponLeftArrowClicked(const CEGUI::EventArgs& args) +bool HUDDemo::handleWeaponLeftArrowClicked(const CEGUI::EventArgs&) { int weaponIndex = static_cast(d_selectedWeapon); selectedWeapon( static_cast(++weaponIndex % 3) ); @@ -517,4 +517,4 @@ extern "C" SAMPLE_EXPORT Sample& getSampleInstance() { static HUDDemo sample; return sample; -} \ No newline at end of file +} diff --git a/samples/HelloWorld/HelloWorld.cpp b/samples/HelloWorld/HelloWorld.cpp index 265e42fa2..d3d58060d 100644 --- a/samples/HelloWorld/HelloWorld.cpp +++ b/samples/HelloWorld/HelloWorld.cpp @@ -136,7 +136,7 @@ void HelloWorldDemo::deinitialise() { } -bool HelloWorldDemo::handleHelloWorldClicked(const CEGUI::EventArgs& args) +bool HelloWorldDemo::handleHelloWorldClicked(const CEGUI::EventArgs&) { std::cout << "Hello World!" << std::endl; @@ -150,4 +150,4 @@ extern "C" SAMPLE_EXPORT Sample& getSampleInstance() { static HelloWorldDemo sample; return sample; -} \ No newline at end of file +} diff --git a/samples/InventoryDemo/BoolArray2D.cpp b/samples/InventoryDemo/BoolArray2D.cpp index a670b8d0e..da77c7e5a 100644 --- a/samples/InventoryDemo/BoolArray2D.cpp +++ b/samples/InventoryDemo/BoolArray2D.cpp @@ -40,6 +40,8 @@ BoolArray2D::BoolArray2D() : //------------------------------------------------------------------------------// BoolArray2D::BoolArray2D(int width, int height) : + d_width(0), + d_height(0), d_content(0) { resetSize(width, height); diff --git a/samples/LookNFeelOverview/CMakeLists.txt b/samples/LookNFeelOverview/CMakeLists.txt new file mode 100644 index 000000000..43221f71a --- /dev/null +++ b/samples/LookNFeelOverview/CMakeLists.txt @@ -0,0 +1,4 @@ +option(CEGUI_SAMPLES_ENABLE_LOOKNFEELOVERVIEW_DEMO "Specifies whether this sample should be built or not" TRUE) +if(CEGUI_SAMPLES_ENABLE_LOOKNFEELOVERVIEW_DEMO) + cegui_add_sample(CEGUILookNFeelOverviewDemo) +endif() \ No newline at end of file diff --git a/samples/LookNFeelOverview/LookNFeelOverview.cpp b/samples/LookNFeelOverview/LookNFeelOverview.cpp new file mode 100644 index 000000000..613b5e860 --- /dev/null +++ b/samples/LookNFeelOverview/LookNFeelOverview.cpp @@ -0,0 +1,156 @@ +/*********************************************************************** +created: 18/4/2015 +author: Lukas E Meindl +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & Thce CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ +#include "LookNFeelOverview.h" + +#include "CEGUI/CEGUI.h" +#include "CEGUI/InputEvent.h" + +#include + + +using namespace CEGUI; + +/************************************************************************* +Sample specific initialisation goes here. +*************************************************************************/ +bool LookNFeelOverviewDemo::initialise(CEGUI::GUIContext* guiContext) +{ + using namespace CEGUI; + + d_usedFiles = CEGUI::String(__FILE__); + + d_guiContext = guiContext; + WindowManager& winMgr = WindowManager::getSingleton(); + + // load scheme and set up defaults + SchemeManager::getSingleton().createFromFile("TaharezLook.scheme"); + SchemeManager::getSingleton().createFromFile("AlfiskoSkin.scheme"); + SchemeManager::getSingleton().createFromFile("WindowsLook.scheme"); + SchemeManager::getSingleton().createFromFile("VanillaSkin.scheme"); + SchemeManager::getSingleton().createFromFile("OgreTray.scheme"); + guiContext->getMouseCursor().setDefaultImage("Vanilla-Images/MouseArrow"); + + // load all Fonts we are going to use and which are not loaded via scheme + d_fontForTaharez = &FontManager::getSingleton().createFromFile("Jura-10.font"); + FontManager::getSingleton().createFromFile("DejaVuSans-10.font"); + + // load all layouts we want to use later + d_taharezOverviewLayout = winMgr.loadLayoutFromFile("TaharezLookOverview.layout"); + d_vanillaOverviewLayout = winMgr.loadLayoutFromFile("VanillaLookOverview.layout"); + + // create a root window + Window* root = winMgr.createWindow("DefaultWindow", "root"); + guiContext->setRootWindow(root); + + CEGUI::Window* skinSelectionContainer = winMgr.createWindow("Vanilla/StaticText", "SkinSelectionContainer"); + skinSelectionContainer->setPosition(CEGUI::UVector2(cegui_reldim(0.0f), cegui_reldim(0.0f))); + skinSelectionContainer->setSize(CEGUI::USize(cegui_reldim(1.0f), cegui_reldim(1.0f))); + root->addChild(skinSelectionContainer); + + d_loadedLayoutContainer = winMgr.createWindow("DefaultWindow", "LoadedLayoutContainer"); + d_loadedLayoutContainer->setPosition(CEGUI::UVector2(cegui_reldim(0.0f), cegui_reldim(0.1f))); + d_loadedLayoutContainer->setSize(CEGUI::USize(cegui_reldim(1.0f), cegui_reldim(0.9f))); + skinSelectionContainer->addChild(d_loadedLayoutContainer); + + CEGUI::Window* skinSelectionComboboxLabel = winMgr.createWindow("Vanilla/Label", "SkinSelectionComboboxLabel"); + skinSelectionContainer->addChild(skinSelectionComboboxLabel); + skinSelectionComboboxLabel->setHorizontalAlignment(HA_CENTRE); + skinSelectionComboboxLabel->setText("Choose a Look N' Feel (= a skin) to display"); + skinSelectionComboboxLabel->setPosition(CEGUI::UVector2(cegui_reldim(-0.18f), cegui_reldim(0.0f))); + skinSelectionComboboxLabel->setSize(CEGUI::USize(cegui_reldim(0.36f), cegui_reldim(0.04f))); + skinSelectionComboboxLabel->setProperty("HorzFormatting", "RightAligned"); + + + CEGUI::Combobox* skinSelectionCombobox = static_cast(winMgr.createWindow("Vanilla/Combobox", "SkinSelectionCombobox")); + skinSelectionContainer->addChild(skinSelectionCombobox); + skinSelectionCombobox->setHorizontalAlignment(HA_CENTRE); + skinSelectionCombobox->setPosition(CEGUI::UVector2(cegui_reldim(0.08f), cegui_reldim(0.003f))); + skinSelectionCombobox->setSize(CEGUI::USize(cegui_reldim(0.15f), cegui_reldim(0.3f))); + skinSelectionCombobox->setReadOnly(true); + skinSelectionCombobox->setSortingEnabled(false); + skinSelectionCombobox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, Event::Subscriber(&LookNFeelOverviewDemo::handleSkinSelectionAccepted, this)); + + d_taharezLookListboxItem = new CEGUI::ListboxTextItem("TaharezLook"); + skinSelectionCombobox->addItem(d_taharezLookListboxItem); + d_taharezLookListboxItem->setSelectionBrushImage("Vanilla-Images/GenericBrush"); + + d_vanillaLookListboxItem = new CEGUI::ListboxTextItem("Vanilla"); + skinSelectionCombobox->addItem(d_vanillaLookListboxItem); + d_vanillaLookListboxItem->setSelectionBrushImage("Vanilla-Images/GenericBrush"); + + skinSelectionCombobox->setItemSelectState(d_taharezLookListboxItem, true); + WindowEventArgs winArgs(skinSelectionCombobox); + skinSelectionCombobox->fireEvent(Combobox::EventListSelectionAccepted, winArgs); + + // success! + return true; +} + +/************************************************************************* +Cleans up resources allocated in the initialiseSample call. +*************************************************************************/ +void LookNFeelOverviewDemo::deinitialise() +{ +} + +/************************************************************************* +An event handler to handle selections +*************************************************************************/ +bool LookNFeelOverviewDemo::handleSkinSelectionAccepted(const CEGUI::EventArgs& args) +{ + const CEGUI::WindowEventArgs& winEventArgs = static_cast(args); + CEGUI::Combobox* skinSelectionCombobox = static_cast(winEventArgs.window); + + ListboxItem* selectedItem = skinSelectionCombobox->getSelectedItem(); + + while(d_loadedLayoutContainer->getChildCount() > 0) + d_loadedLayoutContainer->removeChild(d_loadedLayoutContainer->getChildAtIdx(0)); + + if(selectedItem == d_taharezLookListboxItem) + { + d_loadedLayoutContainer->addChild(d_taharezOverviewLayout); + + // Set default font for the gui context + d_guiContext->setDefaultFont(d_fontForTaharez); + } + else if(selectedItem == d_vanillaLookListboxItem) + { + d_loadedLayoutContainer->addChild(d_vanillaOverviewLayout); + d_guiContext->setDefaultFont(d_fontForTaharez); + } + + return false; +} + +/************************************************************************* +Define the module function that returns an instance of the sample +*************************************************************************/ +extern "C" SAMPLE_EXPORT Sample& getSampleInstance() +{ + static LookNFeelOverviewDemo sample; + return sample; +} \ No newline at end of file diff --git a/samples/LookNFeelOverview/LookNFeelOverview.h b/samples/LookNFeelOverview/LookNFeelOverview.h new file mode 100644 index 000000000..c51622800 --- /dev/null +++ b/samples/LookNFeelOverview/LookNFeelOverview.h @@ -0,0 +1,60 @@ +/*********************************************************************** +created: 18/4/2015 +author: Lukas E Meindl +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ +#ifndef _LookNFeelOverview_Demo_ +#define _LookNFeelOverview_Demo_ + +#include "SampleBase.h" +#include "CEGUI/ForwardRefs.h" + +// Sample class +class LookNFeelOverviewDemo : public Sample +{ +public: + // method to initialse the samples windows and events. + virtual bool initialise(CEGUI::GUIContext* guiContext); + + // method to perform any required cleanup operations. + virtual void deinitialise(); + +protected: + bool handleSkinSelectionAccepted(const CEGUI::EventArgs& args); + + // We store some items for comparison + CEGUI::ListboxTextItem* d_taharezLookListboxItem; + CEGUI::ListboxTextItem* d_vanillaLookListboxItem; + + // We want to change the default font later so we store some fonts in variables + CEGUI::Font* d_fontForTaharez; + CEGUI::Window* d_taharezOverviewLayout; + // We want to change the default font later so we store some fonts in variables + CEGUI::Window* d_vanillaOverviewLayout; + + CEGUI::Window* d_loadedLayoutContainer; + CEGUI::GUIContext* d_guiContext; +}; + +#endif diff --git a/samples/LookNFeelOverview/SampleMetaData.xml b/samples/LookNFeelOverview/SampleMetaData.xml new file mode 100644 index 000000000..9077fa690 --- /dev/null +++ b/samples/LookNFeelOverview/SampleMetaData.xml @@ -0,0 +1,6 @@ + diff --git a/samples/WidgetDemo/WidgetDemo.cpp b/samples/WidgetDemo/WidgetDemo.cpp index c1d19269d..9ceb8aad1 100644 --- a/samples/WidgetDemo/WidgetDemo.cpp +++ b/samples/WidgetDemo/WidgetDemo.cpp @@ -210,7 +210,7 @@ bool WidgetDemo::handleSkinSelectionAccepted(const CEGUI::EventArgs& args) return true; } -bool WidgetDemo::handleRenderingEnded(const CEGUI::EventArgs& args) +bool WidgetDemo::handleRenderingEnded(const CEGUI::EventArgs&) { d_windowLightMouseMoveEvent->disable(); d_windowLightUpdatedEvent->disable(); @@ -237,10 +237,8 @@ bool WidgetDemo::handleRootWindowUpdate(const CEGUI::EventArgs& args) return true; } -bool WidgetDemo::handleWidgetSelectionChanged(const CEGUI::EventArgs& args) +bool WidgetDemo::handleWidgetSelectionChanged(const CEGUI::EventArgs&) { - const WindowEventArgs& winArgs = static_cast(args); - //Get widget name and mapping type CEGUI::String widgetName; CEGUI::String widgetTypeString; @@ -558,9 +556,9 @@ void WidgetDemo::logFiredEvent(const CEGUI::String& logMessage) eventsLog = eventsLog.substr(pos, len); if(len == 2056) { - int newlinePos = eventsLog.find_first_of("\n"); - if(newlinePos != std::string::npos) - eventsLog = eventsLog.substr(newlinePos, std::string::npos); + String::size_type newlinePos = eventsLog.find_first_of("\n"); + if(newlinePos != String::npos) + eventsLog = eventsLog.substr(newlinePos, String::npos); } d_widgetsEventsLog->setText(eventsLog); @@ -951,13 +949,13 @@ void WidgetDemo::fillWidgetPropertiesDisplayWindow(CEGUI::Window* widgetWindowRo // Set the third row item (type) for the property d_widgetPropertiesDisplayWindow->setItem(new MyListItem(curProperty->getDataType()), 1, rowID); - try + CEGUI_TRY { // Set the second row item (value) for the property if it is gettable if(widget->isPropertyPresent(curProperty->getName())) d_widgetPropertiesDisplayWindow->setItem(new MyListItem(widget->getProperty(curProperty->getName())), 2, rowID); } - catch(CEGUI::InvalidRequestException exception) + CEGUI_CATCH(CEGUI::InvalidRequestException exception) { } @@ -1040,4 +1038,4 @@ extern "C" SAMPLE_EXPORT Sample& getSampleInstance() { static WidgetDemo sample; return sample; -} \ No newline at end of file +} diff --git a/samples/common/include/CEGUISamplesConfig.h.in b/samples/common/include/CEGUISamplesConfig.h.in index 8d18f664d..3e3ec4390 100644 --- a/samples/common/include/CEGUISamplesConfig.h.in +++ b/samples/common/include/CEGUISamplesConfig.h.in @@ -41,6 +41,9 @@ Each item in here has a comment to describe what it's for. // Bring in main config file #include "CEGUI/Config.h" +#cmakedefine CEGUI_SAMPLE_DATAPATH "@CEGUI_SAMPLE_DATAPATH@" +#ifndef CEGUI_SAMPLE_DATAPATH + // Define the default place where samples will look for datafiles #if defined(_WIN32) || defined(__WIN32__) # define CEGUI_SAMPLE_DATAPATH "${PROJECT_SOURCE_DIR}/datafiles" @@ -48,13 +51,19 @@ Each item in here has a comment to describe what it's for. # define CEGUI_SAMPLE_DATAPATH "${CMAKE_INSTALL_PREFIX}/${CEGUI_DATA_INSTALL_DIR}" #endif +#endif + ////////////////////////////////////////////////////////////////////////// // Comment/Uncomment these lines to control renderer use in samples. ////////////////////////////////////////////////////////////////////////// #cmakedefine CEGUI_BUILD_RENDERER_OPENGL #cmakedefine CEGUI_BUILD_RENDERER_OPENGL3 +#cmakedefine CEGUI_SAMPLES_SUPPORT_RENDERER_OPENGLES2 +#cmakedefine CEGUI_USE_GLFW_VER @CEGUI_USE_GLFW_VER@ #cmakedefine CEGUI_BUILD_RENDERER_OGRE #cmakedefine CEGUI_BUILD_RENDERER_IRRLICHT +#cmakedefine CEGUI_OPENGL_VER_MAJOR_FORCE @CEGUI_OPENGL_VER_MAJOR_FORCE@ +#define CEGUI_OPENGL_VER_MINOR_FORCE @CEGUI_OPENGL_VER_MINOR_FORCE@ #cmakedefine CEGUI_BUILD_RENDERER_DIRECT3D9 #cmakedefine CEGUI_BUILD_RENDERER_DIRECT3D10 #cmakedefine CEGUI_BUILD_RENDERER_DIRECT3D11 diff --git a/samples/common/include/Sample.h b/samples/common/include/Sample.h index 57dfe2128..4614a66c7 100644 --- a/samples/common/include/Sample.h +++ b/samples/common/include/Sample.h @@ -40,7 +40,7 @@ class Sample virtual void deinitialise() = 0; virtual void onEnteringSample() {} - virtual void update(float timeSinceLastUpdate) {} + virtual void update(float /*timeSinceLastUpdate*/) {} const CEGUI::String& getUsedFilesString() {return d_usedFiles;} @@ -48,4 +48,4 @@ class Sample CEGUI::String d_usedFiles; }; -#endif \ No newline at end of file +#endif diff --git a/samples_framework/CMakeLists.txt b/samples_framework/CMakeLists.txt index 014640df2..50d67fffa 100644 --- a/samples_framework/CMakeLists.txt +++ b/samples_framework/CMakeLists.txt @@ -48,23 +48,52 @@ else() ) endif() - -if (CEGUI_SAMPLES_RENDERER_OPENGL_ACTIVE) - # Append OpenGL and OpenGL3 files +if (ANDROID) list (APPEND CORE_SOURCE_FILES - ./src/CEGuiGLFWSharedBase.cpp + ./src/SamplesFrameworkAndroid.cpp ) +endif () - if (CEGUI_BUILD_RENDERER_OPENGL) - list (APPEND CORE_SOURCE_FILES - ./src/CEGuiOpenGLBaseApplication.cpp - ) - endif() +if (CEGUI_SAMPLES_RENDERER_OPENGL_ACTIVE) + if (NOT ANDROID) - if (CEGUI_BUILD_RENDERER_OPENGL3) list (APPEND CORE_SOURCE_FILES - ./src/CEGuiOpenGL3BaseApplication.cpp + ./src/CEGuiGLFWSharedBase.cpp ) + if (CEGUI_USE_GLFW_VER STREQUAL "3") + list (APPEND CORE_SOURCE_FILES + ./src/CEGuiGLFW3SharedBase.cpp + ) + else() # CEGUI_USE_GLFW_VER STREQUAL "2" + list (APPEND CORE_SOURCE_FILES + ./src/CEGuiGLFW2SharedBase.cpp + ) + endif() + + if (CEGUI_BUILD_RENDERER_OPENGL) + list (APPEND CORE_SOURCE_FILES + ./src/CEGuiOpenGLBaseApplication.cpp + ) + endif() + + if (CEGUI_BUILD_RENDERER_OPENGL3) + list (APPEND CORE_SOURCE_FILES + ./src/CEGuiOpenGL3BaseApplication.cpp + ) + endif() + + endif () + + if (CEGUI_SAMPLES_SUPPORT_RENDERER_OPENGLES2) + if (ANDROID) + list (APPEND CORE_SOURCE_FILES + ./src/CEGuiAndroidOpenglEs2BaseApplication.cpp + ) + else () + list (APPEND CORE_SOURCE_FILES + ./src/CEGuiOpenGLES2BaseApplication.cpp + ) + endif () endif() endif() @@ -143,7 +172,11 @@ endif() ########################################################################### # Dynamically Linked Executable ########################################################################### -add_executable(${CEGUI_TARGET_NAME} ${CORE_SOURCE_FILES} ${CORE_HEADER_FILES}) +if (ANDROID) + add_library (${CEGUI_TARGET_NAME} SHARED ${CORE_SOURCE_FILES}) +else () + add_executable(${CEGUI_TARGET_NAME} ${CORE_SOURCE_FILES} ${CORE_HEADER_FILES}) +endif () # append the _d (or whatever) for debug builds as needed. if (CEGUI_HAS_BUILD_SUFFIX AND CEGUI_BUILD_SUFFIX) @@ -173,18 +206,23 @@ endif() ########################################################################### # MSVC PROJ USER FILE TEMPLATES ########################################################################### -if (MSVC) - configure_file( - ${CMAKE_MODULE_PATH}/templates/VisualStudioUserFile.vcproj.user.in - ${CMAKE_CURRENT_BINARY_DIR}/${CEGUI_TARGET_NAME}.vcproj.user - @ONLY - ) - configure_file( - ${CMAKE_MODULE_PATH}/templates/VisualStudioUserFile.vcxproj.user.in - ${CMAKE_CURRENT_BINARY_DIR}/${CEGUI_TARGET_NAME}.vcxproj.user - @ONLY - ) -endif () +if(MSVC) + # Visual Studio 2008 or less + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0) + configure_file( + ${CMAKE_MODULE_PATH}/templates/VisualStudioUserFile.vcproj.user.in + ${CMAKE_CURRENT_BINARY_DIR}/${CEGUI_TARGET_NAME}.vcproj.user + @ONLY + ) + else () + # Visual Studio 2010 or higher + configure_file( + ${CMAKE_MODULE_PATH}/templates/VisualStudioUserFile.vcxproj.user.in + ${CMAKE_CURRENT_BINARY_DIR}/${CEGUI_TARGET_NAME}.vcxproj.user + @ONLY + ) + endif () +endif() ########################################################################### @@ -207,7 +245,7 @@ endif() add_dependencies(${CEGUI_TARGET_NAME} ${CEGUI_CORE_WR_LIBNAME} CEGUI${CEGUI_OPTION_DEFAULT_XMLPARSER} CEGUI${CEGUI_OPTION_DEFAULT_IMAGECODEC}) - + if (CEGUI_SAMPLES_ENABLE_COMMON_DIALOGUES_DEMO) add_dependencies(${CEGUI_TARGET_NAME} ${CEGUI_COMMON_DIALOGS_LIBNAME}) endif() @@ -216,30 +254,37 @@ endif() # INSTALLATION ########################################################################### install(TARGETS ${CEGUI_TARGET_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} - BUNDLE DESTINATION ${CEGUI_LIB_INSTALL_DIR} + RUNTIME DESTINATION bin COMPONENT cegui_samples + LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_samples + ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_samples + BUNDLE DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_samples ) if (CEGUI_BUILD_STATIC_CONFIGURATION) install(TARGETS ${CEGUI_TARGET_NAME}_Static - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} - BUNDLE DESTINATION ${CEGUI_LIB_INSTALL_DIR} + RUNTIME DESTINATION bin COMPONENT cegui_samples + LIBRARY DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_samples + ARCHIVE DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_samples + BUNDLE DESTINATION ${CEGUI_LIB_INSTALL_DIR} COMPONENT cegui_samples ) endif() if (CEGUI_SAMPLES_RENDERER_OPENGL_ACTIVE) - cegui_add_dependency(${CEGUI_TARGET_NAME} OPENGL) - cegui_add_dependency(${CEGUI_TARGET_NAME} GLFW) + if (CEGUI_USE_EPOXY) + cegui_add_dependency(${CEGUI_TARGET_NAME} EPOXY PRIVATE TRUE) + elseif (CEGUI_USE_GLEW) + cegui_add_dependency(${CEGUI_TARGET_NAME} OPENGL PRIVATE TRUE) + endif () + if (CEGUI_USE_GLFW_VER STREQUAL "3") + cegui_add_dependency(${CEGUI_TARGET_NAME} GLFW3 PRIVATE TRUE) + else () # CEGUI_USE_GLFW_VER STREQUAL "2" + cegui_add_dependency(${CEGUI_TARGET_NAME} GLFW PRIVATE TRUE) + endif () cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_OPENGL_RENDERER_LIBNAME}) endif() if (CEGUI_SAMPLES_RENDERER_OGRE_ACTIVE) - cegui_add_dependency(${CEGUI_TARGET_NAME} OGRE) - cegui_add_dependency(${CEGUI_TARGET_NAME} OIS) + cegui_add_dependency(${CEGUI_TARGET_NAME} OIS PRIVATE TRUE) if (CEGUI_SAMPLES_RENDERER_OGRE_ACTIVE) if (OGRE_STATIC) #if ogre is static, then must include the static plugin libs set(CORE_OGRE_COMPONENTS RenderSystem_Direct3D9 RenderSystem_Direct3D11 RenderSystem_GLES RenderSystem_GLES2 RenderSystem_GL RenderSystem_GL3Plus) @@ -255,37 +300,53 @@ if (CEGUI_SAMPLES_RENDERER_OGRE_ACTIVE) endif() endif() cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_OGRE_RENDERER_LIBNAME} ${CEGUI_OGRE_SAMPLES_EXTRALIBS}) + cegui_add_dependency(${CEGUI_TARGET_NAME} OGRE PRIVATE TRUE) endif() if (CEGUI_SAMPLES_RENDERER_IRRLICHT_ACTIVE) - cegui_add_dependency(${CEGUI_TARGET_NAME} IRRLICHT) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_IRRLICHT_RENDERER_LIBNAME}) + cegui_add_dependency(${CEGUI_TARGET_NAME} IRRLICHT PRIVATE TRUE) endif() if (CEGUI_SAMPLES_RENDERER_DIRECT3D9_ACTIVE OR CEGUI_SAMPLES_RENDERER_DIRECT3D10_ACTIVE OR CEGUI_SAMPLES_RENDERER_DIRECT3D11_ACTIVE) - cegui_target_link_libraries(${CEGUI_TARGET_NAME} dxerr) + + if (MINGW) + cegui_target_link_libraries(${CEGUI_TARGET_NAME} dxerr9 dinput8 dxguid) + else () + cegui_target_link_libraries(${CEGUI_TARGET_NAME} dxerr) + endif() if (CEGUI_SAMPLES_RENDERER_DIRECT3D9_ACTIVE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_DIRECT3D9_RENDERER_LIBNAME} d3d9) endif() if (CEGUI_SAMPLES_RENDERER_DIRECT3D10_ACTIVE) - cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_DIRECT3D10_RENDERER_LIBNAME} d3d10) + cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_DIRECT3D10_RENDERER_LIBNAME}) + if (MINGW) + cegui_target_link_libraries(${CEGUI_TARGET_NAME} d3dx10_43) + else () + cegui_target_link_libraries(${CEGUI_TARGET_NAME} d3d10) + endif() endif() if (CEGUI_SAMPLES_RENDERER_DIRECT3D11_ACTIVE) - cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_DIRECT3D11_RENDERER_LIBNAME} d3d11) + cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_DIRECT3D11_RENDERER_LIBNAME}) + if (MINGW) + cegui_target_link_libraries(${CEGUI_TARGET_NAME} d3dx11_43) + else () + cegui_target_link_libraries(${CEGUI_TARGET_NAME} d3d11) + endif() endif() endif() if (CEGUI_SAMPLES_RENDERER_DIRECTFB_ACTIVE) - cegui_add_dependency(${CEGUI_TARGET_NAME} DIRECTFB) + cegui_add_dependency(${CEGUI_TARGET_NAME} DIRECTFB PRIVATE TRUE) cegui_target_link_libraries(${CEGUI_TARGET_NAME} ${CEGUI_DIRECTFB_RENDERER_LIBNAME}) endif() if (CEGUI_SAMPLES_USE_GTK2) - cegui_add_dependency(${CEGUI_TARGET_NAME} GTK2) + cegui_add_dependency(${CEGUI_TARGET_NAME} GTK2 PRIVATE TRUE) endif() if (APPLE) diff --git a/samples_framework/include/CEGuiAndroidOpenglEs2BaseApplication.h b/samples_framework/include/CEGuiAndroidOpenglEs2BaseApplication.h new file mode 100644 index 000000000..fee299db4 --- /dev/null +++ b/samples_framework/include/CEGuiAndroidOpenglEs2BaseApplication.h @@ -0,0 +1,44 @@ +/*********************************************************************** + created: 27/7/2015 + author: Yaron Cohen-Tal +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ +#ifndef _CEGuiAndroidOpenglEs2BaseApplication_h_ +#define _CEGuiAndroidOpenglEs2BaseApplication_h_ + +#include "CEGuiBaseApplication.h" + +class CEGuiAndroidOpenglEs2BaseApplication : public CEGuiBaseApplication +{ +public: + CEGuiAndroidOpenglEs2BaseApplication(); + bool init(SamplesFrameworkBase* sampleApp, const CEGUI::String &logFile, + const CEGUI::String &dataPathPrefixOverride); +protected: + void destroyWindow() {} + void beginRendering(const float elapsed); + void endRendering() {} +}; + +#endif // end of guard _CEGuiAndroidOpenglEs2BaseApplication_h_ diff --git a/samples_framework/include/CEGuiBaseApplication.h b/samples_framework/include/CEGuiBaseApplication.h index 86cdf94e1..2dabdd3e4 100644 --- a/samples_framework/include/CEGuiBaseApplication.h +++ b/samples_framework/include/CEGuiBaseApplication.h @@ -27,6 +27,8 @@ #ifndef _CEGuiBaseApplication_h_ #define _CEGuiBaseApplication_h_ +#include "CEGUI/String.h" + // If this looks wanky, it's becase it is! Behold that this is not as fullblown // as it could be though. #ifndef PATH_MAX @@ -75,29 +77,37 @@ class CEGuiBaseApplication /*! \brief - Start the base application + Initialise the base application. This will fully initialise the application, finish initialisation of the demo via calls to 'sampleApp', and finally control execution of the sample. This calls calls the virtual run function. + Classes that override this method must first call the implementation of + the superclass! + \param sampleApp Pointer to the CEGuiSample object that the CEGuiBaseApplication is being invoked for. \return - - true if the application initialised and ran okay (cleanup function - will be called). - - false if the application failed to initialise (cleanup function will - not be called). + - true if the application initialised okay (cleanup function will be + called). */ - bool execute(SamplesFrameworkBase* sampleApp); + virtual bool init(SamplesFrameworkBase* sampleApp, + const CEGUI::String& logFile, + const CEGUI::String& dataPathPrefixOverride); /*! \brief Performs any required cleanup of the base application system. + + Classes that override this method must, lastly, call the implementation + of the superclass! */ - void cleanup(); + virtual void cleanup(); + + virtual void destroyRenderer(); /*! \brief @@ -123,7 +133,9 @@ class CEGuiBaseApplication if the variable is not set, a default will be used depending on the build system in use. */ - const char* getDataPathPrefix() const; + CEGUI::String getDataPathPrefix() const { return d_dataPathPrefix; } + + void initDataPathPrefix(const CEGUI::String &override); /*! \brief @@ -131,13 +143,13 @@ class CEGuiBaseApplication */ void registerSampleOverlayHandler(CEGUI::GUIContext* gui_context); + //! The abstract function for running the application. + virtual void run() {} protected: //! name of env var that holds the path prefix to the data files. static const char DATAPATH_VAR_NAME[]; - //! The abstract function for initialising and running the application. - virtual void run() = 0; //! The abstract function for destroying the renderer and the window. virtual void destroyWindow() = 0; //! Implementation function to perform required pre-render operations. @@ -198,6 +210,10 @@ class CEGuiBaseApplication int d_FPSValue; //! whether to spin the logo bool d_spinLogo; + +private: + CEGUI::String d_dataPathPrefix; + }; #endif // end of guard _CEGuiBaseApplication_h_ diff --git a/samples_framework/include/CEGuiD3D10BaseApplication.h b/samples_framework/include/CEGuiD3D10BaseApplication.h index 6be82e5a4..80947a4c7 100644 --- a/samples_framework/include/CEGuiD3D10BaseApplication.h +++ b/samples_framework/include/CEGuiD3D10BaseApplication.h @@ -48,6 +48,8 @@ class CEGuiD3D10BaseApplication : public CEGuiBaseApplication //! Destructor. ~CEGuiD3D10BaseApplication(); + void destroyRenderer(); + protected: /************************************************************************* Implementation Methods diff --git a/samples_framework/include/CEGuiD3D11BaseApplication.h b/samples_framework/include/CEGuiD3D11BaseApplication.h index b50aefff5..308c3ca1f 100644 --- a/samples_framework/include/CEGuiD3D11BaseApplication.h +++ b/samples_framework/include/CEGuiD3D11BaseApplication.h @@ -44,6 +44,7 @@ class CEGuiD3D11BaseApplication : public CEGuiBaseApplication public: CEGuiD3D11BaseApplication(); ~CEGuiD3D11BaseApplication(); + void destroyRenderer(); protected: bool initialiseDirect3D(unsigned int width, unsigned int height, diff --git a/samples_framework/include/CEGuiD3D9BaseApplication.h b/samples_framework/include/CEGuiD3D9BaseApplication.h index 49bd92b21..124803205 100644 --- a/samples_framework/include/CEGuiD3D9BaseApplication.h +++ b/samples_framework/include/CEGuiD3D9BaseApplication.h @@ -51,6 +51,8 @@ class CEGuiD3D9BaseApplication : public CEGuiBaseApplication //! Destructor. ~CEGuiD3D9BaseApplication(); + void destroyRenderer(); + protected: /************************************************************************* Implementation Methods diff --git a/samples_framework/include/CEGuiGLFWSharedBase.h b/samples_framework/include/CEGuiGLFWSharedBase.h index a3beacc34..c484cf24d 100644 --- a/samples_framework/include/CEGuiGLFWSharedBase.h +++ b/samples_framework/include/CEGuiGLFWSharedBase.h @@ -27,17 +27,26 @@ #ifndef _CEGuiGLFWSharedBase_h_ #define _CEGuiGLFWSharedBase_h_ +#include "CEGUISamplesConfig.h" +#include "CEGUI/RendererModules/OpenGL/GL.h" + +#if CEGUI_USE_GLFW_VER == 3 +# include +# if (GLFW_VERSION_MINOR < 1) && (GLFW_VERSION_PATCH < 1) +# define GLFW_DONT_CARE -1 +# endif +#elif CEGUI_USE_GLFW_VER == 2 +# include +#else +# error Unsupported "CEGUI_GLFW_VER". +#endif #include "CEGuiBaseApplication.h" #include "CEGUI/MouseCursor.h" -#include - -class SamplesFrameworkBase; class CEGuiGLFWSharedBase : public CEGuiBaseApplication { public: CEGuiGLFWSharedBase(); - ~CEGuiGLFWSharedBase(); protected: // implementation of base class abstract functions. @@ -55,6 +64,19 @@ class CEGuiGLFWSharedBase : public CEGuiBaseApplication void drawFrame(); +#if GLFW_VERSION_MAJOR >= 3 + + static void glfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); + static void glfwCharCallback(GLFWwindow* window, unsigned codepoint); + static void glfwMouseButtonCallback(GLFWwindow* window, int button, int action, int mods); + static void glfwScrollCallback(GLFWwindow* window, double xoffset, double yoffset); + static void glfwCursorPosCallback(GLFWwindow* window, double xpos, double ypos); + + static void glfwWindowCloseCallback(GLFWwindow* window); + static void glfwWindowResizeCallback(GLFWwindow* window, int width, int height); + +#else // GLFW_VERSION_MAJOR <= 2 + static void GLFWCALL glfwKeyCallback(int key, int action); static void GLFWCALL glfwCharCallback(int character, int action); static void GLFWCALL glfwMouseButtonCallback(int key, int action); @@ -63,6 +85,8 @@ class CEGuiGLFWSharedBase : public CEGuiBaseApplication static int GLFWCALL glfwWindowCloseCallback(void); static void GLFWCALL glfwWindowResizeCallback(int width, int height); + +#endif static CEGUI::Key::Scan GlfwToCeguiKey(int glfwKey); static CEGUI::MouseButton GlfwToCeguiMouseButton(int glfwButton); @@ -70,7 +94,6 @@ class CEGuiGLFWSharedBase : public CEGuiBaseApplication /************************************************************************* Data fields *************************************************************************/ - static CEGuiGLFWSharedBase* d_appInstance; static double d_frameTime; static int d_modifiers; @@ -80,10 +103,14 @@ class CEGuiGLFWSharedBase : public CEGuiBaseApplication static bool d_mouseLeftWindow; static bool d_mouseDisableCalled; - static int d_oldMousePosX; - static int d_oldMousePosY; + static double d_oldMousePosX; + static double d_oldMousePosY; + + static const char d_windowTitle[]; + +#if GLFW_VERSION_MAJOR >= 3 + static GLFWwindow* d_window; +#endif }; - #endif // end of guard _CEGuiGLFWSharedBase_h_ - diff --git a/samples_framework/include/CEGuiIrrlichtBaseApplication.h b/samples_framework/include/CEGuiIrrlichtBaseApplication.h index e0604f8e0..116c55ae7 100644 --- a/samples_framework/include/CEGuiIrrlichtBaseApplication.h +++ b/samples_framework/include/CEGuiIrrlichtBaseApplication.h @@ -61,6 +61,7 @@ class CEGuiIrrlichtBaseApplication : public CEGuiBaseApplication, public: CEGuiIrrlichtBaseApplication(); ~CEGuiIrrlichtBaseApplication(); + void destroyRenderer(); // irrlicht event listener #if CEGUI_IRR_SDK_VERSION >= 14 diff --git a/samples_framework/include/CEGuiOgreBaseApplication.h b/samples_framework/include/CEGuiOgreBaseApplication.h index 914119fa2..485aeb4ed 100644 --- a/samples_framework/include/CEGuiOgreBaseApplication.h +++ b/samples_framework/include/CEGuiOgreBaseApplication.h @@ -72,6 +72,11 @@ class CEGuiOgreBaseApplication : public CEGuiBaseApplication, public Ogre::Frame //! Destructor. ~CEGuiOgreBaseApplication(); + bool init(SamplesFrameworkBase* sampleApp, const CEGUI::String &logFile, + const CEGUI::String &dataPathPrefixOverride); + + void destroyRenderer(); + //! called by the frame listener to perform requried per-frame updates. void doFrameUpdate(float elapsed); @@ -79,13 +84,13 @@ class CEGuiOgreBaseApplication : public CEGuiBaseApplication, public Ogre::Frame bool frameRenderingQueued(const Ogre::FrameEvent& evt); bool isInitialised(); + void run(); protected: // override from base class since we use a non-default resource provider. void initialiseResourceGroupDirectories(); // Implementation of base class abstract methods. - void run(); void destroyWindow(); void beginRendering(const float elapsed); void endRendering(); @@ -109,7 +114,6 @@ class CEGuiOgreBaseApplication : public CEGuiBaseApplication, public Ogre::Frame WndEvtListener* d_windowEventListener; }; - /*! \brief Ogre FrameListener class where we deal with input processing and the like. @@ -118,7 +122,7 @@ class CEGuiDemoFrameListener : public Ogre::FrameListener, public OIS::KeyListen { public: // Construction and Destruction - CEGuiDemoFrameListener(CEGuiOgreBaseApplication* baseApp, SamplesFrameworkBase*& sampleApp, Ogre::RenderWindow* win, Ogre::Camera* cam, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false); + CEGuiDemoFrameListener(CEGuiOgreBaseApplication* baseApp, SamplesFrameworkBase*& sampleApp, Ogre::RenderWindow* win, Ogre::Camera* cam); ~CEGuiDemoFrameListener(); // Processing to be done at start and end of each frame. diff --git a/samples_framework/include/CEGuiOpenGL3BaseApplication.h b/samples_framework/include/CEGuiOpenGL3BaseApplication.h index 4ca1f924c..df75989c2 100644 --- a/samples_framework/include/CEGuiOpenGL3BaseApplication.h +++ b/samples_framework/include/CEGuiOpenGL3BaseApplication.h @@ -33,7 +33,6 @@ class CEGuiOpenGL3BaseApplication : public CEGuiGLFWSharedBase { public: CEGuiOpenGL3BaseApplication(); - ~CEGuiOpenGL3BaseApplication(); protected: static void setGLFWWindowCreationHints(); diff --git a/samples_framework/include/CEGuiOpenGLBaseApplication.h b/samples_framework/include/CEGuiOpenGLBaseApplication.h index 54a28f469..da9ad0849 100644 --- a/samples_framework/include/CEGuiOpenGLBaseApplication.h +++ b/samples_framework/include/CEGuiOpenGLBaseApplication.h @@ -33,7 +33,6 @@ class CEGuiOpenGLBaseApplication : public CEGuiGLFWSharedBase { public: CEGuiOpenGLBaseApplication(); - ~CEGuiOpenGLBaseApplication(); protected: static void setGLFWWindowCreationHints(); diff --git a/samples_framework/include/CEGuiOpenGLES2BaseApplication.h b/samples_framework/include/CEGuiOpenGLES2BaseApplication.h new file mode 100644 index 000000000..bdb09411c --- /dev/null +++ b/samples_framework/include/CEGuiOpenGLES2BaseApplication.h @@ -0,0 +1,41 @@ +/*********************************************************************** +created: 12/2/2012 +author: Paul D Turner +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ +#ifndef _CEGuiOpenGLES2BaseApplication_h_ +#define _CEGuiOpenGLES2BaseApplication_h_ + +#include "CEGuiGLFWSharedBase.h" + +class CEGuiOpenGLES2BaseApplication : public CEGuiGLFWSharedBase +{ +public: + CEGuiOpenGLES2BaseApplication(); + +protected: + static void setGLFWWindowCreationHints(); +}; + +#endif // end of guard _CEGuiOpenGLES2BaseApplication_h_ diff --git a/samples_framework/include/CEGuiRendererSelector.h b/samples_framework/include/CEGuiRendererSelector.h index 42dbfbb41..53845e0c4 100644 --- a/samples_framework/include/CEGuiRendererSelector.h +++ b/samples_framework/include/CEGuiRendererSelector.h @@ -37,8 +37,9 @@ enum CEGuiRendererType Direct3D9GuiRendererType, //!< Renderer that uses the Direct3D 9 API. Direct3D10GuiRendererType, //!< Renderer that uses the Direct3D 10 API. Direct3D11GuiRendererType, //!< Renderer that uses the Direct3D 11 API. - OpenGLGuiRendererType, //!< Renderer that uses the OpenGL API. - OpenGL3GuiRendererType, //!< Renderer that uses the OpenGL3 API. + OpenGLGuiRendererType, //!< Renderer that uses the desktop OpenGL 1.2 API. + OpenGL3GuiRendererType, //!< Renderer that uses the desktop OpenGL 3.2 API. + OpenglEs2GuiRendererType, //!< Renderer that uses the OpenGL ES 2.0 API. IrrlichtGuiRendererType, //!< Renderer that uses the Irrlicht engine. DirectFBGuiRendererType, //!< Renderer that uses the DirectFB engine. RendererTypeCount, //!< Special value that equals the number of renderer types. diff --git a/samples_framework/include/MetaDataWindowManager.h b/samples_framework/include/MetaDataWindowManager.h index 197e28913..12c943cde 100644 --- a/samples_framework/include/MetaDataWindowManager.h +++ b/samples_framework/include/MetaDataWindowManager.h @@ -46,7 +46,7 @@ class MetaDataWindowManager private: MetaDataWindowManager(const MetaDataWindowManager&) {} - MetaDataWindowManager& operator=(const MetaDataWindowManager&) {} + MetaDataWindowManager& operator=(const MetaDataWindowManager&) { return *this; } void init(); @@ -59,4 +59,4 @@ class MetaDataWindowManager CEGUI::Window* d_wndCredits; }; -#endif \ No newline at end of file +#endif diff --git a/samples_framework/include/SampleData.h b/samples_framework/include/SampleData.h index 953df8015..e4d6875c6 100644 --- a/samples_framework/include/SampleData.h +++ b/samples_framework/include/SampleData.h @@ -68,7 +68,7 @@ class SampleData virtual void clearRTTTexture(); virtual void onEnteringSample() = 0; - virtual void update(float timeSinceLastUpdate) {}; + virtual void update(float /*timeSinceLastUpdate*/) {} void setSampleWindow(CEGUI::Window* sampleWindow); CEGUI::Window* getSampleWindow(); diff --git a/samples_framework/include/SamplesBrowserManager.h b/samples_framework/include/SamplesBrowserManager.h index 7738faa6b..6b7ea394f 100644 --- a/samples_framework/include/SamplesBrowserManager.h +++ b/samples_framework/include/SamplesBrowserManager.h @@ -55,7 +55,7 @@ class SamplesBrowserManager SamplesBrowserManager(const SamplesBrowserManager&) {} void init(); - SamplesBrowserManager& operator=(const SamplesBrowserManager&) {} + SamplesBrowserManager& operator=(const SamplesBrowserManager&) { return *this; } static const CEGUI::uint32 d_sampleWindowFrameNormal; static const CEGUI::uint32 d_sampleWindowFrameSelected; @@ -89,4 +89,4 @@ class SamplesBrowserManager std::vector d_sampleWindows; }; -#endif \ No newline at end of file +#endif diff --git a/samples_framework/include/SamplesFramework.h b/samples_framework/include/SamplesFramework.h index 3fb890583..26f7f54b9 100644 --- a/samples_framework/include/SamplesFramework.h +++ b/samples_framework/include/SamplesFramework.h @@ -53,8 +53,9 @@ class SamplesFramework : public SamplesFrameworkBase static void setDefaultResourceGroup(const CEGUI::String& resourceGroup); - bool initialise(); - void deinitialise(); + bool initialise(const CEGUI::String& logFile, + const CEGUI::String& dataPathPrefixOverride); + void cleanup(); void addSampleDataCppModule(CEGUI::String sampleName, CEGUI::String summary, CEGUI::String description, diff --git a/samples_framework/include/SamplesFrameworkBase.h b/samples_framework/include/SamplesFrameworkBase.h index f65caf035..a8b18eb11 100644 --- a/samples_framework/include/SamplesFrameworkBase.h +++ b/samples_framework/include/SamplesFrameworkBase.h @@ -32,6 +32,7 @@ class CEGuiBaseApplication; class CEGuiRendererSelector; #include "CEGUI/InputEvent.h" +#include "CEGUI/Exceptions.h" /*! \brief @@ -55,7 +56,6 @@ class SamplesFrameworkBase */ virtual ~SamplesFrameworkBase(); - /*! \brief Application entry point. @@ -63,25 +63,20 @@ class SamplesFrameworkBase \return code to be returned by the application. */ - int run(); - + int run(const CEGUI::String& dataPathPrefixOverride); /*! \brief - Sample specific initialisation goes here. This method is called by the application base object created - as part of the initialise call. + Initialises the sample system, this includes asking the user for a render to use and + the subsequent creation of the required systems to support that renderer. \return - false if something went wrong. - */ - virtual bool initialise() = 0; - - - /*! - \brief - deinitialise the resources allocated in the initialise if needed. + false if anything went wrong. */ - virtual void deinitialise() = 0; + virtual bool initialise(const CEGUI::String& logFile, + const CEGUI::String& dataPathPrefixOverride); + + virtual void cleanup(); /*! \brief @@ -95,6 +90,8 @@ class SamplesFrameworkBase */ virtual void handleNewWindowSize(float width, float height) = 0; + void renderSingleFrame(float elapsed); + /*! \brief Draw function to draw GUIContexts @@ -177,30 +174,13 @@ class SamplesFrameworkBase */ void setApplicationWindowSize(int width, int height); -protected: - /*! - \brief - Initialises the sample system, this includes asking the user for a render to use and - the subsequent creation of the required systems to support that renderer. - - \return - false if anything went wrong. - */ - virtual bool runApplication(); - - - /*! - \brief - Cleans up all resources allocated by the initialise call. - */ - virtual void cleanup(); - - /*! \brief Output a message to the user in some OS independant way. */ - static void outputExceptionMessage(const char* message); + void outputExceptionMessage(const char* message); + +protected: /************************************************************************* Data fields diff --git a/samples_framework/include/Samples_xmlHandler.h b/samples_framework/include/Samples_xmlHandler.h index abd5d23ea..2da94f7d7 100644 --- a/samples_framework/include/Samples_xmlHandler.h +++ b/samples_framework/include/Samples_xmlHandler.h @@ -75,8 +75,7 @@ class SampleDataHandler : public ChainedXMLHandler SampleDataHandler(const XMLAttributes& attributes, - const String& name_prefix, - SamplesFramework* samplesFramework); + SamplesFramework* samplesFramework); virtual ~SampleDataHandler(); protected: diff --git a/samples_framework/include/Win32AppHelper.h b/samples_framework/include/Win32AppHelper.h index 13139eaf6..d6bfe8845 100644 --- a/samples_framework/include/Win32AppHelper.h +++ b/samples_framework/include/Win32AppHelper.h @@ -38,7 +38,7 @@ # undef max #endif -#if defined(_WIN32) +#ifdef _MSC_VER # pragma comment(lib, "dinput8.lib") # pragma comment(lib, "dxguid.lib") #endif diff --git a/samples_framework/include/Win32CEGuiRendererSelector.h b/samples_framework/include/Win32CEGuiRendererSelector.h index f59966404..f4296f50c 100644 --- a/samples_framework/include/Win32CEGuiRendererSelector.h +++ b/samples_framework/include/Win32CEGuiRendererSelector.h @@ -118,7 +118,7 @@ class Win32CEGuiRendererSelector : public CEGuiRendererSelector \return The number of wide characters copied, including the trailing wide char NULL. */ - static int copyAnsiToWideChar(LPBYTE outBuff, PTSTR ansiString); + static int copyAnsiToWideChar(LPBYTE outBuff, LPCTSTR ansiString); /************************************************************************* diff --git a/samples_framework/src/CEGuiAndroidOpenglEs2BaseApplication.cpp b/samples_framework/src/CEGuiAndroidOpenglEs2BaseApplication.cpp new file mode 100644 index 000000000..f0828cddf --- /dev/null +++ b/samples_framework/src/CEGuiAndroidOpenglEs2BaseApplication.cpp @@ -0,0 +1,49 @@ +/*********************************************************************** + created: 27/7/2015 + author: Yaron Cohen-Tal +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ + +#include "CEGuiAndroidOpenglEs2BaseApplication.h" + +#include "CEGUI/RendererModules/OpenGL/GL3Renderer.h" + +CEGuiAndroidOpenglEs2BaseApplication::CEGuiAndroidOpenglEs2BaseApplication() +{ + d_renderer = &CEGUI::OpenGL3Renderer::create(); +} + +bool CEGuiAndroidOpenglEs2BaseApplication::init(SamplesFrameworkBase* sampleApp, + const CEGUI::String &logFile, const CEGUI::String &dataPathPrefixOverride) +{ + if (!CEGuiBaseApplication::init(sampleApp, logFile, dataPathPrefixOverride)) + return false; + glClearColor(0.f, 0.f, 0.f, 0.f); + return true; +} + +void CEGuiAndroidOpenglEs2BaseApplication::beginRendering(const float /*elapsed*/) +{ + glClear(GL_COLOR_BUFFER_BIT); +} diff --git a/samples_framework/src/CEGuiBaseApplication.cpp b/samples_framework/src/CEGuiBaseApplication.cpp index 7c4d881aa..eb3a97ddd 100644 --- a/samples_framework/src/CEGuiBaseApplication.cpp +++ b/samples_framework/src/CEGuiBaseApplication.cpp @@ -41,6 +41,7 @@ #include "CEGUI/GUIContext.h" #include "CEGUI/RenderTarget.h" #include "CEGUI/AnimationManager.h" +#include "CEGUI/FontManager.h" #include #include #include @@ -106,18 +107,21 @@ void CEGuiBaseApplication::renderSingleFrame(const float elapsed) } //----------------------------------------------------------------------------// -bool CEGuiBaseApplication::execute(SamplesFrameworkBase* sampleApp) +bool CEGuiBaseApplication::init(SamplesFrameworkBase* sampleApp, + const CEGUI::String& logFile, const CEGUI::String& dataPathPrefixOverride) { d_sampleApp = sampleApp; if (!d_renderer) - throw CEGUI::InvalidRequestException("CEGuiBaseApplication::run: " - "Base application subclass did not create Renderer!"); + CEGUI_THROW(CEGUI::InvalidRequestException("CEGuiBaseApplication::run: " + "Base application subclass did not create Renderer!")); // start up CEGUI system using objects created in subclass constructor. - CEGUI::System::create(*d_renderer, d_resourceProvider, 0, d_imageCodec); + CEGUI::System::create(*d_renderer, d_resourceProvider, 0, d_imageCodec, 0, + "", logFile); // initialise resource system + initDataPathPrefix(dataPathPrefixOverride); initialiseResourceGroupDirectories(); initialiseDefaultResourceGroups(); @@ -159,21 +163,27 @@ bool CEGuiBaseApplication::execute(SamplesFrameworkBase* sampleApp) d_sampleApp->setApplicationWindowSize(static_cast(area.getWidth()), static_cast(area.getHeight())); - run(); - - cleanup(); - destroyWindow(); - return true; } //----------------------------------------------------------------------------// void CEGuiBaseApplication::cleanup() { - CEGUI::ImageManager::getSingleton().destroy("cegui_logo"); - d_renderer->destroyGeometryBuffer(*d_logoGeometry); - d_renderer->destroyGeometryBuffer(*d_FPSGeometry); - CEGUI::System::destroy(); + if (d_renderer) + { + CEGUI::ImageManager::getSingleton().destroy("cegui_logo"); + d_renderer->destroyGeometryBuffer(*d_logoGeometry); + d_renderer->destroyGeometryBuffer(*d_FPSGeometry); + CEGUI::System::destroy(); + destroyRenderer(); + destroyWindow(); + } +} + +//----------------------------------------------------------------------------// +void CEGuiBaseApplication::destroyRenderer() +{ + CEGUI_DELETE_AO d_renderer; } //----------------------------------------------------------------------------// @@ -183,27 +193,28 @@ void CEGuiBaseApplication::initialiseResourceGroupDirectories() CEGUI::DefaultResourceProvider* rp = static_cast (CEGUI::System::getSingleton().getResourceProvider()); - - const char* dataPathPrefix = getDataPathPrefix(); - char resourcePath[PATH_MAX]; - - // for each resource type, set a resource group directory - sprintf(resourcePath, "%s/%s", dataPathPrefix, "schemes/"); - rp->setResourceGroupDirectory("schemes", resourcePath); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "imagesets/"); - rp->setResourceGroupDirectory("imagesets", resourcePath); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "fonts/"); - rp->setResourceGroupDirectory("fonts", resourcePath); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "layouts/"); - rp->setResourceGroupDirectory("layouts", resourcePath); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "looknfeel/"); - rp->setResourceGroupDirectory("looknfeels", resourcePath); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "lua_scripts/"); - rp->setResourceGroupDirectory("lua_scripts", resourcePath); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "xml_schemas/"); - rp->setResourceGroupDirectory("schemas", resourcePath); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "animations/"); - rp->setResourceGroupDirectory("animations", resourcePath); + CEGUI::String dataPathPrefix(getDataPathPrefix()); + + /* for each resource type, set a resource group directory. We cast strings + to "const CEGUI::utf8*" in order to support general Unicode strings, + rather than only ASCII strings (even though currently they're all ASCII). + */ + rp->setResourceGroupDirectory("schemes", + dataPathPrefix +reinterpret_cast("/schemes/")); + rp->setResourceGroupDirectory("imagesets", + dataPathPrefix +reinterpret_cast("/imagesets/")); + rp->setResourceGroupDirectory("fonts", + dataPathPrefix +reinterpret_cast("/fonts/")); + rp->setResourceGroupDirectory("layouts", + dataPathPrefix +reinterpret_cast("/layouts/")); + rp->setResourceGroupDirectory("looknfeels", + dataPathPrefix +reinterpret_cast("/looknfeel/")); + rp->setResourceGroupDirectory("lua_scripts", + dataPathPrefix +reinterpret_cast("/lua_scripts/")); + rp->setResourceGroupDirectory("schemas", + dataPathPrefix +reinterpret_cast("/xml_schemas/")); + rp->setResourceGroupDirectory("animations", + dataPathPrefix +reinterpret_cast("/animations/")); } //----------------------------------------------------------------------------// @@ -225,35 +236,42 @@ void CEGuiBaseApplication::initialiseDefaultResourceGroups() } //----------------------------------------------------------------------------// -const char* CEGuiBaseApplication::getDataPathPrefix() const +void CEGuiBaseApplication::initDataPathPrefix(const CEGUI::String &override) { - static char dataPathPrefix[PATH_MAX]; -#ifdef __APPLE__ - CFURLRef datafilesURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), - CFSTR("datafiles"), - 0, 0); - CFURLGetFileSystemRepresentation(datafilesURL, true, - reinterpret_cast(dataPathPrefix), - PATH_MAX); - CFRelease(datafilesURL); -#else - char* envDataPath = 0; - - // get data path from environment var - envDataPath = getenv(DATAPATH_VAR_NAME); - - // set data path prefix / base directory. This will - // be either from an environment variable, or from - // a compiled in default based on original configure - // options - if (envDataPath != 0) - strcpy(dataPathPrefix, envDataPath); - else - strcpy(dataPathPrefix, CEGUI_SAMPLE_DATAPATH); -#endif + if (override.empty()) + { + +# ifdef __APPLE__ + + char c_str[PATH_MAX]; + CFURLRef datafilesURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), + CFSTR("datafiles"), + 0, 0); + CFURLGetFileSystemRepresentation(datafilesURL, true, + reinterpret_cast(c_str), + PATH_MAX); + CFRelease(datafilesURL); + d_dataPathPrefix = c_str; + +# else + + // get data path from environment var + char* envDataPath = getenv(DATAPATH_VAR_NAME); - return dataPathPrefix; + // set data path prefix / base directory. This will + // be either from an environment variable, or from + // a compiled in default based on original configure + // options + d_dataPathPrefix = envDataPath ? + envDataPath : CEGUI_SAMPLE_DATAPATH; + +# endif + + } + else + d_dataPathPrefix = override; + } //----------------------------------------------------------------------------// @@ -294,7 +312,7 @@ void CEGuiBaseApplication::updateFPS(const float elapsed) { d_FPSValue = d_FPSFrames; - CEGUI::Font* fnt = CEGUI::System::getSingleton().getDefaultGUIContext().getDefaultFont(); + CEGUI::Font* fnt = &CEGUI::FontManager::getSingleton().get("DejaVuSans-12"); if (!fnt) return; @@ -377,4 +395,4 @@ void CEGuiBaseApplication::registerSampleOverlayHandler(CEGUI::GUIContext* gui_c } -//----------------------------------------------------------------------------// \ No newline at end of file +//----------------------------------------------------------------------------// diff --git a/samples_framework/src/CEGuiD3D10BaseApplication.cpp b/samples_framework/src/CEGuiD3D10BaseApplication.cpp index bb422be2a..a4e255ebb 100644 --- a/samples_framework/src/CEGuiD3D10BaseApplication.cpp +++ b/samples_framework/src/CEGuiD3D10BaseApplication.cpp @@ -38,6 +38,19 @@ #include #include +#ifdef __MINGW32__ + +extern "C" HRESULT WINAPI D3DX10CreateDeviceAndSwapChain( + IDXGIAdapter* pAdapter, + D3D10_DRIVER_TYPE DriverType, + HMODULE Software, + UINT Flags, + DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, + IDXGISwapChain** ppSwapChain, + ID3D10Device** ppDevice); + +#endif + //----------------------------------------------------------------------------// struct CEGuiBaseApplication10Impl { @@ -52,7 +65,8 @@ CEGuiD3D10BaseApplication::CEGuiD3D10BaseApplication() : pimpl(new CEGuiBaseApplication10Impl), d_lastFrameTime(GetTickCount()) { - if (pimpl->d_window = Win32AppHelper::createApplicationWindow(s_defaultWindowWidth, s_defaultWindowHeight)) + if ((pimpl->d_window = Win32AppHelper::createApplicationWindow( + s_defaultWindowWidth, s_defaultWindowHeight))) { if (initialiseDirect3D(s_defaultWindowWidth, s_defaultWindowHeight, true)) { @@ -88,11 +102,6 @@ CEGuiD3D10BaseApplication::CEGuiD3D10BaseApplication() : //----------------------------------------------------------------------------// CEGuiD3D10BaseApplication::~CEGuiD3D10BaseApplication() { - Win32AppHelper::mouseLeaves(); - - CEGUI::Direct3D10Renderer::destroy( - *static_cast(d_renderer)); - Win32AppHelper::cleanupDirectInput(pimpl->d_directInput); cleanupDirect3D(); @@ -102,10 +111,18 @@ CEGuiD3D10BaseApplication::~CEGuiD3D10BaseApplication() delete pimpl; } +//----------------------------------------------------------------------------// +void CEGuiD3D10BaseApplication::destroyRenderer() +{ + Win32AppHelper::mouseLeaves(); + + CEGUI::Direct3D10Renderer::destroy( + *static_cast(d_renderer)); +} + //----------------------------------------------------------------------------// void CEGuiD3D10BaseApplication::run() { - d_sampleApp->initialise(); Win32AppHelper::setSamplesFramework(d_sampleApp); float clear_colour[4] = {0.0f, 0.0f, 0.0f, 0.0f}; @@ -119,8 +136,6 @@ void CEGuiD3D10BaseApplication::run() { if (idle) { - CEGUI::System& guiSystem = CEGUI::System::getSingleton(); - // do time based updates const DWORD thisTime = GetTickCount(); const float elapsed = @@ -158,7 +173,7 @@ void CEGuiD3D10BaseApplication::destroyWindow() } //----------------------------------------------------------------------------// -void CEGuiD3D10BaseApplication::beginRendering(const float elapsed) +void CEGuiD3D10BaseApplication::beginRendering(const float /*elapsed*/) { } @@ -189,10 +204,17 @@ bool CEGuiD3D10BaseApplication::initialiseDirect3D(unsigned int width, scd.Windowed = windowed; // initialise main parts of D3D +#ifdef __MINGW32__ + res = D3DX10CreateDeviceAndSwapChain(0, D3D10_DRIVER_TYPE_HARDWARE, + 0, 0, + &scd, &pimpl->d_swapChain, + &pimpl->d_device); +#else res = D3D10CreateDeviceAndSwapChain(0, D3D10_DRIVER_TYPE_HARDWARE, 0, 0, D3D10_SDK_VERSION, &scd, &pimpl->d_swapChain, &pimpl->d_device); +#endif if (SUCCEEDED(res)) { diff --git a/samples_framework/src/CEGuiD3D11BaseApplication.cpp b/samples_framework/src/CEGuiD3D11BaseApplication.cpp old mode 100644 new mode 100755 index 8db5471b0..1df6ddb73 --- a/samples_framework/src/CEGuiD3D11BaseApplication.cpp +++ b/samples_framework/src/CEGuiD3D11BaseApplication.cpp @@ -38,6 +38,24 @@ #include #include +#ifdef __MINGW32__ + +extern "C" HRESULT WINAPI D3D11CreateDeviceAndSwapChain( + IDXGIAdapter* pAdapter, + D3D_DRIVER_TYPE DriverType, + HMODULE Software, + UINT Flags, + CONST D3D_FEATURE_LEVEL* pFeatureLevels, + UINT FeatureLevels, + UINT SDKVersion, + CONST DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, + IDXGISwapChain** ppSwapChain, + ID3D11Device** ppDevice, + D3D_FEATURE_LEVEL* pFeatureLevel, + ID3D11DeviceContext** ppImmediateContext ); + +#endif + //----------------------------------------------------------------------------// struct CEGuiBaseApplication11Impl { @@ -54,7 +72,7 @@ CEGuiD3D11BaseApplication::CEGuiD3D11BaseApplication() : pimpl(new CEGuiBaseApplication11Impl), d_lastFrameTime(GetTickCount()) { - if (pimpl->d_window = Win32AppHelper::createApplicationWindow(s_defaultWindowWidth, s_defaultWindowHeight)) + if ((pimpl->d_window = Win32AppHelper::createApplicationWindow(s_defaultWindowWidth, s_defaultWindowHeight))) { if (initialiseDirect3D(s_defaultWindowWidth, s_defaultWindowHeight, true)) { @@ -89,11 +107,6 @@ CEGuiD3D11BaseApplication::CEGuiD3D11BaseApplication() : //----------------------------------------------------------------------------// CEGuiD3D11BaseApplication::~CEGuiD3D11BaseApplication() { - Win32AppHelper::mouseLeaves(); - - CEGUI::Direct3D11Renderer::destroy( - *static_cast(d_renderer)); - Win32AppHelper::cleanupDirectInput(pimpl->d_directInput); cleanupDirect3D(); @@ -103,10 +116,18 @@ CEGuiD3D11BaseApplication::~CEGuiD3D11BaseApplication() delete pimpl; } +//----------------------------------------------------------------------------// +void CEGuiD3D11BaseApplication::destroyRenderer() +{ + Win32AppHelper::mouseLeaves(); + + CEGUI::Direct3D11Renderer::destroy( + *static_cast(d_renderer)); +} + //----------------------------------------------------------------------------// void CEGuiD3D11BaseApplication::run() { - d_sampleApp->initialise(); Win32AppHelper::setSamplesFramework(d_sampleApp); float clear_colour[4] = {0.0f, 0.0f, 0.0f, 0.0f}; @@ -120,8 +141,6 @@ void CEGuiD3D11BaseApplication::run() { if (idle) { - CEGUI::System& guiSystem = CEGUI::System::getSingleton(); - // do time based updates const DWORD thisTime = GetTickCount(); const float elapsed = @@ -160,7 +179,7 @@ void CEGuiD3D11BaseApplication::destroyWindow() //----------------------------------------------------------------------------// -void CEGuiD3D11BaseApplication::beginRendering(const float elapsed) +void CEGuiD3D11BaseApplication::beginRendering(const float /*elapsed*/) { } diff --git a/samples_framework/src/CEGuiD3D9BaseApplication.cpp b/samples_framework/src/CEGuiD3D9BaseApplication.cpp index 394cfc0e2..56bc5fa4d 100644 --- a/samples_framework/src/CEGuiD3D9BaseApplication.cpp +++ b/samples_framework/src/CEGuiD3D9BaseApplication.cpp @@ -57,7 +57,8 @@ CEGuiD3D9BaseApplication::CEGuiD3D9BaseApplication() : pimpl(new CEGuiBaseApplication9Impl), d_lastFrameTime(GetTickCount()) { - if (pimpl->d_window = Win32AppHelper::createApplicationWindow(s_defaultWindowWidth, s_defaultWindowHeight)) + if ((pimpl->d_window = Win32AppHelper::createApplicationWindow( + s_defaultWindowWidth, s_defaultWindowHeight))) { if (initialiseDirect3D(s_defaultWindowWidth, s_defaultWindowHeight, D3DADAPTER_DEFAULT, true)) { @@ -85,11 +86,6 @@ pimpl(new CEGuiBaseApplication9Impl), //----------------------------------------------------------------------------// CEGuiD3D9BaseApplication::~CEGuiD3D9BaseApplication() { - Win32AppHelper::mouseLeaves(); - - CEGUI::Direct3D9Renderer::destroy( - *static_cast(d_renderer)); - Win32AppHelper::cleanupDirectInput(pimpl->d_directInput); // cleanup direct 3d systems @@ -101,10 +97,18 @@ CEGuiD3D9BaseApplication::~CEGuiD3D9BaseApplication() delete pimpl; } +//----------------------------------------------------------------------------// +void CEGuiD3D9BaseApplication::destroyRenderer() +{ + Win32AppHelper::mouseLeaves(); + + CEGUI::Direct3D9Renderer::destroy( + *static_cast(d_renderer)); +} + //----------------------------------------------------------------------------// void CEGuiD3D9BaseApplication::run() { - d_sampleApp->initialise(); Win32AppHelper::setSamplesFramework(d_sampleApp); // @@ -117,8 +121,6 @@ void CEGuiD3D9BaseApplication::run() { if (idle) { - CEGUI::System& guiSystem = CEGUI::System::getSingleton(); - // do time based updates DWORD thisTime = GetTickCount(); const float elapsed = @@ -164,7 +166,7 @@ void CEGuiD3D9BaseApplication::destroyWindow() } //----------------------------------------------------------------------------// -void CEGuiD3D9BaseApplication::beginRendering(const float elapsed) +void CEGuiD3D9BaseApplication::beginRendering(const float /*elapsed*/) { pimpl->d_3DDevice->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); diff --git a/samples_framework/src/CEGuiDirectFBBaseApplication.cpp b/samples_framework/src/CEGuiDirectFBBaseApplication.cpp index 638b20d4d..9f44b66d7 100644 --- a/samples_framework/src/CEGuiDirectFBBaseApplication.cpp +++ b/samples_framework/src/CEGuiDirectFBBaseApplication.cpp @@ -148,9 +148,6 @@ CEGuiDirectFBBaseApplication::CEGuiDirectFBBaseApplication() : //----------------------------------------------------------------------------// CEGuiDirectFBBaseApplication::~CEGuiDirectFBBaseApplication() { - CEGUI::DirectFBRenderer::destroy( - *static_cast(d_renderer)); - cleanupDirectFB(); delete pimpl; diff --git a/samples_framework/src/CEGuiGLFW2SharedBase.cpp b/samples_framework/src/CEGuiGLFW2SharedBase.cpp new file mode 100644 index 000000000..555d3c223 --- /dev/null +++ b/samples_framework/src/CEGuiGLFW2SharedBase.cpp @@ -0,0 +1,262 @@ +/*********************************************************************** +created: 21/7/2015 +author: Yaron Cohen-Tal +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ +#include "CEGuiGLFWSharedBase.h" +#include "SamplesFrameworkBase.h" +#include "CEGUI/CEGUI.h" + +#include +#include + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::run() +{ + // Input callbacks of glfw for CEGUI + glfwSetKeyCallback(glfwKeyCallback); + glfwSetCharCallback(glfwCharCallback); + glfwSetMouseButtonCallback(glfwMouseButtonCallback); + glfwSetMouseWheelCallback(glfwMouseWheelCallback); + glfwSetMousePosCallback(glfwMousePosCallback); + + //Window callbacks + glfwSetWindowCloseCallback(glfwWindowCloseCallback); + glfwSetWindowSizeCallback(glfwWindowResizeCallback); + d_windowSized = false; //The resize callback is being called immediately after setting it in this version of glfw + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + // set starting time + d_frameTime = glfwGetTime(); + + while (!d_sampleApp->isQuitting() && + glfwGetWindowParam(GLFW_OPENED)) + { + if (d_windowSized) + { + d_windowSized = false; + CEGUI::System::getSingleton(). + notifyDisplaySizeChanged( + CEGUI::Sizef(static_cast(d_newWindowWidth), + static_cast(d_newWindowHeight))); + } + + drawFrame(); + } +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::endRendering() +{ + glfwSwapBuffers(); +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::createGLFWWindow() +{ + if (glfwOpenWindow(s_defaultWindowWidth, s_defaultWindowHeight, 0, 0, 0, 0, + 24, 8, GLFW_WINDOW) != GL_TRUE) + { + CEGUI_THROW(RendererException("Failed to open GLFW window.")); + glfwTerminate(); + } + glfwEnable (GLFW_KEY_REPEAT); +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::setGLFWAppConfiguration() +{ + glfwSetWindowTitle(d_windowTitle); + + //Deactivate VSYNC + glfwSwapInterval(0); + + // Disable the mouse position in Non_Debug mode +#ifndef DEBUG + glfwDisable(GLFW_MOUSE_CURSOR); +#endif + // Clear Errors by GLFW, even if Setup is correct. + glGetError(); +} + +//----------------------------------------------------------------------------// +int CEGuiGLFWSharedBase::glfwWindowCloseCallback(void) +{ + d_sampleApp->setQuitting(true); + return GL_TRUE; +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::glfwWindowResizeCallback(int w, int h) +{ + // We cache this in order to minimise calls to notifyDisplaySizeChanged, + // which happens in the main loop whenever d_windowSized is set to true. + d_windowSized = true; + d_newWindowWidth = w; + d_newWindowHeight = h; +} + +//----------------------------------------------------------------------------// +CEGUI::Key::Scan CEGuiGLFWSharedBase::GlfwToCeguiKey(int glfwKey) +{ + switch(glfwKey) + { + case GLFW_KEY_ESC : return CEGUI::Key::Escape; + case GLFW_KEY_F1 : return CEGUI::Key::F1; + case GLFW_KEY_F2 : return CEGUI::Key::F2; + case GLFW_KEY_F3 : return CEGUI::Key::F3; + case GLFW_KEY_F4 : return CEGUI::Key::F4; + case GLFW_KEY_F5 : return CEGUI::Key::F5; + case GLFW_KEY_F6 : return CEGUI::Key::F6; + case GLFW_KEY_F7 : return CEGUI::Key::F7; + case GLFW_KEY_F8 : return CEGUI::Key::F8; + case GLFW_KEY_F9 : return CEGUI::Key::F9; + case GLFW_KEY_F10 : return CEGUI::Key::F10; + case GLFW_KEY_F11 : return CEGUI::Key::F11; + case GLFW_KEY_F12 : return CEGUI::Key::F12; + case GLFW_KEY_F13 : return CEGUI::Key::F13; + case GLFW_KEY_F14 : return CEGUI::Key::F14; + case GLFW_KEY_F15 : return CEGUI::Key::F15; + case GLFW_KEY_UP : return CEGUI::Key::ArrowUp; + case GLFW_KEY_DOWN : return CEGUI::Key::ArrowDown; + case GLFW_KEY_LEFT : return CEGUI::Key::ArrowLeft; + case GLFW_KEY_RIGHT : return CEGUI::Key::ArrowRight; + case GLFW_KEY_LSHIFT : return CEGUI::Key::LeftShift; + case GLFW_KEY_RSHIFT : return CEGUI::Key::RightShift; + case GLFW_KEY_LCTRL : return CEGUI::Key::LeftControl; + case GLFW_KEY_RCTRL : return CEGUI::Key::RightControl; + case GLFW_KEY_LALT : return CEGUI::Key::LeftAlt; + case GLFW_KEY_RALT : return CEGUI::Key::RightAlt; + case GLFW_KEY_TAB : return CEGUI::Key::Tab; + case GLFW_KEY_ENTER : return CEGUI::Key::Return; + case GLFW_KEY_BACKSPACE : return CEGUI::Key::Backspace; + case GLFW_KEY_INSERT : return CEGUI::Key::Insert; + case GLFW_KEY_DEL : return CEGUI::Key::Delete; + case GLFW_KEY_PAGEUP : return CEGUI::Key::PageUp; + case GLFW_KEY_PAGEDOWN : return CEGUI::Key::PageDown; + case GLFW_KEY_HOME : return CEGUI::Key::Home; + case GLFW_KEY_END : return CEGUI::Key::End; + case GLFW_KEY_KP_ENTER : return CEGUI::Key::NumpadEnter; + default : return CEGUI::Key::Unknown; + } +} + +//----------------------------------------------------------------------------// +void GLFWCALL CEGuiGLFWSharedBase::glfwKeyCallback(int key, int action) +{ + CEGUI::Key::Scan ceguiKey = GlfwToCeguiKey(key); + + if(action == GLFW_PRESS) + d_sampleApp->injectKeyDown(ceguiKey); + else if (action == GLFW_RELEASE) + d_sampleApp->injectKeyUp(ceguiKey); +} + +//----------------------------------------------------------------------------// +void GLFWCALL CEGuiGLFWSharedBase::glfwCharCallback(int character, int action) +{ + if(action == GLFW_PRESS) + d_sampleApp->injectChar(character); +} + +//----------------------------------------------------------------------------// +void GLFWCALL CEGuiGLFWSharedBase::glfwMouseButtonCallback(int key, int action) +{ + CEGUI::MouseButton ceguiMouseButton = GlfwToCeguiMouseButton(key); + + if(action == GLFW_PRESS) + d_sampleApp->injectMouseButtonDown(ceguiMouseButton); + else if (action == GLFW_RELEASE) + d_sampleApp->injectMouseButtonUp(ceguiMouseButton); +} + +//----------------------------------------------------------------------------// +void GLFWCALL CEGuiGLFWSharedBase::glfwMouseWheelCallback(int position) +{ + static int lastPosition = 0; + d_sampleApp->injectMouseWheelChange(static_cast(position - lastPosition)); + lastPosition = position; +} + +//----------------------------------------------------------------------------// +void GLFWCALL CEGuiGLFWSharedBase::glfwMousePosCallback(int x, int y) +{ + if (!d_mouseDisableCalled) + { + // if cursor didn't leave the window nothing changes + d_sampleApp->injectMousePosition(static_cast(x), static_cast(y)); + } + else + { + // if the cursor left the window, we need to use the saved position + // because glfw beams the cursor to the middle of the window if + // the cursor is disabled + d_sampleApp->injectMousePosition(static_cast(d_oldMousePosX), static_cast(d_oldMousePosY)); + glfwSetMousePos(static_cast(d_oldMousePosX), static_cast(d_oldMousePosY)); + d_mouseDisableCalled = false; + } + +#ifndef DEBUG + if (x < 0 || y < 0 + || x > d_newWindowWidth + || y > d_newWindowHeight) + { + // show cursor + glfwEnable(GLFW_MOUSE_CURSOR); + + // move the cursor to the position where it left the window + glfwSetMousePos(x, y); + + // "note down" that the cursor left the window + d_mouseLeftWindow = true; + } + else + { + if (d_mouseLeftWindow) + { + // get cursor position to restore afterwards + int mouse_x_int(0); + int mouse_y_int(0); + glfwGetMousePos(&mouse_x_int, &mouse_y_int); + d_oldMousePosX = mouse_x_int; + d_oldMousePosY = mouse_y_int; + + // we need to inject the previous cursor position because + // glfw moves the cursor to the centre of the render + // window if it gets disabled. therefore notify the + // next MousePosCallback invocation of the "mouse disabled" event. + d_mouseDisableCalled = true; + + // disable cursor + glfwDisable(GLFW_MOUSE_CURSOR); + + // "note down" that the cursor is back in the render window + d_mouseLeftWindow = false; + } + } +#endif +} + +//----------------------------------------------------------------------------// + diff --git a/samples_framework/src/CEGuiGLFW3SharedBase.cpp b/samples_framework/src/CEGuiGLFW3SharedBase.cpp new file mode 100644 index 000000000..8c9676518 --- /dev/null +++ b/samples_framework/src/CEGuiGLFW3SharedBase.cpp @@ -0,0 +1,260 @@ +/*********************************************************************** +created: 21/7/2015 +author: Yaron Cohen-Tal +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ + +#include "CEGuiGLFWSharedBase.h" +#include "SamplesFrameworkBase.h" +#include "CEGUI/CEGUI.h" + +//----------------------------------------------------------------------------// +GLFWwindow* CEGuiGLFWSharedBase::d_window = 0; + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::run() +{ + // Input callbacks of glfw for CEGUI + glfwSetKeyCallback(d_window, glfwKeyCallback); + glfwSetCharCallback(d_window, glfwCharCallback); + glfwSetMouseButtonCallback(d_window, glfwMouseButtonCallback); + glfwSetScrollCallback(d_window, glfwScrollCallback); + glfwSetCursorPosCallback(d_window, glfwCursorPosCallback); + + //Window callbacks + glfwSetWindowCloseCallback(d_window, glfwWindowCloseCallback); + glfwSetWindowSizeCallback(d_window, glfwWindowResizeCallback); + d_windowSized = false; //The resize callback is being called immediately after setting it in this version of glfw + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + // set starting time + d_frameTime = glfwGetTime(); + + while (!d_sampleApp->isQuitting()) + { + if (d_windowSized) + { + d_windowSized = false; + CEGUI::System::getSingleton(). + notifyDisplaySizeChanged( + CEGUI::Sizef(static_cast(d_newWindowWidth), + static_cast(d_newWindowHeight))); + } + + drawFrame(); + glfwPollEvents(); + } + +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::endRendering() +{ + glfwSwapBuffers(d_window); +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::createGLFWWindow() +{ + glfwWindowHint(GLFW_RED_BITS, GLFW_DONT_CARE); + glfwWindowHint(GLFW_GREEN_BITS, GLFW_DONT_CARE); + glfwWindowHint(GLFW_BLUE_BITS, GLFW_DONT_CARE); + glfwWindowHint(GLFW_ALPHA_BITS, 0); + if (!(d_window = glfwCreateWindow(s_defaultWindowWidth, + s_defaultWindowHeight, d_windowTitle, 0, 0))) + { + CEGUI_THROW(RendererException("Failed to open GLFW window.")); + glfwTerminate(); + } + glfwMakeContextCurrent (d_window); +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::setGLFWAppConfiguration() +{ + //Deactivate VSYNC + glfwSwapInterval(0); + + // Disable the mouse position in Non_Debug mode +#ifndef DEBUG + glfwSetInputMode(d_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); +#endif + // Clear Errors by GLFW, even if Setup is correct. + glGetError(); +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::glfwWindowCloseCallback(GLFWwindow* /*window*/) +{ + d_sampleApp->setQuitting(true); +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::glfwWindowResizeCallback(GLFWwindow* /*window*/, int width, int height) +{ + // We cache this in order to minimise calls to notifyDisplaySizeChanged, + // which happens in the main loop whenever d_windowSized is set to true. + d_windowSized = true; + d_newWindowWidth = width; + d_newWindowHeight = height; +} + +//----------------------------------------------------------------------------// +CEGUI::Key::Scan CEGuiGLFWSharedBase::GlfwToCeguiKey(int glfwKey) +{ + switch(glfwKey) + { + case GLFW_KEY_ESCAPE : return CEGUI::Key::Escape; + case GLFW_KEY_F1 : return CEGUI::Key::F1; + case GLFW_KEY_F2 : return CEGUI::Key::F2; + case GLFW_KEY_F3 : return CEGUI::Key::F3; + case GLFW_KEY_F4 : return CEGUI::Key::F4; + case GLFW_KEY_F5 : return CEGUI::Key::F5; + case GLFW_KEY_F6 : return CEGUI::Key::F6; + case GLFW_KEY_F7 : return CEGUI::Key::F7; + case GLFW_KEY_F8 : return CEGUI::Key::F8; + case GLFW_KEY_F9 : return CEGUI::Key::F9; + case GLFW_KEY_F10 : return CEGUI::Key::F10; + case GLFW_KEY_F11 : return CEGUI::Key::F11; + case GLFW_KEY_F12 : return CEGUI::Key::F12; + case GLFW_KEY_F13 : return CEGUI::Key::F13; + case GLFW_KEY_F14 : return CEGUI::Key::F14; + case GLFW_KEY_F15 : return CEGUI::Key::F15; + case GLFW_KEY_UP : return CEGUI::Key::ArrowUp; + case GLFW_KEY_DOWN : return CEGUI::Key::ArrowDown; + case GLFW_KEY_LEFT : return CEGUI::Key::ArrowLeft; + case GLFW_KEY_RIGHT : return CEGUI::Key::ArrowRight; + case GLFW_KEY_LEFT_SHIFT : return CEGUI::Key::LeftShift; + case GLFW_KEY_RIGHT_SHIFT : return CEGUI::Key::RightShift; + case GLFW_KEY_LEFT_CONTROL : return CEGUI::Key::LeftControl; + case GLFW_KEY_RIGHT_CONTROL: return CEGUI::Key::RightControl; + case GLFW_KEY_LEFT_ALT : return CEGUI::Key::LeftAlt; + case GLFW_KEY_RIGHT_ALT : return CEGUI::Key::RightAlt; + case GLFW_KEY_TAB : return CEGUI::Key::Tab; + case GLFW_KEY_ENTER : return CEGUI::Key::Return; + case GLFW_KEY_BACKSPACE : return CEGUI::Key::Backspace; + case GLFW_KEY_INSERT : return CEGUI::Key::Insert; + case GLFW_KEY_DELETE : return CEGUI::Key::Delete; + case GLFW_KEY_PAGE_UP : return CEGUI::Key::PageUp; + case GLFW_KEY_PAGE_DOWN : return CEGUI::Key::PageDown; + case GLFW_KEY_HOME : return CEGUI::Key::Home; + case GLFW_KEY_END : return CEGUI::Key::End; + case GLFW_KEY_KP_ENTER : return CEGUI::Key::NumpadEnter; + default : return CEGUI::Key::Unknown; + } +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::glfwKeyCallback(GLFWwindow* /*window*/, int key, + int /*scancode*/, int action, int /*mods*/) +{ + CEGUI::Key::Scan ceguiKey = GlfwToCeguiKey(key); + + if(action == GLFW_PRESS) + d_sampleApp->injectKeyDown(ceguiKey); + else if (action == GLFW_RELEASE) + d_sampleApp->injectKeyUp(ceguiKey); +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::glfwCharCallback + (GLFWwindow* /*window*/, unsigned codepoint) +{ + d_sampleApp->injectChar(codepoint); +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::glfwMouseButtonCallback + (GLFWwindow* /*window*/, int button, int action, int /*mods*/) +{ + CEGUI::MouseButton ceguiMouseButton = GlfwToCeguiMouseButton(button); + + if (action == GLFW_PRESS) + d_sampleApp->injectMouseButtonDown(ceguiMouseButton); + else if (action == GLFW_RELEASE) + d_sampleApp->injectMouseButtonUp(ceguiMouseButton); +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::glfwScrollCallback + (GLFWwindow* /*window*/, double /*xoffset*/, double yoffset) +{ + d_sampleApp->injectMouseWheelChange(static_cast(yoffset/4)); +} + +//----------------------------------------------------------------------------// +void CEGuiGLFWSharedBase::glfwCursorPosCallback + (GLFWwindow* /*window*/, double x, double y) +{ + if (!d_mouseDisableCalled) + { + // if cursor didn't leave the window nothing changes + d_sampleApp->injectMousePosition(static_cast(x), static_cast(y)); + } + else + { + // if the cursor left the window, we need to use the saved position + // because glfw beams the cursor to the middle of the window if + // the cursor is disabled + d_sampleApp->injectMousePosition(static_cast(d_oldMousePosX), static_cast(d_oldMousePosY)); + glfwSetCursorPos(d_window, d_oldMousePosX, d_oldMousePosY); + d_mouseDisableCalled = false; + } + +#ifndef DEBUG + if (x < 0 || y < 0 + || x > d_newWindowWidth + || y > d_newWindowHeight) + { + // show cursor + glfwSetInputMode(d_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); + + // move the cursor to the position where it left the window + glfwSetCursorPos(d_window, x, y); + + // "note down" that the cursor left the window + d_mouseLeftWindow = true; + } + else + { + if (d_mouseLeftWindow) + { + // get cursor position to restore afterwards + glfwGetCursorPos(d_window, &d_oldMousePosX, &d_oldMousePosY); + + // we need to inject the previous cursor position because + // glfw moves the cursor to the centre of the render + // window if it gets disabled. therefore notify the + // next MousePosCallback invocation of the "mouse disabled" event. + d_mouseDisableCalled = true; + + // disable cursor + glfwSetInputMode(d_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + + // "note down" that the cursor is back in the render window + d_mouseLeftWindow = false; + } + } +#endif +} diff --git a/samples_framework/src/CEGuiGLFWSharedBase.cpp b/samples_framework/src/CEGuiGLFWSharedBase.cpp index f8406caff..3efc89270 100644 --- a/samples_framework/src/CEGuiGLFWSharedBase.cpp +++ b/samples_framework/src/CEGuiGLFWSharedBase.cpp @@ -24,20 +24,12 @@ author: Paul D Turner * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/ -#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__HAIKU__) -# include -#endif - -#include "CEGUISamplesConfig.h" #include "CEGuiGLFWSharedBase.h" #include "SamplesFrameworkBase.h" #include "CEGUI/CEGUI.h" -#include -#include - //----------------------------------------------------------------------------// -CEGuiGLFWSharedBase* CEGuiGLFWSharedBase::d_appInstance = 0; +const char CEGuiGLFWSharedBase::d_windowTitle[] = "Crazy Eddie's GUI Mk-2 - Sample Application"; double CEGuiGLFWSharedBase::d_frameTime = 0; int CEGuiGLFWSharedBase::d_modifiers = 0; bool CEGuiGLFWSharedBase::d_windowSized = false; @@ -45,62 +37,18 @@ int CEGuiGLFWSharedBase::d_newWindowWidth = CEGuiGLFWSharedBase::s_defaultWindow int CEGuiGLFWSharedBase::d_newWindowHeight = CEGuiGLFWSharedBase::s_defaultWindowWidth; bool CEGuiGLFWSharedBase::d_mouseLeftWindow = false; bool CEGuiGLFWSharedBase::d_mouseDisableCalled = false; -int CEGuiGLFWSharedBase::d_oldMousePosX = 0; -int CEGuiGLFWSharedBase::d_oldMousePosY = 0; +double CEGuiGLFWSharedBase::d_oldMousePosX = 0.; +double CEGuiGLFWSharedBase::d_oldMousePosY = 0.; //----------------------------------------------------------------------------// CEGuiGLFWSharedBase::CEGuiGLFWSharedBase() { - if (d_appInstance) - throw CEGUI::InvalidRequestException( - "CEGuiGLFWSharedBase instance already exists!"); - - d_appInstance = this; -} - -//----------------------------------------------------------------------------// -CEGuiGLFWSharedBase::~CEGuiGLFWSharedBase() -{ +#if defined CEGUI_OPENGL_VER_MAJOR_FORCE + CEGUI::OpenGLInfo::getSingleton().verForce(CEGUI_OPENGL_VER_MAJOR_FORCE, + CEGUI_OPENGL_VER_MINOR_FORCE); +#endif } -//----------------------------------------------------------------------------// -void CEGuiGLFWSharedBase::run() -{ - d_sampleApp->initialise(); - - // Input callbacks of glfw for CEGUI - glfwSetKeyCallback(glfwKeyCallback); - glfwSetCharCallback(glfwCharCallback); - glfwSetMouseButtonCallback(glfwMouseButtonCallback); - glfwSetMouseWheelCallback(glfwMouseWheelCallback); - glfwSetMousePosCallback(glfwMousePosCallback); - - //Window callbacks - glfwSetWindowCloseCallback(glfwWindowCloseCallback); - glfwSetWindowSizeCallback(glfwWindowResizeCallback); - d_windowSized = false; //The resize callback is being called immediately after setting it in this version of glfw - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - - // set starting time - d_frameTime = glfwGetTime(); - - while (!d_sampleApp->isQuitting() && - glfwGetWindowParam(GLFW_OPENED)) - { - if (d_windowSized) - { - d_windowSized = false; - CEGUI::System::getSingleton(). - notifyDisplaySizeChanged( - CEGUI::Sizef(static_cast(d_newWindowWidth), - static_cast(d_newWindowHeight))); - } - - drawFrame(); - } - - d_sampleApp->deinitialise(); -} //----------------------------------------------------------------------------// void CEGuiGLFWSharedBase::destroyWindow() { @@ -113,12 +61,6 @@ void CEGuiGLFWSharedBase::beginRendering(const float /*elapsed*/) glClear(GL_COLOR_BUFFER_BIT); } -//----------------------------------------------------------------------------// -void CEGuiGLFWSharedBase::endRendering() -{ - glfwSwapBuffers(); -} - //----------------------------------------------------------------------------// void CEGuiGLFWSharedBase::drawFrame() { @@ -126,70 +68,7 @@ void CEGuiGLFWSharedBase::drawFrame() double time_now = glfwGetTime(); const double elapsed = time_now - d_frameTime; d_frameTime = time_now; - - d_appInstance->renderSingleFrame(static_cast(elapsed)); -} - -//----------------------------------------------------------------------------// -int CEGuiGLFWSharedBase::glfwWindowCloseCallback(void) -{ - d_sampleApp->setQuitting(true); - return GL_TRUE; -} - -//----------------------------------------------------------------------------// -void CEGuiGLFWSharedBase::glfwWindowResizeCallback(int w, int h) -{ - // We cache this in order to minimise calls to notifyDisplaySizeChanged, - // which happens in the main loop whenever d_windowSized is set to true. - d_windowSized = true; - d_newWindowWidth = w; - d_newWindowHeight = h; -} - -//----------------------------------------------------------------------------// -CEGUI::Key::Scan CEGuiGLFWSharedBase::GlfwToCeguiKey(int glfwKey) -{ - switch(glfwKey) - { - case GLFW_KEY_ESC : return CEGUI::Key::Escape; - case GLFW_KEY_F1 : return CEGUI::Key::F1; - case GLFW_KEY_F2 : return CEGUI::Key::F2; - case GLFW_KEY_F3 : return CEGUI::Key::F3; - case GLFW_KEY_F4 : return CEGUI::Key::F4; - case GLFW_KEY_F5 : return CEGUI::Key::F5; - case GLFW_KEY_F6 : return CEGUI::Key::F6; - case GLFW_KEY_F7 : return CEGUI::Key::F7; - case GLFW_KEY_F8 : return CEGUI::Key::F8; - case GLFW_KEY_F9 : return CEGUI::Key::F9; - case GLFW_KEY_F10 : return CEGUI::Key::F10; - case GLFW_KEY_F11 : return CEGUI::Key::F11; - case GLFW_KEY_F12 : return CEGUI::Key::F12; - case GLFW_KEY_F13 : return CEGUI::Key::F13; - case GLFW_KEY_F14 : return CEGUI::Key::F14; - case GLFW_KEY_F15 : return CEGUI::Key::F15; - case GLFW_KEY_UP : return CEGUI::Key::ArrowUp; - case GLFW_KEY_DOWN : return CEGUI::Key::ArrowDown; - case GLFW_KEY_LEFT : return CEGUI::Key::ArrowLeft; - case GLFW_KEY_RIGHT : return CEGUI::Key::ArrowRight; - case GLFW_KEY_LSHIFT : return CEGUI::Key::LeftShift; - case GLFW_KEY_RSHIFT : return CEGUI::Key::RightShift; - case GLFW_KEY_LCTRL : return CEGUI::Key::LeftControl; - case GLFW_KEY_RCTRL : return CEGUI::Key::RightControl; - case GLFW_KEY_LALT : return CEGUI::Key::LeftAlt; - case GLFW_KEY_RALT : return CEGUI::Key::RightAlt; - case GLFW_KEY_TAB : return CEGUI::Key::Tab; - case GLFW_KEY_ENTER : return CEGUI::Key::Return; - case GLFW_KEY_BACKSPACE : return CEGUI::Key::Backspace; - case GLFW_KEY_INSERT : return CEGUI::Key::Insert; - case GLFW_KEY_DEL : return CEGUI::Key::Delete; - case GLFW_KEY_PAGEUP : return CEGUI::Key::PageUp; - case GLFW_KEY_PAGEDOWN : return CEGUI::Key::PageDown; - case GLFW_KEY_HOME : return CEGUI::Key::Home; - case GLFW_KEY_END : return CEGUI::Key::End; - case GLFW_KEY_KP_ENTER : return CEGUI::Key::NumpadEnter; - default : return CEGUI::Key::Unknown; - } + d_sampleApp->renderSingleFrame(static_cast(elapsed)); } //----------------------------------------------------------------------------// @@ -204,130 +83,9 @@ CEGUI::MouseButton CEGuiGLFWSharedBase::GlfwToCeguiMouseButton(int glfwButton) } } -//----------------------------------------------------------------------------// -void GLFWCALL CEGuiGLFWSharedBase::glfwKeyCallback(int key, int action) -{ - CEGUI::Key::Scan ceguiKey = GlfwToCeguiKey(key); - - if(action == GLFW_PRESS) - d_sampleApp->injectKeyDown(ceguiKey); - else if (action == GLFW_RELEASE) - d_sampleApp->injectKeyUp(ceguiKey); -} - -//----------------------------------------------------------------------------// -void GLFWCALL CEGuiGLFWSharedBase::glfwCharCallback(int character, int action) -{ - if(action == GLFW_PRESS) - d_sampleApp->injectChar(character); -} - -//----------------------------------------------------------------------------// -void GLFWCALL CEGuiGLFWSharedBase::glfwMouseButtonCallback(int key, int action) -{ - CEGUI::MouseButton ceguiMouseButton = GlfwToCeguiMouseButton(key); - - if(action == GLFW_PRESS) - d_sampleApp->injectMouseButtonDown(ceguiMouseButton); - else if (action == GLFW_RELEASE) - d_sampleApp->injectMouseButtonUp(ceguiMouseButton); -} - -//----------------------------------------------------------------------------// -void GLFWCALL CEGuiGLFWSharedBase::glfwMouseWheelCallback(int position) -{ - static int lastPosition = 0; - d_sampleApp->injectMouseWheelChange(static_cast(position - lastPosition)); - lastPosition = position; -} - -//----------------------------------------------------------------------------// -void GLFWCALL CEGuiGLFWSharedBase::glfwMousePosCallback(int x, int y) -{ - if (!d_mouseDisableCalled) - { - // if cursor didn't leave the window nothing changes - d_sampleApp->injectMousePosition(static_cast(x), static_cast(y)); - } - else - { - // if the cursor left the window, we need to use the saved position - // because glfw beams the cursor to the middle of the window if - // the cursor is disabled - d_sampleApp->injectMousePosition(static_cast(d_oldMousePosX), static_cast(d_oldMousePosY)); - glfwSetMousePos(d_oldMousePosX, d_oldMousePosY); - d_mouseDisableCalled = false; - } - -#ifndef DEBUG - if (x < 0 || y < 0 - || x > d_newWindowWidth - || y > d_newWindowHeight) - { - // show cursor - glfwEnable(GLFW_MOUSE_CURSOR); - - // move the cursor to the position where it left the window - glfwSetMousePos(x, y); - - // "note down" that the cursor left the window - d_mouseLeftWindow = true; - } - else - { - if (d_mouseLeftWindow) - { - // get cursor position to restore afterwards - glfwGetMousePos(&d_oldMousePosX, &d_oldMousePosY); - - // we need to inject the previous cursor position because - // glfw moves the cursor to the centre of the render - // window if it gets disabled. therefore notify the - // next MousePosCallback invocation of the "mouse disabled" event. - d_mouseDisableCalled = true; - - // disable cursor - glfwDisable(GLFW_MOUSE_CURSOR); - - // "note down" that the cursor is back in the render window - d_mouseLeftWindow = false; - } - } -#endif -} - //----------------------------------------------------------------------------// void CEGuiGLFWSharedBase::initGLFW() { - if(!glfwInit()) - CEGUI_THROW(CEGUI::RendererException("Failed to initialise GLFW.")); -} - -//----------------------------------------------------------------------------// -void CEGuiGLFWSharedBase::createGLFWWindow() -{ - if (glfwOpenWindow(s_defaultWindowWidth, s_defaultWindowHeight, 0, 0, 0, 0, 24, 8, GLFW_WINDOW) != GL_TRUE) - { - CEGUI_THROW(CEGUI::RendererException("Failed to open GLFW window.")); - glfwTerminate(); - } -} - -//----------------------------------------------------------------------------// -void CEGuiGLFWSharedBase::setGLFWAppConfiguration() -{ - glfwSetWindowTitle("Crazy Eddie's GUI Mk-2 - Sample Application"); - - //Deactivate VSYNC - glfwSwapInterval(0); - - // Disable the mouse position in Non_Debug mode -#ifndef DEBUG - glfwDisable(GLFW_MOUSE_CURSOR); -#endif - // Clear Errors by GLFW, even if Setup is correct. - glGetError(); + if (glfwInit() != GL_TRUE) + CEGUI_THROW(RendererException("Failed to initialise GLFW.")); } - -//----------------------------------------------------------------------------// - diff --git a/samples_framework/src/CEGuiIrrlichtBaseApplication.cpp b/samples_framework/src/CEGuiIrrlichtBaseApplication.cpp index a5b27b72c..e760b723d 100644 --- a/samples_framework/src/CEGuiIrrlichtBaseApplication.cpp +++ b/samples_framework/src/CEGuiIrrlichtBaseApplication.cpp @@ -104,6 +104,13 @@ d_device(0), //----------------------------------------------------------------------------// CEGuiIrrlichtBaseApplication::~CEGuiIrrlichtBaseApplication() +{ + if (d_device) + d_device->drop(); +} + +//----------------------------------------------------------------------------// +void CEGuiIrrlichtBaseApplication::destroyRenderer() { CEGUI::IrrlichtRenderer& renderer = *static_cast(d_renderer); @@ -115,15 +122,11 @@ CEGuiIrrlichtBaseApplication::~CEGuiIrrlichtBaseApplication() *static_cast(d_imageCodec)); CEGUI::IrrlichtRenderer::destroy(renderer); - - if (d_device) - d_device->drop(); } //----------------------------------------------------------------------------// void CEGuiIrrlichtBaseApplication::run() { - d_sampleApp->initialise(); CEGUI::System& guiSystem = CEGUI::System::getSingleton(); // draw everything diff --git a/samples_framework/src/CEGuiOgreBaseApplication.cpp b/samples_framework/src/CEGuiOgreBaseApplication.cpp index 625361ff7..10e2c79b5 100644 --- a/samples_framework/src/CEGuiOgreBaseApplication.cpp +++ b/samples_framework/src/CEGuiOgreBaseApplication.cpp @@ -119,15 +119,6 @@ CEGuiOgreBaseApplication::CEGuiOgreBaseApplication() : //----------------------------------------------------------------------------// CEGuiOgreBaseApplication::~CEGuiOgreBaseApplication() { - delete d_frameListener; - - CEGUI::OgreRenderer& renderer = - *static_cast(d_renderer); - renderer.destroyOgreResourceProvider( - *static_cast(d_resourceProvider)); - renderer.destroyOgreImageCodec( - *static_cast(d_imageCodec)); - CEGUI::OgreRenderer::destroy(renderer); #ifdef OGRE_STATIC_LIB d_staticPluginLoader->unload(); delete d_staticPluginLoader; @@ -137,22 +128,33 @@ CEGuiOgreBaseApplication::~CEGuiOgreBaseApplication() } //----------------------------------------------------------------------------// -void CEGuiOgreBaseApplication::run() +bool CEGuiOgreBaseApplication::init(SamplesFrameworkBase* sampleApp, + const CEGUI::String &logFile, const CEGUI::String &dataPathPrefixOverride) { + if (!CEGuiBaseApplication::init(sampleApp, logFile, dataPathPrefixOverride)) + return false; + // if base initialisation failed or app was cancelled by user, bail out now. if (!d_ogreRoot || !d_initialised) - return; + return false; Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); - d_sampleApp->initialise(); - // start rendering via Ogre3D engine. - CEGUI_TRY - { - d_ogreRoot->startRendering(); - } - CEGUI_CATCH(...) - {} + return true; +} + +//----------------------------------------------------------------------------// +void CEGuiOgreBaseApplication::destroyRenderer() +{ + delete d_frameListener; + + CEGUI::OgreRenderer& renderer = + *static_cast(d_renderer); + renderer.destroyOgreResourceProvider( + *static_cast(d_resourceProvider)); + renderer.destroyOgreImageCodec( + *static_cast(d_imageCodec)); + CEGUI::OgreRenderer::destroy(renderer); } //----------------------------------------------------------------------------// @@ -162,7 +164,7 @@ void CEGuiOgreBaseApplication::destroyWindow() } //----------------------------------------------------------------------------// -void CEGuiOgreBaseApplication::beginRendering(const float elapsed) +void CEGuiOgreBaseApplication::beginRendering(const float /*elapsed*/) { // this is nover called under Ogre, since we're not in control of the // rendering process. @@ -196,34 +198,46 @@ void CEGuiOgreBaseApplication::initialiseResourceGroupDirectories() // add CEGUI sample framework datafile dirs as resource locations ResourceGroupManager::getSingleton().addResourceLocation("./", "FileSystem"); - const char* dataPathPrefix = getDataPathPrefix(); - char resourcePath[PATH_MAX]; + CEGUI::String dataPathPrefix(getDataPathPrefix()); - // for each resource type, set a resource group directory - sprintf(resourcePath, "%s/%s", dataPathPrefix, "schemes/"); - ResourceGroupManager::getSingleton().addResourceLocation(resourcePath, "FileSystem", "schemes"); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "samples/"); - ResourceGroupManager::getSingleton().addResourceLocation(resourcePath, "FileSystem", "samples"); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "imagesets/"); - ResourceGroupManager::getSingleton().addResourceLocation(resourcePath, "FileSystem", "imagesets"); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "fonts/"); - ResourceGroupManager::getSingleton().addResourceLocation(resourcePath, "FileSystem", "fonts"); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "layouts/"); - ResourceGroupManager::getSingleton().addResourceLocation(resourcePath, "FileSystem", "layouts"); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "looknfeel/"); - ResourceGroupManager::getSingleton().addResourceLocation(resourcePath, "FileSystem", "looknfeels"); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "lua_scripts/"); - ResourceGroupManager::getSingleton().addResourceLocation(resourcePath, "FileSystem", "lua_scripts"); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "animations/"); - ResourceGroupManager::getSingleton().addResourceLocation(resourcePath, "FileSystem", "animations"); - sprintf(resourcePath, "%s/%s", dataPathPrefix, "xml_schemas/"); - ResourceGroupManager::getSingleton().addResourceLocation(resourcePath, "FileSystem", "schemas"); + /* for each resource type, set a resource group directory. We cast strings + to "const CEGUI::utf8*" in order to support general Unicode strings, + rather than only ASCII strings (even though currently they're all ASCII). + */ + ResourceGroupManager::getSingleton().addResourceLocation((dataPathPrefix + +reinterpret_cast("/schemes/")).c_str(), + "FileSystem", "schemes"); + ResourceGroupManager::getSingleton().addResourceLocation((dataPathPrefix + +reinterpret_cast("/samples/")).c_str(), + "FileSystem", "samples"); + ResourceGroupManager::getSingleton().addResourceLocation((dataPathPrefix + +reinterpret_cast("/imagesets/")).c_str(), + "FileSystem", "imagesets"); + ResourceGroupManager::getSingleton().addResourceLocation((dataPathPrefix + +reinterpret_cast("/fonts/")).c_str(), + "FileSystem", "fonts"); + ResourceGroupManager::getSingleton().addResourceLocation((dataPathPrefix + +reinterpret_cast("/layouts/")).c_str(), + "FileSystem", "layouts"); + ResourceGroupManager::getSingleton().addResourceLocation((dataPathPrefix + +reinterpret_cast("/looknfeel/")).c_str(), + "FileSystem", "looknfeels"); + ResourceGroupManager::getSingleton().addResourceLocation((dataPathPrefix + +reinterpret_cast("/lua_scripts/")).c_str(), + "FileSystem", "lua_scripts"); + ResourceGroupManager::getSingleton().addResourceLocation((dataPathPrefix + +reinterpret_cast("/animations/")).c_str(), + "FileSystem", "animations"); + ResourceGroupManager::getSingleton().addResourceLocation((dataPathPrefix + +reinterpret_cast("/xml_schemas/")).c_str(), + "FileSystem", "schemas"); } //----------------------------------------------------------------------------// -void CEGuiOgreBaseApplication::doFrameUpdate(const float elapsed) +void CEGuiOgreBaseApplication::doFrameUpdate(const float /*elapsed*/) { } + //----------------------------------------------------------------------------// bool CEGuiOgreBaseApplication::frameRenderingQueued(const Ogre::FrameEvent& args) { @@ -238,6 +252,18 @@ bool CEGuiOgreBaseApplication::isInitialised() return d_initialised; } +//----------------------------------------------------------------------------// +void CEGuiOgreBaseApplication::run() +{ + // start rendering via Ogre3D engine. + CEGUI_TRY + { + d_ogreRoot->startRendering(); + } + CEGUI_CATCH(...) + {} +} + //----------------------------------------------------------------------------// void CEGuiOgreBaseApplication::setupDefaultConfigIfNeeded() { @@ -303,7 +329,7 @@ void CEGuiOgreBaseApplication::setupDefaultConfigIfNeeded() //----------------------------------------------------------------------------// CEGuiDemoFrameListener::CEGuiDemoFrameListener(CEGuiOgreBaseApplication* baseApp, SamplesFrameworkBase*& sampleApp, - Ogre::RenderWindow* window, Ogre::Camera* camera, bool useBufferedInputKeys, bool useBufferedInputMouse) + Ogre::RenderWindow* window, Ogre::Camera* camera) : d_baseApp(baseApp), d_sampleApp(sampleApp) { @@ -319,13 +345,16 @@ CEGuiDemoFrameListener::CEGuiDemoFrameListener(CEGuiOgreBaseApplication* baseApp windowHndStr << (unsigned int)windowHnd; paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); -#if OGRE_PLATFORM != OGRE_PLATFORM_ANDROID && OGRE_PLATFORM != OGRE_PLATFORM_WINRT && OGRE_PLATFORM != OGRE_PLATFORM_LINUX && defined (DEBUG) - paramList.insert(std::make_pair("x11_keyboard_grab", "false")); - paramList.insert(std::make_pair("x11_mouse_grab", "false")); - paramList.insert(std::make_pair("x11_mouse_hide", "false")); - paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND")); - paramList.insert(std::make_pair("w32_mouse", "DISCL_NONEXCLUSIVE")); -#endif + #ifndef NDEBUG + #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX + paramList.insert(std::make_pair("x11_keyboard_grab", "false")); + paramList.insert(std::make_pair("x11_mouse_grab", "false")); + paramList.insert(std::make_pair("x11_mouse_hide", "false")); + #elif OGRE_PLATFORM == OGRE_PLATFORM_WIN32 + paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND")); + paramList.insert(std::make_pair("w32_mouse", "DISCL_NONEXCLUSIVE")); + #endif + #endif // create input system d_inputManager = OIS::InputManager::createInputSystem(paramList); @@ -395,7 +424,7 @@ bool CEGuiDemoFrameListener::frameStarted(const Ogre::FrameEvent& evt) } //----------------------------------------------------------------------------// -bool CEGuiDemoFrameListener::frameEnded(const Ogre::FrameEvent& evt) +bool CEGuiDemoFrameListener::frameEnded(const Ogre::FrameEvent&) { return true; } @@ -420,7 +449,7 @@ bool CEGuiDemoFrameListener::keyPressed(const OIS::KeyEvent &e) //----------------------------------------------------------------------------// -bool CEGuiDemoFrameListener::keyReleased(const OIS::KeyEvent &e) +bool CEGuiDemoFrameListener::keyReleased(const OIS::KeyEvent& e) { d_sampleApp->injectKeyUp(static_cast(e.key)); @@ -428,18 +457,18 @@ bool CEGuiDemoFrameListener::keyReleased(const OIS::KeyEvent &e) } //----------------------------------------------------------------------------// -bool CEGuiDemoFrameListener::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) +bool CEGuiDemoFrameListener::mousePressed + (const OIS::MouseEvent&, OIS::MouseButtonID id) { d_sampleApp->injectMouseButtonDown(convertOISButtonToCegui(id)); - return true; } //----------------------------------------------------------------------------// -bool CEGuiDemoFrameListener::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) +bool CEGuiDemoFrameListener::mouseReleased + (const OIS::MouseEvent&, OIS::MouseButtonID id) { - d_sampleApp->injectMouseButtonUp(convertOISButtonToCegui(id)); - + d_sampleApp->injectMouseButtonUp(convertOISButtonToCegui(id)); return true; } diff --git a/samples_framework/src/CEGuiOpenGL3BaseApplication.cpp b/samples_framework/src/CEGuiOpenGL3BaseApplication.cpp index 113abcc50..4ba587a0f 100644 --- a/samples_framework/src/CEGuiOpenGL3BaseApplication.cpp +++ b/samples_framework/src/CEGuiOpenGL3BaseApplication.cpp @@ -28,7 +28,7 @@ author: Paul D Turner // We need to include windows.h here before glfw is included (via // CEGuiOpenGL3BaseApplication.h) or there will be a warning when GL.h includes // windows.h (via GL3Renderer.h) -#if defined( __WIN32__ ) || defined( _WIN32 ) +#if defined(CEGUI_USE_GLEW) && (defined( __WIN32__ ) || defined( _WIN32 )) #include "windows.h" #endif @@ -46,19 +46,18 @@ CEGuiOpenGL3BaseApplication::CEGuiOpenGL3BaseApplication() d_renderer = &CEGUI::OpenGL3Renderer::create(); } -//----------------------------------------------------------------------------// -CEGuiOpenGL3BaseApplication::~CEGuiOpenGL3BaseApplication() -{ - CEGUI::OpenGL3Renderer::destroy(static_cast(*d_renderer)); -} - //----------------------------------------------------------------------------// void CEGuiOpenGL3BaseApplication::setGLFWWindowCreationHints() { +#if GLFW_VERSION_MAJOR >= 3 + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); +#else // GLFW_VERSION_MAJOR <= 2 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); +#endif } //----------------------------------------------------------------------------// - diff --git a/samples_framework/src/CEGuiOpenGLBaseApplication.cpp b/samples_framework/src/CEGuiOpenGLBaseApplication.cpp index d8344f520..89eeddd2a 100644 --- a/samples_framework/src/CEGuiOpenGLBaseApplication.cpp +++ b/samples_framework/src/CEGuiOpenGLBaseApplication.cpp @@ -46,18 +46,16 @@ CEGuiOpenGLBaseApplication::CEGuiOpenGLBaseApplication() d_renderer = &CEGUI::OpenGLRenderer::create(); } -//----------------------------------------------------------------------------// -CEGuiOpenGLBaseApplication::~CEGuiOpenGLBaseApplication() -{ - CEGUI::OpenGLRenderer::destroy(static_cast(*d_renderer)); -} - //----------------------------------------------------------------------------// void CEGuiOpenGLBaseApplication::setGLFWWindowCreationHints() { +#if GLFW_VERSION_MAJOR >= 3 + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); +#else // GLFW_VERSION_MAJOR <= 2 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 1); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); +#endif } //----------------------------------------------------------------------------// - diff --git a/samples_framework/src/CEGuiOpenGLES2BaseApplication.cpp b/samples_framework/src/CEGuiOpenGLES2BaseApplication.cpp new file mode 100644 index 000000000..b96654e5f --- /dev/null +++ b/samples_framework/src/CEGuiOpenGLES2BaseApplication.cpp @@ -0,0 +1,57 @@ +/*********************************************************************** +created: 24/9/2004 +author: Paul D Turner +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ + +// We need to include windows.h here before glfw is included (via +// CEGuiOpenGLES2BaseApplication.h) or there will be a warning when GL.h includes +// windows.h (via GL3Renderer.h) +#if defined( __WIN32__ ) || defined( _WIN32 ) +#include "windows.h" +#endif + +#include "CEGuiOpenGLES2BaseApplication.h" +#include "CEGUI/RendererModules/OpenGL/GL3Renderer.h" + +//----------------------------------------------------------------------------// +CEGuiOpenGLES2BaseApplication::CEGuiOpenGLES2BaseApplication() +{ + initGLFW(); + setGLFWWindowCreationHints(); + createGLFWWindow(); + setGLFWAppConfiguration(); + + d_renderer = &CEGUI::OpenGL3Renderer::create(); +} + +//----------------------------------------------------------------------------// +void CEGuiOpenGLES2BaseApplication::setGLFWWindowCreationHints() +{ + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); +} + +//----------------------------------------------------------------------------// diff --git a/samples_framework/src/CLICEGuiRendererSelector.cpp b/samples_framework/src/CLICEGuiRendererSelector.cpp index 6dd9c40a0..d192172e3 100644 --- a/samples_framework/src/CLICEGuiRendererSelector.cpp +++ b/samples_framework/src/CLICEGuiRendererSelector.cpp @@ -62,6 +62,12 @@ bool CLICEGuiRendererSelector::invokeDialog() last_available = OpenGL3GuiRendererType; std::cout << rendererNumber << ". OpenGL 3.2 Core Renderer." << std::endl; } + if (d_rendererAvailability[OpenglEs2GuiRendererType]) + { + ++rendererNumber; + last_available = OpenglEs2GuiRendererType; + std::cout << rendererNumber << ". OpenGL ES 2.0 Renderer." << std::endl; + } if (d_rendererAvailability[IrrlichtGuiRendererType]) { ++rendererNumber; @@ -112,6 +118,10 @@ bool CLICEGuiRendererSelector::invokeDialog() { d_lastSelected = OpenGL3GuiRendererType; } + else if ((d_rendererAvailability[OpenglEs2GuiRendererType]) && (--selection == 0)) + { + d_lastSelected = OpenglEs2GuiRendererType; + } else if ((d_rendererAvailability[IrrlichtGuiRendererType]) && (--selection == 0)) { d_lastSelected = IrrlichtGuiRendererType; diff --git a/samples_framework/src/SampleData.cpp b/samples_framework/src/SampleData.cpp index 24d5948aa..01b0dfcd1 100644 --- a/samples_framework/src/SampleData.cpp +++ b/samples_framework/src/SampleData.cpp @@ -221,13 +221,14 @@ SampleDataModule::SampleDataModule(CEGUI::String sampleName, SampleType sampleTypeEnum, CEGUI::String credits) : SampleData(sampleName, summary, description, sampleTypeEnum, credits) - , d_sample(0) , d_dynamicModule(0) + , d_sample(0) { } SampleDataModule::~SampleDataModule() { + //delete d_dynamicModule; } void SampleDataModule::initialise(int width, int height) @@ -250,8 +251,8 @@ void SampleDataModule::deinitialise() void SampleDataModule::getSampleInstanceFromDLL() { - CEGUI::DynamicModule* sampleModule = new CEGUI::DynamicModule(d_name); - getSampleInstance functionPointerGetSample = (getSampleInstance)sampleModule->getSymbolAddress(CEGUI::String(GetSampleInstanceFuncName)); + d_dynamicModule = new CEGUI::DynamicModule(d_name); + getSampleInstance functionPointerGetSample = reinterpret_cast(d_dynamicModule->getSymbolAddress(CEGUI::String(GetSampleInstanceFuncName))); if(functionPointerGetSample == 0) { @@ -270,4 +271,4 @@ void SampleDataModule::onEnteringSample() void SampleDataModule::update(float timeSinceLastUpdate) { d_sample->update(timeSinceLastUpdate); -} \ No newline at end of file +} diff --git a/samples_framework/src/SamplesFramework.cpp b/samples_framework/src/SamplesFramework.cpp index b5b145c7d..771c6b354 100644 --- a/samples_framework/src/SamplesFramework.cpp +++ b/samples_framework/src/SamplesFramework.cpp @@ -39,14 +39,13 @@ author: Lukas E Meindl #include "CEGUI/widgets/PushButton.h" #include "CEGUI/widgets/ProgressBar.h" - #include #include using namespace CEGUI; //platform-dependant DLL delay-loading includes -#if (defined( __WIN32__ ) || defined( _WIN32 )) +#if (defined( __WIN32__ ) || defined( _WIN32 )) #include "windows.h" #endif @@ -54,24 +53,42 @@ using namespace CEGUI; // Name of the xsd schema file used to validate samples XML files. const String SamplesFramework::XMLSchemaName("Samples.xsd"); +#if !defined __ANDROID__ + +/* Usage: + [-d ] [] + */ + //----------------------------------------------------------------------------// -int main(int argc, char* argv[]) +int main(int /*argc*/, char* argv[]) { - // Basic start-up for the sample browser application. - // Will remain in run() until quitting - int argidx = 1; -#ifdef __APPLE__ - if (argc > 1 && !std::strncmp(argv[argidx], "-psn", 4)) + String xml_filename; + String data_path_prefix_override; + char** arg = argv; + while (true) { - --argc; - ++argidx; - } -#endif - - SamplesFramework sampleFramework(argc > 1 ? argv[argidx] : ""); - return sampleFramework.run(); + ++arg; + if (!*arg) + break; + if ((*arg)[0] == '-') + { + if ((*arg)[1] == 'd') + { + ++arg; + if (!*arg) + break; + data_path_prefix_override = *arg; + } + } + else + xml_filename = *arg; + } + SamplesFramework sampleFramework(xml_filename); + return sampleFramework.run(data_path_prefix_override); } +#endif // !defined __ANDROID__ + //----------------------------------------------------------------------------// SamplesFramework::SamplesFramework(const CEGUI::String& xml_filename) : d_sampleExitButton(0), @@ -91,24 +108,23 @@ SamplesFramework::~SamplesFramework() delete d_metaDataWinMgr; } - - //----------------------------------------------------------------------------// -bool SamplesFramework::initialise() +bool SamplesFramework::initialise(const CEGUI::String& logFile, + const CEGUI::String& dataPathPrefixOverride) { - using namespace CEGUI; - - initialiseLoadScreenLayout(); - - // return true to signalize the initialisation was sucessful and run the - // SamplesFramework - return true; + if (SamplesFrameworkBase::initialise(logFile, dataPathPrefixOverride)) + { + initialiseLoadScreenLayout(); + return true; + } + return false; } //----------------------------------------------------------------------------// -void SamplesFramework::deinitialise() +void SamplesFramework::cleanup() { unloadSamples(); + SamplesFrameworkBase::cleanup(); } //----------------------------------------------------------------------------// @@ -441,7 +457,8 @@ SampleData* SamplesFramework::findSampleData(CEGUI::Window* sampleWindow) } //----------------------------------------------------------------------------// -bool SamplesFramework::handleSampleExitButtonClicked(const CEGUI::EventArgs& args) +bool SamplesFramework::handleSampleExitButtonClicked + (const CEGUI::EventArgs&) { d_quittingSampleView = true; @@ -534,7 +551,7 @@ bool SamplesFramework::updateInitialisationStep() case 0: { const String filename(d_samplesXMLFilename.empty() ? - String(d_baseApp->getDataPathPrefix()) + "/samples/samples.xml" : + d_baseApp->getDataPathPrefix() + "/samples/samples.xml" : d_samplesXMLFilename); loadSamplesDataFromXML(filename); diff --git a/samples_framework/src/SamplesFrameworkAndroid.cpp b/samples_framework/src/SamplesFrameworkAndroid.cpp new file mode 100644 index 000000000..7da8f51f4 --- /dev/null +++ b/samples_framework/src/SamplesFrameworkAndroid.cpp @@ -0,0 +1,118 @@ +/*********************************************************************** + created: 27/7/2015 + author: Yaron Cohen-Tal +*************************************************************************/ +/*************************************************************************** +* Copyright (C) 2004 - 2015 Paul D Turner & The CEGUI Development Team +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +***************************************************************************/ + +#if !defined __ANDROID__ +#error This file should only be used in Android. +#endif + +#include "SamplesFramework.h" + +#include "CEGUI/RendererModules/OpenGL/GL.h" +#include +#include +#include + +typedef jobject AndroidActivity; + +SamplesFramework* G_sampleFramework(0); + +void finishAndroidActivity(JNIEnv* env, AndroidActivity activity) +{ + jclass activity_class(env->FindClass("android/app/Activity")); + assert(env->IsSameObject(activity_class, 0) == (jboolean)JNI_FALSE); + jmethodID finish_method(env->GetMethodID(activity_class, "finish", "()V")); + assert(finish_method); + env->CallVoidMethod(activity, finish_method); +} + +extern "C" +{ + +JNIEXPORT void JNICALL + Java_sample_1framework_cegui_MainActivity_nativeFinish + (JNIEnv* env, jclass /*class_*/, AndroidActivity activity) +{ + bool caught_exception(false); + CEGUI_TRY + { + assert(G_sampleFramework); + G_sampleFramework->cleanup(); + CEGUI_DELETE_AO G_sampleFramework; + G_sampleFramework = 0; + } + CEGUI_CATCH(const std::exception& exception) + { + G_sampleFramework->outputExceptionMessage(exception.what()); + finishAndroidActivity(env, activity); + } +} + +JNIEXPORT void JNICALL + Java_sample_1framework_cegui_MainActivity_init (JNIEnv* env, + jclass /*class_*/, AndroidActivity activity, jstring log_file_java, + jstring data_path_prefix_java) +{ + bool caught_exception(false); + CEGUI_TRY + { + assert(!G_sampleFramework); + G_sampleFramework = new SamplesFramework(""); + const char* log_file(env->GetStringUTFChars(log_file_java, 0)); + const char* data_path_prefix + (env->GetStringUTFChars(data_path_prefix_java, 0)); + G_sampleFramework->initialise( + CEGUI::String(reinterpret_cast(log_file)), + CEGUI::String( + reinterpret_cast(data_path_prefix))); + env->ReleaseStringUTFChars(log_file_java, log_file); + env->ReleaseStringUTFChars(data_path_prefix_java, data_path_prefix); + } + CEGUI_CATCH(const std::exception& exception) + { + G_sampleFramework->outputExceptionMessage(exception.what()); + finishAndroidActivity(env, activity); + } +} + +JNIEXPORT void JNICALL + Java_sample_1framework_cegui_MainActivity_render + (JNIEnv* env, jclass /*class_*/, AndroidActivity activity) +{ + bool caught_exception(false); + CEGUI_TRY + { + glClear(GL_COLOR_BUFFER_BIT); + G_sampleFramework->renderSingleFrame(0); + } + CEGUI_CATCH(const std::exception& exception) + { + G_sampleFramework->outputExceptionMessage(exception.what()); + finishAndroidActivity(env, activity); + } +} + +} // extern "C" diff --git a/samples_framework/src/SamplesFrameworkBase.cpp b/samples_framework/src/SamplesFrameworkBase.cpp index 7cdffe134..902e7469b 100644 --- a/samples_framework/src/SamplesFrameworkBase.cpp +++ b/samples_framework/src/SamplesFrameworkBase.cpp @@ -44,6 +44,16 @@ # include "MacCEGuiRendererSelector.h" #endif +#ifdef __ANDROID__ + +#include + +# ifdef CEGUI_SAMPLES_SUPPORT_RENDERER_OPENGLES2 +# include "CEGuiAndroidOpenglEs2BaseApplication.h" +# endif + +#else + // includes for application types #ifdef CEGUI_SAMPLES_RENDERER_OGRE_ACTIVE # include "CEGuiOgreBaseApplication.h" @@ -55,6 +65,9 @@ # ifdef CEGUI_BUILD_RENDERER_OPENGL3 # include "CEGuiOpenGL3BaseApplication.h" # endif +# ifdef CEGUI_SAMPLES_SUPPORT_RENDERER_OPENGLES2 +# include "CEGuiOpenGLES2BaseApplication.h" +# endif #endif #ifdef CEGUI_SAMPLES_RENDERER_IRRLICHT_ACTIVE # include "CEGuiIrrlichtBaseApplication.h" @@ -62,6 +75,9 @@ #ifdef CEGUI_SAMPLES_RENDERER_DIRECTFB_ACTIVE # include "CEGuiDirectFBBaseApplication.h" #endif + +#endif + #if defined( __WIN32__ ) || defined( _WIN32 ) # ifdef CEGUI_SAMPLES_RENDERER_DIRECT3D9_ACTIVE # include "CEGuiD3D9BaseApplication.h" @@ -73,6 +89,7 @@ # include "CEGuiD3D11BaseApplication.h" # endif #endif + // now we include the base CEGuiBaseApplication just in case someone has managed to // get this far without any of the renderers. This ensures the framework will build, // although there will be no renderers available for selection in the samples. @@ -81,12 +98,10 @@ #include "CEGUI/CEGUI.h" // Include iostream if not on windows. -#if defined( __WIN32__ ) || defined( _WIN32 ) -#else -# include +#if !defined( __WIN32__ ) && !defined( _WIN32 ) +# include #endif - /************************************************************************* Constructor *************************************************************************/ @@ -117,42 +132,38 @@ SamplesFrameworkBase::~SamplesFrameworkBase() } - /************************************************************************* Application entry point *************************************************************************/ -int SamplesFrameworkBase::run() +int SamplesFrameworkBase::run(const CEGUI::String& dataPathPrefixOverride) { CEGUI_TRY { - if(runApplication()) - cleanup(); - } - CEGUI_CATCH (CEGUI::Exception& exc) - { - outputExceptionMessage(exc.getMessage().c_str()); + if (initialise("CEGUI.log", dataPathPrefixOverride)) + d_baseApp->run(); + cleanup(); } - CEGUI_CATCH (std::exception& exc) + CEGUI_CATCH(const std::exception& exc) { outputExceptionMessage(exc.what()); } - CEGUI_CATCH (const char* exc) + CEGUI_CATCH(const char* exc) { - outputExceptionMessage(exc); + SamplesFrameworkBase::outputExceptionMessage(exc); } CEGUI_CATCH(...) { - outputExceptionMessage("Unknown exception was caught!"); + SamplesFrameworkBase::outputExceptionMessage + ("Unknown exception was caught!"); } - return 0; } - /************************************************************************* Start the SamplesFramework application *************************************************************************/ -bool SamplesFrameworkBase::runApplication() +bool SamplesFrameworkBase::initialise + (const CEGUI::String& logFile, const CEGUI::String& dataPathPrefixOverride) { // Setup renderer selection dialog for Win32 #if defined( __WIN32__ ) || defined( _WIN32 ) @@ -169,7 +180,6 @@ bool SamplesFrameworkBase::runApplication() d_rendererSelector->setRendererAvailability(Direct3D11GuiRendererType); #endif - #elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__HAIKU__) // decide which method to use for renderer selection # ifdef CEGUI_SAMPLES_USE_GTK2 @@ -182,6 +192,16 @@ bool SamplesFrameworkBase::runApplication() d_rendererSelector = new MacCEGuiRendererSelector(); #endif +#if defined __ANDROID__ + +# if defined CEGUI_SAMPLES_RENDERER_OPENGL_ACTIVE +# if defined CEGUI_SAMPLES_SUPPORT_RENDERER_OPENGLES2 + d_baseApp = new CEGuiAndroidOpenglEs2BaseApplication(); +# endif +# endif + +#else + // enable available renderer types #ifdef CEGUI_SAMPLES_RENDERER_OGRE_ACTIVE d_rendererSelector->setRendererAvailability(OgreGuiRendererType); @@ -193,6 +213,9 @@ bool SamplesFrameworkBase::runApplication() #ifdef CEGUI_BUILD_RENDERER_OPENGL3 d_rendererSelector->setRendererAvailability(OpenGL3GuiRendererType); #endif + #ifdef CEGUI_SAMPLES_SUPPORT_RENDERER_OPENGLES2 + d_rendererSelector->setRendererAvailability(OpenglEs2GuiRendererType); + #endif #endif #ifdef CEGUI_SAMPLES_RENDERER_IRRLICHT_ACTIVE d_rendererSelector->setRendererAvailability(IrrlichtGuiRendererType); @@ -205,7 +228,7 @@ bool SamplesFrameworkBase::runApplication() if (d_rendererSelector->invokeDialog()) { // create appropriate application type based upon users selection - switch(d_rendererSelector->getSelectedRendererType()) + switch (d_rendererSelector->getSelectedRendererType()) { #ifdef CEGUI_SAMPLES_RENDERER_OGRE_ACTIVE case OgreGuiRendererType: @@ -219,33 +242,42 @@ bool SamplesFrameworkBase::runApplication() break; #endif #if defined( __WIN32__ ) || defined( _WIN32 ) -#ifdef CEGUI_SAMPLES_RENDERER_DIRECT3D9_ACTIVE +# ifdef CEGUI_SAMPLES_RENDERER_DIRECT3D9_ACTIVE case Direct3D9GuiRendererType: d_baseApp = new CEGuiD3D9BaseApplication(); break; -#endif // DX9 -#ifdef CEGUI_SAMPLES_RENDERER_DIRECT3D10_ACTIVE +# endif // DX9 +# ifdef CEGUI_SAMPLES_RENDERER_DIRECT3D10_ACTIVE case Direct3D10GuiRendererType: d_baseApp = new CEGuiD3D10BaseApplication(); break; -#endif // DX10 -#ifdef CEGUI_SAMPLES_RENDERER_DIRECT3D11_ACTIVE +# endif // DX10 +# ifdef CEGUI_SAMPLES_RENDERER_DIRECT3D11_ACTIVE case Direct3D11GuiRendererType: d_baseApp = new CEGuiD3D11BaseApplication(); break; -#endif // DX11 +# endif // DX11 #endif // Win32 #ifdef CEGUI_SAMPLES_RENDERER_OPENGL_ACTIVE - #ifdef CEGUI_BUILD_RENDERER_OPENGL - case OpenGLGuiRendererType: - d_baseApp = new CEGuiOpenGLBaseApplication(); - break; - #endif - #ifdef CEGUI_BUILD_RENDERER_OPENGL3 - case OpenGL3GuiRendererType: - d_baseApp = new CEGuiOpenGL3BaseApplication(); - break; - #endif +# ifdef CEGUI_BUILD_RENDERER_OPENGL + case OpenGLGuiRendererType: + d_baseApp = new CEGuiOpenGLBaseApplication(); + break; +# endif +# ifdef CEGUI_BUILD_RENDERER_OPENGL3 + case OpenGL3GuiRendererType: + d_baseApp = new CEGuiOpenGL3BaseApplication(); + break; +# endif +# ifdef CEGUI_SAMPLES_SUPPORT_RENDERER_OPENGLES2 + case OpenglEs2GuiRendererType: +# if defined __ANDROID__ + d_baseApp = new CEGuiAndroidOpenglEs2BaseApplication(); +# else + d_baseApp = new CEGuiOpenGLES2BaseApplication(); +# endif + break; +# endif #endif #ifdef CEGUI_SAMPLES_RENDERER_IRRLICHT_ACTIVE case IrrlichtGuiRendererType: @@ -258,49 +290,36 @@ bool SamplesFrameworkBase::runApplication() break; #endif - default: - CEGUI_THROW(CEGUI::GenericException("No renderer was selected!")); - break; + default: break; } - // run the base application (which sets up the demo via 'this' and runs it. - if (d_baseApp->execute(this)) - { - // signal that app initialised and ran - return true; - } - - // sample app did not initialise, delete the object. - delete d_baseApp; - d_baseApp = 0; } - // delete renderer selector object delete d_rendererSelector; d_rendererSelector = 0; - // signal app did not initialise and run. - return false; -} +#endif + if (!d_baseApp) + CEGUI_THROW(CEGUI::GenericException("No renderer was selected!")); -/************************************************************************* - Cleanup the sample application. -*************************************************************************/ -void SamplesFrameworkBase::cleanup() -{ - delete d_baseApp; - d_baseApp = 0; - + return d_baseApp->init(this, logFile, dataPathPrefixOverride); +} - if (d_rendererSelector) +void SamplesFrameworkBase::cleanup() +{ + if (d_baseApp) { - delete d_rendererSelector; - d_rendererSelector = 0; + d_baseApp->cleanup(); + delete d_baseApp; + d_baseApp = 0; } - } +void SamplesFrameworkBase::renderSingleFrame(float elapsed) +{ + d_baseApp->renderSingleFrame(elapsed); +} /************************************************************************* Output a message to the user in some OS independant way. @@ -309,6 +328,11 @@ void SamplesFrameworkBase::outputExceptionMessage(const char* message) { #if defined(__WIN32__) || defined(_WIN32) MessageBoxA(0, message, "CEGUI - Exception", MB_OK|MB_ICONERROR); +#elif defined(__ANDROID__) + __android_log_write (ANDROID_LOG_ERROR, "CEGUISampleFramework_NDK", + "An exception was thrown within the sample framework:"); + __android_log_write (ANDROID_LOG_ERROR, "CEGUISampleFramework_NDK", + message); #else std::cout << "An exception was thrown within the sample framework:" << std::endl; std::cout << message << std::endl; @@ -329,4 +353,4 @@ void SamplesFrameworkBase::setApplicationWindowSize(int width, int height) { d_appWindowWidth = width; d_appWindowHeight = height; -} \ No newline at end of file +} diff --git a/samples_framework/src/Samples_xmlHandler.cpp b/samples_framework/src/Samples_xmlHandler.cpp index 8c73195fe..27849e7c1 100644 --- a/samples_framework/src/Samples_xmlHandler.cpp +++ b/samples_framework/src/Samples_xmlHandler.cpp @@ -75,7 +75,7 @@ void Samples_xmlHandler::elementStartLocal(const String& element, } else if (element == SampleDataHandler::ElementName) { - d_chainedHandler = new SampleDataHandler(attributes, "", d_samplesFramework); + d_chainedHandler = new SampleDataHandler(attributes, d_samplesFramework); } else Logger::getSingleton().logEvent("Animation_xmlHandler::elementStart: " @@ -98,7 +98,6 @@ void Samples_xmlHandler::elementEndLocal(const String& element) //----------------------------------------------------------------------------// SampleDataHandler::SampleDataHandler( const XMLAttributes& attributes, - const String& name_prefix, SamplesFramework* samplesFramework) : d_samplesFramework(samplesFramework) { @@ -141,7 +140,7 @@ SampleDataHandler::~SampleDataHandler() //----------------------------------------------------------------------------// void SampleDataHandler::elementStartLocal( const String& element, - const XMLAttributes& attributes) + const XMLAttributes& /*attributes*/) { Logger::getSingleton().logEvent( "AnimationDefinitionHandler::elementStart: " diff --git a/samples_framework/src/Win32AppHelper.cpp b/samples_framework/src/Win32AppHelper.cpp index 56969ff80..c73c4e2f0 100644 --- a/samples_framework/src/Win32AppHelper.cpp +++ b/samples_framework/src/Win32AppHelper.cpp @@ -30,7 +30,7 @@ #include "Win32AppHelper.h" #include "CEGUI/CEGUI.h" -#include +#include #include "SamplesFrameworkBase.h" @@ -199,10 +199,9 @@ LRESULT CALLBACK Win32AppHelper::wndProc(HWND hWnd, UINT message, WPARAM wParam, case WM_PAINT: { - HDC hDC; PAINTSTRUCT ps; - hDC = BeginPaint(hWnd, &ps); + BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); break; } diff --git a/samples_framework/src/Win32CEGuiRendererSelector.cpp b/samples_framework/src/Win32CEGuiRendererSelector.cpp index d2734c09d..706c8e36f 100644 --- a/samples_framework/src/Win32CEGuiRendererSelector.cpp +++ b/samples_framework/src/Win32CEGuiRendererSelector.cpp @@ -387,6 +387,7 @@ INT_PTR CALLBACK Win32CEGuiRendererSelector::dialogProcedure(HWND hDlg, UINT mes // add new stings according to if item is enabled or not obj->addComboboxOption(combo, "OpenGL 3.2 Core Renderer", OpenGL3GuiRendererType); + obj->addComboboxOption(combo, "OpenGL ES 2.0 Renderer", OpenglEs2GuiRendererType); obj->addComboboxOption(combo, "OpenGL Renderer", OpenGLGuiRendererType); obj->addComboboxOption(combo, "Ogre Engine Renderer", OgreGuiRendererType); obj->addComboboxOption(combo, "Microsoft Direct3D 9 Renderer", Direct3D9GuiRendererType); @@ -458,7 +459,7 @@ LPBYTE Win32CEGuiRendererSelector::alignPointer(LPBYTE buff) Converts the Ansi string in 'pAnsiIn' into wide characters and copies the result into the WORD array at 'pWCStr'. *************************************************************************/ -int Win32CEGuiRendererSelector::copyAnsiToWideChar(LPBYTE outBuff, PTSTR ansiString) +int Win32CEGuiRendererSelector::copyAnsiToWideChar(LPBYTE outBuff, LPCTSTR ansiString) { LPWSTR pWCStr = reinterpret_cast(outBuff); diff --git a/tests/README.md b/tests/README.md index 8d4a4b616..7ec061cd6 100644 --- a/tests/README.md +++ b/tests/README.md @@ -10,9 +10,20 @@ We use ctest which is part of cmake to run tests. You first need to enable the tests that you want to run. Enable `CEGUI_BUILD_TESTS` and/or `CEGUI_BUILD_DATAFILES_TEST` options in cmake. -Then run the tests using: +Then run the tests using the following commands, based on your operating system: + +* Linux / Mac OS X ```bash cd $cegui_folder cd build/ CEGUI_SAMPLE_DATAPATH=`pwd`/../datafiles/ ctest -V ``` + +* Windows +``` +cd +cd build/ +set CEGUI_SAMPLE_DATAPATH=%CD%/../datafiles/ +ctest -V -C +``` +Where `` is one of: `Debug`, `Release` or `RelWithDebInfo`, depending on what configuration you have built. \ No newline at end of file diff --git a/tests/performance/PerformanceTest.h b/tests/performance/PerformanceTest.h index 9f3fdec37..efa0230bb 100644 --- a/tests/performance/PerformanceTest.h +++ b/tests/performance/PerformanceTest.h @@ -27,10 +27,11 @@ #ifndef _CEGUITestsPerformanceTest_h_ #define _CEGUITestsPerformanceTest_h_ +#include "CEGUI/WindowManager.h" + #include -#include -#include "CEGUI/WindowManager.h" +#include /*! \brief diff --git a/tests/performance/PropertySet.cpp b/tests/performance/PropertySet.cpp new file mode 100644 index 000000000..b8aa9dcae --- /dev/null +++ b/tests/performance/PropertySet.cpp @@ -0,0 +1,120 @@ +/*********************************************************************** + * created: Fri Sep 19 2014 + * author: Martin Preisler + *************************************************************************/ +/*************************************************************************** + * Copyright (C) 2004 - 2014 Paul D Turner & The CEGUI Development Team + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + ***************************************************************************/ +#include + +#include "PerformanceTest.h" +#include "CEGUI/PropertySet.h" +#include + +static const CEGUI::String PROPERTY_NAME("ExplicitlyAddedTestProperty"); + +class PropertySetStringPerformanceTest : public PerformanceTest +{ +public: + PropertySetStringPerformanceTest(const CEGUI::String& test_name, CEGUI::PropertySet& set): + PerformanceTest(test_name), + d_propertySet(set) + {} + + virtual void doTest() + { + for (unsigned int i = 0; i < 1000000; ++i) + { + d_propertySet.setProperty(PROPERTY_NAME, "{ { 1, 0 }, {0.5, 100} }"); + } + } + + CEGUI::PropertySet& d_propertySet; +}; + +class PropertySetTypedPerformanceTest : public PerformanceTest +{ +public: + PropertySetTypedPerformanceTest(const CEGUI::String& test_name, CEGUI::PropertySet& set): + PerformanceTest(test_name), + d_propertySet(set) + {} + + virtual void doTest() + { + for (unsigned int i = 0; i < 1000000; ++i) + { + d_propertySet.setProperty(PROPERTY_NAME, CEGUI::UVector2(CEGUI::UDim(1, 0), CEGUI::UDim(0.5, 100))); + } + } + + CEGUI::PropertySet& d_propertySet; +}; + +class TestingPropertySet : public CEGUI::PropertySet +{ + public: + TestingPropertySet() + { + const CEGUI::String propertyOrigin("abc"); + + CEGUI_DEFINE_PROPERTY(TestingPropertySet, CEGUI::UVector2, + PROPERTY_NAME, "Doc", + &TestingPropertySet::setTestingProperty, + &TestingPropertySet::getTestingProperty, + CEGUI::UVector2() + ); + } + + void setTestingProperty(const CEGUI::UVector2& v) + { + d_testingProperty = v; + } + + const CEGUI::UVector2& getTestingProperty() const + { + return d_testingProperty; + } + + private: + CEGUI::UVector2 d_testingProperty; +}; + +BOOST_AUTO_TEST_SUITE(PropertySetPerformance) + +BOOST_AUTO_TEST_CASE(StringSetTest) +{ + TestingPropertySet set; + + PropertySetStringPerformanceTest test("PropertySet String set test", set); + test.execute(); +} + +BOOST_AUTO_TEST_CASE(TypedSetTest) +{ + TestingPropertySet set; + + PropertySetTypedPerformanceTest test("PropertySet typed set test", set); + test.execute(); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/unit/AnimationSystem.cpp b/tests/unit/AnimationSystem.cpp index 637595e70..1f1ea8491 100644 --- a/tests/unit/AnimationSystem.cpp +++ b/tests/unit/AnimationSystem.cpp @@ -46,7 +46,7 @@ struct SampleAnimationSetupFixture { d_zeroDuration = CEGUI::AnimationManager::getSingleton().createAnimation("ZeroLength"); d_zeroDuration->setDuration(0.0f); - CEGUI::Affector* affector = d_zeroDuration->createAffector("Alpha", "float"); + d_zeroDuration->createAffector("Alpha", "float"); } } diff --git a/tests/unit/EventSet.cpp b/tests/unit/EventSet.cpp index d4d0f0500..ef4d2cc4d 100644 --- a/tests/unit/EventSet.cpp +++ b/tests/unit/EventSet.cpp @@ -30,8 +30,15 @@ #include "CEGUI/EventArgs.h" #include "CEGUI/Exceptions.h" +#include + #include +//#define CEGUI_TEST_BOOST_BIND +#ifdef CEGUI_TEST_BOOST_BIND +# include +#endif + BOOST_AUTO_TEST_SUITE(EventSet) BOOST_AUTO_TEST_CASE(AddingAndRemovingEvents) @@ -78,6 +85,42 @@ bool freeFunctionSubscriber(const CEGUI::EventArgs& args) return true; } +void freeFunctionSubscriberVoid(const CEGUI::EventArgs& args) +{ + g_GlobalEventValue = static_cast(args).d_targetValue; +} + +bool freeFunctionSubscriberNoArgs() +{ + g_GlobalEventValue = 12; + + return true; +} + +void freeFunctionSubscriberVoidNoArgs() +{ + g_GlobalEventValue = 13; +} + +bool freeFunctionSubscriberOtherArgs(const CEGUI::EventArgs&, const int arg) +{ + g_GlobalEventValue = arg; + + return true; +} + +void freeFunctionSubscriberFirstOtherArgs(const int arg, const CEGUI::EventArgs&) +{ + g_GlobalEventValue = arg; +} + +bool freeFunctionSubscriberJustOtherArgs(const int arg) +{ + g_GlobalEventValue = arg; + + return true; +} + class FunctorSubscriber { public: @@ -89,6 +132,75 @@ class FunctorSubscriber } }; +class FunctorSubscriberConst +{ +public: + bool operator()(const CEGUI::EventArgs& args) const + { + g_GlobalEventValue = static_cast(args).d_targetValue; + + return true; + } +}; + +class FunctorSubscriberVoid +{ +public: + void operator()(const CEGUI::EventArgs& args) + { + g_GlobalEventValue = static_cast(args).d_targetValue; + } +}; + +class FunctorSubscriberVoidConst +{ +public: + void operator()(const CEGUI::EventArgs& args) const + { + g_GlobalEventValue = static_cast(args).d_targetValue; + } +}; + +class FunctorSubscriberNoArgs +{ +public: + bool operator()() + { + g_GlobalEventValue = 24; + + return true; + } +}; + +class FunctorSubscriberNoArgsConst +{ +public: + bool operator()() const + { + g_GlobalEventValue = 25; + + return true; + } +}; + +class FunctorSubscriberVoidNoArgs +{ +public: + void operator()() + { + g_GlobalEventValue = 26; + } +}; + +class FunctorSubscriberVoidNoArgsConst +{ +public: + void operator()() const + { + g_GlobalEventValue = 27; + } +}; + class MemberMethodSubscriber { public: @@ -98,6 +210,25 @@ class MemberMethodSubscriber return true; } + + void memberMethodVoid(const CEGUI::EventArgs& args) + { + g_GlobalEventValue = static_cast(args).d_targetValue; + } + + // always sets the value to 32 + bool memberMethodNoArgs() + { + g_GlobalEventValue = 32; + + return true; + } + + // always sets the value to 33 + void memberMethodVoidNoArgs() + { + g_GlobalEventValue = 33; + } }; BOOST_AUTO_TEST_CASE(Subscribing) @@ -112,25 +243,208 @@ BOOST_AUTO_TEST_CASE(Subscribing) { CEGUI::Event::Connection connection = set.subscribeEvent(eventName, &freeFunctionSubscriber); - args.d_targetValue = 1; + args.d_targetValue = 10; set.fireEvent(eventName, args); - BOOST_CHECK_EQUAL(g_GlobalEventValue, 1); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 10); connection->disconnect(); } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, &freeFunctionSubscriberVoid); + args.d_targetValue = 11; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 11); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, &freeFunctionSubscriberNoArgs); + args.d_targetValue = 12; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 12); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, &freeFunctionSubscriberVoidNoArgs); + args.d_targetValue = 13; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 13); + connection->disconnect(); + } + // C++11 only! +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, std::bind(&freeFunctionSubscriberOtherArgs, std::placeholders::_1, 14)); + args.d_targetValue = 14; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 14); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, std::bind(&freeFunctionSubscriberFirstOtherArgs, 15, std::placeholders::_1)); + args.d_targetValue = 15; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 15); + connection->disconnect(); + } + { + // TODO: why do we need to tell std::bind about the return type when boost::bind can figure it out? + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, std::bind(&freeFunctionSubscriberJustOtherArgs, 16)); + args.d_targetValue = 16; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 16); + connection->disconnect(); + } +# endif + +# ifdef CEGUI_TEST_BOOST_BIND + // broken on g++ 5.1.1 +# ifndef __GNUC__ + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, boost::bind(&freeFunctionSubscriberOtherArgs, _1, 17)); + args.d_targetValue = 17; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 17); + connection->disconnect(); + } +# endif + // broken on g++ 5.1.1 +# ifndef __GNUC__ + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, boost::bind(&freeFunctionSubscriberFirstOtherArgs, 18, _1)); + args.d_targetValue = 18; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 18); + connection->disconnect(); + } +# endif + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, boost::bind(&freeFunctionSubscriberJustOtherArgs, 19)); + args.d_targetValue = 19; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 19); + connection->disconnect(); + } +# endif + { CEGUI::Event::Connection connection = set.subscribeEvent(eventName, FunctorSubscriber()); - args.d_targetValue = 2; + args.d_targetValue = 20; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 20); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, FunctorSubscriberConst()); + args.d_targetValue = 21; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 21); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, FunctorSubscriberVoid()); + args.d_targetValue = 22; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 22); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, FunctorSubscriberVoidConst()); + args.d_targetValue = 23; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 23); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, FunctorSubscriberNoArgs()); + args.d_targetValue = 24; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 24); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, FunctorSubscriberNoArgsConst()); + args.d_targetValue = 25; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 25); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, FunctorSubscriberVoidNoArgs()); + args.d_targetValue = 26; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 26); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, FunctorSubscriberVoidNoArgsConst()); + args.d_targetValue = 27; set.fireEvent(eventName, args); - BOOST_CHECK_EQUAL(g_GlobalEventValue, 2); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 27); connection->disconnect(); } + { MemberMethodSubscriber instance; CEGUI::Event::Connection connection = set.subscribeEvent(eventName, &MemberMethodSubscriber::memberMethod, &instance); - args.d_targetValue = 3; + args.d_targetValue = 30; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 30); + connection->disconnect(); + } + { + MemberMethodSubscriber instance; + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, &MemberMethodSubscriber::memberMethodVoid, &instance); + args.d_targetValue = 31; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 31); + connection->disconnect(); + } + { + MemberMethodSubscriber instance; + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, &MemberMethodSubscriber::memberMethodNoArgs, &instance); + args.d_targetValue = 32; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 32); + connection->disconnect(); + } + { + MemberMethodSubscriber instance; + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, &MemberMethodSubscriber::memberMethodVoidNoArgs, &instance); + args.d_targetValue = 33; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 33); + connection->disconnect(); + } + + // C++11 only! +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, [](const CEGUI::EventArgs&) { g_GlobalEventValue = 40; return true; }); + args.d_targetValue = 40; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 40); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, [](const CEGUI::EventArgs&) { g_GlobalEventValue = 41; }); + args.d_targetValue = 41; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 41); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, []() { g_GlobalEventValue = 42; return true; }); + args.d_targetValue = 42; + set.fireEvent(eventName, args); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 42); + connection->disconnect(); + } + { + CEGUI::Event::Connection connection = set.subscribeEvent(eventName, []() { g_GlobalEventValue = 43; }); + args.d_targetValue = 43; set.fireEvent(eventName, args); - BOOST_CHECK_EQUAL(g_GlobalEventValue, 3); + BOOST_CHECK_EQUAL(g_GlobalEventValue, 43); connection->disconnect(); } +#endif } BOOST_AUTO_TEST_SUITE_END()