diff --git a/RetroFE/CMake/FindSDL.cmake b/RetroFE/CMake/FindSDL.cmake new file mode 100644 index 0000000..91c53f1 --- /dev/null +++ b/RetroFE/CMake/FindSDL.cmake @@ -0,0 +1,87 @@ +# - Find SDL library and headers +# +# Find module for SDL 2.0 (http://www.libsdl.org/). +# It defines the following variables: +# SDL_INCLUDE_DIRS - The location of the headers, e.g., SDL.h. +# SDL_LIBRARIES - The libraries to link against to use SDL. +# SDL_FOUND - If false, do not try to use SDL. +# SDL_VERSION_STRING - Human-readable string containing the version of SDL. +# +# This module responds to the the flag: +# SDL_BUILDING_LIBRARY +# If this is defined, then no SDL_main will be linked in because +# only applications need main(). +# Otherwise, it is assumed you are building an application and this +# module will attempt to locate and set the the proper link flags +# as part of the returned SDL_LIBRARIES variable. +# +# Also defined, but not for general use are: +# SDL_INCLUDE_DIR - The directory that contains SDL.h. +# SDL_LIBRARY - The location of the SDL library. +# SDLMAIN_LIBRARY - The location of the SDLmain library. +# + +#============================================================================= +# Copyright 2013 Benjamin Eikel +# +# 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_package(PkgConfig QUIET) +pkg_check_modules(PC_SDL QUIET sdl) + +find_path(SDL_INCLUDE_DIR + NAMES SDL/SDL.h + HINTS + ${SDL_ROOT}/include +) + +find_library(SDL_LIBRARY + NAMES SDL + HINTS + ${SDL_ROOT}/lib + PATH_SUFFIXES x86 +) + +if(NOT SDL_BUILDING_LIBRARY) + find_library(SDLMAIN_LIBRARY + NAMES SDLmain + HINTS + ${SDL_ROOT}/lib + PATH_SUFFIXES x86 + ) +endif() + +if(SDL_INCLUDE_DIR AND EXISTS "${SDL_INCLUDE_DIR}/SDL/SDL_version.h") + file(STRINGS "${SDL_INCLUDE_DIR}/SDL/SDL_version.h" SDL_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_INCLUDE_DIR}/SDL/SDL_version.h" SDL_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_INCLUDE_DIR}/SDL/SDL_version.h" SDL_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MAJOR "${SDL_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_VERSION_MINOR "${SDL_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_VERSION_PATCH "${SDL_VERSION_PATCH_LINE}") + set(SDL_VERSION_STRING ${SDL_VERSION_MAJOR}.${SDL_VERSION_MINOR}.${SDL_VERSION_PATCH}) + unset(SDL_VERSION_MAJOR_LINE) + unset(SDL_VERSION_MINOR_LINE) + unset(SDL_VERSION_PATCH_LINE) + unset(SDL_VERSION_MAJOR) + unset(SDL_VERSION_MINOR) + unset(SDL_VERSION_PATCH) +endif() + +set(SDL_INCLUDE_DIRS ${SDL_INCLUDE_DIR} ${SDL_INCLUDE_DIR}/SDL) +set(SDL_LIBRARIES ${SDLMAIN_LIBRARY} ${SDL_LIBRARY}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(SDL + REQUIRED_VARS SDL_INCLUDE_DIR SDL_LIBRARY + VERSION_VAR SDL_VERSION_STRING) + +mark_as_advanced(SDL_INCLUDE_DIR SDL_LIBRARY) diff --git a/RetroFE/CMake/FindSDL_gfx.cmake b/RetroFE/CMake/FindSDL_gfx.cmake new file mode 100644 index 0000000..fe9e201 --- /dev/null +++ b/RetroFE/CMake/FindSDL_gfx.cmake @@ -0,0 +1,73 @@ +# Downloaded from http://cmake.3232098.n2.nabble.com/Find-modules-for-SDL-td7585211.html and adapted to SDL_gfx +# +# - Find SDL_gfx library and headers +# +# Find module for SDL_gfx 2.0 (http://www.libsdl.org/projects/SDL_gfx/). +# It defines the following variables: +# SDL_GFX_INCLUDE_DIRS - The location of the headers, e.g., SDL_gfx.h. +# SDL_GFX_LIBRARIES - The libraries to link against to use SDL_gfx. +# SDL_GFX_FOUND - If false, do not try to use SDL_gfx. +# SDL_GFX_VERSION_STRING +# Human-readable string containing the version of SDL_gfx. +# +# Also defined, but not for general use are: +# SDL_GFX_INCLUDE_DIR - The directory that contains SDL_gfx.h. +# SDL_GFX_LIBRARY - The location of the SDL_gfx library. +# + +#============================================================================= +# Copyright 2013 Benjamin Eikel +# +# 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_package(PkgConfig QUIET) +pkg_check_modules(PC_SDL_GFX QUIET SDL_gfx) + +find_path(SDL_GFX_INCLUDE_DIR + NAMES SDL/SDL_rotozoom.h + HINTS + ${SDL_GFX_ROOT} + PATH_SUFFIXES include +) + +find_library(SDL_GFX_LIBRARY + NAMES SDL_gfx + HINTS + ${SDL_GFX_ROOT}/lib + PATH_SUFFIXES x86 +) + +if(SDL_GFX_INCLUDE_DIR AND EXISTS "${SDL_GFX_INCLUDE_DIR}/SDL/SDL_gfx.h") + file(STRINGS "${SDL_GFX_INCLUDE_DIR}/SDL/SDL_gfx.h" SDL_GFX_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_GFX_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_GFX_INCLUDE_DIR}/SDL/SDL_gfx.h" SDL_GFX_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_GFX_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_GFX_INCLUDE_DIR}/SDL/SDL_gfx.h" SDL_GFX_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_GFX_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_GFX_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MAJOR "${SDL_GFX_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_GFX_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MINOR "${SDL_GFX_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_GFX_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_PATCH "${SDL_GFX_VERSION_PATCH_LINE}") + set(SDL_GFX_VERSION_STRING ${SDL_GFX_VERSION_MAJOR}.${SDL_GFX_VERSION_MINOR}.${SDL_GFX_VERSION_PATCH}) + unset(SDL_GFX_VERSION_MAJOR_LINE) + unset(SDL_GFX_VERSION_MINOR_LINE) + unset(SDL_GFX_VERSION_PATCH_LINE) + unset(SDL_GFX_VERSION_MAJOR) + unset(SDL_GFX_VERSION_MINOR) + unset(SDL_GFX_VERSION_PATCH) +endif() + +set(SDL_GFX_INCLUDE_DIRS ${SDL_GFX_INCLUDE_DIR} ${SDL_GFX_INCLUDE_DIR}/SDL) +set(SDL_GFX_LIBRARIES ${SDL_GFX_LIBRARY}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(SDL_gfx + REQUIRED_VARS SDL_GFX_INCLUDE_DIRS SDL_GFX_LIBRARIES + VERSION_VAR SDL_GFX_VERSION_STRING) + +mark_as_advanced(SDL_GFX_INCLUDE_DIR SDL_GFX_LIBRARY) diff --git a/RetroFE/CMake/FindSDL_image.cmake b/RetroFE/CMake/FindSDL_image.cmake new file mode 100644 index 0000000..d4737ad --- /dev/null +++ b/RetroFE/CMake/FindSDL_image.cmake @@ -0,0 +1,70 @@ +# - Find SDL_image library and headers +# +# Find module for SDL_image 2.0 (http://www.libsdl.org/projects/SDL_image/). +# It defines the following variables: +# SDL_IMAGE_INCLUDE_DIRS - The location of the headers, e.g., SDL_image.h. +# SDL_IMAGE_LIBRARIES - The libraries to link against to use SDL_image. +# SDL_IMAGE_FOUND - If false, do not try to use SDL_image. +# SDL_IMAGE_VERSION_STRING +# Human-readable string containing the version of SDL_image. +# +# Also defined, but not for general use are: +# SDL_IMAGE_INCLUDE_DIR - The directory that contains SDL_image.h. +# SDL_IMAGE_LIBRARY - The location of the SDL_image library. +# + +#============================================================================= +# Copyright 2013 Benjamin Eikel +# +# 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_package(PkgConfig QUIET) +pkg_check_modules(PC_SDL_IMAGE QUIET SDL_image) + +find_path(SDL_IMAGE_INCLUDE_DIR + NAMES SDL/SDL_image.h + HINTS + ${SDL_IMAGE_ROOT}/include +) + +find_library(SDL_IMAGE_LIBRARY + NAMES SDL_image + HINTS + ${SDL_IMAGE_ROOT}/lib + PATH_SUFFIXES x86 +) + +if(SDL_IMAGE_INCLUDE_DIR AND EXISTS "${SDL_IMAGE_INCLUDE_DIR}/SDL/SDL_image.h") + file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL/SDL_image.h" SDL_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL/SDL_image.h" SDL_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL/SDL_image.h" SDL_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_MAJOR "${SDL_IMAGE_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_MINOR "${SDL_IMAGE_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_PATCH "${SDL_IMAGE_VERSION_PATCH_LINE}") + set(SDL_IMAGE_VERSION_STRING ${SDL_IMAGE_VERSION_MAJOR}.${SDL_IMAGE_VERSION_MINOR}.${SDL_IMAGE_VERSION_PATCH}) + unset(SDL_IMAGE_VERSION_MAJOR_LINE) + unset(SDL_IMAGE_VERSION_MINOR_LINE) + unset(SDL_IMAGE_VERSION_PATCH_LINE) + unset(SDL_IMAGE_VERSION_MAJOR) + unset(SDL_IMAGE_VERSION_MINOR) + unset(SDL_IMAGE_VERSION_PATCH) +endif() + +set(SDL_IMAGE_INCLUDE_DIRS ${SDL_IMAGE_INCLUDE_DIR} ${SDL_IMAGE_INCLUDE_DIR}/SDL) +set(SDL_IMAGE_LIBRARIES ${SDL_IMAGE_LIBRARY}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(SDL_image + REQUIRED_VARS SDL_IMAGE_INCLUDE_DIRS SDL_IMAGE_LIBRARIES + VERSION_VAR SDL_IMAGE_VERSION_STRING) + +mark_as_advanced(SDL_IMAGE_INCLUDE_DIR SDL_IMAGE_LIBRARY) diff --git a/RetroFE/CMake/FindSDL_mixer.cmake b/RetroFE/CMake/FindSDL_mixer.cmake new file mode 100644 index 0000000..97b3766 --- /dev/null +++ b/RetroFE/CMake/FindSDL_mixer.cmake @@ -0,0 +1,72 @@ +# Downloaded from http://cmake.3232098.n2.nabble.com/Find-modules-for-SDL-td7585211.html and adapted to SDL_mixer +# +# - Find SDL_mixer library and headers +# +# Find module for SDL_mixer 2.0 (http://www.libsdl.org/projects/SDL_mixer/). +# It defines the following variables: +# SDL_MIXER_INCLUDE_DIRS - The location of the headers, e.g., SDL_mixer.h. +# SDL_MIXER_LIBRARIES - The libraries to link against to use SDL_mixer. +# SDL_MIXER_FOUND - If false, do not try to use SDL_mixer. +# SDL_MIXER_VERSION_STRING +# Human-readable string containing the version of SDL_mixer. +# +# Also defined, but not for general use are: +# SDL_MIXER_INCLUDE_DIR - The directory that contains SDL_mixer.h. +# SDL_MIXER_LIBRARY - The location of the SDL_mixer library. +# + +#============================================================================= +# Copyright 2013 Benjamin Eikel +# +# 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_package(PkgConfig QUIET) +pkg_check_modules(PC_SDL_MIXER QUIET SDL_mixer) + +find_path(SDL_MIXER_INCLUDE_DIR + NAMES SDL/SDL_mixer.h + HINTS + ${SDL_MIXER_ROOT}/include +) + +find_library(SDL_MIXER_LIBRARY + NAMES SDL_mixer + HINTS + ${SDL_MIXER_ROOT}/lib + PATH_SUFFIXES x86 +) + +if(SDL_MIXER_INCLUDE_DIR AND EXISTS "${SDL_MIXER_INCLUDE_DIR}/SDL/SDL_mixer.h") + file(STRINGS "${SDL_MIXER_INCLUDE_DIR}/SDL/SDL_mixer.h" SDL_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_MIXER_INCLUDE_DIR}/SDL/SDL_mixer.h" SDL_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_MIXER_INCLUDE_DIR}/SDL/SDL_mixer.h" SDL_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_MIXER_VERSION_MAJOR "${SDL_MIXER_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_MIXER_VERSION_MINOR "${SDL_MIXER_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_MIXER_VERSION_PATCH "${SDL_MIXER_VERSION_PATCH_LINE}") + set(SDL_MIXER_VERSION_STRING ${SDL_MIXER_VERSION_MAJOR}.${SDL_MIXER_VERSION_MINOR}.${SDL_MIXER_VERSION_PATCH}) + unset(SDL_MIXER_VERSION_MAJOR_LINE) + unset(SDL_MIXER_VERSION_MINOR_LINE) + unset(SDL_MIXER_VERSION_PATCH_LINE) + unset(SDL_MIXER_VERSION_MAJOR) + unset(SDL_MIXER_VERSION_MINOR) + unset(SDL_MIXER_VERSION_PATCH) +endif() + +set(SDL_MIXER_INCLUDE_DIRS ${SDL_MIXER_INCLUDE_DIR} ${SDL_MIXER_INCLUDE_DIR}/SDL) +set(SDL_MIXER_LIBRARIES ${SDL_MIXER_LIBRARY}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(SDL_mixer + REQUIRED_VARS SDL_MIXER_INCLUDE_DIRS SDL_MIXER_LIBRARIES + VERSION_VAR SDL_MIXER_VERSION_STRING) + +mark_as_advanced(SDL_MIXER_INCLUDE_DIR SDL_MIXER_LIBRARY) diff --git a/RetroFE/CMake/FindSDL_ttf.cmake b/RetroFE/CMake/FindSDL_ttf.cmake new file mode 100644 index 0000000..650ed70 --- /dev/null +++ b/RetroFE/CMake/FindSDL_ttf.cmake @@ -0,0 +1,73 @@ +# Downloaded from http://cmake.3232098.n2.nabble.com/Find-modules-for-SDL-td7585211.html and adapted to SDL_ttf +# +# - Find SDL_ttf library and headers +# +# Find module for SDL_ttf 2.0 (http://www.libsdl.org/projects/SDL_ttf/). +# It defines the following variables: +# SDL_TTF_INCLUDE_DIRS - The location of the headers, e.g., SDL_ttf.h. +# SDL_TTF_LIBRARIES - The libraries to link against to use SDL_ttf. +# SDL_TTF_FOUND - If false, do not try to use SDL_ttf. +# SDL_TTF_VERSION_STRING +# Human-readable string containing the version of SDL_ttf. +# +# Also defined, but not for general use are: +# SDL_TTF_INCLUDE_DIR - The directory that contains SDL_ttf.h. +# SDL_TTF_LIBRARY - The location of the SDL_ttf library. +# + +#============================================================================= +# Copyright 2013 Benjamin Eikel +# +# 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_package(PkgConfig QUIET) +pkg_check_modules(PC_SDL_TTF QUIET SDL_ttf) + +find_path(SDL_TTF_INCLUDE_DIR + NAMES SDL/SDL_ttf.h + HINTS + ${SDL_TTF_ROOT} + PATH_SUFFIXES include +) + +find_library(SDL_TTF_LIBRARY + NAMES SDL_ttf + HINTS + ${SDL_TTF_ROOT}/lib + PATH_SUFFIXES x86 +) + +if(SDL_TTF_INCLUDE_DIR AND EXISTS "${SDL_TTF_INCLUDE_DIR}/SDL/SDL_ttf.h") + file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL/SDL_ttf.h" SDL_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL/SDL_ttf.h" SDL_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_TTF_INCLUDE_DIR}/SDL/SDL_ttf.h" SDL_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_MAJOR "${SDL_TTF_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_MINOR "${SDL_TTF_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_TTF_VERSION_PATCH "${SDL_TTF_VERSION_PATCH_LINE}") + set(SDL_TTF_VERSION_STRING ${SDL_TTF_VERSION_MAJOR}.${SDL_TTF_VERSION_MINOR}.${SDL_TTF_VERSION_PATCH}) + unset(SDL_TTF_VERSION_MAJOR_LINE) + unset(SDL_TTF_VERSION_MINOR_LINE) + unset(SDL_TTF_VERSION_PATCH_LINE) + unset(SDL_TTF_VERSION_MAJOR) + unset(SDL_TTF_VERSION_MINOR) + unset(SDL_TTF_VERSION_PATCH) +endif() + +set(SDL_TTF_INCLUDE_DIRS ${SDL_TTF_INCLUDE_DIR} ${SDL_TTF_INCLUDE_DIR}/SDL) +set(SDL_TTF_LIBRARIES ${SDL_TTF_LIBRARY}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(SDL_ttf + REQUIRED_VARS SDL_TTF_INCLUDE_DIRS SDL_TTF_LIBRARIES + VERSION_VAR SDL_TTF_VERSION_STRING) + +mark_as_advanced(SDL_TTF_INCLUDE_DIR SDL_TTF_LIBRARY) diff --git a/RetroFE/Source/CMakeLists.txt b/RetroFE/Source/CMakeLists.txt index c9e14f6..fa98324 100755 --- a/RetroFE/Source/CMakeLists.txt +++ b/RetroFE/Source/CMakeLists.txt @@ -40,24 +40,35 @@ endif() if(WIN32) find_package(Glib2 REQUIRED) find_package(GStreamer REQUIRED) - find_package(SDL2 REQUIRED) - find_package(SDL2_image REQUIRED) - find_package(SDL2_mixer REQUIRED) - find_package(SDL2_ttf REQUIRED) + #find_package(SDL2 REQUIRED) + #find_package(SDL2_image REQUIRED) + #find_package(SDL2_mixer REQUIRED) + #find_package(SDL2_ttf REQUIRED) + find_package(SDL REQUIRED ) + find_package(SDL_image REQUIRED ) + find_package(SDL_mixer REQUIRED SDL_mixer) + find_package(SDL_ttf REQUIRED ) + find_package(SDL_gfx REQUIRED ) find_package(ZLIB REQUIRED) else() include(FindPkgConfig) - pkg_search_module(SDL2 REQUIRED sdl2) - pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image) - pkg_search_module(SDL2_MIXER REQUIRED SDL2_mixer) - pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf) + #pkg_search_module(SDL2 REQUIRED sdl2) + #pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image) + #pkg_search_module(SDL2_MIXER REQUIRED SDL2_mixer) + #pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf) + find_package(SDL REQUIRED ) + find_package(SDL_image REQUIRED ) + find_package(SDL_mixer REQUIRED SDL_mixer) + find_package(SDL_ttf REQUIRED ) + find_package(SDL_gfx REQUIRED ) pkg_search_module(ZLIB REQUIRED zlib) pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0 gstreamer-video-1.0) pkg_check_modules(Glib2 REQUIRED glib-2.0 gobject-2.0 gthread-2.0 gmodule-2.0) find_package(Threads REQUIRED) if(APPLE) - find_package(SDL2 REQUIRED) + #find_package(SDL2 REQUIRED) + find_package(SDL REQUIRED ) endif() endif() @@ -65,10 +76,15 @@ set(RETROFE_INCLUDE_DIRS "/usr/local/opt/gst-plugins-base/include/gstreamer-1.0" "${GLIB2_INCLUDE_DIRS}" "${GSTREAMER_INCLUDE_DIRS}" - "${SDL2_INCLUDE_DIRS}" - "${SDL2_IMAGE_INCLUDE_DIRS}" - "${SDL2_MIXER_INCLUDE_DIRS}" - "${SDL2_TTF_INCLUDE_DIRS}" + #"${SDL2_INCLUDE_DIRS}" + #"${SDL2_IMAGE_INCLUDE_DIRS}" + #"${SDL2_MIXER_INCLUDE_DIRS}" + #"${SDL2_TTF_INCLUDE_DIRS}" + "${SDL_INCLUDE_DIRS}" + "${SDL_IMAGE_INCLUDE_DIRS}" + "${SDL_MIXER_INCLUDE_DIRS}" + "${SDL_TTF_INCLUDE_DIRS}" + "${SDL_GFX_INCLUDE_DIRS}" "${ZLIB_INCLUDE_DIRS}" "${SQLITE3_ROOT}" "${RAPIDXML_ROOT}" @@ -81,10 +97,15 @@ endif() set(RETROFE_LIBRARIES ${GLIB2_LIBRARIES} ${GSTREAMER_LIBRARIES} - ${SDL2_LIBRARIES} - ${SDL2_IMAGE_LIBRARIES} - ${SDL2_MIXER_LIBRARIES} - ${SDL2_TTF_LIBRARIES} + #${SDL2_LIBRARIES} + #${SDL2_IMAGE_LIBRARIES} + #${SDL2_MIXER_LIBRARIES} + #${SDL2_TTF_LIBRARIES} + ${SDL_LIBRARIES} + ${SDL_IMAGE_LIBRARIES} + ${SDL_MIXER_LIBRARIES} + ${SDL_TTF_LIBRARIES} + ${SDL_GFX_LIBRARIES} ${ZLIB_LIBRARIES} ) @@ -206,6 +227,7 @@ include_directories(${RETROFE_INCLUDE_DIRS}) add_executable(retrofe ${RETROFE_SOURCES} ${RETROFE_HEADERS}) target_link_libraries(retrofe ${RETROFE_LIBRARIES}) set_target_properties(retrofe PROPERTIES LINKER_LANGUAGE CXX) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wall") if(MINGW) set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -lmingw32 -mwindows") endif() diff --git a/RetroFE/Source/Control/InputHandler.h b/RetroFE/Source/Control/InputHandler.h index 8ef88da..ec2baa6 100644 --- a/RetroFE/Source/Control/InputHandler.h +++ b/RetroFE/Source/Control/InputHandler.h @@ -1,6 +1,6 @@ #pragma once -#include +#include class InputHandler { diff --git a/RetroFE/Source/Control/KeyboardHandler.cpp b/RetroFE/Source/Control/KeyboardHandler.cpp index e7bb72b..93d516c 100644 --- a/RetroFE/Source/Control/KeyboardHandler.cpp +++ b/RetroFE/Source/Control/KeyboardHandler.cpp @@ -1,6 +1,6 @@ #include "KeyboardHandler.h" -KeyboardHandler::KeyboardHandler(SDL_Scancode s) +KeyboardHandler::KeyboardHandler(SDLKey s) : scancode_(s) , pressed_(false) { @@ -15,7 +15,7 @@ bool KeyboardHandler::update(SDL_Event &e) { if(e.type != SDL_KEYUP && e.type != SDL_KEYDOWN) return false; - if(e.key.keysym.scancode == scancode_) + if(e.key.keysym.sym == scancode_) { pressed_ = (e.type == SDL_KEYDOWN); return true; diff --git a/RetroFE/Source/Control/KeyboardHandler.h b/RetroFE/Source/Control/KeyboardHandler.h index b49097c..acf9e28 100644 --- a/RetroFE/Source/Control/KeyboardHandler.h +++ b/RetroFE/Source/Control/KeyboardHandler.h @@ -5,13 +5,13 @@ class KeyboardHandler : public InputHandler { public: - KeyboardHandler(SDL_Scancode scancode); + KeyboardHandler(SDLKey scancode); bool update(SDL_Event &e); bool pressed(); void reset(); private: - SDL_Scancode scancode_; + SDLKey scancode_; bool pressed_; }; diff --git a/RetroFE/Source/Control/UserInput.cpp b/RetroFE/Source/Control/UserInput.cpp index 0907346..09728e8 100644 --- a/RetroFE/Source/Control/UserInput.cpp +++ b/RetroFE/Source/Control/UserInput.cpp @@ -18,12 +18,104 @@ #include "../Database/Configuration.h" #include "../Utility/Log.h" #include "../Utility/Utils.h" -#include "JoyAxisHandler.h" -#include "JoyButtonHandler.h" -#include "JoyHatHandler.h" +#include +//#include "JoyAxisHandler.h" +//#include "JoyButtonHandler.h" +//#include "JoyHatHandler.h" #include "KeyboardHandler.h" #include "MouseButtonHandler.h" +const key_names_s key_names[] = { +/* + a subset of + sed 's/^#define \([^ \t]\+\)[ \t]*\([^\ \t]\+\)/ { \"\1\",\t\2 },/' /usr/include/linux/input.h + */ + { "KEY_RESERVED", SDLK_UNKNOWN }, + { "Escape", SDLK_ESCAPE }, + { "1", SDLK_1 }, + { "2", SDLK_2 }, + { "3", SDLK_3 }, + { "4", SDLK_4 }, + { "5", SDLK_5 }, + { "6", SDLK_6 }, + { "7", SDLK_7 }, + { "8", SDLK_8 }, + { "9", SDLK_9 }, + { "0", SDLK_0 }, + { "-", SDLK_MINUS }, + { "=", SDLK_EQUALS }, + { "Backspace", SDLK_BACKSPACE }, + { "Tab", SDLK_TAB }, + { "Q", SDLK_q }, + { "W", SDLK_w }, + { "E", SDLK_e }, + { "R", SDLK_r }, + { "T", SDLK_t }, + { "Y", SDLK_y }, + { "U", SDLK_u }, + { "I", SDLK_i }, + { "O", SDLK_o }, + { "P", SDLK_p }, + { "[", SDLK_LEFTBRACKET }, + { "]", SDLK_RIGHTBRACKET }, + { "Return", SDLK_RETURN }, + { "Left Ctrl", SDLK_LCTRL }, + { "A", SDLK_a }, + { "S", SDLK_s }, + { "D", SDLK_d }, + { "F", SDLK_f }, + { "G", SDLK_g }, + { "H", SDLK_h }, + { "J", SDLK_j }, + { "K", SDLK_k }, + { "L", SDLK_l }, + { ";", SDLK_SEMICOLON }, + { "'", SDLK_QUOTE }, + { "Left Shift", SDLK_LSHIFT }, + { "\\", SDLK_BACKSLASH }, + { "Z", SDLK_z }, + { "X", SDLK_x }, + { "C", SDLK_c }, + { "V", SDLK_v }, + { "B", SDLK_b }, + { "N", SDLK_n }, + { "M", SDLK_m }, + { ",", SDLK_PERIOD }, + { ".", SDLK_COMMA }, + { "/", SDLK_SLASH }, + { "Right Shift", SDLK_RSHIFT }, + { "Left Alt", SDLK_LALT }, + { "Space", SDLK_SPACE }, + { "CapsLock", SDLK_CAPSLOCK }, + { "F1", SDLK_F1 }, + { "F2", SDLK_F2 }, + { "F3", SDLK_F3 }, + { "F4", SDLK_F4 }, + { "F5", SDLK_F5 }, + { "F6", SDLK_F6 }, + { "F7", SDLK_F7 }, + { "F8", SDLK_F8 }, + { "F9", SDLK_F9 }, + { "F10", SDLK_F10 }, + { "F11", SDLK_F11 }, + { "F12", SDLK_F12 }, + { "Right Ctrl", SDLK_RCTRL }, + { "Right Alt", SDLK_RALT }, + { "Up", SDLK_UP }, + { "PageUp", SDLK_PAGEUP }, + { "Left", SDLK_LEFT }, + { "Right", SDLK_RIGHT }, + { "End", SDLK_END }, + { "Down", SDLK_DOWN }, + { "PageDown", SDLK_PAGEDOWN }, + { "Insert", SDLK_INSERT }, + { "Delete", SDLK_DELETE }, + + + { "LAST", -1 }, +}; + + UserInput::UserInput(Configuration &c) : config_(c) { @@ -93,6 +185,24 @@ bool UserInput::initialize() return retVal; } +/* Return linux Key code from corresponding str*/ +SDLKey UserInput::SDL_GetScancodeFromName(const char *name) +{ + int i=0; + SDLKey returnValue = SDLK_UNKNOWN; + while(key_names[i].code >= 0){ + if(!strncmp(key_names[i].name, name, 32)){ + returnValue = (SDLKey) key_names[i].code; + break; + } + i++; + } + if(key_names[i].code < 0){ + returnValue = SDLK_UNKNOWN; + } + return returnValue; +} + bool UserInput::MapKey(std::string keyDescription, KeyCode_E key) { return MapKey(keyDescription, key, true); @@ -100,7 +210,7 @@ bool UserInput::MapKey(std::string keyDescription, KeyCode_E key) bool UserInput::MapKey(std::string keyDescription, KeyCode_E key, bool required) { - SDL_Scancode scanCode; + SDLKey scanCode; std::string description; std::string configKey = "controls." + keyDescription; @@ -126,9 +236,9 @@ bool UserInput::MapKey(std::string keyDescription, KeyCode_E key, bool required) bool found = false; - if (scanCode != SDL_SCANCODE_UNKNOWN) + if (scanCode != SDLK_UNKNOWN) { - Logger::write(Logger::ZONE_INFO, "Input", "Binding key " + configKey); + Logger::write(Logger::ZONE_INFO, "Input", "Binding key " + configKey + ", Key Value: " + std::to_string(scanCode)); keyHandlers_.push_back(std::pair(new KeyboardHandler(scanCode), key)); found = true; } diff --git a/RetroFE/Source/Control/UserInput.h b/RetroFE/Source/Control/UserInput.h index 3fc0e7e..0a93988 100644 --- a/RetroFE/Source/Control/UserInput.h +++ b/RetroFE/Source/Control/UserInput.h @@ -14,11 +14,17 @@ * along with RetroFE. If not, see . */ #pragma once -#include +#include #include #include #include #include +//#include "SDL_scancode.h" + +typedef struct{ + char name[32]; + int code; +}key_names_s; const int cMaxJoy = 4; @@ -64,6 +70,8 @@ public: void clearJoysticks( ); private: + SDLKey SDL_GetScancodeFromName(const char *name); + //SDL_Scancode SDL_GetScancodeFromName(const char *name); bool MapKey(std::string keyDescription, KeyCode_E key); bool MapKey(std::string keyDescription, KeyCode_E key, bool required); Configuration &config_; diff --git a/RetroFE/Source/Graphics/Component/Component.cpp b/RetroFE/Source/Graphics/Component/Component.cpp index de70612..ec3a5a7 100644 --- a/RetroFE/Source/Graphics/Component/Component.cpp +++ b/RetroFE/Source/Graphics/Component/Component.cpp @@ -68,7 +68,8 @@ void Component::freeGraphicsMemory() if ( backgroundTexture_ ) { SDL_LockMutex(SDL::getMutex()); - SDL_DestroyTexture(backgroundTexture_); + //SDL_DestroyTexture(backgroundTexture_); + SDL_FreeSurface(backgroundTexture_); SDL_UnlockMutex(SDL::getMutex()); backgroundTexture_ = NULL; @@ -80,7 +81,7 @@ void Component::allocateGraphicsMemory() { // make a 4x4 pixel wide surface to be stretched during rendering, make it a white background so we can use // color later - SDL_Surface *surface = SDL_CreateRGBSurface(0, 4, 4, 32, 0, 0, 0, 0); + /*SDL_Surface *surface = SDL_CreateRGBSurface(0, 4, 4, 32, 0, 0, 0, 0); SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 255, 255, 255)); SDL_LockMutex(SDL::getMutex()); @@ -88,7 +89,12 @@ void Component::allocateGraphicsMemory() SDL_UnlockMutex(SDL::getMutex()); SDL_FreeSurface(surface); - SDL_SetTextureBlendMode(backgroundTexture_, SDL_BLENDMODE_BLEND); + SDL_SetTextureBlendMode(backgroundTexture_, SDL_BLENDMODE_BLEND);*/ + + SDL_LockMutex(SDL::getMutex()); + backgroundTexture_ = SDL_CreateRGBSurface(0, 4, 4, 32, 0, 0, 0, 0); + SDL_FillRect(backgroundTexture_, NULL, SDL_MapRGB(backgroundTexture_->format, 255, 255, 255)); + SDL_UnlockMutex(SDL::getMutex()); } } @@ -217,11 +223,11 @@ void Component::draw() rect.x = static_cast(baseViewInfo.XRelativeToOrigin()); rect.y = static_cast(baseViewInfo.YRelativeToOrigin()); - - SDL_SetTextureColorMod(backgroundTexture_, + // TODO : adapt to sdl1.2 + /*SDL_SetTextureColorMod(backgroundTexture_, static_cast(baseViewInfo.BackgroundRed*255), static_cast(baseViewInfo.BackgroundGreen*255), - static_cast(baseViewInfo.BackgroundBlue*255)); + static_cast(baseViewInfo.BackgroundBlue*255));*/ SDL::renderCopy(backgroundTexture_, baseViewInfo.BackgroundAlpha, NULL, &rect, baseViewInfo); } diff --git a/RetroFE/Source/Graphics/Component/Component.h b/RetroFE/Source/Graphics/Component/Component.h index 2abd384..e7f59b2 100644 --- a/RetroFE/Source/Graphics/Component/Component.h +++ b/RetroFE/Source/Graphics/Component/Component.h @@ -67,7 +67,8 @@ private: AnimationEvents *tweens_; Animation *currentTweens_; - SDL_Texture *backgroundTexture_; + //SDL_Texture *backgroundTexture_; + SDL_Surface *backgroundTexture_; ViewInfo storeViewInfo_; unsigned int currentTweenIndex_; diff --git a/RetroFE/Source/Graphics/Component/Container.h b/RetroFE/Source/Graphics/Component/Container.h index d98c0d4..7152c75 100644 --- a/RetroFE/Source/Graphics/Component/Container.h +++ b/RetroFE/Source/Graphics/Component/Container.h @@ -16,7 +16,7 @@ #pragma once #include "Component.h" -#include +#include #include class Container : public Component diff --git a/RetroFE/Source/Graphics/Component/Image.cpp b/RetroFE/Source/Graphics/Component/Image.cpp index c145a12..e6e3f7e 100644 --- a/RetroFE/Source/Graphics/Component/Image.cpp +++ b/RetroFE/Source/Graphics/Component/Image.cpp @@ -17,7 +17,7 @@ #include "../ViewInfo.h" #include "../../SDL.h" #include "../../Utility/Log.h" -#include +#include Image::Image(std::string file, std::string altFile, Page &p, float scaleX, float scaleY) : Component(p) @@ -42,7 +42,8 @@ void Image::freeGraphicsMemory() SDL_LockMutex(SDL::getMutex()); if (texture_ != NULL) { - SDL_DestroyTexture(texture_); + //SDL_DestroyTexture(texture_); + SDL_FreeSurface(texture_); texture_ = NULL; } SDL_UnlockMutex(SDL::getMutex()); @@ -56,18 +57,22 @@ void Image::allocateGraphicsMemory() if(!texture_) { SDL_LockMutex(SDL::getMutex()); - texture_ = IMG_LoadTexture(SDL::getRenderer(), file_.c_str()); + //texture_ = IMG_LoadTexture(SDL::getRenderer(), file_.c_str()); + texture_ = IMG_Load(file_.c_str()); if (!texture_ && altFile_ != "") { - texture_ = IMG_LoadTexture(SDL::getRenderer(), altFile_.c_str()); + //texture_ = IMG_LoadTexture(SDL::getRenderer(), altFile_.c_str()); + texture_ = IMG_Load(altFile_.c_str()); } if (texture_ != NULL) { - SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND); - SDL_QueryTexture(texture_, NULL, NULL, &width, &height); + //SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND); + /*SDL_QueryTexture(texture_, NULL, NULL, &width, &height); baseViewInfo.ImageWidth = width * scaleX_; - baseViewInfo.ImageHeight = height * scaleY_; + baseViewInfo.ImageHeight = height * scaleY_;*/ + baseViewInfo.ImageWidth = texture_->w * scaleX_; + baseViewInfo.ImageHeight = texture_->h * scaleY_; } SDL_UnlockMutex(SDL::getMutex()); diff --git a/RetroFE/Source/Graphics/Component/Image.h b/RetroFE/Source/Graphics/Component/Image.h index 6a1da3f..72b22bd 100644 --- a/RetroFE/Source/Graphics/Component/Image.h +++ b/RetroFE/Source/Graphics/Component/Image.h @@ -16,7 +16,7 @@ #pragma once #include "Component.h" -#include +#include #include class Image : public Component @@ -29,7 +29,8 @@ public: void draw(); protected: - SDL_Texture *texture_; + //SDL_Texture *texture_; + SDL_Surface *texture_; std::string file_; std::string altFile_; float scaleX_; diff --git a/RetroFE/Source/Graphics/Component/ReloadableMedia.h b/RetroFE/Source/Graphics/Component/ReloadableMedia.h index 8d28411..f8057fe 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableMedia.h +++ b/RetroFE/Source/Graphics/Component/ReloadableMedia.h @@ -18,7 +18,7 @@ #include "ReloadableText.h" #include "../../Video/IVideo.h" #include "../../Collection/Item.h" -#include +#include #include class Image; diff --git a/RetroFE/Source/Graphics/Component/ReloadableScrollingText.cpp b/RetroFE/Source/Graphics/Component/ReloadableScrollingText.cpp index cf7ed98..c096ae9 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableScrollingText.cpp +++ b/RetroFE/Source/Graphics/Component/ReloadableScrollingText.cpp @@ -42,8 +42,10 @@ ReloadableScrollingText::ReloadableScrollingText(Configuration &config, bool sys , pluralPrefix_(pluralPrefix) , pluralPostfix_(pluralPostfix) , alignment_(alignment) - , scaleX_(scaleX) - , scaleY_(scaleY) + //, scaleX_(scaleX) + //, scaleY_(scaleY) + , scaleX_(1.0f) //TODO + , scaleY_(1.0f) //TODO , direction_(direction) , scrollingSpeed_(scrollingSpeed) , startPosition_(startPosition) @@ -459,7 +461,8 @@ void ReloadableScrollingText::draw( ) else // If not, use the general font settings font = fontInst_; - SDL_Texture *t = font->getTexture( ); + //SDL_Texture *t = font->getTexture( ); + SDL_Surface *t = font->getTexture( ); float imageWidth = 0; float imageMaxWidth = 0; @@ -481,7 +484,9 @@ void ReloadableScrollingText::draw( ) imageMaxHeight = baseViewInfo.MaxHeight; } - float scale = (float)baseViewInfo.FontSize / (float)font->getHeight( ) / scaleY_; + //float scale = (float)baseViewInfo.FontSize / (float)font->getHeight( ) / scaleY_; + //TODO, modify for scaling - for now, no scaling in effect + float scale = 1.0f; float xOrigin = baseViewInfo.XRelativeToOrigin( ); float yOrigin = baseViewInfo.YRelativeToOrigin( ); @@ -513,17 +518,19 @@ void ReloadableScrollingText::draw( ) Font::GlyphInfo glyph; - if (font->getRect( text_[l][i], glyph) && glyph.rect.h > 0) + //if (font->getRect( text_[l][i], glyph) && glyph.rect.h > 0) + if (font->getRect( text_[l][i], glyph)) { SDL_Rect charRect = glyph.rect; rect.h = static_cast( charRect.h * scale * scaleY_ ); rect.w = static_cast( charRect.w * scale * scaleX_ ); rect.y = static_cast( yOrigin ); - if (font->getAscent( ) < glyph.maxY) + /*if (font->getAscent( ) < glyph.maxY) { rect.y += static_cast( (font->getAscent( ) - glyph.maxY) * scale * scaleY_ ); - } + }*/ + rect.y += static_cast( (font->getAscent( ) - glyph.maxY) * scale * scaleY_ ); // Check if glyph falls partially outside the box at the back end if ((rect.x + static_cast( glyph.advance * scale * scaleX_ )) >= (static_cast( xOrigin ) + imageMaxWidth)) @@ -707,7 +714,8 @@ void ReloadableScrollingText::draw( ) { Font::GlyphInfo glyph; - if (font->getRect( word[i], glyph) && glyph.rect.h > 0) + //if (font->getRect( word[i], glyph) && glyph.rect.h > 0) + if (font->getRect( word[i], glyph)) { SDL_Rect charRect = glyph.rect; rect.h = static_cast( charRect.h * scale * scaleY_ ); diff --git a/RetroFE/Source/Graphics/Component/ReloadableScrollingText.h b/RetroFE/Source/Graphics/Component/ReloadableScrollingText.h index 200391c..e412b8c 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableScrollingText.h +++ b/RetroFE/Source/Graphics/Component/ReloadableScrollingText.h @@ -16,7 +16,7 @@ #pragma once #include "Component.h" #include "../../Collection/Item.h" -#include +#include #include #include diff --git a/RetroFE/Source/Graphics/Component/ReloadableText.h b/RetroFE/Source/Graphics/Component/ReloadableText.h index 82b328b..70f6b0e 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableText.h +++ b/RetroFE/Source/Graphics/Component/ReloadableText.h @@ -19,7 +19,7 @@ #include "../Font.h" #include "../Page.h" #include "../../Collection/Item.h" -#include +#include #include class ReloadableText : public Component diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 812bc7c..9dde8ce 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -34,7 +34,7 @@ #include "../../SDL.h" #include "../ViewInfo.h" #include -#include +#include #include #include #include diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.h b/RetroFE/Source/Graphics/Component/ScrollingList.h index da6e044..b5a78ef 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.h +++ b/RetroFE/Source/Graphics/Component/ScrollingList.h @@ -22,7 +22,7 @@ #include "../Page.h" #include "../ViewInfo.h" #include "../../Database/Configuration.h" -#include +#include class Configuration; diff --git a/RetroFE/Source/Graphics/Component/Text.cpp b/RetroFE/Source/Graphics/Component/Text.cpp index fb8d9a0..a6cb88d 100644 --- a/RetroFE/Source/Graphics/Component/Text.cpp +++ b/RetroFE/Source/Graphics/Component/Text.cpp @@ -73,7 +73,8 @@ void Text::draw( ) else // If not, use the general font settings font = fontInst_; - SDL_Texture *t = font->getTexture( ); + //SDL_Texture *t = font->getTexture( ); + SDL_Surface *t = font->getTexture( ); float imageHeight = 0; float imageWidth = 0; @@ -88,8 +89,14 @@ void Text::draw( ) } imageHeight = (float)font->getHeight( ); - float scale = (float)baseViewInfo.FontSize / (float)imageHeight; + //float scale = (float)baseViewInfo.FontSize / (float)imageHeight; + //TODO, modify for scaling - for now, no scaling in effect + float scale = 1.0f; + + /*printf("\n"); + printf("imageMaxWidth=%f, imageHeight=%f, baseViewInfo.FontSize=%f,scale=%f\n", imageMaxWidth, imageHeight, baseViewInfo.FontSize, scale); +*/ unsigned int textIndexMax = 0; // determine image width @@ -110,6 +117,14 @@ void Text::draw( ) textIndexMax = i; imageWidth += glyph.advance; + + /*printf("textData_[%d]=%c, glyph.advance= %f - %d\n", i, textData_[i], glyph.advance, glyph.advance); + printf("imageWidth=%f \n", imageWidth);*/ + } + else{ + /*std::stringstream ss; + ss << "Could not find Glyph info for char: " << textData_[i]; + Logger::write(Logger::ZONE_WARNING, "Text", ss.str());*/ } } @@ -140,7 +155,8 @@ void Text::draw( ) { Font::GlyphInfo glyph; - if ( font->getRect(textData_[i], glyph) && glyph.rect.h > 0 ) + //if ( font->getRect(textData_[i], glyph) && glyph.rect.h > 0 ) // Not working in SDL1.2 because glyph.rect.h = 0 for spaces + if ( font->getRect(textData_[i], glyph)) { SDL_Rect charRect = glyph.rect; float h = static_cast( charRect.h * scale ); @@ -153,11 +169,13 @@ void Text::draw( ) { rect.x += static_cast( (float)(glyph.minX) * scale ); } - if ( font->getAscent( ) < glyph.maxY ) + /*if ( font->getAscent( ) < glyph.maxY ) { rect.y += static_cast( (font->getAscent( ) - glyph.maxY)*scale ); - } + }*/ + /*printf("font->getAscent( ) = %d, glyph.maxY : %d\n", font->getAscent( ), glyph.maxY );*/ + rect.y += static_cast( (font->getAscent( ) - glyph.maxY)*scale ); SDL::renderCopy( t, baseViewInfo.Alpha, &charRect, &rect, baseViewInfo ); diff --git a/RetroFE/Source/Graphics/Component/Text.h b/RetroFE/Source/Graphics/Component/Text.h index 69162aa..fd3a9c0 100644 --- a/RetroFE/Source/Graphics/Component/Text.h +++ b/RetroFE/Source/Graphics/Component/Text.h @@ -18,7 +18,7 @@ #include "Component.h" #include "../Page.h" -#include +#include #include diff --git a/RetroFE/Source/Graphics/Component/Video.h b/RetroFE/Source/Graphics/Component/Video.h index ff81822..c918b1f 100644 --- a/RetroFE/Source/Graphics/Component/Video.h +++ b/RetroFE/Source/Graphics/Component/Video.h @@ -16,7 +16,7 @@ #pragma once #include "Component.h" #include "../../Video/IVideo.h" -#include +#include #include class Video : public Component diff --git a/RetroFE/Source/Graphics/Component/VideoComponent.cpp b/RetroFE/Source/Graphics/Component/VideoComponent.cpp index da80846..7da329e 100644 --- a/RetroFE/Source/Graphics/Component/VideoComponent.cpp +++ b/RetroFE/Source/Graphics/Component/VideoComponent.cpp @@ -93,12 +93,12 @@ void VideoComponent::draw() rect.w = static_cast(baseViewInfo.ScaledWidth()); videoInst_->draw(); - SDL_Texture *texture = videoInst_->getTexture(); + /*SDL_Texture *texture = videoInst_->getTexture(); if(texture) { SDL::renderCopy(texture, baseViewInfo.Alpha, NULL, &rect, baseViewInfo); - } + }*/ } bool VideoComponent::isPlaying() diff --git a/RetroFE/Source/Graphics/Component/VideoComponent.h b/RetroFE/Source/Graphics/Component/VideoComponent.h index 7b486fb..d4eb9ab 100644 --- a/RetroFE/Source/Graphics/Component/VideoComponent.h +++ b/RetroFE/Source/Graphics/Component/VideoComponent.h @@ -19,7 +19,7 @@ #include "../Page.h" #include "../../Collection/Item.h" #include "../../Video/IVideo.h" -#include +#include #include class VideoComponent : public Component diff --git a/RetroFE/Source/Graphics/Font.cpp b/RetroFE/Source/Graphics/Font.cpp index fbf17bc..264ba14 100644 --- a/RetroFE/Source/Graphics/Font.cpp +++ b/RetroFE/Source/Graphics/Font.cpp @@ -16,8 +16,9 @@ #include "Font.h" #include "../SDL.h" #include "../Utility/Log.h" -#include -#include +#include +#include +#include #include #include @@ -34,7 +35,7 @@ Font::~Font() deInitialize(); } -SDL_Texture *Font::getTexture() +SDL_Surface *Font::getTexture() { return texture; } @@ -87,7 +88,7 @@ bool Font::initialize() GlyphInfoBuild *info = new GlyphInfoBuild; memset(info, 0, sizeof(GlyphInfoBuild)); - color_.a = 255; + //color_.a = 255; info->surface = TTF_RenderGlyph_Blended(font, i, color_); TTF_GlyphMetrics(font, i, &info->glyph.minX, &info->glyph.maxX, @@ -110,11 +111,11 @@ bool Font::initialize() x += info->glyph.rect.w; y = (y > info->glyph.rect.h) ? y : info->glyph.rect.h; - /* - std::stringstream ss; - ss << " tw:" << atlasWidth << " th:" << atlasHeight << " x:" << x << " y:" << y << " w:" << info->Glyph.Rect.w << " h:" << info->Glyph.Rect.h; - Logger::Write(Logger::ZONE_ERROR, "FontCache", ss.str()); - */ + + /*std::stringstream ss; + ss << " tw:" << atlasWidth << " th:" << atlasHeight << " x:" << x << " y:" << y << " w:" << info->glyph.rect.w << " h:" << info->glyph.rect.h; + Logger::write(Logger::ZONE_INFO, "FontCache", ss.str());*/ + } atlasWidth = (atlasWidth >= x) ? atlasWidth : x; @@ -136,21 +137,32 @@ bool Font::initialize() amask = 0xff000000; #endif - SDL_Surface *atlasSurface = SDL_CreateRGBSurface(0, atlasWidth, atlasHeight, 32, rmask, gmask, bmask, amask); + //SDL_Surface *atlasSurface = SDL_CreateRGBSurface(0, atlasWidth, atlasHeight, 32, rmask, gmask, bmask, amask); + texture = SDL_CreateRGBSurface(0, atlasWidth, atlasHeight, 32, rmask, gmask, bmask, amask); + SDL_FillRect(texture, NULL, SDL_MapRGBA(texture->format, 0, 0, 0, 0)); + + /*texture = SDL_CreateRGBSurface(0, atlasWidth, atlasHeight, 32, 0, 0, 0, 0); + int transparentColorKey = SDL_MapRGB(texture->format, color_.r-1, color_.g-1, color_.b-1); + SDL_FillRect(texture, NULL, transparentColorKey); + SDL_SetColorKey(texture, SDL_SRCCOLORKEY, transparentColorKey);*/ + std::map::iterator it; for(it = atlas.begin(); it != atlas.end(); it++) { GlyphInfoBuild *info = it->second; - SDL_BlitSurface(info->surface, NULL, atlasSurface, &info->glyph.rect); + //SDL_BlitSurface(info->surface, NULL, atlasSurface, &info->glyph.rect); + SDL_SetAlpha( info->surface, 0, SDL_ALPHA_OPAQUE ); + SDL_BlitSurface(info->surface, NULL, texture, &info->glyph.rect); + //SDL_gfxBlitRGBA (info->surface, NULL, texture, &info->glyph.rect); SDL_FreeSurface(info->surface); info->surface = NULL; } - SDL_LockMutex(SDL::getMutex()); - texture = SDL_CreateTextureFromSurface(SDL::getRenderer(), atlasSurface); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); + /*SDL_LockMutex(SDL::getMutex()); + //texture = SDL_CreateTextureFromSurface(SDL::getRenderer(), atlasSurface); + //SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); SDL_FreeSurface(atlasSurface); - SDL_UnlockMutex(SDL::getMutex()); + SDL_UnlockMutex(SDL::getMutex());*/ TTF_CloseFont(font); @@ -164,7 +176,8 @@ void Font::deInitialize() if(texture) { SDL_LockMutex(SDL::getMutex()); - SDL_DestroyTexture(texture); + //SDL_DestroyTexture(texture); + SDL_FreeSurface(texture); texture = NULL; SDL_UnlockMutex(SDL::getMutex()); } diff --git a/RetroFE/Source/Graphics/Font.h b/RetroFE/Source/Graphics/Font.h index 65d50f7..cb4951f 100644 --- a/RetroFE/Source/Graphics/Font.h +++ b/RetroFE/Source/Graphics/Font.h @@ -15,7 +15,7 @@ */ #pragma once -#include +#include #include #include @@ -36,7 +36,8 @@ public: virtual ~Font(); bool initialize(); void deInitialize(); - SDL_Texture *getTexture(); + //SDL_Texture *getTexture(); + SDL_Surface *getTexture(); bool getRect(unsigned int charCode, GlyphInfo &glyph); int getHeight(); int getAscent(); @@ -48,7 +49,8 @@ private: SDL_Surface *surface; }; - SDL_Texture *texture; + //SDL_Texture *texture; + SDL_Surface *texture; int height; int ascent; std::map atlas; diff --git a/RetroFE/Source/Graphics/FontCache.cpp b/RetroFE/Source/Graphics/FontCache.cpp index ae9432d..b45e8df 100644 --- a/RetroFE/Source/Graphics/FontCache.cpp +++ b/RetroFE/Source/Graphics/FontCache.cpp @@ -18,7 +18,7 @@ #include "Font.h" #include "../Utility/Log.h" #include "../SDL.h" -#include +#include #include //todo: memory leak when launching games diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index c36d559..198fb55 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -63,7 +63,7 @@ PageBuilder::PageBuilder(std::string layoutKey, std::string layoutPage, Configur { screenWidth_ = SDL::getWindowWidth(); screenHeight_ = SDL::getWindowHeight(); - fontColor_.a = 255; + //fontColor_.a = 255; fontColor_.r = 0; fontColor_.g = 0; fontColor_.b = 0; diff --git a/RetroFE/Source/Graphics/PageBuilder.h b/RetroFE/Source/Graphics/PageBuilder.h index 87451fd..a9086fd 100644 --- a/RetroFE/Source/Graphics/PageBuilder.h +++ b/RetroFE/Source/Graphics/PageBuilder.h @@ -17,8 +17,8 @@ #include "Component/Image.h" #include "FontCache.h" -#include -#include +#include +#include #include #include diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 8bbbf95..720e7c5 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #if defined(__linux) || defined(__APPLE__) #include @@ -50,10 +50,15 @@ #ifdef WIN32 #include -#include -#include +#include +#include #endif +#define REMOVE_TEST_FUNKEY +#define FUNKEY_ALL_POLLEVENT_DELAY 30 //ms + +#define FPS 30 // TODO: set in conf file + RetroFE::RetroFE( Configuration &c ) : initialized(false) @@ -85,15 +90,19 @@ void RetroFE::render( ) { SDL_LockMutex( SDL::getMutex( ) ); - SDL_SetRenderDrawColor( SDL::getRenderer( ), 0x0, 0x0, 0x00, 0xFF ); - SDL_RenderClear( SDL::getRenderer( ) ); + //SDL_SetRenderDrawColor( SDL::getRenderer( ), 0x0, 0x0, 0x00, 0xFF ); + //SDL_RenderClear( SDL::getRenderer( ) ); + SDL_FillRect(SDL::getWindow( ), NULL, SDL_MapRGB(SDL::getWindow( )->format, 0, 0, 0)); if ( currentPage_ ) { currentPage_->draw( ); } - SDL_RenderPresent( SDL::getRenderer( ) ); + //SDL_RenderPresent( SDL::getRenderer( ) ); + //SDL_Flip(SDL::getWindow( )); + SDL::renderAndFlipWindow(); + SDL_UnlockMutex( SDL::getMutex( ) ); } @@ -143,7 +152,7 @@ void RetroFE::launchEnter( ) { // Disable window focus - SDL_SetWindowGrab(SDL::getWindow( ), SDL_FALSE); + //SDL_SetWindowGrab(SDL::getWindow( ), SDL_FALSE); // Free the textures, and optionally take down SDL freeGraphicsMemory( ); @@ -159,9 +168,9 @@ void RetroFE::launchExit( ) allocateGraphicsMemory( ); // Restore the SDL settings - SDL_RestoreWindow( SDL::getWindow( ) ); - SDL_RaiseWindow( SDL::getWindow( ) ); - SDL_SetWindowGrab( SDL::getWindow( ), SDL_TRUE ); + //SDL_RestoreWindow( SDL::getWindow( ) ); + //SDL_RaiseWindow( SDL::getWindow( ) ); + //SDL_SetWindowGrab( SDL::getWindow( ), SDL_TRUE ); // Empty event queue, but handle joystick add/remove events SDL_Event e; @@ -182,7 +191,7 @@ void RetroFE::launchExit( ) } -// Free the textures, and optionall take down SDL +// Free the textures, and optionally take down SDL void RetroFE::freeGraphicsMemory( ) { @@ -224,6 +233,7 @@ void RetroFE::allocateGraphicsMemory( ) currentPage_->allocateGraphicsMemory( ); } + } @@ -264,6 +274,118 @@ bool RetroFE::deInitialize( ) return retVal; } +// Print State +void RetroFE::printState(RETROFE_STATE state){ + switch(state){ + case RETROFE_IDLE: + printf("RETROFE_IDLE"); + break; + case RETROFE_LOAD_ART: + printf("RETROFE_LOAD_ART"); + break; + case RETROFE_ENTER: + printf("RETROFE_ENTER"); + break; + case RETROFE_SPLASH_EXIT: + printf("RETROFE_SPLASH_EXIT"); + break; + case RETROFE_PLAYLIST_REQUEST: + printf("RETROFE_PLAYLIST_REQUEST"); + break; + case RETROFE_PLAYLIST_EXIT: + printf("RETROFE_PLAYLIST_EXIT"); + break; + case RETROFE_PLAYLIST_LOAD_ART: + printf("RETROFE_PLAYLIST_LOAD_ART"); + break; + case RETROFE_PLAYLIST_ENTER: + printf("RETROFE_PLAYLIST_ENTER"); + break; + case RETROFE_MENUJUMP_REQUEST: + printf("RETROFE_MENUJUMP_REQUEST"); + break; + case RETROFE_MENUJUMP_EXIT: + printf("RETROFE_MENUJUMP_EXIT"); + break; + case RETROFE_MENUJUMP_LOAD_ART: + printf("RETROFE_MENUJUMP_LOAD_ART"); + break; + case RETROFE_MENUJUMP_ENTER: + printf("RETROFE_MENUJUMP_ENTER"); + break; + case RETROFE_HIGHLIGHT_REQUEST: + printf("RETROFE_HIGHLIGHT_REQUEST"); + break; + case RETROFE_HIGHLIGHT_EXIT: + printf("RETROFE_HIGHLIGHT_EXIT"); + break; + case RETROFE_HIGHLIGHT_LOAD_ART: + printf("RETROFE_HIGHLIGHT_LOAD_ART"); + break; + case RETROFE_HIGHLIGHT_ENTER: + printf("RETROFE_HIGHLIGHT_ENTER"); + break; + case RETROFE_NEXT_PAGE_REQUEST: + printf("RETROFE_NEXT_PAGE_REQUEST"); + break; + case RETROFE_NEXT_PAGE_MENU_EXIT: + printf("RETROFE_NEXT_PAGE_MENU_EXIT"); + break; + case RETROFE_NEXT_PAGE_MENU_LOAD_ART: + printf("RETROFE_NEXT_PAGE_MENU_LOAD_ART"); + break; + case RETROFE_NEXT_PAGE_MENU_ENTER: + printf("RETROFE_NEXT_PAGE_MENU_ENTER"); + break; + case RETROFE_HANDLE_MENUENTRY: + printf("RETROFE_HANDLE_MENUENTRY"); + break; + case RETROFE_LAUNCH_ENTER: + printf("RETROFE_LAUNCH_ENTER"); + break; + case RETROFE_LAUNCH_REQUEST: + printf("RETROFE_LAUNCH_REQUEST"); + break; + case RETROFE_LAUNCH_EXIT: + printf("RETROFE_LAUNCH_EXIT"); + break; + case RETROFE_BACK_REQUEST: + printf("RETROFE_BACK_REQUEST"); + break; + case RETROFE_BACK_MENU_EXIT: + printf("RETROFE_BACK_MENU_EXIT"); + break; + case RETROFE_BACK_MENU_LOAD_ART: + printf("RETROFE_BACK_MENU_LOAD_ART"); + break; + case RETROFE_BACK_MENU_ENTER: + printf("RETROFE_BACK_MENU_ENTER"); + break; + case RETROFE_MENUMODE_START_REQUEST: + printf("RETROFE_MENUMODE_START_REQUEST"); + break; + case RETROFE_MENUMODE_START_LOAD_ART: + printf("RETROFE_MENUMODE_START_LOAD_ART"); + break; + case RETROFE_MENUMODE_START_ENTER: + printf("RETROFE_MENUMODE_START_ENTER"); + break; + case RETROFE_NEW: + printf("RETROFE_NEW"); + break; + case RETROFE_QUIT_REQUEST: + printf("RETROFE_QUIT_REQUEST"); + break; + case RETROFE_QUIT: + printf("RETROFE_QUIT"); + break; + default: + printf("STATE UNDEFINED:%d", state); + break; + } + printf("\n"); +} + // Run RetroFE void RetroFE::run( ) @@ -293,7 +415,8 @@ void RetroFE::run( ) VideoFactory::createVideo( ); // pre-initialize the gstreamer engine Video::setEnabled( videoEnable ); - initializeThread = SDL_CreateThread( initialize, "RetroFEInit", (void *)this ); + //initializeThread = SDL_CreateThread( initialize, "RetroFEInit", (void *)this ); + initializeThread = SDL_CreateThread( initialize, (void *)this ); if ( !initializeThread ) { @@ -338,10 +461,12 @@ void RetroFE::run( ) exitSplashMode = true; while ( SDL_PollEvent( &e ) ) { +#ifndef REMOVE_TEST_FUNKEY if ( e.type == SDL_JOYDEVICEADDED || e.type == SDL_JOYDEVICEREMOVED ) { input_.update( e ); } +#endif } input_.resetStates( ); attract_.reset( ); @@ -355,6 +480,9 @@ void RetroFE::run( ) break; } + // Uncomment to print State for debug purposes + //printState(state); + switch(state) { @@ -800,7 +928,7 @@ void RetroFE::run( ) // Start menu mode case RETROFE_MENUMODE_START_REQUEST: - if ( currentPage_->isIdle( ) ) + /*if ( currentPage_->isIdle( ) ) { lastMenuOffsets_[currentPage_->getCollectionName( )] = currentPage_->getScrollOffsetIndex( ); lastMenuPlaylists_[currentPage_->getCollectionName( )] = currentPage_->getPlaylistName( ); @@ -822,11 +950,17 @@ void RetroFE::run( ) currentPage_->onNewItemSelected( ); currentPage_->reallocateMenuSpritePoints( ); state = RETROFE_MENUMODE_START_LOAD_ART; - } + }*/ + + /// Clear events + SDL_Event ev; + while ( SDL_PollEvent( &ev ) ); + input_.resetStates( ); + state = RETROFE_IDLE; break; case RETROFE_MENUMODE_START_LOAD_ART: - currentPage_->start(); + //currentPage_->start(); state = RETROFE_MENUMODE_START_ENTER; break; @@ -881,8 +1015,11 @@ void RetroFE::run( ) SDL_Delay( static_cast( sleepTime ) ); } + + // Handle current pages updates if ( currentPage_ ) { +#ifndef REMOVE_TEST_FUNKEY if (!splashMode) { attract_.update( deltaTime, *currentPage_ ); @@ -891,6 +1028,7 @@ void RetroFE::run( ) { attract_.reset( ); } +#endif currentPage_->update( deltaTime ); } @@ -932,9 +1070,14 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput( Page *page ) while ( SDL_PollEvent( &e ) ) { input_.update(e); - if ( e.type == SDL_KEYDOWN && !e.key.repeat ) + /*if ( e.type == SDL_KEYDOWN && !e.key.repeat ) { break; + }*/ + if ( e.type == SDL_KEYDOWN ) + { + //printf("e.key.keysym.sym = %d\n", e.key.keysym.sym); + break; } } @@ -1244,9 +1387,9 @@ CollectionInfo *RetroFE::getCollection(std::string collectionName) (void)config_.getProperty( "showParenthesis", showParenthesis ); (void)config_.getProperty( "showSquareBrackets", showSquareBrackets ); - typedef std::map *> Playlists_T; - for ( Playlists_T::iterator itP = collection->playlists.begin( ); itP != collection->playlists.end( ); itP++ ) - { + typedef std::map *> Playlists_T; + for ( Playlists_T::iterator itP = collection->playlists.begin( ); itP != collection->playlists.end( ); itP++ ) + { for ( std::vector ::iterator itI = itP->second->begin( ); itI != itP->second->end( ); itI++ ) { if ( !showParenthesis ) diff --git a/RetroFE/Source/RetroFE.h b/RetroFE/Source/RetroFE.h index 800c8c7..1e71cea 100644 --- a/RetroFE/Source/RetroFE.h +++ b/RetroFE/Source/RetroFE.h @@ -24,8 +24,8 @@ #include "Graphics/FontCache.h" #include "Video/IVideo.h" #include "Video/VideoFactory.h" -#include -#include +#include +#include #include #include #include @@ -103,6 +103,7 @@ private: void update( float dt, bool scrollActive ); CollectionInfo *getCollection( std::string collectionName ); CollectionInfo *getMenuCollection( std::string collectionName ); + void printState(RETROFE_STATE state); Configuration &config_; DB *db_; diff --git a/RetroFE/Source/SDL.cpp b/RetroFE/Source/SDL.cpp index 6dceb05..84065ef 100644 --- a/RetroFE/Source/SDL.cpp +++ b/RetroFE/Source/SDL.cpp @@ -18,17 +18,23 @@ #include "SDL.h" #include "Database/Configuration.h" #include "Utility/Log.h" -#include +#include +//#include +#include -SDL_Window *SDL::window_ = NULL; -SDL_Renderer *SDL::renderer_ = NULL; +//SDL_Window *SDL::window_ = NULL; +//SDL_Renderer *SDL::renderer_ = NULL; +SDL_Surface *SDL::window_ = NULL; +SDL_Surface *SDL::window_virtual_ = NULL; +SDL_Surface *SDL::texture_copy_alpha_ = NULL; SDL_mutex *SDL::mutex_ = NULL; int SDL::displayWidth_ = 0; int SDL::displayHeight_ = 0; int SDL::windowWidth_ = 0; int SDL::windowHeight_ = 0; bool SDL::fullscreen_ = false; +bool SDL::showFrame_ = true; // Initialize SDL @@ -38,12 +44,13 @@ bool SDL::initialize( Configuration &config ) bool retVal = true; std::string hString; std::string vString; - Uint32 windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS; + Uint32 windowFlags = SDL_HWSURFACE | SDL_DOUBLEBUF; int audioRate = MIX_DEFAULT_FREQUENCY; Uint16 audioFormat = MIX_DEFAULT_FORMAT; /* 16-bit stereo */ int audioChannels = 1; int audioBuffers = 4096; bool hideMouse; + const SDL_VideoInfo* videoInfo; Logger::write( Logger::ZONE_INFO, "SDL", "Initializing" ); if (retVal && SDL_Init( SDL_INIT_EVERYTHING ) != 0) @@ -68,16 +75,16 @@ bool SDL::initialize( Configuration &config ) // check for a few other necessary Configurations if ( retVal ) { - // Get current display mode of all displays. - for(int i = 0; i < SDL_GetNumVideoDisplays( ); ++i) + // Get current screen resolution + videoInfo = SDL_GetVideoInfo(); + if (videoInfo == NULL) { - SDL_DisplayMode mode; - if ( SDL_GetCurrentDisplayMode( i, &mode ) == 0 ) - { - displayWidth_ = mode.w; - displayHeight_ = mode.h; - break; - } + Logger::write( Logger::ZONE_ERROR, "SDL", "SDL_GetVideoInfo failed"); + retVal = false; + } + else{ + displayWidth_ = videoInfo->current_w; + displayHeight_ = videoInfo->current_h; } if ( !config.getProperty( "horizontal", hString ) ) @@ -87,16 +94,7 @@ bool SDL::initialize( Configuration &config ) } else if ( hString == "stretch" ) { - // Get current display mode of all displays. - for(int i = 0; i < SDL_GetNumVideoDisplays( ); ++i) - { - SDL_DisplayMode mode; - if ( SDL_GetCurrentDisplayMode( i, &mode ) == 0 ) - { - windowWidth_ = mode.w; - break; - } - } + windowWidth_ = displayWidth_; } else if ( !config.getProperty( "horizontal", windowWidth_ ) ) { @@ -113,16 +111,7 @@ bool SDL::initialize( Configuration &config ) } else if ( vString == "stretch" ) { - // Get current display mode of all displays. - for(int i = 0; i < SDL_GetNumVideoDisplays( ); ++i) - { - SDL_DisplayMode mode; - if ( SDL_GetDesktopDisplayMode( i, &mode ) == 0 ) - { - windowHeight_ = mode.h; - break; - } - } + windowHeight_ = displayHeight_; } else if ( !config.getProperty( "vertical", windowHeight_ ) ) { @@ -138,11 +127,18 @@ bool SDL::initialize( Configuration &config ) if (retVal && fullscreen_) { -#ifdef WIN32 - windowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP; -#else - windowFlags |= SDL_WINDOW_FULLSCREEN; -#endif + windowFlags |= SDL_FULLSCREEN; + } + + if ( retVal && !config.getProperty( "showFrame", showFrame_ ) ) + { + Logger::write( Logger::ZONE_ERROR, "Configuration", "Missing property: \"showFrame\"" ); + retVal = false; + } + + if (retVal && !showFrame_) + { + windowFlags |= SDL_NOFRAME; } if ( retVal ) @@ -153,17 +149,49 @@ bool SDL::initialize( Configuration &config ) Logger::write( Logger::ZONE_INFO, "SDL", ss.str( )); - window_ = SDL_CreateWindow( "RetroFE", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth_, windowHeight_, windowFlags ); - + window_ = SDL_SetVideoMode(windowWidth_, windowHeight_, 32, windowFlags); if ( window_ == NULL ) { std::string error = SDL_GetError( ); - Logger::write( Logger::ZONE_ERROR, "SDL", "Create window failed: " + error ); + Logger::write( Logger::ZONE_ERROR, "SDL", "SDL_SetVideoMode failed: " + error ); retVal = false; } - } - if ( retVal ) + unsigned int rmask; + unsigned int gmask; + unsigned int bmask; + unsigned int amask; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif + window_virtual_ = SDL_CreateRGBSurface(0, windowWidth_, windowHeight_, 32, 0,0,0,0); + //window_virtual_ = SDL_CreateRGBSurface(0, windowWidth_, windowHeight_, 32, rmask, gmask, bmask, amask); // colors are reversed with this ! + if ( window_virtual_ == NULL ) + { + std::string error = SDL_GetError( ); + Logger::write( Logger::ZONE_ERROR, "SDL", "SDL_CreateRGBSurface window_virtual_ failed: " + error ); + retVal = false; + } + SDL_FillRect(window_virtual_, NULL, SDL_MapRGBA(window_virtual_->format, 0, 0, 0, 0)); + + texture_copy_alpha_ = SDL_CreateRGBSurface(0, windowWidth_, windowHeight_, 32, rmask, gmask, bmask, amask); + if ( texture_copy_alpha_ == NULL ) + { + std::string error = SDL_GetError( ); + Logger::write( Logger::ZONE_ERROR, "SDL", "SDL_CreateRGBSurface texture_copy_alpha_ failed: " + error ); + retVal = false; + } + SDL_FillRect(texture_copy_alpha_, NULL, SDL_MapRGBA(texture_copy_alpha_->format, 0, 0, 0, 0)); + } + /*if ( retVal ) { renderer_ = SDL_CreateRenderer( window_, -1, SDL_RENDERER_ACCELERATED ); @@ -173,14 +201,14 @@ bool SDL::initialize( Configuration &config ) Logger::write( Logger::ZONE_ERROR, "SDL", "Create renderer failed: " + error ); retVal = false; } - } + }*/ - if ( SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1") != SDL_TRUE ) + /*if ( SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1") != SDL_TRUE ) { Logger::write( Logger::ZONE_ERROR, "SDL", "Improve scale quality. Continuing with low-quality settings." ); - } + }*/ - bool minimize_on_focus_loss_; + /*bool minimize_on_focus_loss_; if ( config.getProperty( "minimize_on_focus_loss", minimize_on_focus_loss_ ) ) { if ( minimize_on_focus_loss_ ) @@ -191,7 +219,7 @@ bool SDL::initialize( Configuration &config ) { SDL_SetHintWithPriority( SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0", SDL_HINT_OVERRIDE ); } - } + }*/ if ( retVal ) { @@ -231,16 +259,22 @@ bool SDL::deInitialize( ) mutex_ = NULL; } - if ( renderer_ ) + /*if ( renderer_ ) { SDL_DestroyRenderer(renderer_); renderer_ = NULL; + }*/ + + if ( window_virtual_ ) + { + SDL_FreeSurface(window_virtual_); + window_virtual_ = NULL; } - if ( window_ ) + if ( texture_copy_alpha_ ) { - SDL_DestroyWindow(window_); - window_ = NULL; + SDL_FreeSurface(texture_copy_alpha_); + texture_copy_alpha_ = NULL; } SDL_ShowCursor( SDL_TRUE ); @@ -252,10 +286,10 @@ bool SDL::deInitialize( ) // Get the renderer -SDL_Renderer* SDL::getRenderer( ) +/*SDL_Renderer* SDL::getRenderer( ) { return renderer_; -} +}*/ // Get the mutex @@ -266,14 +300,158 @@ SDL_mutex* SDL::getMutex( ) // Get the window -SDL_Window* SDL::getWindow( ) +SDL_Surface* SDL::getWindow( ) +{ + //return window_; + return window_virtual_; +} +/*SDL_Window* SDL::getWindow( ) { return window_; +}*/ + + + + + + +void SDL::SDL_Rotate_270(SDL_Surface * dst, SDL_Surface * src){ + int i, j; + uint32_t *source_pixels = (uint32_t*) src->pixels; + uint32_t *dest_pixels = (uint32_t*) dst->pixels; + + /// --- Checking for right pixel format --- + //MENU_DEBUG_PRINTF("Source bpb = %d, Dest bpb = %d\n", src->format->BitsPerPixel, dst->format->BitsPerPixel); + if(src->format->BitsPerPixel != 32){ + printf("Error in SDL_Rotate_270, Wrong virtual_hw_surface pixel format: %d bpb, expected: uint32_t bpb\n", src->format->BitsPerPixel); + return; +} + if(dst->format->BitsPerPixel != 32){ + printf("Error in SDL_Rotate_270, Wrong hw_surface pixel format: %d bpb, expected: uint32_t bpb\n", dst->format->BitsPerPixel); + return; + } + + /// --- Checking if same dimensions --- + if(dst->w != src->w || dst->h != src->h){ + printf("Error in SDL_Rotate_270, hw_surface (%dx%d) and virtual_hw_surface (%dx%d) have different dimensions\n", + dst->w, dst->h, src->w, src->h); + return; + } + + /// --- Pixel copy and rotation (270) --- + uint32_t *cur_p_src, *cur_p_dst; + for(i=0; ih; i++){ + for(j=0; jw; j++){ + cur_p_src = source_pixels + i*src->w + j; + cur_p_dst = dest_pixels + (dst->h-1-j)*dst->w + i; + *cur_p_dst = *cur_p_src; + } + } } +// Copy virtual window to HW window and Flip display +void SDL::renderAndFlipWindow( ) +{ + //SDL_BlitSurface(window_virtual_, NULL, window_, NULL); + SDL_Rotate_270(window_, window_virtual_); + + SDL_Flip(window_); +} + + + +Uint32 SDL::get_pixel32( SDL_Surface *surface, int x, int y ) +{ + //Convert the pixels to 32 bit + Uint32 *pixels = (Uint32 *)surface->pixels; + + //Get the requested pixel + return pixels[ ( y * surface->w ) + x ]; +} + +void SDL::put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel ) +{ + //Convert the pixels to 32 bit + Uint32 *pixels = (Uint32 *)surface->pixels; + + //Set the pixel + pixels[ ( y * surface->w ) + x ] = pixel; +} + + +// Flip a surface +SDL_Surface * SDL::flip_surface( SDL_Surface *surface, int flags ) +{ + //Pointer to the soon to be flipped surface + SDL_Surface *flipped = NULL; + + //If the image is color keyed + if( surface->flags & SDL_SRCCOLORKEY ) + { + flipped = SDL_CreateRGBSurface( SDL_SWSURFACE, surface->w, surface->h, surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, 0 ); + } + //Otherwise + else + { + flipped = SDL_CreateRGBSurface( SDL_SWSURFACE, surface->w, surface->h, surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask ); + } + + //If the surface must be locked + if( SDL_MUSTLOCK( surface ) ) + { + //Lock the surface + SDL_LockSurface( surface ); + } + + //Go through columns + for( int x = 0, rx = flipped->w - 1; x < flipped->w; x++, rx-- ) + { + //Go through rows + for( int y = 0, ry = flipped->h - 1; y < flipped->h; y++, ry-- ) + { + //Get pixel + Uint32 pixel = get_pixel32( surface, x, y ); + + //Copy pixel + if( ( flags & FLIP_VERTICAL ) && ( flags & FLIP_HORIZONTAL ) ) + { + put_pixel32( flipped, rx, ry, pixel ); + } + else if( flags & FLIP_HORIZONTAL ) + { + put_pixel32( flipped, rx, y, pixel ); + } + else if( flags & FLIP_VERTICAL ) + { + put_pixel32( flipped, x, ry, pixel ); + } + } + } + + //Unlock surface + if( SDL_MUSTLOCK( surface ) ) + { + SDL_UnlockSurface( surface ); + } + + //Copy color key + if( surface->flags & SDL_SRCCOLORKEY ) + { + SDL_SetColorKey( flipped, SDL_RLEACCEL | SDL_SRCCOLORKEY, surface->format->colorkey ); + } + + //Return flipped surface + return flipped; +} + + + + + // Render a copy of a texture -bool SDL::renderCopy( SDL_Texture *texture, float alpha, SDL_Rect *src, SDL_Rect *dest, ViewInfo &viewInfo ) +/*bool SDL::renderCopy( SDL_Texture *texture, float alpha, SDL_Rect *src, SDL_Rect *dest, ViewInfo &viewInfo )*/ +bool SDL::renderCopy( SDL_Surface *texture, float alpha, SDL_Rect *src, SDL_Rect *dest, ViewInfo &viewInfo ) { SDL_Rect srcRect; @@ -309,11 +487,13 @@ bool SDL::renderCopy( SDL_Texture *texture, float alpha, SDL_Rect *src, SDL_Rect { srcRect.x = 0; srcRect.y = 0; - int w = 0; + /*int w = 0; int h = 0; SDL_QueryTexture(texture, NULL, NULL, &w, &h); srcRect.w = w; - srcRect.h = h; + srcRect.h = h;*/ + srcRect.w = texture->w; + srcRect.h = texture->h; } // Define the scale @@ -369,40 +549,111 @@ bool SDL::renderCopy( SDL_Texture *texture, float alpha, SDL_Rect *src, SDL_Rect } - SDL_SetTextureAlphaMod( texture, static_cast( alpha * 255 ) ); - SDL_RenderCopyEx( getRenderer( ), texture, &srcRect, &dstRect, viewInfo.Angle, NULL, SDL_FLIP_NONE ); + //printf("scaleX : %d, scale Y:%d\n", scaleX, scaleY); + //SDL_SetTextureAlphaMod( texture, static_cast( alpha * 255 ) ); + //SDL_RenderCopyEx( getRenderer( ), texture, &srcRect, &dstRect, viewInfo.Angle, NULL, SDL_FLIP_NONE ); - if ( viewInfo.Reflection == "top" ) + + /*if(texture->format->Amask){ + SDL_SetAlpha( texture, 0, SDL_ALPHA_OPAQUE ); + SDL_BlitSurface (texture, &srcRect, texture_copy_alpha_, &dstRect); + SDL_gfxMultiplyAlpha (texture_copy_alpha_, static_cast( alpha * 255 )); + SDL_BlitSurface (texture_copy_alpha_, &dstRect, getWindow(), &dstRect); + } + else{ + //SDL_SetAlpha(texture, SDL_SRCALPHA, static_cast( alpha * 255 )); + SDL_gfxSetAlpha(texture, static_cast( alpha * 255 )); + SDL_BlitSurface (texture, &srcRect, getWindow(), &dstRect); + }*/ + + /*SDL_SetAlpha(texture, SDL_SRCALPHA, static_cast( alpha * 255 )); + SDL_BlitSurface (texture, &srcRect, getWindow(), &dstRect);*/ + + + unsigned int rmask; + unsigned int gmask; + unsigned int bmask; + unsigned int amask; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif + SDL_Surface * texture_tmp = SDL_CreateRGBSurface(0, texture->w, texture->h, 32, rmask, gmask, bmask, amask); + //SDL_FillRect(texture_tmp, NULL, SDL_MapRGBA(texture_tmp->format, 0, 0, 0, 0)); + SDL_SetAlpha( texture, 0, SDL_ALPHA_OPAQUE ); + SDL_BlitSurface (texture, NULL, texture_tmp, NULL); + SDL_gfxMultiplyAlpha (texture_tmp, static_cast( alpha * 255 )); + //SDL_gfxBlitRGBA(texture_tmp, &srcRect, getWindow(), &dstRect); + SDL_BlitSurface(texture_tmp, &srcRect, getWindow(), &dstRect); + SDL_FreeSurface(texture_tmp); + + + //texture = rotozoomSurfaceXY(texture, viewInfo.Angle, scaleX, scaleY, SMOOTHING_OFF); + //texture = rotozoomSurfaceXY(texture, viewInfo.Angle, 0.5, 0.5, SMOOTHING_OFF); + //double scale_x = 240/1920; + //double scale_y = 240/1080; + //texture = rotozoomSurfaceXY(texture, 0, 0.5, 0.6, SMOOTHING_ON); + + /*if ( viewInfo.Reflection == "top" ) { dstRect.h = static_cast( static_cast(dstRect.h ) * viewInfo.ReflectionScale); dstRect.y = dstRect.y - dstRect.h - viewInfo.ReflectionDistance; - SDL_SetTextureAlphaMod( texture, static_cast( viewInfo.ReflectionAlpha * alpha * 255 ) ); - SDL_RenderCopyEx( getRenderer( ), texture, src, &dstRect, viewInfo.Angle, NULL, SDL_FLIP_VERTICAL ); - } + //SDL_SetTextureAlphaMod( texture, static_cast( viewInfo.ReflectionAlpha * alpha * 255 ) ); + //SDL_RenderCopyEx( getRenderer( ), texture, src, &dstRect, viewInfo.Angle, NULL, SDL_FLIP_VERTICAL ); - if ( viewInfo.Reflection == "bottom" ) + //texture = rotozoomSurfaceXY(texture, viewInfo.Angle, scaleX, scaleY, SMOOTHING_ON); + + + SDL_SetAlpha( texture, 0, SDL_ALPHA_OPAQUE ); + SDL_BlitSurface (texture, &srcRect, texture_copy_alpha_, &dstRect); + texture_copy_alpha_ = flip_surface(texture_copy_alpha_, FLIP_VERTICAL); + SDL_gfxMultiplyAlpha (texture_copy_alpha_, static_cast( alpha * 255 )); + SDL_BlitSurface (texture_copy_alpha_, &dstRect, getWindow(), &dstRect); + }*/ + + /*if ( viewInfo.Reflection == "bottom" ) { dstRect.y = dstRect.y + dstRect.h + viewInfo.ReflectionDistance; dstRect.h = static_cast( static_cast(dstRect.h ) * viewInfo.ReflectionScale); - SDL_SetTextureAlphaMod( texture, static_cast( viewInfo.ReflectionAlpha * alpha * 255 ) ); - SDL_RenderCopyEx( getRenderer( ), texture, src, &dstRect, viewInfo.Angle, NULL, SDL_FLIP_VERTICAL ); + //SDL_SetTextureAlphaMod( texture, static_cast( viewInfo.ReflectionAlpha * alpha * 255 ) ); + //SDL_RenderCopyEx( getRenderer( ), texture, src, &dstRect, viewInfo.Angle, NULL, SDL_FLIP_VERTICAL ); + SDL_SetAlpha(texture, SDL_SRCALPHA, static_cast( alpha * 255 )); + //texture = flip_surface(texture, FLIP_VERTICAL); + //texture = rotozoomSurfaceXY(texture, viewInfo.Angle, scaleX, scaleY, SMOOTHING_ON); + SDL_BlitSurface(texture, src, getWindow(), &dstRect); } if ( viewInfo.Reflection == "left" ) { dstRect.w = static_cast( static_cast(dstRect.w ) * viewInfo.ReflectionScale); dstRect.x = dstRect.x - dstRect.w - viewInfo.ReflectionDistance; - SDL_SetTextureAlphaMod( texture, static_cast( viewInfo.ReflectionAlpha * alpha * 255 ) ); - SDL_RenderCopyEx( getRenderer( ), texture, src, &dstRect, viewInfo.Angle, NULL, SDL_FLIP_HORIZONTAL ); + //SDL_SetTextureAlphaMod( texture, static_cast( viewInfo.ReflectionAlpha * alpha * 255 ) ); + //SDL_RenderCopyEx( getRenderer( ), texture, src, &dstRect, viewInfo.Angle, NULL, SDL_FLIP_HORIZONTAL ); + SDL_SetAlpha(texture, SDL_SRCALPHA, static_cast( alpha * 255 )); + //texture = flip_surface(texture, FLIP_HORIZONTAL); + //texture = rotozoomSurfaceXY(texture, viewInfo.Angle, scaleX, scaleY, SMOOTHING_ON); + SDL_BlitSurface(texture, src, getWindow(), &dstRect); } if ( viewInfo.Reflection == "right" ) { dstRect.x = dstRect.x + dstRect.w + viewInfo.ReflectionDistance; dstRect.w = static_cast( static_cast(dstRect.w ) * viewInfo.ReflectionScale); - SDL_SetTextureAlphaMod( texture, static_cast( viewInfo.ReflectionAlpha * alpha * 255 ) ); - SDL_RenderCopyEx( getRenderer( ), texture, src, &dstRect, viewInfo.Angle, NULL, SDL_FLIP_HORIZONTAL ); - } + //SDL_SetTextureAlphaMod( texture, static_cast( viewInfo.ReflectionAlpha * alpha * 255 ) ); + //SDL_RenderCopyEx( getRenderer( ), texture, src, &dstRect, viewInfo.Angle, NULL, SDL_FLIP_HORIZONTAL ); + SDL_SetAlpha(texture, SDL_SRCALPHA, static_cast( alpha * 255 )); + //texture = flip_surface(texture, FLIP_HORIZONTAL); + //texture = rotozoomSurfaceXY(texture, viewInfo.Angle, scaleX, scaleY, SMOOTHING_ON); + SDL_BlitSurface(texture, src, getWindow(), &dstRect); + }*/ return true; } + diff --git a/RetroFE/Source/SDL.h b/RetroFE/Source/SDL.h index 033692e..6bd5367 100644 --- a/RetroFE/Source/SDL.h +++ b/RetroFE/Source/SDL.h @@ -16,10 +16,14 @@ #pragma once -#include +//#include +#include #include #include "Graphics/ViewInfo.h" +//Flip flags +#define FLIP_VERTICAL 1 +#define FLIP_HORIZONTAL 2 class Configuration; @@ -29,10 +33,13 @@ class SDL public: static bool initialize( Configuration &config ); static bool deInitialize( ); - static SDL_Renderer *getRenderer( ); + //static SDL_Renderer *getRenderer( ); static SDL_mutex *getMutex( ); - static SDL_Window *getWindow( ); - static bool renderCopy( SDL_Texture *texture, float alpha, SDL_Rect *src, SDL_Rect *dest, ViewInfo &viewInfo ); + //static SDL_Window *getWindow( ); + static SDL_Surface *getWindow( ); + static void renderAndFlipWindow( ); + //static bool renderCopy( SDL_Texture *texture, float alpha, SDL_Rect *src, SDL_Rect *dest, ViewInfo &viewInfo ); + static bool renderCopy( SDL_Surface *texture, float alpha, SDL_Rect *src, SDL_Rect *dest, ViewInfo &viewInfo ); static int getWindowWidth( ) { return windowWidth_; @@ -45,14 +52,23 @@ public: { return fullscreen_; } + static void SDL_Rotate_270(SDL_Surface * dst, SDL_Surface * src); private: - static SDL_Window *window_; - static SDL_Renderer *renderer_; + //static SDL_Window *window_; + //static SDL_Renderer *renderer_; + static Uint32 get_pixel32( SDL_Surface *surface, int x, int y ); + static void put_pixel32( SDL_Surface *surface, int x, int y, Uint32 pixel ); + static SDL_Surface * flip_surface( SDL_Surface *surface, int flags ); + static SDL_Surface *window_; + static SDL_Surface *window_virtual_; + static SDL_Surface *texture_copy_alpha_; static SDL_mutex *mutex_; static int displayWidth_; static int displayHeight_; static int windowWidth_; static int windowHeight_; static bool fullscreen_; + static bool showFrame_; }; + diff --git a/RetroFE/Source/Sound/Sound.h b/RetroFE/Source/Sound/Sound.h index 140c0c3..57e3eb5 100644 --- a/RetroFE/Source/Sound/Sound.h +++ b/RetroFE/Source/Sound/Sound.h @@ -16,7 +16,7 @@ #pragma once #include -#include +#include class Sound { public: diff --git a/RetroFE/Source/Utility/Utils.cpp b/RetroFE/Source/Utility/Utils.cpp index 3049966..45ef150 100644 --- a/RetroFE/Source/Utility/Utils.cpp +++ b/RetroFE/Source/Utility/Utils.cpp @@ -23,6 +23,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include Utils::Utils() @@ -253,3 +260,30 @@ std::string Utils::trimEnds(std::string str) return str; } +int Utils::termfix(uint32_t ttyId){ + // Init tty file path + char ttyFilePath[100]; + sprintf(ttyFilePath, "/dev/tty%d", ttyId); + + // Open tty + int fd = open(ttyFilePath, O_RDWR, 0); + + // Unlock virtual terminal + int res = ioctl(fd, VT_UNLOCKSWITCH, 1); + if(res != 0) + { + printf("ioctl VT_UNLOCKSWITCH failed"); + return res; + } + + // Set Virtual terminal mode text (not graphical) + ioctl(fd, KDSETMODE, KD_TEXT); + if(res != 0) + { + printf("ioctl KDSETMODE failed"); + return res; + } + + //printf("Success\n"); + return res; +} diff --git a/RetroFE/Source/Utility/Utils.h b/RetroFE/Source/Utility/Utils.h index a66e8f3..f83e381 100644 --- a/RetroFE/Source/Utility/Utils.h +++ b/RetroFE/Source/Utility/Utils.h @@ -18,6 +18,7 @@ #include #include #include +#include class Utils { public: @@ -42,6 +43,8 @@ public: static std::string combinePath(std::string path1, std::string path2, std::string path3); static std::string combinePath(std::string path1, std::string path2, std::string path3, std::string path4); static std::string combinePath(std::string path1, std::string path2, std::string path3, std::string path4, std::string path5); + + static int termfix(uint32_t ttyId); #ifdef WIN32 static const char pathSeparator = '\\'; diff --git a/RetroFE/Source/Video/GStreamerVideo.cpp b/RetroFE/Source/Video/GStreamerVideo.cpp index eb39d61..0d8d3b5 100644 --- a/RetroFE/Source/Video/GStreamerVideo.cpp +++ b/RetroFE/Source/Video/GStreamerVideo.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -48,7 +48,7 @@ GStreamerVideo::GStreamerVideo() , videoConvert_(NULL) , videoConvertCaps_(NULL) , videoBus_(NULL) - , texture_(NULL) + //, texture_(NULL) , height_(0) , width_(0) , videoBuffer_(NULL) @@ -68,11 +68,11 @@ GStreamerVideo::~GStreamerVideo() videoBuffer_ = NULL; } - if (texture_) + /*if (texture_) { SDL_DestroyTexture(texture_); texture_ = NULL; - } + }*/ freeElements(); } @@ -82,10 +82,10 @@ void GStreamerVideo::setNumLoops(int n) numLoops_ = n; } -SDL_Texture *GStreamerVideo::getTexture() const +/*SDL_Texture *GStreamerVideo::getTexture() const { return texture_; -} +}*/ void GStreamerVideo::processNewBuffer (GstElement * /* fakesink */, GstBuffer *buf, GstPad *new_pad, gpointer userdata) { @@ -158,11 +158,11 @@ bool GStreamerVideo::stop() (void)gst_element_set_state(playbin_, GST_STATE_NULL); } - if(texture_) + /*if(texture_) { SDL_DestroyTexture(texture_); texture_ = NULL; - } + }*/ if(videoBuffer_) { @@ -341,12 +341,12 @@ void GStreamerVideo::draw() void GStreamerVideo::update(float /* dt */) { SDL_LockMutex(SDL::getMutex()); - if(!texture_ && width_ != 0 && height_ != 0) + /*if(!texture_ && width_ != 0 && height_ != 0) { texture_ = SDL_CreateTexture(SDL::getRenderer(), SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, width_, height_); SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND); - } + }*/ if(videoBuffer_) { @@ -364,9 +364,9 @@ void GStreamerVideo::update(float /* dt */) if (bufSize == vbytes) { - SDL_LockTexture(texture_, NULL, &pixels, &pitch); + //SDL_LockTexture(texture_, NULL, &pixels, &pitch); gst_buffer_extract(videoBuffer_, 0, pixels, vbytes); - SDL_UnlockTexture(texture_); + //SDL_UnlockTexture(texture_); } else { @@ -382,10 +382,10 @@ void GStreamerVideo::update(float /* dt */) y_plane = bufInfo.data; u_plane = y_plane + (height_ * y_stride); v_plane = u_plane + ((height_ / 2) * u_stride); - SDL_UpdateYUVTexture(texture_, NULL, + /*SDL_UpdateYUVTexture(texture_, NULL, (const Uint8*)y_plane, y_stride, (const Uint8*)u_plane, u_stride, - (const Uint8*)v_plane, v_stride); + (const Uint8*)v_plane, v_stride);*/ gst_buffer_unmap(videoBuffer_, &bufInfo); } } @@ -398,10 +398,10 @@ void GStreamerVideo::update(float /* dt */) gst_video_meta_map(meta, 0, &y_info, &y_plane, &y_stride, GST_MAP_READ); gst_video_meta_map(meta, 1, &u_info, &u_plane, &u_stride, GST_MAP_READ); gst_video_meta_map(meta, 2, &v_info, &v_plane, &v_stride, GST_MAP_READ); - SDL_UpdateYUVTexture(texture_, NULL, + /*SDL_UpdateYUVTexture(texture_, NULL, (const Uint8*)y_plane, y_stride, (const Uint8*)u_plane, u_stride, - (const Uint8*)v_plane, v_stride); + (const Uint8*)v_plane, v_stride);*/ gst_video_meta_unmap(meta, 0, &y_info); gst_video_meta_unmap(meta, 1, &u_info); gst_video_meta_unmap(meta, 2, &v_info); diff --git a/RetroFE/Source/Video/GStreamerVideo.h b/RetroFE/Source/Video/GStreamerVideo.h index 3ac4579..12b8b50 100644 --- a/RetroFE/Source/Video/GStreamerVideo.h +++ b/RetroFE/Source/Video/GStreamerVideo.h @@ -33,7 +33,7 @@ public: bool play(std::string file); bool stop(); bool deInitialize(); - SDL_Texture *getTexture() const; + //SDL_Texture *getTexture() const; void update(float dt); void draw(); void setNumLoops(int n); @@ -52,7 +52,7 @@ private: GstElement *videoConvert_; GstCaps *videoConvertCaps_; GstBus *videoBus_; - SDL_Texture* texture_; + //SDL_Texture* texture_; gint height_; gint width_; GstBuffer *videoBuffer_; diff --git a/RetroFE/Source/Video/IVideo.h b/RetroFE/Source/Video/IVideo.h index c0417b7..0dc4eea 100644 --- a/RetroFE/Source/Video/IVideo.h +++ b/RetroFE/Source/Video/IVideo.h @@ -15,7 +15,7 @@ */ #pragma once -#include +#include #include class IVideo @@ -26,7 +26,7 @@ public: virtual bool play(std::string file) = 0; virtual bool stop() = 0; virtual bool deInitialize() = 0; - virtual SDL_Texture *getTexture() const = 0; + //virtual SDL_Texture *getTexture() const = 0; virtual void update(float dt) = 0; virtual void draw() = 0; virtual int getHeight() = 0;