diff --git a/.hgeol b/.hgeol index e13b08ced..c7a59fec5 100644 --- a/.hgeol +++ b/.hgeol @@ -1,6 +1,9 @@ [patterns] **.h = native **.cpp = native + +**/database.xml = BIN +**/msg.xml = BIN **.txt = native **.xml = native diff --git a/.hgignore b/.hgignore index 6f730f76e..f4de35608 100644 --- a/.hgignore +++ b/.hgignore @@ -146,6 +146,7 @@ external_stlport .svn thumbs.db Thumbs.db +*.tpl.php # build code/nel/build/* @@ -198,6 +199,16 @@ code/nel/tools/pacs/build_rbank/build_rbank code/ryzom/common/data_leveldesign/leveldesign/game_element/xp_table/skills.skill_tree code/ryzom/common/data_leveldesign/leveldesign/game_element/xp_table/xptable.xp_table code/ryzom/tools/server/sql/ryzom_admin_default_data.sql +code/ryzom/tools/server/ryzom_ams/drupal +code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ams_lib/autoload +code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ams_lib/configs +code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ams_lib/cron +code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ams_lib/img +code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ams_lib/plugins +code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ams_lib/smarty +code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ams_lib/translations +code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ams_lib/libinclude.php +code/ryzom/tools/server/ryzom_ams/www/html/templates_c # Linux server compile code/ryzom/server/src/entities_game_service/entities_game_service @@ -209,5 +220,9 @@ code/ryzom/server/src/ryzom_admin_service/ryzom_admin_service code/ryzom/server/src/ryzom_naming_service/ryzom_naming_service code/ryzom/server/src/ryzom_welcome_service/ryzom_welcome_service code/ryzom/server/src/tick_service/tick_service -# WebTT temp dir +# WebTT temp dir code/ryzom/tools/server/www/webtt/app/tmp +code\ryzom\tools\server\ryzom_ams\old + +# AMS ignore +code/ryzom/tools/server/ryzom_ams/www/config.php diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 8cf86ecc2..926d28345 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -2,7 +2,7 @@ # # NeL # Authors: Nevrax and the NeL Community -# Version: 0.8.0 +# Version: 0.9.0 # # Notes: # * Changing install location: add -DCMAKE_INSTALL_PREFIX:PATH=/my/new/path @@ -41,10 +41,15 @@ INCLUDE(${CMAKE_ROOT}/Modules/Documentation.cmake OPTIONAL) # Force out of source builds. CHECK_OUT_OF_SOURCE() +# Specify Mac OS X deployment target before including Darwin.cmake +IF(NOT CMAKE_OSX_DEPLOYMENT_TARGET) + SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.6") +ENDIF(NOT CMAKE_OSX_DEPLOYMENT_TARGET) + CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(RyzomCore CXX C) SET(NL_VERSION_MAJOR 0) -SET(NL_VERSION_MINOR 8) +SET(NL_VERSION_MINOR 9) SET(NL_VERSION_PATCH 0) SET(NL_VERSION "${NL_VERSION_MAJOR}.${NL_VERSION_MINOR}.${NL_VERSION_PATCH}") @@ -101,14 +106,16 @@ IF(WIN32) ENDIF(WITH_MFC) ENDIF(WIN32) -FIND_PACKAGE(Threads REQUIRED) FIND_PACKAGE(LibXml2 REQUIRED) FIND_PACKAGE(PNG REQUIRED) FIND_PACKAGE(Jpeg) +IF(WITH_STATIC_LIBXML2) + SET(LIBXML2_DEFINITIONS ${LIBXML2_DEFINITIONS} -DLIBXML_STATIC) +ENDIF(WITH_STATIC_LIBXML2) + IF(WITH_STATIC) # libxml2 could need winsock2 library - SET(LIBXML2_DEFINITIONS ${LIBXML2_DEFINITIONS} -DLIBXML_STATIC) SET(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} ${WINSOCK2_LIB}) # on Mac OS X libxml2 requires iconv and liblzma @@ -127,7 +134,7 @@ IF(FINAL_VERSION) ENDIF(FINAL_VERSION) IF(WITH_QT) - FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtXml REQUIRED) + FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtXml QtOpenGL REQUIRED) ENDIF(WITH_QT) IF(WITH_NEL) @@ -135,6 +142,35 @@ IF(WITH_NEL) FIND_PACKAGE(CppTest) ENDIF(WITH_NEL_TESTS) + IF(WITH_GUI) + FIND_PACKAGE(Libwww REQUIRED) + FIND_PACKAGE(Luabind REQUIRED) + FIND_PACKAGE(CURL REQUIRED) + + IF(WIN32 OR CURL_LIBRARIES MATCHES "\\.a") + SET(CURL_STATIC ON) + ENDIF(WIN32 OR CURL_LIBRARIES MATCHES "\\.a") + + IF(CURL_STATIC) + SET(CURL_DEFINITIONS -DCURL_STATICLIB) + + FIND_PACKAGE(OpenSSL QUIET) + + IF(OPENSSL_FOUND) + SET(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR}) + SET(CURL_LIBRARIES ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES}) + ENDIF(OPENSSL_FOUND) + + # CURL Macports version depends on libidn, libintl and libiconv too + IF(APPLE) + FIND_LIBRARY(IDN_LIBRARY idn) + FIND_LIBRARY(INTL_LIBRARY intl) + + SET(CURL_LIBRARIES ${CURL_LIBRARIES} ${IDN_LIBRARY} ${INTL_LIBRARY}) + ENDIF(APPLE) + ENDIF(CURL_STATIC) + ENDIF(WITH_GUI) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/nel/include ${LIBXML2_INCLUDE_DIR}) ADD_DEFINITIONS(${LIBXML2_DEFINITIONS}) ADD_SUBDIRECTORY(nel) diff --git a/code/CMakeModules/AndroidToolChain.cmake b/code/CMakeModules/AndroidToolChain.cmake new file mode 100644 index 000000000..049c39adf --- /dev/null +++ b/code/CMakeModules/AndroidToolChain.cmake @@ -0,0 +1,149 @@ +IF(DEFINED CMAKE_CROSSCOMPILING) + # subsequent toolchain loading is not really needed + RETURN() +ENDIF() + +# Standard settings +SET(CMAKE_SYSTEM_NAME Linux) +SET(CMAKE_SYSTEM_VERSION 1) # TODO: determine target Linux version +SET(UNIX ON) +SET(LINUX ON) +SET(ANDROID ON) + +IF(NOT NDK_ROOT) + SET(NDK_ROOT $ENV{NDK_ROOT}) + + IF(CMAKE_HOST_WIN32) + FILE(TO_CMAKE_PATH ${NDK_ROOT} NDK_ROOT) + ENDIF(CMAKE_HOST_WIN32) +ENDIF(NOT NDK_ROOT) + +IF(NOT TARGET_CPU) + SET(TARGET_CPU "armv7") +ENDIF(NOT TARGET_CPU) + +IF(TARGET_CPU STREQUAL "armv7") + SET(LIBRARY_ARCHITECTURE "armeabi-v7a") + SET(CMAKE_SYSTEM_PROCESSOR "armv7") + SET(TOOLCHAIN_ARCH "arm") + SET(TOOLCHAIN_PREFIX "arm-linux-androideabi") + SET(TOOLCHAIN_BIN_PREFIX "arm") + SET(MINIMUM_NDK_TARGET 4) +ELSEIF(TARGET_CPU STREQUAL "armv5") + SET(LIBRARY_ARCHITECTURE "armeabi") + SET(CMAKE_SYSTEM_PROCESSOR "armv5") + SET(TOOLCHAIN_ARCH "arm") + SET(TOOLCHAIN_PREFIX "arm-linux-androideabi") + SET(TOOLCHAIN_BIN_PREFIX "arm") + SET(MINIMUM_NDK_TARGET 4) +ELSEIF(TARGET_CPU STREQUAL "x86") + SET(LIBRARY_ARCHITECTURE "x86") + SET(CMAKE_SYSTEM_PROCESSOR "x86") + SET(TOOLCHAIN_ARCH "x86") + SET(TOOLCHAIN_PREFIX "x86") + SET(TOOLCHAIN_BIN_PREFIX "i686") + SET(MINIMUM_NDK_TARGET 9) +ELSEIF(TARGET_CPU STREQUAL "mips") + SET(LIBRARY_ARCHITECTURE "mips") + SET(CMAKE_SYSTEM_PROCESSOR "mips") + SET(TOOLCHAIN_ARCH "mips") + SET(TOOLCHAIN_PREFIX "mipsel-linux-android") + SET(TOOLCHAIN_BIN_PREFIX "mipsel") + SET(MINIMUM_NDK_TARGET 9) +ENDIF(TARGET_CPU STREQUAL "armv7") + +IF(NOT NDK_TARGET) + SET(NDK_TARGET ${MINIMUM_NDK_TARGET}) +ENDIF(NOT NDK_TARGET) + +FILE(GLOB _TOOLCHAIN_VERSIONS "${NDK_ROOT}/toolchains/${TOOLCHAIN_PREFIX}-*") +IF(_TOOLCHAIN_VERSIONS) + LIST(SORT _TOOLCHAIN_VERSIONS) + LIST(REVERSE _TOOLCHAIN_VERSIONS) + FOREACH(_TOOLCHAIN_VERSION ${_TOOLCHAIN_VERSIONS}) + STRING(REGEX REPLACE ".+${TOOLCHAIN_PREFIX}-([0-9.]+)" "\\1" _TOOLCHAIN_VERSION "${_TOOLCHAIN_VERSION}") + IF(_TOOLCHAIN_VERSION MATCHES "^([0-9.]+)$") + LIST(APPEND NDK_TOOLCHAIN_VERSIONS ${_TOOLCHAIN_VERSION}) + ENDIF(_TOOLCHAIN_VERSION MATCHES "^([0-9.]+)$") + ENDFOREACH(_TOOLCHAIN_VERSION) +ENDIF(_TOOLCHAIN_VERSIONS) + +IF(NOT NDK_TOOLCHAIN_VERSIONS) + MESSAGE(FATAL_ERROR "No Android toolchain found in default search path ${NDK_ROOT}/toolchains") +ENDIF(NOT NDK_TOOLCHAIN_VERSIONS) + +IF(NDK_TOOLCHAIN_VERSION) + LIST(FIND NDK_TOOLCHAIN_VERSIONS "${NDK_TOOLCHAIN_VERSION}" _INDEX) + IF(_INDEX EQUAL -1) + LIST(GET NDK_TOOLCHAIN_VERSIONS 0 NDK_TOOLCHAIN_VERSION) + ENDIF(_INDEX EQUAL -1) +ELSE(NDK_TOOLCHAIN_VERSION) + LIST(GET NDK_TOOLCHAIN_VERSIONS 0 NDK_TOOLCHAIN_VERSION) +ENDIF(NDK_TOOLCHAIN_VERSION) + +MESSAGE(STATUS "Target Android NDK ${NDK_TARGET} and use GCC ${NDK_TOOLCHAIN_VERSION}") + +IF(CMAKE_HOST_WIN32) + SET(TOOLCHAIN_HOST "windows") + SET(TOOLCHAIN_BIN_SUFFIX ".exe") +ELSEIF(CMAKE_HOST_APPLE) + SET(TOOLCHAIN_HOST "apple") + SET(TOOLCHAIN_BIN_SUFFIX "") +ELSEIF(CMAKE_HOST_UNIX) + SET(TOOLCHAIN_HOST "linux") + SET(TOOLCHAIN_BIN_SUFFIX "") +ENDIF(CMAKE_HOST_WIN32) + +SET(TOOLCHAIN_ROOT "${NDK_ROOT}/toolchains/${TOOLCHAIN_PREFIX}-${NDK_TOOLCHAIN_VERSION}/prebuilt/${TOOLCHAIN_HOST}") +SET(PLATFORM_ROOT "${NDK_ROOT}/platforms/android-${NDK_TARGET}/arch-${TOOLCHAIN_ARCH}") + +IF(NOT EXISTS "${TOOLCHAIN_ROOT}") + FILE(GLOB _TOOLCHAIN_PREFIXES "${TOOLCHAIN_ROOT}*") + IF(_TOOLCHAIN_PREFIXES) + LIST(GET _TOOLCHAIN_PREFIXES 0 TOOLCHAIN_ROOT) + ENDIF(_TOOLCHAIN_PREFIXES) +ENDIF(NOT EXISTS "${TOOLCHAIN_ROOT}") + +MESSAGE(STATUS "Found Android toolchain in ${TOOLCHAIN_ROOT}") +MESSAGE(STATUS "Found Android platform in ${PLATFORM_ROOT}") + +# include dirs +SET(PLATFORM_INCLUDE_DIR "${PLATFORM_ROOT}/usr/include") +SET(STL_DIR "${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++") + +IF(EXISTS "${STL_DIR}/${NDK_TOOLCHAIN_VERSION}") + # NDK version >= 8b + SET(STL_DIR "${STL_DIR}/${NDK_TOOLCHAIN_VERSION}") +ENDIF(EXISTS "${STL_DIR}/${NDK_TOOLCHAIN_VERSION}") + +# Determine bin prefix for toolchain +FILE(GLOB _TOOLCHAIN_BIN_PREFIXES "${TOOLCHAIN_ROOT}/bin/${TOOLCHAIN_BIN_PREFIX}-*-gcc${TOOLCHAIN_BIN_SUFFIX}") +IF(_TOOLCHAIN_BIN_PREFIXES) + LIST(GET _TOOLCHAIN_BIN_PREFIXES 0 _TOOLCHAIN_BIN_PREFIX) + STRING(REGEX REPLACE "${TOOLCHAIN_ROOT}/bin/([a-z0-9-]+)-gcc${TOOLCHAIN_BIN_SUFFIX}" "\\1" TOOLCHAIN_BIN_PREFIX "${_TOOLCHAIN_BIN_PREFIX}") +ENDIF(_TOOLCHAIN_BIN_PREFIXES) + +SET(STL_INCLUDE_DIR "${STL_DIR}/include") +SET(STL_LIBRARY_DIR "${STL_DIR}/libs/${LIBRARY_ARCHITECTURE}") +SET(STL_INCLUDE_CPU_DIR "${STL_LIBRARY_DIR}/include") +SET(STL_LIBRARY "${STL_LIBRARY_DIR}/libgnustl_static.a") + +SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_ROOT} ${PLATFORM_ROOT}/usr ${CMAKE_PREFIX_PATH} ${CMAKE_INSTALL_PREFIX} $ENV{EXTERNAL_ANDROID_PATH} CACHE string "Android find search path root") + +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +INCLUDE_DIRECTORIES(${STL_INCLUDE_DIR} ${STL_INCLUDE_CPU_DIR}) + +MACRO(SET_TOOLCHAIN_BINARY _NAME _BINARY) + SET(${_NAME} ${TOOLCHAIN_ROOT}/bin/${TOOLCHAIN_BIN_PREFIX}-${_BINARY}${TOOLCHAIN_BIN_SUFFIX}) +ENDMACRO(SET_TOOLCHAIN_BINARY) + +SET_TOOLCHAIN_BINARY(CMAKE_C_COMPILER gcc) +SET_TOOLCHAIN_BINARY(CMAKE_CXX_COMPILER g++) + +# Force the compilers to GCC for Android +include (CMakeForceCompiler) +CMAKE_FORCE_C_COMPILER(${CMAKE_C_COMPILER} GNU) +CMAKE_FORCE_CXX_COMPILER(${CMAKE_CXX_COMPILER} GNU) diff --git a/code/CMakeModules/FindCustomMFC.cmake b/code/CMakeModules/FindCustomMFC.cmake index 7dd87c15f..6f2f163d3 100644 --- a/code/CMakeModules/FindCustomMFC.cmake +++ b/code/CMakeModules/FindCustomMFC.cmake @@ -4,42 +4,35 @@ # MFC_LIBRARY_DIR, where to find libraries # MFC_INCLUDE_DIR, where to find headers +IF(CustomMFC_FIND_REQUIRED) + SET(MFC_FIND_REQUIRED TRUE) +ENDIF(CustomMFC_FIND_REQUIRED) + # Try to find MFC using official module, MFC_FOUND is set FIND_PACKAGE(MFC) -SET(CUSTOM_MFC_DIR FALSE) +IF(NOT MFC_DIR) + # If MFC have been found, remember their directory + IF(MFC_FOUND AND VC_DIR) + SET(MFC_STANDARD_DIR "${VC_DIR}/atlmfc") + ENDIF(MFC_FOUND AND VC_DIR) -# If using STLport and MFC have been found, remember its directory -IF(WITH_STLPORT AND MFC_FOUND AND VC_DIR) - SET(MFC_STANDARD_DIR "${VC_DIR}/atlmfc") -ENDIF(WITH_STLPORT AND MFC_FOUND AND VC_DIR) - -# If using STLport or MFC haven't been found, search for afxwin.h -IF(WITH_STLPORT OR NOT MFC_FOUND) FIND_PATH(MFC_DIR include/afxwin.h - PATHS + HINTS ${MFC_STANDARD_DIR} ) +ENDIF(NOT MFC_DIR) - IF(CustomMFC_FIND_REQUIRED) - SET(MFC_FIND_REQUIRED TRUE) - ENDIF(CustomMFC_FIND_REQUIRED) +# Display an error message if MFC are not found, MFC_FOUND is updated +# User will be able to update MFC_DIR to the correct directory +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(MFC DEFAULT_MSG MFC_DIR) - # Display an error message if MFC are not found, MFC_FOUND is updated - # User will be able to update MFC_DIR to the correct directory - INCLUDE(FindPackageHandleStandardArgs) - FIND_PACKAGE_HANDLE_STANDARD_ARGS(MFC DEFAULT_MSG MFC_DIR) +IF(MFC_FOUND) + SET(MFC_INCLUDE_DIR "${MFC_DIR}/include") + INCLUDE_DIRECTORIES(${MFC_INCLUDE_DIR}) - IF(MFC_FOUND) - SET(CUSTOM_MFC_DIR TRUE) - SET(MFC_INCLUDE_DIR "${MFC_DIR}/include") - INCLUDE_DIRECTORIES(${MFC_INCLUDE_DIR}) - ENDIF(MFC_FOUND) -ENDIF(WITH_STLPORT OR NOT MFC_FOUND) - -# Only if using a custom path -IF(CUSTOM_MFC_DIR) # Using 32 or 64 bits libraries IF(TARGET_X64) SET(MFC_LIBRARY_DIR "${MFC_DIR}/lib/amd64") @@ -49,9 +42,7 @@ IF(CUSTOM_MFC_DIR) # Add MFC libraries directory to default library path LINK_DIRECTORIES(${MFC_LIBRARY_DIR}) -ENDIF(CUSTOM_MFC_DIR) -IF(MFC_FOUND) # Set definitions for using MFC in DLL SET(MFC_DEFINITIONS -D_AFXDLL) ENDIF(MFC_FOUND) diff --git a/code/CMakeModules/FindDInput.cmake b/code/CMakeModules/FindDInput.cmake deleted file mode 100644 index 100650652..000000000 --- a/code/CMakeModules/FindDInput.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# - Find DirectInput -# Find the DirectSound includes and libraries -# -# DINPUT_INCLUDE_DIR - where to find dinput.h -# DINPUT_LIBRARIES - List of libraries when using DirectInput. -# DINPUT_FOUND - True if DirectInput found. - -if(DINPUT_INCLUDE_DIR) - # Already in cache, be silent - set(DINPUT_FIND_QUIETLY TRUE) -endif(DINPUT_INCLUDE_DIR) - -find_path(DINPUT_INCLUDE_DIR dinput.h - "$ENV{DXSDK_DIR}" - "$ENV{DXSDK_DIR}/Include" -) - -find_library(DINPUT_LIBRARY - NAMES dinput dinput8 - PATHS - "$ENV{DXSDK_DIR}" - "$ENV{DXSDK_DIR}/Lib" - "$ENV{DXSDK_DIR}/Lib/x86" -) - -# Handle the QUIETLY and REQUIRED arguments and set DINPUT_FOUND to TRUE if -# all listed variables are TRUE. -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(DINPUT DEFAULT_MSG - DINPUT_INCLUDE_DIR DINPUT_LIBRARY) - -if(DINPUT_FOUND) - set(DINPUT_LIBRARIES ${DINPUT_LIBRARY}) -else(DINPUT_FOUND) - set(DINPUT_LIBRARIES) -endif(DINPUT_FOUND) - -mark_as_advanced(DINPUT_INCLUDE_DIR DINPUT_LIBRARY) diff --git a/code/CMakeModules/FindDirectXSDK.cmake b/code/CMakeModules/FindDirectXSDK.cmake index 9947778db..dc6753a8b 100644 --- a/code/CMakeModules/FindDirectXSDK.cmake +++ b/code/CMakeModules/FindDirectXSDK.cmake @@ -6,8 +6,8 @@ # DXSDK_FOUND - True if MAX SDK found. IF(DXSDK_DIR) - # Already in cache, be silent - SET(DXSDK_FIND_QUIETLY TRUE) + # Already in cache, be silent + SET(DXSDK_FIND_QUIETLY TRUE) ENDIF(DXSDK_DIR) FIND_PATH(DXSDK_DIR @@ -26,10 +26,10 @@ FIND_PATH(DXSDK_DIR MACRO(FIND_DXSDK_LIBRARY MYLIBRARY MYLIBRARYNAME) FIND_LIBRARY(${MYLIBRARY} - NAMES ${MYLIBRARYNAME} - PATHS - "${DXSDK_LIBRARY_DIR}" - ) + NAMES ${MYLIBRARYNAME} + PATHS + "${DXSDK_LIBRARY_DIR}" + ) ENDMACRO(FIND_DXSDK_LIBRARY MYLIBRARY MYLIBRARYNAME) IF(DXSDK_DIR) diff --git a/code/CMakeModules/FindFreeType.cmake b/code/CMakeModules/FindFreeType.cmake index 4f3c84cbe..68a3ccdbd 100644 --- a/code/CMakeModules/FindFreeType.cmake +++ b/code/CMakeModules/FindFreeType.cmake @@ -1,14 +1,13 @@ # - Locate FreeType library # This module defines -# FREETYPE_LIBRARY, the library to link against +# FREETYPE_LIBRARIES, libraries to link against # FREETYPE_FOUND, if false, do not try to link to FREETYPE # FREETYPE_INCLUDE_DIRS, where to find headers. -IF(FREETYPE_LIBRARY AND FREETYPE_INCLUDE_DIRS) +IF(FREETYPE_LIBRARIES AND FREETYPE_INCLUDE_DIRS) # in cache already - SET(FREETYPE_FIND_QUIETLY TRUE) -ENDIF(FREETYPE_LIBRARY AND FREETYPE_INCLUDE_DIRS) - + SET(Freetype_FIND_QUIETLY TRUE) +ENDIF(FREETYPE_LIBRARIES AND FREETYPE_INCLUDE_DIRS) FIND_PATH(FREETYPE_INCLUDE_DIRS freetype @@ -40,7 +39,7 @@ IF(FREETYPE_ADDITIONAL_INCLUDE_DIR) SET(FREETYPE_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS} ${FREETYPE_ADDITIONAL_INCLUDE_DIR}) ENDIF(FREETYPE_ADDITIONAL_INCLUDE_DIR) -FIND_LIBRARY(FREETYPE_LIBRARY +FIND_LIBRARY(FREETYPE_LIBRARY_RELEASE NAMES freetype libfreetype freetype219 freetype246 PATHS $ENV{FREETYPE_DIR}/lib @@ -53,22 +52,54 @@ FIND_LIBRARY(FREETYPE_LIBRARY /opt/csw/lib /opt/lib /usr/freeware/lib64 + /usr/lib/x86_64-linux-gnu ) -IF(FREETYPE_LIBRARY AND FREETYPE_INCLUDE_DIRS) - SET(FREETYPE_FOUND "YES") +FIND_LIBRARY(FREETYPE_LIBRARY_DEBUG + NAMES freetyped libfreetyped freetype219d freetype246d + PATHS + $ENV{FREETYPE_DIR}/lib + /usr/local/lib + /usr/lib + /usr/local/X11R6/lib + /usr/X11R6/lib + /sw/lib + /opt/local/lib + /opt/csw/lib + /opt/lib + /usr/freeware/lib64 + /usr/lib/x86_64-linux-gnu +) + +IF(FREETYPE_INCLUDE_DIRS) + IF(FREETYPE_LIBRARY_RELEASE AND FREETYPE_LIBRARY_DEBUG) + # Case where both Release and Debug versions are provided + SET(FREETYPE_FOUND ON) + SET(FREETYPE_LIBRARIES optimized ${FREETYPE_LIBRARY_RELEASE} debug ${FREETYPE_LIBRARY_DEBUG}) + ELSEIF(FREETYPE_LIBRARY_RELEASE) + # Normal case + SET(FREETYPE_FOUND ON) + SET(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY_RELEASE}) + ELSEIF(FREETYPE_LIBRARY_DEBUG) + # Case where Freetype is compiled from sources (debug version is compiled by default) + SET(FREETYPE_FOUND ON) + SET(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY_DEBUG}) + ENDIF(FREETYPE_LIBRARY_RELEASE AND FREETYPE_LIBRARY_DEBUG) +ENDIF(FREETYPE_INCLUDE_DIRS) + +IF(FREETYPE_FOUND) IF(WITH_STATIC_EXTERNAL AND APPLE) FIND_PACKAGE(BZip2) IF(BZIP2_FOUND) SET(FREETYPE_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS} ${BZIP2_INCLUDE_DIR}) - SET(FREETYPE_LIBRARY ${FREETYPE_LIBRARY} ${BZIP2_LIBRARIES}) + SET(FREETYPE_LIBRARIES ${FREETYPE_LIBRARIES} ${BZIP2_LIBRARIES}) ENDIF(BZIP2_FOUND) ENDIF(WITH_STATIC_EXTERNAL AND APPLE) - IF(NOT FREETYPE_FIND_QUIETLY) - MESSAGE(STATUS "Found FreeType: ${FREETYPE_LIBRARY}") - ENDIF(NOT FREETYPE_FIND_QUIETLY) + IF(NOT Freetype_FIND_QUIETLY) + MESSAGE(STATUS "Found FreeType: ${FREETYPE_LIBRARIES}") + ENDIF(NOT Freetype_FIND_QUIETLY) ELSE(FREETYPE_LIBRARY AND FREETYPE_INCLUDE_DIRS) - IF(NOT FREETYPE_FIND_QUIETLY) + IF(NOT Freetype_FIND_QUIETLY) MESSAGE(STATUS "Warning: Unable to find FreeType!") - ENDIF(NOT FREETYPE_FIND_QUIETLY) -ENDIF(FREETYPE_LIBRARY AND FREETYPE_INCLUDE_DIRS) + ENDIF(NOT Freetype_FIND_QUIETLY) +ENDIF(FREETYPE_FOUND) diff --git a/code/CMakeModules/FindLibOVR.cmake b/code/CMakeModules/FindLibOVR.cmake new file mode 100644 index 000000000..1403a4b2c --- /dev/null +++ b/code/CMakeModules/FindLibOVR.cmake @@ -0,0 +1,70 @@ +# - Locate LibOVR library +# This module defines +# LIBOVR_LIBRARIES, the libraries to link against +# LIBOVR_FOUND, if false, do not try to link to LIBOVR +# LIBOVR_INCLUDE_DIR, where to find headers. + +IF(LIBOVR_LIBRARIES AND LIBOVR_INCLUDE_DIR) + # in cache already + SET(LIBOVR_FIND_QUIETLY TRUE) +ENDIF(LIBOVR_LIBRARIES AND LIBOVR_INCLUDE_DIR) + +FIND_PATH(LIBOVR_INCLUDE_DIR + OVR.h + PATHS + $ENV{LIBOVR_DIR}/Include + /usr/local/include + /usr/include + /sw/include + /opt/local/include + /opt/csw/include + /opt/include +) + +IF(UNIX) + IF(TARGET_X64) + SET(LIBOVR_LIBRARY_BUILD_PATH "Lib/Linux/Release/x86_64") + ELSE(TARGET_X64) + SET(LIBOVR_LIBRARY_BUILD_PATH "Lib/Linux/Release/i386") + ENDIF(TARGET_X64) +ELSEIF(APPLE) + SET(LIBOVR_LIBRARY_BUILD_PATH "Lib/MacOS/Release") +ELSEIF(WIN32) + IF(TARGET_X64) + SET(LIBOVR_LIBRARY_BUILD_PATH "Lib/x64") + ELSE(TARGET_X64) + SET(LIBOVR_LIBRARY_BUILD_PATH "Lib/Win32") + ENDIF(TARGET_X64) +ENDIF(UNIX) + +FIND_LIBRARY(LIBOVR_LIBRARY + NAMES ovr + PATHS + $ENV{LIBOVR_DIR}/${LIBOVR_LIBRARY_BUILD_PATH} + /usr/local/lib + /usr/lib + /usr/local/X11R6/lib + /usr/X11R6/lib + /sw/lib + /opt/local/lib + /opt/csw/lib + /opt/lib + /usr/freeware/lib64 +) + +IF(LIBOVR_LIBRARY AND LIBOVR_INCLUDE_DIR) + IF(NOT LIBOVR_FIND_QUIETLY) + MESSAGE(STATUS "Found LibOVR: ${LIBOVR_LIBRARY}") + ENDIF(NOT LIBOVR_FIND_QUIETLY) + SET(LIBOVR_FOUND "YES") + SET(LIBOVR_DEFINITIONS "-DHAVE_LIBOVR") + IF(UNIX) + SET(LIBOVR_LIBRARIES ${LIBOVR_LIBRARY} X11 Xinerama udev pthread) + ELSE(UNIX) + SET(LIBOVR_LIBRARIES ${LIBOVR_LIBRARY}) + ENDIF(UNIX) +ELSE(LIBOVR_LIBRARY AND LIBOVR_INCLUDE_DIR) + IF(NOT LIBOVR_FIND_QUIETLY) + MESSAGE(STATUS "Warning: Unable to find LibOVR!") + ENDIF(NOT LIBOVR_FIND_QUIETLY) +ENDIF(LIBOVR_LIBRARY AND LIBOVR_INCLUDE_DIR) diff --git a/code/CMakeModules/FindLibVR.cmake b/code/CMakeModules/FindLibVR.cmake new file mode 100644 index 000000000..eba9c347e --- /dev/null +++ b/code/CMakeModules/FindLibVR.cmake @@ -0,0 +1,32 @@ +# - Locate LibVR library +# This module defines +# LIBVR_LIBRARIES, the libraries to link against +# LIBVR_FOUND, if false, do not try to link to LIBVR +# LIBVR_INCLUDE_DIR, where to find headers. + +IF(LIBVR_LIBRARIES AND LIBVR_INCLUDE_DIR) + # in cache already + SET(LIBVR_FIND_QUIETLY TRUE) +ENDIF(LIBVR_LIBRARIES AND LIBVR_INCLUDE_DIR) + +FIND_PATH(LIBVR_INCLUDE_DIR hmd.h + PATH_SUFFIXES include/LibVR +) + +FIND_LIBRARY(LIBVR_LIBRARY + NAMES vr + PATH_SUFFIXES lib + PATHS +) + +IF(LIBVR_LIBRARY AND LIBVR_INCLUDE_DIR) + IF(NOT LIBVR_FIND_QUIETLY) + MESSAGE(STATUS "Found LibVR: ${LIBVR_LIBRARY}") + ENDIF(NOT LIBVR_FIND_QUIETLY) + SET(LIBVR_FOUND "YES") + SET(LIBVR_DEFINITIONS "-DHAVE_LIBVR") +ELSE(LIBVR_LIBRARY AND LIBVR_INCLUDE_DIR) + IF(NOT LIBVR_FIND_QUIETLY) + MESSAGE(STATUS "Warning: Unable to find LibVR!") + ENDIF(NOT LIBVR_FIND_QUIETLY) +ENDIF(LIBVR_LIBRARY AND LIBVR_INCLUDE_DIR) diff --git a/code/CMakeModules/FindLibwww.cmake b/code/CMakeModules/FindLibwww.cmake index 77140492e..e742c6ae5 100644 --- a/code/CMakeModules/FindLibwww.cmake +++ b/code/CMakeModules/FindLibwww.cmake @@ -3,17 +3,15 @@ # # This module defines # LIBWWW_INCLUDE_DIR, where to find tiff.h, etc. -# LIBWWW_LIBRARY, where to find the LibWWW library. -# LIBWWW_FOUND, If false, do not try to use LibWWW. +# LIBWWW_LIBRARY, where to find the Libwww library. +# LIBWWW_FOUND, If false, do not try to use Libwww. OPTION(WITH_LIBWWW_STATIC "Use only static libraries for libwww" OFF) -SET(LIBWWW_FIND_QUIETLY ${Libwww_FIND_QUIETLY}) - # also defined, but not for general use are IF(LIBWWW_LIBRARIES AND LIBWWW_INCLUDE_DIR) # in cache already - SET(LIBWWW_FIND_QUIETLY TRUE) + SET(Libwww_FIND_QUIETLY TRUE) ENDIF(LIBWWW_LIBRARIES AND LIBWWW_INCLUDE_DIR) FIND_PATH(LIBWWW_INCLUDE_DIR @@ -47,17 +45,33 @@ IF(LIBWWW_ADDITIONAL_INCLUDE_DIR) ENDIF(LIBWWW_ADDITIONAL_INCLUDE_DIR) # helper to find all the libwww sub libraries -MACRO(FIND_WWW_LIBRARY MYLIBRARY OPTION) +MACRO(FIND_WWW_LIBRARY MYLIBRARY OPTION FILE) IF(WITH_LIBWWW_STATIC AND UNIX AND NOT APPLE AND NOT WITH_STATIC_EXTERNAL) SET(CMAKE_FIND_LIBRARY_SUFFIXES_OLD ${CMAKE_FIND_LIBRARY_SUFFIXES}) SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") ENDIF(WITH_LIBWWW_STATIC AND UNIX AND NOT APPLE AND NOT WITH_STATIC_EXTERNAL) - FIND_LIBRARY(${MYLIBRARY} - NAMES ${ARGN} + FIND_LIBRARY(${MYLIBRARY}_RELEASE + NAMES ${FILE} PATHS /usr/local/lib /usr/lib + /usr/lib/x86_64-linux-gnu + /usr/local/X11R6/lib + /usr/X11R6/lib + /sw/lib + /opt/local/lib + /opt/csw/lib + /opt/lib + /usr/freeware/lib64 + ) + + FIND_LIBRARY(${MYLIBRARY}_DEBUG + NAMES ${FILE}d + PATHS + /usr/local/lib + /usr/lib + /usr/lib/x86_64-linux-gnu /usr/local/X11R6/lib /usr/X11R6/lib /sw/lib @@ -71,17 +85,25 @@ MACRO(FIND_WWW_LIBRARY MYLIBRARY OPTION) SET(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_OLD}) ENDIF(CMAKE_FIND_LIBRARY_SUFFIXES_OLD) - IF(${MYLIBRARY}) + IF(${MYLIBRARY}_RELEASE AND ${MYLIBRARY}_DEBUG) IF(${OPTION} STREQUAL REQUIRED OR WITH_STATIC OR WITH_LIBWWW_STATIC) - SET(LIBWWW_LIBRARIES ${LIBWWW_LIBRARIES} ${${MYLIBRARY}}) + SET(LIBWWW_LIBRARIES ${LIBWWW_LIBRARIES} optimized ${${MYLIBRARY}_RELEASE} debug ${${MYLIBRARY}_DEBUG}) ENDIF(${OPTION} STREQUAL REQUIRED OR WITH_STATIC OR WITH_LIBWWW_STATIC) - ELSE(${MYLIBRARY}) - IF(NOT LIBWWW_FIND_QUIETLY AND NOT WIN32) + ELSEIF(${MYLIBRARY}_RELEASE) + IF(${OPTION} STREQUAL REQUIRED OR WITH_STATIC OR WITH_LIBWWW_STATIC) + SET(LIBWWW_LIBRARIES ${LIBWWW_LIBRARIES} ${${MYLIBRARY}_RELEASE}) + ENDIF(${OPTION} STREQUAL REQUIRED OR WITH_STATIC OR WITH_LIBWWW_STATIC) + ELSEIF(${MYLIBRARY}_DEBUG) + IF(${OPTION} STREQUAL REQUIRED OR WITH_STATIC OR WITH_LIBWWW_STATIC) + SET(LIBWWW_LIBRARIES ${LIBWWW_LIBRARIES} ${${MYLIBRARY}_DEBUG}) + ENDIF(${OPTION} STREQUAL REQUIRED OR WITH_STATIC OR WITH_LIBWWW_STATIC) + ELSE(${MYLIBRARY}_RELEASE AND ${MYLIBRARY}_DEBUG) + IF(NOT Libwww_FIND_QUIETLY AND NOT WIN32) MESSAGE(STATUS "Warning: Libwww: Library not found: ${MYLIBRARY}") - ENDIF(NOT LIBWWW_FIND_QUIETLY AND NOT WIN32) - ENDIF(${MYLIBRARY}) + ENDIF(NOT Libwww_FIND_QUIETLY AND NOT WIN32) + ENDIF(${MYLIBRARY}_RELEASE AND ${MYLIBRARY}_DEBUG) - MARK_AS_ADVANCED(${MYLIBRARY}) + MARK_AS_ADVANCED(${MYLIBRARY}_RELEASE ${MYLIBRARY}_DEBUG) ENDMACRO(FIND_WWW_LIBRARY) MACRO(LINK_WWW_LIBRARY MYLIBRARY OTHERLIBRARY SYMBOL) @@ -162,7 +184,7 @@ LINK_WWW_LIBRARY(LIBWWWAPP_LIBRARY LIBREGEX_LIBRARY regexec) LINK_WWW_LIBRARY(LIBWWWAPP_LIBRARY OPENSSL_LIBRARIES SSL_new) INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibWWW DEFAULT_MSG +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Libwww DEFAULT_MSG LIBWWW_LIBRARIES LIBWWW_INCLUDE_DIR ) diff --git a/code/CMakeModules/FindLua52.cmake b/code/CMakeModules/FindLua52.cmake new file mode 100644 index 000000000..0c25ea840 --- /dev/null +++ b/code/CMakeModules/FindLua52.cmake @@ -0,0 +1,81 @@ +# Locate Lua library +# This module defines +# LUA52_FOUND, if false, do not try to link to Lua +# LUA_LIBRARIES +# LUA_INCLUDE_DIR, where to find lua.h +# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) +# +# Note that the expected include convention is +# #include "lua.h" +# and not +# #include +# This is because, the lua location is not standardized and may exist +# in locations other than lua/ + +#============================================================================= +# Copyright 2007-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.) + +find_path(LUA_INCLUDE_DIR lua.h + HINTS + ENV LUA_DIR + PATH_SUFFIXES include/lua52 include/lua5.2 include/lua-5.2 include/lua include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +find_library(LUA_LIBRARY + NAMES lua52 lua5.2 lua-5.2 lua + HINTS + ENV LUA_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw + /opt/local + /opt/csw + /opt +) + +if(LUA_LIBRARY) + # include the math library for Unix + if(UNIX AND NOT APPLE AND NOT BEOS) + find_library(LUA_MATH_LIBRARY m) + set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") + # For Windows and Mac, don't need to explicitly include the math library + else() + set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") + endif() +endif() + +if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") + file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") + + string(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") + unset(lua_version_str) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua52 + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) + +mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY) + diff --git a/code/CMakeModules/FindLuabind.cmake b/code/CMakeModules/FindLuabind.cmake index c94a61e30..f61885be8 100644 --- a/code/CMakeModules/FindLuabind.cmake +++ b/code/CMakeModules/FindLuabind.cmake @@ -4,6 +4,48 @@ # LUABIND_FOUND, if false, do not try to link to LUABIND # LUABIND_INCLUDE_DIR, where to find headers. +MACRO(FIND_CORRECT_LUA_VERSION) + # Check Lua version linked to Luabind under Linux + IF(LUABIND_LIBRARY_RELEASE MATCHES "\\.so") + INCLUDE(CheckDepends) + + SET(LUA52_LIBRARY "liblua5.2") + CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE LUA52_LIBRARY LUALIB_FOUND) + + IF(LUALIB_FOUND) + MESSAGE(STATUS "Luabind is using Lua 5.2") + FIND_PACKAGE(Lua52 REQUIRED) + ELSE(LUALIB_FOUND) + SET(LUA51_LIBRARY "liblua5.1") + CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE LUA51_LIBRARY LUALIB_FOUND) + + IF(LUALIB_FOUND) + MESSAGE(STATUS "Luabind is using Lua 5.1") + FIND_PACKAGE(Lua51 REQUIRED) + ELSE(LUALIB_FOUND) + SET(LUA50_LIBRARY "liblua5.0") + CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE LUA50_LIBRARY LUALIB_FOUND) + + IF(LUALIB_FOUND) + MESSAGE(STATUS "Luabind is using Lua 5.0") + FIND_PACKAGE(Lua50 REQUIRED) + ELSE(LUALIB_FOUND) + MESSAGE(FATAL_ERROR "Can't determine Lua version used by Luabind") + ENDIF(LUALIB_FOUND) + ENDIF(LUALIB_FOUND) + ENDIF(LUALIB_FOUND) + ELSE(LUABIND_LIBRARY_RELEASE MATCHES "\\.so") + # TODO: find a way to detect Lua version + IF(WITH_LUA52) + FIND_PACKAGE(Lua52 REQUIRED) + ELSEIF(WITH_LUA51) + FIND_PACKAGE(Lua51 REQUIRED) + ELSE(WITH_LUA52) + FIND_PACKAGE(Lua50 REQUIRED) + ENDIF(WITH_LUA52) + ENDIF(LUABIND_LIBRARY_RELEASE MATCHES "\\.so") +ENDMACRO(FIND_CORRECT_LUA_VERSION) + IF(LUABIND_LIBRARIES AND LUABIND_INCLUDE_DIR) # in cache already SET(Luabind_FIND_QUIETLY TRUE) @@ -84,6 +126,9 @@ IF(LUABIND_FOUND) IF(LUABIND_VERSION_FILE) SET(LUABIND_DEFINITIONS "-DHAVE_LUABIND_VERSION") ENDIF(LUABIND_VERSION_FILE) + + FIND_CORRECT_LUA_VERSION() + IF(NOT Luabind_FIND_QUIETLY) MESSAGE(STATUS "Found Luabind: ${LUABIND_LIBRARIES}") ENDIF(NOT Luabind_FIND_QUIETLY) diff --git a/code/CMakeModules/FindMSVC.cmake b/code/CMakeModules/FindMSVC.cmake new file mode 100644 index 000000000..16455b02d --- /dev/null +++ b/code/CMakeModules/FindMSVC.cmake @@ -0,0 +1,96 @@ +# - Find MS Visual C++ +# +# VC_INCLUDE_DIR - where to find headers +# VC_INCLUDE_DIRS - where to find headers +# VC_LIBRARY_DIR - where to find libraries +# VC_FOUND - True if MSVC found. + +MACRO(DETECT_VC_VERSION_HELPER _ROOT _VERSION) + # Software/Wow6432Node/... + GET_FILENAME_COMPONENT(VC${_VERSION}_DIR "[${_ROOT}\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VC7;${_VERSION}]" ABSOLUTE) + + IF(VC${_VERSION}_DIR AND VC${_VERSION}_DIR STREQUAL "/registry") + SET(VC${_VERSION}_DIR) + GET_FILENAME_COMPONENT(VC${_VERSION}_DIR "[${_ROOT}\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;${_VERSION}]" ABSOLUTE) + IF(VC${_VERSION}_DIR AND NOT VC${_VERSION}_DIR STREQUAL "/registry") + SET(VC${_VERSION}_DIR "${VC${_VERSION}_DIR}VC/") + ENDIF(VC${_VERSION}_DIR AND NOT VC${_VERSION}_DIR STREQUAL "/registry") + ENDIF(VC${_VERSION}_DIR AND VC${_VERSION}_DIR STREQUAL "/registry") + + IF(VC${_VERSION}_DIR AND NOT VC${_VERSION}_DIR STREQUAL "/registry") + SET(VC${_VERSION}_FOUND ON) + DETECT_EXPRESS_VERSION(${_VERSION}) + IF(NOT MSVC_FIND_QUIETLY) + SET(_VERSION_STR ${_VERSION}) + IF(MSVC_EXPRESS) + SET(_VERSION_STR "${_VERSION_STR} Express") + ENDIF(MSVC_EXPRESS) + MESSAGE(STATUS "Found Visual C++ ${_VERSION_STR} in ${VC${_VERSION}_DIR}") + ENDIF(NOT MSVC_FIND_QUIETLY) + ELSEIF(VC${_VERSION}_DIR AND NOT VC${_VERSION}_DIR STREQUAL "/registry") + SET(VC${_VERSION}_FOUND OFF) + SET(VC${_VERSION}_DIR "") + ENDIF(VC${_VERSION}_DIR AND NOT VC${_VERSION}_DIR STREQUAL "/registry") +ENDMACRO(DETECT_VC_VERSION_HELPER) + +MACRO(DETECT_VC_VERSION _VERSION) + SET(VC${_VERSION}_FOUND OFF) + DETECT_VC_VERSION_HELPER("HKEY_CURRENT_USER" ${_VERSION}) + + IF(NOT VC${_VERSION}_FOUND) + DETECT_VC_VERSION_HELPER("HKEY_LOCAL_MACHINE" ${_VERSION}) + ENDIF(NOT VC${_VERSION}_FOUND) + + IF(VC${_VERSION}_FOUND) + SET(VC_FOUND ON) + SET(VC_DIR "${VC${_VERSION}_DIR}") + ENDIF(VC${_VERSION}_FOUND) +ENDMACRO(DETECT_VC_VERSION) + +MACRO(DETECT_EXPRESS_VERSION _VERSION) + GET_FILENAME_COMPONENT(MSVC_EXPRESS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\${_VERSION}\\Setup\\VC;ProductDir]" ABSOLUTE) + + IF(MSVC_EXPRESS AND NOT MSVC_EXPRESS STREQUAL "/registry") + SET(MSVC_EXPRESS ON) + ENDIF(MSVC_EXPRESS AND NOT MSVC_EXPRESS STREQUAL "/registry") +ENDMACRO(DETECT_EXPRESS_VERSION) + +IF(MSVC12) + DETECT_VC_VERSION("12.0") + + IF(NOT MSVC12_REDIST_DIR) + # If you have VC++ 2013 Express, put x64/Microsoft.VC120.CRT/*.dll in ${EXTERNAL_PATH}/redist + SET(MSVC12_REDIST_DIR "${EXTERNAL_PATH}/redist") + ENDIF(NOT MSVC11_REDIST_DIR) +ELSEIF(MSVC11) + DETECT_VC_VERSION("11.0") + + IF(NOT MSVC11_REDIST_DIR) + # If you have VC++ 2012 Express, put x64/Microsoft.VC110.CRT/*.dll in ${EXTERNAL_PATH}/redist + SET(MSVC11_REDIST_DIR "${EXTERNAL_PATH}/redist") + ENDIF(NOT MSVC11_REDIST_DIR) +ELSEIF(MSVC10) + DETECT_VC_VERSION("10.0") + + IF(NOT MSVC10_REDIST_DIR) + # If you have VC++ 2010 Express, put x64/Microsoft.VC100.CRT/*.dll in ${EXTERNAL_PATH}/redist + SET(MSVC10_REDIST_DIR "${EXTERNAL_PATH}/redist") + ENDIF(NOT MSVC10_REDIST_DIR) +ELSEIF(MSVC90) + DETECT_VC_VERSION("9.0") +ELSEIF(MSVC80) + DETECT_VC_VERSION("8.0") +ENDIF(MSVC12) + +# If you plan to use VC++ compilers with WINE, set VC_DIR environment variable +IF(NOT VC_DIR) + SET(VC_DIR $ENV{VC_DIR}) +ENDIF(NOT VC_DIR) + +IF(NOT VC_DIR) + STRING(REGEX REPLACE "/bin/.+" "" VC_DIR ${CMAKE_CXX_COMPILER}) +ENDIF(NOT VC_DIR) + +SET(VC_INCLUDE_DIR "${VC_DIR}/include") +SET(VC_INCLUDE_DIRS ${VC_INCLUDE_DIR}) +INCLUDE_DIRECTORIES(${VC_INCLUDE_DIR}) diff --git a/code/CMakeModules/FindMercurial.cmake b/code/CMakeModules/FindMercurial.cmake index a18e50c43..dbb2110ff 100644 --- a/code/CMakeModules/FindMercurial.cmake +++ b/code/CMakeModules/FindMercurial.cmake @@ -48,7 +48,12 @@ # License text for the above reference.) FIND_PROGRAM(Mercurial_HG_EXECUTABLE hg - DOC "mercurial command line client") + DOC "mercurial command line client" + PATHS + /opt/local/bin + "C:/Program Files/TortoiseHg" + "C:/Program Files (x86)/TortoiseHg" + ) MARK_AS_ADVANCED(Mercurial_HG_EXECUTABLE) IF(Mercurial_HG_EXECUTABLE) @@ -58,7 +63,7 @@ IF(Mercurial_HG_EXECUTABLE) STRING(REGEX REPLACE ".*version ([\\.0-9]+).*" "\\1" Mercurial_VERSION_HG "${Mercurial_VERSION_HG}") - + MACRO(Mercurial_WC_INFO dir prefix) EXECUTE_PROCESS(COMMAND ${Mercurial_HG_EXECUTABLE} tip --template "{rev};{node};{tags};{author}" WORKING_DIRECTORY ${dir} diff --git a/code/CMakeModules/FindMySQL.cmake b/code/CMakeModules/FindMySQL.cmake index 1da6157fa..eb2102c8d 100644 --- a/code/CMakeModules/FindMySQL.cmake +++ b/code/CMakeModules/FindMySQL.cmake @@ -58,6 +58,8 @@ ELSE(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES) SET(MYSQL_LIBRARIES optimized ${MYSQL_LIBRARY_RELEASE}) IF(MYSQL_LIBRARY_DEBUG) SET(MYSQL_LIBRARIES ${MYSQL_LIBRARIES} debug ${MYSQL_LIBRARY_DEBUG}) + ELSE(MYSQL_LIBRARY_DEBUG) + SET(MYSQL_LIBRARIES ${MYSQL_LIBRARIES} debug ${MYSQL_LIBRARY_RELEASE}) ENDIF(MYSQL_LIBRARY_DEBUG) FIND_PACKAGE(OpenSSL) IF(OPENSSL_FOUND) diff --git a/code/CMakeModules/FindS3TC.cmake b/code/CMakeModules/FindS3TC.cmake deleted file mode 100644 index f4efb8c5e..000000000 --- a/code/CMakeModules/FindS3TC.cmake +++ /dev/null @@ -1,50 +0,0 @@ -# - Locate S3TC library -# This module defines -# S3TC_LIBRARY, the library to link against -# S3TC_FOUND, if false, do not try to link to S3TC -# S3TC_INCLUDE_DIR, where to find headers. - -IF(S3TC_LIBRARY AND S3TC_INCLUDE_DIR) - # in cache already - SET(S3TC_FIND_QUIETLY TRUE) -ENDIF(S3TC_LIBRARY AND S3TC_INCLUDE_DIR) - - -FIND_PATH(S3TC_INCLUDE_DIR - s3_intrf.h - PATHS - $ENV{S3TC_DIR}/include - /usr/local/include - /usr/include - /sw/include - /opt/local/include - /opt/csw/include - /opt/include - PATH_SUFFIXES S3TC -) - -FIND_LIBRARY(S3TC_LIBRARY - NAMES s3tc libs3tc - PATHS - $ENV{S3TC_DIR}/lib - /usr/local/lib - /usr/lib - /usr/local/X11R6/lib - /usr/X11R6/lib - /sw/lib - /opt/local/lib - /opt/csw/lib - /opt/lib - /usr/freeware/lib64 -) - -IF(S3TC_LIBRARY AND S3TC_INCLUDE_DIR) - SET(S3TC_FOUND "YES") - IF(NOT S3TC_FIND_QUIETLY) - MESSAGE(STATUS "Found S3TC: ${S3TC_LIBRARY}") - ENDIF(NOT S3TC_FIND_QUIETLY) -ELSE(S3TC_LIBRARY AND S3TC_INCLUDE_DIR) - IF(NOT S3TC_FIND_QUIETLY) - MESSAGE(STATUS "Warning: Unable to find S3TC!") - ENDIF(NOT S3TC_FIND_QUIETLY) -ENDIF(S3TC_LIBRARY AND S3TC_INCLUDE_DIR) diff --git a/code/CMakeModules/FindWindowsSDK.cmake b/code/CMakeModules/FindWindowsSDK.cmake index 9d9b91777..fd32d92b5 100644 --- a/code/CMakeModules/FindWindowsSDK.cmake +++ b/code/CMakeModules/FindWindowsSDK.cmake @@ -6,80 +6,304 @@ # WINSDK_LIBRARY_DIR - where to find libraries # WINSDK_FOUND - True if Windows SDK found. -IF(WINSDK_INCLUDE_DIR) - # Already in cache, be silent - SET(WindowsSDK_FIND_QUIETLY TRUE) -ENDIF(WINSDK_INCLUDE_DIR) +IF(WINSDK_FOUND) + # If Windows SDK already found, skip it + RETURN() +ENDIF(WINSDK_FOUND) -# TODO: add the possibility to use a specific Windows SDK +# Values can be CURRENT or any existing versions 7.1, 8.0A, etc... +SET(WINSDK_VERSION "CURRENT" CACHE STRING "Windows SDK version to prefer") -IF(MSVC11) - GET_FILENAME_COMPONENT(WINSDK8_DIR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]" ABSOLUTE CACHE) - GET_FILENAME_COMPONENT(WINSDK8_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;ProductVersion]" NAME) +MACRO(DETECT_WINSDK_VERSION_HELPER _ROOT _VERSION) + GET_FILENAME_COMPONENT(WINSDK${_VERSION}_DIR "[${_ROOT}\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v${_VERSION};InstallationFolder]" ABSOLUTE) - IF(WINSDK8_DIR) + IF(WINSDK${_VERSION}_DIR AND NOT WINSDK${_VERSION}_DIR STREQUAL "/registry") + SET(WINSDK${_VERSION}_FOUND ON) + GET_FILENAME_COMPONENT(WINSDK${_VERSION}_VERSION_FULL "[${_ROOT}\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v${_VERSION};ProductVersion]" NAME) IF(NOT WindowsSDK_FIND_QUIETLY) - MESSAGE(STATUS "Found Windows SDK ${WINSDK8_VERSION} in ${WINSDK8_DIR}") + MESSAGE(STATUS "Found Windows SDK ${_VERSION} in ${WINSDK${_VERSION}_DIR}") ENDIF(NOT WindowsSDK_FIND_QUIETLY) - IF(TARGET_ARM) - SET(WINSDK8_SUFFIX "arm") - ELSEIF(TARGET_X64) - SET(WINSDK8_SUFFIX "x64") - ELSEIF(TARGET_X86) - SET(WINSDK8_SUFFIX "x86") - ENDIF(TARGET_ARM) - ENDIF(WINSDK8_DIR) -ENDIF(MSVC11) + ELSE(WINSDK${_VERSION}_DIR AND NOT WINSDK${_VERSION}_DIR STREQUAL "/registry") + SET(WINSDK${_VERSION}_DIR "") + ENDIF(WINSDK${_VERSION}_DIR AND NOT WINSDK${_VERSION}_DIR STREQUAL "/registry") +ENDMACRO(DETECT_WINSDK_VERSION_HELPER) -GET_FILENAME_COMPONENT(WINSDK71_DIR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v7.1;InstallationFolder]" ABSOLUTE CACHE) -GET_FILENAME_COMPONENT(WINSDK71_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v7.1;ProductVersion]" NAME) +MACRO(DETECT_WINSDK_VERSION _VERSION) + SET(WINSDK${_VERSION}_FOUND OFF) + DETECT_WINSDK_VERSION_HELPER("HKEY_CURRENT_USER" ${_VERSION}) -IF(WINSDK71_DIR) - IF(NOT WindowsSDK_FIND_QUIETLY) - MESSAGE(STATUS "Found Windows SDK ${WINSDK71_VERSION} in ${WINSDK71_DIR}") - ENDIF(NOT WindowsSDK_FIND_QUIETLY) -ENDIF(WINSDK71_DIR) + IF(NOT WINSDK${_VERSION}_FOUND) + DETECT_WINSDK_VERSION_HELPER("HKEY_LOCAL_MACHINE" ${_VERSION}) + ENDIF(NOT WINSDK${_VERSION}_FOUND) +ENDMACRO(DETECT_WINSDK_VERSION) -GET_FILENAME_COMPONENT(WINSDKCURRENT_DIR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" ABSOLUTE CACHE) -GET_FILENAME_COMPONENT(WINSDKCURRENT_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentVersion]" NAME) +SET(WINSDK_VERSIONS "8.0" "8.0A" "7.1" "7.1A" "7.0" "7.0A" "6.1" "6.0" "6.0A") +SET(WINSDK_DETECTED_VERSIONS) -IF(WINSDKCURRENT_DIR) - IF(NOT WindowsSDK_FIND_QUIETLY) - MESSAGE(STATUS "Found Windows SDK ${WINSDKCURRENT_VERSION} in ${WINSDKCURRENT_DIR}") - ENDIF(NOT WindowsSDK_FIND_QUIETLY) -ENDIF(WINSDKCURRENT_DIR) +# Search all supported Windows SDKs +FOREACH(_VERSION ${WINSDK_VERSIONS}) + DETECT_WINSDK_VERSION(${_VERSION}) + IF(WINSDK${_VERSION}_FOUND) + LIST(APPEND WINSDK_DETECTED_VERSIONS ${_VERSION}) + ENDIF(WINSDK${_VERSION}_FOUND) +ENDFOREACH(_VERSION) + +SET(WINSDK_SUFFIX) + +IF(TARGET_ARM) + SET(WINSDK8_SUFFIX "arm") +ELSEIF(TARGET_X64) + SET(WINSDK8_SUFFIX "x64") + SET(WINSDK_SUFFIX "x64") +ELSEIF(TARGET_X86) + SET(WINSDK8_SUFFIX "x86") +ENDIF(TARGET_ARM) + +SET(WINSDKCURRENT_VERSION_INCLUDE $ENV{INCLUDE}) + +IF(WINSDKCURRENT_VERSION_INCLUDE) + FILE(TO_CMAKE_PATH "${WINSDKCURRENT_VERSION_INCLUDE}" WINSDKCURRENT_VERSION_INCLUDE) +ENDIF(WINSDKCURRENT_VERSION_INCLUDE) + +SET(WINSDKENV_DIR $ENV{WINSDK_DIR}) + +MACRO(FIND_WINSDK_VERSION_HEADERS) + IF(WINSDK_DIR AND NOT WINSDK_VERSION) + # Search version in headers + IF(EXISTS ${WINSDK_DIR}/include/Msi.h) + SET(_MSI_FILE ${WINSDK_DIR}/include/Msi.h) + ENDIF(EXISTS ${WINSDK_DIR}/include/Msi.h) + + IF(_MSI_FILE) + # Look for Windows SDK 8.0 + FILE(STRINGS ${_MSI_FILE} _CONTENT REGEX "^#ifndef NTDDI_WIN8") + + IF(_CONTENT) + SET(WINSDK_VERSION "8.0") + ENDIF(_CONTENT) + + IF(NOT WINSDK_VERSION) + # Look for Windows SDK 7.0 + FILE(STRINGS ${_MSI_FILE} _CONTENT REGEX "^#ifndef NTDDI_WIN7") + + IF(_CONTENT) + IF(EXISTS ${WINSDK_DIR}/include/winsdkver.h) + SET(_WINSDKVER_FILE ${WINSDK_DIR}/include/winsdkver.h) + ELSEIF(EXISTS ${WINSDK_DIR}/include/WinSDKVer.h) + SET(_WINSDKVER_FILE ${WINSDK_DIR}/include/WinSDKVer.h) + ENDIF(EXISTS ${WINSDK_DIR}/include/winsdkver.h) + + IF(_WINSDKVER_FILE) + # Load WinSDKVer.h content + FILE(STRINGS ${_WINSDKVER_FILE} _CONTENT REGEX "^#define NTDDI_MAXVER") + + # Get NTDDI_MAXVER value + STRING(REGEX REPLACE "^.*0x([0-9A-Fa-f]+).*$" "\\1" _WINSDKVER "${_CONTENT}") + + # In Windows SDK 7.1, NTDDI_MAXVER is wrong + IF(_WINSDKVER STREQUAL "06010000") + SET(WINSDK_VERSION "7.1") + ELSEIF(_WINSDKVER STREQUAL "0601") + SET(WINSDK_VERSION "7.0A") + ELSE(_WINSDKVER STREQUAL "06010000") + MESSAGE(FATAL_ERROR "Can't determine Windows SDK version with NTDDI_MAXVER 0x${_WINSDKVER}") + ENDIF(_WINSDKVER STREQUAL "06010000") + ELSE(_WINSDKVER_FILE) + SET(WINSDK_VERSION "7.0") + ENDIF(_WINSDKVER_FILE) + ENDIF(_CONTENT) + ENDIF(NOT WINSDK_VERSION) + + IF(NOT WINSDK_VERSION) + # Look for Windows SDK 6.0 + FILE(STRINGS ${_MSI_FILE} _CONTENT REGEX "^#ifndef NTDDI_VISTA") + + IF(_CONTENT) + SET(WINSDK_VERSION "6.0") + ENDIF(_CONTENT) + ENDIF(NOT WINSDK_VERSION) + + IF(NOT WINSDK_VERSION) + # Look for Windows SDK 5.2 + FILE(STRINGS ${_MSI_FILE} _CONTENT REGEX "^#ifndef NTDDI_WS03SP1") + + IF(_CONTENT) + SET(WINSDK_VERSION "5.2") + ENDIF(_CONTENT) + ENDIF(NOT WINSDK_VERSION) + + IF(NOT WINSDK_VERSION) + # Look for Windows SDK 5.1 + FILE(STRINGS ${_MSI_FILE} _CONTENT REGEX "^#ifndef NTDDI_WINXP") + + IF(_CONTENT) + SET(WINSDK_VERSION "5.1") + ENDIF(_CONTENT) + ENDIF(NOT WINSDK_VERSION) + + IF(NOT WINSDK_VERSION) + # Look for Windows SDK 5.0 + FILE(STRINGS ${_MSI_FILE} _CONTENT REGEX "^#ifndef NTDDI_WIN2K") + + IF(_CONTENT) + SET(WINSDK_VERSION "5.0") + ENDIF(_CONTENT) + ENDIF(NOT WINSDK_VERSION) + ELSE(_MSI_FILE) + MESSAGE(FATAL_ERROR "Unable to find Msi.h in ${WINSDK_DIR}") + ENDIF(_MSI_FILE) + ENDIF(WINSDK_DIR AND NOT WINSDK_VERSION) +ENDMACRO(FIND_WINSDK_VERSION_HEADERS) + +MACRO(USE_CURRENT_WINSDK) + SET(WINSDK_DIR "") + SET(WINSDK_VERSION "") + SET(WINSDK_VERSION_FULL "") + + # Use WINSDK environment variable + IF(WINSDKENV_DIR AND EXISTS ${WINSDKENV_DIR}/include/Windows.h) + SET(WINSDK_DIR ${WINSDKENV_DIR}) + ENDIF(WINSDKENV_DIR AND EXISTS ${WINSDKENV_DIR}/include/Windows.h) + + # Use INCLUDE environment variable + IF(NOT WINSDK_DIR AND WINSDKCURRENT_VERSION_INCLUDE) + FOREACH(_INCLUDE ${WINSDKCURRENT_VERSION_INCLUDE}) + FILE(TO_CMAKE_PATH ${_INCLUDE} _INCLUDE) + + # Look for Windows.h because there are several paths + IF(EXISTS ${_INCLUDE}/Windows.h) + STRING(REGEX REPLACE "/(include|INCLUDE|Include)" "" WINSDK_DIR ${_INCLUDE}) + MESSAGE(STATUS "Found Windows SDK environment variable in ${WINSDK_DIR}") + BREAK() + ENDIF(EXISTS ${_INCLUDE}/Windows.h) + ENDFOREACH(_INCLUDE) + ENDIF(NOT WINSDK_DIR AND WINSDKCURRENT_VERSION_INCLUDE) + + IF(WINSDK_DIR) + # Compare WINSDK_DIR with registered Windows SDKs + FOREACH(_VERSION ${WINSDK_DETECTED_VERSIONS}) + IF(WINSDK_DIR STREQUAL "${WINSDK${_VERSION}_DIR}") + SET(WINSDK_VERSION ${_VERSION}) + SET(WINSDK_VERSION_FULL "${WINSDK${WINSDK_VERSION}_VERSION_FULL}") + BREAK() + ENDIF(WINSDK_DIR STREQUAL "${WINSDK${_VERSION}_DIR}") + ENDFOREACH(_VERSION) + + FIND_WINSDK_VERSION_HEADERS() + ENDIF(WINSDK_DIR) + + IF(NOT WINSDK_DIR) + # Use Windows SDK versions installed with VC++ when possible + IF(MSVC12) + SET(WINSDK_VERSION "8.1A") + ELSEIF(MSVC11) + SET(WINSDK_VERSION "8.0A") + ELSEIF(MSVC10) + IF(NOT TARGET_X64 OR NOT MSVC_EXPRESS) + SET(WINSDK_VERSION "7.0A") + ENDIF(NOT TARGET_X64 OR NOT MSVC_EXPRESS) + ELSEIF(MSVC90) + IF(NOT MSVC_EXPRESS) + SET(WINSDK_VERSION "6.0A") + ENDIF(NOT MSVC_EXPRESS) + ELSEIF(MSVC80) + IF(NOT MSVC_EXPRESS) + # TODO: fix this version + SET(WINSDK_VERSION "5.2A") + ENDIF(NOT MSVC_EXPRESS) + ELSE(MSVC12) + MESSAGE(FATAL_ERROR "Your compiler is either too old or too recent, please update this CMake module.") + ENDIF(MSVC12) + + # Use installed Windows SDK + IF(NOT WINSDK_VERSION) + IF(WINSDK7.1_FOUND) + SET(WINSDK_VERSION "7.1") + ELSEIF(WINSDK7.0_FOUND) + SET(WINSDK_VERSION "7.0") + ELSEIF(WINSDK6.1_FOUND) + SET(WINSDK_VERSION "6.1") + ELSEIF(WINSDK6.0_FOUND) + SET(WINSDK_VERSION "6.0") + ELSE(WINSDK7.1_FOUND) + MESSAGE(FATAL_ERROR "You have no compatible Windows SDK installed.") + ENDIF(WINSDK7.1_FOUND) + ENDIF(NOT WINSDK_VERSION) + + # Look for correct registered Windows SDK version + FOREACH(_VERSION ${WINSDK_DETECTED_VERSIONS}) + IF(WINSDK_VERSION STREQUAL _VERSION) + SET(WINSDK_VERSION_FULL "${WINSDK${WINSDK_VERSION}_VERSION_FULL}") + SET(WINSDK_DIR "${WINSDK${WINSDK_VERSION}_DIR}") + BREAK() + ENDIF(WINSDK_VERSION STREQUAL _VERSION) + ENDFOREACH(_VERSION) + ENDIF(NOT WINSDK_DIR) +ENDMACRO(USE_CURRENT_WINSDK) + +IF(WINSDK_VERSION STREQUAL "CURRENT") + USE_CURRENT_WINSDK() +ELSE(WINSDK_VERSION STREQUAL "CURRENT") + IF(WINSDK${WINSDK_VERSION}_FOUND) + SET(WINSDK_VERSION_FULL "${WINSDK${WINSDK_VERSION}_VERSION_FULL}") + SET(WINSDK_DIR "${WINSDK${WINSDK_VERSION}_DIR}") + ELSE(WINSDK${WINSDK_VERSION}_FOUND) + USE_CURRENT_WINSDK() + ENDIF(WINSDK${WINSDK_VERSION}_FOUND) +ENDIF(WINSDK_VERSION STREQUAL "CURRENT") + +IF(WINSDK_DIR) + MESSAGE(STATUS "Using Windows SDK ${WINSDK_VERSION}") +ELSE(WINSDK_DIR) + MESSAGE(FATAL_ERROR "Unable to find Windows SDK!") +ENDIF(WINSDK_DIR) + +# directory where Win32 headers are found FIND_PATH(WINSDK_INCLUDE_DIR Windows.h HINTS - ${WINSDK8_DIR}/Include/um - ${WINSDK71_DIR}/Include - ${WINSDKCURRENT_DIR}/Include + ${WINSDK_DIR}/Include/um + ${WINSDK_DIR}/Include ) +# directory where DirectX headers are found FIND_PATH(WINSDK_SHARED_INCLUDE_DIR d3d9.h HINTS - ${WINSDK8_DIR}/Include/shared - ${WINSDK71_DIR}/Include - ${WINSDKCURRENT_DIR}/Include + ${WINSDK_DIR}/Include/shared + ${WINSDK_DIR}/Include ) +# directory where all libraries are found FIND_PATH(WINSDK_LIBRARY_DIR ComCtl32.lib HINTS - ${WINSDK8_DIR}/Lib/win8/um/${WINSDK8_SUFFIX} - ${WINSDK71_DIR}/Lib - ${WINSDKCURRENT_DIR}/Lib + ${WINSDK_DIR}/Lib/win8/um/${WINSDK8_SUFFIX} + ${WINSDK_DIR}/Lib/${WINSDK_SUFFIX} ) +# signtool is used to sign executables FIND_PROGRAM(WINSDK_SIGNTOOL signtool HINTS - ${WINSDK8_DIR}/Bin/x86 - ${WINSDK71_DIR}/Bin - ${WINSDKCURRENT_DIR}/Bin + ${WINSDK_DIR}/Bin/x86 + ${WINSDK_DIR}/Bin +) + +# midl is used to generate IDL interfaces +FIND_PROGRAM(WINSDK_MIDL midl + HINTS + ${WINSDK_DIR}/Bin/x86 + ${WINSDK_DIR}/Bin ) IF(WINSDK_INCLUDE_DIR) - SET(WINSDK_FOUND TRUE) + SET(WINSDK_FOUND ON) SET(WINSDK_INCLUDE_DIRS ${WINSDK_INCLUDE_DIR} ${WINSDK_SHARED_INCLUDE_DIR}) + SET(CMAKE_LIBRARY_PATH ${WINSDK_LIBRARY_DIR} ${CMAKE_LIBRARY_PATH}) + INCLUDE_DIRECTORIES(${WINSDK_INCLUDE_DIRS}) + + # Fix for using Windows SDK 7.1 with Visual C++ 2012 + IF(WINSDK_VERSION STREQUAL "7.1" AND MSVC11) + ADD_DEFINITIONS(-D_USING_V110_SDK71_) + ENDIF(WINSDK_VERSION STREQUAL "7.1" AND MSVC11) ELSE(WINSDK_INCLUDE_DIR) IF(NOT WindowsSDK_FIND_QUIETLY) MESSAGE(STATUS "Warning: Unable to find Windows SDK!") diff --git a/code/CMakeModules/GetRevision.cmake b/code/CMakeModules/GetRevision.cmake index 18e997af2..21b234f74 100644 --- a/code/CMakeModules/GetRevision.cmake +++ b/code/CMakeModules/GetRevision.cmake @@ -19,6 +19,7 @@ IF(SOURCE_DIR) SET(SOURCE_DIR ${ROOT_DIR}) ENDIF(NOT SOURCE_DIR AND ROOT_DIR) ELSE(SOURCE_DIR) + SET(SOURCE_DIR ${CMAKE_SOURCE_DIR}) SET(ROOT_DIR ${CMAKE_SOURCE_DIR}) ENDIF(SOURCE_DIR) @@ -57,6 +58,15 @@ IF(EXISTS "${ROOT_DIR}/.hg/") ENDIF(MERCURIAL_FOUND) ENDIF(EXISTS "${ROOT_DIR}/.hg/") +# if processing exported sources, use "revision" file if exists +IF(SOURCE_DIR AND NOT DEFINED REVISION) + SET(REVISION_FILE ${SOURCE_DIR}/revision) + IF(EXISTS ${REVISION_FILE}) + FILE(STRINGS ${REVISION_FILE} REVISION LIMIT_COUNT 1) + MESSAGE(STATUS "Read revision ${REVISION} from file") + ENDIF(EXISTS ${REVISION_FILE}) +ENDIF(SOURCE_DIR AND NOT DEFINED REVISION) + IF(SOURCE_DIR AND DEFINED REVISION) IF(EXISTS ${SOURCE_DIR}/revision.h.in) MESSAGE(STATUS "Revision: ${REVISION}") diff --git a/code/CMakeModules/PCHSupport.cmake b/code/CMakeModules/PCHSupport.cmake index d444bfa3d..97b5ed88d 100644 --- a/code/CMakeModules/PCHSupport.cmake +++ b/code/CMakeModules/PCHSupport.cmake @@ -10,7 +10,6 @@ IF(MSVC) SET(PCHSupport_FOUND TRUE) - SET(_PCH_include_prefix "/I") ELSE(MSVC) IF(CMAKE_COMPILER_IS_GNUCXX) EXEC_PROGRAM(${CMAKE_CXX_COMPILER} @@ -26,8 +25,6 @@ ELSE(MSVC) # TODO: make tests for other compilers than GCC SET(PCHSupport_FOUND TRUE) ENDIF(CMAKE_COMPILER_IS_GNUCXX) - - SET(_PCH_include_prefix "-I") ENDIF(MSVC) # Set PCH_FLAGS for common flags, PCH_ARCH_XXX_FLAGS for specific archs flags and PCH_ARCHS for archs @@ -35,35 +32,43 @@ MACRO(PCH_SET_COMPILE_FLAGS _target) SET(PCH_FLAGS) SET(PCH_ARCHS) - SET(FLAGS) + SET(_FLAGS) LIST(APPEND _FLAGS ${CMAKE_CXX_FLAGS}) STRING(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPER_BUILD) LIST(APPEND _FLAGS " ${CMAKE_CXX_FLAGS_${_UPPER_BUILD}}") - IF(NOT MSVC) - GET_TARGET_PROPERTY(_targetType ${_target} TYPE) - IF(${_targetType} STREQUAL SHARED_LIBRARY OR ${_targetType} STREQUAL MODULE_LIBRARY) - LIST(APPEND _FLAGS " -fPIC") - ENDIF(${_targetType} STREQUAL SHARED_LIBRARY OR ${_targetType} STREQUAL MODULE_LIBRARY) - ENDIF(NOT MSVC) + GET_TARGET_PROPERTY(_targetType ${_target} TYPE) + + IF(${_targetType} STREQUAL SHARED_LIBRARY OR ${_targetType} STREQUAL MODULE_LIBRARY) + LIST(APPEND _FLAGS " ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") + ELSE(${_targetType} STREQUAL SHARED_LIBRARY OR ${_targetType} STREQUAL MODULE_LIBRARY) + GET_TARGET_PROPERTY(_pic ${_target} POSITION_INDEPENDENT_CODE) + IF(_pic) + LIST(APPEND _FLAGS " ${CMAKE_CXX_COMPILE_OPTIONS_PIE}") + ENDIF(_pic) + ENDIF(${_targetType} STREQUAL SHARED_LIBRARY OR ${_targetType} STREQUAL MODULE_LIBRARY) GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES) FOREACH(item ${DIRINC}) - LIST(APPEND _FLAGS " ${_PCH_include_prefix}\"${item}\"") + LIST(APPEND _FLAGS " -I\"${item}\"") ENDFOREACH(item) # Required for CMake 2.6 SET(GLOBAL_DEFINITIONS) GET_DIRECTORY_PROPERTY(DEFINITIONS COMPILE_DEFINITIONS) - FOREACH(item ${DEFINITIONS}) - LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") - ENDFOREACH(item) + IF(DEFINITIONS) + FOREACH(item ${DEFINITIONS}) + LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") + ENDFOREACH(item) + ENDIF(DEFINITIONS) GET_DIRECTORY_PROPERTY(DEFINITIONS COMPILE_DEFINITIONS_${_UPPER_BUILD}) - FOREACH(item ${DEFINITIONS}) - LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") - ENDFOREACH(item) + IF(DEFINITIONS) + FOREACH(item ${DEFINITIONS}) + LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") + ENDFOREACH(item) + ENDIF(DEFINITIONS) GET_TARGET_PROPERTY(oldProps ${_target} COMPILE_FLAGS) IF(oldProps) @@ -75,16 +80,41 @@ MACRO(PCH_SET_COMPILE_FLAGS _target) LIST(APPEND _FLAGS " ${oldPropsBuild}") ENDIF(oldPropsBuild) + GET_TARGET_PROPERTY(DIRINC ${_target} INCLUDE_DIRECTORIES) + IF(DIRINC) + FOREACH(item ${DIRINC}) + LIST(APPEND _FLAGS " -I\"${item}\"") + ENDFOREACH(item) + ENDIF(DIRINC) + + GET_TARGET_PROPERTY(DEFINITIONS ${_target} COMPILE_DEFINITIONS) + IF(DEFINITIONS) + FOREACH(item ${DEFINITIONS}) + LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") + ENDFOREACH(item) + ENDIF(DEFINITIONS) + + GET_TARGET_PROPERTY(DEFINITIONS ${_target} COMPILE_DEFINITIONS_${_UPPER_BUILD}) + IF(DEFINITIONS) + FOREACH(item ${DEFINITIONS}) + LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") + ENDFOREACH(item) + ENDIF(DEFINITIONS) + GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS) GET_DIRECTORY_PROPERTY(_directory_definitions DIRECTORY ${CMAKE_SOURCE_DIR} DEFINITIONS) LIST(APPEND _FLAGS " ${GLOBAL_DEFINITIONS}") LIST(APPEND _FLAGS " ${_directory_flags}") LIST(APPEND _FLAGS " ${_directory_definitions}") - STRING(REGEX REPLACE " +" " " _FLAGS ${_FLAGS}) - # Format definitions - SEPARATE_ARGUMENTS(_FLAGS) + IF(MSVC) + # Fix path with space + SEPARATE_ARGUMENTS(_FLAGS UNIX_COMMAND "${_FLAGS}") + ELSE(MSVC) + STRING(REGEX REPLACE " +" " " _FLAGS ${_FLAGS}) + SEPARATE_ARGUMENTS(_FLAGS) + ENDIF(MSVC) IF(CLANG) # Determining all architectures and get common flags @@ -178,6 +208,9 @@ MACRO(PCH_SET_COMPILE_COMMAND _inputcpp _compile_FLAGS) IF(MSVC) GET_PDB_FILENAME(PDB_FILE ${_PCH_current_target}) SET(PCH_COMMAND ${CMAKE_CXX_COMPILER} ${pchsupport_compiler_cxx_arg1} ${_compile_FLAGS} /Yc /Fp"${PCH_OUTPUT}" ${_inputcpp} /Fd"${PDB_FILE}" /c /Fo"${PCH_OUTPUT}.obj") + # Ninja PCH Support + # http://public.kitware.com/pipermail/cmake-developers/2012-March/003653.html + SET_SOURCE_FILES_PROPERTIES(${_inputcpp} PROPERTIES OBJECT_OUTPUTS "${PCH_OUTPUT}.obj") ELSE(MSVC) SET(HEADER_FORMAT "c++-header") SET(_FLAGS "") @@ -237,6 +270,25 @@ MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET _targetName) IF(MSVC) SET(_target_cflags "${oldProps} /Yu\"${PCH_INPUT}\" /FI\"${PCH_INPUT}\" /Fp\"${PCH_OUTPUT}\"") + # Ninja PCH Support + # http://public.kitware.com/pipermail/cmake-developers/2012-March/003653.html + SET_TARGET_PROPERTIES(${_targetName} PROPERTIES OBJECT_DEPENDS "${PCH_OUTPUT}") + + # NMAKE-VS2012 Error LNK2011 (NMAKE-VS2010 do not complain) + # we need to link the pch.obj file, see http://msdn.microsoft.com/en-us/library/3ay26wa2(v=vs.110).aspx + GET_TARGET_PROPERTY(_STATIC_LIBRARY_FLAGS ${_targetName} STATIC_LIBRARY_FLAGS) + IF(NOT _STATIC_LIBRARY_FLAGS) + SET(_STATIC_LIBRARY_FLAGS) + ENDIF(NOT _STATIC_LIBRARY_FLAGS) + SET(_STATIC_LIBRARY_FLAGS "${PCH_OUTPUT}.obj ${_STATIC_LIBRARY_FLAGS}") + + GET_TARGET_PROPERTY(_LINK_FLAGS ${_targetName} LINK_FLAGS) + IF(NOT _LINK_FLAGS) + SET(_LINK_FLAGS) + ENDIF(NOT _LINK_FLAGS) + SET(_LINK_FLAGS "${PCH_OUTPUT}.obj ${_LINK_FLAGS}") + + SET_TARGET_PROPERTIES(${_targetName} PROPERTIES STATIC_LIBRARY_FLAGS ${_STATIC_LIBRARY_FLAGS} LINK_FLAGS ${_LINK_FLAGS}) ELSE(MSVC) # for use with distcc and gcc >4.0.1 if preprocessed files are accessible # on all remote machines set @@ -324,17 +376,6 @@ MACRO(ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp) SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PCH_OUTPUTS}") ENDMACRO(ADD_PRECOMPILED_HEADER) -# Macro to move PCH creation file to the front of files list -# or remove .cpp from library/executable to avoid warning -MACRO(FIX_PRECOMPILED_HEADER _files _pch) - # Remove .cpp creating PCH from the list - LIST(REMOVE_ITEM ${_files} ${_pch}) - IF(MSVC) - # Prepend .cpp creating PCH to the list - LIST(INSERT ${_files} 0 ${_pch}) - ENDIF(MSVC) -ENDMACRO(FIX_PRECOMPILED_HEADER) - MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp) IF(NOT PCHSupport_FOUND) MESSAGE(STATUS "PCH disabled because compiler doesn't support them") @@ -346,10 +387,6 @@ MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp) # 2 => setting PCH for XCode project, works for XCode projects IF(CMAKE_GENERATOR MATCHES "Visual Studio") SET(PCH_METHOD 1) - ELSEIF(CMAKE_GENERATOR MATCHES "NMake Makefiles" AND MFC_FOUND AND CMAKE_MFC_FLAG) - # To fix a bug with MFC - # Don't forget to use FIX_PRECOMPILED_HEADER before creating the target -# SET(PCH_METHOD 1) ELSEIF(CMAKE_GENERATOR MATCHES "Xcode") SET(PCH_METHOD 2) ELSE(CMAKE_GENERATOR MATCHES "Visual Studio") diff --git a/code/CMakeModules/iOSToolChain.cmake b/code/CMakeModules/iOSToolChain.cmake new file mode 100644 index 000000000..5b419778e --- /dev/null +++ b/code/CMakeModules/iOSToolChain.cmake @@ -0,0 +1,183 @@ +# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake +# files which are included with CMake 2.8.4 +# It has been altered for iOS development +# +# Options: +# +# IOS_VERSION = last(default) or specific one (4.3, 5.0, 4.1) +# This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders +# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch. +# SIMULATOR - used to build for the Simulator platforms, which have an x86 arch. +# +# IOS_PLATFORM = OS (default) or SIMULATOR or ALL +# This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders +# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch. +# SIMULATOR - used to build for the Simulator platforms, which have an x86 arch. +# +# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder +# By default this location is automatcially chosen based on the IOS_PLATFORM value above. +# If set manually, it will override the default location and force the user of a particular Developer Platform +# +# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder +# By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value. +# In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path. +# If set manually, this will force the use of a specific SDK version + +IF(DEFINED CMAKE_CROSSCOMPILING) + # subsequent toolchain loading is not really needed + RETURN() +ENDIF() + +# Standard settings +SET(CMAKE_SYSTEM_NAME Darwin) +SET(CMAKE_SYSTEM_VERSION 1) # TODO: determine target Darwin version +SET(UNIX ON) +SET(APPLE ON) +SET(IOS ON) + +# Force the compilers to Clang for iOS +include (CMakeForceCompiler) +CMAKE_FORCE_C_COMPILER (clang Clang) +CMAKE_FORCE_CXX_COMPILER (clang++ Clang) + +# Setup iOS platform +if (NOT DEFINED IOS_PLATFORM) + set (IOS_PLATFORM "OS") +endif (NOT DEFINED IOS_PLATFORM) +set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") + +SET(IOS_PLATFORM_LOCATION "iPhoneOS.platform") +SET(IOS_SIMULATOR_PLATFORM_LOCATION "iPhoneSimulator.platform") + +# Check the platform selection and setup for developer root +if (${IOS_PLATFORM} STREQUAL "OS") + # This causes the installers to properly locate the output libraries + set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") +elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") + # This causes the installers to properly locate the output libraries + set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") +elseif (${IOS_PLATFORM} STREQUAL "ALL") + # This causes the installers to properly locate the output libraries + set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator;-iphoneos") +else (${IOS_PLATFORM} STREQUAL "OS") + message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR") +endif (${IOS_PLATFORM} STREQUAL "OS") +set (CMAKE_XCODE_EFFECTIVE_PLATFORMS ${CMAKE_XCODE_EFFECTIVE_PLATFORMS} CACHE PATH "iOS Platform") + +# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT +# Note Xcode 4.3 changed the installation location, choose the most recent one available +SET(XCODE_POST_43_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms") +SET(XCODE_PRE_43_ROOT "/Developer/Platforms") + +IF(NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) + IF(EXISTS ${XCODE_POST_43_ROOT}) + SET(CMAKE_XCODE_ROOT ${XCODE_POST_43_ROOT}) + ELSEIF(EXISTS ${XCODE_PRE_43_ROOT}) + SET(CMAKE_XCODE_ROOT ${XCODE_PRE_43_ROOT}) + ENDIF(EXISTS ${XCODE_POST_43_ROOT}) + IF(EXISTS ${CMAKE_XCODE_ROOT}/${IOS_PLATFORM_LOCATION}/Developer) + SET(CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_XCODE_ROOT}/${IOS_PLATFORM_LOCATION}/Developer) + ENDIF(EXISTS ${CMAKE_XCODE_ROOT}/${IOS_PLATFORM_LOCATION}/Developer) + IF(EXISTS ${CMAKE_XCODE_ROOT}/${IOS_SIMULATOR_PLATFORM_LOCATION}/Developer) + SET(CMAKE_IOS_SIMULATOR_DEVELOPER_ROOT ${CMAKE_XCODE_ROOT}/${IOS_SIMULATOR_PLATFORM_LOCATION}/Developer) + ENDIF(EXISTS ${CMAKE_XCODE_ROOT}/${IOS_SIMULATOR_PLATFORM_LOCATION}/Developer) +ENDIF(NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) +SET(CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform") +SET(CMAKE_IOS_SIMULATOR_DEVELOPER_ROOT ${CMAKE_IOS_SIMULATOR_DEVELOPER_ROOT} CACHE PATH "Location of iOS Simulator Platform") + +MACRO(GET_AVAILABLE_SDK_VERSIONS ROOT VERSIONS) + FILE(GLOB _CMAKE_IOS_SDKS "${ROOT}/SDKs/iPhoneOS*") + IF(_CMAKE_IOS_SDKS) + LIST(SORT _CMAKE_IOS_SDKS) + LIST(REVERSE _CMAKE_IOS_SDKS) + FOREACH(_CMAKE_IOS_SDK ${_CMAKE_IOS_SDKS}) + STRING(REGEX REPLACE ".+iPhoneOS([0-9.]+)\\.sdk" "\\1" _IOS_SDK "${_CMAKE_IOS_SDK}") + LIST(APPEND ${VERSIONS} ${_IOS_SDK}) + ENDFOREACH(_CMAKE_IOS_SDK) + ENDIF(_CMAKE_IOS_SDKS) +ENDMACRO(GET_AVAILABLE_SDK_VERSIONS) + +# Find and use the most recent iOS sdk +IF(NOT DEFINED CMAKE_IOS_SDK_ROOT) + # Search for a specific version of a SDK + GET_AVAILABLE_SDK_VERSIONS(${CMAKE_IOS_DEVELOPER_ROOT} IOS_VERSIONS) + + IF(NOT IOS_VERSIONS) + MESSAGE(FATAL_ERROR "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.") + ENDIF(NOT IOS_VERSIONS) + + IF(IOS_VERSION) + LIST(FIND IOS_VERSIONS "${IOS_VERSION}" _INDEX) + IF(_INDEX EQUAL -1) + LIST(GET IOS_VERSIONS 0 IOS_SDK_VERSION) + ELSE(_INDEX EQUAL -1) + SET(IOS_SDK_VERSION ${IOS_VERSION}) + ENDIF(_INDEX EQUAL -1) + ELSE(IOS_VERSION) + LIST(GET IOS_VERSIONS 0 IOS_VERSION) + SET(IOS_SDK_VERSION ${IOS_VERSION}) + ENDIF(IOS_VERSION) + + MESSAGE(STATUS "Target iOS ${IOS_VERSION} and use SDK ${IOS_SDK_VERSION}") + + SET(CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/iPhoneOS${IOS_SDK_VERSION}.sdk) + SET(CMAKE_IOS_SIMULATOR_SDK_ROOT ${CMAKE_IOS_SIMULATOR_DEVELOPER_ROOT}/SDKs/iPhoneSimulator${IOS_SDK_VERSION}.sdk) +endif (NOT DEFINED CMAKE_IOS_SDK_ROOT) + +SET(CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK") +SET(CMAKE_IOS_SIMULATOR_SDK_ROOT ${CMAKE_IOS_SIMULATOR_SDK_ROOT} CACHE PATH "Location of the selected iOS Simulator SDK") + +SET(IOS_VERSION ${IOS_VERSION} CACHE STRING "iOS target version") + +# Set the sysroot default to the most recent SDK +SET(CMAKE_IOS_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support") +SET(CMAKE_IOS_SIMULATOR_SYSROOT ${CMAKE_IOS_SIMULATOR_SDK_ROOT} CACHE PATH "Sysroot used for iOS Simulator support") + +IF(CMAKE_GENERATOR MATCHES Xcode) + SET(ARCHS "$(ARCHS_STANDARD_32_BIT)") + IF(${IOS_PLATFORM} STREQUAL "OS") + SET(CMAKE_SYSTEM_PROCESSOR "armv7") + ELSEIF(${IOS_PLATFORM} STREQUAL "SIMULATOR") + SET(CMAKE_SYSTEM_PROCESSOR "x86") + ELSEIF(${IOS_PLATFORM} STREQUAL "ALL") + SET(CMAKE_SYSTEM_PROCESSOR "armv7") + ENDIF(${IOS_PLATFORM} STREQUAL "OS") +ELSE(CMAKE_GENERATOR MATCHES Xcode) + IF(${IOS_PLATFORM} STREQUAL "OS") + SET(ARCHS "armv7") + SET(CMAKE_SYSTEM_PROCESSOR "armv7") + ELSEIF(${IOS_PLATFORM} STREQUAL "SIMULATOR") + # iPhone simulator targets i386 + SET(ARCHS "i386") + SET(CMAKE_SYSTEM_PROCESSOR "x86") + ELSEIF(${IOS_PLATFORM} STREQUAL "ALL") + SET(ARCHS "armv7;i386") + SET(CMAKE_SYSTEM_PROCESSOR "armv7") + ENDIF(${IOS_PLATFORM} STREQUAL "OS") +ENDIF(CMAKE_GENERATOR MATCHES Xcode) + +# set the architecture for iOS - using ARCHS_STANDARD_32_BIT sets armv7,armv7s and appears to be XCode's standard. +# The other value that works is ARCHS_UNIVERSAL_IPHONE_OS but that sets armv7 only +set (CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE string "Build architecture for iOS") + +# Set the find root to the iOS developer roots and to user defined paths +set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} ${CMAKE_INSTALL_PREFIX} $ENV{EXTERNAL_IOS_PATH} CACHE string "iOS find search path root") + +# default to searching for frameworks first +set (CMAKE_FIND_FRAMEWORK FIRST) + +# set up the default search directories for frameworks +set (CMAKE_SYSTEM_FRAMEWORK_PATH + ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks + ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks + ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks +) + +# only search the iOS sdks, not the remainder of the host filesystem +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +#SET(CMAKE_SYSTEM_INCLUDE_PATH /include /usr/include) +#SET(CMAKE_SYSTEM_LIBRARY_PATH /lib /usr/lib) +#SET(CMAKE_SYSTEM_PROGRAM_PATH /bin /usr/bin) diff --git a/code/CMakeModules/nel.cmake b/code/CMakeModules/nel.cmake index 1c339fef8..f239ec779 100644 --- a/code/CMakeModules/nel.cmake +++ b/code/CMakeModules/nel.cmake @@ -123,12 +123,8 @@ MACRO(NL_DEFAULT_PROPS name label) VERSION ${NL_VERSION} SOVERSION ${NL_VERSION_MAJOR} COMPILE_FLAGS "/GA" - LINK_FLAGS "/VERSION:${NL_VERSION}") + LINK_FLAGS "/VERSION:${NL_VERSION_MAJOR}.${NL_VERSION_MINOR}") ENDIF(${type} STREQUAL EXECUTABLE AND WIN32) - - IF(WITH_STLPORT AND WIN32) - SET_TARGET_PROPERTIES(${name} PROPERTIES COMPILE_FLAGS "/X") - ENDIF(WITH_STLPORT AND WIN32) ENDMACRO(NL_DEFAULT_PROPS) ### @@ -247,6 +243,11 @@ MACRO(NL_SETUP_DEFAULT_OPTIONS) ELSE(WIN32) OPTION(WITH_STATIC "With static libraries." OFF) ENDIF(WIN32) + IF (WITH_STATIC) + OPTION(WITH_STATIC_LIBXML2 "With static libxml2" ON ) + ELSE(WITH_STATIC) + OPTION(WITH_STATIC_LIBXML2 "With static libxml2" OFF) + ENDIF(WITH_STATIC) OPTION(WITH_STATIC_DRIVERS "With static drivers." OFF) IF(WIN32) OPTION(WITH_EXTERNAL "With provided external." ON ) @@ -293,6 +294,7 @@ MACRO(NL_SETUP_NEL_DEFAULT_OPTIONS) ### OPTION(WITH_NET "Build NLNET" ON ) OPTION(WITH_3D "Build NL3D" ON ) + OPTION(WITH_GUI "Build GUI" ON ) OPTION(WITH_PACS "Build NLPACS" ON ) OPTION(WITH_GEORGES "Build NLGEORGES" ON ) OPTION(WITH_LIGO "Build NLLIGO" ON ) @@ -318,6 +320,9 @@ MACRO(NL_SETUP_NEL_DEFAULT_OPTIONS) OPTION(WITH_NEL_MAXPLUGIN "Build NeL 3dsMax Plugin" OFF) OPTION(WITH_NEL_SAMPLES "Build NeL Samples" ON ) OPTION(WITH_NEL_TESTS "Build NeL Unit Tests" ON ) + + OPTION(WITH_LIBOVR "With LibOVR support" OFF) + OPTION(WITH_LIBVR "With LibVR support" OFF) ENDMACRO(NL_SETUP_NEL_DEFAULT_OPTIONS) MACRO(NL_SETUP_NELNS_DEFAULT_OPTIONS) @@ -340,7 +345,8 @@ MACRO(NL_SETUP_RYZOM_DEFAULT_OPTIONS) ### # Optional support ### - OPTION(WITH_LUA51 "Build Ryzom Core using Lua51" ON ) + OPTION(WITH_LUA51 "Build Ryzom Core using Lua 5.1" ON ) + OPTION(WITH_LUA52 "Build Ryzom Core using Lua 5.2" OFF) ENDMACRO(NL_SETUP_RYZOM_DEFAULT_OPTIONS) MACRO(NL_SETUP_SNOWBALLS_DEFAULT_OPTIONS) @@ -381,11 +387,11 @@ MACRO(NL_SETUP_BUILD) SET(HOST_CPU ${CMAKE_HOST_SYSTEM_PROCESSOR}) - IF(HOST_CPU MATCHES "amd64") + IF(HOST_CPU MATCHES "(amd|AMD)64") SET(HOST_CPU "x86_64") ELSEIF(HOST_CPU MATCHES "i.86") SET(HOST_CPU "x86") - ENDIF(HOST_CPU MATCHES "amd64") + ENDIF(HOST_CPU MATCHES "(amd|AMD)64") # Determine target CPU @@ -394,11 +400,11 @@ MACRO(NL_SETUP_BUILD) SET(TARGET_CPU ${CMAKE_SYSTEM_PROCESSOR}) ENDIF(NOT TARGET_CPU) - IF(TARGET_CPU MATCHES "amd64") + IF(TARGET_CPU MATCHES "(amd|AMD)64") SET(TARGET_CPU "x86_64") ELSEIF(TARGET_CPU MATCHES "i.86") SET(TARGET_CPU "x86") - ENDIF(TARGET_CPU MATCHES "amd64") + ENDIF(TARGET_CPU MATCHES "(amd|AMD)64") IF(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") SET(CLANG ON) @@ -410,6 +416,11 @@ MACRO(NL_SETUP_BUILD) MESSAGE(STATUS "Generating Xcode project") ENDIF(CMAKE_GENERATOR MATCHES "Xcode") + IF(CMAKE_GENERATOR MATCHES "NMake") + SET(NMAKE ON) + MESSAGE(STATUS "Generating NMake project") + ENDIF(CMAKE_GENERATOR MATCHES "NMake") + # If target and host CPU are the same IF("${HOST_CPU}" STREQUAL "${TARGET_CPU}" AND NOT CMAKE_CROSSCOMPILING) # x86-compatible CPU @@ -529,6 +540,9 @@ MACRO(NL_SETUP_BUILD) SET(MSVC11 ON) ENDIF(MSVC_VERSION EQUAL "1700" AND NOT MSVC11) + # Ignore default include paths + ADD_PLATFORM_FLAGS("/X") + IF(MSVC11) ADD_PLATFORM_FLAGS("/Gy- /MP") # /Ox is working with VC++ 2010, but custom optimizations don't exist @@ -599,22 +613,7 @@ MACRO(NL_SETUP_BUILD) ENDIF(WIN32) IF(APPLE) - IF(IOS) - # Disable CMAKE_OSX_DEPLOYMENT_TARGET for iOS - SET(CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE PATH "" FORCE) - ELSE(IOS) - IF(NOT CMAKE_OSX_DEPLOYMENT_TARGET) - SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE PATH "" FORCE) - ENDIF(NOT CMAKE_OSX_DEPLOYMENT_TARGET) - ENDIF(IOS) - - IF(XCODE) - IF(IOS) - SET(CMAKE_OSX_SYSROOT "iphoneos" CACHE PATH "" FORCE) - ELSE(IOS) -# SET(CMAKE_OSX_SYSROOT "macosx" CACHE PATH "" FORCE) - ENDIF(IOS) - ELSE(XCODE) + IF(NOT XCODE) IF(CMAKE_OSX_ARCHITECTURES) SET(TARGETS_COUNT 0) SET(_ARCHS) @@ -790,16 +789,8 @@ MACRO(NL_SETUP_BUILD) SET(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} ${XARCH}-Wl,-macosx_version_min,${CMAKE_OSX_DEPLOYMENT_TARGET}") ENDIF(CMAKE_IOS_SIMULATOR_SYSROOT AND TARGET_X86) ELSE(IOS) - FOREACH(_SDK ${_CMAKE_OSX_SDKS}) - IF(${_SDK} MATCHES "MacOSX${CMAKE_OSX_DEPLOYMENT_TARGET}\\.sdk") - SET(CMAKE_OSX_SYSROOT ${_SDK} CACHE PATH "" FORCE) - ENDIF(${_SDK} MATCHES "MacOSX${CMAKE_OSX_DEPLOYMENT_TARGET}\\.sdk") - ENDFOREACH(_SDK) - IF(CMAKE_OSX_SYSROOT) ADD_PLATFORM_FLAGS("-isysroot ${CMAKE_OSX_SYSROOT}") - ELSE(CMAKE_OSX_SYSROOT) - MESSAGE(FATAL_ERROR "CMAKE_OSX_SYSROOT can't be determinated") ENDIF(CMAKE_OSX_SYSROOT) # Always force -mmacosx-version-min to override environement variable @@ -812,7 +803,7 @@ MACRO(NL_SETUP_BUILD) IF(HAVE_FLAG_SEARCH_PATHS_FIRST) SET(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,-search_paths_first") ENDIF(HAVE_FLAG_SEARCH_PATHS_FIRST) - ENDIF(XCODE) + ENDIF(NOT XCODE) ELSE(APPLE) IF(HOST_CPU STREQUAL "x86_64" AND TARGET_CPU STREQUAL "x86") ADD_PLATFORM_FLAGS("-m32 -march=i686") @@ -911,20 +902,23 @@ ENDMACRO(NL_SETUP_BUILD) MACRO(NL_SETUP_BUILD_FLAGS) SET(CMAKE_C_FLAGS ${PLATFORM_CFLAGS} CACHE STRING "" FORCE) SET(CMAKE_CXX_FLAGS ${PLATFORM_CXXFLAGS} CACHE STRING "" FORCE) + SET(CMAKE_EXE_LINKER_FLAGS ${PLATFORM_LINKFLAGS} CACHE STRING "" FORCE) + SET(CMAKE_MODULE_LINKER_FLAGS ${PLATFORM_LINKFLAGS} CACHE STRING "" FORCE) + SET(CMAKE_SHARED_LINKER_FLAGS ${PLATFORM_LINKFLAGS} CACHE STRING "" FORCE) ## Debug SET(CMAKE_C_FLAGS_DEBUG ${NL_DEBUG_CFLAGS} CACHE STRING "" FORCE) SET(CMAKE_CXX_FLAGS_DEBUG ${NL_DEBUG_CFLAGS} CACHE STRING "" FORCE) - SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${PLATFORM_LINKFLAGS} ${NL_DEBUG_LINKFLAGS}" CACHE STRING "" FORCE) - SET(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${PLATFORM_LINKFLAGS} ${NL_DEBUG_LINKFLAGS}" CACHE STRING "" FORCE) - SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${PLATFORM_LINKFLAGS} ${NL_DEBUG_LINKFLAGS}" CACHE STRING "" FORCE) + SET(CMAKE_EXE_LINKER_FLAGS_DEBUG ${NL_DEBUG_LINKFLAGS} CACHE STRING "" FORCE) + SET(CMAKE_MODULE_LINKER_FLAGS_DEBUG ${NL_DEBUG_LINKFLAGS} CACHE STRING "" FORCE) + SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG ${NL_DEBUG_LINKFLAGS} CACHE STRING "" FORCE) ## Release SET(CMAKE_C_FLAGS_RELEASE ${NL_RELEASE_CFLAGS} CACHE STRING "" FORCE) SET(CMAKE_CXX_FLAGS_RELEASE ${NL_RELEASE_CFLAGS} CACHE STRING "" FORCE) - SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${PLATFORM_LINKFLAGS} ${NL_RELEASE_LINKFLAGS}" CACHE STRING "" FORCE) - SET(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${PLATFORM_LINKFLAGS} ${NL_RELEASE_LINKFLAGS}" CACHE STRING "" FORCE) - SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${PLATFORM_LINKFLAGS} ${NL_RELEASE_LINKFLAGS}" CACHE STRING "" FORCE) + SET(CMAKE_EXE_LINKER_FLAGS_RELEASE ${NL_RELEASE_LINKFLAGS} CACHE STRING "" FORCE) + SET(CMAKE_MODULE_LINKER_FLAGS_RELEASE ${NL_RELEASE_LINKFLAGS} CACHE STRING "" FORCE) + SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE ${NL_RELEASE_LINKFLAGS} CACHE STRING "" FORCE) ENDMACRO(NL_SETUP_BUILD_FLAGS) # Macro to create x_ABSOLUTE_PREFIX from x_PREFIX @@ -1078,74 +1072,14 @@ MACRO(SETUP_EXTERNAL) IF(WIN32) FIND_PACKAGE(External REQUIRED) - IF(NOT VC_DIR) - SET(VC_DIR $ENV{VC_DIR}) - ENDIF(NOT VC_DIR) - - IF(MSVC11) - IF(NOT MSVC_REDIST_DIR) - # If you have VC++ 2012 Express, put x64/Microsoft.VC110.CRT/*.dll in ${EXTERNAL_PATH}/redist - SET(MSVC_REDIST_DIR "${EXTERNAL_PATH}/redist") - ENDIF(NOT MSVC_REDIST_DIR) - - IF(NOT VC_DIR) - IF(NOT VC_ROOT_DIR) - GET_FILENAME_COMPONENT(VC_ROOT_DIR "[HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\11.0_Config;InstallDir]" ABSOLUTE) - # VC_ROOT_DIR is set to "registry" when a key is not found - IF(VC_ROOT_DIR MATCHES "registry") - GET_FILENAME_COMPONENT(VC_ROOT_DIR "[HKEY_CURRENT_USER\\Software\\Microsoft\\WDExpress\\11.0_Config\\Setup\\VC;InstallDir]" ABSOLUTE) - IF(VC_ROOT_DIR MATCHES "registry") - SET(VS110COMNTOOLS $ENV{VS110COMNTOOLS}) - IF(VS110COMNTOOLS) - FILE(TO_CMAKE_PATH ${VS110COMNTOOLS} VC_ROOT_DIR) - ENDIF(VS110COMNTOOLS) - IF(NOT VC_ROOT_DIR) - MESSAGE(FATAL_ERROR "Unable to find VC++ 2012 directory!") - ENDIF(NOT VC_ROOT_DIR) - ENDIF(VC_ROOT_DIR MATCHES "registry") - ENDIF(VC_ROOT_DIR MATCHES "registry") - ENDIF(NOT VC_ROOT_DIR) - # convert IDE fullpath to VC++ path - STRING(REGEX REPLACE "Common7/.*" "VC" VC_DIR ${VC_ROOT_DIR}) - ENDIF(NOT VC_DIR) - ELSEIF(MSVC10) - IF(NOT MSVC_REDIST_DIR) - # If you have VC++ 2010 Express, put x64/Microsoft.VC100.CRT/*.dll in ${EXTERNAL_PATH}/redist - SET(MSVC_REDIST_DIR "${EXTERNAL_PATH}/redist") - ENDIF(NOT MSVC_REDIST_DIR) - - IF(NOT VC_DIR) - IF(NOT VC_ROOT_DIR) - GET_FILENAME_COMPONENT(VC_ROOT_DIR "[HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\10.0_Config;InstallDir]" ABSOLUTE) - # VC_ROOT_DIR is set to "registry" when a key is not found - IF(VC_ROOT_DIR MATCHES "registry") - GET_FILENAME_COMPONENT(VC_ROOT_DIR "[HKEY_CURRENT_USER\\Software\\Microsoft\\VCExpress\\10.0_Config;InstallDir]" ABSOLUTE) - IF(VC_ROOT_DIR MATCHES "registry") - SET(VS100COMNTOOLS $ENV{VS100COMNTOOLS}) - IF(VS100COMNTOOLS) - FILE(TO_CMAKE_PATH ${VS100COMNTOOLS} VC_ROOT_DIR) - ENDIF(VS100COMNTOOLS) - IF(NOT VC_ROOT_DIR) - MESSAGE(FATAL_ERROR "Unable to find VC++ 2010 directory!") - ENDIF(NOT VC_ROOT_DIR) - ENDIF(VC_ROOT_DIR MATCHES "registry") - ENDIF(VC_ROOT_DIR MATCHES "registry") - ENDIF(NOT VC_ROOT_DIR) - # convert IDE fullpath to VC++ path - STRING(REGEX REPLACE "Common7/.*" "VC" VC_DIR ${VC_ROOT_DIR}) - ENDIF(NOT VC_DIR) - ELSE(MSVC11) - IF(NOT VC_DIR) - IF(${CMAKE_MAKE_PROGRAM} MATCHES "Common7") - # convert IDE fullpath to VC++ path - STRING(REGEX REPLACE "Common7/.*" "VC" VC_DIR ${CMAKE_MAKE_PROGRAM}) - ELSE(${CMAKE_MAKE_PROGRAM} MATCHES "Common7") - # convert compiler fullpath to VC++ path - STRING(REGEX REPLACE "VC/bin/.+" "VC" VC_DIR ${CMAKE_CXX_COMPILER}) - ENDIF(${CMAKE_MAKE_PROGRAM} MATCHES "Common7") - ENDIF(NOT VC_DIR) - ENDIF(MSVC11) + # If using custom boost, we need to define the right variables used by official boost CMake module + IF(DEFINED BOOST_DIR) + SET(BOOST_INCLUDEDIR ${BOOST_DIR}/include) + SET(BOOST_LIBRARYDIR ${BOOST_DIR}/lib) + ENDIF(DEFINED BOOST_DIR) ELSE(WIN32) + FIND_PACKAGE(External QUIET) + IF(APPLE) IF(WITH_STATIC_EXTERNAL) SET(CMAKE_FIND_LIBRARY_SUFFIXES .a) @@ -1161,15 +1095,22 @@ MACRO(SETUP_EXTERNAL) ENDIF(APPLE) ENDIF(WIN32) + # Android and iOS have pthread + IF(ANDROID OR IOS) + SET(CMAKE_USE_PTHREADS_INIT 1) + SET(Threads_FOUND TRUE) + ELSE(ANDROID OR IOS) + FIND_PACKAGE(Threads REQUIRED) + # TODO: replace all -l by absolute path to in CMAKE_THREAD_LIBS_INIT + ENDIF(ANDROID OR IOS) + IF(WITH_STLPORT) FIND_PACKAGE(STLport REQUIRED) INCLUDE_DIRECTORIES(${STLPORT_INCLUDE_DIR}) - IF(MSVC) - SET(VC_INCLUDE_DIR "${VC_DIR}/include") - - FIND_PACKAGE(WindowsSDK REQUIRED) - # use VC++ and Windows SDK include paths - INCLUDE_DIRECTORIES(${VC_INCLUDE_DIR} ${WINSDK_INCLUDE_DIRS}) - ENDIF(MSVC) ENDIF(WITH_STLPORT) + + IF(MSVC) + FIND_PACKAGE(MSVC REQUIRED) + FIND_PACKAGE(WindowsSDK REQUIRED) + ENDIF(MSVC) ENDMACRO(SETUP_EXTERNAL) diff --git a/code/nel/CMakeLists.txt b/code/nel/CMakeLists.txt index 745278cd7..53bf071e3 100644 --- a/code/nel/CMakeLists.txt +++ b/code/nel/CMakeLists.txt @@ -41,6 +41,14 @@ IF(WITH_GTK) FIND_PACKAGE(GTK2) ENDIF(WITH_GTK) +IF(WITH_LIBOVR) + FIND_PACKAGE(LibOVR) +ENDIF(WITH_LIBOVR) + +IF(WITH_LIBVR) + FIND_PACKAGE(LibVR) +ENDIF(WITH_LIBVR) + IF(WITH_INSTALL_LIBRARIES) IF(UNIX) SET(prefix ${CMAKE_INSTALL_PREFIX}) @@ -68,7 +76,11 @@ IF(WITH_NEL_SAMPLES) ADD_SUBDIRECTORY(samples) ENDIF(WITH_NEL_SAMPLES) -IF(WITH_NEL_TOOLS) - FIND_PACKAGE(Squish) +# Allow to compile only max plugins without other tools. +IF(WITH_NEL_TOOLS OR WITH_NEL_MAXPLUGIN) + IF(WITH_NEL_TOOLS) + FIND_PACKAGE(Squish) + ENDIF(WITH_NEL_TOOLS) ADD_SUBDIRECTORY(tools) -ENDIF(WITH_NEL_TOOLS) +ENDIF(WITH_NEL_TOOLS OR WITH_NEL_MAXPLUGIN) + diff --git a/code/nel/include/nel/3d/anim_detail_trav.h b/code/nel/include/nel/3d/anim_detail_trav.h index 471ccd52b..7b51afe84 100644 --- a/code/nel/include/nel/3d/anim_detail_trav.h +++ b/code/nel/include/nel/3d/anim_detail_trav.h @@ -71,7 +71,7 @@ public: // For clipTrav. cleared at beginning of CClipTrav::traverse void clearVisibleList(); - // For ClipTrav only. NB: list is cleared at begining of traverse(). NB: only CTransform are supported + // For ClipTrav only. NB: list is cleared at begininng of traverse(). NB: only CTransform are supported void addVisibleModel(CTransform *model) { _VisibleList[_CurrentNumVisibleModels]= model; diff --git a/code/nel/include/nel/3d/bloom_effect.h b/code/nel/include/nel/3d/bloom_effect.h index 77673741c..c10967254 100644 --- a/code/nel/include/nel/3d/bloom_effect.h +++ b/code/nel/include/nel/3d/bloom_effect.h @@ -138,6 +138,8 @@ private: NLMISC::CSmartPtr _BlurFinalTex; // used as render target in first blur pass, and as displayed texture on second blur pass. NLMISC::CSmartPtr _BlurHorizontalTex; + // original render target + NLMISC::CSmartPtr _OriginalRenderTarget; // materials diff --git a/code/nel/include/nel/3d/camera.h b/code/nel/include/nel/3d/camera.h index 431998f8a..3185dfe7b 100644 --- a/code/nel/include/nel/3d/camera.h +++ b/code/nel/include/nel/3d/camera.h @@ -68,7 +68,7 @@ public: class CCamera : public CTransform { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); diff --git a/code/nel/include/nel/3d/clip_trav.h b/code/nel/include/nel/3d/clip_trav.h index e892ee02e..10dd9dccb 100644 --- a/code/nel/include/nel/3d/clip_trav.h +++ b/code/nel/include/nel/3d/clip_trav.h @@ -93,7 +93,7 @@ public: /// \name Visible List mgt. Those visible models are updated each traverse(). //@{ - // NB: list is cleared at begining of traverse(). + // NB: list is cleared at beginning of traverse(). void addVisibleModel(CTransform *model) { model->_IndexInVisibleList= _CurrentNumVisibleModels; diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index d090d77da..3eb5823ca 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -26,10 +26,12 @@ #include "nel/misc/uv.h" #include "nel/misc/hierarchical_timer.h" #include "nel/3d/texture.h" -#include "nel/3d/shader.h" #include "nel/3d/vertex_buffer.h" #include "nel/3d/index_buffer.h" #include "nel/3d/vertex_program.h" +#include "nel/3d/pixel_program.h" +#include "nel/3d/geometry_program.h" +#include "nel/3d/gpu_program_params.h" #include "nel/3d/material.h" #include "nel/misc/mutex.h" #include "nel/3d/primitive_profile.h" @@ -119,9 +121,9 @@ public: static const uint32 InterfaceVersion; public: - enum TMessageBoxId { okId=0, yesId, noId, abortId, retryId, cancelId, ignoreId, idCount }; - enum TMessageBoxType { okType=0, okCancelType, yesNoType, abortRetryIgnoreType, yesNoCancelType, retryCancelType, typeCount }; - enum TMessageBoxIcon { noIcon=0, handIcon, questionIcon, exclamationIcon, asteriskIcon, warningIcon, errorIcon, informationIcon, stopIcon, iconCount }; + enum TMessageBoxId { okId = 0, yesId, noId, abortId, retryId, cancelId, ignoreId, idCount }; + enum TMessageBoxType { okType = 0, okCancelType, yesNoType, abortRetryIgnoreType, yesNoCancelType, retryCancelType, typeCount }; + enum TMessageBoxIcon { noIcon = 0, handIcon, questionIcon, exclamationIcon, asteriskIcon, warningIcon, errorIcon, informationIcon, stopIcon, iconCount }; enum TCullMode { CCW = 0, CW }; enum TStencilOp { keep = 0, zero, replace, incr, decr, invert }; enum TStencilFunc { never = 0, less, lessequal, equal, notequal, greaterequal, greater, always}; @@ -131,117 +133,225 @@ public: * * \see setPolygonMode, getPolygonMode */ - enum TPolygonMode { Filled=0, Line, Point }; - + enum TPolygonMode { Filled = 0, Line, Point }; /** * Driver Max matrix count. * Kept for backward compatibility. Suppose any Hardware VertexProgram can handle only 16 matrix * */ - enum TMatrixCount { MaxModelMatrix= 16 }; + enum TMatrixCount { MaxModelMatrix = 16 }; + enum TMatrix + { + ModelView= 0, + Projection, + ModelViewProjection, + NumMatrix + }; + + enum TTransform + { + Identity=0, + Inverse, + Transpose, + InverseTranspose, + NumTransform + }; + + enum TProgram + { + VertexProgram = 0, + PixelProgram = 1, + GeometryProgram = 2 + }; protected: + CSynchronized _SyncTexDrvInfos; + TTexDrvSharePtrList _TexDrvShares; + TMatDrvInfoPtrList _MatDrvInfos; + TVBDrvInfoPtrList _VBDrvInfos; + TIBDrvInfoPtrList _IBDrvInfos; + TGPUPrgDrvInfoPtrList _GPUPrgDrvInfos; - CSynchronized _SyncTexDrvInfos; - - TTexDrvSharePtrList _TexDrvShares; - TMatDrvInfoPtrList _MatDrvInfos; - TVBDrvInfoPtrList _VBDrvInfos; - TIBDrvInfoPtrList _IBDrvInfos; TPolygonMode _PolygonMode; - TVtxPrgDrvInfoPtrList _VtxPrgDrvInfos; - TShaderDrvInfoPtrList _ShaderDrvInfos; uint _ResetCounter; public: - IDriver(void); - virtual ~IDriver(void); + IDriver(); + virtual ~IDriver(); - virtual bool init (uint windowIcon = 0, emptyProc exitFunc = 0)=0; + virtual bool init(uint windowIcon = 0, emptyProc exitFunc = 0) = 0; + + /// Deriver should calls IDriver::release() first, to destroy all driver components (textures, shaders, VBuffers). + virtual bool release(); + + /// Before rendering via a driver in a thread, must activate() (per thread). + virtual bool activate() = 0; // Test if the device is lost. Can only happen with D3D. // The calling application may skip some part of its rendering when it is the case (this is not a requirement, but may save cpu for other applications) virtual bool isLost() const = 0; + /// Return true if driver is still active. Return false else. If he user close the window, must return false. + virtual bool isActive() = 0; + + + + /** Return the driver reset counter. + * The reset counter is incremented at each driver reset. + */ + uint getResetCounter() const { return _ResetCounter; } + + // get the number of call to swapBuffer since the driver was created + virtual uint64 getSwapBufferCounter() const = 0; + + + /// \name Disable Hardware Feature /** Disable some Feature that may be supported by the Hardware * Call before setDisplay() to work properly */ // @{ - virtual void disableHardwareVertexProgram()=0; - virtual void disableHardwareVertexArrayAGP()=0; - virtual void disableHardwareTextureShader()=0; + virtual void disableHardwareVertexProgram() = 0; + virtual void disableHardwarePixelProgram() = 0; + virtual void disableHardwareVertexArrayAGP() = 0; + virtual void disableHardwareTextureShader() = 0; // @} + + + /// \name Windowing + // @{ // first param is the associated window. // Must be a HWND for Windows (WIN32). - virtual bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show = true, bool resizeable = true) throw(EBadDisplay)=0; + virtual bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show = true, bool resizeable = true) throw(EBadDisplay) = 0; // Must be called after a setDisplay that initialize the mode - virtual bool setMode(const GfxMode& mode)=0; - virtual bool getModes(std::vector &modes)=0; + virtual bool setMode(const GfxMode &mode) = 0; + virtual bool getModes(std::vector &modes) = 0; /// Set the title of the NeL window - virtual void setWindowTitle(const ucstring &title)=0; - + virtual void setWindowTitle(const ucstring &title) = 0; /// Set icon(s) of the NeL window - virtual void setWindowIcon(const std::vector &bitmaps)=0; - + virtual void setWindowIcon(const std::vector &bitmaps) = 0; /// Set the position of the NeL window - virtual void setWindowPos(sint32 x, sint32 y)=0; - + virtual void setWindowPos(sint32 x, sint32 y) = 0; /// Show or hide the NeL window - virtual void showWindow(bool show)=0; + virtual void showWindow(bool show) = 0; /// return the current screen mode (if we are in windowed, return the screen mode behind the window) - virtual bool getCurrentScreenMode(GfxMode &mode)=0; + virtual bool getCurrentScreenMode(GfxMode &mode) = 0; /// enter/leave the dialog mode - virtual void beginDialogMode() =0; - virtual void endDialogMode() =0; + virtual void beginDialogMode() = 0; + virtual void endDialogMode() = 0; // Return is the associated window information. (Implementation dependent) // Must be a HWND for Windows (WIN32). - virtual nlWindow getDisplay() =0; + virtual nlWindow getDisplay() = 0; - /** - * Setup monitor color properties. - * - * Return false if setup failed. - */ - virtual bool setMonitorColorProperties (const CMonitorColorProperties &properties) = 0; + /// Setup monitor color properties. Return false if setup failed + virtual bool setMonitorColorProperties(const CMonitorColorProperties &properties) = 0; // Return is the associated default window proc for the driver. (Implementation dependent) // Must be a void GlWndProc(IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) for Windows (WIN32). virtual emptyProc getWindowProc() = 0; - /// Before rendering via a driver in a thread, must activate() (per thread). - virtual bool activate(void) = 0; + virtual NLMISC::IEventEmitter *getEventEmitter() = 0; + + /// Copy a string to system clipboard. + virtual bool copyTextToClipboard(const ucstring &text) = 0; - /// Get the number of texture stage available, for multi texturing (Normal material shaders). Valid only after setDisplay(). - virtual uint getNbTextureStages() const = 0; + /// Paste a string from system clipboard. + virtual bool pasteTextFromClipboard(ucstring &text) = 0;/// Return the depth of the driver after init(). - /** is the texture is set up in the driver - * NB: this method is thread safe. - */ - virtual bool isTextureExist(const ITexture&tex)=0; + virtual uint8 getBitPerPixel() = 0; - virtual NLMISC::IEventEmitter* getEventEmitter(void) = 0; + /** Output a system message box and print a message with an icon. This method can be call even if the driver is not initialized. + * This method is used to return internal driver problem when string can't be displayed in the driver window. + * If the driver can't open a messageBox, it should not override this method and let the IDriver class manage it with the ASCII console. + * + * \param message This is the message to display in the message box. + * \param title This is the title of the message box. + * \param type This is the type of the message box, ie number of button and label of buttons. + * \param icon This is the icon of the message box should use like warning, error etc... + */ + virtual TMessageBoxId systemMessageBox(const char *message, const char *title, TMessageBoxType type = okType, TMessageBoxIcon icon = noIcon); - /* Clear the current target surface pixels. The function ignores the viewport settings but uses the scissor. */ + /// Get the width and the height of the window + virtual void getWindowSize(uint32 &width, uint32 &height) = 0; + + /// Get the position of the window always (0,0) in fullscreen + virtual void getWindowPos(sint32 &x, sint32 &y) = 0; + // @} + + + + /// \name Framebuffer operations + // @{ + /// Clear the current target surface pixels. The function ignores the viewport settings but uses the scissor. virtual bool clear2D(CRGBA rgba) = 0; - /* Clear the current target surface zbuffer. The function ignores the viewport settings but uses the scissor. */ + /// Clear the current target surface zbuffer. The function ignores the viewport settings but uses the scissor. virtual bool clearZBuffer(float zval=1) = 0; - /* Clear the current target surface stencil buffer. The function ignores the viewport settings but uses the scissor. */ + /// Clear the current target surface stencil buffer. The function ignores the viewport settings but uses the scissor. virtual bool clearStencilBuffer(float stencilval=0) = 0; /// Set the color mask filter through where the operation done will pass - virtual void setColorMask (bool bRed, bool bGreen, bool bBlue, bool bAlpha) = 0; + virtual void setColorMask(bool bRed, bool bGreen, bool bBlue, bool bAlpha) = 0; + // @} + + + /// \name Copy framebuffer to memory + // @{ + /** get the RGBA back buffer. After swapBuffers(), the content of the back buffer is undefined. + * + * \param bitmap the buffer will be written in this bitmap + */ + virtual void getBuffer(CBitmap &bitmap) = 0; + + /** get the ZBuffer (back buffer). + * + * \param zbuffer the returned array of Z. size of getWindowSize() . + */ + virtual void getZBuffer(std::vector &zbuffer) = 0; + + /** get a part of the RGBA back buffer. After swapBuffers(), the content of the back buffer is undefined. + * NB: 0,0 is the bottom left corner of the screen. + * + * \param bitmap the buffer will be written in this bitmap + * \param rect the in/out (wanted/clipped) part of Color buffer to retrieve. + */ + virtual void getBufferPart(CBitmap &bitmap, NLMISC::CRect &rect) = 0; + + /** get a part of the ZBuffer (back buffer). + * NB: 0,0 is the bottom left corner of the screen. + * + * \param zbuffer the returned array of Z. size of rec.Width*rec.Height. + * \param rect the in/out (wanted/clipped) part of ZBuffer to retrieve. + */ + virtual void getZBufferPart(std::vector &zbuffer, NLMISC::CRect &rect) = 0; + // @} + + + + /// \name Copy memory to framebuffer + // @{ + /** fill the RGBA back buffer + * + * \param bitmap will be written in the buffer. no-op if bad size. + * \return true if success + */ + virtual bool fillBuffer(CBitmap &bitmap) = 0; + // @} + + + + /// \name Viewport depth clipping + // @{ /** Set depth range. Depth range specify a linear mapping from device z coordinates (in the [-1, 1] range) to window coordinates (in the [0, 1] range) * This mapping occurs after clipping of primitives and division by w of vertices coordinates. * Default depth range is [0, 1]. @@ -250,11 +360,20 @@ public: virtual void setDepthRange(float znear, float zfar) = 0; // Get the current depth range virtual void getDepthRange(float &znear, float &zfar) const = 0; + // @} + + + /// \name Textures + // @{ + /** is the texture is set up in the driver + * NB: this method is thread safe. + */ + virtual bool isTextureExist(const ITexture &tex) = 0; /** setup a texture, generate and upload if needed. same as setupTextureEx(tex, true, dummy); */ - virtual bool setupTexture(ITexture& tex) = 0; + virtual bool setupTexture(ITexture &tex) = 0; /** setup a texture in the driver. * \param bUpload if true the texture is created and uploaded to VRAM, if false the texture is only created @@ -267,64 +386,81 @@ public: * is only bound to tex (thus creating and uploading nothing) * NB: the texture must be at least touch()-ed for the recreate to work. */ - virtual bool setupTextureEx (ITexture& tex, bool bUpload, bool& bAllUploaded, - bool bMustRecreateSharedTexture= false) = 0; + virtual bool setupTextureEx( ITexture &tex, bool bUpload, bool &bAllUploaded, + bool bMustRecreateSharedTexture = false) = 0; /** The texture must be created or uploadTexture do nothing. * These function can be used to upload piece by piece a texture. Use it in conjunction with setupTextureEx(..., false); * For compressed textures, the rect must aligned on pixel block. (a block of pixel size is 4x4 pixels). */ - virtual bool uploadTexture (ITexture& tex, NLMISC::CRect& rect, uint8 nNumMipMap) = 0; - virtual bool uploadTextureCube (ITexture& tex, NLMISC::CRect& rect, uint8 nNumMipMap, uint8 nNumFace) = 0; + virtual bool uploadTexture(ITexture &tex, NLMISC::CRect &rect, uint8 nNumMipMap) = 0; + virtual bool uploadTextureCube(ITexture &tex, NLMISC::CRect &rect, uint8 nNumMipMap, uint8 nNumFace) = 0; /** * Invalidate shared texture */ - bool invalidateShareTexture (ITexture &); + bool invalidateShareTexture(ITexture &); /** * Get the driver share texture name */ - static void getTextureShareName (const ITexture& tex, std::string &output); + static void getTextureShareName(const ITexture &tex, std::string &output); /** if true force all the uncompressed RGBA 32 bits and RGBA 24 bits texture to be DXTC5 compressed. * Do this only during upload if ITexture::allowDegradation() is true and if ITexture::UploadFormat is "Automatic" * and if bitmap format is RGBA. */ - virtual void forceDXTCCompression(bool dxtcComp)=0; + virtual void forceDXTCCompression(bool dxtcComp) = 0; /** if different from 0, enable anisotropic filter on textures. -1 enables max value. * Default is 0. */ - virtual void setAnisotropicFilter(sint filter)=0; + virtual void setAnisotropicFilter(sint filter) = 0; /** if !=1, force mostly all the textures (but TextureFonts lightmaps, interfaces etc..) * to be divided by Divisor (2, 4, 8...) * Default is 1. * NB: this is done only on TextureFile */ - virtual void forceTextureResize(uint divisor)=0; + virtual void forceTextureResize(uint divisor) = 0; - /** Sets enforcement of native fragment programs. This is by default enabled. - * - * \param nativeOnly If set to false, fragment programs don't need to be native to stay loaded, - * otherwise (aka if true) they will be purged. + /** Get the number of texture stage available, for multi texturing (Normal material shaders). Valid only after setDisplay(). */ - virtual void forceNativeFragmentPrograms(bool nativeOnly) = 0; + virtual uint getNbTextureStages() const = 0; - - virtual bool setupMaterial(CMaterial& mat)=0; - - /** - * Activate a shader, NULL to disable the current shader. + /** Get max number of per stage constant that can be used simultaneously. + * This will usually match the number of texture stages, but with a D3D driver, this feature is not available most of the time + * so it is emulated. If pixel shaders are available this will be fully supported. + * Under OpenGL this simply returns the maximum number of texture stages (getNbTextureStages) in both return values. */ - virtual bool activeShader(CShader *shd)=0; + virtual void getNumPerStageConstant(uint &lightedMaterial, uint &unlightedMaterial) const = 0; + + // [DEPRECATED] Return if this texture is a rectangle texture that requires RECT sampler (OpenGL specific pre-NPOT functionality) + virtual bool isTextureRectangle(ITexture *tex) const = 0; + + // Return true if driver support non-power of two textures + virtual bool supportNonPowerOfTwoTextures() const = 0; + // @} + + + + /// \name Texture operations + // @{ + // copy the first texture in a second one of different dimensions + virtual bool stretchRect(ITexture *srcText, NLMISC::CRect &srcRect, ITexture *destText, NLMISC::CRect &destRect) = 0; + // @} + + + + /// \name Material + // @{ + virtual bool setupMaterial(CMaterial &mat) = 0; /** Special for Faster Specular Setup. Call this between lot of primitives rendered with Specular Materials. * Visual Errors may arise if you don't correctly call endSpecularBatch(). */ - virtual void startSpecularBatch()=0; - virtual void endSpecularBatch()=0; + virtual void startSpecularBatch() = 0; + virtual void endSpecularBatch() = 0; /// \name Material multipass. /** NB: setupMaterial() must be called before those methods. @@ -332,18 +468,26 @@ public: * NB: Other render calls performs the needed setup automatically */ // @{ - /// init multipass for _CurrentMaterial. return number of pass required to render this material. - virtual sint beginMaterialMultiPass() = 0; - /// active the ith pass of this material. - virtual void setupMaterialPass(uint pass) = 0; - /// end multipass for this material. - virtual void endMaterialMultiPass() = 0; + /// init multipass for _CurrentMaterial. return number of pass required to render this material. + virtual sint beginMaterialMultiPass() = 0; + /// active the ith pass of this material. + virtual void setupMaterialPass(uint pass) = 0; + /// end multipass for this material. + virtual void endMaterialMultiPass() = 0; // @} + // Does the driver support the per-pixel lighting shader ? + virtual bool supportPerPixelLighting(bool specular) const = 0; + // @} + + + + /// \name Camera + // @{ // Setup the camera mode as a perspective/ortho camera. NB: znear and zfar must be >0 (if perspective). - virtual void setFrustum(float left, float right, float bottom, float top, float znear, float zfar, bool perspective=true)=0; - virtual void setFrustumMatrix(CMatrix &frust)=0; - virtual CMatrix getFrustumMatrix()=0; + virtual void setFrustum(float left, float right, float bottom, float top, float znear, float zfar, bool perspective = true) = 0; + virtual void setFrustumMatrix(CMatrix &frust) = 0; + virtual CMatrix getFrustumMatrix() = 0; virtual float getClipSpaceZMin() const = 0; @@ -351,7 +495,7 @@ public: * * NB: you must setupViewMatrix() BEFORE setupModelMatrix(), or else undefined results. */ - virtual void setupViewMatrix(const CMatrix& mtx)=0; + virtual void setupViewMatrix(const CMatrix &mtx)=0; /** setup the view matrix (inverse of camera matrix). * Extended: give a cameraPos (mtx.Pos() is not taken into account but for getViewMatrix()), @@ -365,38 +509,40 @@ public: * \param mtx the same view matrix (still with correct "inversed" camera position) as if passed in setupViewMatrix() * \param cameraPos position of the camera (before inversion, ie mtx.getPos()!=cameraPos ). */ - virtual void setupViewMatrixEx(const CMatrix& mtx, const CVector &cameraPos)=0; + virtual void setupViewMatrixEx(const CMatrix &mtx, const CVector &cameraPos) = 0; /** setup the model matrix. * * NB: you must setupModelMatrix() AFTER setupViewMatrix(), or else undefined results. */ - virtual void setupModelMatrix(const CMatrix& mtx)=0; + virtual void setupModelMatrix(const CMatrix &mtx) = 0; - virtual CMatrix getViewMatrix(void)const=0; + virtual CMatrix getViewMatrix() const = 0; + // @} + + /// \name Fixed pipeline vertex program + // @{ /** Force input normal to be normalized by the driver. default is false. * NB: driver force the normalization himself if: * - current Model matrix has a scale. */ - virtual void forceNormalize(bool normalize)=0; + virtual void forceNormalize(bool normalize) = 0; /** return the forceNormalize() state. */ - virtual bool isForceNormalize() const =0; + virtual bool isForceNormalize() const = 0; + // @} + - /** Get max number of per stage constant that can be used simultaneously. - * This will usually match the number of texture stages, but with a D3D driver, this feature is not available most of the time - * so it is emulated. If pixel shaders are available this will be fully supported. - */ - virtual void getNumPerStageConstant(uint &lightedMaterial, uint &unlightedMaterial) const = 0; - + /// \name Vertex Buffer Hard: Features + // @{ /** return true if driver support VertexBufferHard. */ - virtual bool supportVertexBufferHard() const =0; + virtual bool supportVertexBufferHard() const = 0; /** return true if volatile vertex buffer are supported. (e.g a vertex buffer which can be created with the flag CVertexBuffer::AGPVolatile or CVertexBuffer::RAMVolatile) * If these are not supported, a RAM vb is created instead (transparent to user) @@ -410,9 +556,13 @@ public: /** return true if driver support VertexBufferHard, but vbHard->unlock() are slow (ATI-openGL). */ - virtual bool slowUnlockVertexBufferHard() const =0; + virtual bool slowUnlockVertexBufferHard() const = 0; + // @} + + /// \name Vertex Buffer Hard: Settings + // @{ /* Returns true if static vertex and index buffers must by allocated in VRAM, false in AGP. * Default is false. */ @@ -423,16 +573,15 @@ public: */ void setStaticMemoryToVRAM(bool staticMemoryToVRAM); - /** Return the driver reset counter. - * The reset counter is incremented at each driver reset. - */ - uint getResetCounter () const { return _ResetCounter; } - /** return How many vertices VertexBufferHard support */ - virtual uint getMaxVerticesByVertexBufferHard() const =0; + virtual uint getMaxVerticesByVertexBufferHard() const = 0; + // @} + + /// \name Vertex Buffer Hard + // @{ /** Allocate the initial VertexArray Memory. (no-op if !supportVertexBufferHard()). * VertexArrayRange is first reseted, so any VBhard created before will be deleted. * NB: call it after setDisplay(). But setDisplay() by default call initVertexBufferHard(16Mo, 0); @@ -442,17 +591,21 @@ public: * \param vramMem amount of VRAM Memory required. if 0, reseted. * \return false if one the Buffer has not been allocated (at least at 500K). */ - virtual bool initVertexBufferHard(uint agpMem, uint vramMem=0) =0; + virtual bool initVertexBufferHard(uint agpMem, uint vramMem = 0) = 0; /** Return the amount of AGP memory allocated by initVertexBufferHard() to store vertices. */ - virtual uint32 getAvailableVertexAGPMemory () =0; + virtual uint32 getAvailableVertexAGPMemory() = 0; /** Return the amount of video memory allocated by initVertexBufferHard() to store vertices. */ - virtual uint32 getAvailableVertexVRAMMemory () =0; + virtual uint32 getAvailableVertexVRAMMemory() = 0; + // @} + + /// \name Vertex Buffer Objects + // @{ /** active a current VB, for future render(). * This method suppose that all vertices in the VB will be used. * @@ -462,30 +615,33 @@ public: * * \see activeVertexProgram */ - virtual bool activeVertexBuffer(CVertexBuffer& VB)=0; - + virtual bool activeVertexBuffer(CVertexBuffer &VB) = 0; /** active a current IB, for future render(). * * Don't change the index buffer format/size after having activated it. * Don't lock the index buffer after having activated it. */ - virtual bool activeIndexBuffer(CIndexBuffer& IB)=0; + virtual bool activeIndexBuffer(CIndexBuffer &IB) = 0; + // @} + + /// \name Rendering + // @{ /** Render a list of indexed lines with previously setuped VertexBuffer / IndexBuffer / Matrixes. * \param mat is the material to use during this rendering * \param firstIndex is the first index in the index buffer to use as first line. * \param nlines is the number of line to render. */ - virtual bool renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines)=0; + virtual bool renderLines(CMaterial &mat, uint32 firstIndex, uint32 nlines) = 0; /** Render a list of indexed triangles with previously setuped VertexBuffer / IndexBuffer / Matrixes. * \param mat is the material to use during this rendering * \param firstIndex is the first index in the index buffer to use as first triangle. * \param ntris is the number of triangle to render. */ - virtual bool renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris)=0; + virtual bool renderTriangles(CMaterial &mat, uint32 firstIndex, uint32 ntris) = 0; /** Render a list of triangles with previously setuped VertexBuffer / IndexBuffer / Matrixes, AND previously setuped MATERIAL!! * This use the last material setuped. It should be a "Normal shader" material, because no multi-pass is allowed @@ -496,7 +652,7 @@ public: * \param firstIndex is the first index in the index buffer to use as first triangle. * \param ntris is the number of triangle to render. */ - virtual bool renderSimpleTriangles(uint32 firstIndex, uint32 ntris)=0; + virtual bool renderSimpleTriangles(uint32 firstIndex, uint32 ntris) = 0; /** Render points with previously setuped VertexBuffer / Matrixes. * Points are stored as a sequence in the vertex buffer. @@ -504,7 +660,7 @@ public: * \param startVertex is the first vertex to use during this rendering. * \param numPoints is the number of point to render. */ - virtual bool renderRawPoints(CMaterial& mat, uint32 startVertex, uint32 numPoints)=0; + virtual bool renderRawPoints(CMaterial &mat, uint32 startVertex, uint32 numPoints) = 0; /** Render lines with previously setuped VertexBuffer / Matrixes. * Lines are stored as a sequence in the vertex buffer. @@ -512,7 +668,7 @@ public: * \param startVertex is the first vertex to use during this rendering. * \param numLine is the number of line to render. */ - virtual bool renderRawLines(CMaterial& mat, uint32 startVertex, uint32 numTri)=0; + virtual bool renderRawLines(CMaterial &mat, uint32 startVertex, uint32 numTri) = 0; /** Render triangles with previously setuped VertexBuffer / Matrixes. * Triangles are stored as a sequence in the vertex buffer. @@ -520,15 +676,15 @@ public: * \param startVertex is the first vertex to use during this rendering. * \param numTri is the number of triangle to render. */ - virtual bool renderRawTriangles(CMaterial& mat, uint32 startVertex, uint32 numTri)=0; + virtual bool renderRawTriangles(CMaterial &mat, uint32 startVertex, uint32 numTri) = 0; /** If the driver support it, primitive can be rendered with an offset added to each index * These are the offseted version of the 'render' functions * \see supportIndexOffset */ - virtual bool renderLinesWithIndexOffset(CMaterial& mat, uint32 firstIndex, uint32 nlines, uint indexOffset)=0; - virtual bool renderTrianglesWithIndexOffset(CMaterial& mat, uint32 firstIndex, uint32 ntris, uint indexOffset)=0; - virtual bool renderSimpleTrianglesWithIndexOffset(uint32 firstIndex, uint32 ntris, uint indexOffset)=0; + virtual bool renderLinesWithIndexOffset(CMaterial &mat, uint32 firstIndex, uint32 nlines, uint indexOffset) = 0; + virtual bool renderTrianglesWithIndexOffset(CMaterial &mat, uint32 firstIndex, uint32 ntris, uint indexOffset) = 0; + virtual bool renderSimpleTrianglesWithIndexOffset(uint32 firstIndex, uint32 ntris, uint indexOffset) = 0; /** render quads with previously setuped VertexBuffer / Matrixes. @@ -545,8 +701,13 @@ public: * \param startVertex is the first vertex to use during this rendering. * \param numQuad is the number of quad to render. */ - virtual bool renderRawQuads(CMaterial& mat, uint32 startVertex, uint32 numQuads)=0; + virtual bool renderRawQuads(CMaterial &mat, uint32 startVertex, uint32 numQuads) = 0; + // @} + + + /// \name Texture coordinates fixed pipeline + // @{ /** Say what Texture Stage use what UV coord. * by default activeVertexBuffer*() methods map all stage i to UV i. You can change this behavior, * after calling activeVertexBuffer*(), by using this method. @@ -558,63 +719,58 @@ public: * Warning!: some CMaterial Shader may change automatically this behavior too when setupMaterial() * (and so render*()) is called. But Normal shader doesn't do it. */ - virtual void mapTextureStageToUV(uint stage, uint uv)=0; + virtual void mapTextureStageToUV(uint stage, uint uv) = 0; + // @} + + + /// \name Buffer swapping + // @{ /// Swap the back and front buffers. - virtual bool swapBuffers(void)=0; - - /// Copy a string to system clipboard. - virtual bool copyTextToClipboard(const ucstring &text) =0; - - /// Paste a string from system clipboard. - virtual bool pasteTextFromClipboard(ucstring &text) =0; + virtual bool swapBuffers() = 0; /** set the number of VBL wait when a swapBuffers() is issued. 0 means no synchronisation to the VBL * Default is 1. Values >1 may be clamped to 1 by the driver. */ - virtual void setSwapVBLInterval(uint interval)=0; + virtual void setSwapVBLInterval(uint interval) = 0; /// get the number of VBL wait when a swapBuffers() is issued. 0 means no synchronisation to the VBL - virtual uint getSwapVBLInterval()=0; + virtual uint getSwapVBLInterval() = 0; + // @} + + + /// \name Profiling. // @{ - - /** Get the number of primitives rendered from the last swapBuffers() call. * \param pIn the number of requested rendered primitive. * \param pOut the number of effective rendered primitive. pOut==pIn if no multi-pass material is used * (Lightmap, Specular ...). */ - virtual void profileRenderedPrimitives(CPrimitiveProfile &pIn, CPrimitiveProfile &pOut) =0; - + virtual void profileRenderedPrimitives(CPrimitiveProfile &pIn, CPrimitiveProfile &pOut) = 0; /** Return the amount of Texture memory requested. taking mipmap, compression, texture format, etc... into account. * NB: because of GeForce*, RGB888 is considered to be 32 bits. So it may be false for others cards :). */ - virtual uint32 profileAllocatedTextureMemory() =0; - + virtual uint32 profileAllocatedTextureMemory() = 0; /** Get the number of material setuped from the last swapBuffers() call. */ - virtual uint32 profileSetupedMaterials() const =0; - + virtual uint32 profileSetupedMaterials() const = 0; /** Get the number of matrix setuped from the last swapBuffers() call. */ - virtual uint32 profileSetupedModelMatrix() const =0; - + virtual uint32 profileSetupedModelMatrix() const = 0; /** Enable the sum of texture memory used since last swapBuffers() call. To retrieve the memory used call getUsedTextureMemory(). */ - virtual void enableUsedTextureMemorySum (bool enable=true) =0; - + virtual void enableUsedTextureMemorySum (bool enable = true) = 0; /** Return the amount of texture video memory used since last swapBuffers() call. Before use this method, you should enable * the sum with enableUsedTextureMemorySum(). */ - virtual uint32 getUsedTextureMemory() const =0; - + virtual uint32 getUsedTextureMemory() const = 0; /** If the driver support it, enable profile VBHard locks. * No-Op if already profiling @@ -643,179 +799,126 @@ public: /** For each texture setuped in the driver, "print" result: type, shareName, format and size (mipmap included) */ void profileTextureUsage(std::vector &result); - // @} + /// \name Fog support. // @{ - virtual bool fogEnabled()=0; - virtual void enableFog(bool enable)=0; + virtual bool fogEnabled() = 0; + virtual void enableFog(bool enable = true) = 0; /// setup fog parameters. fog must enabled to see result. start and end are distance values. - virtual void setupFog(float start, float end, CRGBA color)=0; + virtual void setupFog(float start, float end, NLMISC::CRGBA color) = 0; /// Get. - virtual float getFogStart() const =0; - virtual float getFogEnd() const =0; - virtual CRGBA getFogColor() const =0; + virtual float getFogStart() const = 0; + virtual float getFogEnd() const = 0; + virtual NLMISC::CRGBA getFogColor() const = 0; // @} - /// Deriver should calls IDriver::release() first, to destroy all driver components (textures, shaders, VBuffers). - virtual bool release(void); - /// Return true if driver is still active. Return false else. If he user close the window, must return false. - virtual bool isActive()=0; - - /// Return the depth of the driver after init(). - virtual uint8 getBitPerPixel ()=0; - - /** Output a system message box and print a message with an icon. This method can be call even if the driver is not initialized. - * This method is used to return internal driver problem when string can't be displayed in the driver window. - * If the driver can't open a messageBox, it should not override this method and let the IDriver class manage it with the ASCII console. - * - * \param message This is the message to display in the message box. - * \param title This is the title of the message box. - * \param type This is the type of the message box, ie number of button and label of buttons. - * \param icon This is the icon of the message box should use like warning, error etc... - */ - virtual TMessageBoxId systemMessageBox (const char* message, const char* title, TMessageBoxType type=okType, TMessageBoxIcon icon=noIcon); + /// \name Viewport + // @{ /** Set the current viewport * * \param viewport is a viewport to setup as current viewport. */ - virtual void setupViewport (const class CViewport& viewport)=0; + virtual void setupViewport(const class CViewport &viewport) = 0; /** Get the current viewport */ virtual void getViewport(CViewport &viewport) = 0; - /** Set the current Scissor. * \param scissor is a scissor to setup the current Scissor, in Window relative coordinate (0,1). */ - virtual void setupScissor (const class CScissor& scissor)=0; + virtual void setupScissor(const class CScissor &scissor) = 0; + // @} + + /// \name Driver information + // @{ /** * Get the driver version. Not the same than interface version. Incremented at each implementation change. * * \see InterfaceVersion */ - virtual uint32 getImplementationVersion () const = 0; + virtual uint32 getImplementationVersion() const = 0; /** * Get driver information. * get the nel name of the driver (ex: "Opengl 1.2 NeL Driver") */ - virtual const char* getDriverInformation () = 0; + virtual const char *getDriverInformation() = 0; /** * Get videocard information. * get the official name of the driver */ - virtual const char* getVideocardInformation () = 0; + virtual const char *getVideocardInformation () = 0; + // @} + + /// \name Mouse / Keyboard / Game devices // @{ - /// show cursor if b is true, or hide it if b is false - virtual void showCursor (bool b) = 0; + /// show cursor if b is true, or hide it if b is false + virtual void showCursor(bool b) = 0; - /// x and y must be between 0.0 and 1.0 - virtual void setMousePos (float x, float y) = 0; + /// x and y must be between 0.0 and 1.0 + virtual void setMousePos(float x, float y) = 0; - /** Enable / disable low level mouse. This allow to take advantage of some options (speed of the mouse, automatic wrapping) - * It returns a interface to these parameters when it is supported, or NULL otherwise - * The interface pointer is valid as long as the low level mouse is enabled. - * A call to disable the mouse returns NULL, and restore the default mouse behavior - * NB : - In this mode the mouse cursor isn't drawn. - * - Calls to showCursor have no effects - * - Calls to setCapture have no effects - */ - virtual NLMISC::IMouseDevice *enableLowLevelMouse(bool enable, bool exclusive) = 0; + /** Enable / disable low level mouse. This allow to take advantage of some options (speed of the mouse, automatic wrapping) + * It returns a interface to these parameters when it is supported, or NULL otherwise + * The interface pointer is valid as long as the low level mouse is enabled. + * A call to disable the mouse returns NULL, and restore the default mouse behavior + * NB : - In this mode the mouse cursor isn't drawn. + * - Calls to showCursor have no effects + * - Calls to setCapture have no effects + */ + virtual NLMISC::IMouseDevice *enableLowLevelMouse(bool enable, bool exclusive) = 0; - /** Enable / disable a low level keyboard. - * Such a keyboard can only send KeyDown and KeyUp event. It just consider the keyboard as a - * gamepad with lots of buttons... - * This returns a interface to some parameters when it is supported, or NULL otherwise. - * The interface pointer is valid as long as the low level keyboard is enabled. - * A call to disable the keyboard returns NULL, and restore the default keyboard behavior - */ - virtual NLMISC::IKeyboardDevice *enableLowLevelKeyboard(bool enable) = 0; + /** Enable / disable a low level keyboard. + * Such a keyboard can only send KeyDown and KeyUp event. It just consider the keyboard as a + * gamepad with lots of buttons... + * This returns a interface to some parameters when it is supported, or NULL otherwise. + * The interface pointer is valid as long as the low level keyboard is enabled. + * A call to disable the keyboard returns NULL, and restore the default keyboard behavior + */ + virtual NLMISC::IKeyboardDevice *enableLowLevelKeyboard(bool enable) = 0; - /** Get the delay in ms for mouse double clicks. - */ - virtual uint getDoubleClickDelay(bool hardwareMouse) = 0; + /** Get the delay in ms for mouse double clicks. + */ + virtual uint getDoubleClickDelay(bool hardwareMouse) = 0; - /** If true, capture the mouse to force it to stay under the window. - * NB : this has no effects if a low level mouse is used - */ - virtual void setCapture (bool b) = 0; + /** If true, capture the mouse to force it to stay under the window. + * NB : this has no effects if a low level mouse is used + */ + virtual void setCapture(bool b) = 0; - // see if system cursor is currently captured - virtual bool isSystemCursorCaptured() = 0; + // see if system cursor is currently captured + virtual bool isSystemCursorCaptured() = 0; - // Add a new cursor (name is case unsensitive) - virtual void addCursor(const std::string &name, const NLMISC::CBitmap &bitmap) = 0; + // Add a new cursor (name is case unsensitive) + virtual void addCursor(const std::string &name, const NLMISC::CBitmap &bitmap) = 0; - // Display a cursor from its name (case unsensitive) - virtual void setCursor(const std::string &name, NLMISC::CRGBA col, uint8 rot, sint hotSpotX, sint hotSpotY, bool forceRebuild = false) = 0; + // Display a cursor from its name (case unsensitive) + virtual void setCursor(const std::string &name, NLMISC::CRGBA col, uint8 rot, sint hotSpotX, sint hotSpotY, bool forceRebuild = false) = 0; - // Change default scale for all cursors - virtual void setCursorScale(float scale) = 0; + // Change default scale for all cursors + virtual void setCursorScale(float scale) = 0; - /** Check whether there is a low level device manager available, and get its interface. Return NULL if not available - * From this interface you can deal with mouse and keyboard as above, but you can also manage game device (joysticks, joypads ...) - */ - virtual NLMISC::IInputDeviceManager *getLowLevelInputDeviceManager() = 0; + /** Check whether there is a low level device manager available, and get its interface. Return NULL if not available + * From this interface you can deal with mouse and keyboard as above, but you can also manage game device (joysticks, joypads ...) + */ + virtual NLMISC::IInputDeviceManager *getLowLevelInputDeviceManager() = 0; // @} - /// Get the width and the height of the window - virtual void getWindowSize (uint32 &width, uint32 &height) = 0; - - /// Get the position of the window always (0,0) in fullscreen - virtual void getWindowPos (sint32 &x, sint32 &y) = 0; - - /** get the RGBA back buffer. After swapBuffers(), the content of the back buffer is undefined. - * - * \param bitmap the buffer will be written in this bitmap - */ - virtual void getBuffer (CBitmap &bitmap) = 0; - - /** get the ZBuffer (back buffer). - * - * \param zbuffer the returned array of Z. size of getWindowSize() . - */ - virtual void getZBuffer (std::vector &zbuffer) = 0; - - /** get a part of the RGBA back buffer. After swapBuffers(), the content of the back buffer is undefined. - * NB: 0,0 is the bottom left corner of the screen. - * - * \param bitmap the buffer will be written in this bitmap - * \param rect the in/out (wanted/clipped) part of Color buffer to retrieve. - */ - virtual void getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect) = 0; - - // copy the first texture in a second one of different dimensions - virtual bool stretchRect (ITexture * srcText, NLMISC::CRect &srcRect, ITexture * destText, NLMISC::CRect &destRect) = 0; - - // is this texture a rectangle texture ? - virtual bool isTextureRectangle(ITexture * tex) const = 0; - - // return true if driver support Bloom effect. - virtual bool supportBloomEffect() const =0; - - // return true if driver support non-power of two textures - virtual bool supportNonPowerOfTwoTextures() const =0; - - /** get a part of the ZBuffer (back buffer). - * NB: 0,0 is the bottom left corner of the screen. - * - * \param zbuffer the returned array of Z. size of rec.Width*rec.Height. - * \param rect the in/out (wanted/clipped) part of ZBuffer to retrieve. - */ - virtual void getZBufferPart (std::vector &zbuffer, NLMISC::CRect &rect) = 0; + /// \name Render target // TODO: Handle Color/ZBuffer/Stencil consistently + // @{ /** Set the current render target. * * The render target can be a texture (tex pointer) or the back buffer (tex = NULL). @@ -848,14 +951,22 @@ public: * \param cubaFace the face of the cube to copy texture to. * \return true if the render target has been changed */ - virtual bool setRenderTarget (ITexture *tex, - uint32 x = 0, - uint32 y = 0, - uint32 width = 0, - uint32 height = 0, - uint32 mipmapLevel = 0, - uint32 cubeFace = 0 - ) = 0 ; + virtual bool setRenderTarget( ITexture *tex, + uint32 x = 0, + uint32 y = 0, + uint32 width = 0, + uint32 height = 0, + uint32 mipmapLevel = 0, + uint32 cubeFace = 0 + ) = 0; + + virtual ITexture *getRenderTarget() const = 0; + + /** Retrieve the render target size. + * If the render target is the frame buffer, it returns the size of the frame buffer. + * It the render target is a texture, it returns the size of the texture mipmap selected as render target. + */ + virtual bool getRenderTargetSize (uint32 &width, uint32 &height) = 0; /** Trick method : copy the current texture target into another texture without updating the current texture. * @@ -883,30 +994,21 @@ public: * \param height height of the renderable area to copy, if 0, use the whole size. * \param mipmapLevel the mipmap to copy texture to. */ - virtual bool copyTargetToTexture (ITexture *tex, - uint32 offsetx = 0, - uint32 offsety = 0, - uint32 x = 0, - uint32 y = 0, - uint32 width = 0, - uint32 height = 0, - uint32 mipmapLevel = 0 + virtual bool copyTargetToTexture( ITexture *tex, + uint32 offsetx = 0, + uint32 offsety = 0, + uint32 x = 0, + uint32 y = 0, + uint32 width = 0, + uint32 height = 0, + uint32 mipmapLevel = 0 ) = 0; - - /** Retrieve the render target size. - * If the render target is the frame buffer, it returns the size of the frame buffer. - * It the render target is a texture, it returns the size of the texture mipmap selected as render target. - */ - virtual bool getRenderTargetSize (uint32 &width, uint32 &height) = 0; - - /** fill the RGBA back buffer - * - * \param bitmap will be written in the buffer. no-op if bad size. - * \return true if success - */ - virtual bool fillBuffer (CBitmap &bitmap) = 0; + // @} + + /// \name Render state: Polygon mode + // @{ /** Set the global polygon mode. Can be filled, line or point. The implementation driver must * call IDriver::setPolygonMode and active this mode. * @@ -918,13 +1020,27 @@ public: _PolygonMode=mode; } + /** Get the global polygon mode. + * + * \param polygon mode choose in this driver. + * \see setPolygonMode(), TPolygonMode + */ + TPolygonMode getPolygonMode () + { + return _PolygonMode; + } + // @} + + + /// \name Fixed pipeline lights + // @{ /** * return the number of light supported by driver. typically 8. * * \see enableLight() setLight() */ - virtual uint getMaxLight () const = 0; + virtual uint getMaxLight() const = 0; /** * Setup a light. @@ -935,7 +1051,7 @@ public: * \param light is a light to set in this slot. * \see enableLight() */ - virtual void setLight (uint8 num, const CLight& light) = 0; + virtual void setLight(uint8 num, const CLight &light) = 0; /** * Enable / disable light. @@ -946,7 +1062,7 @@ public: * \param enable is true to enable the light, false to disable it. * \see setLight() */ - virtual void enableLight (uint8 num, bool enable=true) = 0; + virtual void enableLight(uint8 num, bool enable = true) = 0; /** * Set ambient. @@ -954,86 +1070,135 @@ public: * \param color is the new global ambient color for the scene. * \see setLight(), enableLight() */ - virtual void setAmbientColor (CRGBA color) = 0; + virtual void setAmbientColor(NLMISC::CRGBA color) = 0; /** Setup the light used for per pixel lighting. The given values should have been modulated by the material diffuse and specular. * This is only useful for material that have their shader set as 'PerPixelLighting' * \param the light used for per pixel lighting */ - virtual void setPerPixelLightingLight(CRGBA diffuse, CRGBA specular, float shininess) = 0; + virtual void setPerPixelLightingLight(NLMISC::CRGBA diffuse, NLMISC::CRGBA specular, float shininess) = 0; /** Setup the unique light used for Lightmap Shader. * Lightmaped primitives are lit per vertex with this light (should be local attenuated for maximum efficiency) * This is only useful for material that have their shader set as 'LightMap' * \param the light used for per pixel lighting */ - virtual void setLightMapDynamicLight (bool enable, const CLight& light) = 0; + virtual void setLightMapDynamicLight(bool enable, const CLight &light) = 0; + // @} - /** Get the global polygon mode. - * - * \param polygon mode choose in this driver. - * \see setPolygonMode(), TPolygonMode - */ - TPolygonMode getPolygonMode () - { - return _PolygonMode; - } - /// \name Vertex program interface + + /// \name Vertex Program // @{ - enum TMatrix - { - ModelView= 0, - Projection, - ModelViewProjection, - NumMatrix - }; - - enum TTransform - { - Identity=0, - Inverse, - Transpose, - InverseTranspose, - NumTransform - }; - - /** - * Does the driver supports vertex programs ? - */ - virtual bool isVertexProgramSupported () const =0; + // Order of preference + // - activeVertexProgram + // - CMaterial pass[n] VP (uses activeVertexProgram, but does not override if one already set by code) + // - default generic VP that mimics fixed pipeline / no VP with fixed pipeline /** * Does the driver supports vertex program, but emulated by CPU ? */ - virtual bool isVertexProgramEmulated () const =0; + virtual bool isVertexProgramEmulated() const = 0; - - - /** - * Activate / disactivate a vertex program - * - * \param program is a pointer on a vertex program. Can be NULL to disable the current vertex program. - * - * \return true if setup/unsetup succeeded, false else. + /** Return true if the driver supports the specified vertex program profile. */ - virtual bool activeVertexProgram (CVertexProgram *program) =0; + virtual bool supportVertexProgram(CVertexProgram::TProfile profile) const = 0; - /** - * Setup constant values. + /** Compile the given vertex program, return if successful. + * If a vertex program was set active before compilation, + * the state of the active vertex program is undefined behaviour afterwards. */ - virtual void setConstant (uint index, float, float, float, float) =0; - virtual void setConstant (uint index, double, double, double, double) =0; - virtual void setConstant (uint index, const NLMISC::CVector& value) =0; - virtual void setConstant (uint index, const NLMISC::CVectorD& value) =0; - /// setup several 4 float csts taken from the given tab - virtual void setConstant (uint index, uint num, const float *src) =0; - /// setup several 4 double csts taken from the given tab - virtual void setConstant (uint index, uint num, const double *src) =0; + virtual bool compileVertexProgram(CVertexProgram *program) = 0; + /** Set the active vertex program. This will override vertex programs specified in CMaterial render calls. + * Also used internally by setupMaterial(CMaterial) when getVertexProgram returns NULL. + * The vertex program is activated immediately. + */ + virtual bool activeVertexProgram(CVertexProgram *program) = 0; + // @} + + + + /// \name Pixel Program + // @{ + + // Order of preference + // - activePixelProgram + // - CMaterial pass[n] PP (uses activePixelProgram, but does not override if one already set by code) + // - PP generated from CMaterial (uses activePixelProgram, but does not override if one already set by code) + + /** Return true if the driver supports the specified pixel program profile. + */ + virtual bool supportPixelProgram(CPixelProgram::TProfile profile) const = 0; + + /** Compile the given pixel program, return if successful. + * If a pixel program was set active before compilation, + * the state of the active pixel program is undefined behaviour afterwards. + */ + virtual bool compilePixelProgram(CPixelProgram *program) = 0; + + /** Set the active pixel program. This will override pixel programs specified in CMaterial render calls. + * Also used internally by setupMaterial(CMaterial) when getPixelProgram returns NULL. + * The pixel program is activated immediately. + */ + virtual bool activePixelProgram(CPixelProgram *program) = 0; + // @} + + + + /// \name Geometry Program + // @{ + + // Order of preference + // - activeGeometryProgram + // - CMaterial pass[n] PP (uses activeGeometryProgram, but does not override if one already set by code) + // - none + + /** Return true if the driver supports the specified pixel program profile. + */ + virtual bool supportGeometryProgram(CGeometryProgram::TProfile profile) const = 0; + + /** Compile the given pixel program, return if successful. + * If a pixel program was set active before compilation, + * the state of the active pixel program is undefined behaviour afterwards. + */ + virtual bool compileGeometryProgram(CGeometryProgram *program) = 0; + + /** Set the active pixel program. This will override pixel programs specified in CMaterial render calls. + * Also used internally by setupMaterial(CMaterial) when getGeometryProgram returns NULL. + * The pixel program is activated immediately. + */ + virtual bool activeGeometryProgram(CGeometryProgram *program) = 0; + // @} + + + + /// \name Program parameters + // @{ + // Set parameters + virtual void setUniform1f(TProgram program, uint index, float f0) = 0; + virtual void setUniform2f(TProgram program, uint index, float f0, float f1) = 0; + virtual void setUniform3f(TProgram program, uint index, float f0, float f1, float f2) = 0; + virtual void setUniform4f(TProgram program, uint index, float f0, float f1, float f2, float f3) = 0; + virtual void setUniform1i(TProgram program, uint index, sint32 i0) = 0; + virtual void setUniform2i(TProgram program, uint index, sint32 i0, sint32 i1) = 0; + virtual void setUniform3i(TProgram program, uint index, sint32 i0, sint32 i1, sint32 i2) = 0; + virtual void setUniform4i(TProgram program, uint index, sint32 i0, sint32 i1, sint32 i2, sint32 i3) = 0; + virtual void setUniform1ui(TProgram program, uint index, uint32 ui0) = 0; + virtual void setUniform2ui(TProgram program, uint index, uint32 ui0, uint32 ui1) = 0; + virtual void setUniform3ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2) = 0; + virtual void setUniform4ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3) = 0; + virtual void setUniform3f(TProgram program, uint index, const NLMISC::CVector& v) = 0; + virtual void setUniform4f(TProgram program, uint index, const NLMISC::CVector& v, float f3) = 0; + virtual void setUniform4f(TProgram program, uint index, const NLMISC::CRGBAF& rgba) = 0; + virtual void setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m) = 0; + virtual void setUniform4fv(TProgram program, uint index, size_t num, const float *src) = 0; + virtual void setUniform4iv(TProgram program, uint index, size_t num, const sint32 *src) = 0; + virtual void setUniform4uiv(TProgram program, uint index, size_t num, const uint32 *src) = 0; + // Set builtin parameters /** - * Setup constants with a current matrix. + * Setup uniforms with a current matrix. * * This call must be done after setFrustum(), setupViewMatrix() or setupModelMatrix() to get correct * results. @@ -1043,10 +1208,9 @@ public: * \param transform is the transformation to apply to the matrix before store it in the constants. * */ - virtual void setConstantMatrix (uint index, TMatrix matrix, TTransform transform) =0; - + virtual void setUniformMatrix(TProgram program, uint index, TMatrix matrix, TTransform transform) = 0; /** - * Setup the constant with the fog vector. This vector must be used to get the final fog value in a vertex shader. + * Setup the uniform with the fog vector. This vector must be used to get the final fog value in a vertex shader. * You must use it like this: * DP4 o[FOGC].x, c[4], R4; * With c[4] the constant used for the fog vector and R4 the vertex local position. @@ -1057,14 +1221,28 @@ public: * \param index is the index where to store the vector. * */ - virtual void setConstantFog (uint index) =0; + virtual void setUniformFog(TProgram program, uint index) = 0; + // Set feature parameters + virtual bool isUniformProgramState() = 0; + // @} - /// Check if the driver support double sided colors vertex programs - virtual bool supportVertexProgramDoubleSidedColor() const = 0; + + /// \name Legacy effects + // @{ // test if support for cloud render in a single pass virtual bool supportCloudRenderSinglePass() const = 0; + // [FIXME] Return true if driver support Bloom effect // FIXME: This is terrible + virtual bool supportBloomEffect() const = 0; + // @} + + + + /// \name Backface color + // @{ + /// Check if the driver support double sided colors vertex programs + virtual bool supportVertexProgramDoubleSidedColor() const = 0; /** * Activate VertexProgram 2Sided Color mode. In 2Sided mode, the BackFace (if material 2Sided enabled) read the * result from o[BFC0], and not o[COL0]. @@ -1072,27 +1250,29 @@ public: * NB: no-op if not supported by driver */ virtual void enableVertexProgramDoubleSidedColor(bool doubleSided) =0; - // @} + + /// \name Texture addressing modes aka textures/pixels shaders // @{ - /// test whether the device supports some form of texture shader. (could be limited to DX6 EMBM for example) - virtual bool supportTextureShaders() const = 0; - // Is the shader water supported ? If not, the driver caller should implement its own version - virtual bool isWaterShaderSupported() const = 0; - // - /// test whether a texture addressing mode is supported - virtual bool isTextureAddrModeSupported(CMaterial::TTexAddressingMode mode) const = 0; - /** setup the 2D matrix for the OffsetTexture, OffsetTextureScale and OffsetTexture addressing mode - * It should be stored as the following - * [a0 a1] - * [a2 a3] - */ - virtual void setMatrix2DForTextureOffsetAddrMode(const uint stage, const float mat[4]) = 0; + /// test whether the device supports some form of texture shader. (could be limited to DX6 EMBM for example) + virtual bool supportTextureShaders() const = 0; + // Is the shader water supported ? If not, the driver caller should implement its own version + virtual bool supportWaterShader() const = 0; + // + /// test whether a texture addressing mode is supported + virtual bool supportTextureAddrMode(CMaterial::TTexAddressingMode mode) const = 0; + /** setup the 2D matrix for the OffsetTexture, OffsetTextureScale and OffsetTexture addressing mode + * It should be stored as the following + * [a0 a1] + * [a2 a3] + */ + virtual void setMatrix2DForTextureOffsetAddrMode(const uint stage, const float mat[4]) = 0; //@} + /** \name EMBM support. If texture shaders are present, this is not available, must use them instead. * EMBM is a color op of CMaterial. * NB : EMBM is the equivalent of the CMaterial::OffsetTexture addressing mode. However, it is both a texture @@ -1104,38 +1284,35 @@ public: */ // @{ - // Test if EMBM is supported. - virtual bool supportEMBM() const = 0; - // Test if EMBM is supported for the given stage - virtual bool isEMBMSupportedAtStage(uint stage) const = 0; - // set the matrix used for EMBM addressing - virtual void setEMBMMatrix(const uint stage, const float mat[4]) = 0; + // Test if EMBM is supported. + virtual bool supportEMBM() const = 0; + // Test if EMBM is supported for the given stage + virtual bool isEMBMSupportedAtStage(uint stage) const = 0; + // set the matrix used for EMBM addressing + virtual void setEMBMMatrix(const uint stage, const float mat[4]) = 0; // @} - // Does the driver support the per-pixel lighting shader ? - virtual bool supportPerPixelLighting(bool specular) const = 0; /// \name Misc // @{ - /** Does the driver support Blend Constant Color ??? If yes CMaterial::blendConstant* enum can be used * for blend Src ord Dst factor. If no, using these enum will have undefined results. */ - virtual bool supportBlendConstantColor() const =0; + virtual bool supportBlendConstantColor() const = 0; /** see supportBlendConstantColor(). Set the current Blend Constant Color. */ - virtual void setBlendConstantColor(NLMISC::CRGBA col)=0; + virtual void setBlendConstantColor(NLMISC::CRGBA col) = 0; /** see supportBlendConstantColor(). Get the current Blend Constant Color. */ - virtual NLMISC::CRGBA getBlendConstantColor() const =0; + virtual NLMISC::CRGBA getBlendConstantColor() const = 0; /** force the driver to flush all command. glFinish() in opengl. * Interesting only for debug and profiling purpose. */ - virtual void finish() =0; + virtual void finish() = 0; // Flush command queue an immediately returns virtual void flush() = 0; @@ -1144,27 +1321,27 @@ public: * See GL_POLYGON_SMOOTH help, and GL_SRC_ALPHA_SATURATE OpenGL doc (not yet implemented now since * used only for alpha part in ShadowMap gen) */ - virtual void enablePolygonSmoothing(bool smooth) =0; + virtual void enablePolygonSmoothing(bool smooth) = 0; /// see enablePolygonSmoothing() - virtual bool isPolygonSmoothingEnabled() const =0; - + virtual bool isPolygonSmoothingEnabled() const = 0; // @} + /** Special method to internally swap the Driver handle of 2 textures. * USE IT WITH CARE (eg: may have Size problems, mipmap problems, format problems ...) * Actually, it is used only by CAsyncTextureManager, to manage Lods of DXTC CTextureFile. * NB: internally, all textures slots are disabled. */ - virtual void swapTextureHandle(ITexture &tex0, ITexture &tex1) =0; + virtual void swapTextureHandle(ITexture &tex0, ITexture &tex1) = 0; /** Advanced usage. Get the texture Handle.Useful for texture sorting for instance * NB: if the texture is not setuped in the driver, 0 is returned. * NB: if implementation does not support it, 0 may be returned. OpenGL ones return the Texture ID. * NB: unlike isTextureExist(), this method is not thread safe. */ - virtual uint getTextureHandle(const ITexture&tex)=0; + virtual uint getTextureHandle(const ITexture&tex) = 0; // see if the Multiply-Add Tex Env operator is supported (see CMaterial::Mad) virtual bool supportMADOperator() const = 0; @@ -1185,16 +1362,16 @@ public: }; // Get the number of hardware renderer available on the client platform. - virtual uint getNumAdapter() const=0; + virtual uint getNumAdapter() const = 0; // Get a hardware renderer description. - virtual bool getAdapter(uint adapter, CAdapter &desc) const=0; + virtual bool getAdapter(uint adapter, CAdapter &desc) const = 0; /** Choose the hardware renderer. * Call it before the setDisplay and enumModes methods * Choose adapter = 0xffffffff for the default one. */ - virtual bool setAdapter(uint adapter)=0; + virtual bool setAdapter(uint adapter) = 0; /** Tell if the vertex color memory format is RGBA (openGL) or BGRA (directx) * BGRA : @@ -1208,20 +1385,22 @@ public: */ virtual CVertexBuffer::TVertexColorType getVertexColorFormat() const =0; + + /// \name Bench // @{ - // Start the bench. See CHTimer::startBench(); - virtual void startBench (bool wantStandardDeviation = false, bool quick = false, bool reset = true) =0; + virtual void startBench(bool wantStandardDeviation = false, bool quick = false, bool reset = true) =0; // End the bench. See CHTimer::endBench(); - virtual void endBench () =0; + virtual void endBench () =0; // Display the bench result - virtual void displayBench (class NLMISC::CLog *log) =0; - + virtual void displayBench (class NLMISC::CLog *log) =0; // @} + + /// \name Occlusion query mechanism // @{ // Test whether this device supports the occlusion query mechanism @@ -1234,8 +1413,8 @@ public: virtual void deleteOcclusionQuery(IOcclusionQuery *oq) = 0; // @} - // get the number of call to swapBuffer since the driver was created - virtual uint64 getSwapBufferCounter() const = 0; + + /** Set cull mode * Useful for mirrors / cube map rendering or when the scene must be rendered upside down @@ -1252,25 +1431,25 @@ public: virtual void stencilMask(uint mask) = 0; protected: - friend class IVBDrvInfos; - friend class IIBDrvInfos; - friend class CTextureDrvShare; - friend class ITextureDrvInfos; - friend class IMaterialDrvInfos; - friend class IVertexProgramDrvInfos; - friend class IShaderDrvInfos; + friend class IVBDrvInfos; + friend class IIBDrvInfos; + friend class CTextureDrvShare; + friend class ITextureDrvInfos; + friend class IMaterialDrvInfos; + friend class IProgramDrvInfos; + friend class IProgramParamsDrvInfos; /// remove ptr from the lists in the driver. - void removeVBDrvInfoPtr(ItVBDrvInfoPtrList vbDrvInfoIt); - void removeIBDrvInfoPtr(ItIBDrvInfoPtrList ibDrvInfoIt); - void removeTextureDrvInfoPtr(ItTexDrvInfoPtrMap texDrvInfoIt); - void removeTextureDrvSharePtr(ItTexDrvSharePtrList texDrvShareIt); - void removeMatDrvInfoPtr(ItMatDrvInfoPtrList shaderIt); - void removeShaderDrvInfoPtr(ItShaderDrvInfoPtrList shaderIt); - void removeVtxPrgDrvInfoPtr(ItVtxPrgDrvInfoPtrList vtxPrgDrvInfoIt); + void removeVBDrvInfoPtr(ItVBDrvInfoPtrList vbDrvInfoIt); + void removeIBDrvInfoPtr(ItIBDrvInfoPtrList ibDrvInfoIt); + void removeTextureDrvInfoPtr(ItTexDrvInfoPtrMap texDrvInfoIt); + void removeTextureDrvSharePtr(ItTexDrvSharePtrList texDrvShareIt); + void removeMatDrvInfoPtr(ItMatDrvInfoPtrList shaderIt); + void removeGPUPrgDrvInfoPtr(ItGPUPrgDrvInfoPtrList gpuPrgDrvInfoIt); private: - bool _StaticMemoryToVRAM; + bool _StaticMemoryToVRAM; + }; // -------------------------------------------------- diff --git a/code/nel/include/nel/3d/driver_user.h b/code/nel/include/nel/3d/driver_user.h index bfe4c1755..30ea98c65 100644 --- a/code/nel/include/nel/3d/driver_user.h +++ b/code/nel/include/nel/3d/driver_user.h @@ -133,6 +133,7 @@ public: // @{ virtual void disableHardwareVertexProgram(); + virtual void disableHardwarePixelProgram(); virtual void disableHardwareVertexArrayAGP(); virtual void disableHardwareTextureShader(); @@ -473,7 +474,6 @@ public: virtual void forceDXTCCompression(bool dxtcComp); virtual void setAnisotropicFilter(sint filter); virtual void forceTextureResize(uint divisor); - virtual void forceNativeFragmentPrograms(bool nativeOnly); virtual bool setMonitorColorProperties (const CMonitorColorProperties &properties); // @} diff --git a/code/nel/include/nel/3d/geometry_program.h b/code/nel/include/nel/3d/geometry_program.h new file mode 100644 index 000000000..48e48e260 --- /dev/null +++ b/code/nel/include/nel/3d/geometry_program.h @@ -0,0 +1,49 @@ +/** \file geometry_program.h + * Geometry program definition + */ + +/* Copyright, 2000, 2001 Nevrax Ltd. + * + * This file is part of NEVRAX NEL. + * NEVRAX NEL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + + * NEVRAX NEL is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with NEVRAX NEL; see the file COPYING. If not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +#ifndef NL_GEOMETRY_PROGRAM_H +#define NL_GEOMETRY_PROGRAM_H + +#include +#include +#include + +#include + +namespace NL3D { + +class CGeometryProgram : public IProgram +{ +public: + /// Constructor + CGeometryProgram(); + /// Destructor + virtual ~CGeometryProgram (); +}; + +} // NL3D + + +#endif // NL_GEOMETRY_PROGRAM_H + +/* End of vertex_program.h */ diff --git a/code/nel/include/nel/3d/gpu_program_params.h b/code/nel/include/nel/3d/gpu_program_params.h new file mode 100644 index 000000000..ce6b8b2f0 --- /dev/null +++ b/code/nel/include/nel/3d/gpu_program_params.h @@ -0,0 +1,178 @@ +/** + * \file gpu_program_params.h + * \brief CGPUProgramParams + * \date 2013-09-07 22:17GMT + * \author Jan Boon (Kaetemi) + * CGPUProgramParams + */ + +/* + * Copyright (C) 2013 by authors + * + * This file is part of NL3D. + * NL3D is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * NL3D is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with NL3D. If not, see + * . + */ + +#ifndef NL3D_GPU_PROGRAM_PARAMS_H +#define NL3D_GPU_PROGRAM_PARAMS_H +#include + +// STL includes +#include +#include + +// NeL includes + +// Project includes + +namespace NLMISC { + class CVector; + class CMatrix; +} + +namespace NL3D { + +/** + * \brief CGPUProgramParams + * \date 2013-09-07 22:17GMT + * \author Jan Boon (Kaetemi) + * A storage for USERCODE-PROVIDED parameters for GPU programs. + * Allows for fast updating and iteration of parameters. + * NOTE TO DRIVER IMPLEMENTORS: DO NOT USE FOR STORING COPIES + * OF HARDCODED DRIVER MATERIAL PARAMETERS OR DRIVER PARAMETERS!!! + * The 4-component alignment that is done in this storage + * class is necessary to simplify support for register-based + * assembly shaders, which require setting per 4 components. + */ +class CGPUProgramParams +{ +public: + enum TType { Float, Int, UInt }; + struct CMeta { uint Index, Size, Count; TType Type; std::string Name; size_t Next, Prev; }; // size is element size, count is nb of elements + +private: + union CVec { float F[4]; sint32 I[4]; uint32 UI[4]; }; + +public: + CGPUProgramParams(); + virtual ~CGPUProgramParams(); + + /// \name User functions + // @{ + // Copy from another params storage + void copy(CGPUProgramParams *params); + + // Set by index, available only when the associated program has been compiled + void set1f(uint index, float f0); + void set2f(uint index, float f0, float f1); + void set3f(uint index, float f0, float f1, float f2); + void set4f(uint index, float f0, float f1, float f2, float f3); + void set1i(uint index, sint32 i0); + void set2i(uint index, sint32 i0, sint32 i1); + void set3i(uint index, sint32 i0, sint32 i1, sint32 i2); + void set4i(uint index, sint32 i0, sint32 i1, sint32 i2, sint32 i3); + void set1ui(uint index, uint32 ui0); + void set2ui(uint index, uint32 ui0, uint32 ui1); + void set3ui(uint index, uint32 ui0, uint32 ui1, uint32 ui2); + void set4ui(uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3); + void set3f(uint index, const NLMISC::CVector& v); + void set4f(uint index, const NLMISC::CVector& v, float f3); + void set4x4f(uint index, const NLMISC::CMatrix& m); + void set4fv(uint index, size_t num, const float *src); + void set4iv(uint index, size_t num, const sint32 *src); + void set4uiv(uint index, size_t num, const uint32 *src); + void unset(uint index); + + // Set by name, it is recommended to use index when repeatedly setting an element + void set1f(const std::string &name, float f0); + void set2f(const std::string &name, float f0, float f1); + void set3f(const std::string &name, float f0, float f1, float f2); + void set4f(const std::string &name, float f0, float f1, float f2, float f3); + void set1i(const std::string &name, sint32 i0); + void set2i(const std::string &name, sint32 i0, sint32 i1); + void set3i(const std::string &name, sint32 i0, sint32 i1, sint32 i2); + void set4i(const std::string &name, sint32 i0, sint32 i1, sint32 i2, sint32 i3); + void set1ui(const std::string &name, uint32 ui0); + void set2ui(const std::string &name, uint32 ui0, uint32 ui1); + void set3ui(const std::string &name, uint32 ui0, uint32 ui1, uint32 ui2); + void set4ui(const std::string &name, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3); + void set3f(const std::string &name, const NLMISC::CVector& v); + void set4f(const std::string &name, const NLMISC::CVector& v, float f3); + void set4x4f(const std::string &name, const NLMISC::CMatrix& m); + void set4fv(const std::string &name, size_t num, const float *src); + void set4iv(const std::string &name, size_t num, const sint32 *src); + void set4uiv(const std::string &name, size_t num, const uint32 *src); + void unset(const std::string &name); + // @} + + // Maps the given name to the given index. + // on duplicate entry the data set by name will be prefered, as it can be + // assumed to have been set after the data set by index, and the mapping + // will usually happen while iterating and finding an element with name + // but no known index. + // Unknown index will be set to ~0, unknown name will have an empty string. + void map(uint index, const std::string &name); + + /// \name Internal + // @{ + /// Allocate specified number of components if necessary (internal use only) + size_t allocOffset(uint index, uint size, uint count, TType type); + size_t allocOffset(const std::string &name, uint size, uint count, TType type); + size_t allocOffset(uint size, uint count, TType type); + /// Return offset for specified index + size_t getOffset(uint index) const; + size_t getOffset(const std::string &name) const; + /// Remove by offset + void freeOffset(size_t offset); + // @} + + /// \name Driver and dev tools + // @{ + // Iteration (returns the offsets for access using getFooByOffset) + inline size_t getBegin() const { return m_Meta.size() ? m_First : s_End; } + inline size_t getNext(size_t offset) const { return m_Meta[offset].Next; } + inline size_t getEnd() const { return s_End; } + + // Data access + inline uint getSizeByOffset(size_t offset) const { return m_Meta[offset].Size; } // size of element (4 for float4) + inline uint getCountByOffset(size_t offset) const { return m_Meta[offset].Count; } // number of elements (usually 1) + inline uint getNbComponentsByOffset(size_t offset) const { return m_Meta[offset].Size * m_Meta[offset].Count; } // nb of components (size * count) + inline float *getPtrFByOffset(size_t offset) { return m_Vec[offset].F; } + inline sint32 *getPtrIByOffset(size_t offset) { return m_Vec[offset].I; } + inline uint32 *getPtrUIByOffset(size_t offset) { return m_Vec[offset].UI; } + inline TType getTypeByOffset(size_t offset) const { return m_Meta[offset].Type; } + inline uint getIndexByOffset(size_t offset) const { return m_Meta[offset].Index; } + const std::string &getNameByOffset(size_t offset) const { return m_Meta[offset].Name; }; + // @} + + // Utility + static inline uint getNbRegistersByComponents(uint nbComponents) { return (nbComponents + 3) >> 2; } // vector register per 4 components + +private: + std::vector m_Vec; + std::vector m_Meta; + std::vector m_Map; // map from index to offset + std::map m_MapName; // map from name to offset + size_t m_First; + size_t m_Last; + static const size_t s_End = -1; + +}; /* class CGPUProgramParams */ + +} /* namespace NL3D */ + +#endif /* #ifndef NL3D_GPU_PROGRAM_PARAMS_H */ + +/* end of file */ diff --git a/code/nel/include/nel/3d/landscape_def.h b/code/nel/include/nel/3d/landscape_def.h index ce90c5b4a..c189a428f 100644 --- a/code/nel/include/nel/3d/landscape_def.h +++ b/code/nel/include/nel/3d/landscape_def.h @@ -81,14 +81,14 @@ class IDriver; class CLandscapeGlobals { public: - // LANDSCAPE RENDERING CONTEXT. Landscape must setup it at the begining at refine()/render(). + // LANDSCAPE RENDERING CONTEXT. Landscape must setup it at the beginning at refine()/render(). // The current date of LandScape for refine only. static sint CurrentDate; // The current date of LandScape for render only. static sint CurrentRenderDate; // The center view for refinement. static CVector RefineCenter; - // What is the treshold for tessellation. + // What is the threshold for tessellation. static float RefineThreshold; // Guess. static float OORefineThreshold; @@ -143,7 +143,7 @@ public: static CLandscapeVBAllocator *CurrentTileVBAllocator; - // PATCH GLOBAL INTERFACE. patch must setup them at the begining at refine()/render(). + // PATCH GLOBAL INTERFACE. patch must setup them at the beginning at refine()/render(). // NO!!! REMIND: can't have any patch global, since a propagated split()/updateErrorMetric() // can arise. must use Patch pointer. diff --git a/code/nel/include/nel/3d/landscape_model.h b/code/nel/include/nel/3d/landscape_model.h index f9ca071bd..981e3e972 100644 --- a/code/nel/include/nel/3d/landscape_model.h +++ b/code/nel/include/nel/3d/landscape_model.h @@ -42,7 +42,7 @@ const NLMISC::CClassId LandscapeModelId=NLMISC::CClassId(0x5a573b55, 0x6b395829 class CLandscapeModel : public CTransform { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); public: diff --git a/code/nel/include/nel/3d/landscapevb_allocator.h b/code/nel/include/nel/3d/landscapevb_allocator.h index d3a081e7b..0e485e990 100644 --- a/code/nel/include/nel/3d/landscapevb_allocator.h +++ b/code/nel/include/nel/3d/landscapevb_allocator.h @@ -21,6 +21,7 @@ #include "nel/misc/smart_ptr.h" #include "nel/3d/tessellation.h" #include "nel/3d/vertex_buffer.h" +#include "nel/3d/vertex_program.h" namespace NL3D @@ -41,6 +42,7 @@ class CVertexProgram; #define NL3D_LANDSCAPE_VPPOS_DELTAPOS (CVertexBuffer::TexCoord3) #define NL3D_LANDSCAPE_VPPOS_ALPHAINFO (CVertexBuffer::TexCoord4) +class CVertexProgramLandscape; // *************************************************************************** /** @@ -107,6 +109,8 @@ public: * Give a vertexProgram Id to activate. Always 0, but 1 For tile Lightmap Pass. */ void activate(uint vpId); + void activateVP(uint vpId); + inline CVertexProgramLandscape *getVP(uint vpId) const { return _VertexProgram[vpId]; } // @} @@ -151,15 +155,35 @@ private: /// \name Vertex Program mgt . // @{ +public: enum {MaxVertexProgram= 2,}; // Vertex Program , NULL if not enabled. - CVertexProgram *_VertexProgram[MaxVertexProgram]; +private: + NLMISC::CSmartPtr _VertexProgram[MaxVertexProgram]; void deleteVertexProgram(); void setupVBFormatAndVertexProgram(bool withVertexProgram); // @} }; +class CVertexProgramLandscape : public CVertexProgram +{ +public: + struct CIdx + { + uint ProgramConstants0; + uint RefineCenter; + uint TileDist; + uint PZBModelPosition; + }; + CVertexProgramLandscape(CLandscapeVBAllocator::TType type, bool lightMap = false); + virtual ~CVertexProgramLandscape() { } + virtual void buildInfo(); +public: + const CIdx &idx() const { return m_Idx; } + CIdx m_Idx; +}; + } // NL3D diff --git a/code/nel/include/nel/3d/load_balancing_trav.h b/code/nel/include/nel/3d/load_balancing_trav.h index 37bd69ddd..43d5c95d8 100644 --- a/code/nel/include/nel/3d/load_balancing_trav.h +++ b/code/nel/include/nel/3d/load_balancing_trav.h @@ -165,7 +165,7 @@ public: // For clipTrav. cleared at beginning of CClipTrav::traverse void clearVisibleList(); - // For ClipTrav only. NB: list is cleared at begining of traverse(). + // For ClipTrav only. NB: list is cleared at beginning of traverse(). void addVisibleModel(CTransform *model) { _VisibleList[_CurrentNumVisibleModels]= model; diff --git a/code/nel/include/nel/3d/material.h b/code/nel/include/nel/3d/material.h index a7ca18bff..671f3339a 100644 --- a/code/nel/include/nel/3d/material.h +++ b/code/nel/include/nel/3d/material.h @@ -22,7 +22,6 @@ #include "nel/misc/rgba.h" #include "nel/misc/matrix.h" #include "nel/3d/texture.h" -#include "nel/3d/shader.h" #include @@ -171,7 +170,8 @@ public: * - Alpha of texture in stage 0 is blended with alpha of texture in stage 1. Blend done with the alpha color of each * stage and the whole is multiplied by the alpha in color vertex [AT0*ADiffuseCol+AT1*(1-ADiffuseCol)]*AStage * - RGB still unchanged - * + * Water : + * - Water */ enum TShader { Normal=0, Bump, @@ -183,7 +183,8 @@ public: PerPixelLightingNoSpec, Cloud, Water, - shaderCount}; + shaderCount, + Program /* internally used when a pixel program is active */ }; /// \name Texture Env Modes. // @{ diff --git a/code/nel/include/nel/3d/mesh_base_instance.h b/code/nel/include/nel/3d/mesh_base_instance.h index 4a4091e3c..b045fa414 100644 --- a/code/nel/include/nel/3d/mesh_base_instance.h +++ b/code/nel/include/nel/3d/mesh_base_instance.h @@ -53,7 +53,7 @@ const NLMISC::CClassId MeshBaseInstanceId=NLMISC::CClassId(0xef44331, 0x739f6bc class CMeshBaseInstance : public CTransformShape { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); public: diff --git a/code/nel/include/nel/3d/mesh_instance.h b/code/nel/include/nel/3d/mesh_instance.h index c4018913f..17eb7a97a 100644 --- a/code/nel/include/nel/3d/mesh_instance.h +++ b/code/nel/include/nel/3d/mesh_instance.h @@ -49,7 +49,7 @@ const NLMISC::CClassId MeshInstanceId=NLMISC::CClassId(0x6bfe0a34, 0x23b26dc9); class CMeshInstance : public CMeshBaseInstance { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); public: diff --git a/code/nel/include/nel/3d/mesh_mrm_instance.h b/code/nel/include/nel/3d/mesh_mrm_instance.h index 03fed2d86..4df6b92f0 100644 --- a/code/nel/include/nel/3d/mesh_mrm_instance.h +++ b/code/nel/include/nel/3d/mesh_mrm_instance.h @@ -49,7 +49,7 @@ const NLMISC::CClassId MeshMRMInstanceId=NLMISC::CClassId(0xec608f3, 0x1111c33) class CMeshMRMInstance : public CMeshBaseInstance { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); protected: diff --git a/code/nel/include/nel/3d/mesh_mrm_skinned_instance.h b/code/nel/include/nel/3d/mesh_mrm_skinned_instance.h index 610744a52..71fac9476 100644 --- a/code/nel/include/nel/3d/mesh_mrm_skinned_instance.h +++ b/code/nel/include/nel/3d/mesh_mrm_skinned_instance.h @@ -49,7 +49,7 @@ const NLMISC::CClassId MeshMRMSkinnedInstanceId=NLMISC::CClassId(0x6cfd2619, 0x class CMeshMRMSkinnedInstance : public CMeshBaseInstance { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); protected: diff --git a/code/nel/include/nel/3d/mesh_multi_lod_instance.h b/code/nel/include/nel/3d/mesh_multi_lod_instance.h index 2b249678c..549979438 100644 --- a/code/nel/include/nel/3d/mesh_multi_lod_instance.h +++ b/code/nel/include/nel/3d/mesh_multi_lod_instance.h @@ -61,7 +61,7 @@ public: Lod0Blend = 0x1, }; - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); /// Last Matrix date for Lods diff --git a/code/nel/include/nel/3d/meshvp_per_pixel_light.h b/code/nel/include/nel/3d/meshvp_per_pixel_light.h index bc211a4b6..a234feddd 100644 --- a/code/nel/include/nel/3d/meshvp_per_pixel_light.h +++ b/code/nel/include/nel/3d/meshvp_per_pixel_light.h @@ -27,9 +27,10 @@ namespace NL3D { +class CVertexProgramPerPixelLight; /** - * This vertex program is used to perform perpixel lighting with meshs. Its ouputs are : + * This vertex program is used to perform perpixel lighting with meshs. Its outputs are : * * Coord Tex 0 : duplicate the tex Coord 0 set from the v.b. * Coord Tex 1 : The light vector in tangent space. @@ -49,6 +50,8 @@ namespace NL3D { class CMeshVPPerPixelLight : public IMeshVertexProgram { public: + friend class CVertexProgramPerPixelLight; + /// true if want Specular Lighting. bool SpecularLighting; public: @@ -84,7 +87,9 @@ private: bool _IsPointLight; // enum { NumVp = 8}; - static std::auto_ptr _VertexProgram[NumVp]; + static NLMISC::CSmartPtr _VertexProgram[NumVp]; + + NLMISC::CRefPtr _ActiveVertexProgram; }; } // NL3D diff --git a/code/nel/include/nel/3d/meshvp_wind_tree.h b/code/nel/include/nel/3d/meshvp_wind_tree.h index 7553d7cca..e2c790d6d 100644 --- a/code/nel/include/nel/3d/meshvp_wind_tree.h +++ b/code/nel/include/nel/3d/meshvp_wind_tree.h @@ -24,6 +24,7 @@ namespace NL3D { +class CVertexProgramWindTree; // *************************************************************************** /** @@ -35,6 +36,7 @@ namespace NL3D { class CMeshVPWindTree : public IMeshVertexProgram { public: + friend class CVertexProgramWindTree; enum {HrcDepth= 3}; @@ -104,6 +106,7 @@ public: // @} private: + static void initVertexPrograms(); void setupLighting(CScene *scene, CMeshBaseInstance *mbi, const NLMISC::CMatrix &invertedModelMat); private: @@ -112,7 +115,9 @@ private: /** The 16 versions: Specular or not (0 or 2), + normalize normal or not (0 or 1). * All multiplied by 4, because support from 0 to 3 pointLights activated. (0.., 4.., 8.., 12..) */ - static std::auto_ptr _VertexProgram[NumVp]; + static NLMISC::CSmartPtr _VertexProgram[NumVp]; + + NLMISC::CRefPtr _ActiveVertexProgram; // WindTree Time for this mesh param setup. Stored in mesh because same for all instances. float _CurrentTime[HrcDepth]; diff --git a/code/nel/include/nel/3d/patch.h b/code/nel/include/nel/3d/patch.h index 4b35660d0..c1363953a 100644 --- a/code/nel/include/nel/3d/patch.h +++ b/code/nel/include/nel/3d/patch.h @@ -808,7 +808,7 @@ private: CTessFarVertex BaseFarVertices[4]; - // Local info for CTessFace tiles. CPatch must setup them at the begining at refine()/render(). + // Local info for CTessFace tiles. CPatch must setup them at the beginning at refine()/render(). // For Far Texture coordinates. float Far0UScale, Far0VScale, Far0UBias, Far0VBias; float Far1UScale, Far1VScale, Far1UBias, Far1VBias; diff --git a/code/nel/include/nel/3d/pixel_program.h b/code/nel/include/nel/3d/pixel_program.h new file mode 100644 index 000000000..0787ae9fb --- /dev/null +++ b/code/nel/include/nel/3d/pixel_program.h @@ -0,0 +1,49 @@ +/** \file pixel_program.h + * Pixel program definition + */ + +/* Copyright, 2000, 2001 Nevrax Ltd. + * + * This file is part of NEVRAX NEL. + * NEVRAX NEL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + + * NEVRAX NEL is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with NEVRAX NEL; see the file COPYING. If not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +#ifndef NL_PIXEL_PROGRAM_H +#define NL_PIXEL_PROGRAM_H + +#include +#include +#include + +#include + +namespace NL3D { + +class CPixelProgram : public IProgram +{ +public: + /// Constructor + CPixelProgram(); + /// Destructor + virtual ~CPixelProgram (); +}; + +} // NL3D + + +#endif // NL_PIXEL_PROGRAM_H + +/* End of vertex_program.h */ diff --git a/code/nel/include/nel/3d/point_light_model.h b/code/nel/include/nel/3d/point_light_model.h index a9da70661..2ca3e46d3 100644 --- a/code/nel/include/nel/3d/point_light_model.h +++ b/code/nel/include/nel/3d/point_light_model.h @@ -55,7 +55,7 @@ const NLMISC::CClassId PointLightModelId=NLMISC::CClassId(0x7e842eba, 0x140b6c6 class CPointLightModel : public CTransform { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); diff --git a/code/nel/include/nel/3d/program.h b/code/nel/include/nel/3d/program.h new file mode 100644 index 000000000..77e6baa62 --- /dev/null +++ b/code/nel/include/nel/3d/program.h @@ -0,0 +1,264 @@ +/** + * \file program.h + * \brief IProgram + * \date 2013-09-07 15:00GMT + * \author Jan Boon (Kaetemi) + * IProgram + */ + +/* + * Copyright (C) 2013 by authors + * + * This file is part of NL3D. + * NL3D is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * NL3D is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with NL3D. If not, see + * . + */ + +#ifndef NL3D_PROGRAM_H +#define NL3D_PROGRAM_H +#include + +// STL includes + +// NeL includes +#include + +// Project includes + +namespace NL3D { + +// List typedef. +class IDriver; +class IProgramDrvInfos; +typedef std::list TGPUPrgDrvInfoPtrList; +typedef TGPUPrgDrvInfoPtrList::iterator ItGPUPrgDrvInfoPtrList; + +// Class for interaction of vertex program with Driver. +// IProgramDrvInfos represent the real data of the GPU program, stored into the driver (eg: just a GLint for opengl). +class IProgramDrvInfos : public NLMISC::CRefCount +{ +private: + IDriver *_Driver; + ItGPUPrgDrvInfoPtrList _DriverIterator; + +public: + IProgramDrvInfos (IDriver *drv, ItGPUPrgDrvInfoPtrList it); + // The virtual dtor is important. + virtual ~IProgramDrvInfos(void); + + virtual uint getUniformIndex(const char *name) const = 0; +}; + +// Features exposed by a program. Used to set builtin parameters on user provided shaders. +// This is only used for user provided shaders, not for builtin shaders, +// as it is a slow method which has to go through all of the options every time. +// Builtin shaders should set all flags to 0. +// Example: +// User shader flags Matrices in the Vertex Program: +// -> When rendering with a material, the driver will call setUniformDriver, +// which will check if the flag Matrices exists, and if so, it will use +// the index cache to find which matrices are needed by the shader, +// and set those which are found. +// This does not work extremely efficient, but it's the most practical option +// for passing builtin parameters onto user provided shaders. +// Note: May need additional flags related to scene sorting, etcetera. +struct CProgramFeatures +{ + CProgramFeatures() : DriverFlags(0), MaterialFlags(0) { } + + // Driver builtin parameters + enum TDriverFlags + { + // Matrices + Matrices = 0x00000001, + + // Fog + Fog = 0x00000002, + }; + uint32 DriverFlags; + + enum TMaterialFlags + { + /// Use the CMaterial texture stages as the textures for a Pixel Program + TextureStages = 0x00000001, + TextureMatrices = 0x00000002, + }; + // Material builtin parameters + uint32 MaterialFlags; +}; + +// Stucture used to cache the indices of builtin parameters which are used by the drivers +// Not used for parameters of specific nl3d programs +struct CProgramIndex +{ + enum TName + { + ModelView, + ModelViewInverse, + ModelViewTranspose, + ModelViewInverseTranspose, + + Projection, + ProjectionInverse, + ProjectionTranspose, + ProjectionInverseTranspose, + + ModelViewProjection, + ModelViewProjectionInverse, + ModelViewProjectionTranspose, + ModelViewProjectionInverseTranspose, + + Fog, + + NUM_UNIFORMS + }; + static const char *Names[NUM_UNIFORMS]; + uint Indices[NUM_UNIFORMS]; +}; + +/** + * \brief IProgram + * \date 2013-09-07 15:00GMT + * \author Jan Boon (Kaetemi) + * A generic GPU program + */ +class IProgram : public NLMISC::CRefCount +{ +public: + enum TProfile + { + none = 0, + + // types + // Vertex Shader = 0x01 + // Pixel Shader = 0x02 + // Geometry Shader = 0x03 + + // nel - 0x31,type,bitfield + nelvp = 0x31010001, // VP supported by CVertexProgramParser, similar to arbvp1, can be translated to vs_1_1 + + // direct3d - 0xD9,type,major,minor + // vertex programs + vs_1_1 = 0xD9010101, + vs_2_0 = 0xD9010200, + // vs_2_sw = 0xD9010201, // not sure... + // vs_2_x = 0xD9010202, // not sure... + // vs_3_0 = 0xD9010300, // not supported + // pixel programs + ps_1_1 = 0xD9020101, + ps_1_2 = 0xD9020102, + ps_1_3 = 0xD9020103, + ps_1_4 = 0xD9020104, + ps_2_0 = 0xD9020200, + // ps_2_x = 0xD9020201, // not sure... + // ps_3_0 = 0xD9020300, // not supported + + // opengl - 0x61,type,bitfield + // vertex programs + // vp20 = 0x61010001, // NV_vertex_program1_1, outdated + arbvp1 = 0x61010002, // ARB_vertex_program + vp30 = 0x61010004, // NV_vertex_program2 + vp40 = 0x61010008, // NV_vertex_program3 + NV_fragment_program3 + gp4vp = 0x61010010, // NV_gpu_program4 + gp5vp = 0x61010020, // NV_gpu_program5 + // pixel programs + // fp20 = 0x61020001, // very limited and outdated, unnecessary + // fp30 = 0x61020002, // NV_fragment_program, now arbfp1, redundant + arbfp1 = 0x61020004, // ARB_fragment_program + fp40 = 0x61020008, // NV_fragment_program2, arbfp1 with "OPTION NV_fragment_program2;\n" + gp4fp = 0x61020010, // NV_gpu_program4 + gp5fp = 0x61020020, // NV_gpu_program5 + // geometry programs + gp4gp = 0x61030001, // NV_gpu_program4 + gp5gp = 0x61030001, // NV_gpu_program5 + + // glsl - 0x65,type,version + glsl330v = 0x65010330, // GLSL vertex program version 330 + glsl330f = 0x65020330, // GLSL fragment program version 330 + glsl330g = 0x65030330, // GLSL geometry program version 330 + }; + + struct CSource : public NLMISC::CRefCount + { + public: + std::string DisplayName; + + /// Minimal required profile for this GPU program + IProgram::TProfile Profile; + + const char *SourcePtr; + size_t SourceLen; + /// Copy the source code string + inline void setSource(const std::string &source) { SourceCopy = source; SourcePtr = &SourceCopy[0]; SourceLen = SourceCopy.size(); } + inline void setSource(const char *source) { SourceCopy = source; SourcePtr = &SourceCopy[0]; SourceLen = SourceCopy.size(); } + /// Set pointer to source code string without copying the string + inline void setSourcePtr(const char *sourcePtr, size_t sourceLen) { SourceCopy.clear(); SourcePtr = sourcePtr; SourceLen = sourceLen; } + inline void setSourcePtr(const char *sourcePtr) { SourceCopy.clear(); SourcePtr = sourcePtr; SourceLen = strlen(sourcePtr); } + + /// CVertexProgramInfo/CPixelProgramInfo/... NeL features + CProgramFeatures Features; + + /// Map with known parameter indices, used for assembly programs + std::map ParamIndices; + + private: + std::string SourceCopy; + }; + +public: + IProgram(); + virtual ~IProgram(); + + // Manage the sources, not allowed after compilation. + // Add multiple sources using different profiles, the driver will use the first one it supports. + inline size_t getSourceNb() const { return m_Sources.size(); }; + inline CSource *getSource(size_t i) const { return m_Sources[i]; }; + inline size_t addSource(CSource *source) { nlassert(!m_Source); m_Sources.push_back(source); return (m_Sources.size() - 1); } + inline void removeSource(size_t i) { nlassert(!m_Source); m_Sources.erase(m_Sources.begin() + i); } + + // Get the idx of a parameter (ogl: uniform, d3d: constant, etcetera) by name. Invalid name returns ~0 + inline uint getUniformIndex(const char *name) const { return m_DrvInfo->getUniformIndex(name); }; + inline uint getUniformIndex(const std::string &name) const { return m_DrvInfo->getUniformIndex(name.c_str()); }; + inline uint getUniformIndex(CProgramIndex::TName name) const { return m_Index.Indices[name]; } + + // Get feature information of the current program + inline CSource *source() const { return m_Source; }; + inline const CProgramFeatures &features() const { return m_Source->Features; }; + inline TProfile profile() const { return m_Source->Profile; } + + // Build feature info, called automatically by the driver after compile succeeds + void buildInfo(CSource *source); + + // Override this to build additional info in a subclass + virtual void buildInfo(); + +protected: + /// The progam source + std::vector > m_Sources; + + /// The source used for compilation + NLMISC::CSmartPtr m_Source; + CProgramIndex m_Index; + +public: + /// The driver information. For the driver implementation only. + NLMISC::CRefPtr m_DrvInfo; + +}; /* class IProgram */ + +} /* namespace NL3D */ + +#endif /* #ifndef NL3D_PROGRAM_H */ + +/* end of file */ diff --git a/code/nel/include/nel/3d/ps_attrib_maker_bin_op_inline.h b/code/nel/include/nel/3d/ps_attrib_maker_bin_op_inline.h index fa077d0f0..421e059cb 100644 --- a/code/nel/include/nel/3d/ps_attrib_maker_bin_op_inline.h +++ b/code/nel/include/nel/3d/ps_attrib_maker_bin_op_inline.h @@ -128,7 +128,7 @@ inline uint32 CPSAttribMakerBinOp::getMinValue(void) const { uint32 lhs = _Arg[0]->getMinValue(); uint32 rhs = _Arg[1]->getMaxValue(); - return rhs > rhs ? 0 : lhs - rhs; + return lhs > rhs ? 0 : lhs - rhs; } break; default: @@ -153,7 +153,7 @@ inline uint32 CPSAttribMakerBinOp::getMaxValue(void) const { uint32 lhs = _Arg[0]->getMaxValue(); uint32 rhs = _Arg[1]->getMinValue(); - return rhs > rhs ? 0 : lhs - rhs; + return lhs > rhs ? 0 : lhs - rhs; } break; default: diff --git a/code/nel/include/nel/3d/ps_attrib_maker_template.h b/code/nel/include/nel/3d/ps_attrib_maker_template.h index 8d7b68ba2..92953b86f 100644 --- a/code/nel/include/nel/3d/ps_attrib_maker_template.h +++ b/code/nel/include/nel/3d/ps_attrib_maker_template.h @@ -29,7 +29,7 @@ namespace NL3D { /* * In this file, we define several template that helps to create attributes maker such as gradient (of float, int, vector etc) * attributes maker are used in the particle system to generate values, such as size, color etc. see ps_attrib_maker.h - * for more informations + * for more information */ diff --git a/code/nel/include/nel/3d/quad_grid_clip_manager.h b/code/nel/include/nel/3d/quad_grid_clip_manager.h index 7e32c07b3..54d427a8b 100644 --- a/code/nel/include/nel/3d/quad_grid_clip_manager.h +++ b/code/nel/include/nel/3d/quad_grid_clip_manager.h @@ -55,7 +55,7 @@ const NLMISC::CClassId QuadGridClipManagerId=NLMISC::CClassId(0x1ffb079a, 0x6c5 class CQuadGridClipManager : public CTransform { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); public: diff --git a/code/nel/include/nel/3d/render_trav.h b/code/nel/include/nel/3d/render_trav.h index 271165427..d50d2c242 100644 --- a/code/nel/include/nel/3d/render_trav.h +++ b/code/nel/include/nel/3d/render_trav.h @@ -27,6 +27,7 @@ #include "nel/3d/mesh_block_manager.h" #include "nel/3d/shadow_map_manager.h" #include "nel/3d/u_scene.h" +#include "nel/3d/vertex_program.h" #include @@ -68,6 +69,41 @@ class CWaterModel; #define NL3D_SHADOW_MESH_SKIN_MANAGER_MAXVERTICES 3000 #define NL3D_SHADOW_MESH_SKIN_MANAGER_NUMVB 8 +/// Container for lighted vertex program. +class CVertexProgramLighted : public CVertexProgram +{ +public: + static const uint MaxLight = 4; + static const uint MaxPointLight = (MaxLight - 1); + struct CIdxLighted + { + uint Ambient; + uint Diffuse[MaxLight]; + uint Specular[MaxLight]; + uint DirOrPos[MaxLight]; // light 0, directional sun; light 1,2,3, omni point light + uint EyePosition; + uint DiffuseAlpha; + }; + struct CFeaturesLighted + { + /// Number of point lights that this program is generated for, varies from 0 to 3. + uint NumActivePointLights; + bool SupportSpecular; + bool Normalize; + /// Start of constants to use for lighting with assembly shaders. + uint CtStartNeLVP; + }; + CVertexProgramLighted() { } + virtual ~CVertexProgramLighted() { } + virtual void buildInfo(); + const CIdxLighted &idxLighted() const { return m_IdxLighted; } + const CFeaturesLighted &featuresLighted() const { return m_FeaturesLighted; } + +protected: + CIdxLighted m_IdxLighted; + CFeaturesLighted m_FeaturesLighted; + +}; // *************************************************************************** @@ -224,10 +260,10 @@ public: // @{ // Max VP Light setup Infos. - enum {MaxVPLight= 4}; + enum {MaxVPLight = CVertexProgramLighted::MaxLight}; /** reset the lighting setup in the driver (all lights are disabled). - * called at begining of traverse(). Must be called by any model (before and after rendering) + * called at beginning of traverse(). Must be called by any model (before and after rendering) * that wish to use CDriver::setLight() instead of the standard behavior with changeLightSetup() */ void resetLightSetup(); @@ -244,7 +280,8 @@ public: */ void changeLightSetup(CLightContribution *lightContribution, bool useLocalAttenuation); - + /// Must call before beginVPLightSetup + void prepareVPLightSetup(); /** setup the driver VP constants to get info from current LightSetup. * Only 0..3 Light + SunLights are supported. The VP do NOT support distance/Spot attenuation * Also it does not handle World Matrix with non uniform scale correctly since lighting is made in ObjectSpace @@ -253,7 +290,7 @@ public: * \param supportSpecular asitsounds. PointLights and dirLight are localViewer * \param invObjectWM the inverse of object matrix: lights are mul by this. Vp compute in object space. */ - void beginVPLightSetup(uint ctStart, bool supportSpecular, const CMatrix &invObjectWM); + void beginVPLightSetup(CVertexProgramLighted *program, const CMatrix &invObjectWM); /** change the driver VP LightSetup constants which depends on material. * \param excludeStrongest This remove the strongest light from the setup. The typical use is to have it computed by using perpixel lighting. @@ -299,7 +336,8 @@ public: * \param numActivePoinLights tells how many point light from 0 to 3 this VP must handle. NB: the Sun directionnal is not option * NB: nlassert(numActiveLights<=MaxVPLight-1). */ - static std::string getLightVPFragment(uint numActivePointLights, uint ctStart, bool supportSpecular, bool normalize); + static std::string getLightVPFragmentNeLVP(uint numActivePointLights, uint ctStart, bool supportSpecular, bool normalize); + // TODO_VP_GLSL /** This returns a reference to a driver light, by its index * \see getStrongestLightIndex @@ -381,12 +419,14 @@ private: mutable uint _StrongestLightIndex; mutable bool _StrongestLightTouched; + // Current vp setuped with beginVPLightSetup() + NLMISC::CRefPtr _VPCurrent; // Current ctStart setuped with beginVPLightSetup() - uint _VPCurrentCtStart; + //uint _VPCurrentCtStart; // Current num of VP lights enabled. uint _VPNumLights; // Current support of specular - bool _VPSupportSpecular; + // bool _VPSupportSpecular; // Sum of all ambiant of all lights + ambiantGlobal. NLMISC::CRGBAF _VPFinalAmbient; // Diffuse/Spec comp of all light / 255. diff --git a/code/nel/include/nel/3d/root_model.h b/code/nel/include/nel/3d/root_model.h index 3faa5b675..d54ad7c20 100644 --- a/code/nel/include/nel/3d/root_model.h +++ b/code/nel/include/nel/3d/root_model.h @@ -39,7 +39,7 @@ const NLMISC::CClassId RootModelId=NLMISC::CClassId(0x25f0505d, 0x75c69f9); class CRootModel : public CTransform { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); diff --git a/code/nel/include/nel/3d/scene.h b/code/nel/include/nel/3d/scene.h index 1d54ce7a6..e0648ebd3 100644 --- a/code/nel/include/nel/3d/scene.h +++ b/code/nel/include/nel/3d/scene.h @@ -826,7 +826,8 @@ private: void flushSSSModelRequests(); // common vb for water display CVertexBuffer _WaterVB; - + + bool _RequestParticlesAnimate; }; diff --git a/code/nel/include/nel/3d/seg_remanence.h b/code/nel/include/nel/3d/seg_remanence.h index dddfa3a61..2e3202a89 100644 --- a/code/nel/include/nel/3d/seg_remanence.h +++ b/code/nel/include/nel/3d/seg_remanence.h @@ -54,7 +54,7 @@ public: CSegRemanence(CSegRemanence &other); CSegRemanence &operator = (CSegRemanence &other); //@} - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); /// to instanciate that model from a scene static CTransform *creator() { return new CSegRemanence; } diff --git a/code/nel/include/nel/3d/shader.h b/code/nel/include/nel/3d/shader.h deleted file mode 100644 index 3377c27d4..000000000 --- a/code/nel/include/nel/3d/shader.h +++ /dev/null @@ -1,99 +0,0 @@ -// NeL - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#ifndef NL_SHADER_H -#define NL_SHADER_H - -#include "nel/misc/types_nl.h" -#include "nel/misc/smart_ptr.h" -#include - - -namespace NL3D { - -using NLMISC::CRefCount; - - -class IDriver; - -// List typedef. -class IShaderDrvInfos; -typedef std::list TShaderDrvInfoPtrList; -typedef TShaderDrvInfoPtrList::iterator ItShaderDrvInfoPtrList; - -/** - * Interface for shader driver infos. - */ -class IShaderDrvInfos : public CRefCount -{ -private: - IDriver *_Driver; - ItShaderDrvInfoPtrList _DriverIterator; - -public: - IShaderDrvInfos(IDriver *drv, ItShaderDrvInfoPtrList it) {_Driver= drv; _DriverIterator= it;} - // The virtual dtor is important. - virtual ~IShaderDrvInfos(); -}; - - -/** - * Shader resource for the driver. It is just a container for a ".fx" text file. - */ -/* *** IMPORTANT ******************** - * *** IF YOU MODIFY THE STRUCTURE OF THIS CLASS, PLEASE INCREMENT IDriver::InterfaceVersion TO INVALIDATE OLD DRIVER DLL - * ********************************** - */ -// -------------------------------------------------- -class CShader -{ -public: - CShader(); - ~CShader(); - - // Load a shader file - bool loadShaderFile (const char *filename); - - // Set the shader text - void setText (const char *text); - - // Get the shader text - const char *getText () const { return _Text.c_str(); } - - // Set the shader name - void setName (const char *name); - - // Get the shader name - const char *getName () const { return _Name.c_str(); } - -public: - // Private. For Driver only. - bool _ShaderChanged; - NLMISC::CRefPtr _DrvInfo; -private: - // The shader - std::string _Text; - // The shader name - std::string _Name; -}; - - -} // NL3D - - -#endif // NL_SHADER_H - -/* End of shader.h */ diff --git a/code/nel/include/nel/3d/skeleton_model.h b/code/nel/include/nel/3d/skeleton_model.h index 196cc680c..ed4f8aadc 100644 --- a/code/nel/include/nel/3d/skeleton_model.h +++ b/code/nel/include/nel/3d/skeleton_model.h @@ -79,7 +79,7 @@ public: /// max number of bones supported in skeleton enum { MaxNumBones = 256 }; - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); public: diff --git a/code/nel/include/nel/3d/stereo_debugger.h b/code/nel/include/nel/3d/stereo_debugger.h new file mode 100644 index 000000000..b07a9630c --- /dev/null +++ b/code/nel/include/nel/3d/stereo_debugger.h @@ -0,0 +1,134 @@ +/** + * \file stereo_debugger.h + * \brief CStereoDebugger + * \date 2013-07-03 20:17GMT + * \author Jan Boon (Kaetemi) + * CStereoDebugger + */ + +/* + * Copyright (C) 2013 by authors + * + * This file is part of NL3D. + * NL3D is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * NL3D is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with NL3D. If not, see + * . + */ + +#if !FINAL_VERSION +#ifndef NL3D_STEREO_DEBUGGER_H +#define NL3D_STEREO_DEBUGGER_H +#include + +// STL includes + +// NeL includes +#include +#include + +// Project includes +#include +#include +#include +#include + +#define NL_STEREO_MAX_USER_CAMERAS 8 + +namespace NL3D { + +class ITexture; +class CTextureUser; +class CPixelProgram; + +/** + * \brief CStereoDebugger + * \date 2013-07-03 20:17GMT + * \author Jan Boon (Kaetemi) + * CStereoDebugger + */ +class CStereoDebugger : public IStereoDisplay +{ +public: + CStereoDebugger(); + virtual ~CStereoDebugger(); + + + /// Sets driver and generates necessary render targets + virtual void setDriver(NL3D::UDriver *driver); + void releaseTextures(); + void initTextures(); + void setTextures(); + void verifyTextures(); + + /// Gets the required screen resolution for this device + virtual bool getScreenResolution(uint &width, uint &height); + /// Set latest camera position etcetera + virtual void updateCamera(uint cid, const NL3D::UCamera *camera); + /// Get the frustum to use for clipping + virtual void getClippingFrustum(uint cid, NL3D::UCamera *camera) const; + + /// Is there a next pass + virtual bool nextPass(); + /// Gets the current viewport + virtual const NL3D::CViewport &getCurrentViewport() const; + /// Gets the current camera frustum + virtual const NL3D::CFrustum &getCurrentFrustum(uint cid) const; + /// Gets the current camera frustum + virtual void getCurrentFrustum(uint cid, NL3D::UCamera *camera) const; + /// Gets the current camera matrix + virtual void getCurrentMatrix(uint cid, NL3D::UCamera *camera) const; + + /// At the start of a new render target + virtual bool wantClear(); + /// The 3D scene + virtual bool wantScene(); + /// Interface within the 3D scene + virtual bool wantInterface3D(); + /// 2D Interface + virtual bool wantInterface2D(); + + /// Returns true if a new render target was set, always fase if not using render targets + virtual bool beginRenderTarget(); + /// Returns true if a render target was fully drawn, always false if not using render targets + virtual bool endRenderTarget(); + + + static void listDevices(std::vector &devicesOut); + +private: + UDriver *m_Driver; + + int m_Stage; + int m_SubStage; + + CViewport m_LeftViewport; + CViewport m_RightViewport; + CFrustum m_Frustum[NL_STEREO_MAX_USER_CAMERAS]; + CMatrix m_CameraMatrix[NL_STEREO_MAX_USER_CAMERAS]; + + NLMISC::CSmartPtr m_LeftTex; + NL3D::CTextureUser *m_LeftTexU; + NLMISC::CSmartPtr m_RightTex; + NL3D::CTextureUser *m_RightTexU; + NL3D::UMaterial m_Mat; + NLMISC::CQuadUV m_QuadUV; + CPixelProgram *m_PixelProgram; + +}; /* class CStereoDebugger */ + +} /* namespace NL3D */ + +#endif /* #ifndef NL3D_STEREO_DEBUGGER_H */ +#endif /* #if !FINAL_VERSION */ + +/* end of file */ diff --git a/code/nel/include/nel/3d/stereo_display.h b/code/nel/include/nel/3d/stereo_display.h new file mode 100644 index 000000000..e3b5b3716 --- /dev/null +++ b/code/nel/include/nel/3d/stereo_display.h @@ -0,0 +1,141 @@ +/** + * \file stereo_display.h + * \brief IStereoDisplay + * \date 2013-06-27 16:29GMT + * \author Jan Boon (Kaetemi) + * IStereoDisplay + */ + +/* + * Copyright (C) 2013 by authors + * + * This file is part of NL3D. + * NL3D is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * NL3D is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with NL3D. If not, see + * . + */ + +#ifndef NL3D_STEREO_DISPLAY_H +#define NL3D_STEREO_DISPLAY_H +#include + +// STL includes + +// NeL includes +#include + +// Project includes + +namespace NL3D { + +class UCamera; +class CViewport; +class CFrustum; +class IStereoDisplay; +class UTexture; +class UDriver; + +class IStereoDeviceFactory : public NLMISC::CRefCount +{ +public: + IStereoDeviceFactory() { } + virtual ~IStereoDeviceFactory() { } + virtual IStereoDisplay *createDevice() const = 0; +}; + +struct CStereoDeviceInfo +{ +public: + enum TStereoDeviceClass + { + StereoDisplay, + StereoHMD, + }; + + enum TStereoDeviceLibrary + { + NeL3D, + OVR, + LibVR, + OpenHMD, + }; + + NLMISC::CSmartPtr Factory; + + TStereoDeviceLibrary Library; + TStereoDeviceClass Class; + std::string Manufacturer; + std::string ProductName; + std::string Serial; // A unique device identifier +}; + +/** + * \brief IStereoDisplay + * \date 2013-06-27 16:29GMT + * \author Jan Boon (Kaetemi) + * IStereoDisplay + */ +class IStereoDisplay +{ +public: + IStereoDisplay(); + virtual ~IStereoDisplay(); + + /// Sets driver and generates necessary render targets + virtual void setDriver(NL3D::UDriver *driver) = 0; + + /// Gets the required screen resolution for this device + virtual bool getScreenResolution(uint &width, uint &height) = 0; + /// Set latest camera position etcetera + virtual void updateCamera(uint cid, const NL3D::UCamera *camera) = 0; + /// Get the frustum to use for clipping + virtual void getClippingFrustum(uint cid, NL3D::UCamera *camera) const = 0; + + /// Is there a next pass + virtual bool nextPass() = 0; + /// Gets the current viewport + virtual const NL3D::CViewport &getCurrentViewport() const = 0; + /// Gets the current camera frustum + virtual const NL3D::CFrustum &getCurrentFrustum(uint cid) const = 0; + /// Gets the current camera frustum + virtual void getCurrentFrustum(uint cid, NL3D::UCamera *camera) const = 0; + /// Gets the current camera matrix + virtual void getCurrentMatrix(uint cid, NL3D::UCamera *camera) const = 0; + + /// At the start of a new render target + virtual bool wantClear() = 0; + /// The 3D scene + virtual bool wantScene() = 0; + /// Interface within the 3D scene + virtual bool wantInterface3D() = 0; + /// 2D Interface + virtual bool wantInterface2D() = 0; + + /// Returns true if a new render target was set, always fase if not using render targets + virtual bool beginRenderTarget() = 0; + /// Returns true if a render target was fully drawn, always false if not using render targets + virtual bool endRenderTarget() = 0; + + static const char *getLibraryName(CStereoDeviceInfo::TStereoDeviceLibrary library); + static void listDevices(std::vector &devicesOut); + static IStereoDisplay *createDevice(const CStereoDeviceInfo &deviceInfo); + static void releaseUnusedLibraries(); + static void releaseAllLibraries(); + +}; /* class IStereoDisplay */ + +} /* namespace NL3D */ + +#endif /* #ifndef NL3D_STEREO_DISPLAY_H */ + +/* end of file */ diff --git a/code/nel/include/nel/3d/stereo_hmd.h b/code/nel/include/nel/3d/stereo_hmd.h new file mode 100644 index 000000000..95c159cfd --- /dev/null +++ b/code/nel/include/nel/3d/stereo_hmd.h @@ -0,0 +1,73 @@ +/** + * \file stereo_hmd.h + * \brief IStereoHMD + * \date 2013-06-27 16:30GMT + * \author Jan Boon (Kaetemi) + * IStereoHMD + */ + +/* + * Copyright (C) 2013 by authors + * + * This file is part of NL3D. + * NL3D is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * NL3D is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with NL3D. If not, see + * . + */ + +#ifndef NL3D_STEREO_HMD_H +#define NL3D_STEREO_HMD_H +#include + +// STL includes + +// NeL includes + +// Project includes +#include + +namespace NL3D { + +/** + * \brief IStereoHMD + * \date 2013-06-27 16:30GMT + * \author Jan Boon (Kaetemi) + * IStereoHMD + */ +class IStereoHMD : public IStereoDisplay +{ +public: + IStereoHMD(); + virtual ~IStereoHMD(); + + /// Get the HMD orientation + virtual NLMISC::CQuat getOrientation() const = 0; + + /// Get GUI center (1 = width, 1 = height, 0 = center) + virtual void getInterface2DShift(uint cid, float &x, float &y, float distance) const = 0; + + /// Set the head model, eye position relative to orientation point + virtual void setEyePosition(const NLMISC::CVector &v) = 0; + /// Get the head model, eye position relative to orientation point + virtual const NLMISC::CVector &getEyePosition() const = 0; + + /// Set the scale of the game in units per meter + virtual void setScale(float s) = 0; + +}; /* class IStereoHMD */ + +} /* namespace NL3D */ + +#endif /* #ifndef NL3D_STEREO_HMD_H */ + +/* end of file */ diff --git a/code/nel/include/nel/3d/stereo_libvr.h b/code/nel/include/nel/3d/stereo_libvr.h new file mode 100644 index 000000000..76d1966fe --- /dev/null +++ b/code/nel/include/nel/3d/stereo_libvr.h @@ -0,0 +1,160 @@ +/** + * \file stereo_libvr.h + * \brief CStereoLibVR + * \date 2013-08-19 19:17MT + * \author Thibaut Girka (ThibG) + * CStereoLibVR + */ + +/* + * Copyright (C) 2013 by authors + * + * This file is part of NL3D. + * NL3D is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * NL3D is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with NL3D. If not, see + * . + */ + +#ifndef NL3D_STEREO_LIBVR_H +#define NL3D_STEREO_LIBVR_H + +#ifdef HAVE_LIBVR + +#include + +// STL includes + +// NeL includes +#include +#include + +// Project includes +#include +#include +#include +#include + +namespace NL3D { + +class ITexture; +class CTextureUser; +class CStereoLibVRDevicePtr; +class CStereoLibVRDeviceHandle; +class CPixelProgram; + +#define NL_STEREO_MAX_USER_CAMERAS 8 + +/** + * \brief CStereoOVR + * \date 2013-06-25 22:22GMT + * \author Jan Boon (Kaetemi) + * CStereoOVR + */ +class CStereoLibVR : public IStereoHMD +{ +public: + CStereoLibVR(const CStereoLibVRDeviceHandle *handle); + virtual ~CStereoLibVR(); + + /// Sets driver and generates necessary render targets + virtual void setDriver(NL3D::UDriver *driver); + + /// Gets the required screen resolution for this device + virtual bool getScreenResolution(uint &width, uint &height); + /// Set latest camera position etcetera + virtual void updateCamera(uint cid, const NL3D::UCamera *camera); + /// Get the frustum to use for clipping + virtual void getClippingFrustum(uint cid, NL3D::UCamera *camera) const; + + /// Is there a next pass + virtual bool nextPass(); + /// Gets the current viewport + virtual const NL3D::CViewport &getCurrentViewport() const; + /// Gets the current camera frustum + virtual const NL3D::CFrustum &getCurrentFrustum(uint cid) const; + /// Gets the current camera frustum + virtual void getCurrentFrustum(uint cid, NL3D::UCamera *camera) const; + /// Gets the current camera matrix + virtual void getCurrentMatrix(uint cid, NL3D::UCamera *camera) const; + + /// At the start of a new render target + virtual bool wantClear(); + /// The 3D scene + virtual bool wantScene(); + /// Interface within the 3D scene + virtual bool wantInterface3D(); + /// 2D Interface + virtual bool wantInterface2D(); + + /// Returns true if a new render target was set, always fase if not using render targets + virtual bool beginRenderTarget(); + /// Returns true if a render target was fully drawn, always false if not using render targets + virtual bool endRenderTarget(); + + + /// Get the HMD orientation + virtual NLMISC::CQuat getOrientation() const; + + /// Get GUI center (1 = width, 1 = height, 0 = center) + virtual void getInterface2DShift(uint cid, float &x, float &y, float distance) const; + + /// Set the head model, eye position relative to orientation point + virtual void setEyePosition(const NLMISC::CVector &v); + /// Get the head model, eye position relative to orientation point + virtual const NLMISC::CVector &getEyePosition() const; + + /// Set the scale of the game in units per meter + virtual void setScale(float s); + + + static void listDevices(std::vector &devicesOut); + static bool isLibraryInUse(); + static void releaseLibrary(); + + + /// Calculates internal camera information based on the reference camera + void initCamera(uint cid, const NL3D::UCamera *camera); + /// Checks if the device used by this class was actually created + bool isDeviceCreated(); + +private: + CStereoLibVRDevicePtr *m_DevicePtr; + int m_Stage; + int m_SubStage; + CViewport m_LeftViewport; + CViewport m_RightViewport; + CFrustum m_ClippingFrustum[NL_STEREO_MAX_USER_CAMERAS]; + CFrustum m_LeftFrustum[NL_STEREO_MAX_USER_CAMERAS]; + CFrustum m_RightFrustum[NL_STEREO_MAX_USER_CAMERAS]; + CMatrix m_CameraMatrix[NL_STEREO_MAX_USER_CAMERAS]; + mutable bool m_OrientationCached; + mutable NLMISC::CQuat m_OrientationCache; + UDriver *m_Driver; + NLMISC::CSmartPtr m_BarrelTex; + NL3D::CTextureUser *m_BarrelTexU; + NL3D::UMaterial m_BarrelMat; + NLMISC::CQuadUV m_BarrelQuadLeft; + NLMISC::CQuadUV m_BarrelQuadRight; + CPixelProgram *m_PixelProgram; + NLMISC::CVector m_EyePosition; + float m_Scale; + +}; /* class CStereoLibVR */ + +} /* namespace NL3D */ + +#endif /* HAVE_LIBVR */ + +#endif /* #ifndef NL3D_STEREO_LIBVR_H */ + +/* end of file */ diff --git a/code/nel/include/nel/3d/stereo_ovr.h b/code/nel/include/nel/3d/stereo_ovr.h new file mode 100644 index 000000000..ba6895bf0 --- /dev/null +++ b/code/nel/include/nel/3d/stereo_ovr.h @@ -0,0 +1,176 @@ +/** + * \file stereo_ovr.h + * \brief CStereoOVR + * \date 2013-06-25 22:22GMT + * \author Jan Boon (Kaetemi) + * CStereoOVR + */ + +/* + * Copyright (C) 2013 by authors + * + * This file is part of NL3D. + * NL3D is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * NL3D is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General + * Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with NL3D. If not, see + * . + * + * Linking this library statically or dynamically with other modules + * is making a combined work based on this library. Thus, the terms + * and conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with the Oculus SDK to produce + * an executable, regardless of the license terms of the Oculus SDK, + * and distribute linked combinations including the two, provided that + * you also meet the terms and conditions of the license of the Oculus + * SDK. You must obey the GNU General Public License in all respects + * for all of the code used other than the Oculus SDK. If you modify + * this file, you may extend this exception to your version of the + * file, but you are not obligated to do so. If you do not wish to do + * so, delete this exception statement from your version. + */ + +#ifndef NL3D_STEREO_OVR_H +#define NL3D_STEREO_OVR_H + +#ifdef HAVE_LIBOVR + +#include + +// STL includes + +// NeL includes +#include +#include + +// Project includes +#include +#include +#include +#include + +namespace NL3D { + +class ITexture; +class CTextureUser; +class CStereoOVRDevicePtr; +class CStereoOVRDeviceHandle; +class CPixelProgramOVR; + +#define NL_STEREO_MAX_USER_CAMERAS 8 + +/** + * \brief CStereoOVR + * \date 2013-06-25 22:22GMT + * \author Jan Boon (Kaetemi) + * CStereoOVR + */ +class CStereoOVR : public IStereoHMD +{ +public: + CStereoOVR(const CStereoOVRDeviceHandle *handle); + virtual ~CStereoOVR(); + + /// Sets driver and generates necessary render targets + virtual void setDriver(NL3D::UDriver *driver); + + /// Gets the required screen resolution for this device + virtual bool getScreenResolution(uint &width, uint &height); + /// Set latest camera position etcetera + virtual void updateCamera(uint cid, const NL3D::UCamera *camera); + /// Get the frustum to use for clipping + virtual void getClippingFrustum(uint cid, NL3D::UCamera *camera) const; + + /// Is there a next pass + virtual bool nextPass(); + /// Gets the current viewport + virtual const NL3D::CViewport &getCurrentViewport() const; + /// Gets the current camera frustum + virtual const NL3D::CFrustum &getCurrentFrustum(uint cid) const; + /// Gets the current camera frustum + virtual void getCurrentFrustum(uint cid, NL3D::UCamera *camera) const; + /// Gets the current camera matrix + virtual void getCurrentMatrix(uint cid, NL3D::UCamera *camera) const; + + /// At the start of a new render target + virtual bool wantClear(); + /// The 3D scene + virtual bool wantScene(); + /// Interface within the 3D scene + virtual bool wantInterface3D(); + /// 2D Interface + virtual bool wantInterface2D(); + + /// Returns true if a new render target was set, always fase if not using render targets + virtual bool beginRenderTarget(); + /// Returns true if a render target was fully drawn, always false if not using render targets + virtual bool endRenderTarget(); + + + /// Get the HMD orientation + virtual NLMISC::CQuat getOrientation() const; + + /// Get GUI center (1 = width, 1 = height, 0 = center) + virtual void getInterface2DShift(uint cid, float &x, float &y, float distance) const; + + /// Set the head model, eye position relative to orientation point + virtual void setEyePosition(const NLMISC::CVector &v); + /// Get the head model, eye position relative to orientation point + virtual const NLMISC::CVector &getEyePosition() const; + + /// Set the scale of the game in units per meter + virtual void setScale(float s); + + + static void listDevices(std::vector &devicesOut); + static bool isLibraryInUse(); + static void releaseLibrary(); + + + /// Calculates internal camera information based on the reference camera + void initCamera(uint cid, const NL3D::UCamera *camera); + /// Checks if the device used by this class was actually created + bool isDeviceCreated(); + +private: + CStereoOVRDevicePtr *m_DevicePtr; + int m_Stage; + int m_SubStage; + CViewport m_LeftViewport; + CViewport m_RightViewport; + CFrustum m_ClippingFrustum[NL_STEREO_MAX_USER_CAMERAS]; + CFrustum m_LeftFrustum[NL_STEREO_MAX_USER_CAMERAS]; + CFrustum m_RightFrustum[NL_STEREO_MAX_USER_CAMERAS]; + CMatrix m_CameraMatrix[NL_STEREO_MAX_USER_CAMERAS]; + mutable bool m_OrientationCached; + mutable NLMISC::CQuat m_OrientationCache; + UDriver *m_Driver; + NLMISC::CSmartPtr m_BarrelTex; + NL3D::CTextureUser *m_BarrelTexU; + NL3D::UMaterial m_BarrelMat; + NLMISC::CQuadUV m_BarrelQuadLeft; + NLMISC::CQuadUV m_BarrelQuadRight; + NLMISC::CRefPtr m_PixelProgram; + NLMISC::CVector m_EyePosition; + float m_Scale; + +}; /* class CStereoOVR */ + +} /* namespace NL3D */ + +#endif /* HAVE_LIBOVR */ + +#endif /* #ifndef NL3D_STEREO_OVR_H */ + +/* end of file */ diff --git a/code/nel/include/nel/3d/transform.h b/code/nel/include/nel/3d/transform.h index cf8d3031f..00e023331 100644 --- a/code/nel/include/nel/3d/transform.h +++ b/code/nel/include/nel/3d/transform.h @@ -90,7 +90,7 @@ const NLMISC::CClassId TransformId=NLMISC::CClassId(0x174750cb, 0xf952024); class CTransform : public ITransformable { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); /// get the scene which has created us @@ -113,7 +113,7 @@ public: /** * Extra init for a model. this method is called by the framework at the very end of CScene::createModel() * Warning! if the model is a CTransformShape, then when initModel() is called, Shape and other related member/setup - * of IShape::createInstance() are not yet done (because createModel() is called at the begining in createInstance()). + * of IShape::createInstance() are not yet done (because createModel() is called at the beginning in createInstance()). * * Because initModel() is called at the very end, deriver could implement anything like creating other models, * but not deleting this model... diff --git a/code/nel/include/nel/3d/transform_shape.h b/code/nel/include/nel/3d/transform_shape.h index 28c5602c3..7bffe971a 100644 --- a/code/nel/include/nel/3d/transform_shape.h +++ b/code/nel/include/nel/3d/transform_shape.h @@ -55,7 +55,7 @@ const NLMISC::CClassId TransformShapeId=NLMISC::CClassId(0x1e6115e6, 0x63502517 class CTransformShape : public CTransform { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); public: diff --git a/code/nel/include/nel/3d/u_driver.h b/code/nel/include/nel/3d/u_driver.h index d66a72e47..2e74ae3fe 100644 --- a/code/nel/include/nel/3d/u_driver.h +++ b/code/nel/include/nel/3d/u_driver.h @@ -168,6 +168,7 @@ public: */ // @{ virtual void disableHardwareVertexProgram()=0; + virtual void disableHardwarePixelProgram()=0; virtual void disableHardwareVertexArrayAGP()=0; virtual void disableHardwareTextureShader()=0; // @} @@ -672,13 +673,6 @@ public: */ virtual void forceTextureResize(uint divisor)=0; - /** Sets enforcement of native fragment programs. This is by default enabled. - * - * \param nativeOnly If set to false, fragment programs don't need to be native to stay loaded, - * otherwise (aka if true) they will be purged. - */ - virtual void forceNativeFragmentPrograms(bool nativeOnly) = 0; - /** Setup monitor color properties. * * Return false if setup failed. diff --git a/code/nel/include/nel/3d/vegetable_blend_layer_model.h b/code/nel/include/nel/3d/vegetable_blend_layer_model.h index ea37a0e4d..1f8840de9 100644 --- a/code/nel/include/nel/3d/vegetable_blend_layer_model.h +++ b/code/nel/include/nel/3d/vegetable_blend_layer_model.h @@ -48,7 +48,7 @@ const NLMISC::CClassId VegetableBlendLayerModelId=NLMISC::CClassId(0x77375163, class CVegetableBlendLayerModel : public CTransform { public: - /// Call at the begining of the program, to register the model + /// Call at the beginning of the program, to register the model static void registerBasic(); public: diff --git a/code/nel/include/nel/3d/vegetable_manager.h b/code/nel/include/nel/3d/vegetable_manager.h index 71ed235e4..ee21af3f3 100644 --- a/code/nel/include/nel/3d/vegetable_manager.h +++ b/code/nel/include/nel/3d/vegetable_manager.h @@ -48,6 +48,7 @@ class CVegetableLightEx; // default distance is 60 meters. #define NL3D_VEGETABLE_DEFAULT_DIST_MAX 60.f +class CVertexProgramVeget; // *************************************************************************** /** @@ -306,7 +307,8 @@ private: // The same, but no VBHard. CVegetableVBAllocator _VBSoftAllocator[CVegetableVBAllocator::VBTypeCount]; // Vertex Program. One VertexProgram for each rdrPass (with / without fog) - CVertexProgram *_VertexProgram[NL3D_VEGETABLE_NRDRPASS][2]; + CSmartPtr _VertexProgram[NL3D_VEGETABLE_NRDRPASS][2]; + CRefPtr _ActiveVertexProgram; // Material. Useful for texture and alphaTest @@ -342,7 +344,7 @@ private: /// setup the vertexProgram constants. - void setupVertexProgramConstants(IDriver *driver); + void setupVertexProgramConstants(IDriver *driver, bool fogEnabled); /** swap the RdrPass type (hard or soft) of the rdrPass of an instance group. diff --git a/code/nel/include/nel/3d/vertex_program.h b/code/nel/include/nel/3d/vertex_program.h index 903e5ccf7..3d77c6104 100644 --- a/code/nel/include/nel/3d/vertex_program.h +++ b/code/nel/include/nel/3d/vertex_program.h @@ -19,90 +19,24 @@ #include "nel/misc/types_nl.h" #include "nel/misc/smart_ptr.h" +#include "nel/3d/program.h" #include - namespace NL3D { -// List typedef. -class IDriver; -class IVertexProgramDrvInfos; -typedef std::list TVtxPrgDrvInfoPtrList; -typedef TVtxPrgDrvInfoPtrList::iterator ItVtxPrgDrvInfoPtrList; - -// Class for interaction of vertex program with Driver. -// IVertexProgramDrvInfos represent the real data of the vertex program, stored into the driver (eg: just a GLint for opengl). -class IVertexProgramDrvInfos : public NLMISC::CRefCount -{ -private: - IDriver *_Driver; - ItVtxPrgDrvInfoPtrList _DriverIterator; - -public: - IVertexProgramDrvInfos (IDriver *drv, ItVtxPrgDrvInfoPtrList it); - // The virtual dtor is important. - virtual ~IVertexProgramDrvInfos(void); -}; - - -/** - * This class is a vertex program. - * - * D3D / OPENGL compatibility notes: - * --------------------------------- - * - * To make your program compatible with D3D and OPENGL nel drivers, please follow thoses directives to write your vertex programs - * - * - Use only v[0], v[1] etc.. syntax for input registers. Don't use v0, v1 or v[OPOS] etc.. - * - Use only c[0], c[1] etc.. syntax for constant registers. Don't use c0, c1 etc.. - * - Use only o[HPOS], o[COL0] etc.. syntax for output registers. Don't use oPos, oD0 etc.. - * - Use only uppercase for registers R1, R2 etc.. Don't use lowercase r1, r2 etc.. - * - Use a semicolon to delineate instructions. - * - Use ARL instruction to load the adress register and not MOV. - * - Don't use the NOP instruction. - * - Don't use macros. - * - * -> Thoses programs work without any change under OpenGL. - * -> Direct3D driver implementation will have to modify the syntax on the fly before the setup like this: - * - "v[0]" must be changed in "v0" etc.. - * - "o[HPOS]" must be changed in oPos etc.. - * - Semicolon must be changed in line return character. - * - ARL instruction must be changed in MOV. - * - * Behaviour of LOG may change depending on implementation: You can only expect to have dest.z = log2(abs(src.w)). - * LIT may or may not clamp the specular exponent to [-128, 128] (not done when EXT_vertex_shader is used for example ..) - * - * Depending on the implementation, some optimizations can be achieved by masking the unused output values of instructions - * as LIT, EXPP .. - * - * \author Cyril 'Hulud' Corvazier - * \author Nevrax France - * \date 2001 - */ -class CVertexProgram : public NLMISC::CRefCount +class CVertexProgram : public IProgram { public: - /// Constructor - CVertexProgram (const char* program); + CVertexProgram(); + CVertexProgram(const char *nelvp); /// Destructor virtual ~CVertexProgram (); - /// Get the program - const std::string& getProgram () const { return _Program; }; - -private: - /// The progam - std::string _Program; - -public: - /// The driver information. For the driver implementation only. - NLMISC::CRefPtr _DrvInfo; }; - } // NL3D diff --git a/code/nel/include/nel/3d/vertex_program_parse.h b/code/nel/include/nel/3d/vertex_program_parse.h index 8c7ec7f9b..88538da07 100644 --- a/code/nel/include/nel/3d/vertex_program_parse.h +++ b/code/nel/include/nel/3d/vertex_program_parse.h @@ -21,6 +21,40 @@ #include +/** + * This class is a vertex program. + * + * D3D / OPENGL compatibility notes: + * --------------------------------- + * + * To make your program compatible with D3D and OPENGL nel drivers, please follow thoses directives to write your vertex programs + * + * - Use only v[0], v[1] etc.. syntax for input registers. Don't use v0, v1 or v[OPOS] etc.. + * - Use only c[0], c[1] etc.. syntax for constant registers. Don't use c0, c1 etc.. + * - Use only o[HPOS], o[COL0] etc.. syntax for output registers. Don't use oPos, oD0 etc.. + * - Use only uppercase for registers R1, R2 etc.. Don't use lowercase r1, r2 etc.. + * - Use a semicolon to delineate instructions. + * - Use ARL instruction to load the adress register and not MOV. + * - Don't use the NOP instruction. + * - Don't use macros. + * + * -> Thoses programs work without any change under OpenGL. + * -> Direct3D driver implementation will have to modify the syntax on the fly before the setup like this: + * - "v[0]" must be changed in "v0" etc.. + * - "o[HPOS]" must be changed in oPos etc.. + * - Semicolon must be changed in line return character. + * - ARL instruction must be changed in MOV. + * + * Behaviour of LOG may change depending on implementation: You can only expect to have dest.z = log2(abs(src.w)). + * LIT may or may not clamp the specular exponent to [-128, 128] (not done when EXT_vertex_shader is used for example ..) + * + * Depending on the implementation, some optimizations can be achieved by masking the unused output values of instructions + * as LIT, EXPP .. + * + * \author Cyril 'Hulud' Corvazier + * \author Nevrax France + * \date 2001 + */ /// Swizzle of an operand in a vertex program struct CVPSwizzle @@ -188,7 +222,7 @@ public: * \warning: Only syntax is checked. It doesn't check that a register has been initialised before use. * \param src The input text of a vertex program, in OpenGL format. * \param result The result program. - * \param errorOuput If parsing failed, contains the reason + * \param errorOutput If parsing failed, contains the reason * \result true if the parsing succeeded */ bool parse(const char *src, TProgram &result, std::string &errorOutput); diff --git a/code/nel/include/nel/3d/water_env_map.h b/code/nel/include/nel/3d/water_env_map.h index 384f55b56..50fca18ec 100644 --- a/code/nel/include/nel/3d/water_env_map.h +++ b/code/nel/include/nel/3d/water_env_map.h @@ -61,7 +61,7 @@ public: // Get envmap 2D texture (after projection of cube map) ITexture *getEnvMap2D() const { return _Env2D; } // tmp for debug : render test mesh with current model / view matrixs - void renderTestMesh(IDriver &driver); + // void renderTestMesh(IDriver &driver); // set constant alpha of envmap void setAlpha(uint8 alpha) { _Alpha = alpha; } uint8 getAlpha() const { return _Alpha; } diff --git a/code/nel/include/nel/3d/water_shape.h b/code/nel/include/nel/3d/water_shape.h index f7a7e1b0b..dc7f20426 100644 --- a/code/nel/include/nel/3d/water_shape.h +++ b/code/nel/include/nel/3d/water_shape.h @@ -49,6 +49,29 @@ const NLMISC::CClassId WaveMakerModelClassId = NLMISC::CClassId(0x16da3356, 0x7 const uint WATER_VERTEX_HARD_SIZE = sizeof(float[3]); const uint WATER_VERTEX_SOFT_SIZE = sizeof(float[5]); +// VP Water No Wave +class CVertexProgramWaterVPNoWave : public CVertexProgram +{ +public: + struct CIdx + { + uint BumpMap0Scale; + uint BumpMap0Offset; + uint BumpMap1Scale; + uint BumpMap1Offset; + uint ObserverHeight; + uint ScaleReflectedRay; + uint DiffuseMapVector0; + uint DiffuseMapVector1; + }; + CVertexProgramWaterVPNoWave(bool diffuse); + virtual ~CVertexProgramWaterVPNoWave() { } + virtual void buildInfo(); + inline const CIdx &idx() const { return m_Idx; } +private: + CIdx m_Idx; + bool m_Diffuse; +}; /** * A water shape. @@ -247,17 +270,17 @@ private: static bool _GridSizeTouched; // - static std::auto_ptr _VertexProgramBump1; - static std::auto_ptr _VertexProgramBump2; + /*static NLMISC::CSmartPtr _VertexProgramBump1; + static NLMISC::CSmartPtr _VertexProgramBump2; // - static std::auto_ptr _VertexProgramBump1Diffuse; - static std::auto_ptr _VertexProgramBump2Diffuse; + static NLMISC::CSmartPtr _VertexProgramBump1Diffuse; + static NLMISC::CSmartPtr _VertexProgramBump2Diffuse; // - static std::auto_ptr _VertexProgramNoBump; - static std::auto_ptr _VertexProgramNoBumpDiffuse; + static NLMISC::CSmartPtr _VertexProgramNoBump; + static NLMISC::CSmartPtr _VertexProgramNoBumpDiffuse;*/ // - static std::auto_ptr _VertexProgramNoWave; - static std::auto_ptr _VertexProgramNoWaveDiffuse; + static NLMISC::CSmartPtr _VertexProgramNoWave; + static NLMISC::CSmartPtr _VertexProgramNoWaveDiffuse; }; diff --git a/code/nel/include/nel/CMakeLists.txt b/code/nel/include/nel/CMakeLists.txt index 874073eb7..b695104ae 100644 --- a/code/nel/include/nel/CMakeLists.txt +++ b/code/nel/include/nel/CMakeLists.txt @@ -4,6 +4,10 @@ IF(WITH_3D) SUBDIRS(3d) ENDIF(WITH_3D) +IF(WITH_GUI) + ADD_SUBDIRECTORY(gui) +ENDIF(WITH_GUI) + IF(WITH_GEORGES) SUBDIRS(georges) ENDIF(WITH_GEORGES) diff --git a/code/nel/include/nel/gui/CMakeLists.txt b/code/nel/include/nel/gui/CMakeLists.txt new file mode 100644 index 000000000..cae6dae6f --- /dev/null +++ b/code/nel/include/nel/gui/CMakeLists.txt @@ -0,0 +1,3 @@ +FILE(GLOB HEADERS *.h) + +INSTALL(FILES ${HEADERS} DESTINATION include/nel/gui COMPONENT headers) diff --git a/code/nel/include/nel/gui/action_handler.h b/code/nel/include/nel/gui/action_handler.h new file mode 100644 index 000000000..70c4b386e --- /dev/null +++ b/code/nel/include/nel/gui/action_handler.h @@ -0,0 +1,156 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef NL_ACTION_HANDLER_H +#define NL_ACTION_HANDLER_H + +#include "nel/misc/types_nl.h" +#include +#include "nel/misc/types_nl.h" +#include "nel/misc/debug.h" +#include "nel/misc/xml_auto_ptr.h" +#include + +namespace NLGUI +{ + + class CCtrlBase; + + + /** + * interface for action handlers + * \author Nicolas Brigand + * \author Nevrax France + * \date 2002 + */ + class IActionHandler + { + public: + // Execute the answer to the action + // Params has the following form : paramName=theParam|paramName2=theParam2|... + virtual void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */) { } + + virtual ~IActionHandler() {} + + static std::string getParam (const std::string &Params, const std::string &ParamName); + + static void getAllParams (const std::string &Params, std::vector< std::pair > &AllParams); + }; + + + /** + interface for action handlers factory + no release in this factory : a handler must be destroyed by the control that created it + */ + class CAHManager + { + public: + typedef std::map< std::string, IActionHandler* > TFactoryMap; + typedef std::map< IActionHandler*, std::string > TNameMap; + + static CAHManager* getInstance() + { + if (_GlobalInstance == NULL) + _GlobalInstance = new CAHManager; + return _GlobalInstance; + } + + /// return pointer to action handler or null if it doesn't exist + IActionHandler *getActionHandler(const std::string &name) const + { + if( name.empty() ) + return NULL; + + TFactoryMap::const_iterator it = FactoryMap.find(name); + if( it == FactoryMap.end() ) + { + nlwarning( "Couldn't find action handler %s", name.c_str() ); + return NULL; + } + else + return it->second; + } + + /// Return the name of the action handler given its pointer + const std::string &getActionHandlerName(IActionHandler *pAH) const + { + TNameMap::const_iterator it = NameMap.find(pAH); + return it != NameMap.end() ? it->second : EmptyName; + } + + /// map of action handler factories + TFactoryMap FactoryMap; + TNameMap NameMap; + std::string EmptyName; + + /// return the Action Handler 'name'. if name is of form 'ah:params', then params are filled (NB: else not changed) + IActionHandler *getAH(const std::string &name, std::string ¶ms); + IActionHandler *getAH(const std::string &name, class CStringShared ¶ms); + + /** common method to parse Action Handler from a xml node + * \param ahId eg: "onclick_l" + * \param paramId eg: "params_l". + * \param params returned parameters. + * NB: if paramId is NULL, empty or does not exist in the xmlNode, then the optional param in ahId (eg: "show:phrase_book") + * is taken + * NB: if none of the optional param in ahId, or the specified param are filled/found, then params is not changed + */ + void parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, std::string ¶ms); + void parseAH(xmlNodePtr cur, const char *ahId, const char *paramId, IActionHandler *&ahRet, class CStringShared ¶ms); + + /// Get the AH name from ptr + const std::string &getAHName(IActionHandler *pAH){ return getActionHandlerName(pAH); } + + void runActionHandler(const std::string &AHName, CCtrlBase *pCaller, const std::string &Params=std::string("") ); + void runActionHandler(IActionHandler *ah, CCtrlBase *pCaller, const std::string &Params=std::string("") ); + + // Submit a generic event + void submitEvent( const std::string &evt ); + static void setEditorMode( bool b ){ editorMode = b; } + + private: + CAHManager(){} + static CAHManager *_GlobalInstance; + static bool editorMode; + + }; + + /// Ah name must all be lower case + #define REGISTER_ACTION_HANDLER(handler ,name) \ + class handler##Factory : public handler \ + { \ + public: \ + handler##Factory () \ + { \ + nlassert(name!=NULL); \ + const char *c= name; \ + while(*c!='\0') \ + { \ + nlassert(islower(*c) || !isalpha(*c)); \ + c++; \ + } \ + CAHManager *pAHFM = CAHManager::getInstance(); \ + pAHFM->FactoryMap.insert(CAHManager::TFactoryMap::value_type(name,this)); \ + pAHFM->NameMap.insert(CAHManager::TNameMap::value_type(this,name)); \ + }; \ + }; \ + handler##Factory handler##FactoryInstance ; \ + \ + + +} + +#endif //NL_ACTION_HANDLER_H diff --git a/code/nel/include/nel/gui/ctrl_base.h b/code/nel/include/nel/gui/ctrl_base.h new file mode 100644 index 000000000..fe8d5ea60 --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_base.h @@ -0,0 +1,190 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef RZ_CTRL_BASE_H +#define RZ_CTRL_BASE_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/view_base.h" +#include "nel/gui/event_descriptor.h" + +namespace NLGUI +{ + class CCtrlBase : public CViewBase + { + public: + + // Tooltip mode + enum TToolTipParentType + { + TTMouse= 0, // The tooltip is displayed relatively to the mouse when it appears + TTCtrl= 1, // The tooltip is displayed relatively to the ctrl it comes from when it apeears + TTWindow= 2, // The tooltip is displayed relatively to the window where the control lies. + TTSpecialWindow= 3, // The tooltip is displayed relatively to a special user window + + NumToolTipParentRef + }; + + public: + + /// Constructor + CCtrlBase(const TCtorParam ¶m) : CViewBase(param) + { + _ToolTipInstant= true; + _ToolTipParent= TTCtrl; + // see interface.txt for meaning of auto + _ToolTipParentPosRef= Hotspot_TTAuto; + _ToolTipPosRef= Hotspot_TTAuto; + resizer = false; + } + + /// Destructor + virtual ~CCtrlBase(); + + static std::string tooltipParentToString( TToolTipParentType type ); + static TToolTipParentType stringToToolTipParent( const std::string &str ); + + std::string getProperty( const std::string &name ) const; + + void setProperty( const std::string &name, const std::string &value ); + + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + // special parse + virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup); + + + /// Handle all events (implemented by derived classes) (return true to signal event handled) + virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + + virtual CCtrlBase *getSubCtrl (sint32 /* x */, sint32 /* y */) { return this; } + + /// Debug + virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + + + /// Get the ContextHelp for this control. Default is to return _ContextHelp + virtual void getContextHelp(ucstring &help) const {help= _ContextHelp;} + /// Get the ContextHelp for this control, with tooltip specific code. Default behaviour is identical to getContextHelp. + virtual void getContextHelpToolTip(ucstring &help) const { getContextHelp(help); } + // Get the name of the context help window. Default to "context_help" + virtual std::string getContextHelpWindowName() const; + /// Get the ContextHelp ActionHandler. If "", noop + const std::string &getContextHelpActionHandler() const {return _OnContextHelp;} + /// Get the ContextHelp ActionHandler Params + const std::string &getContextHelpAHParams() const {return _OnContextHelpParams;} + /// true if both are empty + bool emptyContextHelp() const; + // Should return true if the context help should be displayed instantly + bool wantInstantContextHelp() const { return _ToolTipInstant; } + /// Set true if ToolTip should be displayed instantly + void setInstantContextHelp(bool instant) { _ToolTipInstant = instant;} + + /** If ctrl has a non rectangle shape, perform further test to know + * if control should be taken in account for context help + */ + virtual bool preciseHitTest(sint32 /* x */, sint32 /* y */) const { return true; } + + + /// return the type of anchor for the tooltip of this control + TToolTipParentType getToolTipParent() const { return _ToolTipParent;} + const std::string &getToolTipSpecialParent() const {return _ToolTipSpecialParent.toString();} + /// Set the type of anchor for the tooltip of this control + void setToolTipParent(TToolTipParentType type) { _ToolTipParent = type; } + void setToolTipSpecialParent(const std::string &parent) { _ToolTipSpecialParent = parent; } + /// Get the ToolTip pos references (parent relevant only if getToolTipParent()!=TTMouse) + THotSpot getToolTipParentPosRef() const { return _ToolTipParentPosRef;} + THotSpot getToolTipPosRef() const { return _ToolTipPosRef;} + THotSpot getToolTipParentPosRefAlt() const { return _ToolTipParentPosRefAlt;} + THotSpot getToolTipPosRefAlt() const { return _ToolTipPosRefAlt;} + /// Set the ToolTip pos references (parent relevant only if getToolTipParent()!=TTMouse) + void setToolTipParentPosRef(THotSpot pos) { _ToolTipParentPosRef = pos;} + void setToolTipPosRef(THotSpot pos) { _ToolTipPosRef = pos;} + + /// replace the default contextHelp + ucstring getDefaultContextHelp() const {return _ContextHelp;} + void setDefaultContextHelp(const ucstring &help) {_ContextHelp= help;} + void setOnContextHelp(const std::string &help) {_OnContextHelp= help;} + void setOnContextHelpAHParams(const std::string &p) {_OnContextHelpParams= p;} + + + + // called when this element or a son has been captured + virtual void elementCaptured(CCtrlBase * /* capturedElement */) {} + + virtual bool isCtrl() const { return true; } + + // Made for CtrlResizer to take the precedence over son controls. + virtual uint getDeltaDepth() const { return 0; } + + // true if this ctrl is capturable (true by default, false for tooltip) + virtual bool isCapturable() const {return true;} + + bool isResizer() const{ return resizer; } + + // from CInterfaceElement + virtual void visit(CInterfaceElementVisitor *visitor); + + /** test if virtual desktop change is possible while this element is captured by the mouse + * Useful for resizers + */ + virtual bool canChangeVirtualDesktop() const { return true; } + + // called when keyboard capture has been lost + virtual void onKeyboardCaptureLost() {} + + REFLECT_EXPORT_START(CCtrlBase, CViewBase) + REFLECT_UCSTRING("tooltip", getDefaultContextHelp, setDefaultContextHelp); + REFLECT_EXPORT_END + + // special for mouse over : return true and fill the name of the cursor to display + virtual bool getMouseOverShape(std::string &/* texName */, uint8 &/* rot */, NLMISC::CRGBA &/* col */) { return false; } + + virtual void serial(NLMISC::IStream &f); + + uint32 getDepth( CInterfaceGroup *group ); + + protected: + // This is the ContextHelp filled by default in parse() + ucstring _ContextHelp; + CStringShared _OnContextHelp; + CStringShared _OnContextHelpParams; + CStringShared _ToolTipSpecialParent; + TToolTipParentType _ToolTipParent; + bool _ToolTipInstant : 1; + THotSpot _ToolTipParentPosRef : 6; + THotSpot _ToolTipPosRef : 6; + THotSpot _ToolTipParentPosRefAlt : 6; + THotSpot _ToolTipPosRefAlt : 6; + protected: + void convertTooltipHotSpot(const char *prop, THotSpot &parentHS, THotSpot &childHS); + static std::string TooltipHotSpotToString( THotSpot parent, THotSpot child ); + + void mapAHString( const std::string &key, const std::string &value ); + std::string getAHString( const std::string &key ) const; + + static std::map< std::string, std::map< std::string, std::string > > AHCache; + + bool resizer; + }; + +} + +#endif // RZ_VIEW_BASE_H + +/* End of ctrl_base.h */ diff --git a/code/nel/include/nel/gui/ctrl_base_button.h b/code/nel/include/nel/gui/ctrl_base_button.h new file mode 100644 index 000000000..d4699305f --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_base_button.h @@ -0,0 +1,270 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef NL_CTRL_BASE_BUTTON_H +#define NL_CTRL_BASE_BUTTON_H + +#include "nel/gui/ctrl_base.h" +#include "nel/gui/action_handler.h" + +namespace NLGUI +{ + + // *************************************************************************** + /** + * Base Class For Buttons. + * \author Lionel Berenguier + * \author Nevrax France + * \date 2003 + */ + class CCtrlBaseButton : public CCtrlBase + { + + public: + enum EType { PushButton = 0, ToggleButton, RadioButton, ButtonTypeCount }; + + /// Constructor + CCtrlBaseButton(const TCtorParam ¶m); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + virtual bool parse (xmlNodePtr cur,CInterfaceGroup * parentGroup); + virtual bool handleEvent (const NLGUI::CEventDescriptor& event); + + /// \name Misc + // @{ + void setType (EType t) { _Type = t; } + EType getType() { return _Type; } + std::string getTypeString() const; + void setTypeFromString( const std::string &type ); + + void setClickWhenPushed(bool click) { _ClickWhenPushed = click; } + bool getClickWhenPushed() const { return _ClickWhenPushed; } + + void setPushed (bool state); + bool getPushed () const { return _Pushed; } + + void setFrozen (bool state); + bool getFrozen () const { return _Frozen; } + + // Set half tone mode for the display of frozen buttons. Default is true. + void setFrozenHalfTone(bool enabled); + bool getFrozenHalfTone() const { return _FrozenHalfTone; } + + // if the radio is a radio button, then all radio button are unselected + void unselect(); + // @} + + + /// \name Colors + // @{ + void setColor(NLMISC::CRGBA col) { _ColorNormal = col; } + void setColorPushed(NLMISC::CRGBA col) { _ColorPushed = col; } + void setColorOver(NLMISC::CRGBA col) { _ColorOver = col; } + + NLMISC::CRGBA getColor() const { return _ColorNormal; } + NLMISC::CRGBA getColorPushed() const { return _ColorPushed; } + NLMISC::CRGBA getColorOver() const { return _ColorOver; } + + // Override because mustupdate 3 states + void setModulateGlobalColorAll(bool state); + void setModulateGlobalColorNormal(bool state) {_ModulateGlobalColorNormal= state;} + void setModulateGlobalColorPushed(bool state) {_ModulateGlobalColorPushed= state;} + void setModulateGlobalColorOver(bool state) {_ModulateGlobalColorOver= state;} + + virtual sint32 getAlpha() const { return _ColorNormal.A; } + virtual void setAlpha (sint32 a) { _ColorOver.A = _ColorNormal.A = _ColorPushed.A = (uint8)a; } + + std::string getColorAsString() const + { return NLMISC::toString(_ColorNormal.R) + " " + NLMISC::toString(_ColorNormal.G) + " " + + NLMISC::toString(_ColorNormal.B) + " " + NLMISC::toString(_ColorNormal.A); } + std::string getColorOverAsString() const + { return NLMISC::toString(_ColorOver.R) + " " + NLMISC::toString(_ColorOver.G) + " " + + NLMISC::toString(_ColorOver.B) + " " + NLMISC::toString(_ColorOver.A); } + std::string getColorPushedAsString() const + { return NLMISC::toString(_ColorPushed.R) + " " + NLMISC::toString(_ColorPushed.G) + " " + + NLMISC::toString(_ColorPushed.B) + " " + NLMISC::toString(_ColorPushed.A); } + + void setColorAsString(const std::string &col) { _ColorNormal = convertColor (col.c_str()); } + void setColorOverAsString(const std::string &col) { _ColorOver = convertColor (col.c_str()); } + void setColorPushedAsString(const std::string &col) { _ColorPushed = convertColor (col.c_str()); } + // @} + + ///\name radio button specific + //@{ + /** Initialize radio button reference + * Advanced: + * NB: must call initRBRef() for radio button if button is created without parse(). + * NB: setParent() must be called before (else assert) + */ + void initRBRef(); + //@} + void initRBRefFromRadioButton(CCtrlBaseButton * pBut); + + + /// \name Handlers + // @{ + // Event part + void setActionOnLeftClick (const std::string &actionHandlerName) { _AHOnLeftClickString = actionHandlerName; _AHOnLeftClick = CAHManager::getInstance()->getAH(actionHandlerName, _AHLeftClickParams); } + void setActionOnLeftClickParams(const std::string ¶ms) { _AHOnLeftClickStringParams = params; } + void setActionOnRightClick (const std::string &actionHandlerName) { _AHOnRightClick = CAHManager::getInstance()->getAH(actionHandlerName, _AHRightClickParams); } + void setActionOnClockTick (const std::string &ahName) { _AHOnClockTick = CAHManager::getInstance()->getAH(ahName, _AHClockTickParams); } + void setParamsOnLeftClick (const std::string ¶msHandlerName) { _AHLeftClickParams = paramsHandlerName; } + void setParamsOnRightClick (const std::string ¶msHandlerName) { _AHRightClickParams = paramsHandlerName; } + void setParamsOnClockTick (const std::string &ahParamsName) { _AHClockTickParams = ahParamsName; } + + // get Event part + std::string _getActionOnOver() const{ return CAHManager::getInstance()->getAHName( _AHOnOver ); } + std::string _getActionOnLeftClick() const { return CAHManager::getInstance()->getAHName( _AHOnLeftClick ); } + std::string _getActionOnLeftLongClick() const { return CAHManager::getInstance()->getAHName( _AHOnLeftLongClick ); } + std::string _getActionOnDblLeftClick() const { return CAHManager::getInstance()->getAHName( _AHOnLeftDblClick ); } + std::string _getActionOnRightClick() const { return CAHManager::getInstance()->getAHName( _AHOnRightClick ); } + std::string _getActionOnClockTick() const { return CAHManager::getInstance()->getAHName( _AHOnClockTick ); } + + IActionHandler *getActionOnLeftClick () const { return _AHOnLeftClick; } + IActionHandler *getActionOnRightClick () const { return _AHOnRightClick; } + IActionHandler *getActionOnClockTick () const { return _AHOnClockTick; } + std::string _getParamsOnOver() const{ return _AHOverParams.toString(); } + std::string _getParamsOnLeftClick () const { return _AHLeftClickParams.toString(); } + const std::string &getParamsOnLeftClick () const { return _AHLeftClickParams; } + const std::string &getParamsOnRightClick () const { return _AHRightClickParams; } + const std::string &getParamsOnClockTick () const { return _AHClockTickParams; } + + // run action on left click + void runLeftClickAction(); + + // Context menu accessor/ One for each button + void setListMenuLeft (const std::string &cm) { _ListMenuLeft = cm; } + void setListMenuRight (const std::string &cm) { _ListMenuRight = cm; } + void setListMenuBoth (const std::string &cm) { _ListMenuLeft= _ListMenuRight= cm; } + std::string getListMenuLeft () { return _ListMenuLeft.toString(); } + std::string getListMenuRight () { return _ListMenuRight.toString(); } + // @} + + + + int luaRunLeftClickAction(CLuaState &ls); + REFLECT_EXPORT_START(CCtrlBaseButton, CCtrlBase) + REFLECT_BOOL("pushed", getPushed, setPushed); + REFLECT_STRING("col_normal", getColorAsString, setColorAsString); + REFLECT_STRING("col_over", getColorOverAsString, setColorOverAsString); + REFLECT_STRING("col_pushed", getColorPushedAsString, setColorPushedAsString); + REFLECT_RGBA("col_normal_rgba", getColor, setColor); + REFLECT_RGBA("col_over_rgba", getColorOver, setColorOver); + REFLECT_RGBA("col_pushed_rgba", getColorPushed, setColorPushed); + REFLECT_BOOL("frozen", getFrozen, setFrozen); + REFLECT_BOOL("frozen_half_tone", getFrozenHalfTone, setFrozenHalfTone); + REFLECT_STRING("onclick_l", _getActionOnLeftClick, setActionOnLeftClick); + REFLECT_STRING("params_l", _getParamsOnLeftClick, setParamsOnLeftClick); + REFLECT_LUA_METHOD("runLeftClickAction", luaRunLeftClickAction); + REFLECT_EXPORT_END + + protected: + EType _Type; + + // State + bool _Pushed : 1; + bool _Over : 1; + bool _OverWhenPushed : 1; + bool _Frozen : 1; + bool _FrozenHalfTone : 1; + bool _ClickWhenPushed : 1; + bool _ModulateGlobalColorNormal : 1; + bool _ModulateGlobalColorPushed : 1; + bool _ModulateGlobalColorOver : 1; + bool _LeftLongClickHandled : 1; // Is it already handled ? + bool _LeftDblClickHandled : 1; + + + ///\name radio button specific + //@{ + CCtrlBaseButton *_RBRefBut; // The reference button. If NULL the control do not own the reference + // There is only one radio button per group that own the reference (the first one) + CCtrlBaseButton **_RBRef; // The pointer onto the reference button + //@} + + + // Colors + NLMISC::CRGBA _ColorNormal; + NLMISC::CRGBA _ColorPushed; + NLMISC::CRGBA _ColorOver; + + ///\name Long click specific + //@{ + sint64 _LeftLongClickDate; // Time we left click down + //@} + + // for double click : last date at which last left click occurred + static sint64 _LastLeftClickDate; + static NLMISC::CRefPtr _LastLeftClickButton; + + ///\name Action Handler + //@{ + IActionHandler *_AHOnOver; + CStringShared _AHOverParams; + std::string _AHOnLeftClickString; + std::string _AHOnLeftClickStringParams; + IActionHandler *_AHOnLeftClick; + CStringShared _AHLeftClickParams; + IActionHandler *_AHOnLeftDblClick; + CStringShared _AHLeftDblClickParams; + IActionHandler *_AHOnRightClick; + CStringShared _AHRightClickParams; + IActionHandler *_AHOnClockTick; + CStringShared _AHClockTickParams; + IActionHandler *_AHOnLeftLongClick; + CStringShared _AHLeftLongClickParams; + //@} + CStringShared _ListMenuLeft; + CStringShared _ListMenuRight; + + // get the colors modulated on request + NLMISC::CRGBA getCurrentColorNormal(NLMISC::CRGBA globalColor) const + { + NLMISC::CRGBA rgba = _ColorNormal; + if(_ModulateGlobalColorNormal) + rgba.modulateFromColor(rgba, globalColor); + return rgba; + } + NLMISC::CRGBA getCurrentColorPushed(NLMISC::CRGBA globalColor) const + { + NLMISC::CRGBA rgba = _ColorPushed; + if(_ModulateGlobalColorPushed) + rgba.modulateFromColor(rgba, globalColor); + return rgba; + } + NLMISC::CRGBA getCurrentColorOver(NLMISC::CRGBA globalColor) const + { + NLMISC::CRGBA rgba = _ColorOver; + if(_ModulateGlobalColorOver) + rgba.modulateFromColor(rgba, globalColor); + return rgba; + } + + // call it at draw + void updateOver(bool &lastOver); + virtual void elementCaptured(CCtrlBase *capturedElement); + }; + +} + +#endif // NL_CTRL_BASE_BUTTON_H + +/* End of ctrl_base_button.h */ diff --git a/code/nel/include/nel/gui/ctrl_button.h b/code/nel/include/nel/gui/ctrl_button.h new file mode 100644 index 000000000..02b827329 --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_button.h @@ -0,0 +1,109 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef RZ_CTRL_BUTTON_H +#define RZ_CTRL_BUTTON_H + +#include "nel/gui/ctrl_base_button.h" +#include "nel/gui/view_renderer.h" + +namespace NLGUI +{ + class CEventDescriptor; + + /** + * + * \author Nicolas Brigand + * \author Nevrax France + * \date 2002 + */ + class CCtrlButton : public CCtrlBaseButton + { + public: + DECLARE_UI_CLASS( CCtrlButton ) + + /// Constructor + CCtrlButton(const TCtorParam ¶m) : CCtrlBaseButton(param) + { + _Scale = false; + _Align = 0; + } + + void setAlignFromString( const std::string &s ); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + // Init part + virtual bool parse (xmlNodePtr cur,CInterfaceGroup * parentGroup); + + virtual void updateCoords(); + + virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + + virtual bool getMouseOverShape(std::string &/* texName */, uint8 &/* rot */, NLMISC::CRGBA &/* col */); + + // Display part + virtual void draw(); + + void setTexture (const std::string&name); + void setTexturePushed (const std::string&name); + void setTextureOver (const std::string&name); + + void fitTexture(); + + std::string getTexture () const; + std::string getTexturePushed () const; + std::string getTextureOver() const; + + bool isTextureValid() const { return _TextureIdNormal != -1; } + + // test if the texture must scale + bool getScale() const { return _Scale; } + void setScale(bool scale) { _Scale = scale; } + + + /// \from CInterfaceElement + sint32 getMaxUsedW() const; + sint32 getMinUsedW() const; + + REFLECT_EXPORT_START(CCtrlButton, CCtrlBaseButton) + REFLECT_STRING("texture", getTexture, setTexture); + REFLECT_STRING("texture_pushed", getTexturePushed, setTexturePushed); + REFLECT_STRING("texture_over", getTextureOver, setTextureOver); + REFLECT_BOOL("scale", getScale, setScale); + REFLECT_EXPORT_END + + protected: + + CViewRenderer::CTextureId _TextureIdNormal; + CViewRenderer::CTextureId _TextureIdPushed; + CViewRenderer::CTextureId _TextureIdOver; + + private: + + bool _Scale; + sint32 _Align; /// 1st bit - Left/Right (0/1) 2nd bit - Bottom/Top (0/1) + }; + +} + +#endif // RZ_CTRL_BUTTON_H + +/* End of ctrl_button.h */ diff --git a/code/nel/include/nel/gui/ctrl_col_pick.h b/code/nel/include/nel/gui/ctrl_col_pick.h new file mode 100644 index 000000000..dd779e837 --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_col_pick.h @@ -0,0 +1,111 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef RZ_CTRL_COL_PICK_H +#define RZ_CTRL_COL_PICK_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/ctrl_base.h" + + +namespace NLGUI +{ + + /** + * Class handling a Color Picker + * \author Matthieu 'TrapII' Besson + * \author Nevrax France + * \date 2003 + */ + class CCtrlColPick : public CCtrlBase + { + + public: + DECLARE_UI_CLASS( CCtrlColPick ) + + CCtrlColPick(const TCtorParam ¶m); + ~CCtrlColPick(); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup); + + virtual void updateCoords(); + virtual void draw(); + virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + + sint32 getColorR () const { return _ColorSelect.R; } + sint32 getColorG () const { return _ColorSelect.G; } + sint32 getColorB () const { return _ColorSelect.B; } + sint32 getColorA () const { return _ColorSelect.A; } + + void setColorR (sint32 r) { _ColorSelect.R = (uint8)r; } + void setColorG (sint32 g) { _ColorSelect.G = (uint8)g; } + void setColorB (sint32 b) { _ColorSelect.B = (uint8)b; } + void setColorA (sint32 a) { _ColorSelect.A = (uint8)a; } + + + std::string getColor () const; // Get Color Selected + void setColor (const std::string &col); // Set Color Selected + + std::string getColorOver () const; // Get Color Over + void setColorOver (const std::string &col); // Set Color Over + + REFLECT_EXPORT_START(CCtrlColPick, CCtrlBase) + REFLECT_SINT32("r", getColorR, setColorR); + REFLECT_SINT32("g", getColorG, setColorG); + REFLECT_SINT32("b", getColorB, setColorB); + REFLECT_SINT32("a", getColorA, setColorA); + REFLECT_STRING("color", getColor, setColor); + REFLECT_STRING("color_over", getColorOver, setColorOver); + REFLECT_EXPORT_END + + + protected: + + void selectColor (sint32 x, sint32 y); + NLMISC::CRGBA getColor (sint32 x, sint32 y); + + protected: + + bool _MouseDown; + + sint32 _Texture; + + NLMISC::CRGBA _ColorSelect; // Last Color selected + NLMISC::CRGBA _ColorOver; // Color Under Mouse Pointer + + std::string _AHOnChange; + std::string _AHOnChangeParams; + + CInterfaceProperty _ColSelR; + CInterfaceProperty _ColSelG; + CInterfaceProperty _ColSelB; + CInterfaceProperty _ColSelA; + }; + +} + + +#endif // RZ_CTRL_COL_PICK_H + +/* End of ctrl_col_pick.h */ + + diff --git a/code/nel/include/nel/gui/ctrl_draggable.h b/code/nel/include/nel/gui/ctrl_draggable.h new file mode 100644 index 000000000..3f625db1d --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_draggable.h @@ -0,0 +1,64 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef CTRL_DRAGGABLE_H +#define CTRL_DRAGGABLE_H + +#include "nel/gui/ctrl_base.h" + +namespace NLGUI +{ + + class CCtrlDraggable : public CCtrlBase + { + public: + DECLARE_UI_CLASS( CCtrlDraggable ) + + CCtrlDraggable( const TCtorParam ¶m ); + virtual ~CCtrlDraggable(){}; + + static CCtrlDraggable *getDraggedSheet(){ return _LastDraggedSheet; } + bool isDragged() const{ return dragged; } + void setDragged( bool dragged ){ this->dragged = dragged; } + bool isDraggable() const{ return draggable; } + void setDraggable( bool draggable ){ this->draggable = draggable; } + + void abortDragging() + { + dragged = false; + _LastDraggedSheet = NULL; + } + + // Necessary because of reflection, no other purpose + void draw(){} + + REFLECT_EXPORT_START(CCtrlDraggable, CCtrlBase) + REFLECT_BOOL("dragable", isDraggable, setDraggable); + REFLECT_EXPORT_END + + protected: + static void setDraggedSheet( CCtrlDraggable *draggable ){ _LastDraggedSheet = draggable; } + + private: + static CCtrlDraggable *_LastDraggedSheet; + bool dragged; + bool draggable; + }; + +} + +#endif diff --git a/code/nel/include/nel/gui/ctrl_polygon.h b/code/nel/include/nel/gui/ctrl_polygon.h new file mode 100644 index 000000000..cef57dd3c --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_polygon.h @@ -0,0 +1,95 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef RZ_CTRL_POLYGON_H +#define RZ_CTRL_POLYGON_H + +#include "nel/gui/ctrl_base.h" +#include "nel/gui/view_renderer.h" +#include "nel/misc/geom_ext.h" +#include "nel/misc/polygon.h" + +namespace NLMISC +{ + class CVector2f; +} + +namespace NLGUI +{ + + /** Display of an arbitrary polygon in the ui. + * polygons are clipped & batched. + * + * Derives from CCtrlBase in order to provide button / tooltip capability + * + * \author Nicolas Vizerie + * \author Nevrax France + * \date 1/2006 + */ + class CCtrlPolygon : public CCtrlBase + { + public: + DECLARE_UI_CLASS( CCtrlPolygon ) + CCtrlPolygon( const TCtorParam ¶m ); + virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + virtual void updateCoords(); + virtual void draw(); + /** Change the vertices. This is costly because concav / complex polys are split in a list of triangles + */ + void setVertices(const std::vector &vertices); + const std::vector &getVertices() const { return _Poly.Vertices; } + // test if current position in inside the current (transformed) poly (in window space) + bool contains(const NLMISC::CVector2f &pos) const; + // color + void setColorRGBA(NLMISC::CRGBA col) { _Color = col; } + NLMISC::CRGBA getColorRGBA() const { return _Color; } + // from CViewBase + virtual sint32 getAlpha() const { return (sint32) _Color.A; } + virtual void setAlpha(sint32 a); + /** Change the matrix for this poly. Changing the matrix is usually cheaper than changing + * The vertices because complex poly do not have to be split again + */ + //void setMatrix(const NLMISC::CMatrix &mat); + //const NLMISC::CMatrix &getMatrix() const { return _Matrix; } + // test if last call to 'setVertices' was for a valid poly (e.g one that doesn't overlapp itself) + bool isValid() const { return _Valid; } + virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + + // no capturable by default (just tooltip capability wanted) + virtual bool isCapturable() const { return false; } + private: + NLMISC::CPolygon _Poly; + NLMISC::CPolygon2D _XFormPoly; + //NLMISC::CMatrix _Matrix; + bool _Valid; + bool _Touched; + NLMISC::CRGBA _Color; + std::vector _Tris; + std::vector _RealTris; // clipped tris in screen coordinates + private: + void updateBoudingRect(); + protected: + // TMP TMP : have to solve matrix imprecision for display in map -> do the full computation for now ... + virtual void computeScaledVertex(NLMISC::CVector2f &dest, const NLMISC::CVector2f &src); + public: + void touch(); + }; + +} + + +#endif diff --git a/code/nel/include/nel/gui/ctrl_quad.h b/code/nel/include/nel/gui/ctrl_quad.h new file mode 100644 index 000000000..08c89675e --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_quad.h @@ -0,0 +1,118 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef RZ_CTRL_QUAD_H +#define RZ_CTRL_QUAD_H + +#include "nel/gui/ctrl_base.h" +#include "nel/gui/view_renderer.h" +#include "nel/misc/geom_ext.h" + +namespace NLGUI +{ + + /** Display of an arbitrary textured quad in the UI. The applied texture is filtered. + * Unlike CViewBitmap, the texture is always scaled here, and this ui element coordinates + * are driven by the quad vertices coordinates (see setQuad). + * + * Derives from CCtrlBase for tooltipping support + * + * \author Nicolas Vizerie + * \author Nevrax France + * \date 12/2005 + */ + class CCtrlQuad : public CCtrlBase + { + public: + DECLARE_UI_CLASS( CCtrlQuad ) + + enum TWrapMode { Repeat = 0, Clamp, CustomUVs, WrapModeCount }; + + + CCtrlQuad( const TCtorParam ¶m ); + + // from CInterfaceElement + bool parse(xmlNodePtr cur,CInterfaceGroup *parentGroup); + virtual void updateCoords(); + virtual void draw(); + virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + + // from CViewBase + virtual sint32 getAlpha() const { return (sint32) _Color.A; } + virtual void setAlpha (sint32 a); + + // texture + void setTexture(const std::string &texName); + std::string getTexture () const; + + // color + void setColorRGBA(NLMISC::CRGBA col) { _Color = col; } + NLMISC::CRGBA getColorRGBA() const { return _Color; } + + /** Set a new quad relative to parent pos + * x,y, w, h & hotspot are updated to fit the bounding rect of the quad + */ + void setQuad(const NLMISC::CQuad &quad); + void setQuad(const NLMISC::CVector &start, const NLMISC::CVector &end, float thickness); + /** Fit the given texture size (no hotspot for now, always centered) + * NB : current texture is not modified. + */ + void setQuad(const std::string &texName, const NLMISC::CVector &pos, float angle = 0.f, float offCenter = 0.f); + void setQuad(const NLMISC::CVector &pos, float radius, float angle = 0.f); + const NLMISC::CQuad &getQuad() const { return _Quad; } + + void setAdditif(bool additif); + bool getAdditif() const { return _Additif; } + + void setFiltered(bool filtered); + bool getFiltered() const { return _Filtered; } + + void setPattern(float umin, float umax, TWrapMode wrapMode); + + /** Set uvs for each corners -> this will change the wrap mode to CustomUVs + * Use setPattern(0.f, 0.f, CCtrlQuad::Repeat) to return to previous behavior + */ + void setCustomUVs(const NLMISC::CUV uvs[4]); + + + // from CCtrlBase, no op by default + virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + + // see if this control contains the given point (in parent coords) + bool contains(const NLMISC::CVector2f &pos) const; + + // no capturable by default (just tooltip capability wanted) + virtual bool isCapturable() const { return false; } + + + private: + NLMISC::CRGBA _Color; + NLMISC::CQuad _Quad; + NLMISC::CQuadUV _RealQuad; // absolute coords + float _ClampedUCorrection; + CViewRenderer::CTextureId _TextureId; /// Accelerator + bool _Additif; + bool _Filtered; + float _UMin; + float _UMax; + TWrapMode _WrapMode; + NLMISC::CUV _CustomUVs[4]; + }; + +} + +#endif diff --git a/code/nel/include/nel/gui/ctrl_scroll.h b/code/nel/include/nel/gui/ctrl_scroll.h new file mode 100644 index 000000000..b01a3bf81 --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_scroll.h @@ -0,0 +1,206 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef RZ_CTRL_SCROLL_H +#define RZ_CTRL_SCROLL_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/ctrl_scroll_base.h" + + +namespace NLGUI +{ + + /** + * Class handling scollbar function + * \author Matthieu 'TrapII' Besson + * \author Nevrax France + * \date 2002 + */ + class CCtrlScroll : public CCtrlScrollBase, public NLMISC::ICDBNode::IPropertyObserver + { + + public: + DECLARE_UI_CLASS( CCtrlScroll ) + CCtrlScroll(const TCtorParam ¶m); + ~CCtrlScroll(); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup); + + virtual void updateCoords(); + virtual void draw(); + virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + + void setTarget (CInterfaceGroup *pIG); + // Return the delta value the track has moved + sint32 moveTrackX (sint32 dx); + sint32 moveTrackY (sint32 dy); + + /** Move the Target Ofs with a Delta, and recompute TrackPos from this Ofs. + * Useful for finer controled group scrolling when the list is very big (with mouseWheel or scroll buttons) + */ + void moveTargetX (sint32 dx); + void moveTargetY (sint32 dy); + + void setAlign (sint32 nAlign) { _Aligned = nAlign; } + // invert the factor for target + void setInverted(bool invert) { _Inverted = invert; } + + void setTextureBottomOrLeft (const std::string &txName); + void setTextureMiddle (const std::string &txName); + void setTextureTopOrRight (const std::string &txName); + std::string getTextureBottomOrLeft() const; + std::string getTextureMiddle() const; + std::string getTextureTopOrRight() const; + + void setTextureBottomOrLeft (sint32 txid) { _TxIdB = txid; } + void setTextureMiddle (sint32 txid) { _TxIdM = txid; } + void setTextureMiddleTile (uint8 tile) { _TileM = tile; } // 0 - not tiled (1 BL) (2 BR) (3 TL) (4 TR) + void setTextureTopOrRight (sint32 txid) { _TxIdT = txid; } + + // number scroller + sint32 getValue() const { return _IsDBLink ? _DBLink.getSInt32() : _Value; } + // NB: the value is clamped (see setMinMax) and stepped (see setStepValue()) + void setValue(sint32 value); + void setMinMax(sint32 nMin, sint32 nMax) { _Min = nMin; _Max = nMax; } + void setStepValue(uint32 step) { _StepValue= step; } + + void setTrackPos(sint32 pos); + sint32 getTrackPos() const { return _TrackPos; } + sint32 getTrackSize() const { return _TrackSize; } + // dummy set for track size (forlua export) + void setTrackSize(sint32 /* trackSize */) { throw NLMISC::Exception("TrackSize is read-only"); } + + + void setFrozen (bool state); + bool getFrozen () const { return _Frozen; } + + int luaSetTarget(CLuaState &ls); + int luaEnsureVisible(CLuaState &ls); + + // name + void setName(const std::string & val) {_Name = val;} + std::string getName() const {return _Name;} + + // max + void setMax(sint32 max) {_Max = max;} + sint32 getMax() const {return _Max;} + + REFLECT_EXPORT_START(CCtrlScroll, CCtrlScrollBase) + REFLECT_LUA_METHOD("setTarget", luaSetTarget) + REFLECT_LUA_METHOD("ensureVisible", luaEnsureVisible); + REFLECT_SINT32("value", getValue, setValue); + REFLECT_SINT32("trackPos", getTrackPos, setTrackPos); + REFLECT_SINT32("trackSize", getTrackSize, setTrackSize); + REFLECT_STRING("name", getName, setName); + REFLECT_SINT32("max", getMax, setMax); + REFLECT_EXPORT_END + + /** Ensure that a child element be visible into the frame through which + * its parent group is displayed. + * Example : Had we a list of items for which we want some item 'itemPtr' to have its top position + * matching the middle of the list, we would do : + * this->ensureVisible(itemPtr, Hotspot_Tx, Hotspot_Mx); + * + * The scrollbar will be moved accordingly. + */ + void ensureVisible(CInterfaceElement *childElement, THotSpot childHotSpot, THotSpot parentHotSpot); + + + protected: + + CInterfaceProperty _DBLink; // If this is a value scroller we can link it with db + sint32 _Value; // Or we can use a normal value + sint32 _InitialValue; + + sint32 _Min, _Max; + std::string _AHOnScroll; + std::string _AHOnScrollParams; + // + std::string _AHOnScrollEnd; + std::string _AHOnScrollEndParams; + // + // + std::string _AHOnScrollCancel; + std::string _AHOnScrollCancelParams; + + + sint32 _Aligned; // 0-Top 1-Bottom 2-Left 3-Right + + sint32 _TrackDispPos; + sint32 _TrackPos; + sint32 _TrackSize; + sint32 _TrackSizeMin; + + sint32 _MouseDownOffsetX; + sint32 _MouseDownOffsetY; + + sint32 _TxIdB; // Same as Left if Horizontal sb + sint32 _TxIdM; + sint32 _TxIdT; // Same as Right if Horizontal sb + + uint8 _TileM; + + sint32 _LastTargetHReal; + sint32 _LastTargetMaxHReal; + sint32 _LastTargetOfsY; + sint32 _LastTargetWReal; + sint32 _LastTargetMaxWReal; + sint32 _LastTargetOfsX; + + bool _Vertical : 1; // true if vertical track bar + bool _IsDBLink : 1; + bool _ObserverOn : 1; + bool _Inverted : 1; + bool _MouseDown : 1; + bool _CallingAH : 1; + bool _Cancelable : 1; // true if the slider may be cancelled when pressed on the mouse right button + bool _Frozen : 1; + + // For Target Scroller only: the target offset step in pixel. + sint32 _TargetStepX; + sint32 _TargetStepY; + + // For Value Scroller only: indicate the step the scroll bar has. 0 or 1 means no step + uint32 _StepValue; + + // Slider's name + std::string _Name; + + void computeTargetOfsFromPos(); + + // from IPropertyObserver + virtual void update(NLMISC::ICDBNode *node); + + // step the value, and clamp it + void normalizeValue(sint32 &value); + + void runAH(const std::string &name, const std::string ¶ms); + + }; +} + +#endif // RZ_CTRL_SCROLL_H + +/* End of ctrl_scroll.h */ + + diff --git a/code/nel/include/nel/gui/ctrl_scroll_base.h b/code/nel/include/nel/gui/ctrl_scroll_base.h new file mode 100644 index 000000000..38cfd9c09 --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_scroll_base.h @@ -0,0 +1,60 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef CTRL_SCROLL_BASE_H +#define CTRL_SCROLL_BASE_H + +#include "nel/gui/ctrl_base.h" + +namespace NLGUI +{ + + class CInterfaceGroup; + + class CCtrlScrollBase : public CCtrlBase + { + public: + DECLARE_UI_CLASS( CCtrlScrollBase ) + + CCtrlScrollBase( const TCtorParam ¶m ); + virtual ~CCtrlScrollBase(); + + virtual void setTarget( CInterfaceGroup *pIG ); + CInterfaceGroup* getTarget(){ return _Target; } + virtual sint32 moveTrackX( sint32 dx ); + virtual sint32 moveTrackY( sint32 dy ); + + /** Move the Target Ofs with a Delta, and recompute TrackPos from this Ofs. + * Useful for finer controled group scrolling when the list is very big (with mouseWheel or scroll buttons) + */ + virtual void moveTargetX( sint32 dx ); + virtual void moveTargetY( sint32 dy ); + + + // Necessary because of reflection, no other purpose + void draw(){} + + protected: + CInterfaceGroup *_Target; // If NULL the scroller is a value scroller + + private: + + }; + +} + +#endif + diff --git a/code/nel/include/nel/gui/ctrl_sheet_selection.h b/code/nel/include/nel/gui/ctrl_sheet_selection.h new file mode 100644 index 000000000..36d1c8336 --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_sheet_selection.h @@ -0,0 +1,83 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef CL_SHEET_CTRL_SELECTION_H +#define CL_SHEET_CTRL_SELECTION_H + +namespace NLGUI +{ + class IActionHandler; + + /** Infos about a selection group + */ + class CSheetSelectionGroup + { + public: + CSheetSelectionGroup(std::string name) : _Name(name), _Active(false), _TextureIndex(-1), _Color(NLMISC::CRGBA::White), _GlobalColorEnabled(true) {} + void setTexture(const std::string &texName); + sint32 getTextureIndex() const { return _TextureIndex; } + sint32 getTextureWidth() const { return _TextureWidth; } + sint32 getTextureHeight() const { return _TextureHeight; } + void setColor(NLMISC::CRGBA color) { _Color = color; } + NLMISC::CRGBA getColor() const { return _Color; } + void setActive(bool active) { _Active = active; } + bool isActive() const { return _Active; } + const std::string &getName() const { return _Name; } + void enableGlobalColor(bool enabled) { _GlobalColorEnabled = enabled; } + bool isGlobalColorEnabled() const { return _GlobalColorEnabled; } + private: + std::string _Name; + bool _Active; + sint32 _TextureIndex; // index for the selection texture + sint32 _TextureWidth; + sint32 _TextureHeight; + NLMISC::CRGBA _Color; // color that modulate the texture of selection + bool _GlobalColorEnabled; + }; + + /** Class to manage selection of sheet. + * Sheet are managed by groups, identified by their ID. + */ + class CCtrlSheetSelection + { + public: + // Add a group, and returns its index, or -1 if already created. + sint addGroup(const std::string &name); + // Get a group by its name (must exist) + CSheetSelectionGroup *getGroup(const std::string &name); + const CSheetSelectionGroup *getGroup(const std::string &name) const; + // Get a group by its index + CSheetSelectionGroup *getGroup(uint index); + const CSheetSelectionGroup *getGroup(uint index) const; + // Get the index of a group from its name, return -1 if not a group + sint getGroupIndex(const std::string &name) const; + // Deactivate all groups + void deactivateAll(); + // delete all groups + void deleteGroups(); + private: + // + typedef std::vector TGroupVect; + typedef std::map TGroupNameToIndex; + private: + TGroupVect _Groups; + TGroupNameToIndex _GroupNameToIndex; + }; + +} + +#endif diff --git a/code/nel/include/nel/gui/ctrl_text_button.h b/code/nel/include/nel/gui/ctrl_text_button.h new file mode 100644 index 000000000..2df1dee5d --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_text_button.h @@ -0,0 +1,171 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef NL_CTRL_TEXT_BUTTON_H +#define NL_CTRL_TEXT_BUTTON_H + +#include "nel/gui/ctrl_base_button.h" +#include "nel/gui/view_renderer.h" + + +namespace NLGUI +{ + class CEventDescriptor; + class CViewText; + + // *************************************************************************** + /** + * Text Button that can be either Push or Toggle button. Localized, auto-resize + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CCtrlTextButton : public CCtrlBaseButton + { + public: + DECLARE_UI_CLASS( CCtrlTextButton ) + + /// Constructor + CCtrlTextButton(const TCtorParam ¶m); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + // Init part + virtual bool parse (xmlNodePtr cur,CInterfaceGroup * parentGroup); + + virtual void updateCoords(); + + virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + + // Display part + virtual void draw(); + + // Hide/Show the text also. + virtual void setActive(bool state); + + // Add also our ViewText + virtual void onAddToGroup(); + + + /// \from CInterfaceElement + sint32 getMaxUsedW() const; + sint32 getMinUsedW() const; + + // Special Text Colors accessors + // Colors + NLMISC::CRGBA getTextColorNormal() const {return _TextColorNormal;} + void setTextColorNormal(NLMISC::CRGBA v) {_TextColorNormal= v;} + NLMISC::CRGBA getTextColorPushed() const {return _TextColorPushed;} + void setTextColorPushed(NLMISC::CRGBA v) {_TextColorPushed= v;} + NLMISC::CRGBA getTextColorOver() const {return _TextColorOver;} + void setTextColorOver(NLMISC::CRGBA v) {_TextColorOver= v;} + // Shadow Colors + NLMISC::CRGBA getTextShadowColorNormal() const {return _TextShadowColorNormal;} + void setTextShadowColorNormal(NLMISC::CRGBA v) {_TextShadowColorNormal= v;} + NLMISC::CRGBA getTextShadowColorPushed() const {return _TextShadowColorPushed;} + void setTextShadowColorPushed(NLMISC::CRGBA v) {_TextShadowColorPushed= v;} + NLMISC::CRGBA getTextShadowColorOver() const {return _TextShadowColorOver;} + void setTextShadowColorOver(NLMISC::CRGBA v) {_TextShadowColorOver= v;} + // Global Modulate Colors + bool getTextModulateGlobalColorNormal() const {return _TextModulateGlobalColorNormal;} + void setTextModulateGlobalColorNormal(bool v) {_TextModulateGlobalColorNormal= v;} + bool getTextModulateGlobalColorPushed() const {return _TextModulateGlobalColorPushed;} + void setTextModulateGlobalColorPushed(bool v) {_TextModulateGlobalColorPushed= v;} + bool getTextModulateGlobalColorOver() const {return _TextModulateGlobalColorOver;} + void setTextModulateGlobalColorOver(bool v) {_TextModulateGlobalColorOver= v;} + // Set text (noop if text id) + void setText (const ucstring &text); + ucstring getText () const; + + void setHardText (const std::string &text); + std::string getHardText () const; + + CViewText* getViewText(); + void setViewText(CViewText* text) {_ViewText=text;} + + void setTextX(sint32 x); + sint32 getTextX() const { return _TextX; } + + void setWMargin(sint32 w) { _WMargin = w; } + sint32 getWMargin() const { return _WMargin; } + + sint32 getWMin() const { return _WMin; } + void setWMin( sint32 wmin ) { _WMin = wmin; } + + // Compute Size according to bitmap and Text (Ensure as big as possible button) + sint32 getWMax() const; + + int luaGetViewText(CLuaState &ls); + + REFLECT_EXPORT_START(CCtrlTextButton, CCtrlBaseButton) + REFLECT_UCSTRING("uc_hardtext", getText, setText); + REFLECT_STRING("hardtext", getHardText, setHardText); + REFLECT_SINT32("text_x", getTextX, setTextX) + REFLECT_SINT32("wmargin", getWMargin, setWMargin) + REFLECT_SINT32("wmin", getWMin, setWMin) + REFLECT_LUA_METHOD("getViewText", luaGetViewText) + REFLECT_EXPORT_END + + protected: + + enum {NumTexture= 3}; + + CViewRenderer::CTextureId _TextureIdNormal[NumTexture]; + CViewRenderer::CTextureId _TextureIdPushed[NumTexture]; + CViewRenderer::CTextureId _TextureIdOver[NumTexture]; + + // setup + void setup(); + + private: + + CViewText *_ViewText; + + bool _Setuped; + bool _IsViewTextId; + bool _ForceTextOver; // text is displayed over the "over" texture + // Size of Bitmaps + sint32 _BmpLeftW, _BmpMiddleW, _BmpRightW, _BmpH; + // Value to add to TextW to get button W. + sint32 _WMargin; + // Min W Value + sint32 _WMin; + sint32 _TextY; + sint32 _TextX; + THotSpot _TextPosRef; + THotSpot _TextParentPosRef; + // Special Colors for text + NLMISC::CRGBA _TextColorNormal; + NLMISC::CRGBA _TextColorPushed; + NLMISC::CRGBA _TextColorOver; + NLMISC::CRGBA _TextShadowColorNormal; + NLMISC::CRGBA _TextShadowColorPushed; + NLMISC::CRGBA _TextShadowColorOver; + bool _TextModulateGlobalColorNormal; + bool _TextModulateGlobalColorPushed; + bool _TextModulateGlobalColorOver; + bool _TextHeaderColor; + }; + +} + +#endif // NL_CTRL_TEXT_BUTTON_H + +/* End of ctrl_text_button.h */ diff --git a/code/ryzom/client/src/interface_v3/ctrl_tooltip.h b/code/nel/include/nel/gui/ctrl_tooltip.h similarity index 56% rename from code/ryzom/client/src/interface_v3/ctrl_tooltip.h rename to code/nel/include/nel/gui/ctrl_tooltip.h index da5e17468..a96bbad40 100644 --- a/code/ryzom/client/src/interface_v3/ctrl_tooltip.h +++ b/code/nel/include/nel/gui/ctrl_tooltip.h @@ -19,35 +19,41 @@ #ifndef RZ_CTRL_TOOLTIP_H #define RZ_CTRL_TOOLTIP_H -#include "ctrl_base.h" +#include "nel/gui/ctrl_base.h" #include "nel/3d/u_texture.h" -class CEventDescriptor; -class CInterfaceManager; - -/** - * \author Matthieu 'Mr TRAP' Besson - * \author Nevrax France - * \date 2003 - */ -class CCtrlToolTip : public CCtrlBase +namespace NLGUI { -public: - DECLARE_UI_CLASS(CCtrlToolTip) - /// Constructor - CCtrlToolTip(const TCtorParam ¶m) : CCtrlBase(param) {} + class CEventDescriptor; - virtual bool handleEvent (const CEventDescriptor& eventDesc); - virtual void draw(); - virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); - // Can do nothing with tooltip (but display it :) ) - virtual bool isCapturable() const {return false;} - virtual void serial(NLMISC::IStream &f); -public: -}; + /** + * \author Matthieu 'Mr TRAP' Besson + * \author Nevrax France + * \date 2003 + */ + class CCtrlToolTip : public CCtrlBase + { + public: + DECLARE_UI_CLASS(CCtrlToolTip) + /// Constructor + CCtrlToolTip(const TCtorParam ¶m) : CCtrlBase(param) {} + virtual bool handleEvent (const NLGUI::CEventDescriptor& eventDesc); + virtual void draw(); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + // Can do nothing with tooltip (but display it :) ) + virtual bool isCapturable() const {return false;} + virtual void serial(NLMISC::IStream &f); + public: + + }; + + +} #endif // RZ_CTRL_TOOLTIP_H /* End of ctrl_tooltip.h */ + diff --git a/code/nel/include/nel/gui/db_manager.h b/code/nel/include/nel/gui/db_manager.h new file mode 100644 index 000000000..d5036204d --- /dev/null +++ b/code/nel/include/nel/gui/db_manager.h @@ -0,0 +1,71 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef DBMANAGER_H +#define DBMANAGER_H + +#include "nel/misc/cdb_manager.h" + +namespace NLGUI +{ + + /** + Database Manager + + Provides access to a simple CDB based tree hierarchical data store + */ + class CDBManager : public NLMISC::CCDBManager + { + public: + static CDBManager* getInstance(); + static void release(); + + /** + Retrieves a leaf node from the database. + @param name - name of the data leaf node we are querying. + @param create - when true if a node cannot be found it is created. + */ + NLMISC::CCDBNodeLeaf* getDbProp( const std::string &name, bool create = true ); + + /** + Deletes a node from the database. + @param name - name of the node. + */ + void delDbProp( const std::string &name ); + + /** + Returns a leaf node's content as an sint32 + @param name - name of the leaf node. + */ + sint32 getDbValue32( const std::string &name ); + + /** + Returns the root branch of the database. + */ + NLMISC::CCDBNodeBranch* getDB() const; + + private: + CDBManager(); + ~CDBManager(); + + static CDBManager *instance; + + }; + +} + +#endif diff --git a/code/nel/include/nel/gui/dbgroup_combo_box.h b/code/nel/include/nel/gui/dbgroup_combo_box.h new file mode 100644 index 000000000..75208b1e3 --- /dev/null +++ b/code/nel/include/nel/gui/dbgroup_combo_box.h @@ -0,0 +1,170 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef NL_DBGROUP_COMBO_BOX_H +#define NL_DBGROUP_COMBO_BOX_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/interface_group.h" + +namespace NLGUI +{ + class CCtrlBaseButton; + class CViewText; + class CGroupMenu; + + + // *************************************************************************** + /** + * Widget: ComboBox of text + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CDBGroupComboBox : public CInterfaceGroup + { + public: + DECLARE_UI_CLASS( CDBGroupComboBox ) + + /// Constructor + CDBGroupComboBox(const TCtorParam ¶m); + ~CDBGroupComboBox(); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + /// CInterfaceGroup Interface + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + virtual void updateCoords (); + virtual void checkCoords (); + + // Combo Texts + void resetTexts(); + void addText(const ucstring &text); + void setText(uint i, const ucstring &text); + void insertText(uint i, const ucstring &text); + const ucstring &getText(uint i) const; + const uint &getTextId(uint i) const; + uint getTextPos(uint nId) const; + const ucstring &getTexture(uint i) const; + void removeText(uint nPos); + uint getNumTexts() const {return (uint)_Texts.size();} + void sortText(); + + // selection + void setSelection(sint32 val); + void setSelectionNoTrigger(sint32 val); + sint32 getSelection() const; + + // selection number + void setSelectionNb(sint32 /* val */){} + sint32 getSelectionNb() const {return (sint32)_Texts.size();} + + // selection text + void setSelectionText(const std::string & val); + std::string getSelectionText() const; + + // view text + void setViewText(const ucstring & text); + ucstring getViewText() const; + + void setTexture(uint i, const ucstring &texture); + + sint32 evalContentWidth() const; + + + int luaAddText(CLuaState &ls); + int luaRemoveSelection(CLuaState &ls); + int luaRemoveText(CLuaState &ls); + int luaRemoveTextByIndex(CLuaState &ls); + int luaResetTexts(CLuaState &ls); + int luaSetText(CLuaState &ls); + int luaInsertText(CLuaState &ls); + int luaGetText(CLuaState &ls); + int luaGetNumTexts(CLuaState &ls); + int luaSetTexture(CLuaState &ls); + + + REFLECT_EXPORT_START(CDBGroupComboBox, CInterfaceGroup) + REFLECT_SINT32("selection", getSelection, setSelection) + REFLECT_LUA_METHOD("addText", luaAddText) + REFLECT_LUA_METHOD("setText", luaSetText) + REFLECT_LUA_METHOD("insertText", luaInsertText) + REFLECT_LUA_METHOD("setTexture", luaSetTexture) + REFLECT_LUA_METHOD("getText", luaGetText) + REFLECT_LUA_METHOD("getNumTexts", luaGetNumTexts) + REFLECT_LUA_METHOD("removeSelection", luaRemoveSelection) + REFLECT_LUA_METHOD("removeText", luaRemoveText) + REFLECT_LUA_METHOD("removeTextByIndex", luaRemoveTextByIndex) + REFLECT_LUA_METHOD("resetTexts", luaResetTexts) + REFLECT_SINT32 ("selectionNb", getSelectionNb, setSelectionNb) + REFLECT_STRING ("selection_text", getSelectionText, setSelectionText) + REFLECT_UCSTRING ("view_text", getViewText, setViewText) + REFLECT_EXPORT_END + + + protected: + friend class CHandlerComboBoxSelectStart; + + bool _LinkedToDB; // if not linked to db, then _NotLinkedToDBSelection is used instead + bool _Setuped; + bool _DirtySelection; + sint32 _CacheSelection; + + // sint32 + CInterfaceProperty _Selection; + sint32 _NotLinkedToDBSelection; + std::vector > _Texts; + std::vector _Textures; + + // Action Handler called on combo click + std::string _AHOnSelectStart; + + // Action handler called when the content is changed + std::string _AHOnChange; + std::string _AHOnChangeParams; + bool _CallingOnChangeActionHandler; // avoid infinite loop here + + + // Children + CViewText *_ViewText; + CCtrlBaseButton *_SelectButton; + + bool _IsExternViewText; + ucstring _ExternViewText; + + + private: + void setup(); + void dirt(); + public: + // private : fill a menu with current content + void fillMenu(CGroupMenu *groupMenu) const; + + + static std::string measureMenu; + static std::string selectMenu; + static std::string selectMenuOut; + }; + +} + +#endif // NL_DBGROUP_COMBO_BOX_H + +/* End of dbgroup_combo_box.h */ diff --git a/code/nel/include/nel/gui/dbgroup_select_number.h b/code/nel/include/nel/gui/dbgroup_select_number.h new file mode 100644 index 000000000..a5ef692ff --- /dev/null +++ b/code/nel/include/nel/gui/dbgroup_select_number.h @@ -0,0 +1,101 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef NL_DBGROUP_SELECT_NUMBER_H +#define NL_DBGROUP_SELECT_NUMBER_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/interface_group.h" + + +namespace NLGUI +{ + class CCtrlBaseButton; + class CViewText; + class CViewBitmap; + + // *************************************************************************** + /** + * Widget to select a number + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CDBGroupSelectNumber : public CInterfaceGroup + { + public: + DECLARE_UI_CLASS( CDBGroupSelectNumber ) + + /// Constructor + CDBGroupSelectNumber(const TCtorParam ¶m); + ~CDBGroupSelectNumber(); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + /// CInterfaceGroup Interface + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + virtual void updateCoords (); + virtual void checkCoords(); + virtual void draw (); + virtual void clearViews (); + virtual bool handleEvent (const NLGUI::CEventDescriptor &eventDesc); + + // mod interface + void changeValue(sint delta); + + sint32 getMinValue () const { return _MinValue; } + void setMinValue (sint32 m) { _MinValue = m; } + sint32 getMaxValue () const { return _MaxValue; } + void setMaxValue (sint32 m) { _MaxValue = m; } + + sint32 getCurrentValue () const { return _Number.getSInt32(); } + void setCurrentValue (sint32 val) { _Number.setSInt32(val); } + + REFLECT_EXPORT_START(CDBGroupSelectNumber, CInterfaceGroup) + REFLECT_SINT32("min", getMinValue, setMinValue); + REFLECT_SINT32("max", getMaxValue, setMaxValue); + REFLECT_EXPORT_END + + protected: + + // sint32 + CInterfaceProperty _Number; + bool _LoopMode; + sint _MinValue; + sint _MaxValue; + sint _DeltaMultiplier; + + // Children + CViewBitmap *_SlotNumber; + CViewText *_TextNumber; + CCtrlBaseButton *_ButtonUp; + CCtrlBaseButton *_ButtonDown; + + private: + + void setup(); + + }; + +} + +#endif // NL_DBGROUP_SELECT_NUMBER_H + +/* End of dbgroup_select_number.h */ diff --git a/code/nel/include/nel/gui/dbview_bar.h b/code/nel/include/nel/gui/dbview_bar.h new file mode 100644 index 000000000..d4a3de340 --- /dev/null +++ b/code/nel/include/nel/gui/dbview_bar.h @@ -0,0 +1,116 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef RZ_DBVIEW_BAR_H +#define RZ_DBVIEW_BAR_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/view_bitmap.h" + +namespace NLGUI +{ + + /** + * class implementing a bitmap used as the front texture of a progress bar + * the bitmap is drawn from _X to _W * _Range/_RangeMax + * \author Nicolas Brigand + * \author Nevrax France + * \date 2002 + */ + class CDBViewBar : public CViewBitmap + { + public: + enum TViewBar { ViewBar_UltraMini, ViewBar_Mini, ViewBar_Normal, ViewBar_MiniThick }; + public: + DECLARE_UI_CLASS( CDBViewBar ) + + /// Constructor + CDBViewBar(const TCtorParam ¶m) + : CViewBitmap(param), + _Slot(TCtorParam()) + { + _Color= NLMISC::CRGBA::White; + _ValueInt= 0; + _RangeInt = 255; + _ReferenceInt= 0; + _Type = ViewBar_Normal; + } + + void setType (TViewBar vb); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + bool parse(xmlNodePtr cur,CInterfaceGroup * parentGroup); + virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + virtual void updateCoords (); + virtual void draw (); + + /// Nbs: Values by Int are not used if the Links are setuped + void setValue (sint32 r) { _ValueInt = r; } + void setRange (sint32 r) { _RangeInt = r; } + void setReference (sint32 r) { _ReferenceInt = r; } + sint32 getValue () const { return _ValueInt; } + sint32 getRange () const { return _RangeInt; } + sint32 getReference () const { return _ReferenceInt; } + + void setValueDbLink (const std::string &r); + void setRangeDbLink (const std::string &r); + void setReferenceDbLink (const std::string &r); + std::string getValueDbLink () const; + std::string getRangeDbLink () const; + std::string getReferenceDbLink () const; + + // Reflect ValueInt (ie not used if the link is setuped) + REFLECT_EXPORT_START(CDBViewBar, CViewBitmap) + REFLECT_SINT32 ("value", getValue, setValue); + REFLECT_SINT32 ("range", getRange, setRange); + REFLECT_SINT32 ("reference", getReference, setReference); + REFLECT_STRING ("value_dblink", getValueDbLink, setValueDbLink); + REFLECT_STRING ("range_dblink", getRangeDbLink, setRangeDbLink); + REFLECT_STRING ("reference_dblink", getReferenceDbLink, setReferenceDbLink); + REFLECT_EXPORT_END + + protected: + + CViewBitmap _Slot; + TViewBar _Type; + sint32 _HBar; + NLMISC::CRGBA _ColorNegative; + + // Value of the progression in arbitrary units. should be integer + CInterfaceProperty _Value; + // Max range of the progression in arbitrary units. should be integer + CInterfaceProperty _Range; + // Reference of the progression (substracted from value and range). + CInterfaceProperty _Reference; + + /// Nbs: Values by Int are not used if the Links are setuped. NB: not overwritten by links + sint32 _ValueInt; + sint32 _RangeInt; + sint32 _ReferenceInt; + + void parseValProp(xmlNodePtr cur, CInterfaceProperty &dbProp, sint32 &intProp, const char *name); + sint64 getCurrentValProp(const CInterfaceProperty &dbProp, sint32 intProp); + }; + +} + +#endif // RZ_DBVIEW_BAR_H + +/* End of dbview_bar.h */ diff --git a/code/nel/include/nel/gui/dbview_bar3.h b/code/nel/include/nel/gui/dbview_bar3.h new file mode 100644 index 000000000..785cb165b --- /dev/null +++ b/code/nel/include/nel/gui/dbview_bar3.h @@ -0,0 +1,111 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef RZ_DBVIEW_BAR3_H +#define RZ_DBVIEW_BAR3_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/view_bitmap.h" + +namespace NLGUI +{ + + /** + * class implementing a 3 Bar widget + * \author Matthieu 'TrapII' Besson + * \author Nevrax France + * \date 2002 + */ + class CDBViewBar3 : public CViewBitmap + { + public: + DECLARE_UI_CLASS( CDBViewBar3 ) + + /// Constructor + CDBViewBar3(const TCtorParam ¶m); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + bool parse(xmlNodePtr cur,CInterfaceGroup * parentGroup); + virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + virtual void updateCoords (); + + void setMini (bool mini); + + virtual void draw (); + + /// Nbs: Values by Int are not used if the Links are setuped + void setValue0 (sint32 r) { _ValueInt[0] = r; } + void setValue1 (sint32 r) { _ValueInt[1] = r; } + void setValue2 (sint32 r) { _ValueInt[2] = r; } + void setRange0 (sint32 r) { _RangeInt[0] = r; } + void setRange1 (sint32 r) { _RangeInt[1] = r; } + void setRange2 (sint32 r) { _RangeInt[2] = r; } + sint32 getValue0 () const { return _ValueInt[0]; } + sint32 getValue1 () const { return _ValueInt[1]; } + sint32 getValue2 () const { return _ValueInt[2]; } + sint32 getRange0 () const { return _RangeInt[0]; } + sint32 getRange1 () const { return _RangeInt[1]; } + sint32 getRange2 () const { return _RangeInt[2]; } + + // Reflect ValueInt (ie not used if the link is setuped) + REFLECT_EXPORT_START(CDBViewBar3, CViewBitmap) + REFLECT_SINT32 ("value1", getValue0, setValue0); + REFLECT_SINT32 ("value2", getValue1, setValue1); + REFLECT_SINT32 ("value3", getValue2, setValue2); + REFLECT_SINT32 ("range1", getRange0, setRange0); + REFLECT_SINT32 ("range2", getRange1, setRange1); + REFLECT_SINT32 ("range3", getRange2, setRange2); + REFLECT_EXPORT_END + + static void forceLink(); + + protected: + + CViewBitmap _Slot; + + // Value of the progression in arbitrary units. should be integer + CInterfaceProperty _Value[3]; + // Max range of the progression in arbitrary units. should be integer + CInterfaceProperty _Range[3]; + + /// Nbs: Values by Int are not used if the Links are setuped. NB: not overwritten by links + sint32 _ValueInt[3]; + sint32 _RangeInt[3]; + + + NLMISC::CRGBA _Colors[3]; + NLMISC::CRGBA _ColorsNegative[3]; + + bool _Mini; + + // Height of the bitmap + sint32 _BarH; + + void parseValProp(xmlNodePtr cur, CInterfaceProperty &dbProp, sint32 &intProp, const char *name); + void setValProp( const std::string &value, CInterfaceProperty &dbProp, sint32 &intProp ); + sint32 getCurrentValProp(const CInterfaceProperty &dbProp, sint32 intProp); + std::string getValProp( const CInterfaceProperty &prop, sint32 intProp ) const; + }; + +} + +#endif // RZ_DBVIEW_BAR3_H + +/* End of dbview_bar3.h */ diff --git a/code/nel/include/nel/gui/dbview_digit.h b/code/nel/include/nel/gui/dbview_digit.h new file mode 100644 index 000000000..33446b2de --- /dev/null +++ b/code/nel/include/nel/gui/dbview_digit.h @@ -0,0 +1,68 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef NL_DBVIEW_DIGIT_H +#define NL_DBVIEW_DIGIT_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/view_base.h" + +namespace NLGUI +{ + + // *************************************************************************** + /** + * A number displayed with special bitmaps + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CDBViewDigit : public CViewBase + { + public: + DECLARE_UI_CLASS( CDBViewDigit ) + + /// Constructor + CDBViewDigit(const TCtorParam ¶m); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup); + virtual void draw (); + virtual void updateCoords(); + + protected: + CInterfaceProperty _Number; + sint32 _Cache; + sint32 _NumDigit; + NLMISC::CRGBA _Color; + // space between each digit + sint32 _WSpace; + // The texture digit for the current number + sint32 _DigitId[10]; + uint _DivBase; + + + }; + +} + +#endif // NL_DBVIEW_DIGIT_H + +/* End of dbview_digit.h */ diff --git a/code/nel/include/nel/gui/dbview_number.h b/code/nel/include/nel/gui/dbview_number.h new file mode 100644 index 000000000..2c76a255d --- /dev/null +++ b/code/nel/include/nel/gui/dbview_number.h @@ -0,0 +1,78 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef NL_DBVIEW_NUMBER_H +#define NL_DBVIEW_NUMBER_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/view_text.h" + +namespace NLGUI +{ + + // *************************************************************************** + /** + * Display a text from a database number + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CDBViewNumber : public CViewText + { + public: + DECLARE_UI_CLASS( CDBViewNumber ) + + /// Constructor + CDBViewNumber(const TCtorParam ¶m); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup); + virtual void checkCoords(); + virtual void draw (); + + void link (const std::string &dbprop) + { + _Number.link (dbprop.c_str()); + } + + static void forceLink(); + + protected: + + sint64 getVal() { if (_Modulo == 0) return (_Number.getSInt64() / _Divisor); + else return (_Number.getSInt64() / _Divisor)%_Modulo; } + + protected: + + CInterfaceProperty _Number; + sint64 _Cache; + bool _Positive; // only positive values are displayed + bool _Format; // the number will be formatted (like "1,000,000") if >= 10k + sint64 _Divisor, _Modulo; + // string to append to the value (eg: meters) + CStringShared _Suffix; + CStringShared _Prefix; + }; + +} + +#endif // NL_DBVIEW_NUMBER_H + +/* End of dbview_number.h */ diff --git a/code/nel/include/nel/gui/dbview_quantity.h b/code/nel/include/nel/gui/dbview_quantity.h new file mode 100644 index 000000000..67c4e57ba --- /dev/null +++ b/code/nel/include/nel/gui/dbview_quantity.h @@ -0,0 +1,66 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef NL_DBVIEW_QUANTITY_H +#define NL_DBVIEW_QUANTITY_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/view_text.h" + +namespace NLGUI +{ + + // *************************************************************************** + /** + * Display a text in the form of val / max or "empty" + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CDBViewQuantity : public CViewText + { + public: + DECLARE_UI_CLASS( CDBViewQuantity ) + + /// Constructor + CDBViewQuantity(const TCtorParam ¶m); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup); + virtual void draw (); + + static void forceLink(); + + + protected: + CInterfaceProperty _Number; + CInterfaceProperty _NumberMax; + sint32 _Cache; + sint32 _CacheMax; + ucstring _EmptyText; + + void buildTextFromCache(); + }; + +} + +#endif // NL_DBVIEW_QUANTITY_H + +/* End of dbview_quantity.h */ diff --git a/code/ryzom/client/src/interface_v3/event_descriptor.h b/code/nel/include/nel/gui/event_descriptor.h similarity index 99% rename from code/ryzom/client/src/interface_v3/event_descriptor.h rename to code/nel/include/nel/gui/event_descriptor.h index fcb9d5f3a..d44448027 100644 --- a/code/ryzom/client/src/interface_v3/event_descriptor.h +++ b/code/nel/include/nel/gui/event_descriptor.h @@ -20,7 +20,10 @@ #define RZ_EVENT_DESCRIPTOR_H #include "nel/misc/types_nl.h" +#include "nel/misc/events.h" +namespace NLGUI +{ // ---------------------------------------------------------------------------- class CEventDescriptor @@ -247,6 +250,8 @@ protected: bool _HasFocus; }; +} + #endif // RZ_EVENT_DESCRIPTOR_H /* End of event_descriptor.h */ diff --git a/code/nel/include/nel/gui/event_listener.h b/code/nel/include/nel/gui/event_listener.h new file mode 100644 index 000000000..06a2d0776 --- /dev/null +++ b/code/nel/include/nel/gui/event_listener.h @@ -0,0 +1,44 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef EVENT_LISTENER +#define EVENT_LISTENER + +#include "nel/misc/event_listener.h" +#include "nel/gui/input_handler.h" + +namespace NLGUI +{ + class CEventListener : public NLMISC::IEventListener + { + public: + CEventListener(); + ~CEventListener(); + void addToServer( NLMISC::CEventServer *server ); + void removeFromServer(); + void operator()( const NLMISC::CEvent &evnt ); + + private: + NLGUI::CInputHandler inputHandler; + NLMISC::CEventServer *eventServer; + }; + +} + +#endif + + diff --git a/code/nel/include/nel/gui/group_container.h b/code/nel/include/nel/gui/group_container.h new file mode 100644 index 000000000..452674aa1 --- /dev/null +++ b/code/nel/include/nel/gui/group_container.h @@ -0,0 +1,664 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef RZ_GROUP_CONTAINER_H +#define RZ_GROUP_CONTAINER_H + +#include "nel/gui/interface_group.h" +#include "nel/gui/group_container_base.h" +#include "nel/misc/smart_ptr.h" + +namespace NLGUI +{ + class CEventDescriptorLocalised; + class CCtrlButton; + class CCtrlScroll; + class CViewText; + class CViewBitmap; + class CGroupList; + class COptionsContainerInsertion; + class COptionsContainerMove; + class COptionsLayer; + class CGroupContainer; + + + + // *************************************************************************** + /** + * class describing a resizer for the container + * \author Matthieu 'TrapII' Besson + * \date 2003 + */ + class CCtrlResizer : public CCtrlBase + { + + public: + DECLARE_UI_CLASS( CCtrlResizer ) + + CCtrlResizer(const TCtorParam ¶m); + virtual void draw (); + virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + // Add a big delta so when the user is over the Resizer, always take it whatever other controls under + virtual uint getDeltaDepth() const { return 100; } + + // get real resizer pos : if parent has pop_min_w == pop_max_w, then horizontal resizer will be discarded + // if parent has pop_min_h == pop_max_h, then vertical resizer will be discarded + THotSpot getRealResizerPos() const; + THotSpot getResizerPos() const { return _ResizerPos; } + void setResizerPos(THotSpot resizerPos) { _ResizerPos = resizerPos; } + + bool IsMaxH; // Do this resizer is a MaxH resizer ? + + // Max sizes for the parent + sint32 WMin, WMax; + sint32 HMin, HMax; + + // from CCtrlBase + virtual bool canChangeVirtualDesktop() const { return !_MouseDown; } + + private: + + sint32 resizeW (sint32 dx); + sint32 resizeH (sint32 dy); + + private: + THotSpot _ResizerPos; // how the resizer should resize its parent + bool _MouseDown; + sint32 _MouseDownX; + sint32 _MouseDownY; + sint32 _XBias; + sint32 _YBias; + }; + + + // *************************************************************************** + /** + * Class describing a Mover for the container + * Clicking on it can also open the container + * This can be used to move a container if it is movable. + * If the container is popable, it will first pull it of the hierarchy, then it becomes movable. + * It can also be used to change the position of a group container that is inserted in the list of another container. + * \author Lionel Berenguier + * \date 2003 + */ + class CCtrlMover : public CCtrlBase + { + public: + DECLARE_UI_CLASS( CCtrlMover ) + + CCtrlMover(const TCtorParam ¶m, bool canMove = true, bool canOpen = true ); + ~CCtrlMover(); + virtual void draw (); + virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + bool canMove() { return _CanMove; } + + bool isMoving() const {return _Moving;} + bool isMovingInParentList() const { return _MovingInParentList; } + + // from CCtrlBase + virtual bool canChangeVirtualDesktop() const { return !_Moving; } + + private: + sint32 _MoveStartX, _MoveStartY; + sint32 _MoveDeltaXReal, _MoveDeltaYReal; + sint64 _ScrollTime; + sint32 _StartIndex; + sint32 _InsertionIndex; + // clip window from parent list + sint32 _ParentListTop; + sint32 _ParentListBottom; + // + sint64 _WaitToOpenCloseDate; + // + bool _CanMove : 1; + bool _CanOpen : 1; + bool _Moving : 1; + bool _MovingInParentList : 1; + bool _HasMoved : 1; + bool _ParentScrollingUp : 1; + bool _ParentScrollingDown : 1; + bool _StopScrolling : 1; // stop scrolling at next draw + bool _WaitToOpenClose : 1; + // + static COptionsContainerInsertion *getInsertionOptions(); + private: + void setPoped(CGroupContainer *gc, sint32 x, sint32 y, const NLGUI::CEventDescriptorMouse &eventDesc); + void setMovingInParent(CGroupContainer *gc, sint32 x, sint32 y, const NLGUI::CEventDescriptorMouse &eventDesc); + void updateInsertionIndex(const CGroupList *gl, sint32 posY); + void stopMove(); + bool runTitleActionHandler(); + void handleScrolling(); + + }; + + + // *************************************************************************** + /** + * class describing a group of views controls and other groups + * \author Matthieu 'TrapII' Besson + * \author Nevrax France + * \date 2002 + */ + class CGroupContainer : public CGroupContainerBase + { + public: + enum { NumResizers = 8 }; + public: + // observer to know when children have moved. This can be used to keep external datas in sync + struct IChildrenObs + { + virtual void childrenMoved(uint srcIndex, uint destIndex, CGroupContainer *children) = 0; + }; + public: + DECLARE_UI_CLASS( CGroupContainer ) + CGroupContainer(const TCtorParam ¶m); + ~CGroupContainer(); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + xmlNodePtr serializeTreeData( xmlNodePtr parentNode ) const; + + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + + virtual void updateCoords (); + + virtual void draw (); + + virtual void clearViews (); + + virtual bool handleEvent (const NLGUI::CEventDescriptor &eventDesc); + + virtual void launch (); + + virtual void setActive (bool state); + + virtual bool getViewsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vVB); // Return true if x,y under the group + + virtual bool getCtrlsUnder (sint32 x, sint32 y, sint32 clipX, sint32 clipY, sint32 clipW, sint32 clipH, std::vector &vICL); + + void open(); + + void close(); + + void setup(); // Create the container + + /** If insertion order is -1, pIC is added at the end of the container + * otherwise it is inserted after containers of a lower order + */ + void attachContainer (CGroupContainer *pIC, sint insertionOrder = -1); + // Insert a container at the given index. + bool attachContainerAtIndex(CGroupContainer *pIC, uint index); + + // Before a container is detached from parent, it should be pop in + void detachContainer (CGroupContainer *pIC); + void removeAllContainers(); + + void setOpen(bool opened) + { + if (opened) + { + open(); + } + else + { + close(); + } + } + bool isOpen() const { return _Opened; } + + // Force Open for container setActive and open() + virtual void forceOpen(); + + /// Set the title open and close + virtual bool isMovable() const {return _Movable;} + void setMovable(bool b); + + void setContent (CInterfaceGroup *pC); + + std::string getTitle () const; + void setTitle (const std::string &title); + std::string getTitleOpened () const; + void setTitleOpened (const std::string &title); + std::string getTitleClosed () const; + void setTitleClosed (const std::string &title); + std::string getTitleColorAsString() const; + void setTitleColorAsString(const std::string &col); + + void setHeaderColor (const std::string &ptr) { _HeaderColor.link(ptr.c_str()); } + + // Get the header color draw. NB: depends if grayed, and if active. + NLMISC::CRGBA getDrawnHeaderColor () const; + + ucstring getUCTitleOpened () const; + void setUCTitleOpened (const ucstring &title); + ucstring getUCTitleClosed () const; + void setUCTitleClosed (const ucstring &title); + ucstring getUCTitle () const; + void setUCTitle (const ucstring &title); + + void setPopable(bool popable) { _Popable = popable; } + bool isPopable() const { return _Popable; } + bool isPopuped() const { return _Poped; } + + + void setMovableInParentList(bool /* movable */) { _MovableInParentList = true; } + bool isMovableInParentList() const { return _MovableInParentList; } + + // high light the border of the container + void setHighLighted(bool hightlighted, uint8 alpha=255) { _HighLighted = hightlighted; _HighLightedAlpha = alpha; } + bool isHighLighted() const { return _HighLighted; } + + // y offset for content of container + sint32 getContentYOffset() const { return (sint32) _ContentYOffset; } + void setContentYOffset(sint32 value); + + // Window requires attention + void requireAttention(); + + // Lua exports + int luaBlink(CLuaState &ls); + int luaSetHeaderColor(CLuaState &ls); + + REFLECT_EXPORT_START(CGroupContainer, CGroupContainerBase) + REFLECT_LUA_METHOD("blink", luaBlink); + REFLECT_LUA_METHOD("setHeaderColor", luaSetHeaderColor); + REFLECT_STRING("title", getTitle, setTitle); + REFLECT_STRING("title_opened", getTitleOpened, setTitleOpened); + REFLECT_STRING("title_closed", getTitleClosed, setTitleClosed); + REFLECT_UCSTRING("uc_title_opened", getUCTitleOpened, setUCTitleOpened); + REFLECT_UCSTRING("uc_title_closed", getUCTitleClosed, setUCTitleClosed); + REFLECT_UCSTRING("uc_title", getUCTitle, setUCTitle); + REFLECT_STRING("title_color", getTitleColorAsString, setTitleColorAsString); + REFLECT_SINT32("pop_min_h", getPopupMinH, setPopupMinH); + REFLECT_SINT32("pop_max_h", getPopupMaxH, setPopupMaxH); + REFLECT_SINT32("pop_min_w", getPopupMinW, setPopupMinW); + REFLECT_SINT32("pop_max_w", getPopupMaxW, setPopupMaxW); + REFLECT_SINT32("title_delta_max_w", getTitleDeltaMaxW, setTitleDeltaMaxW); + REFLECT_SINT32("content_y_offset", getContentYOffset, setContentYOffset); + REFLECT_BOOL("openable", isOpenable, setOpenable); + REFLECT_BOOL("opened", isOpen, setOpen); + REFLECT_BOOL("lockable", isLockable, setLockable); + REFLECT_BOOL("locked", isLocked, setLocked); + + REFLECT_BOOL("header_active", getHeaderActive, setHeaderActive); + REFLECT_BOOL("right_button_enabled", getRightButtonEnabled, setRightButtonEnabled); + REFLECT_EXPORT_END + + sint32 getLayerSetup() const { return _LayerSetup; } + + // if this window is popable, pop it at its actual position + void popupCurrentPos(); + // Popup at previous memorized position + void popup(); + /** Popin the window and possibly put it back in its father container, using the order defined in the list of the container. + * \param putBackInFather When true, put the window back in its former father container, otherwise, the container is unliked from the hierachy (parents are NULL) + * \param insertPos If this is equal to -1, then the window is inserted at its previous position. Otherwise it is inserted before the given position in the list + */ + void popin(sint32 insertPos = -1, bool putBackInFatherContainer = true); + + // get the mover control associated with that control, or NULL if none + CCtrlMover *getCtrlMover() const { return _Mover; } + + // true if there is a mover and if the window is being moved + bool isMoving() const { return _Mover && _Mover->isMoving(); } + + /** Force the container to blink (to tell the user that an event has happened). + * This uses the global color, so the container must use it + * This state is automatically disabled if the container is opened + * \param numBlinks 0 If the container should blink endlessly, the number of blink otherwise + */ + virtual void enableBlink(uint numBlinks = 0); + virtual void disableBlink(); + virtual bool isBlinking() const { return _Blinking; } + + CGroupList *getList() const { return _List; } + + CInterfaceGroup *getHeaderOpened() const { return _HeaderOpened; } + CInterfaceGroup *getHeaderClosed() const { return _HeaderClosed; } + CInterfaceGroup *getContent() const { return _Content; } + + void setChildrenObs(IChildrenObs *obs) { _ChildrenObs = obs; } + IChildrenObs *getChildrenObs() const { return _ChildrenObs; } + + // Get current father container (if any). + CGroupContainer *getFatherContainer() const; + // Get current father container (if any). If the container is popup, it gives the proprietary container + CGroupContainer *getProprietaryContainer() const; + + + bool isOpenable() const { return _Openable; } + void setOpenable(bool openable); + + bool getHeaderActive() const { return _HeaderActive; } + void setHeaderActive(bool active) { _HeaderActive = active; } + + bool getRightButtonEnabled() const { return _EnabledRightButton; } + void setRightButtonEnabled(bool enabled); + + CCtrlScroll *getScroll() const { return _ScrollBar; } + + bool isSavable() const { return _Savable; } + void setSavable(bool savable) { _Savable = savable; } + bool isActiveSavable() const { return _ActiveSavable; } + + bool isLocalize() const { return _Localize; } + void setLocalize(bool localize) { _Localize = localize; } + + void setPopupX(sint32 x) { _PopupX = x; } + void setPopupY(sint32 y) { _PopupY = y; } + void setPopupW(sint32 w) { _PopupW = w; } + void setPopupH(sint32 h) { _PopupH = h; } + + sint32 getPopupX() const { return _PopupX; } + sint32 getPopupY() const { return _PopupY; } + sint32 getPopupW() const { return _PopupW; } + sint32 getPopupH() const { return _PopupH; } + + sint32 getRefW() const { return _RefW; } + + /** Increase the rollover alpha for the current frame. + * Example of use : an edit box that has focus in a group container + */ + void rollOverAlphaUp(); + // force the rollover alpha to its max value, depending on there's keyboard focus or not + void forceRolloverAlpha(); + + bool isOpenWhenPopup() const { return _OpenWhenPopup; } + + /// Locking of window (prevent it from being moved) + void setLockable(bool lockable); + bool isLockable() const { return _Lockable; } + void setLocked(bool locked); + + // to be called by the 'deactive check' handler + static void validateCanDeactivate(bool validate) { _ValidateCanDeactivate = validate; } + const std::string &getAHOnDeactiveCheck() const { return CAHManager::getInstance()->getAHName(_AHOnDeactiveCheck); } + const std::string &getAHOnDeactiveCheckParams() const { return _AHOnDeactiveCheckParams; } + // + const std::string &getAHOnCloseButton() const { return CAHManager::getInstance()->getAHName(_AHOnCloseButton); } + const std::string &getAHOnCloseButtonParams() const { return _AHOnCloseButtonParams; } + // + IActionHandler *getAHOnMovePtr() const { return _AHOnMove; } + const std::string &getAHOnMove() const { return CAHManager::getInstance()->getAHName(_AHOnMove); } + const std::string &getAHOnMoveParams() const { return _AHOnMoveParams; } + // + IActionHandler *getAHOnResizePtr() const { return _AHOnResize; } + const std::string &getAHOnResize() const { return CAHManager::getInstance()->getAHName(_AHOnResize); } + const std::string &getAHOnResizeParams() const { return _AHOnResizeParams; } + // + IActionHandler *getAHOnBeginMovePtr() const { return _AHOnBeginMove; } + const std::string &getAHOnBeginMove() const { return CAHManager::getInstance()->getAHName(_AHOnBeginMove); } + const std::string &getAHOnBeginMoveParams() const { return _AHOnBeginMoveParams; } + + // + void setOnCloseButtonHandler(const std::string &h) { _AHOnCloseButton = CAHManager::getInstance()->getAH(h,_AHOnCloseButtonParams); } + void setOnCloseButtonParams(const std::string &p) { _AHOnCloseButtonParams = p; } + + void setModalParentList (const std::string &name); + bool checkIfModal(const NLGUI::CEventDescriptor& event); // Return true if we can handle the event (and prevent from selecting a window) + bool isGrayed() const; + bool blinkAllSons(); + + // true if the resizer is enabled. + bool getEnabledResizer() const {return _EnabledResizer;} + + sint32 getPopupMinW() const {return _PopupMinW;} + sint32 getPopupMaxW() const {return _PopupMaxW;} + sint32 getPopupMinH() const {return _PopupMinH;} + sint32 getPopupMaxH() const {return _PopupMaxH;} + sint32 getMinW() const {return _MinW;} + void setMinW(sint32 minW) { _MinW = minW;} + void setMaxW(sint32 maxW) { _MaxW = maxW;} + sint32 getMaxW() const {return _MaxW;} + void setPopupMinW(sint32 minW); + void setPopupMaxW(sint32 maxW); + void setPopupMinH(sint32 minW); + void setPopupMaxH(sint32 maxW); + + + // backup the current position of this container + void backupPosition(); + // restore the current position of this container + void restorePosition(); + // get x for backup position + sint32 getBackupX() const { return _BackupX; } + sint32 getBackupY() const { return _BackupY; } + // Set backup position + void setBackupPosition(sint32 x, sint32 y); + // clear backup + void clearBackup() { _PositionBackuped = false; } + // Test if position has been backuped (flag cleared by 'restorePosition()') + bool isPositionBackuped() const { return _PositionBackuped; } + // check if the container has been moved, resized, or popuped by the user (and eventually clear that flag) + bool getTouchFlag(bool clearFlag) const; + // from CInterfaceGroup + virtual void restoreAllContainersBackupPosition() { restorePosition(); } + + // when isModal() is true, the whole interface cannot switch desktop + bool isModal() const { return _Modal; } + void setModal(bool modal) { _Modal = modal; } + + // return true if the container has a modal parent window setuped => the whole interface cannot switch desktop + bool isModalSon() const { return !_ModalParents.empty(); } + + // return the help web page of this container. "" if none + const std::string &getHelpPage() const { return _HelpPage; } + // set the help web page of this container. "" if none. NB: the help button is not updated + void setHelpPage(const std::string &newPage); + + void setTitleDeltaMaxW(sint32 delta) { _TitleDeltaMaxW = delta; } + sint32 getTitleDeltaMaxW() const { return _TitleDeltaMaxW; } + + protected: + uint8 _ICurrentRolloverAlphaContainer; + uint8 _HighLightedAlpha; + float _CurrentRolloverAlphaContainer; + float _CurrentRolloverAlphaContent; + sint32 _LayerSetup; + ucstring _TitleTextOpened; + ucstring _TitleTextClosed; + CViewText *_TitleOpened; + CViewText *_TitleClosed; + sint32 _TitleDeltaMaxW; + CViewBitmap *_ViewOpenState; // Arrow showing if we are opened or not (if we are openable) + CCtrlButton *_RightButton; // Multi usage button : deactive or popup or popin + CCtrlButton *_HelpButton; // Help button + + CGroupList *_List; + CCtrlScroll *_ScrollBar; + CGroupContainer *_OldFatherContainer; + + // NB: _ModalParentNames is a list of modal parent, separated by '|' + std::string _ModalParentNames; // Modal handling between container (container can be linked together, + std::vector _ModalSons; // when the son is active the parent is not active + std::vector _ModalParents; // (but the rest of the interface is)) + + uint _InsertionOrder; + uint _BlinkDT; + uint _NumBlinks; + + CInterfaceGroup *_Content; // Read From Script + CInterfaceGroup *_HeaderOpened; // Read From Script + CInterfaceGroup *_HeaderClosed; // Read From Script + + CCtrlResizer *_Resizer[NumResizers]; // up to 8 resizers are available + + // + CCtrlMover *_Mover; + + IChildrenObs *_Obs; + + // If layer==0 constraint on resize + sint32 _PopupMinW; + sint32 _PopupMaxW; + sint32 _PopupMinH; + sint32 _PopupMaxH; + // If layer>0 constraint on resize + sint32 _MinW; + sint32 _MaxW; + + // backuped position + sint32 _BackupX; + sint32 _BackupY; + + // old position at which the window was popup, -1 values means that the window hasn't been turned into a popup yet + sint32 _PopupX; + sint32 _PopupY; + sint32 _PopupW; + sint32 _PopupH; + // + sint32 _RefW; + + + sint32 _MoverDeltaW; + + // action handler + IActionHandler *_AHOnOpen; + CStringShared _AHOnOpenParams; + IActionHandler *_AHOnClose; + CStringShared _AHOnCloseParams; + IActionHandler *_AHOnCloseButton; + CStringShared _AHOnCloseButtonParams; + IActionHandler *_AHOnMove; + CStringShared _AHOnMoveParams; + IActionHandler *_AHOnResize; + CStringShared _AHOnResizeParams; + IActionHandler *_AHOnBeginMove; + CStringShared _AHOnBeginMoveParams; + + // action handler to test whether the windows can be deactivated (when the close button is pressed) + IActionHandler *_AHOnDeactiveCheck; + CStringShared _AHOnDeactiveCheckParams; + + + // Observer to know when children have moved + IChildrenObs *_ChildrenObs; + + // list of container that are poped up + std::vector _PopedCont; + + // Open management + bool _Openable : 1; // Is the container can be manually opened or closed ? + bool _Opened : 1; // Is the container currently opened or closed ? + bool _OpenWhenPopup : 1; // Does the container must open when poped up ? (layer>0) + // and close when poped in... + bool _OpenAtStart : 1; // Mgt : to setup _Opened state at start + bool _OpenedBeforePopup : 1; // Mgt : Is the container opened before poped up ? (layer>0) + + // Move management + bool _Movable : 1; // Is the container movable ? + bool _MovableInParentList: 1; + bool _Lockable : 1; + bool _MovingInParentList : 1; // Mgt : currently moving ? + + // Pop up / pop in + bool _Popable : 1; + bool _Poped : 1; + + bool _EnabledResizer : 1; + + bool _HighLighted : 1; + bool _Blinking : 1; + bool _BlinkState : 1; + + bool _Savable : 1; + bool _ActiveSavable : 1; + + // Display title background or not + bool _HeaderActive : 1; + bool _EnabledRightButton : 1; // Is the Button Deactive/Popup/Popin is enabled ? + // + enum TTileClass {TitleText=0, TitleTextFormated, TitleTextId, TitleTextDynString}; + uint8 _TitleClass : 2; + // + mutable bool _TouchFlag : 1; + bool _PositionBackuped : 1; + bool _Modal : 1; // the container is modal and prevent from switching virtual desktop + // + bool _EnabledHelpButton : 1; // Is the Button Help is enabled ? + // + bool _TitleOverExtendViewText : 1; // Does the title over extend view text + bool _Localize : 1; + + CInterfaceProperty _HeaderColor; + + + + sint8 _ContentYOffset; + + // Special Top Resizer Height (for Inventory and ChatGroup). <0 (default) => take default option value + sint8 _ResizerTopSize; + uint8 _ICurrentRolloverAlphaContent; + + + static bool _ValidateCanDeactivate; + + CStringShared _OptionsName; + + // Web Page used for help + CStringShared _HelpPage; + + private: + + sint32 getLayer(); + void updateResizerSize(CCtrlResizer *cr); + void updateRightButton(); + void updateHelpButton(); + void updateMover(); + void updateViewOpenState(); + void updateTitle(); + + void createResizer(uint index, THotSpot posRef, THotSpot type, sint32 offsetX, sint32 offsetY, bool bMaxH); + void createResizerMaxH(); + void removeResizerMaxH(); + + TTileClass convertTitleClass(const char *ptr); + + static COptionsContainerMove *getMoveOptions(); + + COptionsLayer *getContainerOptions(sint32 ls=-1); // Depends if overload by OptionsName or default used + + bool hasKeyboardFocus() const; + + // private for modal system + void addModalParent (CGroupContainer *pParent); + void addModalSon (CGroupContainer *pSon); + + // Avoid each frame setup layer0, layer1 etc... + enum {NumLayerName=10}; + static const std::string _OptionLayerName[NumLayerName]; + + public: + // for use by CCtrlMover + // Tell that this group is moving in its parent list + void setMovingInParentList(bool enable); + CGroupList *getPreviousParentList() const { return _OldFatherContainer ? _OldFatherContainer->_List : NULL; } + CCtrlScroll *getPreviousParentScrollBar() const { return _OldFatherContainer ? _OldFatherContainer->_ScrollBar : NULL; } + CGroupContainer *getPreviousContainer() const { return _OldFatherContainer; } + // set the 'hasMoved' flag + void touch(bool touched = true) { _TouchFlag = touched; } + + friend class CICDeactive; + }; + +} + +#endif // RZ_INTERFACE_CONTAINER_H + +/* End of interface_container.h */ diff --git a/code/nel/include/nel/gui/group_container_base.h b/code/nel/include/nel/gui/group_container_base.h new file mode 100644 index 000000000..fe3fc8d07 --- /dev/null +++ b/code/nel/include/nel/gui/group_container_base.h @@ -0,0 +1,117 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef GROUP_CONTAINER_BASE_H +#define GROUP_CONTAINER_BASE_H + +#include "nel/gui/interface_group.h" +#include "nel/misc/rgba.h" + +namespace NLGUI +{ + + class CGroupContainerBase : public CInterfaceGroup + { + public: + DECLARE_UI_CLASS( CGroupContainerBase ) + + CGroupContainerBase( const TCtorParam ¶m ); + virtual ~CGroupContainerBase(); + + virtual void removeAllContainers(); + virtual void setLocked( bool locked ); + bool isLocked() const { return _Locked; } + + uint8 getContainerAlpha() const { return _ContainerAlpha; } + uint8 getContentAlpha() const { return _ContentAlpha; } + uint8 getRolloverAlphaContent() const { return _RolloverAlphaContent; } + uint8 getRolloverAlphaContainer() const { return _RolloverAlphaContainer; } + + void setContainerAlpha( uint8 alpha ); + void setContentAlpha( uint8 alpha ); + void setRolloverAlphaContent( uint8 alpha ); + void setRolloverAlphaContainer( uint8 alpha ); + + // for export + sint32 getContainerAlphaAsSInt32() const{ return (sint32)_ContainerAlpha; } + sint32 getContentAlphaAsSInt32() const{ return (sint32)_ContentAlpha; } + sint32 getRolloverAlphaContentAsSInt32() const{ return (sint32)_RolloverAlphaContent; } + sint32 getRolloverAlphaContainerAsSInt32() const{ return (sint32)_RolloverAlphaContainer; } + + // sin32 versions for export + void setContainerAlpha( sint32 alpha ){ setContainerAlpha((uint8) alpha); } + void setContentAlpha( sint32 alpha ){ setContentAlpha((uint8) alpha); } + void setRolloverAlphaContent( sint32 alpha ){ setRolloverAlphaContent((uint8) alpha); } + void setRolloverAlphaContainer( sint32 alpha ){ setRolloverAlphaContainer((uint8) alpha); } + + void setUseGlobalAlpha( bool use ); + bool isUsingGlobalAlpha() const{ return _UseGlobalAlpha; } + + std::string getAHOnAlphaSettingsChanged() const{ return CAHManager::getInstance()->getAHName( _AHOnAlphaSettingsChanged ); } + std::string getAHOnAlphaSettingsChangedParams() const{ return _AHOnAlphaSettingsChangedParams; } + + void setAHOnAlphaSettingsChanged( const std::string &h ){ _AHOnAlphaSettingsChanged = CAHManager::getInstance()->getAH( h, _AHOnAlphaSettingsChangedParams ); } + void setAHOnAlphaSettingsChangedParams( const std::string &p ){ _AHOnAlphaSettingsChangedParams = p; } + + REFLECT_EXPORT_START( CGroupContainerBase, CInterfaceGroup ) + REFLECT_SINT32("container_alpha", getContainerAlphaAsSInt32, setContainerAlpha); + REFLECT_SINT32("content_alpha", getContentAlphaAsSInt32, setContentAlpha); + REFLECT_SINT32("rollover_content_alpha", getRolloverAlphaContentAsSInt32, setRolloverAlphaContent); + REFLECT_SINT32("rollover_container_alpha", getRolloverAlphaContainerAsSInt32, setRolloverAlphaContainer); + REFLECT_BOOL("use_global_alpha_settings", isUsingGlobalAlpha, setUseGlobalAlpha); + REFLECT_STRING("on_alpha_settings_changed", getAHOnAlphaSettingsChanged, setAHOnAlphaSettingsChanged); + REFLECT_STRING("on_alpha_settings_changed_aparams", getAHOnAlphaSettingsChangedParams, setAHOnAlphaSettingsChangedParams); + REFLECT_EXPORT_END + + virtual bool isMoving() const{ return false; } + + // Get the header color draw. NB: depends if grayed, and if active. + virtual NLMISC::CRGBA getDrawnHeaderColor () const{ return NLMISC::CRGBA(); }; + + uint8 getCurrentContainerAlpha() const{ return _CurrentContainerAlpha; } + uint8 getCurrentContentAlpha() const{ return _CurrentContentAlpha; } + + virtual bool isGrayed() const{ return false; } + virtual bool getTouchFlag(bool clearFlag) const{ return false; } + virtual void backupPosition(){} + virtual void restorePosition(){} + + protected: + void triggerAlphaSettingsChangedAH(); + + uint8 _CurrentContainerAlpha; + uint8 _CurrentContentAlpha; + uint8 _ContainerAlpha; + uint8 _ContentAlpha; + uint8 _RolloverAlphaContainer; // Alpha for the window when mouse not over it + uint8 _RolloverAlphaContent; // Alpha for the content when mouse not over it + bool _Locked : 1; // Is the container locked (ie override movable, openable ...) + bool _UseGlobalAlpha : 1; + + IActionHandler *_AHOnAlphaSettingsChanged; + CStringShared _AHOnAlphaSettingsChangedParams; + + private: + + }; + + + +} + + +#endif diff --git a/code/nel/include/nel/gui/group_editbox.h b/code/nel/include/nel/gui/group_editbox.h new file mode 100644 index 000000000..7ea2ab529 --- /dev/null +++ b/code/nel/include/nel/gui/group_editbox.h @@ -0,0 +1,368 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef RZ_CTRL_EDITBOX_H +#define RZ_CTRL_EDITBOX_H + +#include "nel/gui/interface_group.h" +#include "nel/gui/group_editbox_base.h" +#include "nel/3d/u_texture.h" + +namespace NLGUI +{ + class CEventDescriptor; + class CViewText; + + // ---------------------------------------------------------------------------- + class CGroupEditBox : public CGroupEditBoxBase + { + public: + DECLARE_UI_CLASS( CGroupEditBox ) + + class IComboKeyHandler + { + public: + virtual ~IComboKeyHandler(){} + virtual bool isComboKeyChat( const NLGUI::CEventDescriptorKey &edk ) const = 0; + }; + + enum TEntryType { Text, Integer, PositiveInteger, Float, PositiveFloat, Alpha, AlphaNum, AlphaNumSpace, Password, Filename, PlayerName }; // the type of entry this edit bot can deal with + + /// Constructor + CGroupEditBox(const TCtorParam ¶m); + /// Dtor + ~CGroupEditBox(); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + bool parse(xmlNodePtr cur,CInterfaceGroup * parentGroup); + virtual uint32 getMemory() { return (uint32)(sizeof(*this)+_Id.size()); } + + virtual void draw(); + + virtual bool handleEvent (const NLGUI::CEventDescriptor& eventDesc); + + /// Accessors + ucstring getInputString() const { return _InputString; } + const ucstring &getInputStringRef() const { return _InputString; } + const ucstring &getPrompt() const { return _Prompt; } + + /** Set the prompt + * NB : line returns are encoded as '\n', not '\r\n' + */ + void setPrompt(const ucstring &s) { _Prompt = s; } + void setInputString(const ucstring &str); + void setInputStringRef(const ucstring &str) {_InputString = str; }; + void setInputStringAsInt(sint32 val); + sint32 getInputStringAsInt() const; + void setInputStringAsInt64(sint64 val); + sint64 getInputStringAsInt64() const; + void setInputStringAsFloat(float val); + float getInputStringAsFloat() const; + void setInputStringAsStdString(const std::string &str); + std::string getInputStringAsStdString() const; + void setInputStringAsUtf8(const std::string &str); + std::string getInputStringAsUtf8() const; + void setColor(NLMISC::CRGBA col); + + + /// force the selection of all the text + void setSelectionAll(); + + virtual void checkCoords(); + virtual void updateCoords(); + virtual void clearViews (); + + virtual void setActive (bool state); + + static CGroupEditBox *getMenuFather() { return _MenuFather; } + + void setCommand(const ucstring &command, bool execute); + + // Stop parent from blinking + void stopParentBlink() { if (_Parent) _Parent->disableBlink(); } + + // Get / set cursor position + sint32 getCursorPos () const {return _CursorPos;} + void setCursorPos (sint32 pos) {_CursorPos=pos;} + + // Get / set cursor at previous line end + bool isCursorAtPreviousLineEnd () const {return _CursorAtPreviousLineEnd;} + void setCursorAtPreviousLineEnd (bool setCursor) {_CursorAtPreviousLineEnd=setCursor;} + + // Get / set current selection position + static sint32 getSelectCursorPos () {return _SelectCursorPos;} + static void setSelectCursorPos (sint32 pos) {_SelectCursorPos=pos;} + + // Get the view text + const CViewText *getViewText () const {return _ViewText;} + + // Get the historic information + sint32 getMaxHistoric() const {return _MaxHistoric;} + sint32 getCurrentHistoricIndex () const {return _CurrentHistoricIndex;} + void setCurrentHistoricIndex (sint32 index) {_CurrentHistoricIndex=index;} + const ucstring &getHistoric(uint32 index) const {return _Historic[index];} + uint32 getNumHistoric() const {return (uint32)_Historic.size ();} + + // Get on change action handler + const std::string &getAHOnChange() const {return _AHOnChange;} + const std::string &getParamsOnChange() const {return _ParamsOnChange;} + + void cutSelection(); + + /// From CInterfaceElement + sint32 getMaxUsedW() const; + sint32 getMinUsedW() const; + + // Copy the selection into buffer + void copy(); + // Paste the selection into buffer + void paste(); + // Write the string into buffer + void writeString(const ucstring &str, bool replace = true, bool atEnd = true); + + // Expand the expression (true if there was a '/' at the start of the line) + bool expand(); + + // Back space + void back(); + + // ignore the next char/key event -> useful when a key set the focus on an editbox (keydown is received, the focus, then keychar is received by the editbox again, but is irrelevant) + void bypassNextKey() { _BypassNextKey = true; } + + // True if the editBox loose the focus on enter + bool getLooseFocusOnEnter() const {return _LooseFocusOnEnter;} + // + virtual void clearAllEditBox(); + // From CInterfaceElement + virtual bool wantSerialConfig() const; + // From CInterfaceElement + virtual void serialConfig(NLMISC::IStream &f); + // From CInterfaceElement + virtual void onQuit(); + // From CInterfaceElement + virtual void onLoadConfig(); + + // from CCtrlBase + virtual void elementCaptured(CCtrlBase *capturedElement); + + // from CCtrlBase + virtual void onKeyboardCaptureLost(); + + // set the input string as "default". will be reseted at first click (used for user information) + void setDefaultInputString(const ucstring &str); + + // For Interger and PositiveInteger, can specify min and max values + void setIntegerMinValue(sint32 minValue) {_IntegerMinValue=minValue;} + void setIntegerMaxValue(sint32 maxValue) {_IntegerMaxValue=maxValue;} + void setPositiveIntegerMinValue(uint32 minValue) {_PositiveIntegerMinValue=minValue;} + void setPositiveIntegerMaxValue(uint32 maxValue) {_PositiveIntegerMaxValue=maxValue;} + + void setFocusOnText(); + + int luaSetSelectionAll(CLuaState &ls); + int luaSetupDisplayText(CLuaState &ls); + int luaSetFocusOnText(CLuaState &ls); + int luaCancelFocusOnText(CLuaState &ls); + REFLECT_EXPORT_START(CGroupEditBox, CGroupEditBoxBase) + REFLECT_LUA_METHOD("setupDisplayText", luaSetupDisplayText); + REFLECT_LUA_METHOD("setSelectionAll", luaSetSelectionAll); + REFLECT_LUA_METHOD("setFocusOnText", luaSetFocusOnText); + REFLECT_LUA_METHOD("cancelFocusOnText", luaCancelFocusOnText); + REFLECT_STRING("input_string", getInputStringAsStdString, setInputStringAsStdString); + REFLECT_UCSTRING("uc_input_string", getInputString, setInputString); + REFLECT_EXPORT_END + + /** Restore the original value of the edit box. + * This value is captured when the edit box get focus + * (return true if no undo was available) + * Will always fails ifthe edito box do not have the focus + */ + bool undo(); + + /** Cancel last undo operation + * Return true if redo operation is available + */ + bool redo(); + + /// freeze the control (loose focus, and cannot edit) + void setFrozen (bool state); + bool getFrozen () const { return _Frozen; } + + protected: + + // Cursor infos + float _BlinkTime; + sint32 _CursorPos; + uint32 _MaxNumChar; + uint32 _MaxNumReturn; + uint32 _MaxFloatPrec; // used in setInputStringAsFloat() only + sint32 _MaxCharsSize; + sint32 _FirstVisibleChar; + sint32 _LastVisibleChar; + + // Text selection + static sint32 _SelectCursorPos; + bool _SelectingText; + NLMISC::CRGBA _TextSelectColor; + NLMISC::CRGBA _BackSelectColor; + + // Text info + ucstring _Prompt; + ucstring _InputString; + CViewText *_ViewText; + + // undo / redo + ucstring _StartInputString; // value of the input string when focus was acuired first + ucstring _ModifiedInputString; + + + // Historic info + typedef std::deque THistoric; + THistoric _Historic; + uint32 _MaxHistoric; + sint32 _CurrentHistoricIndex; + sint32 _PrevNumLine; + + // Action Handler + std::string _AHOnChange; + std::string _ParamsOnChange; + std::string _ListMenuRight; + + std::string _AHOnFocusLost; + std::string _AHOnFocusLostParams; + + // entry type + TEntryType _EntryType; + + + bool _Setupped : 1; // setup + bool _BypassNextKey : 1; + bool _BlinkState : 1; + bool _CursorAtPreviousLineEnd : 1; // force the cursor to be displayed at the end of the previous line end (if END has beeen pressed while in a string split accross 2 lines) + bool _LooseFocusOnEnter : 1; + bool _ResetFocusOnHide : 1; + bool _BackupFatherContainerPos : 1; // Backup father container position when characters are typed. + // If the edit box is at the bottom of the screen and if it expands on y + // because of multiline, thz parent container will be moved to top + // The good position can be restored by a press on enter then + bool _WantReturn : 1; // Want return char, don't call the enter action handler + bool _Savable : 1; // should content be saved ? + bool _DefaultInputString : 1; // Is the current input string the default one (should not be edited) + bool _Frozen : 1; // is the control frozen? (cannot edit in it) + + bool _CanRedo : 1; + bool _CanUndo : 1; + + std::vector _NegativeFilter; + + sint _CursorTexID; + sint32 _CursorWidth; + + sint32 _IntegerMinValue; + sint32 _IntegerMaxValue; + uint32 _PositiveIntegerMinValue; + uint32 _PositiveIntegerMaxValue; + + sint32 _ViewTextDeltaX; + + private: + void setupDisplayText(); + void makeTopWindow(); + void handleEventChar(const NLGUI::CEventDescriptorKey &event); + void handleEventString(const NLGUI::CEventDescriptorKey &event); + void setup(); + void triggerOnChangeAH(); + void appendStringFromClipboard(const ucstring &str); + + ucstring getSelection(); + + static CGroupEditBox *_MenuFather; + + static bool isValidAlphaNumSpace(ucchar c) + { + if (c > 255) return false; + char ac = (char) c; + return (ac >= '0' && ac <= '9') || + (ac >= 'a' && ac <= 'z') || + (ac >= 'A' && ac <= 'Z') || + ac==' '; + } + + static bool isValidAlphaNum(ucchar c) + { + if (c > 255) return false; + char ac = (char) c; + return (ac >= '0' && ac <= '9') || + (ac >= 'a' && ac <= 'z') || + (ac >= 'A' && ac <= 'Z'); + } + + static bool isValidAlpha(ucchar c) + { + if (c > 255) return false; + char ac = (char) c; + return (ac >= 'a' && ac <= 'z') || + (ac >= 'A' && ac <= 'Z'); + } + + static bool isValidPlayerNameChar(ucchar c) + { + // valid player name (with possible shard prefix / suffix format + return isValidAlpha(c) || c=='.' || c=='(' || c==')'; + } + + static bool isValidFilenameChar(ucchar c) + { + if (c == '\\' || + c == '/' || + c == ':' || + c == '*' || + c == '?' || + c == '\"' || + c == '<' || + c == '>' || + c == '|') return false; + return true; + } + // + bool isFiltered(ucchar c) + { + uint length = (uint)_NegativeFilter.size(); + for (uint k = 0; k < length; ++k) + { + if ((ucchar) _NegativeFilter[k] == c) return true; + } + return false; + } + + static IComboKeyHandler *comboKeyHandler; + + public: + static void setComboKeyHandler( IComboKeyHandler *handler ){ comboKeyHandler = handler; } + + }; + + +} + +#endif // RZ_CTRL_EDITBOX_H + +/* End of ctrl_editbox.h */ diff --git a/code/nel/include/nel/gui/group_editbox_base.h b/code/nel/include/nel/gui/group_editbox_base.h new file mode 100644 index 000000000..3aa6a555f --- /dev/null +++ b/code/nel/include/nel/gui/group_editbox_base.h @@ -0,0 +1,67 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef GROUP_EDITBOX_BASE_H +#define GROUP_EDITBOX_BASE_H + +#include "nel/gui/interface_group.h" + +namespace NLGUI +{ + + class CGroupEditBoxBase : public CInterfaceGroup + { + public: + DECLARE_UI_CLASS( CGroupEditBoxBase ) + + CGroupEditBoxBase( const TCtorParam ¶m ); + ~CGroupEditBoxBase(); + + // True if the editBox can recover the focus on enter. if not, it does not erase OldCapturedKeyboard when loose focus + bool getRecoverFocusOnEnter() const{ return _RecoverFocusOnEnter; } + void setRecoverFocusOnEnter( bool state ){ _RecoverFocusOnEnter = state; } + + std::string getAHOnFocus(){ return _AHOnFocus; } + std::string getAHOnFocusParams(){ return _AHOnFocusParams; } + + // disable any current selection + static void disableSelection(){ _CurrSelection = NULL; } + + // Get / set current selection + static CGroupEditBoxBase *getCurrSelection(){ return _CurrSelection; } + static void setCurrSelection( CGroupEditBoxBase *selection ){ _CurrSelection = selection; } + + void draw(){} + + REFLECT_EXPORT_START( CGroupEditBoxBase, CInterfaceGroup ) + REFLECT_BOOL( "enter_recover_focus", getRecoverFocusOnEnter, setRecoverFocusOnEnter ); + REFLECT_EXPORT_END + + protected: + bool _RecoverFocusOnEnter : 1; + + std::string _AHOnFocus; + std::string _AHOnFocusParams; + + static CGroupEditBoxBase *_CurrSelection; // the edit box for which the selection is currently active, or NULL if there's none + + }; + +} + +#endif + diff --git a/code/nel/include/nel/gui/group_frame.h b/code/nel/include/nel/gui/group_frame.h new file mode 100644 index 000000000..3d350b4d5 --- /dev/null +++ b/code/nel/include/nel/gui/group_frame.h @@ -0,0 +1,119 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef NL_GROUP_FRAME_H +#define NL_GROUP_FRAME_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/interface_group.h" + + +namespace NLGUI +{ + + + // *************************************************************************** + /** A Group with a background and a frame displayed + * \author Lionel Berenguier + * \author Nevrax France + * \date 2002 + */ + class CGroupFrame : public CInterfaceGroup + { + public: + DECLARE_UI_CLASS( CGroupFrame ) + + /// Constructor + CGroupFrame(const TCtorParam ¶m); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + virtual void draw (); + + void copyOptionFrom(const CGroupFrame &other); + void setupOptions(); + + + void setColorAsString(const std::string & col); + std::string getColorAsString() const; + + REFLECT_EXPORT_START(CGroupFrame, CInterfaceGroup) + REFLECT_STRING ("color", getColorAsString, setColorAsString); + REFLECT_EXPORT_END + + + static void resetDisplayTypes() { _DispTypes.clear(); } + + // ****************** + protected: + + bool _DisplayFrame; + + NLMISC::CRGBA _Color; + + uint8 _DispType; + + std::string _Options; + + // Fields Defined in the XML => must not herit them from extends="" + bool _DisplayFrameDefined : 1; + bool _ColorDefined : 1; + bool _DispTypeDefined : 1; + + // Static stuff + enum + { + TextTL= 0, + TextTM, + TextTR, + TextML, + TextMM, + TextMR, + TextBL, + TextBM, + TextBR + }; + + struct SDisplayType + { + std::string Name; + sint32 BorderIds[9]; + uint8 TileBorder[9]; // Dont works for TextTL, TextTR, TextBL, TextBR + sint32 LeftBorder; // enum + sint32 RightBorder; + sint32 TopBorder; + sint32 BottomBorder; + + // ----------------------- + SDisplayType() + { + for (uint i = 0; i < 9; ++i) + TileBorder[i] = 0; + } + }; + static std::vector _DispTypes; + }; + +} + +#endif // NL_GROUP_FRAME_H + +/* End of group_frame.h */ diff --git a/code/nel/include/nel/gui/group_header.h b/code/nel/include/nel/gui/group_header.h new file mode 100644 index 000000000..ab6c94c35 --- /dev/null +++ b/code/nel/include/nel/gui/group_header.h @@ -0,0 +1,97 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef CL_GROUP_HEADER_H +#define CL_GROUP_HEADER_H + +#include "nel/gui/group_list.h" + +namespace NLGUI +{ + + class CGroupHeaderEntry; + + // ***************************************************************************************************************** + /** Display a header with movable entries. + * Usually used with a table to change the size of each column (much like the windows file explorer in 'details' mode) + * + * \author Nicolas Vizerie + * \author Nevrax France + * \date 2006 + */ + class CGroupHeader : public CGroupList + { + public: + DECLARE_UI_CLASS( CGroupHeader ) + + REFLECT_EXPORT_START(CGroupHeader, CGroupList) + REFLECT_LUA_METHOD("enlargeColumns", luaEnlargeColumns); + REFLECT_LUA_METHOD("resizeColumnsAndContainer", luaResizeColumnsAndContainer); + REFLECT_EXPORT_END + + CGroupHeader(const TCtorParam ¶m); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + // from CInterfaceGroup + virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup); + sint32 getHeaderMaxSize() const { return _HeaderMaxSize; } + // get the entries in this header + void getEntries(std::vector &dest); + // ensure that max. content of columns is visible (without the total width becoming more than 'getHeaderMaxSize()' + void enlargeColumns(sint32 margin); + // ensure that content of each column is visible + void resizeColumnsAndContainer(sint32 margin); + private: + sint32 _HeaderMaxSize; + int luaEnlargeColumns(CLuaState &ls); + int luaResizeColumnsAndContainer(CLuaState &ls); + }; + + // ***************************************************************************************************************** + // an entry in a header, includes a "mover control" to move it inside its parent header + // NOTE : when not used inside a CGroupHeader, will work, but there will be no 'max_size' + class CGroupHeaderEntry : public CInterfaceGroup + { + public: + DECLARE_UI_CLASS( CGroupHeaderEntry ) + + CGroupHeaderEntry(const TCtorParam ¶m); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + // from CInterfaceGroup + virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup); + sint32 getMinSize() const { return _MinSize; } + virtual void updateCoords(); + CInterfaceGroup *getTargetColumn() const; + + const std::string &getAHOnResize() const { return _AHOnResize; } + const std::string &getAHOnResizeParams() const { return _AHOnResizeParams; } + + private: + sint32 _MinSize; + sint32 _ResizerSize; + std::string _TargetColumnId; + std::string _AHOnResize; + std::string _AHOnResizeParams; + }; + + +} + +#endif + diff --git a/code/nel/include/nel/gui/group_html.h b/code/nel/include/nel/gui/group_html.h new file mode 100644 index 000000000..3f5526197 --- /dev/null +++ b/code/nel/include/nel/gui/group_html.h @@ -0,0 +1,673 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef CL_GROUP_HTML_H +#define CL_GROUP_HTML_H + +#define CURL_STATICLIB 1 +#include + +#include "nel/misc/types_nl.h" +#include "nel/gui/interface_group.h" +#include "nel/gui/group_scrolltext.h" +#include "nel/gui/group_tree.h" +#include "nel/gui/ctrl_button.h" +#include "nel/gui/group_table.h" + +typedef std::map TStyle; + +extern "C" +{ +#include "WWWInit.h" +} + +namespace NLGUI +{ + class CCtrlButton; + class CCtrlScroll; + class CGroupList; + class CDBGroupComboBox; + class CGroupParagraph; + + + + // HTML group + /** + * Widget to have a resizable scrolltext and its scrollbar + * \author Cyril 'Hulud' Corvazier + * \author Nevrax France + * \date 2002 + */ + class CGroupHTML : public CGroupScrollText + { + public: + DECLARE_UI_CLASS( CGroupHTML ) + + friend void TextAdd (struct _HText *me, const char * buf, int len); + friend void TextBeginElement (_HText *me, int element_number, const BOOL *present, const char ** value); + friend void TextEndElement (_HText *me, int element_number); + friend void TextLink (struct _HText *me, int element_number, int attribute_number, struct _HTChildAnchor *anchor, const BOOL *present, const char **value); + friend void TextBuild (HText * me, HTextStatus status); + friend void TextBeginUnparsedElement(HText *me, const char *buffer, int length); + friend void TextEndUnparsedElement(HText *me, const char *buffer, int length); + friend int requestTerminater (HTRequest * request, HTResponse * response, void * param, int status); + + /// Web browser options for CGroupHTML + struct SWebOptions + { + public: + /// Id of the browser ( e.g.: Chrome, Firefox, Ryzom ) + std::string appName; + /// Version of the browser + std::string appVersion; + /// Language code of the browser( e.g.: en, hu ) + std::string languageCode; + /// List of domains the widget can consider secure. + std::vector< std::string > trustedDomains; + + SWebOptions() + { + } + }; + + static SWebOptions options; + + // Constructor + CGroupHTML(const TCtorParam ¶m); + ~CGroupHTML(); + + std::string getProperty( const std::string &name ) const; + void setProperty( const std::string &name, const std::string &value ); + xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + + // CInterfaceGroup Interface + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + virtual void draw (); + + // Events + virtual bool handleEvent (const NLGUI::CEventDescriptor& eventDesc); + + // Browse + virtual void browse (const char *url); + + // Refresh + void refresh(); + + // submit form + void submitForm (uint formId, const char *submitButtonName); + + // Browse error + void browseError (const char *msg); + + // stop browse + void stopBrowse (); + + bool isBrowsing(); + + void clean() { stopBrowse(); updateRefreshButton(); removeContent(); } + + // Update coords + void updateCoords(); + + // New paragraph + void newParagraph(uint beginSpace); + + // End of the paragraph + void endParagraph(); + + // Timeout + void setTimeout(float tm) {_TimeoutValue= std::max(0.f, tm);} + float getTimeout() const {return (float)_TimeoutValue;} + + // Some constants + NLMISC::CRGBA BgColor; + NLMISC::CRGBA ErrorColor; + NLMISC::CRGBA LinkColor; + NLMISC::CRGBA TextColor; + NLMISC::CRGBA H1Color; + NLMISC::CRGBA H2Color; + NLMISC::CRGBA H3Color; + NLMISC::CRGBA H4Color; + NLMISC::CRGBA H5Color; + NLMISC::CRGBA H6Color; + bool ErrorColorGlobalColor; + bool LinkColorGlobalColor; + bool TextColorGlobalColor; + bool H1ColorGlobalColor; + bool H2ColorGlobalColor; + bool H3ColorGlobalColor; + bool H4ColorGlobalColor; + bool H5ColorGlobalColor; + bool H6ColorGlobalColor; + uint TextFontSize; + uint H1FontSize; + uint H2FontSize; + uint H3FontSize; + uint H4FontSize; + uint H5FontSize; + uint H6FontSize; + uint TDBeginSpace; + uint PBeginSpace; + uint LIBeginSpace; + uint ULBeginSpace; + uint LIIndent; + uint ULIndent; + float LineSpaceFontFactor; + std::string DefaultButtonGroup; + std::string DefaultFormTextGroup; + std::string DefaultFormTextAreaGroup; + std::string DefaultFormSelectGroup; + std::string DefaultCheckBoxBitmapNormal; + std::string DefaultCheckBoxBitmapPushed; + std::string DefaultCheckBoxBitmapOver; + std::string DefaultBackgroundBitmapView; + std::string CurrentLinkTitle; + + // Browser home + std::string Home; + + // Undo browse: Browse the precedent url browsed. no op if none + void browseUndo (); + // Redo browse: Browse the precedent url undoed. no op if none + void browseRedo (); + // clear undo/redo + void clearUndoRedo(); + + + std::string getURL() const { return _URL; } + void setURL(const std::string &url); + + + int luaBrowse(CLuaState &ls); + int luaRefresh(CLuaState &ls); + int luaRemoveContent(CLuaState &ls); + int luaInsertText(CLuaState &ls); + int luaAddString(CLuaState &ls); + int luaAddImage(CLuaState &ls); + int luaBeginElement(CLuaState &ls); + int luaEndElement(CLuaState &ls); + int luaShowDiv(CLuaState &ls); + + REFLECT_EXPORT_START(CGroupHTML, CGroupScrollText) + REFLECT_LUA_METHOD("browse", luaBrowse) + REFLECT_LUA_METHOD("refresh", luaRefresh) + REFLECT_LUA_METHOD("removeContent", luaRemoveContent) + REFLECT_LUA_METHOD("insertText", luaInsertText) + REFLECT_LUA_METHOD("addString", luaAddString) + REFLECT_LUA_METHOD("addImage", luaAddImage) + REFLECT_LUA_METHOD("beginElement", luaBeginElement) + REFLECT_LUA_METHOD("endElement", luaEndElement) + REFLECT_LUA_METHOD("showDiv", luaShowDiv) + REFLECT_STRING("url", getURL, setURL) + REFLECT_FLOAT("timeout", getTimeout, setTimeout) + REFLECT_EXPORT_END + + protected : + + // \name callback from libwww + + // Begin of the parsing of a HTML document + virtual void beginBuild (); + + // End of the parsing of a HTML document + virtual void endBuild (); + + // A new text block has been parsed + virtual void addText (const char * buf, int len); + + // A link has been parsed + virtual void addLink (uint element_number, uint attribute_number, HTChildAnchor *anchor, const BOOL *present, const char **value); + + // A new begin HTML element has been parsed ( for exemple) + virtual void beginElement (uint element_number, const BOOL *present, const char **value); + + // A new end HTML element has been parsed ( for exemple) + virtual void endElement (uint element_number); + + // A new begin unparsed element has been found + virtual void beginUnparsedElement(const char *buffer, int length); + + // A new end unparsed element has been found + virtual void endUnparsedElement(const char *buffer, int length); + + // Add GET params to the url + virtual void addHTTPGetParams (std::string &url, bool trustedDomain); + + // Add POST params to the libwww list + virtual void addHTTPPostParams (HTAssocList *formfields, bool trustedDomain); + + // the current request is terminated + virtual void requestTerminated(HTRequest *request); + + // Get Home URL + virtual std::string home(); + + // Parse style html tag + TStyle parseStyle(const std::string &str_styles); + + // Handle some work at each pass + virtual void handle (); + + // \name internal methods + + // Add a group in the current parent group + void addGroup (CInterfaceGroup *group, uint beginSpace); + + // Get the current parent group + CInterfaceGroup *getCurrentGroup(); + + // Update current paragraph dependent data + void paragraphChange (); + + // Clear the contexts info + void clearContext(); + + // Translate a char + bool translateChar(ucchar &output, ucchar input, ucchar lastChar) const; + + // Add a string in the current paragraph + void addString(const ucstring &str); + + // Add an image in the current paragraph + void addImage(const char *image, bool globalColor, bool reloadImg=false); + + // Add a text area in the current paragraph + CInterfaceGroup *addTextArea (const std::string &templateName, const char *name, uint rows, uint cols, bool multiLine, const ucstring &content); + + // Add a combo box in the current paragraph + CDBGroupComboBox *addComboBox(const std::string &templateName, const char *name); + + // Add a button in the current paragraph. actionHandler, actionHandlerParams and tooltip can be NULL. + CCtrlButton *addButton(CCtrlButton::EType type, const std::string &name, const std::string &normalBitmap, const std::string &pushedBitmap, + const std::string &overBitmap, bool useGlobalColor, const char *actionHandler, const char *actionHandlerParams, const char *tooltip); + + // Set the background color + void setBackgroundColor (const NLMISC::CRGBA &bgcolor); + + // Set the background + void setBackground (const std::string &bgtex, bool scale, bool tile); + + // Force the current string to be in a single string + void flushString(); + + // Set the title + void setTitle (const ucstring &title); + + // Lookup a url in local file system + bool lookupLocalFile (std::string &result, const char *url, bool isUrl); + + // Delete page content and prepare next page + void removeContent (); + + // Current URL + std::string _URL; + + // Current DOMAIN + bool _TrustedDomain; + + // Title prefix + ucstring _TitlePrefix; + + // Title string + ucstring _TitleString; + + // Need to browse next update coords.. + bool _BrowseNextTime; + bool _PostNextTime; + uint _PostFormId; + std::string _PostFormSubmitButton; + + // Browsing.. + bool _Browsing; + bool _Connecting; + double _TimeoutValue; // the timeout in seconds + double _ConnectingTimeout; + + // minimal embeded lua script support + // Note : any embeded script is executed immediately after the closing + // element has been found + // True when the element has been encountered + bool _ParsingLua; + bool _IgnoreText; + // the script to execute + std::string _LuaScript; + + bool _Object; + std::string _ObjectScript; + + // Someone is conecting. We got problem with libwww : 2 connection requests can deadlock the client. + static CGroupHTML *_ConnectingLock; + + // LibWWW data + class CLibWWWData *_LibWWW; + + // Current paragraph + std::string _DivName; + CGroupParagraph* _Paragraph; + inline CGroupParagraph *getParagraph() + { + return _Paragraph; + /*if (_Paragraph.empty()) + return NULL; + return _Paragraph.back();*/ + } + + // PRE mode + std::vector _PRE; + inline bool getPRE() const + { + if (_PRE.empty()) + return false; + return _PRE.back(); + } + + // UL mode + std::vector _UL; + inline bool getUL() const + { + if (_UL.empty()) + return false; + return _UL.back(); + } + + // A mode + std::vector _A; + inline bool getA() const + { + if (_A.empty()) + return false; + return _A.back(); + } + + // IL mode + bool _LI; + + // Current text color + std::vector _TextColor; + inline const NLMISC::CRGBA &getTextColor() const + { + if (_TextColor.empty()) + return TextColor; + return _TextColor.back(); + } + + // Current global color flag + std::vector _GlobalColor; + inline bool getGlobalColor() const + { + if (_GlobalColor.empty()) + return false; + return _GlobalColor.back(); + } + + // Current font size + std::vector _FontSize; + inline uint getFontSize() const + { + if (_FontSize.empty()) + return TextFontSize; + return _FontSize.back(); + } + + // Current link + std::vector _Link; + inline const char *getLink() const + { + if (_Link.empty()) + return ""; + return _Link.back().c_str(); + } + + std::vector _LinkTitle; + inline const char *getLinkTitle() const + { + if (_LinkTitle.empty()) + return ""; + return _LinkTitle.back().c_str(); + } + std::vector _LinkClass; + inline const char *getLinkClass() const + { + if (_LinkClass.empty()) + return ""; + return _LinkClass.back().c_str(); + } + + // Divs (i.e. interface group) + std::vector _Divs; + inline CInterfaceGroup *getDiv() const + { + if (_Divs.empty()) + return NULL; + return _Divs.back(); + } + + // Tables + std::vector _Tables; + inline CGroupTable *getTable() const + { + if (_Tables.empty()) + return NULL; + return _Tables.back(); + } + + // Cells + std::vector _Cells; + + // TR + std::vector _TR; + inline bool getTR() const + { + if (_TR.empty()) + return false; + return _TR.back(); + } + + // Forms + class CForm + { + public: + + class CEntry + { + public: + CEntry () + { + TextArea = NULL; + Checkbox = NULL; + ComboBox = NULL; + InitialSelection = 0; + } + + // Variable name + std::string Name; + + // Variable value + ucstring Value; + + // Text area group + CInterfaceGroup *TextArea; + + // Checkbox + CCtrlButton *Checkbox; + + // Combobox group + CDBGroupComboBox *ComboBox; + + // select values (for the ' . $output; + if ($labels) { + $_output .= ''; + } + + $_output .= $separator; + return $_output; +} + +?> \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/smarty/libs/plugins/function.html_image.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/smarty/libs/plugins/function.html_image.php new file mode 100644 index 000000000..6521966bb --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/smarty/libs/plugins/function.html_image.php @@ -0,0 +1,159 @@ + + * Name: html_image
+ * Date: Feb 24, 2003
+ * Purpose: format HTML tags for the image
+ * Examples: {html_image file="/images/masthead.gif"}
+ * Output:
+ * Params: + *
+ * - file        - (required) - file (and path) of image
+ * - height      - (optional) - image height (default actual height)
+ * - width       - (optional) - image width (default actual width)
+ * - basedir     - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
+ * - path_prefix - prefix for path output (optional, default empty)
+ * 
+ * + * @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image} + * (Smarty online manual) + * @author Monte Ohrt + * @author credits to Duda + * @version 1.0 + * @param array $params parameters + * @param Smarty_Internal_Template $template template object + * @return string + * @uses smarty_function_escape_special_chars() + */ +function smarty_function_html_image($params, $template) +{ + require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + + $alt = ''; + $file = ''; + $height = ''; + $width = ''; + $extra = ''; + $prefix = ''; + $suffix = ''; + $path_prefix = ''; + $basedir = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : ''; + foreach($params as $_key => $_val) { + switch ($_key) { + case 'file': + case 'height': + case 'width': + case 'dpi': + case 'path_prefix': + case 'basedir': + $$_key = $_val; + break; + + case 'alt': + if (!is_array($_val)) { + $$_key = smarty_function_escape_special_chars($_val); + } else { + throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + } + break; + + case 'link': + case 'href': + $prefix = ''; + $suffix = ''; + break; + + default: + if (!is_array($_val)) { + $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; + } else { + throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + } + break; + } + } + + if (empty($file)) { + trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE); + return; + } + + if ($file[0] == '/') { + $_image_path = $basedir . $file; + } else { + $_image_path = $file; + } + + // strip file protocol + if (stripos($params['file'], 'file://') === 0) { + $params['file'] = substr($params['file'], 7); + } + + $protocol = strpos($params['file'], '://'); + if ($protocol !== false) { + $protocol = strtolower(substr($params['file'], 0, $protocol)); + } + + if (isset($template->smarty->security_policy)) { + if ($protocol) { + // remote resource (or php stream, …) + if(!$template->smarty->security_policy->isTrustedUri($params['file'])) { + return; + } + } else { + // local file + if(!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) { + return; + } + } + } + + if (!isset($params['width']) || !isset($params['height'])) { + // FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader! + if (!$_image_data = @getimagesize($_image_path)) { + if (!file_exists($_image_path)) { + trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); + return; + } else if (!is_readable($_image_path)) { + trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); + return; + } else { + trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); + return; + } + } + + if (!isset($params['width'])) { + $width = $_image_data[0]; + } + if (!isset($params['height'])) { + $height = $_image_data[1]; + } + } + + if (isset($params['dpi'])) { + if (strstr($_SERVER['HTTP_USER_AGENT'], 'Mac')) { + // FIXME: (rodneyrehm) wrong dpi assumption + // don't know who thought this up… even if it was true in 1998, it's definitely wrong in 2011. + $dpi_default = 72; + } else { + $dpi_default = 96; + } + $_resize = $dpi_default / $params['dpi']; + $width = round($width * $_resize); + $height = round($height * $_resize); + } + + return $prefix . '' . $alt . '' . $suffix; +} + +?> \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/smarty/libs/plugins/function.html_options.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/smarty/libs/plugins/function.html_options.php new file mode 100644 index 000000000..68fa0524a --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/smarty/libs/plugins/function.html_options.php @@ -0,0 +1,193 @@ + + * Name: html_options
+ * Purpose: Prints the list of