pax_global_header00006660000000000000000000000064134157707550014530gustar00rootroot0000000000000052 comment=a6236c16ea486a5b22b61469815e653c248d9464 fifechan-0.1.5/000077500000000000000000000000001341577075500132765ustar00rootroot00000000000000fifechan-0.1.5/.gitignore000066400000000000000000000005041341577075500152650ustar00rootroot00000000000000*.la *.lo *.o *.pc *.so *.so* *.dylib .DS_Store .deps .libs Makefile Makefile.in build/ aclocal.m4 autom4te.cache/ config.guess config.log config.status config.sub configure depcomp include/config.hpp include/config.hpp.in include/stamp-h1 install-sh libtool ltmain.sh missing CMakeCache.txt CMakeFiles/ cmake_install.cmake fifechan-0.1.5/.mailmap000066400000000000000000000001211341577075500147110ustar00rootroot00000000000000Olof Næssén Thorbjørn Lindeijer fifechan-0.1.5/.travis.yml000066400000000000000000000073441341577075500154170ustar00rootroot00000000000000language: cpp compiler: clang os: - linux - osx dist: xenial git: depth: 5 addons: apt: sources: #- llvm-toolchain-xenial-7 packages: # 7z is used for packaging (see before_deploy) - p7zip-full - mesa-common-dev - libsdl2-dev - libsdl2-image-dev - libsdl2-ttf-dev - libfreetype6-dev #- clang-7.0 #- llvm-7.0-dev #- libclang-7.0-dev before_install: # change clang to version 5.0 #- if [ $TRAVIS_OS_NAME == linux ]; then sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-5.0 20; sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-5.0 20; fi #- if [ $TRAVIS_OS_NAME == linux ]; then sudo rm -f /usr/local/clang-3.9.0/bin/clang; sudo rm -f /usr/local/clang-3.9.0/bin/clang++; sudo update-alternatives --config clang; sudo update-alternatives --config clang++; fi - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get -qq update && sudo apt-get install -y libgle3-dev cppcheck; fi - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install sdl2 sdl2_image sdl2_ttf freetype; fi # build OGLFT - if [ $TRAVIS_OS_NAME == osx ]; then svn checkout https://svn.code.sf.net/p/oglft/code/trunk oglft-code; fi - if [ $TRAVIS_OS_NAME == osx ]; then cd oglft-code; fi # Patch CMakeLists.txt dont load shipped CMake Modul to load FreeType, its provided by CMake and able to find FreeType. - if [ $TRAVIS_OS_NAME == osx ]; then sed -i.bak '4d' CMakeLists.txt; fi # Also include Freetype - if [ $TRAVIS_OS_NAME == osx ]; then sed -i.bak -e '6a\'$'\n''if(FREETYPE_FOUND)' CMakeLists.txt; fi - if [ $TRAVIS_OS_NAME == osx ]; then sed -i.bak -e '7a\'$'\n''INCLUDE_DIRECTORIES(${FREETYPE_INCLUDE_DIRS})' CMakeLists.txt; fi - if [ $TRAVIS_OS_NAME == osx ]; then sed -i.bak -e '8a\'$'\n''endif(FREETYPE_FOUND)' CMakeLists.txt; fi # configure oglft - install into /usr folder - if [ $TRAVIS_OS_NAME == osx ]; then cmake -DCMAKE_CXX_FLAGS=-fPIC -DCMAKE_INSTALL_PREFIX=/usr/local . ; fi # make oglft - if [ $TRAVIS_OS_NAME == osx ]; then make -j3; fi # install oglft - if [ $TRAVIS_OS_NAME == osx ]; then sudo make install; fi - if [ $TRAVIS_OS_NAME == osx ]; then cd ..; fi script: # create folder for an out-of-source-tree build - mkdir _build # switch to build folder - cd _build # call cmake to configure the build env - if [ $TRAVIS_OS_NAME == linux ]; then cmake -DCMAKE_INSTALL_PREFIX=/fifechan ..; fi - if [ $TRAVIS_OS_NAME == osx ]; then cmake -DENABLE_SDL_CONTRIB=ON -DENABLE_OPENGL_CONTRIB=ON -DCMAKE_INSTALL_PREFIX=/fifechan ..; fi # finally, make - make -j3 VERBOSE=1 # then install - sudo make install after_script: # run cppcheck only on Linux - if [ $TRAVIS_OS_NAME == linux ]; then cd /home/travis/build/fifengine/fifechan; fi - if [ $TRAVIS_OS_NAME == linux ]; then cppcheck --verbose --enable=all --std=posix --std=c++11 --quiet -I include src; fi before_deploy: - sudo ls -alh /fifechan/* # let's package for Linux - if [ $TRAVIS_OS_NAME == linux ]; then 7z a -ttar -so fifechan.tar /fifechan/* | 7z a -si fifechan-$TRAVIS_TAG.tar.gz; fi # let's package for Mac - if [ $TRAVIS_OS_NAME == osx ]; then 7z a -ttar -so fifechan.tar /fifechan/* | 7z a -si fifechan-mac-$TRAVIS_TAG.tar.gz; fi deploy: provider: releases api_key: secure: "pWuM+6g5NjLo0mIyanHpNSWgs8f99fAqWb8ttY3YGNkiKWPmtTMZxktGdONp3dIOYykK8fHuCX2fuXNGhfv3wYllNAqbHgZ2Z6718q57xbjIplvJwdJ1+iAmmMGs1UDNyNLlMVr9y+hXzJLfIhd5/mp4+Wb3JqSDXtk+9ScV2JE=" file: fifechan*.tar.gz # wildcard for "fifechan-1.2.3.tar.gz" and "fifechan-mac-1.2.3.tar.gz" file_glob: true skip_cleanup: true overwrite: true on: tags: true notifications: irc: irc.freenode.org#fife email: false fifechan-0.1.5/AUTHORS000066400000000000000000000006151341577075500143500ustar00rootroot00000000000000Per Larsson finalman at gmail.com Olof Naessn olof.naessen at gmail.com prock wprasek at gmail.com vdaras vasileiosdaras at gmail.com Nicols Alvarez nicolas.alvarezi at gmail.com Karsten Bock KarstenBock at gmx.net Christopher Meng cickumqt at gmail.com helios2000 helios2000 at gmx.net stubb kiliankoeppchen at googlemail.com Jens A. Koch jakoch at web.de linuxdonald linuxdonald at posteo.de fifechan-0.1.5/CHANGELOG.md000066400000000000000000000057731341577075500151230ustar00rootroot00000000000000# ChangeLog ## [0.1.5] - 2019-01-11 - Added AT Key - Added Auto layouting - Fixed compile problems - Fixed some more bugs ## [0.1.4] - 2017-02-07 - Added mouse wheel left and right events - Fixed another possible segfault situation, issue #45 ## [0.1.3] - 2016-11-05 - Requires CMake 2.6.0 to use Freetype find_package function. Freetype is required by oglft. - Updated to SDL2 - Updated FPS demo for SDL2 - Bug fixes - travis build fixes - added Appveyor build configuration - added Auto layouting - fixes some possible segfaults - Enhanced modal focus handling - added a new logo ## [0.1.2] - 2014-08-10 - Added the possibility for horizontal scrolling. - Added isSetVisible() to the Widget class. It's very similar to isVisible() but ignores the parent. - Added GuiDeathListener. That should prevent crashes if the widget is hidden and removed on the same pump. - Added ${LIB_SUFFIX} for CMake lib path. Can be used via -DLIB_SUFFIX argument. - Fixed a segfault that could happen if the Widgets are destroyed after the Gui. ## [0.1.1] - 2014-02-23 - Correct CMake SDL_ttf module name by Christopher Meng - Setting the selected property of dropdowns to a value < 0 now will make them deselect the current item. - Fixed extensions not being built with the correct export definition. This will fix undefined references when linking with the created shared libraries. - Changed cmake options to enable contrib extensions for sdl and opengl to be OFF by default. - OGLFTFone is now compiled into fifechan. It can be enabled or disabled by setting the cmake option ENABLE_OPENGL_CONTRIB to ON or OFF. It is enabled by default. - Fixed SDLTrueTypeFont not included by CMake. It can be disabled by setting ENABLE_SDL_CONTRIB to OFF, which defaults to ON. - Add SDLIMAGE_INCLUDE_DIR to CMake by Nicolás Alvarez ## [0.1.0] - 2012-12-05 There are already some important bug fixes and new features such as: - A Widget is now able to detect that the mouse enters it when a Widget above it gets hidden and the mouse cursor was over it. - Text objects do not try to access rows if they are empty, which caused crashes before. - Widgets now distribute events if their ancestors where shown/hidden. - UTF8 support for TextBox and TextField widgets. - Work is done in a separate branch to support auto-layouting in fifechan. Needs to be improved and tested. - New widgets - Circular container, which implements a container that arranges its children in a circular fashion. (only available in the auto-layouting branch) - IconProgressBar, which implements a progressbar that uses images to show progress. - PasswordField, which implements password input. [Unreleased]: https://github.com/fifengine/fifechan/compare/0.1.3...HEAD [0.1.3]: https://github.com/fifengine/fifechan/compare/0.1.2...0.1.3 [0.1.2]: https://github.com/fifengine/fifechan/compare/0.1.1...0.1.2 [0.1.1]: https://github.com/fifengine/fifechan/compare/0.1.0...0.1.1 [0.1.0]: https://github.com/fifengine/fifechan/releases/tag/0.1.0 fifechan-0.1.5/CMake/000077500000000000000000000000001341577075500142565ustar00rootroot00000000000000fifechan-0.1.5/CMake/Modules/000077500000000000000000000000001341577075500156665ustar00rootroot00000000000000fifechan-0.1.5/CMake/Modules/FindAllegro.cmake000066400000000000000000000032711341577075500210610ustar00rootroot00000000000000# - Try to find Allegro # Once done this will define # # ALLEGRO_FOUND - system has Allegro # ALLEGRO_INCLUDE_DIRS - the Allegro include directory # ALLEGRO_LIBRARIES - Link these to use Allegro # ALLEGRO_DEFINITIONS - Compiler switches required for using Allegro # # Copyright (c) 2008 Olof Naessen # # Redistribution and use is allowed according to the terms of the New # BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. # if (ALLEGRO_LIBRARIES AND ALLEGRO_INCLUDE_DIRS) # in cache already set(ALLEGRO_FOUND TRUE) else (ALLEGRO_LIBRARIES AND ALLEGRO_INCLUDE_DIRS) find_path(ALLEGRO_INCLUDE_DIR NAMES allegro.h PATHS /usr/include /usr/local/include /opt/local/include /sw/include PATH_SUFFIXES allegro ) find_library(ALLEG_LIBRARY NAMES alleg PATHS /usr/lib /usr/local/lib /opt/local/lib /sw/lib ) set(ALLEGRO_INCLUDE_DIRS ${ALLEGRO_INCLUDE_DIR} ) set(ALLEGRO_LIBRARIES ${ALLEG_LIBRARY} ) if (ALLEGRO_INCLUDE_DIRS AND ALLEGRO_LIBRARIES) set(ALLEGRO_FOUND TRUE) endif (ALLEGRO_INCLUDE_DIRS AND ALLEGRO_LIBRARIES) if (ALLEGRO_FOUND) if (NOT Allegro_FIND_QUIETLY) message(STATUS "Found Allegro: ${ALLEGRO_LIBRARIES}") endif (NOT Allegro_FIND_QUIETLY) else (ALLEGRO_FOUND) if (Allegro_FIND_REQUIRED) message(FATAL_ERROR "Could not find Allegro") endif (Allegro_FIND_REQUIRED) endif (ALLEGRO_FOUND) # show the ALLEGRO_INCLUDE_DIRS and ALLEGRO_LIBRARIES variables only in the advanced view mark_as_advanced(ALLEGRO_INCLUDE_DIRS ALLEGRO_LIBRARIES) endif (ALLEGRO_LIBRARIES AND ALLEGRO_INCLUDE_DIRS) fifechan-0.1.5/CMake/Modules/FindIrrlicht.cmake000066400000000000000000000033131341577075500212510ustar00rootroot00000000000000# - Try to find Irrlicht # Once done this will define # # IRRLICHT_FOUND - system has Irrlicht # IRRLICHT_INCLUDE_DIRS - the Irrlicht include directory # IRRLICHT_LIBRARIES - Link these to use Irrlicht # IRRLICHT_DEFINITIONS - Compiler switches required for using Irrlicht # # Copyright (c) 2008 Olof Naessen # # Redistribution and use is allowed according to the terms of the New # BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. # if (IRRLICHT_LIBRARIES AND IRRLICHT_INCLUDE_DIRS) # in cache already set(IRRLICHT_FOUND TRUE) else (IRRLICHT_LIBRARIES AND IRRLICHT_INCLUDE_DIRS) find_path(IRRLICHT_INCLUDE_DIR NAMES irrlicht.h PATHS /usr/include /usr/local/include /opt/local/include PATH_SUFFIXES irrlicht ) find_library(IRRLICHT_LIBRARY NAMES Irrlicht PATHS /usr/lib /usr/local/lib /opt/local/lib ) set(IRRLICHT_INCLUDE_DIRS ${IRRLICHT_INCLUDE_DIR} ) set(IRRLICHT_LIBRARIES ${IRRLICHT_LIBRARY} ) if (IRRLICHT_INCLUDE_DIRS AND IRRLICHT_LIBRARIES) set(IRRLICHT_FOUND TRUE) endif (IRRLICHT_INCLUDE_DIRS AND IRRLICHT_LIBRARIES) if (IRRLICHT_FOUND) if (NOT Irrlicht_FIND_QUIETLY) message(STATUS "Found Irrlicht: ${IRRLICHT_LIBRARIES}") endif (NOT Irrlicht_FIND_QUIETLY) else (IRRLICHT_FOUND) if (Irrlicht_FIND_REQUIRED) message(FATAL_ERROR "Could not find Irrlicht") endif (Irrlicht_FIND_REQUIRED) endif (IRRLICHT_FOUND) # show the IRRLICHT_INCLUDE_DIRS and IRRLICHT_LIBRARIES variables only in the advanced view mark_as_advanced(IRRLICHT_INCLUDE_DIRS IRRLICHT_LIBRARIES) endif (IRRLICHT_LIBRARIES AND IRRLICHT_INCLUDE_DIRS) fifechan-0.1.5/CMake/Modules/FindOGLFT.cmake000066400000000000000000000023221341577075500203430ustar00rootroot00000000000000# - Try to find OGLFT # Once done this will define # # OGLFT_FOUND - system has OGLFT # OGLFT_INCLUDE_DIRS - the OGLFT include directory # OGLFT_LIBRARIES - Link these to use OGLFT # OGLFT_DEFINITIONS - Compiler switches required for using OGLFT # # Copyright (c) 2008 Olof Naessen # # Redistribution and use is allowed according to the terms of the New # BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. # if (OGLFT_LIBRARIES AND OGLFT_INCLUDE_DIRS) # in cache already set(OGLFT_FOUND TRUE) else (OGLFT_LIBRARIES AND OGLFT_INCLUDE_DIRS) find_path(OGLFT_INCLUDE_DIRS NAMES OpenGL-FT.h OGLFT.h PATHS /usr/include /usr/local/include /opt/local/include PATH_SUFFIXES oglft OGLFT ) find_library(OGLFT_LIBRARIES NAMES OpenGL-FT OGLFT oglft PATHS /usr/lib /usr/local/lib /opt/local/lib ) add_definitions(-DOGLFT_NO_QT) include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) FIND_PACKAGE_HANDLE_STANDARD_ARGS(OGLFT REQUIRED_VARS OGLFT_LIBRARIES OGLFT_INCLUDE_DIRS) endif (OGLFT_LIBRARIES AND OGLFT_INCLUDE_DIRS) fifechan-0.1.5/CMake/Modules/FindSDL2.cmake000066400000000000000000000070141341577075500201770ustar00rootroot00000000000000# - Find SDL2 library and headers # # Find module for SDL 2.0 (http://www.libsdl.org/). # It defines the following variables: # SDL2_INCLUDE_DIRS - The location of the headers, e.g., SDL.h. # SDL2_LIBRARIES - The libraries to link against to use SDL2. # SDL2_FOUND - If false, do not try to use SDL2. # SDL2_VERSION_STRING - Human-readable string containing the version of SDL2. # # This module responds to the the flag: # SDL2_BUILDING_LIBRARY # If this is defined, then no SDL2_main will be linked in because # only applications need main(). # Otherwise, it is assumed you are building an application and this # module will attempt to locate and set the the proper link flags # as part of the returned SDL2_LIBRARIES variable. # # Also defined, but not for general use are: # SDL2_INCLUDE_DIR - The directory that contains SDL.h. # SDL2_LIBRARY - The location of the SDL2 library. # SDL2MAIN_LIBRARY - The location of the SDL2main 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_SDL2 QUIET sdl2) find_path(SDL2_INCLUDE_DIR NAMES SDL.h HINTS ${PC_SDL2_INCLUDEDIR} ${PC_SDL2_INCLUDE_DIRS} PATH_SUFFIXES SDL2 ) find_library(SDL2_LIBRARY NAMES SDL2 HINTS ${PC_SDL2_LIBDIR} ${PC_SDL2_LIBRARY_DIRS} PATH_SUFFIXES x64 x86 ) if(NOT SDL2_BUILDING_LIBRARY) find_library(SDL2MAIN_LIBRARY NAMES SDL2main HINTS ${PC_SDL2_LIBDIR} ${PC_SDL2_LIBRARY_DIRS} PATH_SUFFIXES x64 x86 ) endif() if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$") string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}") string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}") string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}") set(SDL2_VERSION_STRING ${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH}) unset(SDL2_VERSION_MAJOR_LINE) unset(SDL2_VERSION_MINOR_LINE) unset(SDL2_VERSION_PATCH_LINE) unset(SDL2_VERSION_MAJOR) unset(SDL2_VERSION_MINOR) unset(SDL2_VERSION_PATCH) endif() set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR}) set(SDL2_LIBRARIES ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY}) include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(SDL2 REQUIRED_VARS SDL2_INCLUDE_DIR SDL2_LIBRARY VERSION_VAR SDL2_VERSION_STRING) mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY) fifechan-0.1.5/CMake/Modules/FindSDL2_image.cmake000066400000000000000000000064461341577075500213510ustar00rootroot00000000000000# - Find SDL2_image library and headers # # Find module for SDL_image 2.0 (http://www.libsdl.org/projects/SDL_image/). # It defines the following variables: # SDL2_IMAGE_INCLUDE_DIRS - The location of the headers, e.g., SDL_image.h. # SDL2_IMAGE_LIBRARIES - The libraries to link against to use SDL2_image. # SDL2_IMAGE_FOUND - If false, do not try to use SDL2_image. # SDL2_IMAGE_VERSION_STRING # Human-readable string containing the version of SDL2_image. # # Also defined, but not for general use are: # SDL2_IMAGE_INCLUDE_DIR - The directory that contains SDL_image.h. # SDL2_IMAGE_LIBRARY - The location of the SDL2_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_SDL2_IMAGE QUIET SDL2_image) find_path(SDL2_IMAGE_INCLUDE_DIR NAMES SDL_image.h HINTS ${PC_SDL2_IMAGE_INCLUDEDIR} ${PC_SDL2_IMAGE_INCLUDE_DIRS} PATH_SUFFIXES SDL2 ) find_library(SDL2_IMAGE_LIBRARY NAMES SDL2_image HINTS ${PC_SDL2_IMAGE_LIBDIR} ${PC_SDL2_IMAGE_LIBRARY_DIRS} PATH_SUFFIXES x64 x86 ) if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h") file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$") file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$") file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_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" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}") string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}") string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}") set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH}) unset(SDL2_IMAGE_VERSION_MAJOR_LINE) unset(SDL2_IMAGE_VERSION_MINOR_LINE) unset(SDL2_IMAGE_VERSION_PATCH_LINE) unset(SDL2_IMAGE_VERSION_MAJOR) unset(SDL2_IMAGE_VERSION_MINOR) unset(SDL2_IMAGE_VERSION_PATCH) endif() set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR}) set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY}) include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(SDL2_image REQUIRED_VARS SDL2_IMAGE_INCLUDE_DIRS SDL2_IMAGE_LIBRARIES VERSION_VAR SDL2_IMAGE_VERSION_STRING) mark_as_advanced(SDL2_IMAGE_INCLUDE_DIR SDL2_IMAGE_LIBRARY) fifechan-0.1.5/CMake/Modules/FindSDL2_ttf.cmake000066400000000000000000000062341341577075500210570ustar00rootroot00000000000000# - Find SDL2_ttf library and headers # # Find module for SDL_ttf 2.0 (http://www.libsdl.org/projects/SDL_ttf/). # It defines the following variables: # SDL2_TTF_INCLUDE_DIRS - The location of the headers, e.g., SDL_ttf.h. # SDL2_TTF_LIBRARIES - The libraries to link against to use SDL2_ttf. # SDL2_TTF_FOUND - If false, do not try to use SDL2_ttf. # SDL2_TTF_VERSION_STRING # Human-readable string containing the version of SDL2_ttf. # # Also defined, but not for general use are: # SDL2_TTF_INCLUDE_DIR - The directory that contains SDL_ttf.h. # SDL2_TTF_LIBRARY - The location of the SDL2_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_SDL2_TTF QUIET SDL2_ttf) find_path(SDL2_TTF_INCLUDE_DIR NAMES SDL_ttf.h HINTS ${PC_SDL2_TTF_INCLUDEDIR} ${PC_SDL2_TTF_INCLUDE_DIRS} PATH_SUFFIXES SDL2 ) find_library(SDL2_TTF_LIBRARY NAMES SDL2_ttf HINTS ${PC_SDL2_TTF_LIBDIR} ${PC_SDL2_TTF_LIBRARY_DIRS} PATH_SUFFIXES x64 x86 ) if(SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h") file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$") file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$") file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_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" SDL2_TTF_VERSION_MAJOR "${SDL2_TTF_VERSION_MAJOR_LINE}") string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MINOR "${SDL2_TTF_VERSION_MINOR_LINE}") string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_PATCH "${SDL2_TTF_VERSION_PATCH_LINE}") set(SDL2_TTF_VERSION_STRING ${SDL2_TTF_VERSION_MAJOR}.${SDL2_TTF_VERSION_MINOR}.${SDL2_TTF_VERSION_PATCH}) unset(SDL2_TTF_VERSION_MAJOR_LINE) unset(SDL2_TTF_VERSION_MINOR_LINE) unset(SDL2_TTF_VERSION_PATCH_LINE) unset(SDL2_TTF_VERSION_MAJOR) unset(SDL2_TTF_VERSION_MINOR) unset(SDL2_TTF_VERSION_PATCH) endif() set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR}) set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY}) include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(SDL2_ttf REQUIRED_VARS SDL2_TTF_INCLUDE_DIRS SDL2_TTF_LIBRARIES VERSION_VAR SDL2_TTF_VERSION_STRING) mark_as_advanced(SDL2_TTF_INCLUDE_DIR SDL2_TTF_LIBRARY) fifechan-0.1.5/CMake/get-sdl2.cmake000066400000000000000000000045701341577075500167070ustar00rootroot00000000000000#------------------------------------------------------------------------------ # External Project: SDL2 # Downloads: https://libsdl.org/release/ #------------------------------------------------------------------------------ include(ExternalProject) set(SDL2_VERSION "2.0.9") # For Windows it's faster to download the pre-compiled development binaries. if (WIN32) if(MINGW) # download pre-compiled SDL2 dev package for MinGW 32/64-bit ExternalProject_Add( sdl2 PREFIX ${DEPENDENCY_EXTRACT_DIR} DOWNLOAD_DIR ${DEPENDENCY_DOWNLOAD_DIR} URL http://libsdl.org/release/SDL2-devel-${SDL2_VERSION}-mingw.tar.gz URL_MD5 f5645eed64214c3bc22a3e157fc1f15f CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2/lib ${DEPENDENCY_INSTALL_DIR}/lib COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2/include ${DEPENDENCY_INSTALL_DIR}/include/SDL2 ) endif(MINGW) if(MSVC) # download pre-compiled SDL2 dev package for Visual C++ 32/64-bit ExternalProject_Add( sdl2 PREFIX ${DEPENDENCY_EXTRACT_DIR} DOWNLOAD_DIR ${DEPENDENCY_DOWNLOAD_DIR} URL http://libsdl.org/release/SDL2-devel-${SDL2_VERSION}-VC.zip URL_MD5 22bdb85ce4874673c4fafcce772d8b72 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2/lib ${DEPENDENCY_INSTALL_DIR}/lib COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2/include ${DEPENDENCY_INSTALL_DIR}/include/SDL2 ) endif(MSVC) else() # build from source set(SDL2_CMAKE_ARGS -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_INSTALL_PREFIX:PATH= -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} ) ExternalProject_Add( sdl2 PREFIX ${DEPENDENCY_EXTRACT_DIR} DOWNLOAD_DIR ${DEPENDENCY_DOWNLOAD_DIR} URL http://libsdl.org/release/SDL2-${SDL2_VERSION}.tar.gz URL_MD5 f2ecfba915c54f7200f504d8b48a5dfe #CONFIGURE_COMMAND /configure --prefix=${DEPENDENCY_INSTALL_DIR} INSTALL_DIR ${DEPENDENCY_INSTALL_DIR} CMAKE_ARGS ${SDL2_CMAKE_ARGS} ) endif() fifechan-0.1.5/CMake/get-sdl2_image.cmake000066400000000000000000000044031341577075500200440ustar00rootroot00000000000000#------------------------------------------------------------------------------ # External Project: SDL2_image # Downloads: https://libsdl.org/projects/SDL_image/ #------------------------------------------------------------------------------ include(ExternalProject) set(SDL2_IMAGE_VERSION "2.0.4") # For win32 it's faster to download the pre-compiled development binaries. if (WIN32) if(MINGW) # download pre-compiled SDL2 dev package for MinGW 32/64-bit ExternalProject_Add( sdl2-image DEPENDS sdl2 PREFIX ${DEPENDENCY_EXTRACT_DIR} DOWNLOAD_DIR ${DEPENDENCY_DOWNLOAD_DIR} URL https://libsdl.org/projects/SDL_image/release/SDL2_image-devel-${SDL2_IMAGE_VERSION}-mingw.tar.gz URL_MD5 53fd232ce4d70a3af18909a8a7248094 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2-image/lib ${DEPENDENCY_INSTALL_DIR}/lib COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2-image/include ${DEPENDENCY_INSTALL_DIR}/include/SDL2 ) endif(MINGW) if(MSVC) # download pre-compiled SDL2 dev package for Visual C++ 32/64-bit ExternalProject_Add( sdl2-image DEPENDS sdl2 PREFIX ${DEPENDENCY_EXTRACT_DIR} DOWNLOAD_DIR ${DEPENDENCY_DOWNLOAD_DIR} URL https://libsdl.org/projects/SDL_image/release/SDL2_image-devel-${SDL2_IMAGE_VERSION}-VC.zip URL_MD5 9435e3ecc2f03eed6a24c7ed2dd96d99 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2-image/lib ${DEPENDENCY_INSTALL_DIR}/lib COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2-image/include ${DEPENDENCY_INSTALL_DIR}/include/SDL2 ) endif(MSVC) else() # build from source ExternalProject_Add( sdl2-image PREFIX ${DEPENDENCY_EXTRACT_DIR} DOWNLOAD_DIR ${DEPENDENCY_DOWNLOAD_DIR} URL https://libsdl.org/projects/SDL_image/release/SDL2_image-${SDL2_IMAGE_VERSION}.tar.gz URL_MD5 88b9766d5b64a67f82ba511c57e7ce10 CONFIGURE_COMMAND /configure --prefix=${DEPENDENCY_INSTALL_DIR} ) endif()fifechan-0.1.5/CMake/get-sdl2_ttf.cmake000066400000000000000000000050131341577075500175550ustar00rootroot00000000000000#------------------------------------------------------------------------------ # External Project: SDL2_ttf # Downloads: https://libsdl.org/projects/SDL_ttf/ #------------------------------------------------------------------------------ include(ExternalProject) set(SDL2_TTF_VERSION "2.0.14") # For win32 it's faster to download the pre-compiled development binaries. if (WIN32) if(MINGW) # download pre-compiled SDL2 dev package for MinGW 32/64-bit ExternalProject_Add( sdl2-ttf DEPENDS sdl2 PREFIX ${DEPENDENCY_EXTRACT_DIR} DOWNLOAD_DIR ${DEPENDENCY_DOWNLOAD_DIR} URL https://libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-${SDL2_TTF_VERSION}-mingw.tar.gz URL_MD5 1 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2-ttf/lib ${DEPENDENCY_INSTALL_DIR}/lib COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2-ttf/include ${DEPENDENCY_INSTALL_DIR}/include/SDL2 ) endif(MINGW) if(MSVC) # download pre-compiled SDL2 dev package for Visual C++ 32/64-bit ExternalProject_Add( sdl2-ttf DEPENDS sdl2 PREFIX ${DEPENDENCY_EXTRACT_DIR} DOWNLOAD_DIR ${DEPENDENCY_DOWNLOAD_DIR} URL https://libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-${SDL2_TTF_VERSION}-VC.zip URL_MD5 304d4aa67fec7a5a8c3c47c4639b91e2 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2-ttf/lib ${DEPENDENCY_INSTALL_DIR}/lib COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPENDENCY_EXTRACT_DIR}/src/sdl2-ttf/include ${DEPENDENCY_INSTALL_DIR}/include/SDL2 ) endif(MSVC) else() # build from source ExternalProject_Add( freetype2 PREFIX ${DEPENDENCY_EXTRACT_DIR} URL http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz URL_MD5 1 DOWNLOAD_DIR ${DOWNLOAD_DIR} CONFIGURE_COMMAND /configure --prefix=${DEPENDENCY_INSTALL_DIR} ) ExternalProject_Add( sdl2-ttf DEPENDS freetype2 PREFIX ${DEPENDENCY_EXTRACT_DIR} DOWNLOAD_DIR ${DEPENDENCY_DOWNLOAD_DIR} URL https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-${SDL2_TTF_VERSION}.tar.gz URL_MD5 1 CONFIGURE_COMMAND /configure --prefix=${DEPENDENCY_INSTALL_DIR} --with-freetype-prefix=${DEPENDENCY_INSTALL_DIR} ) endif()fifechan-0.1.5/CMakeLists.txt000066400000000000000000000511351341577075500160430ustar00rootroot00000000000000#------------------------------------------------------------------------------ # FifeChan / FifeGUI #------------------------------------------------------------------------------ CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0) PROJECT(fifechan) #------------------------------------------------------------------------------ # Version #------------------------------------------------------------------------------ SET(MAJOR_VERSION 0) SET(MINOR_VERSION 1) SET(PATCH_VERSION 5) SET(FIFECHAN_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}) SET(LIB_SUFFIX "" CACHE STRING "Suffix to append to the system lib folder") #------------------------------------------------------------------------------ # Options #------------------------------------------------------------------------------ OPTION(BUILD_FIFECHAN_SHARED "Build the Fifechan core library as a shared library" ON) OPTION(ENABLE_ALLEGRO "Enable the Fifechan Allegro extension" OFF) OPTION(BUILD_FIFECHAN_ALLEGRO_SHARED "Build the Fifechan Allegro extension library as a shared library" OFF) OPTION(ENABLE_IRRLICHT "Enable the Fifechan Irrlicht extension" OFF) OPTION(BUILD_FIFECHAN_IRRLICHT_SHARED "Build the Fifechan Irrlicht extension library as a shared library" OFF) OPTION(ENABLE_OPENGL "Enable the Fifechan OpenGL extension" ON) OPTION(ENABLE_OPENGL_CONTRIB "Enable the Fifechan OpenGL contrib extension (freetype, oglft)" OFF) OPTION(BUILD_FIFECHAN_OPENGL_SHARED "Build the Fifechan OpenGL extension library as a shared library" ON) OPTION(ENABLE_SDL "Enable the Fifechan SDL extension" ON) OPTION(ENABLE_SDL_CONTRIB "Enable the Fifechan SDL contrib extension (SDL2_ttf)" OFF) OPTION(BUILD_FIFECHAN_SDL_SHARED "Build the Fifechan SDL extension library as a shared library" ON) #------------------------------------------------------------------------------ # Display Status #------------------------------------------------------------------------------ message("") message("== Building FIFECHAN version ${FIFECHAN_VERSION} using build type '${CMAKE_BUILD_TYPE}'.") message(STATUS " Source directory is '${PROJECT_SOURCE_DIR}'.") message(STATUS " Build directory is '${PROJECT_BINARY_DIR}'.") message(STATUS " Installation path is '${CMAKE_INSTALL_PREFIX}' (set -DCMAKE_INSTALL_PREFIX= to change).") message("") #------------------------------------------------------------------------------ # Find Dependencies - Windows #------------------------------------------------------------------------------ # Tell CMake where to search for binaries (dlls), includes and libs on Windows if(WIN32) set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${PROJECT_SOURCE_DIR}/../fifechan-dependencies/includes/bin" "${PROJECT_SOURCE_DIR}/../fifechan-dependencies/includes/include" "${PROJECT_SOURCE_DIR}/../fifechan-dependencies/includes/include/SDL2" "${PROJECT_SOURCE_DIR}/../fifechan-dependencies/includes/lib/x86" "${PROJECT_SOURCE_DIR}/../fifechan-dependencies/includes/lib" ) endif(WIN32) #------------------------------------------------------------------------------ # Configure #------------------------------------------------------------------------------ # Path to local modules SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules) # Do not allow an in-source-tree build, request an out-of-source-tree build. if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) message(FATAL_ERROR "#Please build outside of the source tree!\n Make a separate folder for building and run CMake there:\n mkdir _build; cd _build; cmake ..\n Before that, cleanup:\nrm -rf CMakeCache.txt CMakeFiles") endif() # Disable in-source builds and modifications to the source tree. set(CMAKE_DISABLE_SOURCE_CHANGES ON) set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) #------------------------------------------------------------------------------ # Compiler Options #------------------------------------------------------------------------------ if(WIN32) if(MSVC) # ensure we use minimal "windows.h" lib without the crazy min max macros SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"WIN32_LEAN_AND_MEAN\"") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"NOMINMAX\"") endif(MSVC) endif(WIN32) #------------------------------------------------------------------------------ # Source Files #------------------------------------------------------------------------------ INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/include") # The Fifechan core library FILE(GLOB FIFECHAN_HEADER include/fifechan.hpp) FILE(GLOB FIFECHAN_HEADERS include/fifechan/actionevent.hpp include/fifechan/actionlistener.hpp include/fifechan/cliprectangle.hpp include/fifechan/color.hpp include/fifechan/containerevent.hpp include/fifechan/containerlistener.hpp include/fifechan/deathlistener.hpp include/fifechan/defaultfont.hpp include/fifechan/event.hpp include/fifechan/exception.hpp include/fifechan/focushandler.hpp include/fifechan/focuslistener.hpp include/fifechan/font.hpp include/fifechan/genericinput.hpp include/fifechan/glut.hpp include/fifechan/graphics.hpp include/fifechan/gui.hpp include/fifechan/image.hpp include/fifechan/imagefont.hpp include/fifechan/imageloader.hpp include/fifechan/input.hpp include/fifechan/inputevent.hpp include/fifechan/key.hpp include/fifechan/keyevent.hpp include/fifechan/keyinput.hpp include/fifechan/keylistener.hpp include/fifechan/listmodel.hpp include/fifechan/mouseevent.hpp include/fifechan/mouseinput.hpp include/fifechan/mouselistener.hpp include/fifechan/platform.hpp include/fifechan/point.hpp include/fifechan/rectangle.hpp include/fifechan/selectionevent.hpp include/fifechan/selectionlistener.hpp include/fifechan/size.hpp include/fifechan/text.hpp include/fifechan/utf8stringeditor.hpp include/fifechan/version.hpp include/fifechan/visibilityeventhandler.hpp include/fifechan/widget.hpp include/fifechan/widgetlistener.hpp include/fifechan/opengl.hpp ) FILE(GLOB FIFECHAN_WIDGET_HEADERS include/fifechan/widgets/*.hpp) FILE(GLOB FIFECHAN_UTIL_HEADERS include/fifechan/util/*.hpp) FILE(GLOB FIFECHAN_SRC src/*.cpp) FILE(GLOB FIFECHAN_WIDGET_SRC src/widgets/*.cpp) # Grouping of the source for nicer display in IDEs such as Visual Studio SOURCE_GROUP(src FILES ${FIFECHAN_HEADER}) SOURCE_GROUP(src/fifechan FILES ${FIFECHAN_HEADERS} ${FIFECHAN_SRC}) SOURCE_GROUP(src/fifechan/widgets FILES ${FIFECHAN_WIDGET_HEADERS} ${FIFECHAN_WIDGET_SRC}) #------------------------------------------------------------------------------ # Fifechan core library as a shared library #------------------------------------------------------------------------------ IF(BUILD_FIFECHAN_SHARED) SET(FIFECHAN_LIBRARY_TYPE SHARED) ELSE(BUILD_FIFECHAN_SHARED) SET(FIFECHAN_LIBRARY_TYPE STATIC) ENDIF(BUILD_FIFECHAN_SHARED) ADD_LIBRARY(${PROJECT_NAME} ${FIFECHAN_LIBRARY_TYPE} ${FIFECHAN_HEADER} ${FIFECHAN_HEADERS} ${FIFECHAN_WIDGET_HEADERS} ${FIFECHAN_UTIL_HEADERS} ${FIFECHAN_SRC} ${FIFECHAN_WIDGET_SRC} ) ADD_CUSTOM_TARGET(lib DEPENDS ${PROJECT_NAME}) # Create symlink SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FIFECHAN_VERSION} SOVERSION ${FIFECHAN_VERSION} CLEAN_DIRECT_OUTPUT 1 # Allow creating static and shared libraries without conflict OUTPUT_NAME ${PROJECT_NAME} # Avoid conflicts between library and binary target names COMPILE_DEFINITIONS "FIFECHAN_BUILD" ) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib${LIB_SUFFIX} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) INSTALL(FILES ${FIFECHAN_HEADER} DESTINATION include/) INSTALL(FILES ${FIFECHAN_HEADERS} DESTINATION include/fifechan/) INSTALL(FILES ${FIFECHAN_WIDGET_HEADERS} DESTINATION include/fifechan/widgets/) INSTALL(FILES ${FIFECHAN_UTIL_HEADERS} DESTINATION include/fifechan/util/) #REMOVE_DEFINITIONS("-DFIFECHAN_BUILD") #ADD_DEFINITIONS("-DFIFECHAN_EXTENSION_BUILD") #------------------------------------------------------------------------------ # The Fifechan Allegro extension library #------------------------------------------------------------------------------ FIND_PACKAGE(Allegro) IF(ENABLE_ALLEGRO AND ALLEGRO_FOUND) INCLUDE_DIRECTORIES(${ALLEGRO_INCLUDE_DIR}) # The Fifechan Allegro extension source FILE(GLOB FIFECHAN_ALLEGRO_HEADER include/fifechan/allegro.hpp) FILE(GLOB FIFECHAN_ALLEGRO_HEADERS include/fifechan/allegro/*.hpp) FILE(GLOB FIFECHAN_ALLEGRO_CONTRIB_HEADERS include/fifechan/contrib/allegro/*.hpp) FILE(GLOB FIFECHAN_ALLEGRO_SRC src/allegro/*.cpp) # Grouping of the source for nicer display in IDEs such as Visual Studio SOURCE_GROUP(src/fifechan FILES ${FIFECHAN_ALLEGRO_HEADER}) SOURCE_GROUP(src/fifechan/allegro FILES ${FIFECHAN_ALLEGRO_HEADERS} ${FIFECHAN_ALLEGRO_SRC}) SOURCE_GROUP(src/fifechan/contrib/allegro FILES ${FIFECHAN_ALLEGRO_CONTRIB_HEADERS}) IF(BUILD_FIFECHAN_ALLEGRO_SHARED) SET(FIFECHAN_ALLEGRO_LIBRARY_TYPE SHARED) ELSE(BUILD_FIFECHAN_ALLEGRO_SHARED) SET(FIFECHAN_ALLEGRO_LIBRARY_TYPE STATIC) ENDIF(BUILD_FIFECHAN_ALLEGRO_SHARED) ADD_LIBRARY(${PROJECT_NAME}_allegro ${FIFECHAN_ALLEGRO_LIBRARY_TYPE} ${FIFECHAN_ALLEGRO_HEADER} ${FIFECHAN_ALLEGRO_HEADERS} ${FIFECHAN_ALLEGRO_CONTRIB_HEADERS} ${FIFECHAN_ALLEGRO_SRC} ) TARGET_LINK_LIBRARIES(${PROJECT_NAME}_allegro ${ALLEG_LIBRARY} ${PROJECT_NAME}) ADD_CUSTOM_TARGET(allegrolib DEPENDS ${PROJECT_NAME}_allegro) # Create symlink SET_TARGET_PROPERTIES(${PROJECT_NAME}_allegro PROPERTIES VERSION ${FIFECHAN_VERSION} SOVERSION ${FIFECHAN_VERSION} CLEAN_DIRECT_OUTPUT 1 # Allow creating static and shared libraries without conflict OUTPUT_NAME ${PROJECT_NAME}_allegro # Avoid conflicts between library and binary target names COMPILE_DEFINITIONS "FIFECHAN_EXTENSION_BUILD" ) INSTALL(TARGETS ${PROJECT_NAME}_allegro DESTINATION lib${LIB_SUFFIX} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) INSTALL(FILES ${FIFECHAN_ALLEGRO_HEADER} DESTINATION include/fifechan/) INSTALL(FILES ${FIFECHAN_ALLEGRO_HEADERS} DESTINATION include/fifechan/allegro/) INSTALL(FILES ${FIFECHAN_ALLEGRO_CONTRIB_HEADERS} DESTINATION include/fifechan/contrib/allegro/) ENDIF(ENABLE_ALLEGRO AND ALLEGRO_FOUND) #------------------------------------------------------------------------------ # Fifechan Irrlicht extension library #------------------------------------------------------------------------------ FIND_PACKAGE(Irrlicht) IF(ENABLE_IRRLICHT AND IRRLICHT_FOUND) INCLUDE_DIRECTORIES(${IRRLICHT_INCLUDE_DIR}) # The Fifechan Irrlicht extension source FILE(GLOB FIFECHAN_IRRLICHT_HEADER include/fifechan/irrlicht.hpp) FILE(GLOB FIFECHAN_IRRLICHT_HEADERS include/fifechan/irrlicht/*.hpp) FILE(GLOB FIFECHAN_IRRLICHT_SRC src/irrlicht/*.cpp) # Grouping of the source for nicer display in IDEs such as Visual Studio SOURCE_GROUP(src/fifechan FILES ${FIFECHAN_IRRLICHT_HEADER}) SOURCE_GROUP(src/fifechan/irrlicht FILES ${FIFECHAN_IRRLICHT_HEADERS} ${FIFECHAN_IRRLICHT_SRC}) IF(BUILD_FIFECHAN_IRRLICHT_SHARED) SET(FIFECHAN_IRRLICHT_LIBRARY_TYPE SHARED) ELSE(BUILD_FIFECHAN_IRRLICHT_SHARED) SET(FIFECHAN_IRRLICHT_LIBRARY_TYPE STATIC) ENDIF(BUILD_FIFECHAN_IRRLICHT_SHARED) ADD_LIBRARY(${PROJECT_NAME}_irrlicht ${FIFECHAN_IRRLICHT_LIBRARY_TYPE} ${FIFECHAN_IRRLICHT_HEADER} ${FIFECHAN_IRRLICHT_HEADERS} ${FIFECHAN_IRRLICHT_SRC} ) TARGET_LINK_LIBRARIES(${PROJECT_NAME}_irrlicht ${IRRLICHT_LIBRARY} ${PROJECT_NAME}) ADD_CUSTOM_TARGET(irrlichtlib DEPENDS ${PROJECT_NAME}_irrlicht) # Create symlink SET_TARGET_PROPERTIES(${PROJECT_NAME}_irrlicht PROPERTIES VERSION ${FIFECHAN_VERSION} SOVERSION ${FIFECHAN_VERSION} CLEAN_DIRECT_OUTPUT 1 # Allow creating static and shared libraries without conflict OUTPUT_NAME ${PROJECT_NAME}_irrlicht # Avoid conflicts between library and binary target names COMPILE_DEFINITIONS "FIFECHAN_EXTENSION_BUILD" ) INSTALL(TARGETS ${PROJECT_NAME}_irrlicht DESTINATION lib${LIB_SUFFIX} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) INSTALL(FILES ${FIFECHAN_IRRLICHT_HEADER} DESTINATION include/fifechan/) INSTALL(FILES ${FIFECHAN_IRRLICHT_HEADERS} DESTINATION include/fifechan/irrlicht/) ENDIF(ENABLE_IRRLICHT AND IRRLICHT_FOUND) #------------------------------------------------------------------------------ # The Fifechan OpenGL extension library #------------------------------------------------------------------------------ FIND_PACKAGE(OpenGL) IF(APPLE AND ENABLE_OPENGL) FIND_LIBRARY(OPENGL_LIBRARY OpenGL) MARK_AS_ADVANCED(OPENGL_LIBRARY) SET(EXTRA_LIBS ${OPENGL_LIBRARY}) ENDIF(APPLE AND ENABLE_OPENGL) IF(ENABLE_OPENGL_CONTRIB) FIND_PACKAGE(Freetype) FIND_PACKAGE(OGLFT) ENDIF(ENABLE_OPENGL_CONTRIB) IF(ENABLE_OPENGL AND OPENGL_FOUND) INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR}) IF(ENABLE_OPENGL_CONTRIB AND OGLFT_FOUND AND FREETYPE_FOUND) INCLUDE_DIRECTORIES(${FREETYPE_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${OGLFT_INCLUDE_DIRS}) ENDIF(ENABLE_OPENGL_CONTRIB AND OGLFT_FOUND AND FREETYPE_FOUND) # The OpenGL extension source FILE(GLOB OGLFT_FOUNDFIFECHAN_OPENGL_HEADER include/fifechan/opengl.hpp) FILE(GLOB FIFECHAN_OPENGL_HEADERS include/fifechan/opengl/*.hpp) FILE(GLOB FIFECHAN_OPENGL_CONTRIB_HEADERS include/fifechan/contrib/opengl/*.hpp) FILE(GLOB FIFECHAN_OPENGL_SRC src/opengl/*.cpp) IF(ENABLE_OPENGL_CONTRIB) FILE(GLOB FIFECHAN_OPENGL_CONTRIB_SRC src/contrib/opengl/*.cpp) ENDIF(ENABLE_OPENGL_CONTRIB) # Grouping of the source for nicer display in IDEs such as Visual Studio SOURCE_GROUP(src/fifechan FILES ${FIFECHAN_OPENGL_HEADER}) SOURCE_GROUP(src/fifechan/opengl FILES ${FIFECHAN_OPENGL_HEADERS} ${FIFECHAN_OPENGL_SRC}) SOURCE_GROUP(src/fifechan/contrib/opengl FILES ${FIFECHAN_OPENGL_CONTRIB_HEADERS} ${FIFECHAN_OPENGL_CONTRIB_SRC}) IF(BUILD_FIFECHAN_OPENGL_SHARED) SET(FIFECHAN_OPENGL_LIBRARY_TYPE SHARED) ELSE(BUILD_FIFECHAN_OPENGL_SHARED) SET(FIFECHAN_OPENGL_LIBRARY_TYPE STATIC) ENDIF(BUILD_FIFECHAN_OPENGL_SHARED) ADD_LIBRARY(${PROJECT_NAME}_opengl ${FIFECHAN_OPENGL_LIBRARY_TYPE} ${FIFECHAN_OPENGL_HEADER} ${FIFECHAN_OPENGL_HEADERS} ${FIFECHAN_OPENGL_CONTRIB_HEADERS} ${FIFECHAN_OPENGL_SRC} ${FIFECHAN_OPENGL_CONTRIB_SRC}) IF(ENABLE_OPENGL_CONTRIB AND OGLFT_FOUND) TARGET_LINK_LIBRARIES(${PROJECT_NAME}_opengl ${OPENGL_LIBRARY} ${FREETYPE_LIBRARIES} ${OGLFT_LIBRARIES} ${PROJECT_NAME}) ELSE(ENABLE_OPENGL_CONTRIB AND OGLFT_FOUND) TARGET_LINK_LIBRARIES(${PROJECT_NAME}_opengl ${OPENGL_LIBRARY} ${PROJECT_NAME}) ENDIF(ENABLE_OPENGL_CONTRIB AND OGLFT_FOUND) ADD_CUSTOM_TARGET(opengllib DEPENDS ${PROJECT_NAME}_opengl) # Create symlink SET_TARGET_PROPERTIES(${PROJECT_NAME}_opengl PROPERTIES VERSION ${FIFECHAN_VERSION} SOVERSION ${FIFECHAN_VERSION} CLEAN_DIRECT_OUTPUT 1 # Allow creating static and shared libraries without conflict OUTPUT_NAME ${PROJECT_NAME}_opengl # Avoid conflicts between library and binary target names COMPILE_DEFINITIONS "FIFECHAN_EXTENSION_BUILD" ) INSTALL(TARGETS ${PROJECT_NAME}_opengl DESTINATION lib${LIB_SUFFIX} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) INSTALL(FILES ${FIFECHAN_OPENGL_HEADER} DESTINATION include/fifechan/) INSTALL(FILES ${FIFECHAN_OPENGL_HEADERS} DESTINATION include/fifechan/opengl/) INSTALL(FILES ${FIFECHAN_OPENGL_CONTRIB_HEADERS} DESTINATION include/fifechan/contrib/opengl/) ENDIF(ENABLE_OPENGL AND OPENGL_FOUND) #------------------------------------------------------------------------------ # The Fifechan SDL extension library #------------------------------------------------------------------------------ FIND_PACKAGE(SDL2) FIND_PACKAGE(SDL2_image) IF(ENABLE_SDL_CONTRIB) FIND_PACKAGE(SDL2_ttf) ENDIF(ENABLE_SDL_CONTRIB) IF(APPLE AND ENABLE_SDL) FIND_LIBRARY(SDL2_LIBRARY SDL2) FIND_LIBRARY(SDL2_IMAGE_LIBRARY SDL2_image) MARK_AS_ADVANCED(SDL2_LIBRARY SDL2_IMAGE_LIBRARY) SET(EXTRA_LIBS ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY}) ENDIF(APPLE AND ENABLE_SDL) IF(ENABLE_SDL AND SDL2_FOUND AND SDL2_IMAGE_FOUND) INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR}) # The Fifechan SDL extension source FILE(GLOB FIFECHAN_SDL_HEADER include/fifechan/sdl.hpp) FILE(GLOB FIFECHAN_SDL_HEADERS include/fifechan/sdl/*.hpp) FILE(GLOB FIFECHAN_SDL_CONTRIB_HEADERS include/fifechan/contrib/sdl/*.hpp) FILE(GLOB FIFECHAN_SDL_SRC src/sdl/*.cpp) IF(ENABLE_SDL_CONTRIB AND SDLTTF_FOUND) INCLUDE_DIRECTORIES(${SDL_TTF_INCLUDE_DIRS}) FILE(GLOB FIFECHAN_CONTRIB_SRC src/contrib/sdl/*.cpp) ENDIF(ENABLE_SDL_CONTRIB AND SDLTTF_FOUND) # Grouping of the source for nicer display in IDEs such as Visual Studio SOURCE_GROUP(src/fifechan FILES ${FIFECHAN_SDL_HEADER}) SOURCE_GROUP(src/fifechan/sdl FILES ${FIFECHAN_SDL_HEADERS} ${FIFECHAN_SDL_SRC}) SOURCE_GROUP(src/fifechan/contrib/sdl FILES ${FIFECHAN_SDL_CONTRIB_HEADERS} ${FIFECHAN_CONTRIB_SRC}) IF(BUILD_FIFECHAN_SDL_SHARED) SET(FIFECHAN_SDL_LIBRARY_TYPE SHARED) ELSE(BUILD_FIFECHAN_SDL_SHARED) SET(FIFECHAN_SDL_LIBRARY_TYPE STATIC) ENDIF(BUILD_FIFECHAN_SDL_SHARED) ADD_LIBRARY(${PROJECT_NAME}_sdl ${FIFECHAN_SDL_LIBRARY_TYPE} ${FIFECHAN_SDL_HEADER} ${FIFECHAN_SDL_HEADERS} ${FIFECHAN_SDL_CONTRIB_HEADERS} ${FIFECHAN_SDL_SRC} ${FIFECHAN_CONTRIB_SRC} ) IF(WIN32) get_filename_component(SDL2_LIBRARY_DIR ${SDL2_LIBRARY} DIRECTORY) IF(MINGW) TARGET_LINK_LIBRARIES(${PROJECT_NAME}_sdl ${MINGW32_LIBRARY} ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY} ${SDL_TTF_LIBRARY} ${PROJECT_NAME}) ELSE(MINGW) TARGET_LINK_LIBRARIES(${PROJECT_NAME}_sdl ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY} ${SDL_TTF_LIBRARY} ${PROJECT_NAME}) ENDIF(MINGW) ELSE(WIN32) TARGET_LINK_LIBRARIES(${PROJECT_NAME}_sdl ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY} ${PROJECT_NAME}) ENDIF(WIN32) ADD_CUSTOM_TARGET(sdllib DEPENDS ${PROJECT_NAME}_sdl) # Create symlink SET_TARGET_PROPERTIES(${PROJECT_NAME}_sdl PROPERTIES VERSION ${FIFECHAN_VERSION} SOVERSION ${FIFECHAN_VERSION} CLEAN_DIRECT_OUTPUT 1 # Allow creating static and shared libraries without conflict OUTPUT_NAME ${PROJECT_NAME}_sdl # Avoid conflicts between library and binary target names COMPILE_DEFINITIONS "FIFECHAN_EXTENSION_BUILD" ) INSTALL(TARGETS ${PROJECT_NAME}_sdl DESTINATION lib${LIB_SUFFIX} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) INSTALL(FILES ${FIFECHAN_SDL_HEADER} DESTINATION include/fifechan/) INSTALL(FILES ${FIFECHAN_SDL_HEADERS} DESTINATION include/fifechan/sdl/) INSTALL(FILES ${FIFECHAN_SDL_CONTRIB_HEADERS} DESTINATION include/fifechan/contrib/sdl/) ENDIF(ENABLE_SDL AND SDL2_FOUND AND SDL2_IMAGE_FOUND) MESSAGE(STATUS "Fifechan Makefiles have been generated!") fifechan-0.1.5/INSTALL.md000066400000000000000000000017761341577075500147410ustar00rootroot00000000000000GNU/Linux --------- Execute the following lines: ``` cmake . make sudo make install ``` Microsoft Windows ----------------- 1. Install Windows version of cmake 2. Run `cmake-gui.exe` 3. Press `configure` 3. Generate appropriate project files (you may have to modify some cmake variables to point to SDL and SDL_image) 4. Load the project files in your IDE and build the project Dependencies ------------ For Allegro support you need the following libraries installed: * Allegro - http://alleg.sourceforge.net/ For OpenGL support you need the following libraries installed: * OpenGL - check with your graphics card vendor Optional OpenGL Contrib Dependencies (Set ENABLE_OPENGL_CONTRIB to ON if you need them) * OpenGL-FreeType Library - http://oglft.sourceforge.net/ For SDL support you need the following libraries installed: * SDL2 - http://www.libsdl.org * SDL2_image - http://www.libsdl.org Optional SDL Contrib Dependencies (Set ENABLE_SDL_CONTRIB to ON if you need them) * SDL2_ttf - http://www.libsdl.org fifechan-0.1.5/LICENSE.md000066400000000000000000000667531341577075500147230ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ----- Copyright (c) 2004, 2005, 2006, 2007 Olof Naess�n and Per Larsson Per Larsson a.k.a finalman Olof Naess�n a.k.a jansem/yakslem All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Guichan nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. fifechan-0.1.5/README.md000066400000000000000000000055671341577075500145720ustar00rootroot00000000000000![FIFEGUI LOGO](https://raw.githubusercontent.com/fifengine/fifechan/master/docs/logo/FIFEgui_small_c3.png) ## FIFECHAN | [Website](http://fifengine.net/) | [![#fife on Freenode](https://img.shields.io/badge/freenode-%23fife-green.svg)](https://webchat.freenode.net/?channels=fife) | [Changelog](https://github.com/fifengine/fifechan/blob/master/CHANGELOG.md) | [Releases](https://github.com/fifengine/fifechan/releases) | [Source Code (zip)](https://github.com/fifengine/fifechan/archive/master.zip) | |:--------:|:--------:|:--------:|:--------:|:--------:| | Continuous Integration | Linux | Mac | Windows | |:----------------------:|:-----:|:--------:|:-------:| | **Build Status** | [![Travis Build Status](https://travis-ci.org/fifengine/fifechan.svg?branch=master)](https://travis-ci.org/fifengine/fifechan) | [![Travis Build Status](https://travis-ci.org/fifengine/fifechan.svg?branch=master)](https://travis-ci.org/fifengine/fifechan) | [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/github/fifengine/fifechan?branch=master&svg=true)](https://ci.appveyor.com/project/LinuxDonald/fifechan) | | **Development Releases** | - | - | [All artifacts](https://ci.appveyor.com/project/LinuxDonald/fifechan/build/artifacts)
[fifechan-shared-VC15-x86.zip](https://ci.appveyor.com/api/projects/LinuxDonald/fifechan/artifacts/fifechan-shared-VC15-x86.zip)
[fifechan-static-VC15-x86.zip](https://ci.appveyor.com/api/projects/LinuxDonald/fifechan/artifacts/fifechan-static-VC15-x86.zip) | Fifechan is also already available from the following package repositories: [![Packaging status](https://repology.org/badge/vertical-allrepos/fifechan.svg)](https://repology.org/metapackage/fifechan) ## Introduction to Fifechan Fifechan is a lightweight cross platform GUI library written in C++ specifically designed for games. It has a small yet powerful built in set of extendable GUI Widgets allowing users to create virtually unlimited types of widgets. Fifechan supports rendering in SDL, OpenGL, or Allegro out of the box or it can be adapted to use any rendering engine the user requires. Events are pushed to Fifechan which allows users to use any input library they wish or they could use the built in input handling through either SDL input or Allegro input. The primary goal for Fifechan is to keep it extendable, lightweight and still be powerful enough to use in all types of games out of the box. ## Downloads #### Latest Releases You find the latest releases on [Github Releases](https://github.com/fifengine/fifechan/releases). #### Development Releases We also provide releases for the latest successful build. You find them listed in the Continous Integration table above. ## Getting involved If you want to get involved with the development, come join our IRC channel #fife on Freenode. Feel free to drop us a line there and we'll help you getting started! fifechan-0.1.5/appveyor.yml000066400000000000000000000113251341577075500156700ustar00rootroot00000000000000# Build worker image (VM template) image: Visual Studio 2017 # scripts that are called at very beginning, before repo cloning init: - date /T & time /T - git config --global core.autocrlf input - cmake --version # Set "build version number" to "short-commit-hash" or when tagged to "tag name" (Travis style) - ps: >- if ($env:APPVEYOR_REPO_TAG -eq "true") { Update-AppveyorBuild -Version "$env:APPVEYOR_REPO_TAG_NAME" } else { Update-AppveyorBuild -Version "dev-$($env:APPVEYOR_REPO_COMMIT.substring(0,7))" } clone_depth: 5 version: '{build}' platform: - x86 # - x64 configuration: - Release #- Debug environment: matrix: - generator: "Visual Studio 15" #- generator: "MinGW Makefiles" matrix: fast_finish: true #cache: # - C:\projects\fifechan-dependencies\downloads # - C:\projects\fifengine-dependencies\includes install: # get dependencies - cmake dependencies -G "%generator%" -B../fifechan-dependencies/build - cmake --build ../fifechan-dependencies/build --target ALL_BUILD --config %configuration% # show dependency folders - dir ..\fifechan-dependencies - dir ..\fifechan-dependencies\downloads - dir ..\fifechan-dependencies\includes /s #before_build: # git sh.exe conflicts with MinGW makefiles #- if "%generator%"=="MinGW Makefiles" (set "PATH=%PATH:C:\Program Files\Git\usr\bin;=%") build_script: - dir # create folder for an out-of-source-tree build: "c:\projects\build" - cd.. - mkdir build - cd build # generate build script - SHARED - > cmake ..\fifechan -G "%generator%" -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX="c:/fifechan/install-shared" # build - cmake --build . --target ALL_BUILD --config %configuration% # install - cmake --build . --target INSTALL --config %configuration% # generate build script - STATIC - > cmake ..\fifechan -G "%generator%" -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX="c:/fifechan/install-static" -DBUILD_FIFECHAN_SHARED=OFF -DBUILD_FIFECHAN_OPENGL_SHARED=OFF -DBUILD_FIFECHAN_SDL_SHARED=OFF # build - cmake --build . --target ALL_BUILD --config %configuration% -- /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" # install - cmake --build . --target INSTALL --config %configuration% after_build: # show defined env variables #- set - if "%generator%"=="Visual Studio 15" (set COMPILER="VC15") - if "%generator%"=="MinGW Makefiles" (set COMPILER="MinGW") # package artifact folder (shared library) - cd c:\fifechan\install-shared - mkdir bin - move c:\fifechan\install-shared\lib\*.dll c:\fifechan\install-shared\bin - 7z a -tzip -mx9 "%APPVEYOR_BUILD_FOLDER%\fifechan-shared-%APPVEYOR_BUILD_VERSION%-%COMPILER%-%platform%.zip" - appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\fifechan-shared-%APPVEYOR_BUILD_VERSION%-%COMPILER%-%platform%.zip" # publish an additional unversionized artifact (for being able to directly link the latest build) - copy "%APPVEYOR_BUILD_FOLDER%\fifechan-shared-%APPVEYOR_BUILD_VERSION%-%COMPILER%-%platform%.zip" "%APPVEYOR_BUILD_FOLDER%\fifechan-shared-%COMPILER%-%platform%.zip" - appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\fifechan-shared-%COMPILER%-%platform%.zip" # package artifact folder (static library) - cd c:\fifechan\install-static - 7z a -tzip -mx9 "%APPVEYOR_BUILD_FOLDER%\fifechan-static-%APPVEYOR_BUILD_VERSION%-%COMPILER%-%platform%.zip" - appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\fifechan-static-%APPVEYOR_BUILD_VERSION%-%COMPILER%-%platform%.zip" # publish an additional unversionized artifact (for being able to directly link the latest build) - copy "%APPVEYOR_BUILD_FOLDER%\fifechan-static-%APPVEYOR_BUILD_VERSION%-%COMPILER%-%platform%.zip" "%APPVEYOR_BUILD_FOLDER%\fifechan-static-%COMPILER%-%platform%.zip" - appveyor PushArtifact "%APPVEYOR_BUILD_FOLDER%\fifechan-static-%COMPILER%-%platform%.zip" artifacts: - path: '\fifechan-static-*.zip' name: Static-Library - path: '\fifechan-shared-*.zip' name: Shared-Library # deploy to Github Releases on tag push deploy: provider: GitHub release: 'Fifechan $(APPVEYOR_REPO_TAG_NAME)' tag: $(APPVEYOR_REPO_TAG_NAME) description: '[**Changelog**](https://github.com/fifengine/fifechan/blob/master/CHANGELOG.md)' artifact: Static-Library, Shared-Library draft: false prerelease: false force_update: true # overwrite files of existing release on GitHub on: branch: master # release from master branch only appveyor_repo_tag: true # deploy on tag push only auth_token: # encrypted token from GitHub secure: PklA532IBf2s4paPOoYBviN4cz1Dew9+Bce0aO6VaINDMCxDLRiNGeg3Jchaw03C fifechan-0.1.5/dependencies/000077500000000000000000000000001341577075500157245ustar00rootroot00000000000000fifechan-0.1.5/dependencies/CMakeLists.txt000066400000000000000000000104171341577075500204670ustar00rootroot00000000000000#------------------------------------------------------------------------------ # FifeChan / FifeGUI Dependencies #------------------------------------------------------------------------------ CMAKE_MINIMUM_REQUIRED(VERSION 3.5) PROJECT(fifechan-dependencies) set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/../../${PROJECT_NAME}/includes) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../cmake) set(CMAKE_VERBOSE_MAKEFILE ON) if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "default install path" FORCE ) endif() message(STATUS "\nWelcome!\n== Build System for ${PROJECT_NAME}") # create a "Release" build by default if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Select build type. Options are: 'Debug', 'Release', 'RelWithDebInfo' and 'MinSizeRel'." FORCE ) message(STATUS "Set CMAKE_BUILD_TYPE to default '${CMAKE_BUILD_TYPE}'.") endif(NOT CMAKE_BUILD_TYPE) # set a fallback download folder for dependencies ("dependencies/../../${PROJECT_NAME}/downloads") if(NOT DEPENDENCY_DOWNLOAD_DIR) set(DEPENDENCY_DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_NAME}/downloads) message(" DEPENDENCY_DOWNLOAD_DIR not set. Using default.") endif(NOT DEPENDENCY_DOWNLOAD_DIR) # set a fallback installation folder for dependencies ("dependencies/../../${PROJECT_NAME}/includes") if(NOT DEPENDENCY_INSTALL_DIR) set(DEPENDENCY_INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_NAME}/includes) message(" DEPENDENCY_INSTALL_DIR not set. Using default.") endif(NOT DEPENDENCY_INSTALL_DIR) # set a fallback folder for the extracted dependencies ("dependencies/../../${PROJECT_NAME}/extracted") if(NOT DEPENDENCY_EXTRACT_DIR) set(DEPENDENCY_EXTRACT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_NAME}/extracted) message(" DEPENDENCY_EXTRACT_DIR not set. Using default.") endif(NOT DEPENDENCY_EXTRACT_DIR) #------------------------------------------------------------------------------ # Display Status #------------------------------------------------------------------------------ message("") message("== Config Overview") message("") message(" CMAKE_BUILD_TYPE | ${CMAKE_BUILD_TYPE}") message(" CMAKE_BINARY_DIR | ${CMAKE_BINARY_DIR}") message(" CMAKE_INSTALL_PREFIX | ${CMAKE_INSTALL_PREFIX}") message(" DEPENDENCY_INSTALL_DIR | ${DEPENDENCY_INSTALL_DIR}") message(" DEPENDENCY_DOWNLOAD_DIR | ${DEPENDENCY_DOWNLOAD_DIR}") message(" DEPENDENCY_EXTRACT_DIR | ${DEPENDENCY_EXTRACT_DIR}") message("") #------------------------------------------------------------------------------ # Options #------------------------------------------------------------------------------ OPTION(FIFECHAN_DEPENDENCY_SDL2 "Download and build dependency: SDL2" ON) OPTION(FIFECHAN_DEPENDENCY_SDL2_IMAGE "Download and build dependency: SDL2_IMAGE" ON) OPTION(FIFECHAN_DEPENDENCY_SDL2_TTF "Download and build dependency: SDL2_TTF" ON) OPTION(FIFECHAN_DEPENDENCY_ALLEGRO "Download and build dependency: ALLEGRO" OFF) OPTION(FIFECHAN_DEPENDENCY_IRRLICHT "Download and build dependency: IRRLICHT" OFF) OPTION(FIFECHAN_DEPENDENCY_OGLFT "Download and build dependency: OGLFT" OFF) #------------------------------------------------------------------------------ # Check Options + Include external build scripts #------------------------------------------------------------------------------ IF(FIFECHAN_DEPENDENCY_SDL2) INCLUDE(get-sdl2) ENDIF(FIFECHAN_DEPENDENCY_SDL2) IF(FIFECHAN_DEPENDENCY_SDL2_IMAGE) INCLUDE(get-sdl2_image) ENDIF(FIFECHAN_DEPENDENCY_SDL2_IMAGE) IF(FIFECHAN_DEPENDENCY_SDL2_TTF) INCLUDE(get-sdl2_ttf) ENDIF(FIFECHAN_DEPENDENCY_SDL2_TTF) IF(FIFECHAN_DEPENDENCY_ALLEGRO) INCLUDE(get-allegro) ENDIF(FIFECHAN_DEPENDENCY_ALLEGRO) IF(FIFECHAN_DEPENDENCY_IRRLICHT) INCLUDE(get-irrlicht) ENDIF(FIFECHAN_DEPENDENCY_IRRLICHT) IF(FIFECHAN_DEPENDENCY_OGLFT) INCLUDE(get-oglft) ENDIF(FIFECHAN_DEPENDENCY_OGLFT) fifechan-0.1.5/docs/000077500000000000000000000000001341577075500142265ustar00rootroot00000000000000fifechan-0.1.5/docs/logo/000077500000000000000000000000001341577075500151665ustar00rootroot00000000000000fifechan-0.1.5/docs/logo/FIFEgui_small_c3.png000066400000000000000000000571371341577075500207040ustar00rootroot00000000000000PNG  IHDR;7^bKGD pHYsodtIME .79 IDATxy[wyi}F3ޝxj'N&+ IJK{{[h^A[ZН[J!P(dd88ؚ}rs$#mAXH<                                   lD!<|N ״Wo CdA/K !pG Pa,4pG9)) f)c  >Ե3@0), J-p|=y?8OվMe1P  bG*lOkwٗ/;y< ^AD!ri>e,-|CA;B1g-pVM/C'm@0=( j06} w>? Cqٳ -p?k s%5;t;ڿc W=. ؙ fƑ ߲/g 'p-|l ^AD^SQ*pG>9.K# bGx-peUrɾeuR] f$͸^VeBd_*-|²4 "v 8YI/_ w` ~YA;ԊIu3^,+Ry*  &G\U& YixȾ ;ڟPtmA#/p"xȌƱNJ ]ADr͇eEf /ڗKۤk 8 [݌ oؗ C;diAD'LX?c)IcA3N-pdU?8Ѿ!| ؙx-pTɪF/wﰅϷYYA;AaEnŊɪIy d5l_>hFkEYA!"͸YVMO[W덻du2?@0'K" bg:bX(ɥcy=sa,ӕ_wC#w> 75H"<y2 ˒ ؙjs=Vg+dE2NjO:ʹ.TVdOG %A3Ygnk&2/\'swqh]"~c^C1YA; +Z9 }aWk?bt8Je4َ"OQ onFIq9\bE|^ C, lg4G8B';9ӞfQG;ͥOmiwܿ-hJR\y8'Ve9ADho~8w ݌s%^yS)C8uϲյ.&5F{ďZCe-ea5b, <;z![ %K:|CT}t"7 ,Oqk3,_Sz̡(?%?`o4!oTVљ);_ĚkdAR]r AhN@!ދFJܨNz?[Qה{2F<^^HcďvEzа`yo!7Jy d'?iYAY,vmP+3?Η:OFLB쨴lM7=>O^q.Um\@SkX.YADÚ$!@Ë F*GM"U0o{2RUe/ʛ/]͗ \blG)pSo!+Z8q'^ %A8 hNJ|hV8d۳طmd)nz?;7O897~|3#i,mߠ?Zte5w!ނLR\EJu=d "vQH2Uʼn=vNI +rOJ6ʆ-M%g'x{o?:SGGE}4T]m4L(ÌOcE| Cc$ ؙzTղ{c/LU G-c(WJyr pG`RUvm nƆ4v翭ke(6]ke-ҵY;+pVaEo6.)3Gփ.QBmDV *l[,U5QbQv01tZ+M$#@f%+i"kZ/[$]A31!pn(x\={G0 TNK[׵&g̱avo sLI WGuMC[-^@]c4T -p Wms;2tB DE^EJ\+q?ak=h-pq Oq-,[- .Xў/lۗ2R'K(vxr1]Σُ5on[\r(sLJvo&NcMȉ** Ħ-4 o4b>MNf)~-[ZDoOwͲm h*o a!VpP h}ޏ,) kPٷm\1 %rƖr6mmaæĺ77q&bNhHOڴM Oin}Fmd, R"v32c]:.ŰNB̸[,[]˦Y.،ݵZ%+j%2fbZ`*o9u5s}XF C= ؑo=ɛ/Ŵ%r|*YJ-r ^-M4q Z;y˸l{z}ݑTGii]cm&ofǏ/qzo!ni0$%aADL]n?:9o W26lnfu W]fęcC3dž莝*8yhhh) A*aADQe~pמb3]\|8T*!z0"BgɊ6nifGJ:dte-KW^'rzԖ&t){",ˋOξHEpRm(Xwm#Uv*.D(+as3W飃'GWJ䀝Rm7gѾ7ҹQ^z?h* :IUWPM,t4{8f/CQk,1M sZ՛z/Пmf~yK1_|iŚV6־hAsC;xћIDr2:P[_Xw]>QӈijN\83j{׶򎲵.޶dqH % 6kv湰q^"/=IיQE:h[R-ͬX['}]f 1~Q3)rt<6|`1TnE :)G "v ;ڬ>^';|Jٍm+V]]φʹ.#p0:Ю>ax0VI4q׃Y{}lOqf9ALW9ɬ-_}{w/=-v 2뛨] dzJ¦9qh;z:7ա0~ˁ{Y;\&@2Ĝ,¬e";7;f"EME^zS#-mFn]\ŦY^l!.e=;8@< U5~nyo!- gU˞ANbˤ~}j&6DM}]xLs`?衻k]|e5w>-hܘ/q} :${Z;ʼn8S"1yKD'ͭl tN(jGu,Ҕ 23L`ANb緀/MuGxN^}h `:6̢咪2֮^X3> CqͭVk/n=*le:LkE։yv1.qզ_D]RU%xPSg\co ppg/CMS{[7utU w= /3{uu3x?k_M+Ep{m/N9zh _D#GY}3OtL ` lldF:OspW/g:{l#T֖z s-leK|EO]1oYuSճ|}fAuN w֕@yr8g.auM,^^H01,fjϯóS 4?;MyNۢ*Fm}Iu0|;zm&vƁAsybgZr<.vɛ3!1bgRArچi CQc ؙ8(4-k[\5WQ#Lq :7RLsAl -6-0:.>nJ9zG7G{g"$#~AD\`7~XQr3o]c3[Q$dEkChǪA v%;Y-oL1:dO3(Cq΍rզV0s҅Q졿'ij"kT B_(X-1`IAD\>,ߖ+|< +8z/dvUV'iǹSìDۢ*9FcK̸ ֶ)6miZΡ@046GvwݳxON.CEܷǞi MY> L씜 134EzckaXb(R ػ#LKk%nVG1ͩc91D,1Je)K8;Wױ6[*P\:]V>ޛSY"d?8EǞ /"C GQʊ fS"'Z'-ZE_8_bRy #<:8J[} ,[Y*;PP: ؙ PW.cўFgZZ۪Pb癳 E9}bhҗφش6~o(bGav]"v<CQvA%-`i5}t9"&RpF{5!zGY:Im%Q G45h:>XM[%9TTG)h0XXFYD5"0N}~R@<QYOEwN~F ,[Yˡ=}8<LeYiTg|ԩAikLR[5==tGEM[8"8Z>KĴ.d)+őL9h =.;%'[U5~ (\⧬`Í,_SǡݽFi-KXQ˳12̙*hhRYH1IDqt|M,ZVi)zP0-IA;%;C,rDt(Jm֕qc{+Qgl4nUl)Pѱ TWDc&㌍m_0#;|m=WS&!tHV9'Kɂ sDnϛD2J*RfeBhis9{bSAU9+Ĩ*LDkxQ󱝺24`h X*՞ 45(8I%)p}g)_O2VY1褢=)Ad%kh]PSt_uxi-[ĵfh,ByA?6fD4'g,#ɒqa>V֖qŊ:j1 g&udMc٢gh MASbggŎRI`=:I3+[)wǕh[XŹ3C ido붸֌1ʔ(ϴFs&J6n iڽrN[Y`j[+Mbt cg*i)Gxf{E<ygOwSrZw+)j3bfa**šϪ5 EtqxLk);ڣ}&Q1QR 1 qGl e-U:䮴r Ϩs1og"קاگ+r}f;ٙUD E%ZGt+Hm)k4Lq7SS[N_W3B#ь04TG4)E)U+T&e>NuAv@%e>;e=E E_G9L;GA̓px"V$ìLqi, J*-H *l4ua}2=;-~ADL`H;wTxUh InVN +CsS%&:Q"Ee8IaUT0|Vkәr1Amj[8*HrVWeKgKS~#0";ҊVX]o9AUۢm>=ŕR\2]%Hq3Ĝ~ v0τrE]Z31MKfL&+|>*~9qDS8JS%|4 ChAFQJ1Kz6#9u!18S\rO'ʀ2"!s`eԵ+e(OTv |T1(WTV4V5#ّ "v#=K{Ȏr6tS7'O*c )zG D{mb6^=5>j>='HHVF 9vާ}s|JEزDMRs?grŜ,)-` ,VT32:$K]@ٝ)ެ=R\ Y) ?%pEa޼E\<1NϹq8nhM4M{chJM0AG ˔13Phk@4o؉A{b' {JiH *52" qfemGWGi j|MUq{y_ҫiGG]Vit]5MmN+3P\ذ&:l/8S,Ŗǒ?:ؙ(ǀ'y/r}Nq߱"<[׷h%Ԏ/iaK?FN IDAT&s$DY 1ܞ8`p,FU&JkY[5~ַ7{!©C /a(]UŒ3uhh wq\b'Zj˜I{T4xvЉ9zGvJJ"]Ĩgzst*BiVNF3(6Fj ZVPQcSZ[XqM Kț;<2'޺2niae>k;8]VwEu4rPIoRs#y?j? IߎAJmt{RTUb Pe3+ nVN lx2?6hr m^QɴRZ?̊M 9qЖWeW׀DNv +'UV>>3ݭ:Ox>NQUYT@xF; sLpGR=gy[o(mK*##Rvxfw%~.Da*ZU'+wߦEBf˽N?2c- ˔m@9Vyx'nn*k1*BEE XށDd+J-ݓݑLAaVNKq דGP`#tg4N̆+6rյ|Cfg*nxW ued DWoC0Iq\#1qqM9y8, )7̏Uu(:(?4+vU\!ӛ,]אQS 9͋*Xqm-UuʭČ)4vs=;}ַ=ƌꗓ_h9tG0MF,< DhNq4 =`HZr bbdHI"c]F|f匈NBd%|=Rqz:#,]W͕jӚ:FPԵqGq(>~3(0]-lɊb1gZYѝsc5H*eUxLK[j+Š,),AD[&`Zдވ`$%GR\d-?O=R\ٌv45ytԱtmMǎb~Wp>?}i< om[ɇ}]JQŖ.bm3{brPDh[^=k쉗$:J%N4bGazObPCvE kx0/~ݹ> .ևSQIt<1B{K6QB%k9-5ww9T^*WbG "vW<\'klQ}E9U~%b6+'I.r"%\RM=z؏GЎJhW{푥,_ƪ[y3L?Z#+i^TmMJ:#:V k^ș&~.5Wj*RsʭD4².M%-;+ G "vv.uOYXGyoFᡉSxuƀP&rwxn0_:ʊ 4VJ\>kZ̋Wh^T;>6[IqRXd̘vTX&X)5W(5/*+Oy"eR G<#h%_G;3 S:8 E2+ey24${QfeN_9dfu|_?'w,R^e*is#7ܻ\w klUɪ190TgV{W 4ЅpG{'Z DM"q+|=1N1Iў)fឞ).5C̖r&Nz>|%o[|)#]&\dA{xj;cv*{(6ʞ./T@Lܳǎc%,bG;3$Dv\郔XsybA%ŕլδSr1I(On)_[Œ5N?sTFYt52#_'8y"Rs򘉧B\ΐAgcpnATb1}к% Cc۬q]~Iz-:2ʩTQ^r?Snt!ݬew~h͕ngm.hM| ۟Nd'CuNjoQd+3BGD{Ka:1fS@OIço*w*)H{CrE$}~1,A1Jyst&N|(cor~Ȋk&\MOyb s.#Ay'vlJ `o$ˉQNSx7x Ucd6d9qfN.%Y:Hebb/jy[ Y=s ,4+'K˽ʮ?~<&?keKK+5WYJFϜI 1a`oԭ57{JA";3N씻N@VB34+.=u "pJG#G(V&J]iGV.3 \ M걣?uA9 *Z'U2O|Ř<]T 9Ee@*}YLMqt\hJӷ}7ٗWb_G;3@0TNMi'Iv\њ"iF_[+E""+[JP2i{ ܥMq.9( 1*"Uz^|K_#[n2'4=豓=U>jJJĎ @ xE`V0ϲ lz.?FD㔕\  Cc& z7tN\ SFh$"11S H TjHЖŊA)ef>4_1!5M+zǭ6Dh[J COk ٙbgiJ?DzgV.$ufBR@4HKqgǜ=6s;:J bgSjƂ>I>EfeǗSY͹E / Ncrʨ^>KURkLcuG3*JXv.bGylKcʳNvڱL3nd; w<RϨ9*mWrsx 4&Y]2uRl*qLcGM;*D⌍ŧ3#~!O\5i8W59^a bgZ Cc5S*vZ-Jd\Kdh<Nу!M$<1x IrPC99^,14cr;T5VJ0=͎Rs\bvFvD^< >z_s.:nu [&I>vؙpW֗M@_)v #T|12!7vx3g<쳃Y|QjrկgK  fb%ޖ=!ہ t!A$S28(mVV^ 543sd;AgO7ֲrچ2hSٞ)qݓev6$fVˬh˛NLl0+'}= C<Ďd\\jRӇLFQEΥH2jpJQv.QADHd'7Mm G4V!ӐDC$EMNv6&ì$LJfe*+0ûóӬl<4Rs&\(5W)<*k*Aox<#%_GyϬNc@T>G}2O,l#G)\t<^lsRs<>ۜ(MS_%bG;s5L釹3͐8Ta4VG" gxʦJ NHRscK嗚ܻRtGujʴ̘A;a*= ?LScjFL=S|{QfeH 9#򛕍|gϪhifq;M!ȟJ/57Ԝ))5Op0oKߚl  ǜ "v$E/?k2|s'x MO)f͑ + =%T`ywa@=KDg1J:.?OcTDX<>>EDZDuADd C_ C1K8}/^*BE$44=ww7马J54#:X;Y5 &+57p'ɶiCۀ-ǁ.; "v9 M\~+ u;n<ITft?>+Owɑʝ)_NFtbP3\X4.ao{u8S:8|#@0d>D&#0N 2=ǁw| FOdt$y"LisvTHyFP0+;oEPΖ_h/8~` o;8nMχ{5˯q4C'wlB5ixpǣӇBǣQ35慙'*+[,5?q31|>vxdɐR<<;\]}) 8AJB׀g pGs+7W[r̒s.O/?ՙ<}BfS\[4;)5/UUVRG>;S϶ ~g wy:OyZ,|'AD!ps =5=ȹ:<:q{u_<+0|ʕJǢ&} rGwOFxru*Ӣ8 y esesTFRsc2z\^UVRsᕧ;??d0SӜM[/_NJu_)vyO, } X|H/bGa@9@0Fh"]wC\Cs[}R#}|s`!KT=iV:ӳuY%M` 1c My;<u;K,jZ۴ ~멮͚1^ |# wo#zo? \;v>_ CC:;8 w 3-_S˧u\{ks2HcX?6/=%UYxA bf4s1ڴ#9>;VdGOJ9:L'yK1r 3D<4Wws7U;u w?VpGW =X{ ̃Ȏׇw`Oph=nqq_!AD+ }K wrD`aE2:AN<^ъSK^g& n1QyFכW42?0/|Nϖ3xWVKNu w?GbW( KU@0RSh VCKV{-2,'" F'?լG`9Ꞝ/-_fI.5?yh[?ĝc2ea%~>WfEuPf\9 J,a`Xn&ƣOꄮ-Ǔꃣ=wtG2XxR2dkW4(pleZk^yW>O޻^a(J:::OĽ~͑rik)K>#(GYs愨1r^p_O{ykz SӺ]Q=]~`G1&\&5]OnO Im|V ;ITP=۳'? ՙ>^qU- DSd. İۜ%Ďs374Ԧj 2 +jq/J[S"%K$gjR\^g 2>eZʍ/57Rsl{שi+fd@0G>;P|y`hř}6۟ĒR.M\s_!ٗ9P 2UC1)2y қj١WVO1vvrǡ#Xʙ*t7AN!Qz&x\O 2(Rno/#3j'*̬|q+VSVP&a #x2>LL5|khYP1S`cKȎ >@0S7UK)PwrёJcͫ2V|9#< WZhe5-+ {Fc$kѶV̑5KJtdL*3!P3yN')pLI߳r|ˌ,HR.9- K"HdgFxn2. 9CIrWgrMY͉jV>pyuMTTRj3\:?ThSSQ75CTcoJ+̹ +A3 3q̸gxNkU0%"ni/7&nV.0ŕ~[{{flTVJ^j~xO??y19:5=񺖭#\MSM[E~S>(veD.<1S>c Œ"'XTJW?ޜ,Q|lat`W7Cdg6\BE/0/57㚗"'?oC`eyw 3L\>|AH3;OmͿ=ʉOJx#KpSe90k7|/ϗsTZ L< 猢.!@coJųPZV|p+- N&GsN>C\(-+CwFF)9d؉[Lzk|/;Xxj:N7eLv,#>;^|r=-Gv_5c->-ٍTnv2 Ln vМiʒRܙ9U;x?3??_)$}AG ;Gmp2-_5_U_DIZ~^4psk+ky45䞶:7ϟ‰ťyiA=iO4a(/K74lY{рAELZ7v~e׎Օlِ5K (ǩI+2,I ; = ji5AEEj۰Q;$FMVaTk$Îy [%ɰRi UYxZ6c7_gK$vt!p}֚b*^^˿0~sMf $k0sN$ɰ =7wƭ]|=w=4싇sm e`FFGJaGx~SjwkȜ/MqǁA%ɰ <2`H֚~.%qۃ0'I3 &X! I2x8ہYA*$<Q Ykm1HaGG>4[= `jFoZ9#Ɋ n{ "zB ;s dm0j*$ɰ</íaV$v3odkcv hU!I/ ,!cK WV$܍cA\8Ӡ#IrdHV 5*`zF[ Iao⣸Wad$X}JF?B ~@$iGvdE)wj>J>r; %I' }GGma.I2}gpq5"fkKrqNQp}&}AGO%_G|%0#m$ɰ3x ZlQIaG]e@KF߰%I/L$5}RL \B[Odс!GxہAV$uRA\<mБ$v Azkl)IҡpK$+oyP v2$Îz2\D#X/afH ;g) k+H ;3 \S־$ɰxޱ՛˂0.I R0zxfpAGԛ~%+ voK0j K ;ʇs (遗[\Q5+ImNca(p!_n`AGt8(?N1vKAͷ%I{qOifa'I2(.g a&I:\n ¨rYM2O$qdG,YQU7g YC$ÎBx sAX3$/Ɋyք$I$I$I$I$I$I$I$I$I$I$I$I$I$I$IR?EI(VIENDB`fifechan-0.1.5/docs/logo/FIFEgui_small_c3.xcf000066400000000000000000002072001341577075500206640ustar00rootroot00000000000000gimp xcf file;B$B$Bgimp-image-grid(style solid) (fgcolor (color-rgba 0.000000 0.000000 0.000000 1.000000)) (bgcolor (color-rgba 1.000000 1.000000 1.000000 1.000000)) (xspacing 10.000000) (yspacing 10.000000) (spacing-unit inches) (xoffset 0.000000) (yoffset 0.000000) (offset-unit inches) gamma0.45455000000000001;FIFE_small_c3.png     k;P\ht;O 8"60x<JSch hjykalq*uWgwU 8 9 I Y       0@ =963 0-*'%""%$$$$$$# =963 0-*'%""%$$$$$$# =;9;6;3 ;0;-;*;';%;";;";%;$;$;$;$;$;$;#; = x8o6g3^0 V -M *D'<%3"+#zri """V"%"!!963 0-*'$""%(+. 1 47::za8ݤlbbc6͑dccdee3~bcdeffgh1ߦncdeffghiij/ϓecdefghijjkls,鼀bdefghhijkll*obdefghijkklm)ѕebcefghijklmt&꽁abcdfghijklm}$o`bcdeghijklm"Җc_abdefgijklq 뿁]_`bcdfghjklz n\^_abdefhijkԖ`[]^`acdfghjn963 0-*'$""%(+. 1 47::t* 8] 6F 3y. 1` /I  ,{1 .i*c A{(K !S&}2 ,d$d =t"L  N 2 )] d 8mK  G|;9;6;3 ;0;-;*;';$;";;";%;(;+;.; 1; 4;7;:;;-;:;9&;8;5;6;.4;:'2;6 0;/ ;,;:("3;*;6 )55);0 .44&;:(!133$;7 &33";1 +2 2 ;) .1 1;7 $11;2)00,8$|6s3j0b - Y *Q'H$@"7.&~u!m#d& \) S, K/B29518(<0*  $     #&;;;;;;;;;;YY9YYn6ט\YY0ĄZYYn,qY Y`(ٜcZZ[ [Z[#Lj]\\]]^]\rv]^^_`}Δd``_^]e۠h__``abeާobba`_`a`aabbcdo幀ddccba`wabbccddeeff~ ʓifeedcbaajdefgiإrggffeddccbcfgghhirീihhggffeddcb{ hijjƒkjiihggfeddcm klӢskjjihggfedcd "ڱlkjjihgffedc~(nlkjjihgfedcn*͟smlkjihgfedce,ծmlkjihgfedcb.ﻍmlkjihgfedban0Ǜsmkjihgfecba2ϩ|lkjihgedc4ҵlkjigfe7pkihg9ɣwji0*  $     #&;;;;;;;;;;:6O206g,l N(S 6#;lp$ -xI SY   Fb    <@   ^x1     &q .t G Y E^ B[s1 +u /oF ] D[! F W"m0 .x(C `*V! H,h/ 0{.x@ b0Q  2a+ 4q;7K9Z&;;0;;* ; ;$ ; ;;;;;;;;;;; ;; ; ;;#;;&;;;;;;;;;;;;;;;;;;;;;;:;4;6;3);2;+!8;,;8# 2;(;3+;$;,  #8;;9$ '/3;;4.::5 ,;;4998' $9;;%89 9.4;;,883 -;; 2887&&9; ;$577,5; ;*661 .; ;06"64$':;;(5* 6;;*5/ /;;,42"':;3.3' 303- 2220 151%171* 090- _c؀(/ Whx )Nho#Fhf= h ^5 h U hMhDh; h3 hڂ*hz"h!qh#hh&h8h8h8h8h8h8h8h8h 8pm08<96 30.+(%""%(+-03 69<=c;a`_8cba_^m6edca`^]`4gfecb`_]\Z1<96 30.+(%""%(+-03 69<= I; 0|8 c6  I4 /~1;<;9;6 ;3;0;.;+;(;%;";";%;(;+;-;0;3; 6;9;<;;6;=;0;;;(:;8; 7;6;1;4;);2;`;W 8N5F2 =/ 4-܄,*{#'s$j!aY !P$G'?*6-݆- 0}% 3t5l8c;Z = <96 4 1 1 1 2 2 2 2 2 <96 4 1 1 1 2 2 2 2 2 ;<;9;6 ;4 ;1 ;1 ;1 ;2 ;2 ;2 ;2 ;2 R;I8A583 ߇*@@ D*p*p+p+p}+pK+p+p5@ 5555555 @ @4@$@0 $0 $0 $0 $0 $0 $0 $@4 (@@ 1 1 1 1 1 1  @PPPPPPP####"""""!!!ˋ^YnYYYYYYYYev   !!!"""""#####$$$$$%%%%%&&&&&''''####"""""!!!>/EZp$9Odz   !!!"""""#####$$$$$%%%%%&&&&&''''#;#;#;#;";";";";";!;!;!;;.;;;;;;$;+;2;9;; ;;; ;';. ;5 ;!;!;!;!;";";";";";#;#;#;#;#;$;$;$;$;$;%;%;%;%;%;&;&;&;&;&;';';';';!^!,!   e 3 l: sB{I    P !!!!W!%!"""^"-"###f#4#$$$m$;$ %%%t%B%&&&{&J&''''QYZ[]_`bcefhiunYYZ\]_`bceghט`YYZ\^_abdejÄZYYZ\^_abdppYYZ\^_acy ؚbYYZ\^_c ņZYYZ\^h!rYYZ\q#۝cY Y[}&Ȉ[Y Ya(tY Yk*ܟeY YZx-[Y Y_/ Yh1Yu4Yo5Y\3 Yb2 Yl0 YZ{.YrYY[]c,YeYYZ\_acn+Y]YY\^`bdfh{)Yu{[]_acegikn'Yhp`bdfhjmoqv%Y\kehjlnprtv$Ykkmoqsuwy{"Ynprtvy{} Y|tvxz|~Y{y{}\YY}~lYY}}YYpYYcYYYYټYYZYY[YY[ cYYZ\ tYYZ]~ YY[]qijYY\^eǬYZ\_aȣYZ]_aĘY[]`b׺Y\^`cٯ\\^ac֢k\_ac|]_ad]_bds^`beh^`ceg^`ceh^acfh_acfhgadfiwadfiˆbdfi~™bdgiq©bdgikºbdgikbdgikbdgik2 #Vg 0dN  ?s5 N~k '\ Q  6j 8Du!nS|#U +a}&}; :lz(zq" Itx*xX %Xv-v 4et/t Cmr1r!Qo4o_m5m4fk3k Ci2i Qg0g '[d.d5 9`b,b>|Q G`+`0~{u< (R^)^!}{xi( 6W\'\~|zxvY $BXY%Y}{ywusI"$/JW$Ww~|zxvtrk<!#&(+:PU"Ui~|ywusqoa1 "%'*-/3BQS SZ}{xvtrpnlU*!#&)+.136:HPPK~|zxvtqomkhJ)(*-/257:ACHLL,~|zxvtrpmkigeZ=258:=@BEGJKJJ-~|ywusqomkhfdbR<9<>ADFIKNPLHHC }{yvtrpnljheca^M>@CEHJMPRUSIEEX~|zxvtqomkigec`^YJDFILNQTVY[TFCCny}{ywusqnljhfdb`][UKKMPRUXZ]_`QBAAj~|zxvtrpnkigeca_]ZXRPQTWY\^adfcL??[~|zwusqomkifdb`^\ZXUSUX[]`cehjmaF==L}{yvtrpnljhfca_][YWUSV\_adgilnqs\>: :̷ =~|zxvtqomkigeca^\ZXVTRS\cfhkmpsuxuT98 8˷".}{ywusqnljhfdb`^[YWUSQOVeilortwy|~tJ6 6ɷ7|zxvtrpnkigeca_]ZXVTRPNN\mpsux{}m?44ǷM~|zwusqomkifdb`^\ZXVSQOMKOftwz|b622Ʒb }{ywtrpnljhfca_][YWURPNLJHTp{~U//ķx z~|zxvtqomkigeca^\ZXVTRPMKIGF\{E--· l}{ywusqoljhfdb`^[YWUSQOMJHFDGhu7++ ]|zxvtrpnligeca_][XVTRPNLJGECAMwe-) N~|zwusqomkigdb`^\ZXVSQOMKIGEB@>WS ?}{ywtrpnljhfda_][YWUSPNLJHFDB?=>f- 0~|zxvtqomkigeca_\ZXVTRPNKIGECA?=:BwB }{ywusqoljhfdb`^[YWUSQOMKHFDB@><:7MX }zxvtrpnligeca_][XVTRPNLJHECA?=;974^m ~|zxusqomkigdb`^\ZXVSQOMKIGEC@><:8648r }}{ywurpnljhfda_][YWUSPNLJHFDB@=;97531A n~|zxvtqomkigeca_\ZXVTRPNKIGECA?=;86420.Q ^}{ywusqomjhfdb`^\YWUSQOMKHFDB@><:7531/- N}zxvtrpnligeca_][YVTRPNLJHECA?=;97420.& ?~|zxusqomkigeb`^\ZXVTQOMKIGEC@><:8642/; .}{ywurpnljhfda_][YWUSQNLJHFDB@=;97531O ~|zxvtromkigeca_\ZXVTRPNLIGECA?=;8642d ~{ywusqomjhfdb`^\YWUSQOMKIFDB@><:853y }{xvtrpnljgeca_][YVTRPNLJHECA?=;975 ~~|zxvsqomkigeb`^\ZXVTQOMKIGECA><:86â n}{ywuspnljhfdb_][YWUSQNLJHFDB@=;97;* -00;8!".//;2&..;+ +..;8"  ,-- ;3$-- ;+(,!,;9#  *+#+;4 !+&+;- %*(*;9$ )***5 )-) #(/( &(1( '4' !&5&$&3& %2% %0% !$.$ "#,#+ #+#+*)")" ++**$ "'",++*))  !&!,++**))(  $ (,++*))((%  " $,,+**))(''"  -,++**)((''& -,,++*))(('&&% --,++**))(''&&%".-,,++*))((''&%%$  .--,,+**))(''&&%%$#..--,++**)((''&%%$$##.-,+*))(('&&%%$##"!#)..--,,+**))(''&&%$$##"! *#/..-,,++*))((''&%%$$#""!! !!1//.--,,+**))(('&&%%$##""!  !!"#!80/..--,++**)((''&%%$$##"!!  !"#$$%  ;0//..-,,++*))(('&&%%$##""!!  !""#$%&'& ; 00/..--,,+**))(''&&%$$##"!! !"#$%%&'()& ; 10//..-,,++**)((''&%%$$#""!!  #$%&'(()*+%;100//.--,,+**))(('&&%%$##""! "%&'()*++,,#; -100/..--,++**)((''&%%$$##"!! %())*+,-..,;')110//..-,,++*))(('&&%%$$#""!! !(*+,,-./01+;.$1100/..--,,+**))(''&&%$$##"!! $+,-.//0123(;52110//..--,++**)((''&%%$$#""!! '-./0122344$;:22100//.--,,+**))(('&&%%$##""!  ,/012345562;;321100/..--,++**)((''&&%$$##"!! $0223456778;;322110//..-,,++*))(('&&%%$$#""!! (34556789;; 3321100/..--,,+**))(''&&%$$##"!! .567889;;3322110//..--,++**)((''&%%$$#""!! "3789:;;#.3322100//.--,,+**))(('&&%%$##""! (89:;;*)43321100/..--,++**))(''&&%$$##"!! .;;1$43322110//..-,,++*))(('&&%%$$#""!! ;;8443321100//.--,,+**))(''&&%$$##""! ;;544322110//..--,++**)((''&%%$$#""!! ;; 5543322100//.--,,++*))(('&&%%$##""! ;;55443321100/..--,++**))(''&&%$$##"!! ;; 65543322110//..-,,++*))(('&&%%$$#""!! ;; 365443321100//.--,,+**))(''&&%%$##""! ;;'/65544322110//..--,++**)((''&%%$$#""!! ;;.)665543322100//.--,,++*))(('&&%%$##""!! ;;4#7655443321100/..--,++**))(''&&%$$##"!! <ͯ>????????????????????????????????>;97642󒮿0/-+썴)ꆩŹ(ç&̱͓"ᅸӽިʡ}}֭ڛ{{໓ˋzz~˚~xxܦyx x綊הx xĐƆxxzԙ}xxᨃxx鷅ӼȌ} ט~~}{ }~~|zy칁|}}|zx}ˊz{}~???????}?z?x?v?t?r?o?m?k?i?g?d?b?`?^?\?Y?W?U?S?P?N?L?J?H?E>CNA;AJ]`?9?E[gdb=7=?Wlkhfc:6:Pnromjhe848Glxvtqnlif626>f}zwurpmjh4046\~|yvtqodQ2/2O}{xunVKM/-/Ay|w^IJLN-+-5lhKGIKMO+)+-]vPDFHJLNP)()KZACEGIKMOQ'&':iCACEGIKMNPR>$"$+pyH>@BDFHJLNPRTz.""#[R;=?ACEGIKMOQSUb"  Cb9:<>@BDFHJLNPRTVJ/崲v=79;=?ACEGIKMOQSUW3 i巶F468:<>@BDFHJLNPRTVXq"OW2468:<=?ACEGIKMOQSUWYY 7m213579;=?ACEGIKMNPRTVXZ-e@ &{߷9.02468:<>@BDFHJLNPRTVXZ\,*2{,bعF+-/13579;=?ACEGIKMOQSUWY[]-+)'>lIֺZ(*,.02468:<>@BDFHJLNPRTVXZ\^/,*(&$PS2Ӷp+')+-/13579;=?ACEGIKMOQSUWY[]_0.,*'%#%gyЇ5%')+,.02468:<>@BDFHJLNPRTVXZ\^`1/-+)'$" -ΞE"$&(*,.02468:<>?ACEGIKMOQSUWY[]_a20.,*(&$!<ɽ\ !#%')+-/13579;=?ACEGIKMOPRTVXZ\^`b420-+)'%#!S¾s% "$&(*,.02468:<>@BDFHJLNPRTVXZ\^`bc531/-*(&$" l؍2!#%')+-/13579;=?ACEGIKMOQSUWY[]_ace=0#/>/.-?,+*?)(?'&%?$#"?! ??~;9! 7##"! 6$%$#"!!4$'&%$$#"!2#)(''&%$#"!0 **))('&%$$"/*,,+*)(('&$-(/.-,++*)(&!+&10/..-,+*)#)"12110/.-,+'(/433210/..+!&,665432110.$/"'8876544321(::*"7:98776543- :;<:%4<;::987653# ;<=>?8/?>=<;:9886( ;<=>?AB3)@A@?>=<;:9/ !<=>?@ABCC-!>DCBA?>=<;5  !5=?@ABCDEFB%9FEDCBA@?>;' !!%<@ABDEFGHI? 2IHGFEDCBA?. !".ACDEFGHIJK7*HKJIHGFDCB7 !!"6EFGHIJKLML/"DNMLKIHGFE?$ !!""!?GIJKLMNOPI&>PONMLKJIHE, !!""*FJKMNOPQRRC6QRQPONMLKI5 !!""#5LMNOPRSSTTSRQPOML@ !!"##?NPQRSTUUTRQPOI( !!""##&IQRTUVVUTSRO2 !""##$0PTUVVUTS> !!""#$$ihgedba_^\ZYl/lgfdba_^\[YY_-Ürfdca`^\[YYZ*Ǩ}eca`^][YYn(eb`^][YY`&k`^][YYZ# ¡u^][YYq! ^[YYbbY YZlY YszZY Yc`Y Y[jY YuvZY Y_YYYYeYY^pY Yo~ZY YaY Ym^\ZYYbYYzca_][YY[YYkgec`^\ZYYwYYsljhfdb_^[iYY~qomkigecaeYY 顉wusqnljhfeÀYYf 磑~zxvtrpnki{tYYw 昅}{ywusqovhYY䜍}zxvtu\YY㞔~|zwŻYY♑}ƯYYƣYYǖYYܚȊYY]ܢ|YYmܤqYY~ܦdYYܧ[YYۨ˼\ZYY۩̰][YYۥ̤^[YYן͗^\ZYY؟΋_]ZYdؠ_][Yuءr`^[Yآf`^\Yأca_\ZؤѼda_]Zؤұdb_][إҥeb`^[ئәec`^_٧Ԍfca^n٨fca_٩sfda_٩ifdb_٪igdb_٫׼igdb`٬ذjgeb`٭ؤjgeb`ڮ٘jgebiگڋjgecyگ~jhecڰqjhecڱljhec e/wC K-R 2*`+ h(n:  O&yH 6# ~V"l! e0 S}p> 9zvL ox[' Uvh7 <toF #rrT# }o`1mj4kIiV g_+ 1dc; FbJ F\`U' 8thq^Z7 $gz|Z\D  Uwy{}MYM, Crvxz|~> WR8%# 5jsuwy{}0 UTB.)'$"*^prtvxz|~!% SI60-+(&# #Pmoqsuwy{};PL?741/,*'$""Eilnprtvxz|~PNMF=;8630.+)&;9636Odfhjlnprtvxz|~YHJNOLJGEB?=:8I_cegikmoqsuwy{}JFPUSPNKIFCA>FZ`bdfhjlnprtvxz|~;ZWTROMJGEFT]_acegikmoqsuwy{}+^[YVSQNLJQ[]_acegikmnprtvxz|~/_]ZXURPQWZ\^`bdfhjlnprtvxz|~ Da^\YVTTWY[]_acegikmoqsuwy{}Zb`]XTTVXZ\^`bdfhjlnprtvxz|~xod`VQSUWY[]_acegikmoqsuwy{}j[PPRTVXZ\^`bdfhjlnprtvxz|~[NPRTVXZ\]_acegikmoqsuwy{}LOQSUWY[]_acegikmoprtvxz|~=PRTVXZ\^`bdfhjlnprtvxz|~.#QSUWY[]_acegikmoqsuwy{} 9RTVXZ\^`bdfhjlnprtvxz|~ NSUWY[]_acegikmoqsuwy{} dTVXZ\^`bdfhjlnprtvxz|~z yVXZ\^_acegikmoqsuwy{}k WY[]_acegikmoqrtvxz|~] XZ\^`bdfhjlnprtvxz|~M Y[]_acegikmoqsuwy{}? Z\^`bdfhjlnprtvxz|~0 0[]_acegikmoqsuwy{}  E\^`bdfhjlnprtvxz|~ Z^`acegikmoqsuwy{} o_acegikmoqstvxz|~z `bdfhjlnprtvxz|~k acegikmoqsuwy{}\ bdfhjlnprtvxz|~M cegikmoqsuwy{}> (dfhjlnprtvxz|~. =egikmoqsuwy{} Qgikmoqsuvxz|~ f!7;/;(2;-;.+ *;+;.-! "8;(;-%3;&;-)+;$; ,+  #8;!; +"3;;+' ,;;*) $9;;*  4;;)$ -;;(& %9;;( (;;'"/;;&%6;;&;;% ;;%" ;;$# ;;#;;#($%;;"! #**+;;" )**+2;;! '))**+9;;  %())**++;;  !'(())*++,  ;;  &'(())**++,;; %&''(()**++,,;; "%&''(())**+,,)!;;%%&&''())**++,,#(;;$$%&&''(())*++,,-/;;"$$%%&&'(())**++,--5;; ##$%%&&''(())*++,,--;;"##$$%%&&'(())**++,--.;;!""##$%%&&''(()**++,,--. ;; !""##$$%%&''(())**+,,--..;; !!""#$$%%&&''())**++,,--.-;;  !!""##$$%&&''(())*++,,--..($;;  !!"##$$%%&&'(())**++,--../#+;; !!""##$%%&&''(())*++,,--../2;; !""##$$%%&&'(())**++,--..//9;; !!""#$$%%&&''(()**++,,--.//0;; !!""##$$%%&''(())**+,,--..//0 ;; !"#$$%%&&''())**++,,-..//00 ;; !!""##$$%&&''(())*++,,--../001;; !!"##$$%%&&'(())**++,--..//00- ;; !"#$%%&&''(())*++,,--../001(';; !""##$$%%&&'(())**++,--..//001$.;; !!""#$$%%&&''(()**++,,--.//00115;;!"#$%&''(())**+,,--..//0112;;!"#$$%%&&''())**++,,-..//00112;;!""##$$%&&''(())*++,,--../001122;;!"##$$%%&&'(())**++,--..//001123 ;;"#$%%&&''(())*++,,--../001122;;"##$$%%&''(())**++,--..//001223-$;;"#$$%%&&''(()**++,,--.//0011223)+;;#$%&''(())**+,,--..//0112233$1;;#$$%%&&''())**++,,-..//001123348;;#$$%&&''(())*++,,--../001122334;;$%&'(())**++,--..//001123344 ;;$%%&&''(())*++,,--../0011223345;;$%%&''(())**++,--..//0012233445 ;;%&'())**++,,--.//00112234452!;;== 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 566666777778888899999:::::;;;;;;<<<<<========= 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 566666777778888899999:::::;;;;;;<<<<<========= ;3 ;3 ;3 ;3 ;3 ;4 ;4 ;4 ;4 ;4 ;4 ;5 ;5 ;5 ;5 ;5;6;6;6;6;6;7;7;7;7;7;8;8;8;8;8;9;9;9;9;9;:;:;:;:;:;;;;;;;;;;;;;<;<;<;<;<;=;=;=;=;=;=;=;=;=; ,p,p,  R2 2 3 3 3 Y3 (334.ia.p /.p .p /p /p h/p 6/p /p 0@@6o6=6 677v7E772T2p~2pL2p2p3p3p3pS3p!3M:::Z:(::;;a;0;;<<i<7< <==p=>=555 H)x)))))))))@ Tf777777777]0 $0 $ $B- $0 $0 $0 $0 $0 $0 $0 $0 $ @ @4@$@B$  0  0  0  0  0  0  0  0  !   1  @%%%%%%%@4(@@ax         nPP/C'H'H'H'H'H'H'H'H'@;6HHHHHHHH1i'(((((()))))*****+++++,,,,,-----.....//////000 1 3 5790:975 4 5 6789:<'(((((()))))*****+++++,,,,,-----.....//////000 1 3 5790:975 4 5 6789:<';(;(;(;(;(;(;);););););*;*;*;*;*;+;+;+;+;+;,;,;,;,;,;-;-;-;-;-;.;.;.;.;.;/;/;/;/;/;/;0;0;0 ;1 ;3 ;5;7;9;;0;;:;9;7;5 ;4 ;5 ;6;7;8;9;:;<;'((((X(&()))_)-)***f*5*+++n+<+ ,,,u,C,---|-J-....R. / / / /Y /' / 0 0 x/`0.52[4 6 8g?#0,f 9`8975}45[6?7(89 :<pcdgikqdgikÁdgikÑdfik|ádfiknñdfikmcfhkmcfhjmcehjliegjlxegjlĈdgikĘdfikuĨcfhjmĹcehjlbegjlbdgikbdfikncfhj~cegjbdgi{adfhmacehj`bdgi_adfh^acegc`bdgr_acf^`ce]_bdp\_ace[^`bdZ]_acY\^`bY[]_a eZ\^` vY[]_ YY\^t YY[]c ~YY[^ YZ\^ Y[]_r YZ\^`e Y[]_acjYY[]_actYZ\^`bdh\[]_`bdf m[]_acegv \^_acegk`^`bdegir^`bdfhiw_`bdfhildabdfhjkvacdfhjkwacdfhikmٸgcdfhiklzcdfhiklwbdfgijlmݻidegijkm}deghjklvcefhiklm kdfgijkm!deghjkls"cefgijkl´ ^~|zxvtromkigeca_\ZXVTRPNLIGECA?=;9M~{ywusqomkhfdb`^\ZWUSQOMKIFDB@><:1<}{xvtrpnljgeca_][YWTRPNLJHFCA?=;F+~|zxvsqomkigec`^\ZXVTROMKIGECA><Z }{ywuspnljhfdb_][YWUSQOLJHFDB@>n ~|zxvtrpmkigeca_\ZXVTRPNLIGECA? ~|ywusqomkhfdb`^\ZWUSQOMKIGDB@Ö }}{yvtrpnljheca_][YWTRPNLJHFCAë l~|zxvtqomkigec`^\ZXVTROMKIGEC[}{ywusqnljhfdb`][YWUSQOLJHFD'H~|zxvtrpmkigeca_]ZXVTRPNLIGE;6~|ywusqomkifdb`^\ZXUSQOMKIGO #}{yvtrpnljheca_][YWURPNLJHc ~|zxvtqomkigec`^\ZXVTRPMKIw }{ywusqnljhfdb`][YWUSQOMJċ |zxvtrpnkigeca_]ZXVTRPNLĠ x~|zwusqomkifdb`^\ZXUSQOMij e}{ywtrpnljhfca_][YWURPN Qε~|zxvtqomkigeca^\ZXVTRP. >ϴ}{ywusqnljhfdb`^[YWUSQB +϶|zxvtrpnkigeca_][XVTRV е~|zwusqomkifdb`^\ZXVSj ж}{ywtrpnljhfca_][YWU ѵ~|zxvtqomkigeca^\ZXV ҵ}{ywusqoljhfdb`^[YW mҶ|zxvtrpnligeca_][X Zӵ~|zxusqomkigdb`^\Z  FӶ}{ywtrpnljhfda_][4 2Ե~|zxvtqomkigeca_\H յ}{ywusqoljhfdb`^\ ն}zxvtrpnligeca_q ֵ~|zxusqomkigdb` ֶ}{ywurpnljhfda u׵~|zxvtromkigec a ص~{ywusqomjhfd L ض}zxvtrpnljge%7 ٵ~|zxvsqomkig:" ٶ}{ywurpnljhP ڵ~|zxvtromki.k ۵~{ywusqomjA ۶}{xvtrpnl ܵ~|zxvsqom kڶ}{ywuspn  Aܶ~|zxvtrp "޵~|ywusq9 j޶}{xvtrg Aߵ~|zxvt  $ݶ}{ywu = h߶~|zxvk  @ᵳ~|yw %ᶴ}{yD f⵳~|zq ?㴲}{֘$ &~|ׯI c~v >ڜ) %۱O `{ <ޞ, $߲S [ 8!0 !{"W U;:7665544322110//..-,,++*))((''&%%$$#""!! ;; 77665443321100//.--,,+**))(''&&%%$##""! ;;87765544322110//..--,++**)((''&%%$$##"!! ;;887665543322100//.--,,++*))(('&&%%$##""!! ;; 7877665443321100/..--,++**))(''&&%$$##"!! ;;#3887665544322110//..-,,++*))((''&%%$$#""!! ;;*.9877665443321100//.--,,+**))(''&&%%$##""! ;;0)98877655443221100/..--,++**)((''&%%$$##"!! ;;7#99887665543322100//.--,,++*))(('&&%%$##""!! ;;:99877665443321100/..--,,+**))(''&&%$$##"!! ;; :99887665544322110//..-,,++*))((''&%%$$#""!! ;;::99877665443322100//.--,,+**))(''&&%%$##""! ;; ;::98877655443221100/..--,++**)((''&%%$$##"!! ;; 8;:99887665543322100//..-,,++*))(('&&%%$##""!! ;;&3;::99877665443321100/..--,,+**))(''&&%$$##"!! ;;--;;:99887665544322110//..-,,++*))((''&%%$$#""!! ;;4&;;::99877665543322100//.--,,+**))(('&&%%$##""! ;;: ;;:98877655443221100/..--,++**)((''&%%$$##"!! ;;;;:99887665543322110//..-,,++*))(('&&%%$$#""!! ;;;;:9877665443321100/..--,,+**))(''&&%$$##"!! ;;;;:99887765544322110//..-,,++**)((''&%%$$#""!! ;;;;:9877665543322100//.--,,+**))(('&&%%$##""! ;;"6;;:98877655443221100/..--,++**)((''&%%$$##"!! ;;)0;;:99887665543322110//..-,,++*))(('&&%%$$#""!! ;;/);;:9877665443321100/..--,,+**))(''&&%$$##"!! ;;6#;;:99887765544322110//..--,++**)((''&%%$$#""!!;;;;:9877665543322100//.--,,+**))(('&&%%$##""!;; ;;:98877655443321100/..--,++**)((''&&%$$##"!;;;;:99887665543322110//..-,,++*))(('&&%%$$#"";; ;;:9877665443321100//.--,,+**))(''&&%$$##";;9;;:99887765544322110//..--,++**)((''&%%$$#";;%3;;:9877665543322100//.--,,+**))(('&&%%$##;;+,;;:98877655443321100/..--,++**))(''&&%$$#;;2&; ;:99887665543322110//..-,,++*))(('&&%%$$;;9; ;:9877665443321100//.--,,+**))(''&&%%$;;; ;:99887765544322110//..--,++**)((''&%%$;; ; ;:987665543322100//.--,,++*))(('&&%%;; ; ;:98877655443321100/..--,++**))(''&&%;;; ;:99887665544322110//..-,,++*))((''&%;;#; ;:9877665443321100//.--,,+**))(''&&;;8; ;:9887765544322110//..--,++**)((''&;; /; ;:987665543322100//.--,,++*))(('&;; "; ;:98877655443321100/..--,++**))('';; 7;;:99887665544322110//..-,,++*))((';;- /;;:9877665443321100//.--,,+**))(';7";;:98877655443221100/..--,++**)((;!7;;:987665543322100//.--,,++*))( ;/ .;;:98877665443321100/..--,++**)); ;8";;:99887665544322110//..-,,++*));;"6;;:9877665443322100//.--,,+**);;0  .;;:98877655443221100/..--,++**;;8!:;;:987665543322100//.--,,++*;;%6;;:9877665443321100/..--,,+*;;1  -;;:99887665544322110//..-,,++;;9 :;::99877665543322100//.--,,+;;&5;::98877655443221100/..--,+;;2  ,;:99887665543322100//..-,,;;99:99877665443321100/..--,;;'499887665544322110//..-,;;3 *99877665543322100//.--;;9887655443221100/..-; ;)2887665543322110//..;!;4 (877665443321100/..;";:7765544322110//. ՘:mT867, 4Pu2u2N4*67k9C;~펌~|{yxxĠxyz|}}|zyxxĆxz{}~~}{zxxĆy{|~~|{yxz|}~}|zx{|~~|{yĈ|}}|zĉ}~~}{Ċ}~|ċ~}ċ~ċČčĎďĐĐđĒĒÓ딉¢ĔãĔĤĕĥ№ŦߖƧėǨĖȩėɪĘɫĘʬę˭ę̮ĚͮĚίĚΰěϱěвĜѳĜҴĜӵĝӶöԷĞոğֹğ׺ŠػêؼƢٽǣھġۿĢܿĢĢÙģĤĤ҇޼ulĥڞmljĦ̈́lkjiק۶sljihg6420.,*(%#!,R "$&(*,.02468:<>@BDFHJLNPRTVXZ\^`bdf8531/-+)'%" -!$&')+-/13579;=?ACEGIKMOQSUWY[]_aceg97520.,*(&$!-!#%')+-.02469:<>@BDFHJLNPRTVXZ\^`bdfh:86420-+)'%#!. "$&(*,.02468:<>@ACEGILMOQSUWY[]_acegi;97531/-*(&$" /!#%')+-/13579;=?ACEGIKMOQRTVXZ\_`bdfhj=;96420.,*(%#!0 "$&(*,.02468:<>@BDFHJLNPRTVXZ\^`bdegik><:8631/-+)'%" 0!#%')+-/13579;=?ACEGIKMOQSUWY[]_acegikm?=;97530.,*(&$"ü1 "$&(*,.02468:<>@BDFHJLNPRTVXZ\^`bdfhjlnA?<:86420.+)'%#!2!$&()+-/13579;=?ACEGIKMOQSUWY[]_acegikmoB@>;97531/-+(&$" 4#%')+-/02469;<>@BDFHJLNPRTVXZ\^`bdfhjlnpCA?=;96420.,*(&#!5$&(*,.02468:<>@ACEGILNOQSUWY[]_acegikmoqDB@><:8631/-+)'%#5%')+-/13579;=?ACEGIKMOQSTVXZ\_abdfhjlnprFDA?=;97530.,*(&$ú6&(*,.02468:<>@BDFHJLNPRTVXZ\^`bdfgikmoqsGECA?<:86420.+)'%7')+-/13579;=?ACEGIKMOQSUWY[]_acegikmoqsuHFDB@><97531/-+(&8(*,.02468:<>@BDFHJLNPRTVXZ\^`bdfhjlnprtvIGECA?=;96420.,*(:*+-/13579;=?ACEGIKMOQSUWY[]_acegikmoqsuwKIGEB@><:8641/-+);+-/12469;=>@BDFHJLNPRTVXZ\^`bdfhjlnprtvxLJHFDA?=;97531.,*ø;,.02468:<>@BCEGILNPQSUWY[]_acegikmoqsuwyMKIGECA?<:86420.,<-/13579;=?ACEGIKMOQSUVXZ\_acdfhjlnprtvxzOMJHFDB@><97531/-=.02468:<>@BDFHJLNPRTVXZ\^`bdfhikmoqtuwy{PNLJGECA?=;96420.>/13579;=?ACEGIKMOQSUWY[]_acegikmoqsuwy{|QOMKIGEB@><:8641/?02468:<>@BDFHJLNPRTVXZ\^`bdfhjlnprtvxz|~SPNLJHFDB?=;97531?13579;=?ACEGIKMOQSUWY[]_acegikmoqsuwy{}TRPNKIGECA?=:8642@2469;=?@BDFHJLNPRTVXZ\^`bdfhjlnprtvxz|~USQOMJHFDB@><:753­A468:<>@BDEGILNPRSUWY[]_acegikmoqsuwy{}VTRPNLJGECA?=;974A579;=?ACEGIKMOQSUWXZ\_acefhjlnprtvxz|~XVSQOMKIGEB@><:86B68:<>@BDFHJLNPRTVXZ\^`bdfhjkmoqtvwy{}YWUSPNLJHFDB?=;97B79;=?ACEGIKMOQSUWY[]_acegikmoqsuwy{}~ZXVTRPNKIGECA?=:8¡C8:<>@BDFHJLNPRTVXZ\^`bdfhjlnprtvxz|~\YWUSQOMKHFDB@><:D9;=?ACEGIKMOQSUWY[]_acegikmoqsuwy{}][XVTRPNLJHECA?=;E;=?ABDFHJLNPRTVXZ\^`bdfhjlnprtvxz|~^\ZXVTQOMKIGEC@><E<>@BDFGILNPRTUWY[]_acegikmoqsuwy{}_][YWUSPNLJHFDB@=•F=?ACEGIKMOQSUWYZ\_acefhjlnprtvxz|~a_\ZXVTRPNLIGECA?F>@BDFHJLNPRTVXZ\^`bdfhjlmoqtvxy{}b`^\YWUSQOMKHFDB@}G?ACEGIKMOQSUWY[]_acegikmoqsuwy{}ca_][YVTRPNLJHECA{G@BDFHJLNPRTVXZ\^`bdfhjlnprtvxz|~eb`^\ZXVTQOMKIGECy‰HACEGIKMOQSUWY[]_acegikmoqsuwy{}fdb_][YWUSQNLJHFDwICDFHJLNPRTVXZ\^`bdfhjlnprtvxz|~geca_\ZXVTRPNLIGEuJDFHILNPRTVWY[]_acegikmoqsuwy{}hfdb`^\ZWUSQOMKIFsJEGIKMOQSUWY[\_aceghjlnprtvxz|~jgeca_][YVTRPNLJHq~~}KFHJLNPRTVXZ\^`bdfhjlnoqtvxz{}kigeb`^\ZXVTROMKIoz{{zzKGIKMOQSUWY[]_acegikmoqsuwy{}ljhfdb_][YWUSQNLJmwwLHJLNPRTVXZ\^`bdfhjlnprtvxz|~mkigeca_\ZXVTRPNLkttLIKMOQSUWY[]_acegikmoqsuwy{}omkhfdb`^\ZWUSQOMirrqMJLNPRTVXZ\^`bdfhjlnprtvxz|~pnljheca_][YWTRPNgnoonnNLNPRTVWY[]_acegikmoqsuwy{}qomkigec`^\ZXVTROdkkOMOQSUWY[]_acegijlnprtvxz|~spnljhfdb`][YWUSQchhONPRTVXZ\^`bdfhjlnpqtvxz|}trpmkigeca_\ZXVTR`effePOQSUWY[]_acegikmoqsuwy{}usqomkhfdb`^\ZXUS^bccbbPPRTVXZ\^`bdfhjlnprtvxz|~vtrpnljheca_][YWT\__QSUWY[]_acegikmoqsuwy{}xvtqomkigec`^\ZXVZ]]\QRTVXZ\^`bdfhjlnprtvxz|~ywusqnljhfdb`][YWXYZZYSTVXY[]_acegikmoqsuwy{}zxvtrpnkigeca_]ZXVVSUWY[]_acegiklnprtvxz|~|ywusqomkifdb`^\ZTSSTVXZ\^`bdfhjlnprtvxz|~}{yvtrpnljhfca_][RQQPTWY[]_acegikmoqsuwy{}~|zxvtqomkigeca^\PMNNMMUXZ\^`bdfhjlnprtvxz|~}{ywusqnljhfdb`^NJJUY[]_acegikmoqsuwy{}|zxvtrpnkigeca_LGGVZ\^`bdfhjlnprtvxz|~~|zwusqomkifdb`JEEDW[]_acegikmoqsuwy{}9}{ywtrpnljhfcaHABBAAX]_acegikmnprtvxz|~z#~|zxvtqomkigecF>>X^`bdfhjlnprtvxz|~U}{ywusqoljhfdD;;Y_acegikmoqsuwy{}5|zxvtrpnkigeA8998Y`bdfhjlnprtvxz|~s KTUUTT& !!""##$$CSTTSS !!""#$$%CRSSRR !!""##$$%BQQ !!"##$$%%APPO !!""##$%%&@OON !""##$$%%&?MNNMM !!""#$$%%&&?LL !!""##$$%%&'>KK !!""#$$%%&&'??>> !!""##$%%&&''(()**4== !""##$$%%&''(())**3<< !!""#$$%%&&''())**+3;; !!""##$$%%&''(())**+2:: !!"##$$%%&&''())**++199 !!""##$$%&&''(())*++, 188 !!"##$$%%&&'(())**++, 077 !!""##$%%&&''(()**++,, /66 !""##$$%%&''(())**+,,-! .55 !!""#$$%%&&''())**++,,-!! .44 !!""##$$%%&''(())**+,,--"! -33 !!"##$$%%&&''())**++,,-."!! ,22 !!""##$%%&&''(())*++,,--.""! ,11 !!"##$$%%&&'(())**++,--..#"!! +00 !!""##$%%&&''(()**++,,--./#""!! *// !""##$$%%&''(())**+,,--../##""! ).. !!""#$$%%&&''())**++,,--.//$#""!! )-- !!""##$$%&&''(())**+,,--..//$##""! (,, !!"##$$%%&&''())**++,,-..//0$$##"!! '++ !!""##$%%&&''(())*++,,--../00%$$#""!! '** !!"##$$%%&&'(())**++,--..//00%%$##""! &)) !!""##$%%&&''(()**++,,--.//001%%$$#""!! %(( !""##$$%%&''(())**+,,--..//011&%%$##""!! %'(('' !!""#$$%%&&''())**++,,--.//0011&&%$$##"!! $'' !!""##$$%&&''(())**+,,--..//0112'&%%$$#""!! #&&% !!"##$$%%&&'(())**++,,-..//00112'&&%%$##""! #%% !!""##$%%&&''(())*++,,--../001122''&%%$$##"!! "$$ !!"##$$%%&&'(())**++,--..//001223('&&%%$##""!! "## !!""##$%%&&''(()**++,,--.//0011223(''&&%$$##"!! !"" !""##$$%%&''(())**+,,--..//0112233((''&%%$$#""!!  !! !!""#$$%%&&''())**++,,--.//00112234)(''&&%%$##""!    !!""##$$%&&''(())**+,,--..//01122334)((''&%%$$##"!!  !!"##$$%%&&'(())**++,,-..//001123344))(('&&%%$##""!!  !!""##$%%&&''(())*++,,--../0011223345*))(''&&%$$##"!!  !"##$$%%&&'(())**++,--..//0012233445*))((''&%%$$#""!! !!""##$%%&&''(()**++,,--.//00112234455**))(('&&%%$##""! !!""##$$%%&''(())**+,,--..//01122334455+**)((''&%%$$##"! !!""#$$%%&&''())**++,,--.//001122344556++*))(('&&%%$##""!!""##$$%&&''(())*++,,--..//011223344566,+**))(''&&%$$##"!!"##$$%%&&'(())**++,--..//0011233445566,++**)((''&%%$$#" !""##$%%&&''(())*++,,--../0011223345566,+**))(('&&%%$## !"##$$%%&&'(())**++,--..//0012233445561-,++**)((''&%%$$# ""##$%%&&''(()**++,,--.//001122344556( -,,++*))(('&&%%$$ "##$$%%&''(())**+,,--..//01122334454--,,+**))(''&&%$$ "#$$%%&&''())**++,,--.//0011223445/.-,,++**)((''&%%$ ##$$%&&''(())*++,,--..//011223344& ڲljhecڳݼljgecڴްljgebڴߢljgedߕljgerligdzkigdokifdmkifd۹mjhfcۺmjhecۻljhecܼljgeiܽkigdyܾkifdܾtjhfcܿljhecligebkifdbjhfcajgecaigdbnhfda~zhecakgdb`hfda_geca^gdb`^fca_]eb`^bda_]r~c`^\mb_][ca_\Zb`^[Ya_\ZY`^[YY_\ZYZ][YYfl\ZYY]c][YY`^\ZYYta_][YYfa_][YYdb`^\ZY[udb`_][Yj ieca_][Y gecb`^\]  whfdb`^\m lhfdb`_]ߎjhfdca_a wjhgeca_r mjhgeca_ۋljhgecaewljhgecavmkjhgeca! ։mkjhfecf$ vlkihfecy% mljihfdc% mljigfdi%kjhged{%ihfec%gfdk&ed~&hjlnprtvxz|~ zikmoqsuwy{}z jlnprtvxz|~k kmoqsuwy{}[lnprtvxz|~Jmoqsuwy{}:3oqsuwxz|~)Gprtvxz|~[qsuwy{} ortvxz|~ suwy{}y tvxz|~h uwy{}Wwyz|~F(xz|~3 <y{}  Pz|~ d{} x|~ }t ~c ݀P ݁= .݂) B݃ W݄ k݅ ݇ 爊k 牋W  芌B 鋍. 3錎 Hꍏ ]ꎐ r됑 둓s쒔^퓕I픖n B ! l  𚜞B c񛝟$  䜞k 8 束B g  瞠&  蠢i =ꡣA  k 뢤%  죥d D? q不& #𦨪` I! 򧩛; u$ $ )% Z M% z% ,% R%~& .&%&''(())**+,,--..//0112233445-';;%&&''())**++,,-..//00112334455(.;;&'()*++,,--../001122334556#4;;&'(())**++,--..//001123344556:;;&''(()**++,,--../0011223345566 ;;''(())**++,--..//0012233445567;;''())**++,,--.//00112234455667 ;;'(())**+,,--..//01122334456676;;'())**++,,-..//001123344556671$;;()*++,,--../001122334556677-*;;())**++,--..//001123344556678'1;;()**++,,--../0011223345566778"7;;)*+,,--..//0012233445567788;;)**++,,--.//00112234455667789 ;;)**+,,--..//01122334456677889;;*+,-..//001123344556678899 ;;*++,,--../0011223345566778896 ;;*++,--..//0011233445566788991';;+,-./001122334556677889:+-;;+,,--..//001223344556778899:%4;;+,,--.//001122344556677899:: :;;,-./011223344566778899:: ;;,-..//001123344556678899::;;;,--../0011223345566778899:;; ;;-./0123344556678899::;:;;-.//001122334556677889::;;5#;;-..//001223344556778899::;;/);;-.//001122344556677899::;;)0;;./011223344566778899:;;"7;;.//001123344556678899::;;;;./0011223345566778899:;; ;;/0123344556678899::;;;;/001122334556677889::;;;;/011223344556778899::;;8;;012344556677899::;;2%;;011223344566778899:;;,,;;01123344556678899::;;%3;;12345566778899:;;9;;1223344556678899::;;;;122334556677889::;;0;;23456778899::;;#;2344556677899::;;8;23344566778899:;;0 ;345678899::;;# ;345566778899:;;7 ;;;344556678899::;;/ .;; ;456789::;;"7;; ;456778899::;7!; ; ;4556677899::;.  /; ;;4566778899:;"8;;;5678899:5#;;; 566778899-  0;;; 56678898!8;;6784$;;67788+  1;;6779;!; 73&;$; 7*  2;%; 9;%; ';%;3;%;9;%;(;&;4;&;>w=E=<<<~=>=;>;=Q=6%mdeghijl%܁cefghjkq&ddefhijk'mcdeghij~'݃bcdfghin(bbcdfghi(mabcdefgy(߄`abcdefk(a`abcdee)l_``abcdu)]^_`abbf)^]^__`aa )k[\]^__`n )Z[[\]^^ *\YZ[[\ *kYY*YY+]Y+n**)('&$#"!  "#$%&'(*+,-./1 2 3 4 5 679:;<=>%4%1 t&Z O' .'4 m(^ H( ((6 f(` @) ")7 ^)c 9 )  )7 *e **;+i+**)('&$#"!  "#$%&'(*+,-./1 2 3 4 5 679:;<=>%;*07665543322100//;%;4 &7655443321100/;&;:465543322110/;';+.65443321100;';5 $5544322110(;:354332210(;, ,4433211(;6"433221);13321);- +322);632*; 0 );. );7 *;!*;/*;7+;"+;/*;8*;);(;';&;$;#;";!; ;; ;";#;$;%;&;';(;*;+;,;-;.;/;1 ;2 ;3 ;4 ;5 ;6;7;9;:;;;<;=;>;?=!<;:9d7G6.54 3 2 y0 Y/ =.'-, +*m(N'5& %$#"b E-  "w#W$;%%&'(*k+L,3-. / 1 2_ 3C4+56 79t:T;:;$<=Ħיlkjhgfeħɀkjihfedkħױpjihgfdc}}ĨӔjihgfecczz٩|ihgfedbkxxکԬmhgfedcavvuϐhgfedcbassݩѿwfedcba`kqqުѦiedcba`_~nn߫ʊdcbba`__}ll᫵κrcba`__^j {ii⬶͠ea`__^]\ ygg㬷ƃ`__^]]\] awee嬸˴l^^]\\[Zi \]vbb歹ʚ_]\[[ZYYZ[[it``}[[ZZYY[Y\r]]򮺼ǯfYYjYzq[[󮻽Ǔ[YYYepYYŽwYY\YYZpYYīdYYl^YYwpYYÏZYYoYYcpYYuYY]YYZpYYbYYn_YYtqYYZYY rYYbqYYrYY^#YY]YY]YYp&`YY(tYY_+Y Yr.aY Y0vYY`3YYt6cYY8ya;)<<:98765 4 2 1 0/.-+*)('$" "툆~|zwusqomkig?55Zacegikmoqsuwy{}O}{ywtrpnljh=22Zbdfhjlnprtvxz|~1 ~|zxvtqomki;//[cegikmoqsuwy{}l 0}{ywusqolj9,--,,\egikmoprtvxz|~J Y}zxvtrpnl7))]fhjlnprtvxz|~+ 폍~|zxusqom5&&]gikmoqsuwy{}e 2퐎}{ywurpn3##^hjlnprtvxz|~B [Ƒ~|zxvtqo1 !! ^ikmoqsuwy{}}% 퓑}{ywusq/_jlnprtvxz|~_ 3픒}zxvtr-_kmoqsuwy{}< ]핓~|zxus+amoqrtvxz|~v  헔}{ywu)anprtvxz|~V 4 y~|zxv'boqsuwy{}4 _ W~{yw%bprtvxz|~p 0}{x"  cqsuwy{}O4q~|z!crtvxz|~~+bM}{dsuwy{}h(~|etvxz|~F8k~fvxz|~y%g>Ggwy{}b n$~hxz|~A< eiy{}s!jCBiz|\ q!xjz<?  ^^n#G&v C("r+K .z G0% v3O"6~ K8( y;)<<:98765 4 2 1 0/.-+*)('$" ".--,,+**))(('&&%%!#$$%%&&'(())**++,--..//001123343..--,++**)((''&&%!#$%%&&''(())*++,,--../00112233-/..-,,++*))(('&&%!$$%%&&'(())**++,--..//0012233$ 4/..--,,+**))(''&&!$%%&&''(()**++,,--.//0011221:;//..--,++**)((''&  !$%%&''(())**+,,--..//01122,+;;0//.--,,+**))(('&  !%%&&''())**++,,-..//00112!5;;0/..--,++**))(''  !%&&''(())*++,,--..//0110:;;10//..-,,++*))(('  "%&&'(())**++,--..//001) +;;100//.--,,+**))('  "&&''(())*++,,--../0015;;10//..--,++**)((  !&&'(())**++,--..//0.;;2100//.--,,++*))("&''(()**++,,--.//0' ,; ;21100/..--,++**))"''(())**+,,--..//6; ;(2110//..-,,++*)) "''())**++,,-../,; ;1100//.--,,+**) #'(())*++,,--..&-; ;-10//..--,++** #(())**++,--..6;;&00//.--,,++* #(())*++,,--+ ;;00/..--,++* #())**++,--#.;; ,//..-,,++ #()**++,,-7;;$//.--,,+ #))**+,,) !;;/..--,+ $)**++,!/;;# +.--,, $)*++,8;;0 ".--, $**+' ";;8--, $*+0;;% (- %*8; ;1   #;#;9 1;&;&8;(;2 %;+;9 1;.;' 9;0;3 &;3;: 2;6;(9;8;4 ';;;:5;);;<;<;:;9;8;7;6;5; 4; 2; 1; 0;/;.;-;+;*;);(;';$;";; ;"; ?<.;: 98x7X6=5&43 2 0m /N .5 - ,+*(b'E$-"h J1wW!<c&&'&%$#"  !"#$&'()*+-./0 1 2 3 56789:<= U&&'&%$#"  !"#$&'()*+-./0 1 2 3 56789:<=:;&;);&;';&;%;$;#;"; ;;; ;!;";#;$;&;';(;);*;+;-;.;/;0 ;1 ;2 ;3 ;5;6;7;8;9;:;<;=;(&z%Z$>#'"!  nP6! !"#c%F&.'( )*y,Y- =. '/ 0 1 2n4O556 789;c<FEHH55L5q6]``N')+-0 2 4 79;k')+-0 2 4 79;k;';);+;-;0 ;2 ;4 ;7;9;;;k&&~(] *A ,* l/M1 43 6r8R:8zjFG##fifechan-0.1.5/doxygen.conf000066400000000000000000000222151341577075500156240ustar00rootroot00000000000000# Doxyfile 1.5.8 #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = Fifechan PROJECT_NUMBER = 0.1.3 OUTPUT_DIRECTORY = docs/ CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English BRIEF_MEMBER_DESC = NO REPEAT_BRIEF = YES ABBREVIATE_BRIEF = ALWAYS_DETAILED_SEC = NO INLINE_INHERITED_MEMB = NO FULL_PATH_NAMES = NO STRIP_FROM_PATH = include/ STRIP_FROM_INC_PATH = SHORT_NAMES = NO JAVADOC_AUTOBRIEF = YES QT_AUTOBRIEF = NO MULTILINE_CPP_IS_BRIEF = NO INHERIT_DOCS = YES SEPARATE_MEMBER_PAGES = NO TAB_SIZE = 4 ALIASES = OPTIMIZE_OUTPUT_FOR_C = NO OPTIMIZE_OUTPUT_JAVA = NO OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_OUTPUT_VHDL = NO EXTENSION_MAPPING = BUILTIN_STL_SUPPORT = NO CPP_CLI_SUPPORT = NO SIP_SUPPORT = NO IDL_PROPERTY_SUPPORT = NO DISTRIBUTE_GROUP_DOC = NO SUBGROUPING = YES TYPEDEF_HIDES_STRUCT = NO SYMBOL_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- EXTRACT_ALL = NO EXTRACT_PRIVATE = NO EXTRACT_STATIC = NO EXTRACT_LOCAL_CLASSES = YES EXTRACT_LOCAL_METHODS = NO EXTRACT_ANON_NSPACES = NO HIDE_UNDOC_MEMBERS = NO HIDE_UNDOC_CLASSES = NO HIDE_FRIEND_COMPOUNDS = NO HIDE_IN_BODY_DOCS = YES INTERNAL_DOCS = NO CASE_SENSE_NAMES = YES HIDE_SCOPE_NAMES = NO SHOW_INCLUDE_FILES = YES INLINE_INFO = YES SORT_MEMBER_DOCS = YES SORT_BRIEF_DOCS = YES SORT_GROUP_NAMES = NO SORT_BY_SCOPE_NAME = YES GENERATE_TODOLIST = YES GENERATE_TESTLIST = YES GENERATE_BUGLIST = YES GENERATE_DEPRECATEDLIST= YES ENABLED_SECTIONS = NO MAX_INITIALIZER_LINES = 30 SHOW_USED_FILES = YES SHOW_DIRECTORIES = NO SHOW_FILES = YES SHOW_NAMESPACES = YES FILE_VERSION_FILTER = LAYOUT_FILE = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- QUIET = NO WARNINGS = YES WARN_IF_UNDOCUMENTED = YES WARN_IF_DOC_ERROR = YES WARN_NO_PARAMDOC = NO WARN_FORMAT = "$file:$line: $text" WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- INPUT = include/fifechan \ src/ INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.hpp \ *.cpp RECURSIVE = YES EXCLUDE = EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = EXCLUDE_SYMBOLS = EXAMPLE_PATH = EXAMPLE_PATTERNS = *.cpp EXAMPLE_RECURSIVE = NO IMAGE_PATH = INPUT_FILTER = FILTER_PATTERNS = FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- SOURCE_BROWSER = YES INLINE_SOURCES = NO STRIP_CODE_COMMENTS = YES REFERENCED_BY_RELATION = YES REFERENCES_RELATION = YES REFERENCES_LINK_SOURCE = YES USE_HTAGS = NO VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- ALPHABETICAL_INDEX = NO COLS_IN_ALPHA_INDEX = 5 IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- GENERATE_HTML = YES HTML_OUTPUT = html HTML_FILE_EXTENSION = .html HTML_HEADER = HTML_FOOTER = HTML_STYLESHEET = HTML_ALIGN_MEMBERS = YES HTML_DYNAMIC_SECTIONS = NO GENERATE_DOCSET = NO DOCSET_FEEDNAME = "Doxygen generated docs" DOCSET_BUNDLE_ID = org.doxygen.Project GENERATE_HTMLHELP = NO CHM_FILE = HHC_LOCATION = GENERATE_CHI = NO CHM_INDEX_ENCODING = BINARY_TOC = NO TOC_EXPAND = NO GENERATE_QHP = NO QCH_FILE = QHP_NAMESPACE = QHP_VIRTUAL_FOLDER = doc QHP_CUST_FILTER_NAME = QHP_CUST_FILTER_ATTRS = QHP_SECT_FILTER_ATTRS = QHG_LOCATION = DISABLE_INDEX = NO ENUM_VALUES_PER_LINE = 4 GENERATE_TREEVIEW = NO TREEVIEW_WIDTH = 250 FORMULA_FONTSIZE = 10 #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- GENERATE_LATEX = NO LATEX_OUTPUT = latex LATEX_CMD_NAME = latex MAKEINDEX_CMD_NAME = makeindex COMPACT_LATEX = NO PAPER_TYPE = a4wide EXTRA_PACKAGES = LATEX_HEADER = PDF_HYPERLINKS = NO USE_PDFLATEX = NO LATEX_BATCHMODE = NO LATEX_HIDE_INDICES = NO #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- GENERATE_RTF = NO RTF_OUTPUT = rtf COMPACT_RTF = NO RTF_HYPERLINKS = NO RTF_STYLESHEET_FILE = RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- GENERATE_MAN = NO MAN_OUTPUT = man MAN_EXTENSION = .3 MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- GENERATE_XML = NO XML_OUTPUT = xml XML_SCHEMA = XML_DTD = XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- GENERATE_PERLMOD = NO PERLMOD_LATEX = NO PERLMOD_PRETTY = YES PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- ENABLE_PREPROCESSING = YES MACRO_EXPANSION = NO EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES INCLUDE_PATH = INCLUDE_FILE_PATTERNS = PREDEFINED = EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- # Configuration::additions related to external references #--------------------------------------------------------------------------- TAGFILES = GENERATE_TAGFILE = ALLEXTERNALS = NO EXTERNAL_GROUPS = YES PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- CLASS_DIAGRAMS = YES MSCGEN_PATH = HIDE_UNDOC_RELATIONS = YES HAVE_DOT = NO DOT_FONTNAME = FreeSans DOT_FONTSIZE = 10 DOT_FONTPATH = CLASS_GRAPH = YES COLLABORATION_GRAPH = YES GROUP_GRAPHS = YES UML_LOOK = NO TEMPLATE_RELATIONS = NO INCLUDE_GRAPH = YES INCLUDED_BY_GRAPH = YES CALL_GRAPH = NO CALLER_GRAPH = NO GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = YES DOT_IMAGE_FORMAT = png DOT_PATH = DOTFILE_DIRS = DOT_GRAPH_MAX_NODES = 50 MAX_DOT_GRAPH_DEPTH = 0 DOT_TRANSPARENT = NO DOT_MULTI_TARGETS = NO GENERATE_LEGEND = YES DOT_CLEANUP = YES #--------------------------------------------------------------------------- # Options related to the search engine #--------------------------------------------------------------------------- SEARCHENGINE = NO fifechan-0.1.5/include/000077500000000000000000000000001341577075500147215ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan.hpp000066400000000000000000000146421341577075500172040ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naess�n and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naess�n a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_FIFECHAN_HPP #define FCN_FIFECHAN_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "fifechan/platform.hpp" #include "fifechan/version.hpp" class Widget; extern "C" { /** * Gets the the version of Fifechan. As it is a C function * it can be used to check for Fifechan with autotools. * * @return the version of Fifechan. */ FCN_CORE_DECLSPEC extern const char* fcnFifechanVersion(); } #endif // end FCN_FIFECHAN_HPP fifechan-0.1.5/include/fifechan/000077500000000000000000000000001341577075500164645ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/actionevent.hpp000066400000000000000000000131661341577075500215230ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_ACTIONEVENT_HPP #define FCN_ACTIONEVENT_HPP #include "fifechan/event.hpp" #include "fifechan/platform.hpp" #include namespace fcn { class Widget; /** * Represents an action event. An action event is an event * that can be fired by a widget whenever an action has occured. * What exactly an action is is up to the widget that fires * the action event. An example is a Button which fires an action * event as soon as the Button is clicked, another example is * TextField which fires an action event as soon as the enter * key is pressed. * * Any object can listen for actions from widgets by implementing * the ActionListener interface. * * If you have implement a widget of your own it's a good idea to * let the widget fire action events whenever you feel an action * has occured so action listeners of the widget can be informed * of the state of the widget. * * @see Widget::addActionListener, Widget::removeActionListener, * Widget::distributeActionEvent * @author Olof Naessn */ class FCN_CORE_DECLSPEC ActionEvent: public Event { public: /** * Constructor. * * @param source The source widget of the event. * @param id An identifier of the event. */ ActionEvent(Widget* source, const std::string& id); /** * Destructor. */ virtual ~ActionEvent(); /** * Gets the identifier of the event. An identifier can * be used to distinguish from two actions from the same * widget or to let many widgets fire the same widgets * that should be treated equally. * * @return The identifier of the event. */ const std::string& getId() const; protected: /** * Holds the identifier of the event. */ std::string mId; }; } #endif // FCN_ACTIONEVENT_HPP fifechan-0.1.5/include/fifechan/actionlistener.hpp000066400000000000000000000114201341577075500222160ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_ACTIONLISTENER_HPP #define FCN_ACTIONLISTENER_HPP #include #include "fifechan/actionevent.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Interface for listening for action events from widgets. * * @see Widget::addActionListener, Widget::removeActionListener, * ActionEvent * @author Olof Naessn * @author Per Larsson */ class FCN_CORE_DECLSPEC ActionListener { public: /** * Destructor. */ virtual ~ActionListener() { } /** * Called when an action is recieved from a widget. It is used * to be able to recieve a notification that an action has * occured. * * @param actionEvent The event of the action. */ virtual void action(const ActionEvent& actionEvent) = 0; protected: /** * Constructor. * * You should not be able to make an instance of ActionListener, * therefore its constructor is protected. */ ActionListener() { } }; } #endif // end FCN_ACTIONLISTENER_HPP fifechan-0.1.5/include/fifechan/allegro.hpp000066400000000000000000000102321341577075500206200ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_ALLEGRO_HPP #define FCN_ALLEGRO_HPP #include #include #include #include #include extern "C" { /** * Exists to be able to check for Guichan Allegro with autotools. * * @bug Autotools is incapable of finding this function. */ extern void fcnAllegro(); } #endif // end FCN_ALLEGRO_HPP fifechan-0.1.5/include/fifechan/allegro/000077500000000000000000000000001341577075500201115ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/allegro/allegrofont.hpp000066400000000000000000000114121341577075500231350ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_ALLEGROFONT_HPP #define FCN_ALLEGROFONT_HPP #include #include "fifechan/font.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Allegro font implementation of Font that uses the native * Allegro font. */ class FCN_EXTENSION_DECLSPEC AllegroFont : public Font { public: /** * Constructor. * * @param font An Allegro font. */ AllegroFont(FONT* font); /** * Constructor. The font loaded with this constructor will be freed in the destructor. * * @param filename The filename of the Allegro font to load. */ AllegroFont(const std::string& filename); /** * Destructor. */ ~AllegroFont(); // Inherited from Font virtual int getWidth(const std::string& text) const; virtual int getHeight() const; virtual void drawString(fcn::Graphics* graphics, const std::string& text, int x, int y); protected: bool mAutoFree; FONT* mAllegroFont; }; } #endif // FCN_ALLEGROFONT_HPP fifechan-0.1.5/include/fifechan/allegro/allegrographics.hpp000066400000000000000000000145731341577075500240020ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_ALLEGROGRAPHICS_HPP #define FCN_ALLEGROGRAPHICS_HPP #include #include "fifechan/color.hpp" #include "fifechan/graphics.hpp" #include "fifechan/platform.hpp" namespace fcn { class Font; /** * Allegro implementation of Graphics. */ class FCN_EXTENSION_DECLSPEC AllegroGraphics : public Graphics { public: // Needed so that drawImage(fcn::Image *, int, int) is visible. using Graphics::drawImage; /** * Constructor. */ AllegroGraphics(); /** * Contsructor. Sets the drawing target. * * @param target the target to draw to. */ AllegroGraphics(BITMAP *target); /** * Destructor. */ virtual ~AllegroGraphics(); /** * Sets the target bitmap to draw to. It can be any bitmap with the same * bit-depth as the screen. However, if you pass the screen bitmap you * will probably get flicker. Use a double buffer! * * @param target the bitmap to draw to. */ virtual void setTarget(BITMAP *target); /** * Gets the target bitmap. * * @return the target bitmap. */ virtual BITMAP *getTarget(); /** * Gets the color in Allegro format. * * @return the color in Allegro format. */ int getAllegroColor() const; /** * Draws an Allegro bitmap. * * @param bitmap the bitmap to draw. * @param dstX the x-coordinate where to draw the bitmap. * @param dstY the y-coordinate where to draw the bitmap. */ virtual void drawBitmap(BITMAP* bitmap, int dstX, int dstY); // Inherited from Graphics virtual void _beginDraw(); virtual void _endDraw(); virtual bool pushClipArea(Rectangle area); virtual void popClipArea(); virtual void drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height); virtual void drawPoint(int x, int y); virtual void drawLine(int x1, int y1, int x2, int y2); virtual void drawRectangle(const Rectangle& rectangle); virtual void fillRectangle(const Rectangle& rectangle); virtual void setColor(const Color& color); virtual const Color& getColor() const; protected: BITMAP *mTarget; bool mClipNull; int mAllegroColor; Color mColor; }; } #endif // end FCN_ALLEGROGRAPHICS_HPP fifechan-0.1.5/include/fifechan/allegro/allegroimage.hpp000066400000000000000000000121271341577075500232550ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_ALLEGROIMAGE_HPP #define FCN_ALLEGROIMAGE_HPP #include #include #include "fifechan/color.hpp" #include "fifechan/platform.hpp" #include "fifechan/image.hpp" namespace fcn { /** * Allegro implementation of Image. */ class FCN_EXTENSION_DECLSPEC AllegroImage : public Image { public: /** * Constructor. Load an image from an Allegro BITMAP. * * NOTE: The functions getPixel and putPixel are only guaranteed to work * before an image has been converted to display format. * * @param bitmap the bitmap from which to load. * @param autoFree true if the surface should automatically be deleted. */ AllegroImage(BITMAP* bitmap, bool autoFree); /** * Destructor. */ virtual ~AllegroImage(); /** * Gets the Allegro bitmap for the image. * * @return the Allegro bitmap for the image. */ virtual BITMAP* getBitmap() const; // Inherited from Image virtual void free(); virtual int getWidth() const; virtual int getHeight() const; virtual Color getPixel(int x, int y); virtual void putPixel(int x, int y, const Color& color); virtual void convertToDisplayFormat(); protected: BITMAP* mBitmap; bool mAutoFree; }; } #endif // end FCN_ALLEGROIMAGE_HPP fifechan-0.1.5/include/fifechan/allegro/allegroimageloader.hpp000066400000000000000000000104331341577075500244420ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_ALLEGROIMAGELOADER_HPP #define FCN_ALLEGROIMAGELOADER_HPP #include #include "fifechan/image.hpp" #include "fifechan/imageloader.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Allegro implementation of ImageLoader. */ class FCN_EXTENSION_DECLSPEC AllegroImageLoader : public ImageLoader { public: // Inherited from ImageLoader virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true); protected: virtual BITMAP* loadBitmap(const std::string& filename, PALETTE pal); }; } #endif // end FCN_ALLEGROIMAGELOADER_HPP fifechan-0.1.5/include/fifechan/allegro/allegroinput.hpp000066400000000000000000000125571341577075500233410ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_ALLEGROINPUT_HPP #define FCN_ALLEGROINPUT_HPP #include #include #include "fifechan/input.hpp" #include "fifechan/keyinput.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Allegro implementation of the Input. */ class FCN_EXTENSION_DECLSPEC AllegroInput : public Input { public: /** * Constructor. */ AllegroInput(); /** * Destructor. */ virtual ~AllegroInput() { } // Inherited from Input virtual bool isKeyQueueEmpty(); virtual KeyInput dequeueKeyInput(); virtual bool isMouseQueueEmpty(); virtual MouseInput dequeueMouseInput(); virtual void _pollInput(); protected: /** * Handles the mouse input called by _pollInput. */ virtual void pollMouseInput(); /** * Handles the key input called by _pollInput. */ virtual void pollKeyInput(); /** * Converts scancode and unicode to Key object. */ virtual Key convertToKey(int scancode, int unicode); virtual bool isNumericPad(int scancode); // This map holds the currently pressed Keys // so we can send the correct key releases. // it maps from scancode to key objects. std::map mPressedKeys; std::queue mKeyQueue; std::queue mMouseQueue; bool mMouseButton1, mMouseButton2, mMouseButton3; int mLastMouseX, mLastMouseY, mLastMouseZ; }; } #endif // end FCN_INPUT_HPP /* * finalman - "A dyslectic walks in to a bra..." * yakslem - "...eh...ok..." */ fifechan-0.1.5/include/fifechan/cairo.hpp000066400000000000000000000101101341577075500202630ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2008 Mehdi Abbad a.k.a slyf0x * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CAIRO_HPP #define FCN_CAIRO_HPP #include #include #include #include extern "C" { /** * Exists to be able to check for Guichan Cairo with autotools. * * @bug Autotools is incapable of finding this function. */ extern void fcnCairo(); } #endif // end FCN_CAIRO_HPP fifechan-0.1.5/include/fifechan/cairo/000077500000000000000000000000001341577075500175615ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/cairo/cairofont.hpp000066400000000000000000000115071341577075500222620ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2008 Mehdi Abbad a.k.a slyf0x * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CAIROFONT_HPP #define FCN_CAIROFONT_HPP #include "fifechan/font.hpp" #include "fifechan/color.hpp" #include "fifechan/platform.hpp" #include "cairo.h" namespace fcn { /** * Cairo font implementation of Fonts used by Cairo. */ class FCN_EXTENSION_DECLSPEC CairoFont : public Font { public: /** * Constructor. * The new created object will hold a reference to the passed fontface. * * @param fontface a Cairo scaled font face created with one of the font backends. */ CairoFont(cairo_scaled_font_t* fontface); /** * Destructor. */ ~CairoFont(); //void SetFontFace(cairo_font_face_t* fontface); void SetFontColor(const Color& color); // Inherited from Font virtual int getWidth(const std::string& text) const; virtual int getHeight() const; virtual void drawString(fcn::Graphics* graphics, const std::string& text, int x, int y); private : cairo_scaled_font_t* mFontFace; cairo_font_extents_t mFontExtents; Color mColor; double mColorR,mColorG,mColorB,mColorA; }; } #endif fifechan-0.1.5/include/fifechan/cairo/cairographics.hpp000066400000000000000000000135741341577075500231220ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2008 Mehdi Abbad a.k.a slyf0x * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CAIROGRAPHICS_HPP #define FCN_CAIROGRAPHICS_HPP #include "fifechan/color.hpp" #include "fifechan/graphics.hpp" #include "fifechan/platform.hpp" #include "cairo.h" namespace fcn { class Image; class Rectangle; /** * Cairo implementation of the Graphics. */ class FCN_EXTENSION_DECLSPEC CairoGraphics : public Graphics { public: // Needed so that drawImage(fcn::Image *, int, int) is visible. using Graphics::drawImage; /** * Constructor. * Create a CairoGraphics backend using a specific cairo target surface. * * @param TargetSurface a cairo_surface_t* where the drawings are made. It can * be any surface type (png, Xlib, Win32). */ CairoGraphics(cairo_surface_t* TargetSurface,int Width,int Height); /** * Destructor. */ virtual ~CairoGraphics(); /** * Returns the current cairo context encapsulated by the graphics object * @return A pointer to the associated cairo_t object. */ cairo_t* GetContext(); // Inherited from Graphics virtual void _beginDraw(); virtual void _endDraw(); virtual bool pushClipArea(Rectangle area); virtual void popClipArea(); virtual void drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height); virtual void drawPoint(int x, int y); virtual void drawLine(int x1, int y1, int x2, int y2); virtual void drawRectangle(const Rectangle& rectangle); virtual void fillRectangle(const Rectangle& rectangle); virtual void setColor(const Color& color); virtual const Color& getColor() const; private: void SetCurrentColorAsSource(); cairo_t* mCairoContext; cairo_surface_t* mTargetSurface; cairo_surface_t* mBufferSurface; int mWidth, mHeight; bool FinalizeTargetSurface; Color mColor; double mColorR,mColorG,mColorB,mColorA; }; } #endif fifechan-0.1.5/include/fifechan/cairo/cairoimage.hpp000066400000000000000000000115451341577075500224000ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2008 Mehdi Abbad a.k.a slyf0x * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CAIROIMAGE_HPP #define FCN_CAIROIMAGE_HPP #include #include #include "fifechan/color.hpp" #include "fifechan/platform.hpp" #include "fifechan/image.hpp" namespace fcn { /** * Cairo implementation of Image. */ class FCN_EXTENSION_DECLSPEC CairoImage : public Image { friend class CairoGraphics; public: CairoImage(cairo_surface_t* surface); /** * Destructor. */ virtual ~CairoImage(); /** * Gets a pointer to the encapsulated cairo image surface. */ cairo_surface_t* GetSurface(); // Inherited from Image virtual void free(); virtual int getWidth() const; virtual int getHeight() const; virtual Color getPixel(int x, int y); virtual void putPixel(int x, int y, const Color& color); virtual void convertToDisplayFormat(); private: unsigned long PrecomputeAlpha(const Color& color); unsigned long GetRGB(const Color& color); Color GetColorFromRGB(unsigned long color); Color GetColorFromARGB(unsigned long color); cairo_surface_t* mCairoSurface; bool mFinished; }; } #endif fifechan-0.1.5/include/fifechan/cairo/cairoimageloader.hpp000066400000000000000000000101451341577075500235620ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2008 Mehdi Abbad a.k.a slyf0x * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CAIROIMAGELOADER_HPP #define FCN_CAIROIMAGELOADER_HPP #include "fifechan/imageloader.hpp" #include "fifechan/platform.hpp" namespace fcn { class Image; /** * Cairo implementation of ImageLoader. */ class FCN_EXTENSION_DECLSPEC CairoImageLoader : public ImageLoader { public: // Inherited from ImageLoader virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true); }; } #endif fifechan-0.1.5/include/fifechan/cliprectangle.hpp000066400000000000000000000131701341577075500220130ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CLIPRECTANGLE_HPP #define FCN_CLIPRECTANGLE_HPP #include "fifechan/rectangle.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * A rectangle used when dealing with clipping. A clip rectangle is * a regular rectangle extended with variables for x offsets and y * offsets. The offsets are used for calculations from relative * screen coordinates to actual screen coordinates. */ class FCN_CORE_DECLSPEC ClipRectangle : public Rectangle { public: /** * Constructor. */ ClipRectangle(); /** * Constructor. * * @param x The rectangle x coordinate. * @param y The rectangle y coordinate. * @param width The rectangle width. * @param height The rectangle height. * @param xOffset The offset of the x coordinate. Used to for * calculating the actual screen coordinate from * the relative screen coordinate. * @param yOffset The offset of the y coordinate. Used to for * calculating the actual screen coordinate from * the relative screen coordinate. */ ClipRectangle(int x, int y, int width, int height, int xOffset, int yOffset); /** * Copy constructor. Copies x, y, width and height * field from a rectangle to a clip rectangle. * * @param other The rectangle to copy data from. * @returns A clip rectangle with data copyied from a rectangle. */ const ClipRectangle& operator=(const Rectangle& other); /** * Holds the x offset of the x coordinate. */ int xOffset; /** * Holds the y offset of the y coordinate. */ int yOffset; }; } #endif // end FCN_CLIPRECTANGLE_HPP fifechan-0.1.5/include/fifechan/color.hpp000066400000000000000000000170151341577075500203170ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_COLOR_HPP #define FCN_COLOR_HPP #include "fifechan/platform.hpp" #include namespace fcn { /** * Represents a color with red, green, blue and alpha components. */ class FCN_CORE_DECLSPEC Color { public: /** * Constructor. Initializes the color to black. */ Color(); /** * Constructor. Constructs a color from the bytes in an integer. * Call it with a hexadecimal constant for HTML-style color representation. * The alpha component is 255 by default. * * EXAMPLE: Color(0xff50a0) constructs a very nice pinkish color. * * NOTE: Because of this constructor, integers will be automatically * casted to a color by your compiler. * * @param color The color to initialise the object with. */ Color(int color); /** * Constructor. The default alpha value is 255. * * @param r Red color component (range 0-255). * @param g Green color component (range 0-255). * @param b Blue color component (range 0-255). * @param a Alpha, used for transparency. A value of 0 means * totaly transparent, 255 is totaly opaque. */ Color(int r, int g, int b, int a = 255); /** * Adds the RGB values of two colors together. The values will be * clamped if they go out of range. * * WARNING: This function will reset the alpha value of the * returned color to 255. * * @param color A color to add to this color. * @return The added colors with an alpha value set to 255. */ Color operator+(const Color& color) const; /** * Subtracts the RGB values of one color from another. * The values will be clamped if they go out of range. * * WARNING: This function will reset the alpha value of the * returned color to 255. * * @param color A color to subtract from this color. * @return The subtracted colors with an alpha value set to 255. */ Color operator-(const Color& color) const; /** * Multiplies the RGB values of a color with a float value. * The values will be clamped if they go out of range. * * @param value The value to multiply the color with. * @return The multiplied colors. The alpha value will, unlike * the add and subtract operations, be multiplied as * well. */ Color operator*(float value) const; /** * Compares two colors. * * @return True if the two colors have the same RGBA components * false otherwise. */ bool operator==(const Color& color) const; /** * Compares two colors. * * @return True if the two colors have different RGBA components, * false otherwise. */ bool operator!=(const Color& color) const; /** * Output operator for output. * * @param out The stream to output to. * @param color The color to output. */ friend std::ostream& operator<<(std::ostream& out, const Color& Color); /** * Holds the red color component (range 0-255). */ int r; /** * Holds the green color component (range 0-255). */ int g; /** * Holds the blue color component (range 0-255). */ int b; /** * Holds the alpha color component. A value of 0 means totally * transparent while a value of 255 is considered opaque. */ int a; }; } #endif // end FCN_COLOR_HPP fifechan-0.1.5/include/fifechan/containerevent.hpp000066400000000000000000000117771341577075500222360ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CONTAINEREVENT_HPP #define FCN_CONTAINEREVENT_HPP #include "fifechan/event.hpp" #include "fifechan/platform.hpp" namespace fcn { class Container; class Widget; /** * Represents a container event. A container event is an event * that can be fired by a container whenever a widget is added * or removed. * * Any object can listen for actions from a container by implementing * the ContainerListener interface. * * @see Container::addContainerListener, Container::removeContainerListener, * Container::distributeContainerEvent * @author Olof Naessn */ class FCN_CORE_DECLSPEC ContainerEvent: public Event { public: /** * Constructor. * * @param source The source widget of the event. * @param container The container the event concerns. */ ContainerEvent(Widget* source, Container* container); /** * Destructor. */ virtual ~ContainerEvent(); /** * Gets the container the event concerns. * * @return The container the event concerns. */ Container* getContainer() const; protected: /** * Holds the container the event concerns. */ Container* mContainer; }; } #endif // FCN_ACTIONEVENT_HPP fifechan-0.1.5/include/fifechan/containerlistener.hpp000066400000000000000000000116671341577075500227400ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CONTAINERLISTENER_HPP #define FCN_CONTAINERLISTENER_HPP #include "fifechan/containerevent.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Interface for listening for action from a container, such as BasicContainer. * * @see BasicContainer::addContainerListener, BasicContainer::removeContainerListener, * ContainerEvent * @author Olof Naessn */ class FCN_CORE_DECLSPEC ContainerListener { public: /** * Destructor. */ virtual ~ContainerListener() { } /** * Called when a widget is added to a container. * * @param containerEvent The event of the action. */ virtual void widgetAdded(const ContainerEvent& containerEvent) = 0; /** * Called when a widget is removed from a container. * * @param containerEvent The event of the action. */ virtual void widgetRemoved(const ContainerEvent& containerEvent) = 0; protected: /** * Constructor. * * You should not be able to make an instance of ContainerListener, * therefore its constructor is protected. */ ContainerListener() { } }; } #endif // end FCN_ACTIONLISTENER_HPP fifechan-0.1.5/include/fifechan/contrib/000077500000000000000000000000001341577075500201245ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/contrib/allegro/000077500000000000000000000000001341577075500215515ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/contrib/allegro/allegroglyphkeeperfont.hpp000066400000000000000000000132631341577075500270430ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CONTRIB_ALLEGROTRUETYPEFONT_HPP #define FCN_CONTRIB_ALLEGROTRUETYPEFONT_HPP #include "fifechan/font.hpp" #include "fifechan/platform.hpp" struct GLYPH_FACE; struct GLYPH_REND; struct GLYPH_KEEP; namespace fcn { class Graphics; namespace contrib { /** * True type font support using Allegro and GlyphKeeper. * * Note: GlyphKeeper must be compiled for allegro (define * GLYPH_TARGET=GLYPH_TARGET_ALLEGRO) and must be * initialized before using this class. * * There's only basic functionality implemented here, so * you can add more and advanced functionality by deriving * from this class. * * @author Tobias Scheuer. */ class FCN_EXTENSION_DECLSPEC AllegroGlyphKeeperFont : public Font { public: /** * Constructor. * * @param filename the filename of the True Type Font. * @param size the size the font should be in. */ AllegroGlyphKeeperFont(const std::string& filename, int size); /** * Constructor. * * @param filename the filename of the True Type Font. * @param width the width the font should be in. * @param height the height the font should be in. */ AllegroGlyphKeeperFont(const std::string& filename, int width, int height); /** * Destructor. */ ~AllegroGlyphKeeperFont(); // Inherited from Font virtual int getWidth(const std::string& text) const; virtual int getHeight() const; virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); protected: void load(const std::string& filename, int w, int h); GLYPH_FACE* mFace; GLYPH_REND* mRend; GLYPH_KEEP* mKeeper; }; } } #endif fifechan-0.1.5/include/fifechan/contrib/opengl/000077500000000000000000000000001341577075500214105ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/contrib/opengl/oglftfont.hpp000066400000000000000000000126121341577075500241250ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CONTRIB_OGLFTFONT_HPP #define FCN_CONTRIB_OGLFTFONT_HPP #include #include #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" #include "fifechan/platform.hpp" namespace fcn { namespace contrib { /** * OpenGL True Type Font implementation of Font. It uses the OGLFT library * to display True Type Fonts with OpenGL. * * @author Verneuil Julien */ class FCN_EXTENSION_DECLSPEC OGLFTFont: public Font { public: /** * Constructor. * * @param filename the filename of the True Type Font. * @param size the size the font should be in. */ OGLFTFont (const std::string& filename, int size); /** * Destructor. */ virtual ~OGLFTFont(); /** * Sets the spacing between rows in pixels. Default is 0 pixels. * The spacing can be negative. * * @param spacing the spacing in pixels. */ virtual void setRowSpacing (int spacing); /** * Gets the spacing between rows in pixels. * * @return the spacing. */ virtual int getRowSpacing(); // Inherited from Font virtual int getWidth(const std::string& text) const; virtual int getHeight() const; virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); protected: OGLFT::TranslucentTexture* mFont; std::string mFilename; int mSize; int mRowSpacing; }; } } #endif fifechan-0.1.5/include/fifechan/contrib/sdl/000077500000000000000000000000001341577075500207065ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/contrib/sdl/sdltruetypefont.hpp000066400000000000000000000150301341577075500246710ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CONTRIB_SDLTRUETYPEFONT_HPP #define FCN_CONTRIB_SDLTRUETYPEFONT_HPP #include #include #include #include "fifechan/font.hpp" #include "fifechan/platform.hpp" namespace fcn { class Graphics; namespace contrib { /** * SDL True Type Font implementation of Font. It uses the SDL_ttf library * to display True Type Fonts with SDL. * * NOTE: You must initialize the SDL_ttf library before using this * class. Also, remember to call the SDL_ttf libraries quit * function. * * @author Walluce Pinkham * @author Olof Naessn */ class FCN_EXTENSION_DECLSPEC SDLTrueTypeFont: public Font { public: /** * Constructor. * * @param filename the filename of the True Type Font. * @param size the size the font should be in. */ SDLTrueTypeFont (const std::string& filename, int size); /** * Destructor. */ virtual ~SDLTrueTypeFont(); /** * Sets the spacing between rows in pixels. Default is 0 pixels. * The spacing can be negative. * * @param spacing the spacing in pixels. */ virtual void setRowSpacing (int spacing); /** * Gets the spacing between rows in pixels. * * @return the spacing. */ virtual int getRowSpacing(); /** * Sets the spacing between letters in pixels. Default is 0 pixels. * The spacing can be negative. * * @param spacing the spacing in pixels. */ virtual void setGlyphSpacing(int spacing); /** * Gets the spacing between letters in pixels. * * @return the spacing. */ virtual int getGlyphSpacing(); /** * Sets the use of anti aliasing.. * * @param antaAlias true for use of antia aliasing. */ virtual void setAntiAlias(bool antiAlias); /** * Checks if anti aliasing is used. * * @return true if anti aliasing is used. */ virtual bool isAntiAlias(); // Inherited from Font virtual int getWidth(const std::string& text) const; virtual int getHeight() const; virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); protected: TTF_Font *mFont; int mHeight; int mGlyphSpacing; int mRowSpacing; std::string mFilename; bool mAntiAlias; }; } } #endif fifechan-0.1.5/include/fifechan/deathlistener.hpp000066400000000000000000000112341341577075500220310ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_DEATHLISTENER_HPP #define FCN_DEATHLISTENER_HPP #include #include "fifechan/event.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Interface for listening for death events from widgets. * * @see Widget::addDeathListener, Widget::removeDeathListener * @author Olof Naessn */ class FCN_CORE_DECLSPEC DeathListener { public: /** * Destructor. */ virtual ~DeathListener() { } /** * Called when a widget dies. It is used to be able to recieve * a notification when a death of a widget occurs. * * @param event The event of the death. */ virtual void death(const Event& event) = 0; protected: /** * Constructor. * * You should not be able to make an instance of DeathListener, * therefore its constructor is protected. */ DeathListener() { } }; } #endif // end FCN_DEATHLISTENER_HPP fifechan-0.1.5/include/fifechan/defaultfont.hpp000066400000000000000000000122311341577075500215070ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_DEFAULTFONT_HPP #define FCN_DEFAULTFONT_HPP #include "fifechan/font.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * A font only capable of drawing rectangles. It is used by default * in Fifechan if no font has been set merely to show that no font has * been set. */ class FCN_CORE_DECLSPEC DefaultFont : public Font { public: /** * Destructor. */ virtual ~DefaultFont(){} /** * Draws a glyph as a rectangle. The glyphs will always be drawn as * rectangles no matter the glyph. * * NOTE: You normally won't use this function to draw text since * the Graphics class contains better functions for drawing * text. * * @param graphics A Graphics object to be used for drawing. * @param glyph The glyph to draw. * @param x The x coordinate where to draw the glyph. * @param y The y coordinate where to draw the glyph. * @return The width of the drawn glyph in pixels. */ virtual int drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y); // Inherited from Font virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); virtual int getWidth(const std::string& text) const; virtual int getHeight() const; virtual int getStringIndexAt(const std::string& text, int x) const; }; } #endif // end FCN_DEFAULTFONT_HPP fifechan-0.1.5/include/fifechan/directx3d.hpp000066400000000000000000000101351341577075500210660ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2007 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_D3D_HPP #define FCN_D3D_HPP #include #include #include #include #include "platform.hpp" extern "C" { /** * Exists to be able to check for Guichan Directx 3D with autotools. */ FCN_EXTENSION_DECLSPEC extern void fcnD3D(); } #endif // end FCN_D3D_HPP fifechan-0.1.5/include/fifechan/directx3d/000077500000000000000000000000001341577075500203555ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/directx3d/directx3dgraphics.hpp000066400000000000000000000172351341577075500245100ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2007 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_DIRECTX3DGRAPHICS_HPP #define FCN_DIRECTX3DGRAPHICS_HPP #include "fifechan/color.hpp" #include "fifechan/graphics.hpp" #include "fifechan/platform.hpp" #include namespace fcn { /** * DirectX 3D implementation of the Graphics. */ class FCN_EXTENSION_DECLSPEC DirectX3DGraphics: public Graphics { public: // Needed so that drawImage(fcn::Image *, int, int) is visible. using Graphics::drawImage; /** * Constructor. * * @param device The D3D device to use when drawing. */ DirectX3DGraphics(LPDIRECT3DDEVICE9 device); /** * Constructor. * * @param device The D3D device to use when drawing. * @param width The width of the logical drawing surface. Should be the * same as the screen resolution. * @param height The height ot the logical drawing surface. Should be * the same as the screen resolution. */ DirectX3DGraphics(LPDIRECT3DDEVICE9 device, int width, int height); /** * Destructor. */ virtual ~DirectX3DGraphics(); /** * Sets the target plane on where to draw. * * @param width The width of the logical drawing surface. Should be the * same as the screen resolution. * @param height The height ot the logical drawing surface. Should be * the same as the screen resolution. */ virtual void setTargetPlane(int width, int height); /** * Sets the D3D device to use when drawing. * * @param device The D3D device to use when drawing. */ virtual void setDevice(LPDIRECT3DDEVICE9 device); /** * Gets the D3D device to use when drawing. * * @return The D3D device to use when drawing. */ virtual LPDIRECT3DDEVICE9 getDevice() const; /** * Gets the width of the target plane. * * @return The width of the target plane. */ virtual int getTargetPlaneWidth() const; /** * Gets the height of the target plane. * * @return The height of the target plane. */ virtual int getTargetPlaneHeight() const; /** * A struct for plain vertex information. */ struct Vertex { float x, y, z, rhw; DWORD color; }; /** * A struct for vertex information that contians texture coordinates. */ struct VertexWithTexture { float x, y, z, rhw; DWORD color; float u, v; }; // Inherited from Graphics virtual void _beginDraw(); virtual void _endDraw(); virtual bool pushClipArea(Rectangle area); virtual void popClipArea(); virtual void drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height); virtual void drawPoint(int x, int y); virtual void drawLine(int x1, int y1, int x2, int y2); virtual void drawRectangle(const Rectangle& rectangle); virtual void fillRectangle(const Rectangle& rectangle); virtual void setColor(const Color& color); virtual const Color& getColor() const; protected: /** * Hold the width of the target plane. */ int mWidth; /** * Holds the height of the target plane. */ int mHeight; /** * True if the last color set includes alpha. */ bool mAlpha; /** * Holds the last color set. */ Color mColor; /** * Holds the D3D device to use when drawing. */ LPDIRECT3DDEVICE9 mDevice; }; } #endif // end FCN_DIRECTX3DGRAPHICS_HPP fifechan-0.1.5/include/fifechan/directx3d/directx3dimage.hpp000066400000000000000000000150231341577075500237630ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2007 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_DIRECTX3DIMAGE_HPP #define FCN_DIRECTX3DIMAGE_HPP #include #include #include #include "fifechan/color.hpp" #include "fifechan/platform.hpp" #include "fifechan/image.hpp" namespace fcn { /** * DirectX implementation of Image. */ class FCN_EXTENSION_DECLSPEC DirectX3DImage : public Image { public: /** * Constructor. Load an image from a DirectX surface. * * @param surface The surface from which to load. * @param device The D3D device to use when converting the image to display format. * @param autoFree True if the surface should automatically be deleted. */ DirectX3DImage(LPDIRECT3DSURFACE9 surface, LPDIRECT3DDEVICE9 device, int width, int height, bool autoFree); /** * Destructor. */ virtual ~DirectX3DImage(); /** * Gets the D3D texture for the image. * * @return The D3D texture handle for the image. */ virtual LPDIRECT3DTEXTURE9 getTexture() const; /** * Gets the D3D texture width of the image. * * @return The D3D texture width of the image. */ virtual int getTextureWidth() const; /** * Gets the D3D texture height of the image. * * @return The D3D texture height of the image. */ virtual int getTextureHeight() const; // Inherited from Image virtual void free(); virtual int getWidth() const; virtual int getHeight() const; virtual Color getPixel(int x, int y); virtual void putPixel(int x, int y, const Color& color); virtual void convertToDisplayFormat(); protected: /** * Holds the surface image. This surface is NULL after the image * has been converted to display format. */ LPDIRECT3DSURFACE9 mSurface; /** * Holds the texture of the image. This texture isn't initialized until * the image is converted to display format. */ LPDIRECT3DTEXTURE9 mTexture; /** * Holds the D3D device used when converting the image to display format. */ LPDIRECT3DDEVICE9 mDevice; /** * True if the image should be auto freed. */ bool mAutoFree; /** * Holds the width of the image. */ int mWidth; /** * Holds the height of the image. */ int mHeight; /** * Holds the texture width of the image. */ int mTextureWidth; /** * Holds the texture height of the image. */ int mTextureHeight; }; } #endif // end FCN_DIRECTX3DIMAGE_HPP fifechan-0.1.5/include/fifechan/directx3d/directx3dimageloader.hpp000066400000000000000000000113331341577075500251520ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2007 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_DIRECTX3DIMAGELOADER_HPP #define FCN_DIRECTX3DIMAGELOADER_HPP #include "fifechan/imageloader.hpp" #include "fifechan/platform.hpp" #include namespace fcn { class Image; /** * DirectX ImageLoader. */ class FCN_EXTENSION_DECLSPEC DirectX3DImageLoader : public ImageLoader { public: /** * Constructor. * * @param device The D3D device to use when loading images. */ DirectX3DImageLoader(LPDIRECT3DDEVICE9 device); /** * Sets the D3D device to use when loading images. * * @param device The D3D device to use when loading images. */ virtual void setDevice(LPDIRECT3DDEVICE9 device); // Inherited from ImageLoader virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true); protected: /** * Holds the D3D device to use when loading images. */ LPDIRECT3DDEVICE9 mDevice; }; } #endif // end FCN_DIRECTX3DIMAGELOADER_HPP fifechan-0.1.5/include/fifechan/directx3d/directx3dinput.hpp000066400000000000000000000134571341577075500240510ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2007 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_DIRECTX3DINPUT_HPP #define FCN_DIRECTX3DINPUT_HPP #include #define WIN32_LEAN_AND_MEAN #include #include "fifechan/input.hpp" #include "fifechan/keyinput.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/platform.hpp" namespace fcn { class Key; /** * DirectX 3D implementation of Input. */ class FCN_EXTENSION_DECLSPEC DirectX3DInput : public Input { public: /** * Constructor. */ DirectX3DInput(); /** * Dispatches a windows message. It should be called as soon as a windows * message is received in the window proc function. * * @param window A windows window handle. * @param message A message from windows. */ virtual void dispatchMessage(HWND window, MSG message); /** * Polls all input. It exists for input driver compatibility. If you * only use DirectX and plan sticking with DirectX you can safely ignore this * function as it in the DirectX case does nothing. */ virtual void _pollInput() { } // Inherited from Input virtual bool isKeyQueueEmpty(); virtual KeyInput dequeueKeyInput(); virtual bool isMouseQueueEmpty(); virtual MouseInput dequeueMouseInput(); protected: /** * Converts a character to a key value. * * @param wParam Windows parameter to retreive * character information from. * @param lParam Windows parameter to retreive * character information from. * @param kbstate The keybord state retreived from * GetKeyboardState. * @return A key value. * @see Key */ int convertKeyCharacter(WPARAM wParam, LPARAM lParam, unsigned char * kbstate); std::queue mKeyInputQueue; std::queue mMouseInputQueue; int mLastMouseZ; bool mMouseDown; bool mMouseInWindow; }; } #endif // end FCN_DIRECTX3DINPUT_HPP fifechan-0.1.5/include/fifechan/event.hpp000066400000000000000000000110701341577075500203150ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_EVENT_HPP #define FCN_EVENT_HPP #include "fifechan/platform.hpp" namespace fcn { class Widget; /** * Base class for all events. All events in Guichan should * inherit from this class. * * @author Olof Naessn */ class FCN_CORE_DECLSPEC Event { public: /** * Constructor. * * @param source The source widget of the event. */ Event(Widget* source); /** * Destructor. */ virtual ~Event(); /** * Gets the source widget of the event. The function * is used to tell which widget fired an event. * * @return The source widget of the event. */ Widget* getSource() const; protected: /** * Holds the source widget of the event. */ Widget* mSource; }; } #endif // end FCN_EVENT_HPP fifechan-0.1.5/include/fifechan/exception.hpp000066400000000000000000000165761341577075500212120ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_EXCEPTION_HPP #define FCN_EXCEPTION_HPP #include #include "fifechan/platform.hpp" #ifndef __FUNCTION__ #define __FUNCTION__ "?" #endif /* * A macro used to create a standard exception object. * What it basicly does is that it creates a new exception * and automatically sets the filename and line number where * the exception occured by using other compiler macros. */ #define FCN_EXCEPTION(mess) fcn::Exception(mess, \ __FUNCTION__, \ __FILE__, \ __LINE__) namespace fcn { /** * An exception containing a message, a file and a line number * where the exception occured. Guichan will only throw exceptions * of this class. * * You can use this class for your own exceptions that has * something to do with a GUI exception. A nifty feature of the * excpetion class is that it can tell you from which line and * file it was thrown. To make things easier when throwing * exceptions there exists a macro for creating exceptions * which automatically sets the filename and line number. * * EXAMPLE: @code * throw FCN_EXCEPTION("my error message"); * @endcode */ class FCN_CORE_DECLSPEC Exception { public: /** * Constructor. */ Exception(); /** * Constructor. * * @param message The error message of the exception. */ Exception(const std::string& message); /** * Constructor. * * NOTE: Don't use this constructor. Use the FCN_EXCEPTION macro instead. * This constructor merely exists for the FCN_EXCEPTION macro to * use. * * @param message The error message of the exception. * @param function The function name where the exception occured. * @param filename The name of the file where the exception occured. * @param line The line number in the source code where the exception * occured. */ Exception(const std::string& message, const std::string& function, const std::string& filename, unsigned int line); /** * Gets the function name where the exception occured. * * @return The function name where the exception occured. */ const std::string& getFunction() const; /** * Gets the error message of the exception. * * @return The error message of the exception. */ const std::string& getMessage() const; /** * Gets the filename where the exception occured. * * @return The filename where the exception occured. */ const std::string& getFilename() const; /** * Gets the line number where the exception occured. * * @return The line number where the exception occured. */ unsigned int getLine() const; protected: /** * Holds the name of the function name where the * exception occured. */ std::string mFunction; /** * Holds the error message of the exception. */ std::string mMessage; /** * Holds the filename where the exception occured. */ std::string mFilename; /** * Holds the line number where the exception occured. */ unsigned int mLine; }; } #endif // end FCN_EXCEPTION_HPP /* * "Final Fantasy XI is the BEST!... It's even better then water!" * - Astrolite * I believe it's WoW now days. */ fifechan-0.1.5/include/fifechan/focushandler.hpp000066400000000000000000000356521341577075500216650ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_FOCUSHANDLER_HPP #define FCN_FOCUSHANDLER_HPP #include #include "fifechan/event.hpp" #include "fifechan/platform.hpp" namespace fcn { class Widget; /** * Handles focus for widgets in a Gui. Each Gui has at least one * focus handler. * You will probably not use the focus handler directly as Widget * has functions that automatically uses the active focus handler. * * @see Widget::isFocus, Widget::isModalFocused, * Widget::isModalMouseInputFocused, Widget::requestFocus, * Widget::requestModalFocus, Widget::requestModalMouseInputFocus, * Widget::releaseModalFocus, Widget::relaseModalMouseInputFocus, * Widget::setFocusable, Widget::isFocusable, FocusListener * */ class FCN_CORE_DECLSPEC FocusHandler { public: /** * Constructor. */ FocusHandler(); /** * Destructor. */ virtual ~FocusHandler() { }; /** * Requests focus for a widget. Focus will only be granted to a widget * if it's focusable and if no other widget has modal focus. * If a widget receives focus a focus event will be sent to the * focus listeners of the widget. * * @param widget The widget to request focus for. * @see isFocused, Widget::requestFocus */ virtual void requestFocus(Widget* widget); /** * Requests modal focus for a widget. Focus will only be granted * to a widget if it's focusable and if no other widget has modal * focus. * * @param widget The widget to request modal focus for. * @throws Exception when another widget already has modal focus. * @see releaseModalFocus, Widget::requestModalFocus */ virtual void requestModalFocus(Widget* widget); /** * Requests modal mouse input focus for a widget. Focus will only * be granted to a widget if it's focusable and if no other widget * has modal mouse input focus. * * Modal mouse input focus means no other widget then the widget with * modal mouse input focus will receive mouse input. The widget with * modal mouse input focus will also receive mouse input no matter what * the mouse input is or where the mouse input occurs. * * @param widget The widget to focus for modal mouse input focus. * @throws Exception when another widget already has modal mouse input * focus. * @see releaseModalMouseInputFocus, Widget::requestModalMouseInputFocus */ virtual void requestModalMouseInputFocus(Widget* widget); /** * Releases modal focus if the widget has modal focus. * If the widget doesn't have modal focus no relase will occur. * * @param widget The widget to release modal focus for. * @see reuqestModalFocus, Widget::releaseModalFocus */ virtual void releaseModalFocus(Widget* widget); /** * Releases modal mouse input focus if the widget has modal mouse input * focus. If the widget doesn't have modal mouse input focus no relase * will occur. * * @param widget the widget to release modal mouse input focus for. * @see requestModalMouseInputFocus, Widget::releaseModalMouseInputFocus */ virtual void releaseModalMouseInputFocus(Widget* widget); /** * Checks if a widget is focused. * * @param widget The widget to check. * @return True if the widget is focused, false otherwise. * @see Widget::isFocused */ virtual bool isFocused(const Widget* widget) const; /** * Gets the widget with focus. * * @return The widget with focus. NULL if no widget has focus. */ virtual Widget* getFocused() const; /** * Gets the widget with modal focus. * * @return The widget with modal focus. NULL if no widget has * modal focus. */ virtual Widget* getModalFocused() const; /** * Gets the widget with modal mouse input focus. * * @return The widget with modal mouse input focus. NULL if * no widget has modal mouse input focus. */ virtual Widget* getModalMouseInputFocused() const; /** * Focuses the next widget added to a conainer. * If no widget has focus the first widget gets focus. The order * in which the widgets are focused is determined by the order * they were added to a container. * * @see focusPrevious */ virtual void focusNext(); /** * Focuses the previous widget added to a contaienr. * If no widget has focus the first widget gets focus. The order * in which the widgets are focused is determined by the order * they were added to a container. * * @see focusNext */ virtual void focusPrevious(); /** * Adds a widget to by handles by the focus handler. * * @param widget The widget to add. * @see remove */ virtual void add(Widget* widget); /** * Removes a widget from the focus handler. * * @param widget The widget to remove. * @see add */ virtual void remove(Widget* widget); /** * Focuses nothing. A focus event will also be sent to the * focused widget's focus listeners if a widget has focus. */ virtual void focusNone(); /** * Focuses the next widget which allows tabbing in unless * the current focused Widget disallows tabbing out. * * @see tabPrevious */ virtual void tabNext(); /** * Focuses the previous widget which allows tabbing in unless * current focused widget disallows tabbing out. * * @see tabNext */ virtual void tabPrevious(); /** * Gets the widget being dragged. Used by the Gui class to * keep track of the dragged widget. * * @return the widget being dragged. * @see setDraggedWidget */ virtual Widget* getDraggedWidget(); /** * Sets the widget being dragged. Used by the Gui class to * keep track of the dragged widget. * * @param draggedWidget The widget being dragged. * @see getDraggedWidget */ virtual void setDraggedWidget(Widget* draggedWidget); /** * Gets the last widget with the mouse. Used by the Gui class * to keep track the last widget with the mouse. * * @return The last widget with the mouse. * @see setLastWidgetWithMouse */ virtual Widget* getLastWidgetWithMouse(); /** * Sets the last widget with the mouse. Used by the Gui class * to keep track the last widget with the mouse. * * @param lastWidgetWithMouse The last widget with the mouse. * @see getLastWidgetWithMouse */ virtual void setLastWidgetWithMouse(Widget* lastWidgetWithMouse); /** * Gets the last widget with modal focus. * * @return The last widget with modal focus. * @see setLastWidgetWithModalFocus */ virtual Widget* getLastWidgetWithModalFocus(); /** * Sets the last widget with modal focus. * * @param lastWidgetWithModalFocus The last widget with modal focus. * @see getLastWidgetWithModalFocus */ virtual void setLastWidgetWithModalFocus(Widget* lastWidgetWithModalFocus); /** * Gets the last widget with modal mouse input focus. * * @return The last widget with modal mouse input focus. * @see setLastWidgetWithModalMouseInputFocus */ virtual Widget* getLastWidgetWithModalMouseInputFocus(); /** * Sets the last widget with modal mouse input focus. * * @param lastMouseWithModalMouseInputFocus The last widget with * modal mouse input focus. * @see getLastWidgetWithModalMouseInputFocus */ virtual void setLastWidgetWithModalMouseInputFocus(Widget* lastWidgetWithModalMouseInputFocus); /** * Gets the last widget pressed. Used by the Gui class to keep track * of pressed widgets. * * @return The last widget pressed. * @see setLastWidgetPressed */ virtual Widget* getLastWidgetPressed(); /** * Sets the last widget pressed. Used by the Gui class to keep track * of pressed widgets. * * @param lastWidgetPressed The last widget pressed. * @see getLastWidgetPressed */ virtual void setLastWidgetPressed(Widget* lastWidgetPressed); /** * Informs the focus handler that a widget was hidden. This is needed because * the focus handler must determine which widget has the mouse now. * * @param widget Widget that was hidden */ virtual void widgetHidden(Widget* widget); protected: /** * Distributes a focus lost event. * * @param focusEvent the event to distribute. */ virtual void distributeFocusLostEvent(const Event& focusEvent); /** * Distributes a focus gained event. * * @param focusEvent the event to distribute. */ virtual void distributeFocusGainedEvent(const Event& focusEvent); /** * Typedef. */ typedef std::vector WidgetVector; /** * Typedef. */ typedef WidgetVector::iterator WidgetIterator; /** * Holds the widgets currently being handled by the * focus handler. */ WidgetVector mWidgets; /** * Holds the focused widget. NULL if no widget has focus. */ Widget* mFocusedWidget; /** * Holds the modal focused widget. NULL if no widget has * modal focused. */ Widget* mModalFocusedWidget; /** * Holds the modal mouse input focused widget. NULL if no widget * is being dragged. */ Widget* mModalMouseInputFocusedWidget; /** * Holds the dragged widget. NULL if no widget is * being dragged. */ Widget* mDraggedWidget; /** * Holds the last widget with the mouse. */ Widget* mLastWidgetWithMouse; /** * Holds the last widget with modal focus. */ Widget* mLastWidgetWithModalFocus; /** * Holds the last widget with modal mouse input focus. */ Widget* mLastWidgetWithModalMouseInputFocus; /** * Holds the last widget pressed. */ Widget* mLastWidgetPressed; }; } #endif // end FCN_FOCUSHANDLER_HPP fifechan-0.1.5/include/fifechan/focuslistener.hpp000066400000000000000000000114051341577075500220630ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_FOCUSLISTENER_HPP #define FCN_FOCUSLISTENER_HPP #include #include "fifechan/event.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Interface for listening for focus events from widgets. * * @see Widget::addFocusListener, Widget::removeFocusListener * @author Olof Naessn */ class FCN_CORE_DECLSPEC FocusListener { public: /** * Destructor. */ virtual ~FocusListener() { } /** * Called when a widget gains focus. * * @param event Discribes the event. */ virtual void focusGained(const Event& event) { }; /** * Called when a widget loses focus. * * @param event Discribes the event. */ virtual void focusLost(const Event& event) { }; protected: /** * Constructor. * * You should not be able to make an instance of FocusListener, * therefore its constructor is protected. */ FocusListener() { } }; } #endif // end FCN_FOCUSLISTENER_HPP fifechan-0.1.5/include/fifechan/font.hpp000066400000000000000000000131101341577075500201370ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_FONT_HPP #define FCN_FONT_HPP #include #include "fifechan/platform.hpp" namespace fcn { class Graphics; /** * Interface for a font. * * @see ImageFont */ class FCN_CORE_DECLSPEC Font { public: /** * Destructor. */ virtual ~Font(){ } /** * Gets the width of a string. The width of a string is not necesserily * the sum of all the widths of it's glyphs. * * @param text The string to return the width of. * @return The width of a string. */ virtual int getWidth(const std::string& text) const = 0; /** * Gets the height of the glyphs in the font. * * @return The height of the glyphs int the font. */ virtual int getHeight() const = 0; /** * Gets a string index in a string providing an x coordinate. * Used to retrive a string index (for a character in a * string) at a certain x position. It is especially useful * when a mouse clicks in a TextField and you want to know which * character was clicked. * * @return A string index in a string providing an x coordinate. */ virtual int getStringIndexAt(const std::string& text, int x) const; /** * Draws a string. * * NOTE: You normally won't use this function to draw text since * Graphics contains better functions for drawing text. * * @param graphics A Graphics object to use for drawing. * @param text The string to draw. * @param x The x coordinate where to draw the string. * @param y The y coordinate where to draw the string. */ virtual void drawString(Graphics* graphics, const std::string& text, int x, int y) = 0; }; } #endif // end FCN_FONT_HPP fifechan-0.1.5/include/fifechan/genericinput.hpp000066400000000000000000000164431341577075500217010ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_GENERICINPUT_HPP #define FCN_GENERICINPUT_HPP #include #include "fifechan/input.hpp" #include "fifechan/keyinput.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/platform.hpp" namespace fcn { class Key; /** * Implementation of a generic input which can be used with any * back end. */ class FCN_CORE_DECLSPEC GenericInput: public Input { public: /** * Constructor. */ GenericInput(); /** * Pushes a key pressed event. * * NOTE: If a special key is pressed, like the F1 key, * the corresponding Guichan key value found * in the enum in Key should be pushed as the * unicode value. * * @param unicode The unicode value of the key. */ void pushKeyPressed(int unicode); /** * Pushes a key released event. * * NOTE: If a special key is pressed, like the F1 key, * the corresponding Guichan key value found * in the enum in Key should be pushed as the * unicode value. * * @param unicode The unicode value of the key. */ void pushKeyReleased(int unicode); /** * Pushes a mouse button pressed event. * * @param x The x coordinate of the mouse event. * @param y The y coordinate of the mouse event. * @param button The button of the mouse event. */ void pushMouseButtonPressed(int x, int y, int button); /** * Pushes a mouse button released event. * * @param x The x coordinate of the mouse event. * @param y The y coordinate of the mouse event. * @param button The button of the mouse event. */ void pushMouseButtonReleased(int x, int y, int button); /** * Pushes a mouse wheel moved up event. * * @param x The x coordinate of the mouse event. * @param y The y coordinate of the mouse event. */ void pushMouseWheelMovedUp(int x, int y); /** * Pushes a mouse wheel moved down event. * * @param x The x coordinate of the mouse event. * @param y The y coordinate of the mouse event. */ void pushMouseWheelMovedDown(int x, int y); /** * Pushes a mouse wheel moved right event. * * @param x The x coordinate of the mouse event. * @param y The y coordinate of the mouse event. */ void pushMouseWheelMovedRight(int x, int y); /** * Pushes a mouse wheel moved left event. * * @param x The x coordinate of the mouse event. * @param y The y coordinate of the mouse event. */ void pushMouseWheelMovedLeft(int x, int y); /** * Pushes a mouse moved event. * * @param x The x coordinate of the mouse event. * @param y The y coordinate of the mouse event. */ void pushMouseMoved(int x, int y); // Inherited from Input virtual bool isKeyQueueEmpty(); virtual KeyInput dequeueKeyInput(); virtual bool isMouseQueueEmpty(); virtual MouseInput dequeueMouseInput(); virtual void _pollInput(); protected: /** * Holds the key input queue. */ std::queue mKeyInputQueue; /** * Holds the mouse input queue. */ std::queue mMouseInputQueue; }; } #endif // end FCN_INPUT_HPP fifechan-0.1.5/include/fifechan/glut.hpp000066400000000000000000000076651341577075500201660ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_GLUT_HPP #define FCN_GLUT_HPP #include #include "platform.hpp" extern "C" { /** * Exists to be able to check for Guichan GLUT with autotools. */ FCN_EXTENSION_DECLSPEC extern void fcnGLUT(); } #endif // end FCN_GLUT_HPP fifechan-0.1.5/include/fifechan/glut/000077500000000000000000000000001341577075500174375ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/glut/glutinput.hpp000066400000000000000000000172621341577075500222130ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // #ifndef FCN_GLUTINPUT_HPP // #define FCN_GLUTINPUT_HPP // #include // #include // #include "fifechan/input.hpp" // #include "fifechan/key.hpp" // #include "fifechan/keyinput.hpp" // #include "fifechan/mouseinput.hpp" // #include "fifechan/platform.hpp" // namespace fcn // { // /** // * GLUT implementation of Input. // */ // class FCN_EXTENSION_DECLSPEC GLUTInput : public Input // { // public: // /** // * Constructor. // */ // GLUTInput(); // /** // * Pushes a key down. It should be called in the // * glutKeyboardFunc call back function. // * // * @param key a key from GLUT. // */ // virtual void pushKeyDownInput(unsigned char key); // /** // * Pushes a key up. It should be called in the // * glutKeyboardUpFunc call back function. // * // * @param key a key from GLUT. // */ // virtual void pushKeyUpInput(unsigned char key); // /** // * Pushes a special key down. It should be called in the // * glutSpecialFunc call back function. // * // * @param key a key from GLUT. // */ // virtual void pushSpecialDownInput(unsigned char key); // /** // * Pushes a special key up. It should be called in the // * glutSpecialUpFunc call back function. // * // * @param key a key from GLUT. // */ // virtual void pushSpecialUpInput(unsigned char key); // /** // * Pushes a mouse input. It should be called in the glutMouseFunc // * call back function. // * // * @param button a button from GLUT. // * @param state a mouse state from GLUT. // * @param x an x coordinate from GLUT. // * @param y an y coordinate from GLUT. // */ // virtual void pushMouseInput(int button, int state, int x, int y); // /** // * Pushes a mouse motion input. It should be called in the // * glutMotionFunc call back function. // * // * @param x an x coordinate from GLUT. // * @param y an y coordinate from GLUT. // */ // virtual void pushMotionInput(int x, int y); // /** // * Pushes a passive mouse motion input. It should be called in the // * glutPassiveMotionFunc call back function. // * // * @param x an x coordinate from GLUT. // * @param y an y coordinate from GLUT. // */ // virtual void pushPassiveMotionInput(int x, int y); // /** // * Polls all input. It exists for input driver compatibility. If you // * only use GLUT and plan sticking with GLUT you can safely ignore this // * function as it in the GLUT case does nothing. // */ // virtual void _pollInput() { } // // Inherited from Input // virtual bool isKeyQueueEmpty(); // virtual KeyInput dequeueKeyInput(); // virtual bool isMouseQueueEmpty(); // virtual MouseInput dequeueMouseInput(); // protected: // /** // * Converts a GLUT key to a Key object. // * // * @param key a GLUT key. // * @return a Key object. // */ // Key convertKeyCharacter(unsigned char key); // /** // * Converts a special GLUT key to a Key object. // * // * @param key a GLUT key. // * @return a Key object. // */ // Key convertSpecialCharacter(unsigned char key); // /** // * Converts a mouse button from GLUT to a Guichan mouse button // * representation. // * // * @param button a GLUT mouse button. // * @return a Guichan mouse button. // */ // int convertMouseButton(int button); // std::queue mKeyInputQueue; // std::queue mMouseInputQueue; // }; // } // #endif // end FCN_GLUTINPUT_HPP fifechan-0.1.5/include/fifechan/graphics.hpp000066400000000000000000000365751341577075500210150ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_GRAPHICS_HPP #define FCN_GRAPHICS_HPP #include #include #include "fifechan/cliprectangle.hpp" #include "fifechan/platform.hpp" #include "fifechan/point.hpp" namespace fcn { class Color; class Font; class Image; /** * Abstract class for providing drawing primitve functions. * It contains all vital functions for drawing. * * Guichan contains implementations of Graphics for common * libraries like the Allegro library, the HGE library, * the OpenGL library, the OpenLayer library, and the SDL library. * To make Guichan usable with other libraries, a Graphics class * must be implemented. * * In Graphics you can set clip areas to limit drawing to certain * areas of the screen. Clip areas are put on a stack, which * means that you can push smaller and smaller clip areas onto the * stack. All coordinates will be relative to the top most clip area. * In most cases you won't have to worry about the clip areas, * unless you want to implement some really complex widget. * Pushing and poping of clip areas are handled automatically by * container widgets when their child widgets are drawn. * * IMPORTANT: Remember to pop each clip area that you pushed on the stack * after you are done with it. * * If you feel that Graphics is to restrictive for your needs, * there is no one stopping you from using your own code for drawing * in widgets. You could for instance use pure SDL in the drawing of * widgets bypassing Graphics. This might however hurt portability of * your application. * * If you implement a Graphics class not present in Guichan we would * be very happy to add it to Guichan. * * @see AllegroGraphics, HGEGraphics, OpenLayerGraphics, OpenGLGraphics, * SDLGraphics, Image */ class FCN_CORE_DECLSPEC Graphics { public: /** * Alignments for text drawing. */ enum Alignment { Left = 0, Center, Right }; /** * Constructor. */ Graphics(); /** * Destructor. */ virtual ~Graphics() { } /** * Initializes drawing. Called by the Gui when Gui::draw() is called. * It is needed by some implementations of Graphics to perform * preparations before drawing. An example of such an implementation * is the OpenGLGraphics. * * NOTE: You will never need to call this function yourself, unless * you use a Graphics object outside of Guichan. * * @see _endDraw, Gui::draw */ virtual void _beginDraw() { } /** * Deinitializes drawing. Called by the Gui when a Gui::draw() is done. * done. It should reset any state changes made by _beginDraw(). * * NOTE: You will never need to call this function yourself, unless * you use a Graphics object outside of Guichan. * * @see _beginDraw, Gui::draw */ virtual void _endDraw() { } /** * Pushes a clip area onto the stack. The x and y coordinates in the * rectangle is relative to the last pushed clip area. * If the new area falls outside the current clip area, it will be * clipped as necessary. * * If a clip area is outside of the top clip area a clip area with * zero width and height will be pushed. * * @param area The clip area to be pushed onto the stack. * @return False if the the new area lays outside the current clip * area. */ virtual bool pushClipArea(Rectangle area); /** * Removes the top most clip area from the stack. * * @throws Exception if the stack is empty. */ virtual void popClipArea(); /** * Gets the current clip area. Usefull if you want to do drawing * bypassing Graphics. * * @return The current clip area. */ virtual const ClipRectangle& getCurrentClipArea(); /** * Draws a part of an image. * * NOTE: Width and height arguments will not scale the image but * specifies the size of the part to be drawn. If you want * to draw the whole image there is a simplified version of * this function. * * EXAMPLE: @code drawImage(myImage, 10, 10, 20, 20, 40, 40); @endcode * Will draw a rectangular piece of myImage starting at * coordinate (10, 10) in myImage, with width and height 40. * The piece will be drawn with it's top left corner at * coordinate (20, 20). * * @param image The image to draw. * @param srcX The source image x coordinate. * @param srcY The source image y coordinate. * @param dstX The destination x coordinate. * @param dstY The destination y coordinate. * @param width The width of the piece. * @param height The height of the piece. */ virtual void drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height) = 0; /** * Draws an image. A simplified version of the other drawImage. * It will draw a whole image at the coordinate you specify. * It is equivalent to calling: * @code drawImage(myImage, 0, 0, dstX, dstY, image->getWidth(), \ image->getHeight()); @endcode */ virtual void drawImage(const Image* image, int dstX, int dstY); /** * Draws a single point/pixel. * * @param x The x coordinate. * @param y The y coordinate. */ virtual void drawPoint(int x, int y) = 0; /** * Draws a line. * * @param x1 The first x coordinate. * @param y1 The first y coordinate. * @param x2 The second x coordinate. * @param y2 The second y coordinate. */ virtual void drawLine(int x1, int y1, int x2, int y2) = 0; /** * Draws a thick line. * * @param x1 The first x coordinate. * @param y1 The first y coordinate. * @param x2 The second x coordinate. * @param y2 The second y coordinate. * @param width The line width. */ virtual void drawLine(int x1, int y1, int x2, int y2, unsigned int width) = 0; /** * Draws lines between points with given width. * * @param points Contains the points that are used for drawing. * @param width The line width. */ virtual void drawPolyLine(const PointVector& points, unsigned int width) = 0; /** * Draws a bezier curve. * * @param points The coordinates as points in a vector. * @param steps The steps for each line between two points. * @param width The line width. */ virtual void drawBezier(const PointVector& points, int steps, unsigned int width) = 0; /** * Draws a simple, non-filled rectangle with a one pixel width. * * @param rectangle The rectangle to draw. */ virtual void drawRectangle(const Rectangle& rectangle) = 0; /** * Draws a simple, non-filled rectangle with a one pixel width. * * This is an overload provided for convenience. * * @param x The x coordinate of the rectangle * @param y The y coordinate of the rectangle * @param width The width of the rectangle * @param height The height of the rectangle * */ inline void drawRectangle(int x, int y, int width, int height) { drawRectangle(Rectangle(x, y, width, height)); } /** * Draws a filled rectangle. * * @param rectangle The filled rectangle to draw. */ virtual void fillRectangle(const Rectangle& rectangle) = 0; /** * Draws a filled rectangle. * * This is an overload provided for convenience. * * @param x The x coordinate of the rectangle * @param y The y coordinate of the rectangle * @param width The width of the rectangle * @param height The height of the rectangle * */ inline void fillRectangle(int x, int y, int width, int height) { fillRectangle(Rectangle(x, y, width, height)); } /** * Draws a simple, non-filled circle with a one pixel width. * * @param p The circle center coordinate as point. * @param radius The circle radius. * */ virtual void drawCircle(const Point& p, unsigned int radius) = 0; /** * Draws a filled circle. * * @param p The circle center coordinate as point. * @param radius The circle radius. * */ virtual void drawFillCircle(const Point& p, unsigned int radius) = 0; /** * Draws a simple, non-filled circle segment with a one pixel width. * Note: The start angle must be less than the end angle. 0 angle is right side. * * @param p The circle center coordinate as point. * @param radius The circle radius. * @param sangle The start angle of the segment. * @param eangle The end angle of the segment. * */ virtual void drawCircleSegment(const Point& p, unsigned int radius, int sangle, int eangle) = 0; /** * Draws a filled circle segment. * Note: The start angle must be less than the end angle. 0 angle is right side. * * @param p The circle center coordinate as point. * @param radius The circle radius. * @param sangle The start angle of the segment. * @param eangle The end angle of the segment. * */ virtual void drawFillCircleSegment(const Point& p, unsigned int radius, int sangle, int eangle) = 0; /** * Sets the color to use when drawing. * * @param color A color. * @see getColor */ virtual void setColor(const Color& color) = 0; /** * Gets the color to use when drawing. * * @return The color used when drawing. * @see setColor */ virtual const Color& getColor() const = 0; /** * Sets the font to use when drawing text. * * @param font The font to use when drawing. */ virtual void setFont(Font* font); /** * Draws text. * * @param text The text to draw. * @param x The x coordinate where to draw the text. * @param y The y coordinate where to draw the text. * @param alignment The alignemnt to use when drawing. * @throws Exception when no font has been set. */ virtual void drawText(const std::string& text, int x, int y, Alignment alignment = Left); protected: /** * Holds the clip area stack. */ std::stack mClipStack; /** * Holds the current font. */ Font* mFont; }; } #endif // end FCN_GRAPHICS_HPP fifechan-0.1.5/include/fifechan/gui.hpp000066400000000000000000000451071341577075500177700ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_GUI_HPP #define FCN_GUI_HPP #include #include #include #include "fifechan/keyevent.hpp" #include "fifechan/mouseevent.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/platform.hpp" namespace fcn { class FocusHandler; class GuiDeathListener; class Graphics; class Input; class KeyListener; class VisibilityEventHandler; class Widget; // The following comment will appear in the doxygen main page. /** * @mainpage * @section Introduction * This documentation is mostly intended as a reference to the API. If you want to get started with Guichan, we suggest you check out the programs in the examples directory of the Guichan release. * @n * @n * This documentation is, and will always be, work in progress. If you find any errors, typos or inconsistencies, or if you feel something needs to be explained in more detail - don't hesitate to tell us. */ /** * Contains a Guichan GUI. This is the core class of Guichan to which * implementations of back ends are passed, to make Guichan work with * a specific library, and to where the top widget (root widget of GUI) * is added. If you want to be able to have more then one widget in your * GUI, the top widget should be a container. * * A Gui object cannot work properly without passing back end * implementations to it. A Gui object must have an implementation of a * Graphics and an implementation of Input. * * NOTE: A complete GUI also must have the ability to load images. * Images are loaded with the Image class, so to make Guichan * able to load images an implementation of ImageLoader must be * passed to Image. * * @see Graphics, Input, Image */ class FCN_CORE_DECLSPEC Gui { public: /** * Constructor. */ Gui(); /** * Destructor. */ virtual ~Gui(); /** * Sets the top widget. The top widget is the root widget * of the GUI. If you want a GUI to be able to contain more * than one widget the top widget should be a container. * * @param top The top widget. * @see Container */ virtual void setTop(Widget* top); /** * Gets the top widget. The top widget is the root widget * of the GUI. * * @return The top widget. NULL if no top widget has been set. */ virtual Widget* getTop() const; /** * Sets the graphics object to use for drawing. * * @param graphics The graphics object to use for drawing. * @see getGraphics, AllegroGraphics, HGEGraphics, * OpenLayerGraphics, OpenGLGraphics, SDLGraphics */ virtual void setGraphics(Graphics* graphics); /** * Gets the graphics object used for drawing. * * @return The graphics object used for drawing. NULL if no * graphics object has been set. * @see setGraphics, AllegroGraphics, HGEGraphics, * OpenLayerGraphics, OpenGLGraphics, SDLGraphics */ virtual Graphics* getGraphics() const; /** * Sets the input object to use for input handling. * * @param input The input object to use for input handling. * @see getInput, AllegroInput, HGEInput, OpenLayerInput, * SDLInput */ virtual void setInput(Input* input); /** * Gets the input object being used for input handling. * * @return The input object used for handling input. NULL if no * input object has been set. * @see setInput, AllegroInput, HGEInput, OpenLayerInput, * SDLInput */ virtual Input* getInput() const; /** * Performs logic of the GUI. By calling this function all logic * functions down in the GUI heirarchy will be called. When logic * is called for Gui, user input will be handled. * * @see Widget::logic */ virtual void logic(); /** * Draws the GUI. By calling this funcion all draw functions * down in the GUI hierarchy will be called. When draw is called * the used Graphics object will be initialised and drawing of * the top widget will commence. * * @see Widget::draw */ virtual void draw(); /** * Focuses none of the widgets in the Gui. * */ virtual void focusNone(); /** * Sets tabbing enabled, or not. Tabbing is the usage of * changing focus by utilising the tab key. * * @param tabbing True if tabbing should be enabled, false * otherwise. * @see isTabbingEnabled */ virtual void setTabbingEnabled(bool tabbing); /** * Checks if tabbing is enabled. * * @return True if tabbing is enabled, false otherwise. * @see setTabbingEnabled */ virtual bool isTabbingEnabled(); /** * Adds a global key listener to the Gui. A global key listener * will receive all key events generated from the GUI and global * key listeners will receive the events before key listeners * of widgets. * * @param keyListener The key listener to add. * @see removeGlobalKeyListener */ virtual void addGlobalKeyListener(KeyListener* keyListener); /** * Removes global key listener from the Gui. * * @param keyListener The key listener to remove. * @throws Exception if the key listener hasn't been added. * @see addGlobalKeyListener */ virtual void removeGlobalKeyListener(KeyListener* keyListener); /** * Inform gui that a widget was hidden. * * @param widget Hidden widget. */ void enqueueHiddenWidget(Widget* widget); /** * Inform gui that a widget was shown. * * @param widget Shown widget. */ void enqueueShownWidget(Widget* widget); /** * Inform gui that a widget was deleted. * * @param widget Deleted widget. */ void widgetDied(Widget* widget); protected: /** * Handles all mouse input. * */ virtual void handleMouseInput(); /** * Handles key input. * */ virtual void handleKeyInput(); /** * Handles mouse moved input. * * @param mouseInput The mouse input to handle. */ virtual void handleMouseMoved(const MouseInput& mouseInput); /** * Handles mouse pressed input. * * @param mouseInput The mouse input to handle. */ virtual void handleMousePressed(const MouseInput& mouseInput); /** * * Handles mouse wheel moved down input. * * @param mouseInput The mouse input to handle. */ virtual void handleMouseWheelMovedDown(const MouseInput& mouseInput); /** * Handles mouse wheel moved up input. * * @param mouseInput The mouse input to handle. */ virtual void handleMouseWheelMovedUp(const MouseInput& mouseInput); /** * Handles mouse wheel moved right input. * * @param mouseInput The mouse input to handle. */ virtual void handleMouseWheelMovedRight(const MouseInput& mouseInput); /** * Handles mouse wheel moved left input. * * @param mouseInput The mouse input to handle. */ virtual void handleMouseWheelMovedLeft(const MouseInput& mouseInput); /** * Handles mouse released input. * * @param mouseInput The mouse input to handle. */ virtual void handleMouseReleased(const MouseInput& mouseInput); /** * Handles modal focus. Modal focus needs to be checked at * each logic iteration as it might be necessary to distribute * mouse entered or mouse exited events. * */ virtual void handleModalFocus(); /** * Handles modal mouse input focus. Modal mouse input focus needs * to be checked at each logic iteration as it might be necessary to * distribute mouse entered or mouse exited events. * */ virtual void handleModalMouseInputFocus(); /** * Handles modal focus gained. If modal focus has been gained it might * be necessary to distribute mouse entered or mouse exited events. * */ virtual void handleModalFocusGained(); /** * Handles modal focus released. If modal focus has been * released it might be necessary to distribute mouse entered or mouse * exited events. * */ virtual void handleModalFocusReleased(); /** * Handles modal mouse input focus gained. If modal focus has been gained it might * be necessary to distribute mouse entered or mouse exited events. * */ virtual void handleModalMouseInputFocusGained(); /** * Handles modal mouse input focus released. If modal focus has been * released it might be necessary to distribute mouse entered or mouse * exited events. * */ virtual void handleModalMouseInputFocusReleased(); /** * Handles hidden widgets. */ virtual void handleHiddenWidgets(); /** * Handles shown widgets. */ virtual void handleShownWidgets(); /** * Distributes a mouse event. * * @param type The type of the event to distribute, * @param button The button of the event (if any used) to distribute. * @param x The x coordinate of the event. * @param y The y coordinate of the event. * @param fource indicates whether the distribution should be forced or not. * A forced distribution distributes the event even if a widget * is not enabled, not visible, another widget has modal * focus or another widget has modal mouse input focus. * Default value is false. * @param toSourceOnly indicates whether the distribution should be to the * source widget only or to it's parent's mouse listeners * as well. * */ virtual void distributeMouseEvent(Widget* source, int type, int button, int x, int y, bool force = false, bool toSourceOnly = false); /** * Distributes a key event. * * @param keyEvent The key event to distribute. */ virtual void distributeKeyEvent(KeyEvent& keyEvent); /** * Distributes a key event to the global key listeners. * * @param keyEvent The key event to distribute. * */ virtual void distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent); /** * Gets the widget at a certain position. * * @return The widget at a certain position. */ virtual Widget* getWidgetAt(int x, int y, Widget* exclude = NULL); /** * Gets the source of the mouse event. * * @return The source widget of the mouse event. */ virtual Widget* getMouseEventSource(int x, int y); /** * Gets the source of the key event. * * @return The source widget of the key event. */ virtual Widget* getKeyEventSource(); /** * Gets all widgets a certain coordinate in the Gui. * * @param x The x coordinate. * @param y The y coordinate. * @return A set of all widgets at the specified coordinate. */ virtual std::set getWidgetsAt(int x, int y); /** * Holds the top widget. */ Widget* mTop; /** * Holds hidden widgets. */ std::queue mHiddenWidgets; /** * Holds shown widgets. */ std::queue mShownWidgets; /** * Holds the graphics implementation used. */ Graphics* mGraphics; /** * Holds the input implementation used. */ Input* mInput; /** * Holds the focus handler for the Gui. */ FocusHandler* mFocusHandler; /** * Holds the visibility event handler for the Gui. */ VisibilityEventHandler *mVisibilityEventHandler; /** * True if tabbing is enabled, false otherwise. */ bool mTabbing; /** * Typedef. */ typedef std::list KeyListenerList; /** * Typedef. */ typedef KeyListenerList::iterator KeyListenerListIterator; /** * Holds the global key listeners of the Gui. */ KeyListenerList mKeyListeners; /** * True if shift is pressed, false otherwise. */ bool mShiftPressed; /** * True if meta is pressed, false otherwise. */ bool mMetaPressed; /** * True if control is pressed, false otherwise. */ bool mControlPressed; /** * True if alt is pressed, false otherwise. */ bool mAltPressed; /** * Holds the last mouse button pressed. */ unsigned int mLastMousePressButton; /** * Holds the last mouse press time stamp. */ int mLastMousePressTimeStamp; /** * Holds the last mouse x coordinate. */ int mLastMouseX; /** * Holds the last mouse y coordinate. */ int mLastMouseY; /** * Holds the current click count. Used to keep track * of clicks for a the last pressed button. */ int mClickCount; /** * Holds the last button used when a drag of a widget * was initiated. Used to be able to release a drag * when the same button is released. */ int mLastMouseDragButton; GuiDeathListener* mDeathListener; }; } #endif // end FCN_GUI_HPP fifechan-0.1.5/include/fifechan/hge.hpp000066400000000000000000000076431341577075500177520ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_HGE_HPP #define FCN_HGE_HPP #include #include #include #include #include #endif // end FCN_HGE_HPP fifechan-0.1.5/include/fifechan/hge/000077500000000000000000000000001341577075500172275ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/hge/hgegraphics.hpp000066400000000000000000000121011341577075500222170ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_HGEGRAPHICS_HPP #define FCN_HGEGRAPHICS_HPP #include #include "fifechan/graphics.hpp" #include "fifechan/platform.hpp" #include "fifechan/color.hpp" namespace fcn { class Color; /** * HGE implementation of Graphics. * * @author Kevin Lynx */ class FCN_EXTENSION_DECLSPEC HGEGraphics : public Graphics { public: /** * Constructor. */ HGEGraphics(); /** * Destructor. */ ~HGEGraphics(); //Inherited from Graphics void _beginDraw(); void _endDraw(); void drawImage(const Image *image, int srcX, int srcY, int dstX, int dstY, int width, int height); void drawImage(const Image* image, int dstX, int dstY); void drawPoint(int x, int y); void drawLine(int x1, int y1, int x2, int y2); void drawRectangle(const Rectangle &rectangle); void fillRectangle(const Rectangle &rectangle); void setColor(const Color &color); const Color &getColor() const; bool pushClipArea(Rectangle area); void popClipArea(); protected: static HGE *mHGE; Color mColor; DWORD mHardwareColor; bool mClipNull; }; } #endif // end FCN_HGEGRAPHICS_HPP fifechan-0.1.5/include/fifechan/hge/hgeimage.hpp000066400000000000000000000123701341577075500215110ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_HGEIMAGE_HPP #define FCN_HGEIMAGE_HPP #include #include #include #include "fifechan/color.hpp" #include "fifechan/platform.hpp" #include "fifechan/image.hpp" namespace fcn { /** * HGE implementation of Image. * * @author Kevin Lynx */ class FCN_EXTENSION_DECLSPEC HGEImage : public Image { public: /** * Constructor. * * Creates an image from a HGE texture. * * NOTE : The functions getPixel and putPixel are only guaranteed to work * with a 32bits image. * * @param sprite A HGE texture to create the image from. * @param autoFree True it the image should be automatically deleted by * the destructor, false otherwise. */ HGEImage(HTEXTURE texture, bool autoFree = false); /** * Destructor. * */ ~HGEImage(); /** * Gets the HGE sprite of the image. * * @return the HGE sprite of the image. */ virtual hgeSprite *getSprite() const; // Inherited from Image virtual void free(); virtual int getWidth() const; virtual int getHeight() const; virtual Color getPixel(int x, int y); virtual void putPixel(int x, int y, const Color &color); virtual void convertToDisplayFormat(); protected: static HGE *mHGE; bool mAutoFree; hgeSprite *mHGESprite; HTEXTURE mTexture; }; } #endif // end FCN_HGEIMAGE_HPP fifechan-0.1.5/include/fifechan/hge/hgeimagefont.hpp000066400000000000000000000123451341577075500224020ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_HGEIMAGEFONT_HPP #define FCN_HGEIMAGEFONT_HPP #include #include #include "fifechan/font.hpp" #include "fifechan/platform.hpp" namespace fcn { class Graphics; /** * Font to be used with HGE. As HGE does not support colorkey blitting of images it's recommended * to use HGE's internal font in Guichan. * * @author Kevin Lynx */ class FCN_EXTENSION_DECLSPEC HGEImageFont : public Font { public: /** * Constructor. Creates a font from a HGE font file. * * @param filename the filename of the HGE font. */ HGEImageFont(const std::string& filename); /** * Destructor. */ ~HGEImageFont(); /** * Gets the loaded HGE font. The HGE font can be used to set certain properties like * setting the blend mode. Properties of the HGE font will effect the Guichan font as well. * * @return the loaded HGE font. */ virtual hgeFont *getFont() const; /** * Gets the width from a character. * * @param character the character to get the width from. */ int getWidth(char character) const; //Inherited from Font int getWidth(const std::string &text) const; int getHeight() const; int getStringIndexAt(const std::string &text, int x) const; void drawString(Graphics *graphics, const std::string &text, int x, int y); protected: hgeFont *mHGEFont; }; } #endif // end FCN_HGEIMAGEFONT_HPP fifechan-0.1.5/include/fifechan/hge/hgeimageloader.hpp000066400000000000000000000121201341577075500226710ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_HGEIMAGELOADER_HPP #define FCN_HGEIMAGELOADER_HPP #include #include #include "fifechan/platform.hpp" #include "fifechan/imageloader.hpp" namespace fcn { class Image; /** * HGE implementation of ImageLoader. * * @author Kevin Lynx */ class FCN_EXTENSION_DECLSPEC HGEImageLoader : public ImageLoader { public: /** * Constructor. */ HGEImageLoader(); /** * Destructor. */ ~HGEImageLoader(); /** * Loads an image with the HGE resource manager. * * NOTE: The functions Image::getPixel and Image::putPixel * are only guaranteed to work before an image has * been converted to display format. * * @param manager The manager to use. * @param name The name of the image. * @param resourceGroup The resource group. * @param convertToDisplayFormat True if the image should be converted * to display, false otherwise. */ virtual Image* load(hgeResourceManager* manager, char* name, int resourceGroup, bool convertToDisplayFormat); // Inherited from ImageLoader virtual Image* load(const std::string &filename, bool convertToDisplayFormat = true); protected: static HGE *mHGE; }; } #endif // end FCN_HGEIMAGELOADER_HPP fifechan-0.1.5/include/fifechan/hge/hgeinput.hpp000066400000000000000000000132301341577075500215620ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_HGEINPUT_HPP #define FCN_HGEINPUT_HPP #include #include #if defined(DELETE) #undef DELETE #endif #include "fifechan/input.hpp" #include "fifechan/keyinput.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * HGE implementation of Input. * * @author Kevin Lynx */ class FCN_EXTENSION_DECLSPEC HGEInput : public Input { public: /** * Constructor. */ HGEInput(); /** * Destructor. */ virtual ~HGEInput(); //Inherited from Input virtual bool isKeyQueueEmpty(); virtual bool isMouseQueueEmpty(); virtual KeyInput dequeueKeyInput(); virtual MouseInput dequeueMouseInput(); virtual void _pollInput(); protected: /** * Handles key input. The function is called by _pollInput. * * @param ki the hge input event to handle. */ void pollKeyInput(hgeInputEvent &ki); /** * Handles mouse input. The function is called by _pollInput. * * This function directly deal with the mouse input , and it avoid * the odd things in HGE. */ void pollMouseInput(); /** * Converts the keycode and characters to a Key object. * * @param key The key to convert. * @param chr The character to convert. */ Key convertToKey(int key, int chr); /** * Checks if a keyCode is numeric. * * @param keyCode The key code to check. */ bool isNumericPad(int keyCode); protected: static HGE *mHGE; std::queue mKeyInputQueue; std::queue mMouseInputQueue; float mMouseX; float mMouseY; bool mLeftMouseButtonDown; bool mRightMouseButtonDown; bool mMiddleMouseButtonDown; }; } #endif // end FCN_HGEINPUT_HPP fifechan-0.1.5/include/fifechan/image.hpp000066400000000000000000000175371341577075500202740ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_IMAGE_HPP #define FCN_IMAGE_HPP #include #include "fifechan/platform.hpp" namespace fcn { class Color; class ImageLoader; /** * Holds an image. To be able to use this class you must first set an * ImageLoader in Image by calling * @code Image::setImageLoader(myImageLoader) @endcode * The function is static. If this is not done, the constructor taking a * filename will throw an exception. The ImageLoader you use must be * compatible with the Graphics object you use. * * EXAMPLE: If you use SDLGraphics you should use SDLImageLoader. * Otherwise your program might crash in a most bizarre way. * @see AllegroImageLoader, HGEImageLoader, OpenLayerImageLoader, * OpenGLAllegroImageLoader, OpenGLSDLImageLoader, SDLImageLoader */ class FCN_CORE_DECLSPEC Image { public: /** * Constructor. */ Image(); /** * Destructor. */ virtual ~Image(); /** * Loads an image by using the class' image laoder. All image loaders implemented * in Guichan return a newly instantiated image which must be deleted in * order to avoid a memory leak. * * NOTE: The functions getPixel and putPixel are only guaranteed to work * before an image has been converted to display format. * * @param filename The file to load. * @param convertToDisplayFormat True if the image should be converted * to display, false otherwise. */ static Image* load(const std::string& filename, bool convertToDisplayFormat = true); /** * Gets the image loader used for loading images. * * @return The image loader used for loading images. * @see setImageLoader, AllegroImageLoader, HGEImageLoader, * OpenLayerImageLoader, OpenGLAllegroImageLoader, * OpenGLSDLImageLoader, SDLImageLoader */ static ImageLoader* getImageLoader(); /** * Sets the ImageLoader to be used for loading images. * * IMPORTANT: The image loader is static and MUST be set before * loading images! * * @param imageLoader The image loader to be used for loading images. * @see getImageLoader, AllegroImageLoader, HGEImageLoader, * OpenLayerImageLoader, OpenGLAllegroImageLoader, * OpenGLSDLImageLoader, SDLImageLoader */ static void setImageLoader(ImageLoader* imageLoader); /** * Frees an image. * */ virtual void free() = 0; /** * Gets the width of the image. * * @return The width of the image. * */ virtual int getWidth() const = 0; /** * Gets the height of the image. * * @return The height of the image. * */ virtual int getHeight() const = 0; /** * Gets the color of a pixel at coordinate (x, y) in the image. * * IMPORTANT: Only guaranteed to work before the image has been * converted to display format. * * @param x The x coordinate. * @param y The y coordinate. * @return The color of the pixel. * */ virtual Color getPixel(int x, int y) = 0; /** * Puts a pixel with a certain color at coordinate (x, y). * * @param x The x coordinate. * @param y The y coordinate. * @param color The color of the pixel to put. */ virtual void putPixel(int x, int y, const Color& color) = 0; /** * Converts the image, if possible, to display format. * * IMPORTANT: Only guaranteed to work before the image has been * converted to display format. */ virtual void convertToDisplayFormat() = 0; protected: /** * Holds the image loader to be used when loading images. */ static ImageLoader* mImageLoader; }; } #endif // end FCN_IMAGE_HPP fifechan-0.1.5/include/fifechan/imagefont.hpp000066400000000000000000000256231341577075500211560ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_IMAGEFONT_HPP #define FCN_IMAGEFONT_HPP #include #include "fifechan/font.hpp" #include "fifechan/platform.hpp" #include "fifechan/rectangle.hpp" namespace fcn { class Color; class Graphics; class Image; /** * A font using an image containing the font data. ImageFont can be used * with any image supported by the currently used ImageLoader. * * These are two examples of an image containing a font. * \image html imagefontexample.bmp * \image html imagefontexample2.bmp * * The first pixel at coordinate (0,0) tells which color the image font * looks for when seperating glyphs. The glyphs in the image is provided * to the image font's constructor in the order they appear in the image. * * To create an ImageFont from the first image example above the following * constructor call should be made: * @code fcn::ImageFont imageFont("fixedfont_big.bmp"," abcdefghijklmno\ pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); @endcode * * Noteworthy is that the first glyph actually gives the width of space. * Glyphs can, as seen in the second image example above, be seperated with * horizontal lines making it possible to draw glyphs on more then one * line in the image. However, these horizontal lines must have a height of * one pixel! */ class FCN_CORE_DECLSPEC ImageFont: public Font { public: /** * Constructor. Takes an image file containing the font and * a string containing the glyphs. The glyphs in the string should * be in the same order as they appear in the font image. * * @param filename The filename of the image. * @param glyphs The glyphs found in the image. * @throws Exception when glyph list is incorrect or the font file is * corrupt or if no ImageLoader exists. */ ImageFont(const std::string& filename, const std::string& glyphs); /** * Constructor. Takes an image containing the font and * a string containing the glyphs. The glyphs in the string should * be in the same order as they appear in the font image. * The image will be deleted in the destructor. * * @param image The image with font glyphs. * @param glyphs The glyphs found in the image. * @throws Exception when glyph list is incorrect or the font image is * is missing. */ ImageFont(Image* image, const std::string& glyphs); /** * Constructor. Takes an image file containing the font and * two boundaries of ASCII values. The font image should include * all glyphs specified with the boundaries in increasing ASCII * order. The boundaries are inclusive. * * @param filename The filename of the image. * @param glyphsFrom The ASCII value of the first glyph found in the * image. * @param glyphsTo The ASCII value of the last glyph found in the * image. * @throws Exception when glyph bondaries are incorrect or the font * file is corrupt or if no ImageLoader exists. */ ImageFont(const std::string& filename, unsigned char glyphsFrom=32, unsigned char glyphsTo=126); /** * Destructor. */ virtual ~ImageFont(); /** * Draws a glyph. * * NOTE: You normally won't use this function to draw text since * the Graphics class contains better functions for drawing * text. * * @param graphics A graphics object used for drawing. * @param glyph A glyph to draw. * @param x The x coordinate where to draw the glyph. * @param y The y coordinate where to draw the glyph. * @return The width of the glyph in pixels. */ virtual int drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y); /** * Sets the space between rows in pixels. Default is 0 pixels. * The space can be negative. * * @param spacing The space between rows in pixels. * @see getRowSpacing */ virtual void setRowSpacing(int spacing); /** * Gets the space between rows in pixels. * * @return The space between rows in pixels. * @see setRowSpacing */ virtual int getRowSpacing(); /** * Sets the spacing between glyphs in pixels. Default is 0 pixels. * The space can be negative. * * @param spacing The glyph space in pixels. * @see getGlyphSpacing */ virtual void setGlyphSpacing(int spacing); /** * Gets the spacing between letters in pixels. * * @return the spacing. * @see setGlyphSpacing */ virtual int getGlyphSpacing(); /** * Gets a width of a glyph in pixels. * * @param glyph The glyph which width will be returned. * @return The width of a glyph in pixels. */ virtual int getWidth(unsigned char glyph) const; // Inherited from Font virtual int getWidth(const std::string& text) const; virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); virtual int getHeight() const; virtual int getStringIndexAt(const std::string& text, int x) const; protected: /** * Scans for a certain glyph. * * @param glyph The glyph to scan for. Used for exception messages. * @param x The x coordinate where to begin the scan. The coordinate * will be updated with the end x coordinate of the glyph * when the scan is complete. * @param y The y coordinate where to begin the scan. The coordinate * will be updated with the end y coordinate of the glyph * when the scan is complete. * @param separator The color separator to look for where the glyph ends. * @return A rectangle with the found glyph dimension in the image * with the font. * @throws Exception when no glyph is found. */ Rectangle scanForGlyph(unsigned char glyph, int x, int y, const Color& separator); /** * Holds the glyphs areas in the image. */ Rectangle mGlyph[256]; /** * Holds the height of the image font. */ int mHeight; /** * Holds the glyph spacing of the image font. */ int mGlyphSpacing; /** * Holds the row spacing of the image font. */ int mRowSpacing; /** * Holds the image with the font data. */ Image* mImage; /** * Holds the filename of the image with the font data. */ std::string mFilename; }; } #endif // end FCN_IMAGEFONT_HPP fifechan-0.1.5/include/fifechan/imageloader.hpp000066400000000000000000000124301341577075500214460ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_IMAGELOADER_HPP #define FCN_IMAGELOADER_HPP #include #include "fifechan/platform.hpp" namespace fcn { class Image; /** * Abstract class for providing functions for loading images. * * Guichan contains implementations of ImageLoader for common * libraries like the Allegro library, the HGE library, * he OpenLayer library, and the SDL library. * To make Guichan usable with other libraries, an ImageLoader * class must be implemented. * * To make Guichan use an image loader, the image loader needs * to be passed to the Image class using the static method * Image::setImageLoader. * * @see Image::setImageLoader, Image::getImageLoader, * AllegroImageLoader, HGEImageLoader, OpenLayerImageLoader, * OpenGLAllegroImageLoader, OpenGLSDLImageLoader, * SDLImageLoader */ class FCN_CORE_DECLSPEC ImageLoader { public: /** * Destructor. */ virtual ~ImageLoader() { } /** * Loads an image. * * NOTE: The functions Image::getPixel and Image::putPixel * are only guaranteed to work before an image has * been converted to display format. * * @param filename The filename of the image to load. * @param convertToDisplayFormat True if the image should be converted * to display, false otherwise. */ virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true) = 0; }; } #endif // end FCN_IMAGELOADER_HPP fifechan-0.1.5/include/fifechan/input.hpp000066400000000000000000000127011341577075500203350ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_INPUT_HPP #define FCN_INPUT_HPP #include "fifechan/platform.hpp" namespace fcn { class KeyInput; class MouseInput; /** * Abstract class for providing functions for user input. * * Guichan contains implementations of Input for common * libraries like the Allegro library, the HGE library, * and the SDL library. * To make Guichan usable with other libraries, an Input * class must be implemented. * * @see AllegroInput, HGEInput, OpenLayerInput, * SDLInput */ class FCN_CORE_DECLSPEC Input { public: /** * Destructor. */ virtual ~Input(){ } /** * Checks if the key queue is empty, or not. * * @return True if the key queue is empty, * false otherwise. */ virtual bool isKeyQueueEmpty() = 0; /** * Dequeues the key input queue. * * @return The first key input in the key input queue. */ virtual KeyInput dequeueKeyInput() = 0; /** * Checks if the mouse queue is empyt, or not. * * @return True if the mouse queue is empty, * false otherwise. */ virtual bool isMouseQueueEmpty() = 0; /** * Dequeues the mouse input queue. * * @return The first mouse input in the mouse input queue. */ virtual MouseInput dequeueMouseInput() = 0; /** * Polls all exsisting input. Called when input should * be polled. The function exists for compatibility reason * where some libraries need to poll input at a certain * logic rate. */ virtual void _pollInput() = 0; }; } #endif // end FCN_INPUT_HPP fifechan-0.1.5/include/fifechan/inputevent.hpp000066400000000000000000000172111341577075500214000ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_INPUTEVENT_HPP #define FCN_INPUTEVENT_HPP #include "fifechan/event.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Base class for all events concerning input. * * @author Olof Naessn */ class FCN_CORE_DECLSPEC InputEvent: public Event { public: /** * Constructor. * * @param source The widget the event concerns. * @param distributor The distributor of the event. * @param isShiftPressed True if shift is pressed, false otherwise. * @param isControlPressed True if control is pressed, false otherwise. * @param isAltPressed True if alt is pressed, false otherwise. * @param isMetaPressed True if meta is pressed, false otherwise. */ InputEvent(Widget* source, Widget* distributor, bool isShiftPressed, bool isControlPressed, bool isAltPressed, bool isMetaPressed); /** * Checks if shift is pressed. * * @return True if shift was pressed at the same time as the key, * false otherwise. */ bool isShiftPressed() const; /** * Checks if control is pressed. * * @return True if control was pressed at the same time as the key, * false otherwise. */ bool isControlPressed() const; /** * Checks if alt is pressed. * * @return True if alt was pressed at the same time as the key, * false otherwise. */ bool isAltPressed() const; /** * Checks whether meta is pressed. * * @return True if meta was pressed at the same time as the key, * false otherwise. */ bool isMetaPressed() const; /** * Marks the event as consumed. Input event listeners may discard * consumed input or act on consumed input. An example of a widget * that discards consumed input is the ScrollArea widget that * discards consumed mouse wheel events so the ScrollArea will not * scroll if for instance a Slider's value inside the ScrollArea was * changed with the mouse wheel. * * @see isConsumed */ void consume(); /** * Checks if the input event is consumed. * * @return True if the input event is consumed, * false otherwise. * @see consume */ bool isConsumed() const; /** * Gets the distributor of the event. The function is * used to tell which widget actually distributed the * event. As input events bubbles up, the source of the event * may not be the same as the distributor of the event. */ Widget* getDistributor() const; protected: /** * True if shift is pressed, false otherwise. */ bool mShiftPressed; /** * True if control is pressed, false otherwise. */ bool mControlPressed; /** * True if alt is pressed, false otherwise. */ bool mAltPressed; /** * True if meta is pressed, false otherwise. */ bool mMetaPressed; /** * True if the input event is consumed, * false otherwise. */ bool mIsConsumed; /** * Holds the distributor of the event. */ Widget* mDistributor; /** * Gui is a friend of this class in order to be able to manipulate * the protected member variables of this class and at the same time * keep the MouseEvent class as const as possible. Gui needs to * update the distributer of this class whenever the distributer * changes as events bubble up. */ friend class Gui; }; } #endif // end FCN_INPUTEVENT_HPP fifechan-0.1.5/include/fifechan/irrlicht.hpp000066400000000000000000000101601341577075500210130ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_IRRLICHT_HPP #define FCN_IRRLICHT_HPP #include #include #include #include #include extern "C" { /** * Exists to be able to check for Guichan Irrlicht with autotools. */ FCN_EXTENSION_DECLSPEC extern void fcnIrrlicht(); } #endif // end FCN_IRRLICHT_HPP fifechan-0.1.5/include/fifechan/irrlicht/000077500000000000000000000000001341577075500203045ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/irrlicht/irrlichtgraphics.hpp000066400000000000000000000125771341577075500243720ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_IRRLICHTGRAPHICS_HPP #define FCN_IRRLICHTGRAPHICS_HPP #include "irrlicht.h" #include "fifechan/color.hpp" #include "fifechan/graphics.hpp" #include "fifechan/platform.hpp" namespace fcn { class Image; class Rectangle; /** * Irrlicht implementation of the Graphics. * * @author Aaron Andersen */ class FCN_EXTENSION_DECLSPEC IrrlichtGraphics : public Graphics { public: // Needed so that drawImage(fcn::Image *, int, int) is visible. using Graphics::drawImage; /** * Constructor. * * @param driver the Irrlicht video driver to draw to. */ IrrlichtGraphics(irr::video::IVideoDriver* driver); /** * Destructor. */ ~IrrlichtGraphics(); // Inherited from Graphics virtual void _beginDraw(); virtual void _endDraw(); virtual bool pushClipArea(Rectangle area); virtual void popClipArea(); virtual void drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height); virtual void drawPoint(int x, int y); virtual void drawLine(int x1, int y1, int x2, int y2); virtual void drawRectangle(const Rectangle& rectangle); virtual void fillRectangle(const Rectangle& rectangle); virtual void setColor(const Color& color); virtual const Color& getColor() const; protected: Color mColor; irr::video::IVideoDriver* mDriver; }; } #endif // end FCN_IRRLICHTGRAPHICS_HPP fifechan-0.1.5/include/fifechan/irrlicht/irrlichtimage.hpp000066400000000000000000000143321341577075500236430ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_IRRLICHTIMAGE_HPP #define FCN_IRRLICHTIMAGE_HPP #include "irrlicht.h" #include #include "fifechan/color.hpp" #include "fifechan/platform.hpp" #include "fifechan/image.hpp" namespace fcn { /** * Irrlicht implementation of Image. * * @author Aaron Andersen */ class FCN_EXTENSION_DECLSPEC IrrlichtImage : public Image { public: /** * Constructor. Load an image from an Irrlicht IImage. * * NOTE: The functions getPixel and putPixel will only work * before an image has been converted to display format. * * @param image the image from which to load. * @param driver the Irrlicht video driver to use when converting the image to display format. * @param name the filename of the image. * @param autoFree true if the image should automatically be deleted. * @param convertToDisplayFormat true if the image should be converted to display format. */ IrrlichtImage(irr::video::IImage* image, irr::video::IVideoDriver* driver, const std::string& name, bool autoFree, bool convertToDisplayFormat); /** * Destructor. */ virtual ~IrrlichtImage(); /** * Gets the Irrlicht ITexture for the image. * * @return the Irrlicht ITexture for the image. */ virtual irr::video::ITexture* getTexture() const; // Inherited from Image virtual void free(); virtual int getWidth() const; virtual int getHeight() const; virtual Color getPixel(int x, int y); virtual void putPixel(int x, int y, const Color& color); virtual void convertToDisplayFormat(); protected: /** * Holds the Irrlicht IImage. This Irrlicht IImage is NULL after the image * has been converted to display format. */ irr::video::IImage* mImage; /** * Holds the texture of the image. This texture isn't initialized until * the image is converted to display format. */ irr::video::ITexture* mTexture; /** * Holds the D3D device used when converting the image to display format. */ irr::video::IVideoDriver* mDriver; /** * Holds the filename of the image. */ std::string mName; /** * True if the image should be auto freed. */ bool mAutoFree; }; } #endif // end FCN_IRRLICHTIMAGE_HPP fifechan-0.1.5/include/fifechan/irrlicht/irrlichtimageloader.hpp000066400000000000000000000112151341577075500250270ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_IRRLICHTIMAGELOADER_HPP #define FCN_IRRLICHTIMAGELOADER_HPP #include "fifechan/imageloader.hpp" #include "fifechan/platform.hpp" #include "irrlicht.h" namespace fcn { class Image; /** * Irrlicht implementation of ImageLoader. * * @author Aaron Andersen */ class FCN_EXTENSION_DECLSPEC IrrlichtImageLoader : public ImageLoader { public: /** * Constructor. * * @param device The Irrlicht IVideoDriver device to use when loading images. */ IrrlichtImageLoader(irr::video::IVideoDriver* driver); /** * Destructor. */ ~IrrlichtImageLoader(); // Inherited from ImageLoader virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true); protected: /** * Holds the Irrlicht IVideoDriver to use when loading images. */ irr::video::IVideoDriver* mDriver; }; } #endif // end FCN_IRRLICHTIMAGELOADER_HPP fifechan-0.1.5/include/fifechan/irrlicht/irrlichtinput.hpp000066400000000000000000000127461341577075500237270ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_IRRLICHTINPUT_HPP #define FCN_IRRLICHTINPUT_HPP #include #include "irrlicht.h" #include "fifechan/input.hpp" #include "fifechan/keyinput.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/platform.hpp" namespace fcn { class Key; /** * Irrlicht implementation of Input. * * @author Aaron Andersen */ class FCN_EXTENSION_DECLSPEC IrrlichtInput : public Input { public: /** * Constructor. */ IrrlichtInput(irr::IrrlichtDevice* device); /** * Pushes an Irrlicht event. It should be called at least once per frame to * update input with user input. * * @param event an event from Irrlicht. */ virtual void pushInput(const irr::SEvent& event); /** * Polls all input. It exists for input driver compatibility. If you * only use Irrlicht and plan sticking with Irrlicht you can safely ignore this * function as it in the Irrlicht case does nothing. */ virtual void _pollInput() { } // Inherited from Input virtual bool isKeyQueueEmpty(); virtual KeyInput dequeueKeyInput(); virtual bool isMouseQueueEmpty(); virtual MouseInput dequeueMouseInput(); protected: /** * Converts an Irrlicht event to a Guichan key value. * * @param keysym The Irrlicht event to convert. * @return A Fifechan key value. -1 if no conversion took place. * @see Key */ int convertIrrlichtEventToFifechanKeyValue(const irr::SEvent& event); std::queue mKeyInputQueue; std::queue mMouseInputQueue; irr::IrrlichtDevice* mIrrlichtDevice; bool mAltKeyDown; bool mMetaKeyDown; }; } #endif // end FCN_IRRLICHTINPUT_HPP fifechan-0.1.5/include/fifechan/key.hpp000066400000000000000000000151601341577075500177700ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_KEY_HPP #define FCN_KEY_HPP #include "fifechan/platform.hpp" namespace fcn { /** * Represents a key or a character. */ class FCN_CORE_DECLSPEC Key { public: /** * Constructor. * * @param value The ascii or enum value for the key. */ Key(int value = 0); /** * Checks if a key is a character. * * @return True if the key is a letter, number or whitespace, * false otherwise. */ bool isCharacter() const; /** * Checks if a key is a number. * * @return True if the key is a number (0-9), * false otherwise. */ bool isNumber() const; /** * Checks if a key is a letter. * * @return True if the key is a letter (a-z,A-Z), * false otherwise. */ bool isLetter() const; /** * Gets the value of the key. If an ascii value exists it * will be returned. Otherwise an enum value will be returned. * * @return the value of the key. */ int getValue() const; /** * Compares two keys. * * @param key The key to compare this key with. * @return True if the keys are equal, false otherwise. */ bool operator==(const Key& key) const; /** * Compares two keys. * * @param key The key to compare this key with. * @return True if the keys are not equal, false otherwise. */ bool operator!=(const Key& key) const; /** * An enum with key values. */ enum { Space = ' ', Tab = '\t', Enter = '\n', // Negative values, to avoid conflicts with higher character codes LeftAlt = -1000, RightAlt, LeftShift, RightShift, LeftControl, RightControl, LeftMeta, RightMeta, LeftSuper, RightSuper, Insert, Home, PageUp, Delete, End, PageDown, Escape, CapsLock, Backspace, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, PrintScreen, ScrollLock, Pause, NumLock, AltGr, Left, Right, Up, Down, At }; protected: /** * Holds the value of the key. It may be an ascii value * or an enum value. */ int mValue; }; } #endif // end FCN_KEY_HPP fifechan-0.1.5/include/fifechan/keyevent.hpp000066400000000000000000000140761341577075500210370ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_KEYEVENT_HPP #define FCN_KEYEVENT_HPP #include "fifechan/inputevent.hpp" #include "fifechan/key.hpp" #include "fifechan/platform.hpp" namespace fcn { class Widget; /** * Represents a key event. */ class FCN_CORE_DECLSPEC KeyEvent: public InputEvent { public: /** * Key event types. */ enum { Pressed = 0, Released }; /** * Constructor. * * @param source The widget the event concerns.. * @param distributor The distributor of the event. * @param isShiftPressed True if shift is pressed, false otherwise. * @param isControlPressed True if control is pressed, false otherwise. * @param isAltPressed True if alt is pressed, false otherwise. * @param isMetaPressed True if meta is pressed, false otherwise. * @param type The type of the event. A value from KeyEventType. * @param isNumericPad True if the event occured on the numeric pad, * false otherwise. * @param key The key of the event. */ KeyEvent(Widget* source, Widget* distributor, bool isShiftPressed, bool isControlPressed, bool isAltPressed, bool isMetaPressed, unsigned int type, bool isNumericPad, const Key& key); /** * Destructor. */ virtual ~KeyEvent(); /** * Gets the type of the event. * * @return The type of the event. */ unsigned int getType() const; /** * Checks if the key event occured on the numeric pad. * * @return True if key event occured on the numeric pad, * false otherwise. * */ bool isNumericPad() const; /** * Gets the key of the event. * * @return The key of the event. */ const Key& getKey() const; protected: /** * Holds the type of the key event. */ unsigned int mType; /** * True if the numeric pad was used, false otherwise. */ bool mIsNumericPad; /** * Holds the key of the key event. */ Key mKey; }; } #endif // end FCN_KEYEVENT_HPP fifechan-0.1.5/include/fifechan/keyinput.hpp000066400000000000000000000215221341577075500210470ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_KEYINPUT_HPP #define FCN_KEYINPUT_HPP #include "fifechan/key.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Internal class that represents key input. Generally you won't have to * bother using this class unless you implement an Input class for * a back end. * */ class FCN_CORE_DECLSPEC KeyInput { public: /** * Constructor. */ KeyInput() { }; /** * Constructor. * * @param key The key of the key input. * @param type The type of key input. */ KeyInput(const Key& key, unsigned int type); /** * Sets the type of the key input. * * @param type The type of key input. * @see getType */ void setType(unsigned int type); /** * Gets the type of the key input. * * @return the input type. * @see setType */ int getType() const; /** * Sets the key of the key input. * * @param key The key of the key input. * @see getKey */ void setKey(const Key& key); /** * Gets the key of the key input. * * @return The key of the key input. * @see setKey */ const Key& getKey() const; /** * Checks if shift is pressed. * * @return True if shift was pressed at the same * time as the key, false otherwise. * @see setShiftPressed */ bool isShiftPressed() const; /** * Sets shift to be pressed at the same time as the key, * or not. * * @param pressed True if shift is pressed, false otherwise. * @see isShiftPressed */ void setShiftPressed(bool pressed); /** * Checks if control is pressed. * * @return True if control was pressed at the same * time as the key, false otherwise. * @see setControlPressed */ bool isControlPressed() const; /** * Sets control to be pressed at the same time as the key, * or not. * * @param pressed True if control is pressed, false otherwise. * @see isControlPressed */ void setControlPressed(bool pressed); /** * Checks if alt is pressed. * * @return True if alt was pressed at the same * time as the key, false otherwise. * @see setAltPressed */ bool isAltPressed() const; /** * Sets the alt to be pressed at the same time as the key, * or not. * * @param pressed True if alt is pressed at the same * time as the key, , false otherwise. * @see isAltPressed */ void setAltPressed(bool pressed); /** * Checks if meta is pressed. * * @return True if meta was pressed at the same * time as the key, false otherwise. * @see setMetaPressed */ bool isMetaPressed() const; /** * Sets meta to be pressed at the same time as the key, * or not. * * @param pressed True if meta is pressed at the same * time as the key, false otherwise. * @see isMetaPressed */ void setMetaPressed(bool pressed); /** * Checks if the key was pressed at the numeric pad. * * @return True if key pressed at the numeric pad, * false otherwise. * @setNumericPad */ bool isNumericPad() const; /** * Sets the key to be pressed at the numeric pad. * * @param numpad True if the key was pressed at the numeric * pad, false otherwise. * @see isNumericPad */ void setNumericPad(bool numpad); /** * Key input types. This enum corresponds to the enum with event * types on KeyEvent for easy mapping. */ enum { Pressed = 0, Released }; protected: /** * Holds the key of the key input. */ Key mKey; /** * Holds the type of the key input. */ unsigned int mType; /** * True if shift was pressed at the same time as the key, * false otherwise. */ bool mShiftPressed; /** * True if control was pressed at the same time as the key, * false otherwise. */ bool mControlPressed; /** * True if alt was pressed at the same time as the key, * false otherwise. */ bool mAltPressed; /** * True if meta was pressed at the same time as the key, * false otherwise. */ bool mMetaPressed; /** * True if the numeric pad was used when the key was pressed, * false otherwise. */ bool mNumericPad; }; } #endif // end FCN_KEYINPUT_HPP fifechan-0.1.5/include/fifechan/keylistener.hpp000066400000000000000000000115461341577075500215420ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_KEYLISTENER_HPP #define FCN_KEYLISTENER_HPP #include "fifechan/keyevent.hpp" #include "fifechan/platform.hpp" namespace fcn { class Key; /** * Interface for listening for key events from widgets. * * @see Widget::addKeyListener, Widget::removeKeyListener */ class FCN_CORE_DECLSPEC KeyListener { public: /** * Destructor. */ virtual ~KeyListener() { } /** * Called if a key is pressed when the widget has keyboard focus. * If a key is held down the widget will generate multiple key * presses. * * @param keyEvent Discribes the event. */ virtual void keyPressed(KeyEvent& keyEvent) { } /** * Called if a key is released when the widget has keyboard focus. * * @param keyEvent Discribes the event. */ virtual void keyReleased(KeyEvent& keyEvent) { } protected: /** * Constructor. * * You should not be able to make an instance of KeyListener, * therefore its constructor is protected. */ KeyListener() { } }; } #endif // end FCN_KEYLISTENER_HPP fifechan-0.1.5/include/fifechan/listmodel.hpp000066400000000000000000000112551341577075500211750ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_LISTMODEL_HPP #define FCN_LISTMODEL_HPP #include #include "fifechan/platform.hpp" namespace fcn { /** * An interface for a model that represents a list. It is * used in certain widgets, like the ListBox, to handle a * lists with string elements. If you want to use widgets * like ListBox, make a derived class from this class that * represents your list. */ class FCN_CORE_DECLSPEC ListModel { public: /** * Destructor. */ virtual ~ListModel() { } /** * Gets the number of elements in the list. * * @return The number of elements in the list */ virtual int getNumberOfElements() = 0; /** * Gets an element at a certain index in the list. * * @param i An index in the list. * @return An element as a string at the a certain index. */ virtual std::string getElementAt(int i) = 0; }; } #endif // end FCN_LISTMODEL_HPP fifechan-0.1.5/include/fifechan/mouseevent.hpp000066400000000000000000000201531341577075500213700ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_MOUSEEVENT_HPP #define FCN_MOUSEEVENT_HPP #include "fifechan/inputevent.hpp" #include "fifechan/platform.hpp" namespace fcn { class Gui; class Widget; /** * Represents a mouse event. * * @author Olof Naessn */ class FCN_CORE_DECLSPEC MouseEvent: public InputEvent { public: /** * Constructor. * * @param source The widget the event concerns. * @param distributor The distributor of the mouse event. * @param isShiftPressed True if shift is pressed, false otherwise. * @param isControlPressed True if control is pressed, false otherwise. * @param isAltPressed True if alt is pressed, false otherwise. * @param isMetaPressed True if meta is pressed, false otherwise. * @param type The type of the mouse event. * @param button The button of the mouse event. * @param x The x coordinate of the event relative to the source widget. * @param y The y coordinate of the event relative the source widget. * @param clickCount The number of clicks generated with the same button. * It's set to zero if another button is used. */ MouseEvent(Widget* source, Widget* distributor, bool isShiftPressed, bool isControlPressed, bool isAltPressed, bool isMetaPressed, unsigned int type, unsigned int button, int x, int y, int clickCount); /** * Gets the button of the mouse event. * * @return The button of the mouse event. */ unsigned int getButton() const; /** * Gets the x coordinate of the mouse event. * The coordinate relative to widget the mouse listener * receiving the events have registered to. * * @return The x coordinate of the mouse event. * @see Widget::addMouseListener, Widget::removeMouseListener */ int getX() const; /** * Gets the y coordinate of the mouse event. * The coordinate relative to widget the mouse listener * receiving the events have registered to. * * @return The y coordinate of the mouse event. * @see Widget::addMouseListener, Widget::removeMouseListener */ int getY() const; /** * Gets the number of clicks generated with the same button. * It's set to zero if another button is used. * * @return The number of clicks generated with the same button. */ int getClickCount() const; /** * Gets the type of the event. * * @return The type of the event. */ unsigned int getType() const; /** * Mouse event types. */ enum { Moved = 0, Pressed, Released, WheelMovedDown, WheelMovedUp, WheelMovedRight, WheelMovedLeft, Clicked, Entered, Exited, Dragged }; /** * Mouse button types. */ enum { Empty = 0, Left, Right, Middle, X1, X2 }; protected: /** * Holds the type of the mouse event. */ unsigned int mType; /** * Holds the button of the mouse event. */ unsigned int mButton; /** * Holds the x-coordinate of the mouse event. */ int mX; /** * Holds the y-coordinate of the mouse event. */ int mY; /** * The number of clicks generated with the same button. * It's set to zero if another button is used. */ int mClickCount; /** * Gui is a friend of this class in order to be able to manipulate * the protected member variables of this class and at the same time * keep the MouseEvent class as const as possible. Gui needs to * update the x och y coordinates for the coordinates to be relative * to widget the mouse listener receiving the events have registered * to. */ friend class Gui; }; } #endif // FCN_MOUSEEVENT_HPP fifechan-0.1.5/include/fifechan/mouseinput.hpp000066400000000000000000000200411341577075500214020ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_MOUSEINPUT_HPP #define FCN_MOUSEINPUT_HPP #include "fifechan/platform.hpp" namespace fcn { /** * Internal class that represents mouse input. Generally you won't have to * bother using this class unless you implement an Input class for * a back end. * * @author Olof Naessn * @author Per Larsson */ class FCN_CORE_DECLSPEC MouseInput { public: /** * Constructor. */ MouseInput() { }; /** * Constructor. * * @param button The button pressed. * @param type The type of mouse input. * @param x The mouse x coordinate. * @param y The mouse y coordinate. * @param timeStamp The timestamp of the mouse input. Used to * check for double clicks. */ MouseInput(unsigned int button, unsigned int type, int x, int y, int timeStamp); /** * Sets the type of the mouse input. * * @param type The type of the mouse input. Should be a value from the * mouse event type enum * @see getType */ void setType(unsigned int type); /** * Gets the type of the mouse input. * * @return The type of the mouse input. A value from the mouse event * type enum. * @see setType */ unsigned int getType() const; /** * Sets the button pressed. * * @param button The button pressed. Should be one of the values * in the mouse event button enum. * @see getButton. */ void setButton(unsigned int button); /** * Gets the button pressed. * * @return The button pressed. A value from the mouse event * button enum. * @see setButton */ unsigned int getButton() const; /** * Sets the timestamp for the mouse input. * Used to check for double clicks. * * @param timeStamp The timestamp of the mouse input. * @see getTimeStamp */ void setTimeStamp(int timeStamp); /** * Gets the time stamp of the input. * Used to check for double clicks. * * @return The time stamp of the mouse input. * @see setTimeStamp */ int getTimeStamp() const; /** * Sets the x coordinate of the mouse input. * * @param x The x coordinate of the mouse input. * @see getX */ void setX(int x); /** * Gets the x coordinate of the mouse input. * * @return The x coordinate of the mouse input. * @see setX */ int getX() const; /** * Sets the y coordinate of the mouse input. * * @param y The y coordinate of the mouse input. * @see getY */ void setY(int y); /** * Gets the y coordinate of the mouse input. * * @return The y coordinate of the mouse input. * @see setY */ int getY() const; /** * Mouse input event types. This enum partially corresponds * to the enum with event types in MouseEvent for easy mapping. */ enum { Moved = 0, Pressed, Released, WheelMovedDown, WheelMovedUp, WheelMovedRight, WheelMovedLeft }; /** * Mouse button types. */ enum { Empty = 0, Left, Right, Middle, X1, X2 }; protected: /** * Holds the type of the mouse input. */ unsigned int mType; /** * Holds the button of the mouse input. */ unsigned int mButton; /** * Holds the timestamp of the mouse input. Used to * check for double clicks. */ int mTimeStamp; /** * Holds the x coordinate of the mouse input. */ int mX; /** * Holds the y coordinate of the mouse input. */ int mY; }; } #endif // end FCN_MOUSEINPUT_HPP fifechan-0.1.5/include/fifechan/mouselistener.hpp000066400000000000000000000162771341577075500221100ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_MOUSELISTENER_HPP #define FCN_MOUSELISTENER_HPP #include "fifechan/mouseevent.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Interface for listening for mouse events from widgets. * * @see Widget::addMouseListener, Widget::removeMouseListener */ class FCN_CORE_DECLSPEC MouseListener { public: /** * Destructor. */ virtual ~MouseListener() { } /** * Called when the mouse has entered into the widget area. * * @param mouseEvent Describes the event. */ virtual void mouseEntered(MouseEvent& mouseEvent) { } /** * Called when the mouse has exited the widget area. * * @param mouseEvent Describes the event. */ virtual void mouseExited(MouseEvent& mouseEvent) { } /** * Called when a mouse button has been pressed on the widget area. * * NOTE: A mouse press is NOT equal to a mouse click. * Use mouseClickMessage to check for mouse clicks. * * @param mouseEvent Describes the event. */ virtual void mousePressed(MouseEvent& mouseEvent) { } /** * Called when a mouse button has been released on the widget area. * * @param mouseEvent Describes the event. */ virtual void mouseReleased(MouseEvent& mouseEvent) { } /** * Called when a mouse button is pressed and released (clicked) on * the widget area. * * @param mouseEvent Describes the event. */ virtual void mouseClicked(MouseEvent& mouseEvent) { } /** * Called when the mouse wheel has moved up on the widget area. * * @param mouseEvent Describes the event. */ virtual void mouseWheelMovedUp(MouseEvent& mouseEvent) { } /** * Called when the mouse wheel has moved down on the widget area. * * @param mousEvent Describes the event. */ virtual void mouseWheelMovedDown(MouseEvent& mouseEvent) { } /** * Called when the mouse wheel has moved right on the widget area. * * @param mousEvent Describes the event. */ virtual void mouseWheelMovedRight(MouseEvent& mouseEvent) { } /** * Called when the mouse wheel has moved left on the widget area. * * @param mousEvent Describes the event. */ virtual void mouseWheelMovedLeft(MouseEvent& mouseEvent) { } /** * Called when the mouse has moved in the widget area and no mouse button * has been pressed (i.e no widget is being dragged). * * @param mouseEvent Describes the event. */ virtual void mouseMoved(MouseEvent& mouseEvent) { } /** * Called when the mouse has moved and the mouse has previously been * pressed on the widget. * * @param mouseEvent Describes the event. */ virtual void mouseDragged(MouseEvent& mouseEvent) { } protected: /** * Constructor. * * You should not be able to make an instance of MouseListener, * therefore its constructor is protected. */ MouseListener() { } }; } #endif // end FCN_MOUSELISTENER_HPP fifechan-0.1.5/include/fifechan/opengl.hpp000066400000000000000000000077721341577075500204760ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENGL_HPP #define FCN_OPENGL_HPP #include #include #include "fifechan/platform.hpp" extern "C" { /** * Exists to be able to check for Guichan OpenGL with autotools. */ FCN_EXTENSION_DECLSPEC extern void fcnOpenGL(); } #endif // end FCN_OPENGL_HPP fifechan-0.1.5/include/fifechan/opengl/000077500000000000000000000000001341577075500177505ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/opengl/openglallegroimageloader.hpp000066400000000000000000000144231341577075500255110ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENGLALLEGROIMAGELOADER_HPP #define FCN_OPENGLALLEGROIMAGELOADER_HPP #include #include #include #include #include namespace fcn { /** * OpenGL ImageLoader that loads images with Allegro. */ class OpenGLAllegroImageLoader : public ImageLoader { public: // Inherited from ImageLoader virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true) { BITMAP *bmp = load_bitmap(filename.c_str(), NULL); if (bmp == NULL) { throw FCN_EXCEPTION( std::string("Unable to load image file: ") + filename); } int bitmapBpp = bitmap_color_depth(bmp); // As a BITMAP without an alpha channel in Allegro has // all it's alpha values set to zero we have to check // if the BITMAP has an alpha channel. If no alpha channel // exists then we need to change the alpha values to 255 // before creating the OpenGL image. bool hasAlphaChannel = false; int x, y; for (y = 0; y < bmp->h; y++) { for (x = 0; x < bmp->w; x++) { int pixel = getpixel(bmp, x, y); if (geta_depth(bitmapBpp, pixel) != 0) { hasAlphaChannel = true; } } } unsigned int *pixels = new unsigned int[bmp->w * bmp->h]; for (y = 0; y < bmp->h; y++) { for (x = 0; x < bmp->w; x++) { int pixel = getpixel(bmp,x, y); if (!hasAlphaChannel) { pixels[x + y * bmp->w] = pixel | 0xff000000; } else { pixels[x + y * bmp->w] = pixel; } } } OpenGLImage *image = new OpenGLImage(pixels, bmp->w, bmp->h, convertToDisplayFormat); delete[] pixels; destroy_bitmap(bmp); return image; } }; } #endif // end FCN_OPENGLALLEGROIMAGELOADER_HPP fifechan-0.1.5/include/fifechan/opengl/openglgraphics.hpp000066400000000000000000000143211341577075500234670ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENGLGRAPHICS_HPP #define FCN_OPENGLGRAPHICS_HPP #include "fifechan/color.hpp" #include "fifechan/graphics.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * OpenGL implementation of the Graphics. */ class FCN_EXTENSION_DECLSPEC OpenGLGraphics: public Graphics { public: // Needed so that drawImage(fcn::Image *, int, int) is visible. using Graphics::drawImage; /** * Constructor. */ OpenGLGraphics(); /** * Constructor. * * @param width the width of the logical drawing surface. Should be the * same as the screen resolution. * * @param height the height ot the logical drawing surface. Should be * the same as the screen resolution. */ OpenGLGraphics(int width, int height); /** * Destructor. */ virtual ~OpenGLGraphics(); /** * Sets the target plane on where to draw. * * @param width the width of the logical drawing surface. Should be the * same as the screen resolution. * @param height the height ot the logical drawing surface. Should be * the same as the screen resolution. */ virtual void setTargetPlane(int width, int height); /** * Gets the target plane width. * * @return The target plane width. */ virtual int getTargetPlaneWidth() const; /** * Gets the target plane height. * * @return The target plane height. */ virtual int getTargetPlaneHeight() const; // Inherited from Graphics virtual void _beginDraw(); virtual void _endDraw(); virtual bool pushClipArea(Rectangle area); virtual void popClipArea(); virtual void drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height); virtual void drawPoint(int x, int y); virtual void drawLine(int x1, int y1, int x2, int y2); virtual void drawRectangle(const Rectangle& rectangle); virtual void fillRectangle(const Rectangle& rectangle); virtual void setColor(const Color& color); virtual const Color& getColor() const; protected: int mWidth, mHeight; bool mAlpha; Color mColor; }; } #endif // end FCN_OPENGLGRAPHICS_HPP fifechan-0.1.5/include/fifechan/opengl/openglimage.hpp000066400000000000000000000152261341577075500227560ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENGLIMAGE_HPP #define FCN_OPENGLIMAGE_HPP #if defined (_WIN32) #define WIN32_LEAN_AND_MEAN #include #endif #if defined (__amigaos4__) #include #elif defined (__APPLE__) #include #else #include #endif #include #include "fifechan/color.hpp" #include "fifechan/platform.hpp" #include "fifechan/image.hpp" namespace fcn { /** * OpenGL implementation of Image. */ class FCN_EXTENSION_DECLSPEC OpenGLImage : public Image { public: /** * Constructor. Loads an image from an array of pixels. The pixel array is * is copied in the constructor and should thus be freed after the constructor * has been called. * * NOTE: The functions getPixel and putPixel are only guaranteed to work * before an image has been converted to display format. * * @param pixels to load from. * @param width the width of the image. * @param height the height of the image. * @param convertToDisplayFormat true if the image should be converted * to display, false otherwise. */ OpenGLImage(const unsigned int* pixels, int width, int height, bool convertToDisplayFormat = true); /** * Constructor. Load an image from an OpenGL texture handle. The width * and height specifies the size of the "interesting" part of the * texture, the real width and height of the texture are assumed to * be the closest higher power of two. * * @param textureHandle the texture handle from which to load. * @param width the width of the image. * @param height the height of the image. * @param autoFree true if the surface should automatically be deleted. */ OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree); /** * Destructor. */ virtual ~OpenGLImage(); /** * Gets the OpenGL texture handle for the image. * * @return the OpenGL texture handle for the image. */ virtual GLuint getTextureHandle() const; /** * Gets the width of texture. * * @return the width of the texture. */ virtual int getTextureWidth() const; /** * Gets the height of the texture. * * @return the height of the texture. */ virtual int getTextureHeight() const; // Inherited from Image virtual void free(); virtual int getWidth() const; virtual int getHeight() const; virtual Color getPixel(int x, int y); virtual void putPixel(int x, int y, const Color& color); virtual void convertToDisplayFormat(); protected: GLuint mTextureHandle; unsigned int* mPixels; bool mAutoFree; int mWidth; int mHeight; int mTextureWidth; int mTextureHeight; }; } #endif // end FCN_OPENGLIMAGE_HPP fifechan-0.1.5/include/fifechan/opengl/openglsdlimageloader.hpp000066400000000000000000000121671341577075500246510ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENGLSDLIMAGELOADER_HPP #define FCN_OPENGLSDLIMAGELOADER_HPP #include #include #include namespace fcn { class Image; /** * OpenGL ImageLoader that loads images with SDL. */ class OpenGLSDLImageLoader : public SDLImageLoader { public: // Inherited from ImageLoader virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true) { SDL_Surface *loadedSurface = loadSDLSurface(filename); if (loadedSurface == NULL) { throw FCN_EXCEPTION( std::string("Unable to load image file: ") + filename); } SDL_Surface *surface = convertToStandardFormat(loadedSurface); SDL_FreeSurface(loadedSurface); if (surface == NULL) { throw FCN_EXCEPTION( std::string("Not enough memory to load: ") + filename); } OpenGLImage *image = new OpenGLImage((unsigned int*)surface->pixels, surface->w, surface->h, convertToDisplayFormat); SDL_FreeSurface(surface); return image; } }; } #endif // end FCN_OPENGLSDLIMAGELOADER_HPP fifechan-0.1.5/include/fifechan/openlayer.hpp000066400000000000000000000102051341577075500211710ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENLAYER_HPP #define FCN_OPENLAYER_HPP #include #include #include #include #include "fifechan/platform.hpp" extern "C" { /** * Exists to be able to check for Guichan Open Layer * with autotools. */ FCN_EXTENSION_DECLSPEC extern void fcnOpenLayer(); } #endif // end FCN_OPENLAYER_HPP fifechan-0.1.5/include/fifechan/openlayer/000077500000000000000000000000001341577075500204625ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/openlayer/openlayerfont.hpp000066400000000000000000000121161341577075500240610ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENLAYERFONT_HPP #define FCN_OPENLAYERFONT_HPP #include #if defined (DELETE) #undef DELETE #endif #include "fifechan/font.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * OpenLayer font implementation of Font that uses the native * OpenLayer font. */ class FCN_EXTENSION_DECLSPEC OpenLayerTTFont : public Font { public: /** * Constructor. The font loaded with this constructor will be freed in the destructor. * * @param filename The filename of the font to load. * @param size The size of the font. */ OpenLayerTTFont(const std::string& filename, int size); /** * Constructor. The font loaded with this constructor will be freed in the destructor. * * @param filename The filename of the font to load. * @param width The width of the font. * @param height The height of the font. */ OpenLayerTTFont(const std::string& filename, int width, int height); /** * Destructor. */ ~OpenLayerTTFont(); // Inherited from Font virtual int getWidth(const std::string& text) const; virtual int getHeight() const; virtual void drawString(Graphics* graphics, const std::string& text, int x, int y); protected: ol::TextRenderer mTextRenderer; }; } #endif // FCN_OPENLAYERFONT_HPP fifechan-0.1.5/include/fifechan/openlayer/openlayergraphics.hpp000066400000000000000000000141731341577075500247200ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENLAYERGRAPHICS_HPP #define FCN_OPENLAYERGRAPHICS_HPP #include #if defined (DELETE) #undef DELETE #endif #include #include "fifechan/color.hpp" #include "fifechan/exception.hpp" #include "fifechan/graphics.hpp" namespace fcn { /** * OpenLayer implementation of Graphics. */ class FCN_EXTENSION_DECLSPEC OpenLayerGraphics: public Graphics { public: // Needed so that drawImage(fcn::Image *, int, int) is visible. using Graphics::drawImage; /** * Constructor. */ OpenLayerGraphics(); /** * Constructor. * * @param width the width of the logical drawing surface. Should be the * same as the screen resolution. * * @param height the height ot the logical drawing surface. Should be * the same as the screen resolution. */ OpenLayerGraphics(int width, int height); /** * Destructor. */ virtual ~OpenLayerGraphics(); /** * Sets the target plane on where to draw. * * @param width the width of the logical drawing surface. Should be the * same as the screen resolution. * @param height the height ot the logical drawing surface. Should be * the same as the screen resolution. */ virtual void setTargetPlane(int width, int height); // Inherited from Graphics. virtual void _beginDraw(); virtual void _endDraw(); virtual bool pushClipArea(Rectangle area); virtual void popClipArea(); virtual void drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height); virtual void drawPoint(int x, int y); virtual void drawLine(int x1, int y1, int x2, int y2); virtual void drawRectangle(const Rectangle& rectangle); virtual void fillRectangle(const Rectangle& rectangle); virtual void setColor(const Color& color); virtual const Color& getColor() const; const ol::Rgba& getOpenLayerColor() const; protected: int mWidth, mHeight; ol::Rgba mRgba; Color mColor; }; } #endif // FCN_OPENLAYERGRAPHICS_HPP fifechan-0.1.5/include/fifechan/openlayer/openlayerimage.hpp000066400000000000000000000120641341577075500241770ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENLAYERIMAGE_HPP #define FCN_OPENLAYERIMAGE_HPP #include #if defined (DELETE) #undef DELETE #endif #include #include "fifechan/color.hpp" #include "fifechan/platform.hpp" #include "fifechan/image.hpp" namespace fcn { /** * OpenLayer implementation of Image. */ class FCN_EXTENSION_DECLSPEC OpenLayerImage : public Image { public: /** * Constructor. Load an image from an Allegro BITMAP. * * @param bitmap the bitmap from which to load. * @param autoFree true if the bitmap should automatically be deleted. */ OpenLayerImage(BITMAP* bitmap, bool autoFree = true); /** * Destructor. */ virtual ~OpenLayerImage(); /** * Gets the OpenLayer bitmap for the image. * * @return the OpenLayer bitmap for the image. */ virtual ol::Bitmap* getBitmap() const; // Inherited from Image virtual void free(); virtual int getWidth() const; virtual int getHeight() const; virtual Color getPixel(int x, int y); virtual void putPixel(int x, int y, const Color& color); virtual void convertToDisplayFormat(); protected: ol::Bitmap* mOpenLayerBitmap; BITMAP* mAllegroBitmap; bool mAutoFree; }; } #endif // end FCN_OPENLAYERIMAGE_HPP fifechan-0.1.5/include/fifechan/openlayer/openlayerimageloader.hpp000066400000000000000000000102611341577075500253630ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENLAYERIMAGELOADER_HPP #define FCN_OPENLAYERIMAGELOADER_HPP #include "fifechan/image.hpp" #include "fifechan/imageloader.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * OpenLayer implementation of ImageLoader. */ class FCN_EXTENSION_DECLSPEC OpenLayerImageLoader : public ImageLoader { public: // Inherited from ImageLoader virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true); }; } #endif // end FCN_OPENLAYERIMAGELOADER_HPP fifechan-0.1.5/include/fifechan/openlayer/openlayerinput.hpp000066400000000000000000000124651341577075500242610ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_OPENLAYERINPUT_HPP #define FCN_OPENLAYERINPUT_HPP #include #include #include "fifechan/input.hpp" #include "fifechan/keyinput.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * OpenLayer implementation of the Input. */ class FCN_EXTENSION_DECLSPEC OpenLayerInput : public Input { public: /** * Constructor. */ OpenLayerInput(); /** * Destructor. */ virtual ~OpenLayerInput() { } // Inherited from Input virtual bool isKeyQueueEmpty(); virtual KeyInput dequeueKeyInput(); virtual bool isMouseQueueEmpty(); virtual MouseInput dequeueMouseInput(); virtual void _pollInput(); protected: /** * Handles the mouse input called by _pollInput. */ virtual void pollMouseInput(); /** * Handles the key input called by _pollInput. */ virtual void pollKeyInput(); /** * Converts scancode and unicode to Key object. */ virtual Key convertToKey(int scancode, int unicode); virtual bool isNumericPad(int scancode); // This map holds the currently pressed Keys // so we can send the correct key releases. // it maps from scancode to key objects. std::map mPressedKeys; std::queue mKeyQueue; std::queue mMouseQueue; bool mMouseButton1, mMouseButton2, mMouseButton3; int mLastMouseX, mLastMouseY, mLastMouseZ; }; } #endif // end FCN_OPENLAYERINPUT_HPP fifechan-0.1.5/include/fifechan/platform.hpp000066400000000000000000000111141341577075500210170ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_PLATFORM_HPP #define FCN_PLATFORM_HPP #if defined (__MINGW32__) && defined(FIFECHAN_BUILD) #define FCN_CORE_DECLSPEC __declspec(dllexport) #elif defined (__MINGW32__) && defined(FIFECHAN_EXTENSION_BUILD) #define FCN_EXTENSION_DECLSPEC __declspec(dllexport) #define FCN_CORE_DECLSPEC __declspec(dllimport) #elif defined (__MINGW32__) && defined(FIFECHAN_DLL_IMPORT) #define FCN_CORE_DECLSPEC __declspec(dllimport) #define FCN_EXTENSION_DECLSPEC __declspec(dllimport) #elif defined(_MSC_VER) && defined(FIFECHAN_BUILD) #define FCN_CORE_DECLSPEC _declspec(dllexport) #elif defined(_MSC_VER) && defined(FIFECHAN_EXTENSION_BUILD) #define FCN_CORE_DECLSPEC _declspec(dllimport) #define FCN_EXTENSION_DECLSPEC _declspec(dllexport) #endif #ifndef FCN_CORE_DECLSPEC #define FCN_CORE_DECLSPEC #endif #ifndef FCN_EXTENSION_DECLSPEC #define FCN_EXTENSION_DECLSPEC #endif #ifndef NULL #define NULL 0 #endif #endif // end FCN_PLATFORM_HPP fifechan-0.1.5/include/fifechan/point.hpp000066400000000000000000000134351341577075500203340ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2014-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_POINT_H #define FCN_POINT_H // Standard C++ library includes #include #include #include // Platform specific includes // 3rd party library includes // FCN includes // These includes are split up in two parts, separated by one empty line // First block: files included from the FCN root src directory // Second block: files included from the same folder #include "fifechan/util/fcn_math.hpp" namespace fcn { /** A 2D Point * * This is a small helper class to aid in 2d vector arithmetics. * @see Rect */ class Point { public: union { int val[2]; struct { int x,y; }; }; /** Constructor * * Creates a with 0 as default values. */ explicit Point(int _x = 0, int _y = 0): x(_x), y(_y) { } /** Copy Constructor */ Point(const Point& rhs): x(rhs.x), y(rhs.y) { } /** Vector addition */ Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); } /** Vector substraction */ Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); } /** Vector inplace addition */ Point& operator+=(const Point& p) { x += p.x; y += p.y; return *this; } /** Vector inplace substraction */ Point& operator-=(const Point& p) { x -= p.x; y -= p.y; return *this; } /** Scalar multiplication with an integer value */ Point operator*(const int& i) const { return Point(x * i, y * i); } /** Scalar division with an integer value */ Point operator/(const int& i) const { return Point(x / i, y / i); } /** Equality comparision */ bool operator==(const Point& p) const { return x == p.x && y == p.y; } /** Equality comparision */ bool operator!=(const Point& p) const { return !(x == p.x && y == p.y); } /** Return length */ int length() const { double sq; sq = x*x + y*y; return static_cast(Mathf::Sqrt(sq)); } /** Normalizes the point */ void normalize() { int invLength = static_cast(1.0/length()); //TODO: get rid of this static cast if (invLength > static_cast(Mathf::zeroTolerance())) { x = x * invLength; y = y * invLength; } else { x = 0; y = 0; } } /** Rotates the point around the origin */ void rotate(int angle){ //TODO: get rid of this static cast int theta = (angle * static_cast(Mathd::pi()))/180; int costheta = static_cast(Mathd::Cos(theta)); int sintheta = static_cast(Mathd::Sin(theta)); int nx = x; int ny = y; x = costheta * nx - sintheta * ny; y = sintheta * nx + costheta * ny; } /** Rotates the point around an origin */ void rotate(const Point& origin, int angle){ //TODO: get rid of this static cast int theta = (angle * static_cast(Mathd::pi()))/180; int costheta = static_cast(Mathd::Cos(theta)); int sintheta = static_cast(Mathd::Sin(theta)); int nx = x - origin.x; int ny = y - origin.y; x = costheta * nx - sintheta * ny; y = sintheta * nx + costheta * ny; } /** Sets the x and y coordinate of the 2D point */ void set(int _x, int _y) { x = _x; y = _y; } inline int& operator[] (int ind) { assert(ind > -1 && ind < 2); return val[ind]; } friend std::ostream& operator<<(std::ostream& os, const Point& p) { return os << "(" << p.x << ":" << p.y << ")"; } }; typedef std::vector PointVector; } #endif fifechan-0.1.5/include/fifechan/rectangle.hpp000066400000000000000000000167421341577075500211530ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_RECTANGLE_HPP #define FCN_RECTANGLE_HPP #include "fifechan/platform.hpp" #include namespace fcn { /** * Represents a rectangle. * */ class FCN_CORE_DECLSPEC Rectangle { public: /** * Constructor. The default rectangle is an empty rectangle * at the coordinates (0,0). */ Rectangle(); /** * Constructor. * * @param x The x coordinate of the rectangle. * @param y The y coordinate of the rectangle. * @param width The width of the rectangle. * @param height The height of the rectangle. */ Rectangle(int x, int y, int width, int height); /** * Sets the dimension of a rectangle. * * @param x The x coordinate of the rectangle. * @param y The y coordinate of the rectangle. * @param width The width of the rectangle. * @param height The height of the rectangle. */ void setAll(int x, int y, int width, int height); /** * Checks if another rectangle intersects with the rectangle. * * @param rectangle Another rectangle to check for intersection. * @return True if the rectangles intersect, false otherwise. */ bool isIntersecting(const Rectangle& rectangle) const; /** * Checks the rectangle contains a point. * * @param x The x coordinate of the point. * @param y The y coordinate of the point. * @return True if the rectangle contains the point, * false otherwise. */ bool isContaining(int x, int y) const; /** * Checks if the rectangle contains a rectangle. * * @param other The rectangle to check. * @return True if the rectangle contains the rectangle, * false otherwise. */ bool isContaining(const Rectangle& other) const; /** * Checks whether the rectangle is empty or not. A rectangle * is considered empty when it's width or height is either * zero or negative. * * @return True if the rectangle is empty, false otherwise. */ bool isEmpty() const; /** * Adds a rectangle to this rectangle. The resulting rectangle * is the union of the two rectangles. * * @param rh The rectangle to add. * @return The union of the two rectangles. */ Rectangle operator+(const Rectangle& rh) const; /** * Adds a rectangle to this rectangle. This rectangle will be * the union of the two rectangles. * * @param rh The rectangle to add. * @return A reference to this rectangle. */ const Rectangle& operator+=(const Rectangle& rh); /** * Gets the intersection between two rectangles. * * @param rh The rectangle to calculate the intersection with. * @return The intersection between two rectangles. */ Rectangle intersection(const Rectangle& rh) const; /** * Output operator for output. * * @param out The stream to output to. * @param rectangle The rectangle to output. */ friend std::ostream& operator<<(std::ostream& out, const Rectangle& rectangle); /** * Holds the x coordinate of the rectangle. */ int x; /** * Holds the x coordinate of the rectangle. */ int y; /** * Holds the width of the rectangle. */ int width; /** * Holds the height of the rectangle. */ int height; }; } #endif // end FCN_RECTANGEL_HPP fifechan-0.1.5/include/fifechan/sdl.hpp000066400000000000000000000100461341577075500177600ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_SDL_HPP #define FCN_SDL_HPP #include #include #include #include #include "platform.hpp" extern "C" { /** * Exists to be able to check for Guichan SDL with autotools. */ FCN_EXTENSION_DECLSPEC extern void fcnSDL(); } #endif // end FCN_SDL_HPP fifechan-0.1.5/include/fifechan/sdl/000077500000000000000000000000001341577075500172465ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/sdl/sdlgraphics.hpp000066400000000000000000000151631341577075500222700ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_SDLGRAPHICS_HPP #define FCN_SDLGRAPHICS_HPP #include "SDL.h" #include "fifechan/color.hpp" #include "fifechan/graphics.hpp" #include "fifechan/platform.hpp" namespace fcn { class Image; class Rectangle; /** * SDL implementation of the Graphics. */ class FCN_EXTENSION_DECLSPEC SDLGraphics : public Graphics { public: // Needed so that drawImage(fcn::Image *, int, int) is visible. using Graphics::drawImage; /** * Constructor. */ SDLGraphics(); /** * Sets the target SDL_Surface to draw to. The target can be any * SDL_Surface. This funtion also pushes a clip areas corresponding to * the dimension of the target. * * @param target the target to draw to. */ virtual void setTarget(SDL_Surface* target); /** * Gets the target SDL_Surface. * * @return the target SDL_Surface. */ virtual SDL_Surface* getTarget() const; /** * Draws an SDL_Surface on the target surface. Normaly you'll * use drawImage, but if you want to write SDL specific code * this function might come in handy. * * NOTE: The clip areas will be taken into account. */ virtual void drawSDLSurface(SDL_Surface* surface, SDL_Rect source, SDL_Rect destination); // Inherited from Graphics virtual void _beginDraw(); virtual void _endDraw(); virtual bool pushClipArea(Rectangle area); virtual void popClipArea(); virtual void drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height); virtual void drawPoint(int x, int y); virtual void drawLine(int x1, int y1, int x2, int y2); virtual void drawRectangle(const Rectangle& rectangle); virtual void fillRectangle(const Rectangle& rectangle); virtual void setColor(const Color& color); virtual const Color& getColor() const; protected: /** * Draws a horizontal line. * * @param x1 the start coordinate of the line. * @param y the y coordinate of the line. * @param x2 the end coordinate of the line. */ virtual void drawHLine(int x1, int y, int x2); /** * Draws a vertical line. * * @param x the x coordinate of the line. * @param y1 the start coordinate of the line. * @param y2 the end coordinate of the line. */ virtual void drawVLine(int x, int y1, int y2); SDL_Surface* mTarget; Color mColor; bool mAlpha; }; } #endif // end FCN_SDLGRAPHICS_HPP fifechan-0.1.5/include/fifechan/sdl/sdlimage.hpp000066400000000000000000000121031341577075500215410ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_SDLIMAGE_HPP #define FCN_SDLIMAGE_HPP #include "SDL.h" #include #include "fifechan/color.hpp" #include "fifechan/platform.hpp" #include "fifechan/image.hpp" namespace fcn { /** * SDL implementation of Image. */ class FCN_EXTENSION_DECLSPEC SDLImage : public Image { public: /** * Constructor. Load an image from an SDL surface. * * NOTE: The functions getPixel and putPixel are only guaranteed to work * before an image has been converted to display format. * * @param surface the surface from which to load. * @param autoFree true if the surface should automatically be deleted. */ SDLImage(SDL_Surface* surface, bool autoFree); /** * Destructor. */ virtual ~SDLImage(); /** * Gets the SDL surface for the image. * * @return the SDL surface for the image. */ virtual SDL_Surface* getSurface() const; // Inherited from Image virtual void free(); virtual int getWidth() const; virtual int getHeight() const; virtual Color getPixel(int x, int y); virtual void putPixel(int x, int y, const Color& color); virtual void convertToDisplayFormat(); protected: SDL_Surface* mSurface; bool mAutoFree; }; } #endif // end FCN_SDLIMAGE_HPP fifechan-0.1.5/include/fifechan/sdl/sdlimageloader.hpp000066400000000000000000000106351341577075500227400ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_SDLIMAGELOADER_HPP #define FCN_SDLIMAGELOADER_HPP #include "fifechan/imageloader.hpp" #include "fifechan/platform.hpp" #include "SDL.h" namespace fcn { class Image; /** * SDL implementation of ImageLoader. */ class FCN_EXTENSION_DECLSPEC SDLImageLoader : public ImageLoader { public: // Inherited from ImageLoader virtual Image* load(const std::string& filename, bool convertToDisplayFormat = true); const SDL_PixelFormat& getSDLPixelFormat(); void setSDLPixelFormat(const SDL_PixelFormat& format); protected: virtual SDL_Surface* loadSDLSurface(const std::string& filename); virtual SDL_Surface* convertToStandardFormat(SDL_Surface* surface); private: SDL_PixelFormat mPixelFormat; }; } #endif // end FCN_SDLIMAGELOADER_HPP fifechan-0.1.5/include/fifechan/sdl/sdlinput.hpp000066400000000000000000000131121341577075500216170ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_SDLINPUT_HPP #define FCN_SDLINPUT_HPP #include #include "SDL.h" #include "fifechan/input.hpp" #include "fifechan/keyinput.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/platform.hpp" namespace fcn { class Key; /** * SDL implementation of Input. */ class FCN_EXTENSION_DECLSPEC SDLInput : public Input { public: /** * Constructor. */ SDLInput(); /** * Pushes an SDL event. It should be called at least once per frame to * update input with user input. * * @param event an event from SDL. */ virtual void pushInput(SDL_Event event); /** * Polls all input. It exists for input driver compatibility. If you * only use SDL and plan sticking with SDL you can safely ignore this * function as it in the SDL case does nothing. */ virtual void _pollInput() { } // Inherited from Input virtual bool isKeyQueueEmpty(); virtual KeyInput dequeueKeyInput(); virtual bool isMouseQueueEmpty(); virtual MouseInput dequeueMouseInput(); protected: /** * Converts a mouse button from SDL to a Guichan mouse button * representation. * * @param button an SDL mouse button. * @return a Guichan mouse button. */ int convertMouseButton(int button); /** * Converts an SDL event to a Guichan key value. * * @param keysym The SDL event to convert. * @return A Guichan key value. -1 if no conversion took place. * @see Key */ int convertSDLEventToFifechanKeyValue(SDL_Event event); std::queue mKeyInputQueue; std::queue mMouseInputQueue; bool mMouseDown; bool mMouseInWindow; }; } #endif // end FCN_SDLINPUT_HPP fifechan-0.1.5/include/fifechan/sdl/sdlpixel.hpp000066400000000000000000000230571341577075500216120ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_SDLPIXEL_HPP #define FCN_SDLPIXEL_HPP #include "SDL.h" #include "fifechan/color.hpp" namespace fcn { /** * Checks a pixels color of an SDL_Surface. * * @param surface an SDL_Surface where to check for a pixel color. * @param x the x coordinate on the surface. * @param y the y coordinate on the surface. * @return a color of a pixel. */ inline const Color SDLgetPixel(SDL_Surface* surface, int x, int y) { int bpp = surface->format->BytesPerPixel; SDL_LockSurface(surface); Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; unsigned int color = 0; switch(bpp) { case 1: color = *p; break; case 2: color = *(Uint16 *)p; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { color = p[0] << 16 | p[1] << 8 | p[2]; } else { color = p[0] | p[1] << 8 | p[2] << 16; } break; case 4: color = *(Uint32 *)p; break; } unsigned char r,g,b,a; SDL_GetRGBA(color, surface->format, &r, &g, &b, &a); SDL_UnlockSurface(surface); return Color(r,g,b,a); } /** * Puts a pixel on an SDL_Surface. * * @param x the x coordinate on the surface. * @param y the y coordinate on the surface. * @param color the color the pixel should be in. */ inline void SDLputPixel(SDL_Surface* surface, int x, int y, const Color& color) { int bpp = surface->format->BytesPerPixel; SDL_LockSurface(surface); Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); switch(bpp) { case 1: *p = pixel; break; case 2: *(Uint16 *)p = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *(Uint32 *)p = pixel; break; } SDL_UnlockSurface(surface); } /** * Blends two 32 bit colors together. * * @param src the source color. * @param dst the destination color. * @param a alpha. */ inline unsigned int SDLAlpha32(unsigned int src, unsigned int dst, unsigned char a) { unsigned int b = ((src & 0xff) * a + (dst & 0xff) * (255 - a)) >> 8; unsigned int g = ((src & 0xff00) * a + (dst & 0xff00) * (255 - a)) >> 8; unsigned int r = ((src & 0xff0000) * a + (dst & 0xff0000) * (255 - a)) >> 8; return (b & 0xff) | (g & 0xff00) | (r & 0xff0000); } /** * Blends two 16 bit colors together. * * @param src the source color. * @param dst the destination color. * @param a alpha. */ inline unsigned short SDLAlpha16(unsigned short src, unsigned short dst, unsigned char a, const SDL_PixelFormat *f) { unsigned int b = ((src & f->Rmask) * a + (dst & f->Rmask) * (255 - a)) >> 8; unsigned int g = ((src & f->Gmask) * a + (dst & f->Gmask) * (255 - a)) >> 8; unsigned int r = ((src & f->Bmask) * a + (dst & f->Bmask) * (255 - a)) >> 8; return (unsigned short)((b & f->Rmask) | (g & f->Gmask) | (r & f->Bmask)); } /* typedef struct{ SDL_Palette *palette; Uint8 BitsPerPixel; Uint8 BytesPerPixel; Uint32 Rmask, Gmask, Bmask, Amask; Uint8 Rshift, Gshift, Bshift, Ashift; Uint8 Rloss, Gloss, Bloss, Aloss; Uint32 colorkey; Uint8 alpha; } SDL_PixelFormat; */ /** * Puts a pixel on an SDL_Surface with alpha * * @param x the x coordinate on the surface. * @param y the y coordinate on the surface. * @param color the color the pixel should be in. */ inline void SDLputPixelAlpha(SDL_Surface* surface, int x, int y, const Color& color) { int bpp = surface->format->BytesPerPixel; SDL_LockSurface(surface); Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); switch(bpp) { case 1: *p = pixel; break; case 2: *(Uint16 *)p = SDLAlpha16(pixel, *(Uint32 *)p, color.a, surface->format); break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { unsigned int r = (p[0] * (255 - color.a) + color.r * color.a) >> 8; unsigned int g = (p[1] * (255 - color.a) + color.g * color.a) >> 8; unsigned int b = (p[2] * (255 - color.a) + color.b * color.a) >> 8; p[2] = b; p[1] = g; p[0] = r; } else { unsigned int r = (p[2] * (255 - color.a) + color.r * color.a) >> 8; unsigned int g = (p[1] * (255 - color.a) + color.g * color.a) >> 8; unsigned int b = (p[0] * (255 - color.a) + color.b * color.a) >> 8; p[0] = b; p[1] = g; p[2] = r; } break; case 4: *(Uint32 *)p = SDLAlpha32(pixel, *(Uint32 *)p, color.a); break; } SDL_UnlockSurface(surface); } } #endif // end FCN_SDLPIXEL_HPP fifechan-0.1.5/include/fifechan/selectionevent.hpp000066400000000000000000000104071341577075500222260ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_SELECTIONEVENT_HPP #define FCN_SELECTIONEVENT_HPP #include "fifechan/event.hpp" #include "fifechan/platform.hpp" namespace fcn { class Widget; /** * Represents a selection event. * * @author Olof Naessn */ class FCN_CORE_DECLSPEC SelectionEvent: public Event { public: /** * Constructor. * * @param source source The widget of the selection event. */ SelectionEvent(Widget* source); /** * Destructor. */ virtual ~SelectionEvent(); }; } #endif // end FCN_SELECTIONEVENT_HPP fifechan-0.1.5/include/fifechan/selectionlistener.hpp000066400000000000000000000115721341577075500227360ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_SELECTIONLISTENER_HPP #define FCN_SELECTIONLISTENER_HPP #include #include "fifechan/selectionevent.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Interface for listening for selection events from widgets. * * @see ListBox::addSelectionListener, * ListBox::removeSelectionListener, * DropDown::addSelectionListener, * DropDown::removeSelectionListener * @author Olof Naessn */ class FCN_CORE_DECLSPEC SelectionListener { public: /** * Destructor. */ virtual ~SelectionListener() { } /** * Called when the value of a selection has been changed in a Widget. * It is used to be able to recieve a notification that a value has * been changed. * * @param event The event of the value change. */ virtual void valueChanged(const SelectionEvent& event) { }; protected: /** * Constructor. * * You should not be able to make an instance of SelectionListener, * therefore its constructor is protected. */ SelectionListener() { } }; } #endif // end FCN_SELECTIONLISTENER_HPP fifechan-0.1.5/include/fifechan/size.hpp000066400000000000000000000050211341577075500201450ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_SIZE_HPP #define FCN_SIZE_HPP #include "fifechan/platform.hpp" namespace fcn { class FCN_CORE_DECLSPEC Size { public: /** * Constructor initializes size values. * * @param width Width of size. * @param height Height of size. */ Size(int width = 0, int height = 0); ~Size(); /** * @return Width of size. */ int getWidth() const; /** * @return Height of size. */ int getHeight() const; /** * Sets the width of size. * * @param width Desired width. */ void setWidth(int width); /** * Sets the height of size. * * @param height Desired height. */ void setHeight(int height); private: // width of the size int mWidth; // height of the size int mHeight; }; }; #endif fifechan-0.1.5/include/fifechan/text.hpp000066400000000000000000000307261341577075500201710ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_TEXT_HPP #define FCN_TEXT_HPP #include "fifechan/platform.hpp" #include "fifechan/rectangle.hpp" #include #include namespace fcn { class Font; /** * A utility class to ease working with text in widgets such as * TextBox and TextField. The class wraps common text operations * such as inserting and deleting text. * */ class FCN_CORE_DECLSPEC Text { public: /** * Constructor. */ Text(); /** * Constructor. * * @param content The content of the text. */ Text(const std::string& content); /** * Destructor. */ virtual ~Text(); /** * Sets the content of the text. Will completely remove * any previous text and reset the caret position. * * @param content The content of the text. */ virtual void setContent(const std::string& text); /** * Gets the content of the text. * * @return The content of the text. */ virtual std::string getContent() const; /** * Sets the content of a row. * * @param row The row to set the text of. * @throws Exception when the row does not exist. */ virtual void setRow(unsigned int row, const std::string& content); /** * Adds a row to the content. Calling this method will * not change the current caret position. * * @param row The row to add. */ virtual void addRow(const std::string& row); /** * Inserts a row before the specified row position. Calling this method * will not change the current caret position. * * @param row The row to add. * @param position Inserts new row before this row. */ virtual void insertRow(const std::string& row, unsigned int position); /** * Erases the given row. Calling this method will not change the current * caret position. * * @param row Row to be erased. */ virtual void eraseRow(unsigned int row); /** * Gets a reference to a row. * * @param row The row to get the content of. * @return The reference to a row. * @throws Exception when no such row exists. */ virtual std::string& getRow(unsigned int row); /** * Inserts a character at the current caret position. * * @parameter character The character to insert. */ virtual void insert(int character); /** * Removes a given number of characters at starting * at the current caret position. * * If the number of characters to remove is negative * characters will be removed left of the caret position. * If the number is positive characters will be removed * right of the caret position. If a line feed is * removed the row with the line feed will be merged * with the row above the line feed. * * @param numberOfCharacters The number of characters to remove. */ virtual void remove(int numberOfCharacters); /** * Gets the caret position. * * @return The caret position. */ virtual int getCaretPosition() const; /** * Sets the caret position. The position will be * clamp to the dimension of the content. * * @param position The position of the caret. */ virtual void setCaretPosition(int position); /** * Sets the caret position given an x and y coordinate in pixels * relative to the text. The coordinates will be clamp to the content. * * @param x The x coordinate of the caret. * @param y The y coordinate of the caret. * @param font The font to use when calculating the position. */ virtual void setCaretPosition(int x, int y, Font* font); /** * Gets the column the caret is currently in. * * @return The column the caret is currently in. */ virtual int getCaretColumn() const; /** * Gets the row the caret is currently in. * * @return The row the caret is currently in. */ virtual int getCaretRow() const; /** * Sets the column the caret should be in. The column * will be clamp to the current row. * * @param column The column the caret should be in. */ virtual void setCaretColumn(int column); /** * Sets the row the caret should be in. If the row lies o * outside of the text, the row will be set to zero or the * maximum row depending on where the row lies outside of the * text. * * Calling this function trigger a recalculation of the caret * column. * * @param row The row the caret should be in. */ virtual void setCaretRow(int row); /** * Gets the x coordinate of the caret in pixels given a font. * * @param font The font to use when calculating the x coordinate. * @return The x coorinate of the caret in pixels. */ virtual int getCaretX(Font* font) const; /** * Gets the y coordinate of the caret in pixels given a font. * * @param font The font to use when calculating the y coordinate. * @return The y coorinate of the caret in pixels. */ virtual int getCaretY(Font* font) const; /** * Gets the dimension in pixels of the text given a font. If there * is no text present a dimension of a white space will be returned. * * @param font The font to use when calculating the dimension. * @return The dimension in pixels of the text given a font. */ virtual Rectangle getDimension(Font* font) const; /** * Gets the caret dimension relative to this text. * The returned dimension is perfect for use with Widget::showPart * so the caret is always shown. * * @param font The font to use when calculating the dimension. * @return The dimension of the caret. */ virtual Rectangle getCaretDimension(Font* font) const; /** * Gets the width in pixels of a row. If the row is not * present in the text zero will be returned. * * @param row The row to get the width of. * @return The width in pixels of a row. */ virtual int getWidth(int row, Font* font) const; /** * Gets the maximum row the caret can be in. * * @return The maximum row the caret can be in. */ virtual unsigned int getMaximumCaretRow() const; /** * Gets the maximum column of a row the caret can be in. * * @param row The row of the caret. * @return The maximum column of a row the caret can be in. */ virtual unsigned int getMaximumCaretRow(unsigned int row) const; /** * Gets the number of rows in the text. * * @return The number of rows in the text. */ virtual unsigned int getNumberOfRows() const; /** * Gets the number of characters in the text. * * @return The number of characters in the text. */ virtual unsigned int getNumberOfCharacters() const; /** * Gets the number of characters in a certain row in the text. * If the row does not exist, zero will be returned. * * @param row The row to get the number of characters in. * @return The number of characters in a certain row, or zero * if the row does not exist. */ virtual unsigned int getNumberOfCharacters(unsigned int row) const; protected: /** * Calculates the caret position from the caret row and caret column. */ void calculateCaretPositionFromRowAndColumn(); /** * Holds the text row by row. */ std::vector mRows; /** * Holds the position of the caret. This variable should * always be valid. */ unsigned int mCaretPosition; /** * Holds the row the caret is in. This variable should always * be valid. */ unsigned int mCaretRow; /** * Holds the column the caret is in. This variable should always * be valid. */ unsigned int mCaretColumn; }; } #endif fifechan-0.1.5/include/fifechan/utf8stringeditor.hpp000066400000000000000000000072071341577075500225270ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_UTF8STRINGEDITOR_HPP #define FCN_UTF8STRINGEDITOR_HPP // Standard C++ library includes #include namespace fcn { /** * UTF-8 string editor. * * This is a helper class which allows to use UTF-8 strings in * your application. * * @author Przemyslaw Grzywacz */ class UTF8StringEditor { public: /** * Returns byte offset of the next character. * * @param text UTF-8 text to navigate. * @param byteOffset Byte offset of current character. * @return Byte offset of the next character. */ static int nextChar(const std::string& text, int byteOffset); /** * Returns byte offset of the previous character. * * @param text UTF-8 text to navigate. * @param byteOffset Byte offset of current character. * @return Byte offset of the previous character. */ static int prevChar(const std::string& text, int byteOffset); /** * Erase character at specified byte offset. * * @param text UTF-8 text to modify. * @param byteOffset Byte offset of the character to erase. * @return New byte offset (is equal to byteOffset). */ static int eraseChar(std::string& text, int byteOffset); /** * Insert a character at specified byte offset. * * @param text UTF-8 text to modify. * @param byteOffset Byte offset where character will be inserted. * @param ch Unicode character to insert. * @return New byte offset (after the new character). */ static int insertChar(std::string& text, int byteOffset, int ch); /** * Counts characters up to byteOffset. * * @param text UTF-8 text to navigate. * @param byteOffset Byte offset inside the text. * @return Number of characters. */ static int countChars(const std::string& text, int byteOffset); /** * Gets byte offset for character index. * * This method automaticly clips charIndex to be inside * the string + EOF * * @param text UTF-8 text to navigate. * @param charIndex Character index to move to. * @return Byte offset of character at charIndex. */ static int getOffset(const std::string& text, int charIndex); }; }; #endif // !FCN_UTF8STRINGEDITOR_HPP fifechan-0.1.5/include/fifechan/util/000077500000000000000000000000001341577075500174415ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/util/Makefile.am000066400000000000000000000001411341577075500214710ustar00rootroot00000000000000libfifechanincludedir = $(includedir)/fifechan/util libfifechaninclude_HEADERS = \ fcn_math.hppfifechan-0.1.5/include/fifechan/util/fcn_math.hpp000066400000000000000000000255051341577075500217400ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2014-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_UTIL_FCN_MATH_H #define FCN_UTIL_FCN_MATH_H // Standard C++ library includes #include #include #include // Platform specific includes // 3rd party library includes // FCN includes // These includes are split up in two parts, separated by one empty line // First block: files included from the FCN root src directory // Second block: files included from the same folder #ifndef ABS #define ABS(x) ((x)<0?-(x):(x)) #endif namespace fcn { // Sort out the missing round function in MSVC: #if defined( WIN32 ) && defined( _MSC_VER ) inline double round(const double x) { return x < 0.0 ? ceil(x - 0.5) : floor(x + 0.5); } #endif static const float FLT_STD_EPSILON = std::numeric_limits::epsilon(); static const float FLT_STD_MAX = std::numeric_limits::max(); static const float FLT_ZERO_TOLERANCE = 1e-06f; static const float FLT_PI = 4.0f*std::atan(1.0f); static const float FLT_TWO_PI = 2.0f*FLT_PI; static const float FLT_HALF_PI = 0.5f*FLT_PI; static const float FLT_INVERSE_PI = 1.0f/FLT_PI; static const float FLT_INVERSE_TWO_PI = 1.0f/FLT_TWO_PI; static const float FLT_DEG_TO_RAD = FLT_PI/180.0f; static const float FLT_RAD_TO_DEG = 180.0f/FLT_PI; static const float FLT_LOG_2 = std::log(2.0f); static const float FLT_LOG_10 = std::log(10.0f); static const float FLT_INV_LOG_2 = 1.0f/std::log(2.0f); static const float FLT_INV_LOG_10 = 1.0f/std::log(10.0f); static const double DBL_STD_EPSILON = std::numeric_limits::epsilon(); static const double DBL_STD_MAX = std::numeric_limits::max(); static const double DBL_ZERO_TOLERANCE = 1e-08; static const double DBL_PI = 4.0*std::atan(1.0); static const double DBL_TWO_PI = 2.0*DBL_PI; static const double DBL_HALF_PI = 0.5*DBL_PI; static const double DBL_INVERSE_PI = 1.0/DBL_PI; static const double DBL_INVERSE_TWO_PI = 1.0/DBL_TWO_PI; static const double DBL_DEG_TO_RAD = DBL_PI/180.0; static const double DBL_RAD_TO_DEG = 180.0f/DBL_PI; static const double DBL_LOG_2 = std::log(2.0); static const double DBL_LOG_10 = std::log(10.0); static const double DBL_INV_LOG_2 = 1.0/std::log(2.0); static const double DBL_INV_LOG_10 = 1.0/std::log(10.0); template struct float_traits { }; template <> struct float_traits { typedef float float_type; static inline float_type epsilon() { return FLT_STD_EPSILON; } static inline float_type zeroTolerance() { return FLT_ZERO_TOLERANCE; } static inline float_type max() { return FLT_STD_MAX; } static inline float_type pi() { return FLT_PI; } static inline float_type twoPi() { return FLT_TWO_PI; } static inline float_type halfPi() { return FLT_HALF_PI; } static inline float_type inversePi() { return FLT_INVERSE_PI; } static inline float_type inverseTwoPi() { return FLT_INVERSE_TWO_PI; } static inline float_type degToRad() { return FLT_DEG_TO_RAD; } static inline float_type radToDeg() { return FLT_RAD_TO_DEG; } static inline float_type log2() { return FLT_LOG_2; } static inline float_type log10() { return FLT_LOG_10; } static inline float_type invLog2() { return FLT_INV_LOG_2; } static inline float_type invLog10() { return FLT_INV_LOG_10; } }; template <> struct float_traits { typedef double float_type; static inline float_type epsilon() { return DBL_STD_EPSILON; } static inline float_type zeroTolerance() { return DBL_ZERO_TOLERANCE; } static inline float_type max() { return DBL_STD_MAX; } static inline float_type pi() { return DBL_PI; } static inline float_type twoPi() { return DBL_TWO_PI; } static inline float_type halfPi() { return DBL_HALF_PI; } static inline float_type inversePi() { return DBL_INVERSE_PI; } static inline float_type inverseTwoPi() { return DBL_INVERSE_TWO_PI; } static inline float_type degToRad() { return DBL_DEG_TO_RAD; } static inline float_type radToDeg() { return DBL_RAD_TO_DEG; } static inline float_type log2() { return DBL_LOG_2; } static inline float_type log10() { return DBL_LOG_10; } static inline float_type invLog2() { return DBL_INV_LOG_2; } static inline float_type invLog10() { return DBL_INV_LOG_10; } }; template class Math { public: typedef T num_type; typedef float_traits traits_type; static inline num_type epsilon() { return traits_type::epsilon(); } static inline num_type zeroTolerance() { return traits_type::zeroTolerance(); } static inline num_type max() { return traits_type::max(); } static inline num_type pi() { return traits_type::pi(); } static inline num_type twoPi() { return traits_type::twoPi(); } static inline num_type halfPi() { return traits_type::halfPi(); } static inline num_type inversePi() { return traits_type::inversePi(); } static inline num_type inverseTwoPi() { return traits_type::inverseTwoPi(); } static inline num_type degToRad() { return traits_type::degToRad(); } static inline num_type radToDeg() { return traits_type::radToDeg(); } static inline num_type log2() { return traits_type::log2(); } static inline num_type log10() { return traits_type::log10(); } static inline num_type invLog2() { return traits_type::invLog2(); } static inline num_type invLog10() { return traits_type::invLog10(); } static T ACos(T _val); static T ASin(T _val); static T ATan(T _val); static T ATan2(T _x, T _y); static T Ceil(T _val); static T Cos(T _val); static T Exp(T _val); static T FAbs(T _val); static T Floor(T _val); static T FMod (T _x, T _y); static T InvSqrt(T _val); static T Log(T _val); static T Log2(T _val); static T Log10(T _val); static T Pow(T _base, T _exponent); static T Sin(T _val); static T Sqr(T _val); static T Sqrt(T _val); static T Tan(T _val); static bool Equal(T _val1, T _val2); }; typedef Math Mathf; typedef Math Mathd; template inline T Math::ACos(T _val) { if (-static_cast(1) < _val) { if (_val < static_cast(1)) { return static_cast(std::acos(_val)); } else { return static_cast(0); } } else { return pi(); } } template inline T Math::ASin(T _val) { if (-static_cast(1) < _val) { if (_val < static_cast(1)) { return static_cast(std::asin(_val)); } else { return halfPi(); } } else { return -halfPi(); } } template inline T Math::ATan(T _val) { return static_cast(std::atan(_val)); } template inline T Math::ATan2(T _x, T _y) { return static_cast(std::atan2(_x, _y)); } template inline T Math::Ceil(T _val) { return static_cast(std::ceil(_val)); } template inline T Math::Cos(T _val) { return static_cast(std::cos(_val)); } template inline T Math::Exp(T _val){ return static_cast(std::exp(_val)); } template inline T Math::FAbs(T _val) { return static_cast(std::fabs(_val)); } template inline T Math::Floor(T _val) { return static_cast(std::floor(_val)); } template inline T Math::FMod(T _x, T _y) { return static_cast(std::fmod(_x, _y)); } template inline T Math::InvSqrt(T _val) { return static_cast(1/std::sqrt(_val)); } template inline T Math::Log(T _val) { return static_cast(std::log(_val)); } template inline T Math::Log2(T _val) { return invLog2() * static_cast(std::log(_val)); } template inline T Math::Log10(T _val) { return invLog10() * static_cast(std::log(_val)); } template inline T Math::Pow(T _base, T _exponent) { return static_cast(std::pow(_base, _exponent)); } template inline T Math::Sin(T _val) { return static_cast(std::sin(_val)); } template inline T Math::Sqr(T _val) { return _val*_val; } template inline T Math::Sqrt(T _val) { return static_cast(std::sqrt(_val)); } template inline T Math::Tan(T _val) { return static_cast(std::tan(_val)); } template inline bool Math::Equal(T _val1, T _val2) { return std::fabs(_val1 - _val2) < epsilon(); } /** Returns the next higher power of 2 based on the passed argument */ inline unsigned nextPow2(unsigned x) { --x; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return ++x; } } //FCN #endif // FCN_UTIL_FCN_MATH_H fifechan-0.1.5/include/fifechan/util/utf8/000077500000000000000000000000001341577075500203275ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/util/utf8/utf8.hpp000066400000000000000000000060001341577075500217220ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ // Copyright 2006 Nemanja Trifunovic /* Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 #define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 #include "utf8/checked.hpp" #include "utf8/unchecked.hpp" #endif // header guard fifechan-0.1.5/include/fifechan/util/utf8/utf8/000077500000000000000000000000001341577075500212155ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/util/utf8/utf8/checked.hpp000066400000000000000000000326311341577075500233210ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ // Copyright 2006 Nemanja Trifunovic /* Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 #define UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 #include "core.hpp" #include namespace utf8 { // Base for the exceptions that may be thrown from the library class exception : public ::std::exception { }; // Exceptions that may be thrown from the library functions. class invalid_code_point : public exception { uint32_t cp; public: invalid_code_point(uint32_t cp) : cp(cp) {} virtual const char* what() const throw() { return "Invalid code point"; } uint32_t code_point() const {return cp;} }; class invalid_utf8 : public exception { uint8_t u8; public: invalid_utf8 (uint8_t u) : u8(u) {} virtual const char* what() const throw() { return "Invalid UTF-8"; } uint8_t utf8_octet() const {return u8;} }; class invalid_utf16 : public exception { uint16_t u16; public: invalid_utf16 (uint16_t u) : u16(u) {} virtual const char* what() const throw() { return "Invalid UTF-16"; } uint16_t utf16_word() const {return u16;} }; class not_enough_room : public exception { public: virtual const char* what() const throw() { return "Not enough space"; } }; /// The library API - functions intended to be called by the users template octet_iterator append(uint32_t cp, octet_iterator result) { if (!utf8::internal::is_code_point_valid(cp)) throw invalid_code_point(cp); if (cp < 0x80) // one octet *(result++) = static_cast(cp); else if (cp < 0x800) { // two octets *(result++) = static_cast((cp >> 6) | 0xc0); *(result++) = static_cast((cp & 0x3f) | 0x80); } else if (cp < 0x10000) { // three octets *(result++) = static_cast((cp >> 12) | 0xe0); *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); *(result++) = static_cast((cp & 0x3f) | 0x80); } else { // four octets *(result++) = static_cast((cp >> 18) | 0xf0); *(result++) = static_cast(((cp >> 12) & 0x3f) | 0x80); *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); *(result++) = static_cast((cp & 0x3f) | 0x80); } return result; } template output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement) { while (start != end) { octet_iterator sequence_start = start; internal::utf_error err_code = utf8::internal::validate_next(start, end); switch (err_code) { case internal::UTF8_OK : for (octet_iterator it = sequence_start; it != start; ++it) *out++ = *it; break; case internal::NOT_ENOUGH_ROOM: throw not_enough_room(); case internal::INVALID_LEAD: out = utf8::append (replacement, out); ++start; break; case internal::INCOMPLETE_SEQUENCE: case internal::OVERLONG_SEQUENCE: case internal::INVALID_CODE_POINT: out = utf8::append (replacement, out); ++start; // just one replacement mark for the sequence while (start != end && utf8::internal::is_trail(*start)) ++start; break; } } return out; } template inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out) { static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd); return utf8::replace_invalid(start, end, out, replacement_marker); } template uint32_t next(octet_iterator& it, octet_iterator end) { uint32_t cp = 0; internal::utf_error err_code = utf8::internal::validate_next(it, end, cp); switch (err_code) { case internal::UTF8_OK : break; case internal::NOT_ENOUGH_ROOM : throw not_enough_room(); case internal::INVALID_LEAD : case internal::INCOMPLETE_SEQUENCE : case internal::OVERLONG_SEQUENCE : throw invalid_utf8(*it); case internal::INVALID_CODE_POINT : throw invalid_code_point(cp); } return cp; } template uint32_t peek_next(octet_iterator it, octet_iterator end) { return utf8::next(it, end); } template uint32_t prior(octet_iterator& it, octet_iterator start) { // can't do much if it == start if (it == start) throw not_enough_room(); octet_iterator end = it; // Go back until we hit either a lead octet or start while (utf8::internal::is_trail(*(--it))) if (it == start) throw invalid_utf8(*it); // error - no lead byte in the sequence return utf8::peek_next(it, end); } /// Deprecated in versions that include "prior" template uint32_t previous(octet_iterator& it, octet_iterator pass_start) { octet_iterator end = it; while (utf8::internal::is_trail(*(--it))) if (it == pass_start) throw invalid_utf8(*it); // error - no lead byte in the sequence octet_iterator temp = it; return utf8::next(temp, end); } template void advance (octet_iterator& it, distance_type n, octet_iterator end) { for (distance_type i = 0; i < n; ++i) utf8::next(it, end); } template typename std::iterator_traits::difference_type distance (octet_iterator first, octet_iterator last) { typename std::iterator_traits::difference_type dist; for (dist = 0; first < last; ++dist) utf8::next(first, last); return dist; } template octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result) { while (start != end) { uint32_t cp = utf8::internal::mask16(*start++); // Take care of surrogate pairs first if (utf8::internal::is_lead_surrogate(cp)) { if (start != end) { uint32_t trail_surrogate = utf8::internal::mask16(*start++); if (utf8::internal::is_trail_surrogate(trail_surrogate)) cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET; else throw invalid_utf16(static_cast(trail_surrogate)); } else throw invalid_utf16(static_cast(cp)); } // Lone trail surrogate else if (utf8::internal::is_trail_surrogate(cp)) throw invalid_utf16(static_cast(cp)); result = utf8::append(cp, result); } return result; } template u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result) { while (start != end) { uint32_t cp = utf8::next(start, end); if (cp > 0xffff) { //make a surrogate pair *result++ = static_cast((cp >> 10) + internal::LEAD_OFFSET); *result++ = static_cast((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN); } else *result++ = static_cast(cp); } return result; } template octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result) { while (start != end) result = utf8::append(*(start++), result); return result; } template u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result) { while (start != end) (*result++) = utf8::next(start, end); return result; } // The iterator class template class iterator : public std::iterator { octet_iterator it; octet_iterator range_start; octet_iterator range_end; public: iterator () {} explicit iterator (const octet_iterator& octet_it, const octet_iterator& range_start, const octet_iterator& range_end) : it(octet_it), range_start(range_start), range_end(range_end) { if (it < range_start || it > range_end) throw std::out_of_range("Invalid utf-8 iterator position"); } // the default "big three" are OK octet_iterator base () const { return it; } uint32_t operator * () const { octet_iterator temp = it; return utf8::next(temp, range_end); } bool operator == (const iterator& rhs) const { if (range_start != rhs.range_start || range_end != rhs.range_end) throw std::logic_error("Comparing utf-8 iterators defined with different ranges"); return (it == rhs.it); } bool operator != (const iterator& rhs) const { return !(operator == (rhs)); } iterator& operator ++ () { utf8::next(it, range_end); return *this; } iterator operator ++ (int) { iterator temp = *this; utf8::next(it, range_end); return temp; } iterator& operator -- () { utf8::prior(it, range_start); return *this; } iterator operator -- (int) { iterator temp = *this; utf8::prior(it, range_start); return temp; } }; // class iterator } // namespace utf8 #endif //header guard fifechan-0.1.5/include/fifechan/util/utf8/utf8/core.hpp000066400000000000000000000277241341577075500226720ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ // Copyright 2006 Nemanja Trifunovic /* Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 #define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 #include namespace utf8 { // The typedefs for 8-bit, 16-bit and 32-bit unsigned integers // You may need to change them to match your system. // These typedefs have the same names as ones from cstdint, or boost/cstdint typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; // Helper code - not intended to be directly called by the library users. May be changed at any time namespace internal { // Unicode constants // Leading (high) surrogates: 0xd800 - 0xdbff // Trailing (low) surrogates: 0xdc00 - 0xdfff const uint16_t LEAD_SURROGATE_MIN = 0xd800u; const uint16_t LEAD_SURROGATE_MAX = 0xdbffu; const uint16_t TRAIL_SURROGATE_MIN = 0xdc00u; const uint16_t TRAIL_SURROGATE_MAX = 0xdfffu; const uint16_t LEAD_OFFSET = LEAD_SURROGATE_MIN - (0x10000 >> 10); const uint32_t SURROGATE_OFFSET = 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN; // Maximum valid value for a Unicode code point const uint32_t CODE_POINT_MAX = 0x0010ffffu; template inline uint8_t mask8(octet_type oc) { return static_cast(0xff & oc); } template inline uint16_t mask16(u16_type oc) { return static_cast(0xffff & oc); } template inline bool is_trail(octet_type oc) { return ((utf8::internal::mask8(oc) >> 6) == 0x2); } template inline bool is_lead_surrogate(u16 cp) { return (cp >= LEAD_SURROGATE_MIN && cp <= LEAD_SURROGATE_MAX); } template inline bool is_trail_surrogate(u16 cp) { return (cp >= TRAIL_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX); } template inline bool is_surrogate(u16 cp) { return (cp >= LEAD_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX); } template inline bool is_code_point_valid(u32 cp) { return (cp <= CODE_POINT_MAX && !utf8::internal::is_surrogate(cp)); } template inline typename std::iterator_traits::difference_type sequence_length(octet_iterator lead_it) { uint8_t lead = utf8::internal::mask8(*lead_it); if (lead < 0x80) return 1; else if ((lead >> 5) == 0x6) return 2; else if ((lead >> 4) == 0xe) return 3; else if ((lead >> 3) == 0x1e) return 4; else return 0; } template inline bool is_overlong_sequence(uint32_t cp, octet_difference_type length) { if (cp < 0x80) { if (length != 1) return true; } else if (cp < 0x800) { if (length != 2) return true; } else if (cp < 0x10000) { if (length != 3) return true; } return false; } enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT}; /// Helper for get_sequence_x template utf_error increase_safely(octet_iterator& it, octet_iterator end) { if (++it == end) return NOT_ENOUGH_ROOM; if (!utf8::internal::is_trail(*it)) return INCOMPLETE_SEQUENCE; return UTF8_OK; } #define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END) {utf_error ret = increase_safely(IT, END); if (ret != UTF8_OK) return ret;} /// get_sequence_x functions decode utf-8 sequences of the length x template utf_error get_sequence_1(octet_iterator& it, octet_iterator end, uint32_t& code_point) { if (it == end) return NOT_ENOUGH_ROOM; code_point = utf8::internal::mask8(*it); return UTF8_OK; } template utf_error get_sequence_2(octet_iterator& it, octet_iterator end, uint32_t& code_point) { if (it == end) return NOT_ENOUGH_ROOM; code_point = utf8::internal::mask8(*it); UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) code_point = ((code_point << 6) & 0x7ff) + ((*it) & 0x3f); return UTF8_OK; } template utf_error get_sequence_3(octet_iterator& it, octet_iterator end, uint32_t& code_point) { if (it == end) return NOT_ENOUGH_ROOM; code_point = utf8::internal::mask8(*it); UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) code_point = ((code_point << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff); UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) code_point += (*it) & 0x3f; return UTF8_OK; } template utf_error get_sequence_4(octet_iterator& it, octet_iterator end, uint32_t& code_point) { if (it == end) return NOT_ENOUGH_ROOM; code_point = utf8::internal::mask8(*it); UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) code_point = ((code_point << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff); UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) code_point += (utf8::internal::mask8(*it) << 6) & 0xfff; UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) code_point += (*it) & 0x3f; return UTF8_OK; } #undef UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR template utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point) { // Save the original value of it so we can go back in case of failure // Of course, it does not make much sense with i.e. stream iterators octet_iterator original_it = it; uint32_t cp = 0; // Determine the sequence length based on the lead octet typedef typename std::iterator_traits::difference_type octet_difference_type; const octet_difference_type length = utf8::internal::sequence_length(it); // Get trail octets and calculate the code point utf_error err = UTF8_OK; switch (length) { case 0: return INVALID_LEAD; case 1: err = utf8::internal::get_sequence_1(it, end, cp); break; case 2: err = utf8::internal::get_sequence_2(it, end, cp); break; case 3: err = utf8::internal::get_sequence_3(it, end, cp); break; case 4: err = utf8::internal::get_sequence_4(it, end, cp); break; } if (err == UTF8_OK) { // Decoding succeeded. Now, security checks... if (utf8::internal::is_code_point_valid(cp)) { if (!utf8::internal::is_overlong_sequence(cp, length)){ // Passed! Return here. code_point = cp; ++it; return UTF8_OK; } else err = OVERLONG_SEQUENCE; } else err = INVALID_CODE_POINT; } // Failure branch - restore the original value of the iterator it = original_it; return err; } template inline utf_error validate_next(octet_iterator& it, octet_iterator end) { uint32_t ignored; return utf8::internal::validate_next(it, end, ignored); } } // namespace internal /// The library API - functions intended to be called by the users // Byte order mark const uint8_t bom[] = {0xef, 0xbb, 0xbf}; template octet_iterator find_invalid(octet_iterator start, octet_iterator end) { octet_iterator result = start; while (result != end) { utf8::internal::utf_error err_code = utf8::internal::validate_next(result, end); if (err_code != internal::UTF8_OK) return result; } return result; } template inline bool is_valid(octet_iterator start, octet_iterator end) { return (utf8::find_invalid(start, end) == end); } template inline bool starts_with_bom (octet_iterator it, octet_iterator end) { return ( ((it != end) && (utf8::internal::mask8(*it++)) == bom[0]) && ((it != end) && (utf8::internal::mask8(*it++)) == bom[1]) && ((it != end) && (utf8::internal::mask8(*it)) == bom[2]) ); } //Deprecated in release 2.3 template inline bool is_bom (octet_iterator it) { return ( (utf8::internal::mask8(*it++)) == bom[0] && (utf8::internal::mask8(*it++)) == bom[1] && (utf8::internal::mask8(*it)) == bom[2] ); } } // namespace utf8 #endif // header guard fifechan-0.1.5/include/fifechan/util/utf8/utf8/unchecked.hpp000066400000000000000000000243301341577075500236610ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ // Copyright 2006 Nemanja Trifunovic /* Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 #define UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 #include "core.hpp" namespace utf8 { namespace unchecked { template octet_iterator append(uint32_t cp, octet_iterator result) { if (cp < 0x80) // one octet *(result++) = static_cast(cp); else if (cp < 0x800) { // two octets *(result++) = static_cast((cp >> 6) | 0xc0); *(result++) = static_cast((cp & 0x3f) | 0x80); } else if (cp < 0x10000) { // three octets *(result++) = static_cast((cp >> 12) | 0xe0); *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); *(result++) = static_cast((cp & 0x3f) | 0x80); } else { // four octets *(result++) = static_cast((cp >> 18) | 0xf0); *(result++) = static_cast(((cp >> 12) & 0x3f)| 0x80); *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); *(result++) = static_cast((cp & 0x3f) | 0x80); } return result; } template uint32_t next(octet_iterator& it) { uint32_t cp = utf8::internal::mask8(*it); typename std::iterator_traits::difference_type length = utf8::internal::sequence_length(it); switch (length) { case 1: break; case 2: it++; cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f); break; case 3: ++it; cp = ((cp << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff); ++it; cp += (*it) & 0x3f; break; case 4: ++it; cp = ((cp << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff); ++it; cp += (utf8::internal::mask8(*it) << 6) & 0xfff; ++it; cp += (*it) & 0x3f; break; } ++it; return cp; } template uint32_t peek_next(octet_iterator it) { return utf8::unchecked::next(it); } template uint32_t prior(octet_iterator& it) { while (utf8::internal::is_trail(*(--it))) ; octet_iterator temp = it; return utf8::unchecked::next(temp); } // Deprecated in versions that include prior, but only for the sake of consistency (see utf8::previous) template inline uint32_t previous(octet_iterator& it) { return utf8::unchecked::prior(it); } template void advance (octet_iterator& it, distance_type n) { for (distance_type i = 0; i < n; ++i) utf8::unchecked::next(it); } template typename std::iterator_traits::difference_type distance (octet_iterator first, octet_iterator last) { typename std::iterator_traits::difference_type dist; for (dist = 0; first < last; ++dist) utf8::unchecked::next(first); return dist; } template octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result) { while (start != end) { uint32_t cp = utf8::internal::mask16(*start++); // Take care of surrogate pairs first if (utf8::internal::is_lead_surrogate(cp)) { uint32_t trail_surrogate = utf8::internal::mask16(*start++); cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET; } result = utf8::unchecked::append(cp, result); } return result; } template u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result) { while (start < end) { uint32_t cp = utf8::unchecked::next(start); if (cp > 0xffff) { //make a surrogate pair *result++ = static_cast((cp >> 10) + internal::LEAD_OFFSET); *result++ = static_cast((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN); } else *result++ = static_cast(cp); } return result; } template octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result) { while (start != end) result = utf8::unchecked::append(*(start++), result); return result; } template u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result) { while (start < end) (*result++) = utf8::unchecked::next(start); return result; } // The iterator class template class iterator : public std::iterator { octet_iterator it; public: iterator () {} explicit iterator (const octet_iterator& octet_it): it(octet_it) {} // the default "big three" are OK octet_iterator base () const { return it; } uint32_t operator * () const { octet_iterator temp = it; return utf8::unchecked::next(temp); } bool operator == (const iterator& rhs) const { return (it == rhs.it); } bool operator != (const iterator& rhs) const { return !(operator == (rhs)); } iterator& operator ++ () { ::std::advance(it, utf8::internal::sequence_length(it)); return *this; } iterator operator ++ (int) { iterator temp = *this; ::std::advance(it, utf8::internal::sequence_length(it)); return temp; } iterator& operator -- () { utf8::unchecked::prior(it); return *this; } iterator operator -- (int) { iterator temp = *this; utf8::unchecked::prior(it); return temp; } }; // class iterator } // namespace utf8::unchecked } // namespace utf8 #endif // header guard fifechan-0.1.5/include/fifechan/version.hpp000066400000000000000000000150041341577075500206620ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the FCNchan team * * http://FCNchan.github.com/FCNchan * * This file is part of FCNchan. * * * * FCNchan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_VERSION_HPP #define FCN_VERSION_HPP /** These version numbers should be checked and updated * as part of the release process for Fifechan. */ #ifndef FCN_MAJOR_VERSION #define FCN_MAJOR_VERSION 0 #endif #ifndef FCN_MINOR_VERSION #define FCN_MINOR_VERSION 1 #endif #ifndef FCN_PATCH_VERSION #define FCN_PATCH_VERSION 5 #endif /** Types * 0 = none (pre-release info is not appended to the version in this case) * 1 = alpha * 2 = beta * 3 = rc */ #ifndef FCN_PRERELEASE_TYPE #define FCN_PRERELEASE_TYPE 0 #endif #ifndef FCN_PRERELEASE_VERSION #define FCN_PRERELEASE_VERSION 0 #endif /*************************************************************************** * Do not update anything below this line! ***************************************************************************/ #define FCN_STR(s) # s #define FCN_XSTR(s) FCN_STR(s) #define FCN_DOT(a,b) a.b #define FCN_XDOT(a,b) FCN_DOT(a,b) #define FCN_PLUS(a,b) a+b #define FCN_XPLUS(a,b) FCN_PLUS(a,b) #define FCN_MINUS(a,b) a-b #define FCN_XMINUS(a,b) FCN_MINUS(a,b) #if FCN_PRERELEASE_TYPE==1 #define FCN_PRERELEASE alpha #elif FCN_PRERELEASE_TYPE==2 #define FCN_PRERELEASE beta #elif FCN_PRERELEASE_TYPE==3 #define FCN_PRERELEASE rc #endif #if FCN_PRERELEASE_VERSION>0 #ifdef FCN_PRERELEASE #define FCN_PRERELEASE_STR \ FCN_XDOT( \ FCN_PRERELEASE, \ FCN_PRERELEASE_VERSION \ ) #endif #endif #define FCN_VERSION \ FCN_XDOT( \ FCN_XDOT(FCN_MAJOR_VERSION, FCN_MINOR_VERSION), \ FCN_PATCH_VERSION \ ) #ifdef FCN_PRERELEASE_STR #define FCN_VERSION_STRING \ FCN_XMINUS( \ FCN_VERSION, \ FCN_PRERELEASE_STR \ ) #endif #ifdef FCN_GIT_HASH #ifndef FCN_VERSION_STRING #define FCN_VERSION_STRING \ FCN_XPLUS( \ FCN_VERSION, \ FCN_GIT_HASH \ ) #else #undef FCN_VERSION_STRING #ifdef FCN_PRERELEASE_STR #define FCN_VERSION_STRING \ FCN_XMINUS( \ FCN_VERSION, \ FCN_XPLUS( \ FCN_PRERELEASE_STR, \ FCN_GIT_HASH \ ) \ ) #else #define FCN_VERSION_STRING \ FCN_XPLUS( \ FCN_VERSION, \ FCN_GIT_HASH \ ) #endif #endif #else #define FCN_GIT_HASH "" #endif // This is an actual release #ifndef FCN_VERSION_STRING #define FCN_VERSION_STRING FCN_VERSION #endif /** All Fifechan related code is in this namespace. */ namespace fcn { inline const char* getVersion() { return FCN_XSTR(FCN_VERSION_STRING); } inline int getMajor() { return FCN_MAJOR_VERSION; } inline int getMinor() { return FCN_MINOR_VERSION; } inline int getPatch() { return FCN_PATCH_VERSION; } inline const char* getHash() { return FCN_XSTR(FCN_GIT_HASH); } } //fcn //cleanup #undef FCN_STR #undef FCN_XSTR #undef FCN_DOT #undef FCN_XDOT #undef FCN_PLUS #undef FCN_XPLUS #undef FCN_MINUS #undef FCN_XMINUS #undef FCN_VERSION_STRING #undef FCN_VERSION #undef FCN_PRERELEASE #undef FCN_PRERELEASE_STR #endif //FCN_VERSION_HPP fifechan-0.1.5/include/fifechan/visibilityeventhandler.hpp000066400000000000000000000047351341577075500237750ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_VISIBILITYEVENTHANDLER_HPP #define FCN_VISIBILITYEVENTHANDLER_HPP #include "fifechan/widgetlistener.hpp" namespace fcn { class Event; class Gui; class Widget; /** * Class that handles Widget visiblity changes. Addresses input issues arised * when widgets are shown or hidden. */ class FCN_CORE_DECLSPEC VisibilityEventHandler : public WidgetListener { public: /** * Constructor */ VisibilityEventHandler(Gui* gui); /** * Destructor */ virtual ~VisibilityEventHandler() {}; /** * Informs gui that a widget was hidden. */ virtual void widgetHidden(const Event& e); /** * Informs gui that a widget was shown. */ virtual void widgetShown(const Event& e); protected: Gui *mGui; }; } #endif //FCN_VISIBILITYEVENTHANDLER_HPPfifechan-0.1.5/include/fifechan/widget.hpp000066400000000000000000001660171341577075500204730ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_WIDGET_HPP #define FCN_WIDGET_HPP #include #include #include "fifechan/color.hpp" #include "fifechan/rectangle.hpp" #include "fifechan/size.hpp" #include "fifechan/widgetlistener.hpp" namespace fcn { class ActionListener; class DeathListener; class DefaultFont; class FocusHandler; class FocusListener; class Font; class Graphics; class KeyInput; class KeyListener; class MouseInput; class MouseListener; class VisibilityEventHandler; class WidgetListener; /** * Abstract class for widgets of Guichan. It contains basic functions * every widget should have. * * NOTE: Functions begining with underscore "_" should not * be overloaded unless you know what you are doing. * * @author Olof Naessn * @author Per Larsson */ class FCN_CORE_DECLSPEC Widget { public: /** * Selection mode. */ enum SelectionMode { Selection_None = 0, Selection_Border = 1, Selection_Background = 2 }; /** * Constructor. Resets member variables. Noteable, a widget is not * focusable as default, therefore, widgets that are supposed to be * focusable should overide this default in their own constructor. */ Widget(); /** * Default destructor. */ virtual ~Widget(); /** * Draws the widget. The call to draw is initiated by the widget's * parent. The graphics object is set up so that all drawing is relative * to the widget, i.e coordinate (0,0) is the top left corner of the widget. * It is not possible to draw outside of a widget's dimension. If a widget * has children, the parent's draw function will always be called before * the children's draw functions are called. * * NOTE: A widget with children won't draw its children unless the * children area given by Widget::getChildrenArea returns a * none empty rectangle inside the widgets dimension. The children * area is considered relative to the widget's position. * * @param graphics A graphics object to draw with. * @see getChildrenArea, drawOutline, drawBorder */ virtual void draw(Graphics* graphics) = 0; /** * Called when a widget is given a chance to draw a outline around itself. * The outline is not considered as part of the widget, it only allows a outline * to be drawn around the widget, thus a outline will never be included when * calculating if a widget should receive events from user input. Also * a widget's outline will never be included when calculating a widget's * position. * * The size of the outline is calculated using the widget's outline size. * If a widget has a outline size of 10 pixels than the area the drawOutline * function can draw to will be the size of the widget with an additional * extension of 10 pixels in each direction. * * An example when drawOutline is a useful function is if a widget needs * a glow around itself. * * @param graphics A graphics object to draw with. * @see setOutlineSize, getOutlineSize */ virtual void drawOutline(Graphics* graphics); /** * Called when a widget have a border. * * @param graphics A graphics object to draw with. * @see setBorderSize, getBorderSize */ virtual void drawBorder(Graphics* graphics); /** * Called when a widget is "active" and the selection mode is Frame or FrameWithBackground. * Currently the size of the border is used, so it will replace the border with the frame. * * @param graphics A graphics object to draw with. * @see setSelectionMode, getSelectionMode, setSelectionColor, getSelectionColor */ virtual void drawSelectionFrame(Graphics* graphics); /** * Sets the size of the widget's outline. The outline is not considered as part of * the widget, it only allows a outline to be drawn around the widget, thus a outline * will never be included when calculating if a widget should receive events * from user input. Also a widget's outline will never be included when calculating * a widget's position. * * A outline size of 0 means that the widget has no outline. The default outline size * is 0. * * @param size The size of the widget's outline. * @see getOutlineSize, drawOutline */ void setOutlineSize(unsigned int size); /** * Gets the size of the widget's outline. The outline is not considered as part of * the widget, it only allows a outline to be drawn around the widget, thus a outline * will never be included when calculating if a widget should receive events * from user input. Also a widget's outline will never be included when calculating * a widget's position. * * A outline size of 0 means that the widget has no outline. The default outline size * is 0. * * @return The size of the widget's outline. * @see setOutlineSize, drawOutline */ unsigned int getOutlineSize() const; /** * Sets the size of the widget's border. The border is considered as part of * the widget. * * A border size of 0 means that the widget has no border. The default border size * is 0. * * @param size The size of the widget's border. * @see getBorderSize, drawBorder */ void setBorderSize(unsigned int size); /** * Gets the size of the widget's border. The border is considered as part of * the widget. * * A border size of 0 means that the widget has no border. The default border size * is 0. * * @return The size of the widget's border. * @see setBorderSize, drawBorder */ unsigned int getBorderSize() const; /** * Sets all 4 margins to one value. * The margin clears an area around an element (outside the border). * The margin does not have a background color, and is completely transparent. * It is also possible to use negative values, to overlap content. * @param margin The margin of the widget. * @see setMarginTop, setMarginRight, setMarginBottom, setMarginRight */ void setMargin(int margin); /** * Sets the top margin. * The margin clears an area around an element (outside the border). * The margin does not have a background color, and is completely transparent. * It is also possible to use negative values, to overlap content. * @param margin The top margin of the widget. * @see getMarginTop */ void setMarginTop(int margin); /** * Gets the top margin. * The margin clears an area around an element (outside the border). * The margin does not have a background color, and is completely transparent. * It is also possible to use negative values, to overlap content. * @return The top margin of the widget. * @see setMarginTop */ int getMarginTop() const; /** * Sets the right margin. * The margin clears an area around an element (outside the border). * The margin does not have a background color, and is completely transparent. * It is also possible to use negative values, to overlap content. * @param margin The right margin of the widget. * @see getMarginRight */ void setMarginRight(int margin); /** * Gets the right margin. * The margin clears an area around an element (outside the border). * The margin does not have a background color, and is completely transparent. * It is also possible to use negative values, to overlap content. * @return The right margin of the widget. * @see setMarginRight */ int getMarginRight() const; /** * Sets the bottom margin. * The margin clears an area around an element (outside the border). * The margin does not have a background color, and is completely transparent. * It is also possible to use negative values, to overlap content. * @param margin The bottom margin of the widget. * @see getMarginBottom */ void setMarginBottom(int margin); /** * Gets the bottom margin. * The margin clears an area around an element (outside the border). * The margin does not have a background color, and is completely transparent. * It is also possible to use negative values, to overlap content. * @return The bottom margin of the widget. * @see setMarginBottom */ int getMarginBottom() const; /** * Sets the left margin. * The margin clears an area around an element (outside the border). * The margin does not have a background color, and is completely transparent. * It is also possible to use negative values, to overlap content. * @param margin The left margin of the widget. * @see getMarginLeft */ void setMarginLeft(int margin); /** * Gets the left margin. * The margin clears an area around an element (outside the border). * The margin does not have a background color, and is completely transparent. * It is also possible to use negative values, to overlap content. * @return The left margin of the widget. * @see setMarginLeft */ int getMarginLeft() const; /** * Sets all 4 paddings to one value. * The padding clears an area around the content (inside the border) of * an element. The padding is affected by the background color of the element. * @param padding The top padding of the widget. * @see setPaddingTop, setPaddingRight, setPaddingBottom, setPaddingLeft */ void setPadding(unsigned int padding); /** * Sets the top padding. * The padding clears an area around the content (inside the border) of * an element. The padding is affected by the background color of the element. * @param padding The top padding of the widget. * @see getPaddingTop */ void setPaddingTop(unsigned int padding); /** * Gets the top padding. * The padding clears an area around the content (inside the border) of * an element. The padding is affected by the background color of the element. * @return The top padding of the widget. * @see setPaddingTop */ unsigned int getPaddingTop() const; /** * Sets the right padding. * The padding clears an area around the content (inside the border) of * an element. The padding is affected by the background color of the element. * @param padding The right padding of the widget. * @see getPaddingRight */ void setPaddingRight(unsigned int padding); /** * Gets the right padding. * The padding clears an area around the content (inside the border) of * an element. The padding is affected by the background color of the element. * @return The right padding of the widget. * @see setPaddingRight */ unsigned int getPaddingRight() const; /** * Sets the bottom padding. * The padding clears an area around the content (inside the border) of * an element. The padding is affected by the background color of the element. * @param padding The bottom padding of the widget. * @see getPaddingBottom */ void setPaddingBottom(unsigned int padding); /** * Gets the bottom padding. * The padding clears an area around the content (inside the border) of * an element. The padding is affected by the background color of the element. * @return The bottom padding of the widget. * @see setPaddingBottom */ unsigned int getPaddingBottom() const; /** * Sets the left padding. * The padding clears an area around the content (inside the border) of * an element. The padding is affected by the background color of the element. * @param padding The left padding of the widget. * @see getPaddingLeft */ void setPaddingLeft(unsigned int padding); /** * Gets the left padding. * The padding clears an area around the content (inside the border) of * an element. The padding is affected by the background color of the element. * @return The left padding of the widget. * @see setPaddingLeft */ unsigned int getPaddingLeft() const; /** * Called for all widgets in the gui each time Gui::logic is called. * You can do logic stuff here like playing an animation. * * @see Gui::logic */ virtual void logic() { } /** * Gets the widget's parent container. * * @return The widget's parent container. NULL if the widget * has no parent. */ virtual Widget* getParent() const; /** * Gets the top widget, or top parent, of this widget. * * @return The top widget, or top parent, for this widget. NULL if no top widget * exists (this widget doesn't have a parent). */ virtual Widget* getTop() const; /** * Sets the width of the widget. * * @param width The width of the widget. * @see getWidth, setHeight, getHeight, setSize, * setDimension, getDimension */ void setWidth(int width); /** * Gets the width of the widget. * * @return The width of the widget. * @see setWidth, setHeight, getHeight, setSize, * setDimension, getDimension */ int getWidth() const; /** * Sets the height of the widget. * * @param height The height of the widget. * @see getHeight, setWidth, getWidth, setSize, * setDimension, getDimension */ void setHeight(int height); /** * Gets the height of the widget. * * @return The height of the widget. * @see setHeight, setWidth, getWidth, setSize, * setDimension, getDimension */ int getHeight() const; /** * Sets the size of the widget. * * @param width The width of the widget. * @param height The height of the widget. * @see setWidth, setHeight, getWidth, getHeight, * setDimension, getDimension */ void setSize(int width, int height); /** * Sets the x coordinate of the widget. The coordinate is * relateive to the widget's parent. * * @param x The x coordinate of the widget. * @see getX, setY, getY, setPosition, setDimension, getDimension */ void setX(int x); /** * Gets the x coordinate of the widget. The coordinate is * relative to the widget's parent. * * @return The x coordinate of the widget. * @see setX, setY, getY, setPosition, setDimension, getDimension */ int getX() const; /** * Sets the y coordinate of the widget. The coordinate is * relative to the widget's parent. * * @param y The y coordinate of the widget. * @see setY, setX, getX, setPosition, setDimension, getDimension */ void setY(int y); /** * Gets the y coordinate of the widget. The coordinate is * relative to the widget's parent. * * @return The y coordinate of the widget. * @see setY, setX, getX, setPosition, setDimension, getDimension */ int getY() const; /** * Sets position of the widget. The position is relative * to the widget's parent. * * @param x The x coordinate of the widget. * @param y The y coordinate of the widget. * @see setX, getX, setY, getY, setDimension, getDimension */ void setPosition(int x, int y); /** * Sets the dimension of the widget. The dimension is * relative to the widget's parent. * * @param dimension The dimension of the widget. * @see getDimension, setX, getX, setY, getY, setPosition */ void setDimension(const Rectangle& dimension); /** * Gets the dimension of the widget. The dimension is * relative to the widget's parent. * * @return The dimension of the widget. * @see getDimension, setX, getX, setY, getY, setPosition */ const Rectangle& getDimension() const; /** * Gets how many childs the widget have. * * @return The children count of the widget. */ unsigned int getChildrenCount() const; /** * Gets how many visible childs the widget have. * * @return The visible children count of the widget. */ unsigned int getVisibleChildrenCount() const; /** * Sets the minimal dimension of the widget. * * @param size The minimal size of the widget. * @see getMinSize */ void setMinSize(const Size& size); /** * Gets the minimal dimension of the widget. * * @return The minimal size of the widget. * @see setMinSize */ const Size& getMinSize() const; /** * Sets the maximal dimension of the widget. * * @param size The maximal size of the widget. * @see getMaxSize */ void setMaxSize(const Size& size); /** * Gets the maximal dimension of the widget. * * @return The maximal size of the widget. * @see setMaxSize */ const Size& getMaxSize() const; /** * Sets the dimension of the widget to a fixed size. * To disable it, provide a size with negative values. * * @param size The fixed size of the widget. * @see getFixedSize, isFixedSize */ void setFixedSize(const Size& size); /** * Gets the fixed size of the widget. * * @return The fixed size of the widget. * @see setFixedSize, isFixedSize */ const Size& getFixedSize() const; /** * Gets if the widget use a fixed size. * * @return True if the widget use a fixed size, otherwise false. * @see setFixedSize, getFixedSize */ bool isFixedSize() const; /** * Sets the widget to be fosusable, or not. * * @param focusable True if the widget should be focusable, * false otherwise. * @see isFocusable */ void setFocusable(bool focusable); /** * Checks if a widget is focsable. * * @return True if the widget should be focusable, false otherwise. * @see setFocusable */ bool isFocusable() const; /** * Checks if the widget is focused. * * @return True if the widget is focused, false otherwise. */ virtual bool isFocused() const; /** * Sets the widget to enabled, or not. A disabled * widget will never recieve mouse or key events. * * @param enabled True if widget should be enabled, * false otherwise. * @see isEnabled */ void setEnabled(bool enabled); /** * Checks if the widget is enabled. A disabled * widget will never recieve mouse or key events. * * @return True if widget is enabled, false otherwise. * @see setEnabled */ bool isEnabled() const; /** * Sets the widget to be visible, or not. * * @param visible True if widget should be visible, false otherwise. * @see isVisible */ void setVisible(bool visible); /** * Checks if the widget is visible. * * @return True if widget is be visible, false otherwise. * @see setVisible */ bool isVisible() const; /** * Checks if the widget setting is visible. * * @return True if widget setting is be visible, false otherwise. */ bool isSetVisible() const; /** * Sets the base color of the widget. * * @param color The baseground color. * @see getBaseColor */ void setBaseColor(const Color& color); /** * Gets the base color. * * @return The base color. * @see setBaseColor */ const Color& getBaseColor() const; /** * Sets the foreground color. * * @param color The foreground color. * @see getForegroundColor */ void setForegroundColor(const Color& color); /** * Gets the foreground color. * * @see setForegroundColor */ const Color& getForegroundColor() const; /** * Sets the background color. * * @param color The background Color. * @see setBackgroundColor */ void setBackgroundColor(const Color& color); /** * Gets the background color. * * @see setBackgroundColor */ const Color& getBackgroundColor() const; /** * Sets the selection color. * * @param color The selection color. * @see getSelectionColor */ void setSelectionColor(const Color& color); /** * Gets the selection color. * * @return The selection color. * @see setSelectionColor */ const Color& getSelectionColor() const; /** * Sets the outline color. * * @param color The outline color. * @see getOutlineColor */ void setOutlineColor(const Color& color); /** * Gets the outline color. * * @return The outline color. * @see setOutlineColor */ const Color& getOutlineColor() const; /** * Sets the border color. * * @param color The border color. * @see getBorderColor */ void setBorderColor(const Color& color); /** * Gets the border color. * * @return The border color. * @see setBorderColor */ const Color& getBorderColor() const; /** * Sets the selection mode. * * @param mode The selection mode that is used when the widget is "active". * @see getSelectionMode */ void setSelectionMode(SelectionMode mode); /** * Gets the selection mode. * * @return The selection mode that is used when the widget is "active". * @see setSelectionMode */ SelectionMode getSelectionMode() const; /** * Requests focus for the widget. A widget will only recieve focus * if it is focusable. * */ virtual void requestFocus(); /** * Requests a move to the top in the parent widget. * */ virtual void requestMoveToTop(); /** * Requests a move to the bottom in the parent widget. * */ virtual void requestMoveToBottom(); /** * Called whenever a widget should draw itself. The function will * set up clip areas and call the draw function for this widget * and for all its children. * * WARNING: This function is used internally and should not * be called or overloaded unless you know what you * are doing. */ virtual void _draw(Graphics* graphics); /** * Called whenever a widget should perform logic. The function will * call the logic function for this widget and for all its children. * * WARNING: This function is used internally and should not * be called or overloaded unless you know what you * are doing. */ virtual void _logic(); /** * Sets the focus handler to be used. * * WARNING: This function is used internally and should not * be called or overloaded unless you know what you * are doing. * * @param focusHandler The focus handler to use. * @see _getFocusHandler */ virtual void _setFocusHandler(FocusHandler* focusHandler); /** * Gets the focus handler used. * * WARNING: This function is used internally and should not * be called or overloaded unless you know what you * are doing. * * @return The focus handler used. * @see _setFocusHandler */ virtual FocusHandler* _getFocusHandler(); /** * Adds an action listener to the widget. When an action event * is fired by the widget the action listeners of the widget * will get notified. * * @param actionListener The action listener to add. * @see removeActionListener */ void addActionListener(ActionListener* actionListener); /** * Removes an added action listener from the widget. * * @param actionListener The action listener to remove. * @see addActionListener */ void removeActionListener(ActionListener* actionListener); /** * Adds a death listener to the widget. When a death event is * fired by the widget the death listeners of the widget will * get notified. * * @param deathListener The death listener to add. * @see removeDeathListener */ void addDeathListener(DeathListener* deathListener); /** * Removes an added death listener from the widget. * * @param deathListener The death listener to remove. * @see addDeathListener */ void removeDeathListener(DeathListener* deathListener); /** * Adds a mouse listener to the widget. When a mouse event is * fired by the widget the mouse listeners of the widget will * get notified. * * @param mouseListener The mouse listener to add. * @see removeMouseListener */ void addMouseListener(MouseListener* mouseListener); /** * Removes an added mouse listener from the widget. * * @param mouseListener The mouse listener to remove. * @see addMouseListener */ void removeMouseListener(MouseListener* mouseListener); /** * Adds a key listener to the widget. When a key event is * fired by the widget the key listeners of the widget will * get notified. * * @param keyListener The key listener to add. * @see removeKeyListener */ void addKeyListener(KeyListener* keyListener); /** * Removes an added key listener from the widget. * * @param keyListener The key listener to remove. * @see addKeyListener */ void removeKeyListener(KeyListener* keyListener); /** * Adds a focus listener to the widget. When a focus event is * fired by the widget the key listeners of the widget will * get notified. * * @param focusListener The focus listener to add. * @see removeFocusListener */ void addFocusListener(FocusListener* focusListener); /** * Removes an added focus listener from the widget. * * @param focusListener The focus listener to remove. * @see addFocusListener */ void removeFocusListener(FocusListener* focusListener); /** * Adds a widget listener to the widget. When a widget event is * fired by the widget the key listeners of the widget will * get notified. * * @param widgetListener The widget listener to add. * @see removeWidgetListener */ void addWidgetListener(WidgetListener* widgetListener); /** * Removes an added widget listener from the widget. * * @param widgetListener The widget listener to remove. * @see addWidgetListener */ void removeWidgetListener(WidgetListener* widgetListener); /** * Sets the action event identifier of the widget. The identifier is * used to be able to identify which action has occured. * * NOTE: An action event identifier should not be used to identify a * certain widget but rather a certain event in your application. * Several widgets can have the same action event identifer. * * @param actionEventId The action event identifier. * @see getActionEventId */ void setActionEventId(const std::string& actionEventId); /** * Gets the action event identifier of the widget. * * @return The action event identifier of the widget. * @see setActionEventId */ const std::string& getActionEventId() const; /** * Gets the absolute position on the screen for the widget. * * @param x The absolute x coordinate will be stored in this parameter. * @param y The absolute y coordinate will be stored in this parameter. */ virtual void getAbsolutePosition(int& x, int& y) const; /** * Sets the parent of the widget. A parent must be a BasicContainer. * * WARNING: This function is used internally and should not * be called or overloaded unless you know what you * are doing. * * @param parent The parent of the widget. * @see getParent */ virtual void _setParent(Widget* parent); /** * Gets the font set for the widget. If no font has been set, * the global font will be returned. If no global font has been set, * the default font will be returend. * * @return The font set for the widget. * @see setFont, setGlobalFont */ Font *getFont() const; /** * Sets the global font to be used by default for all widgets. * * @param font The global font. * @see getGlobalFont */ static void setGlobalFont(Font* font); /** * Sets the font for the widget. If NULL is passed, the global font * will be used. * * @param font The font to set for the widget. * @see getFont */ void setFont(Font* font); /** * Called when the font has changed. If the change is global, * this function will only be called if the widget doesn't have a * font already set. * */ virtual void fontChanged() { } /** * Checks if a widget exists or not, that is if it still exists * an instance of the object. * * @param widget The widget to check. * @return True if an instance of the widget exists, false otherwise. */ static bool widgetExists(const Widget* widget); /** * Checks if tab in is enabled. Tab in means that you can set focus * to this widget by pressing the tab button. If tab in is disabled * then the focus handler will skip this widget and focus the next * in its focus order. * * @return True if tab in is enabled, false otherwise. * @see setTabInEnabled */ bool isTabInEnabled() const; /** * Sets tab in enabled, or not. Tab in means that you can set focus * to this widget by pressing the tab button. If tab in is disabled * then the FocusHandler will skip this widget and focus the next * in its focus order. * * @param enabled True if tab in should be enabled, false otherwise. * @see isTabInEnabled */ void setTabInEnabled(bool enabled); /** * Checks if tab out is enabled. Tab out means that you can lose * focus to this widget by pressing the tab button. If tab out is * disabled then the FocusHandler ignores tabbing and focus will * stay with this widget. * * @return True if tab out is enabled, false otherwise. * @see setTabOutEnabled */ bool isTabOutEnabled() const; /** * Sets tab out enabled. Tab out means that you can lose * focus to this widget by pressing the tab button. If tab out is * disabled then the FocusHandler ignores tabbing and focus will * stay with this widget. * * @param enabled True if tab out should be enabled, false otherwise. * @see isTabOutEnabled */ void setTabOutEnabled(bool enabled); /** * Checks if a widget is modal focusable. * * @return True if no other widget is modal focused, false otherwise. * @see requestModalFocus, releaseModalFocus */ virtual bool isModalFocusable() const; /** * Checks if a widget is modal mouse input focusable. * * @return True if no other widget is modal mouse input focused, false otherwise. * @see requestModalMouseInputFocus, releaseModalMouseInputFocus */ virtual bool isModalMouseInputFocusable() const; /** * Requests modal focus. When a widget has modal focus, only that * widget and it's children may recieve input. * * @throws Exception if another widget already has modal focus. * @see releaseModalFocus, isModalFocused */ virtual void requestModalFocus(); /** * Requests modal mouse input focus. When a widget has modal input focus * that widget will be the only widget receiving input even if the input * occurs outside of the widget and no matter what the input is. * * @throws Exception if another widget already has modal focus. * @see releaseModalMouseInputFocus, isModalMouseInputFocused */ virtual void requestModalMouseInputFocus(); /** * Releases modal focus. Modal focus will only be released if the * widget has modal focus. * * @see requestModalFocus, isModalFocused */ virtual void releaseModalFocus(); /** * Releases modal mouse input focus. Modal mouse input focus will only * be released if the widget has modal mouse input focus. * * @see requestModalMouseInputFocus, isModalMouseInputFocused */ virtual void releaseModalMouseInputFocus(); /** * Checks if the widget or it's parent has modal focus. * * @return True if the widget has modal focus, false otherwise. * @see requestModalFocus, releaseModalFocus */ virtual bool isModalFocused() const; /** * Checks if the widget or it's parent has modal mouse input focus. * * @return True if the widget has modal mouse input focus, false * otherwise. * @see requestModalMouseInputFocus, releaseModalMouseInputFocus */ virtual bool isModalMouseInputFocused() const; /** * Gets a widget at a certain position in the widget. * This function is used to decide which gets mouse input, * thus it can be overloaded to change that behaviour. * * NOTE: This always returns NULL if the widget is not * a container. * * @param x The x coordinate of the widget to get. * @param y The y coordinate of the widget to get. * @param exclude Widget to exclude from search, if NULL * no widgets get excluded. * @return The widget at the specified coodinate, NULL * if no widget is found. */ virtual Widget *getWidgetAt(int x, int y, Widget* exclude = NULL); /** * Gets all widgets inside a certain area of the widget. * * NOTE: This always returns an emtpy list if the widget is not * a container. * * @param area The area to check. * @param ignore If supplied, this widget will be ignored. * @return A list of widgets. An empty list if no widgets was found. */ virtual std::list getWidgetsIn(const Rectangle& area, Widget* ignore = NULL); /** * Gets the mouse listeners of the widget. * * @return The mouse listeners of the widget. */ virtual const std::list& _getMouseListeners(); /** * Gets the key listeners of the widget. * * @return The key listeners of the widget. */ virtual const std::list& _getKeyListeners(); /** * Gets the focus listeners of the widget. * * @return The focus listeners of the widget. */ virtual const std::list& _getFocusListeners(); /** * Gets the area of the widget occupied by the widget's children. * By default this method returns an empty rectangle as not all * widgets are containers. If you want to make a container this * method should return the area where the children resides. This * method is used when drawing children of a widget when computing * clip rectangles for the children. * * NOTE: The returned rectangle should be relative to the widget, * i.e a rectangle with x and y coordinate (0,0) and with * width and height the same as the widget will let the * children draw themselves in the whole widget. * * An example of a widget that overloads this method is ScrollArea. * A ScrollArea has a view of its contant and that view is the * children area. The size of a ScrollArea's children area might * vary depending on if the scroll bars of the ScrollArea is shown * or not. * * @return The area of the widget occupied by the widget's children. */ virtual Rectangle getChildrenArea(); /** * Gets the internal focus handler used. * * @return the internalFocusHandler used. If no internal focus handler * is used, NULL will be returned. * @see setInternalFocusHandler */ virtual FocusHandler* _getInternalFocusHandler(); /** * Sets the internal focus handler. An internal focus handler is * needed if both a widget in the widget and the widget itself * should be foucsed at the same time. * * @param focusHandler The internal focus handler to be used. * @see getInternalFocusHandler */ void setInternalFocusHandler(FocusHandler* internalFocusHandler); /** * Moves a widget to the top of this widget. The moved widget will be * drawn above all other widgets in this widget. * * This method is safe to call at any time. * * @param widget The widget to move to the top. * @see moveToBottom */ virtual void moveToTop(Widget* widget); /** * Moves a widget in this widget to the bottom of this widget. * The moved widget will be drawn below all other widgets in this widget. * * This method is safe to call at any time. * * @param widget The widget to move to the bottom. * @see moveToTop */ virtual void moveToBottom(Widget* widget); /** * Focuses the next widget in the widget. * * @see moveToBottom */ virtual void focusNext(); /** * Focuses the previous widget in the widget. * * @see moveToBottom */ virtual void focusPrevious(); /** * Tries to show a specific part of a widget by moving it. Used if the * widget should act as a container. * * @param widget The target widget. * @param area The area to show. */ virtual void showWidgetPart(Widget* widget, Rectangle area); /** * Sets an id of a widget. An id can be useful if a widget needs to be * identified in a container. For example, if widgets are created by an * XML document, a certain widget can be retrieved given that the widget * has an id. * * @param id The id to set to the widget. * @see getId, BasicContainer::findWidgetById */ void setId(const std::string& id); /** * Gets the id of a widget. An id can be useful if a widget needs to be * identified in a container. For example, if widgets are created by an * XML document, a certain widget can be retrieved given that the widget * has an id. * * @param id The id to set to the widget. * @see setId, BasicContainer::findWidgetById */ const std::string& getId() const; /** * Shows a certain part of a widget in the widget's parent. * Used when widgets want a specific part to be visible in * its parent. An example is a TextArea that wants a specific * part of its text to be visible when a TextArea is a child * of a ScrollArea. * * @param rectangle The rectangle to be shown. */ virtual void showPart(Rectangle rectangle); /** * Sets the visibility event handler to be used. * * WARNING: This function is used internally and should not * be called unless you know what you * are doing. * * FIXME We don't like the visibility handler being static * but we leave it as is for the moment, until we * come up a better solution. * * @param visibilityEventHandler The visibility event handler to be used. */ static void _setVisibilityEventHandler(VisibilityEventHandler* visibilityEventHandler); /** * Gets the visibility event handler of this widget. * * WARNING: This function is used internally and should not * be called unless you know what you * are doing. * * FIXME We don't like the visibility handler being static * but we leave it as is for the moment, until we * come up a better solution. */ static VisibilityEventHandler* _getVisibilityEventHandler(); static void _setGuiDeathListener(DeathListener* deathListener); static DeathListener* _getGuiDeathListener(); /** * Sets the widget to vertical expandable. * * @param expand True if the widget can be vertical expanded, otherwise false. * @see isVerticalExpand */ void setVerticalExpand(bool expand); /** * Gets if widget is vertical expandable. * * @return True if the widget can be vertical expanded, otherwise false. * @see setVerticalExpand */ bool isVerticalExpand() const; /** * Sets the widget to horizontal expandable. * * @param expand True if the widget can be horizontal expanded, otherwise false. * @see isHorizontalExpand */ void setHorizontalExpand(bool expand); /** * Gets if widget is horizontal expandable. * * @return True if the widget can be horizontal expanded, otherwise false. * @see setHorizontalExpand */ bool isHorizontalExpand() const; /** * Execute the layouting. * In case you want to relayout a visible widget. This function will * automatically perform the layout adaption from the widget. * * @param top If true the layout adaption starts from the top-most layouted widget. */ virtual void adaptLayout(bool top=true); /** * Resizes the widget's size to fit the content exactly, * calls recursively all childs. * * @param recursiv If true all child widgets also get the call. */ virtual void resizeToContent(bool recursiv=true) {} /** * Resizes the widget's size to fit the content exactly. */ virtual void adjustSize() {} /** * Expands the child widgets to the size of this widget, * calls recursively all childs. * * @param recursiv If true all child widgets also get the call. */ virtual void expandContent(bool recursiv=true) {} /** * Helper function to decide if we need to layout. */ virtual bool isLayouted() { return false; } void getLastPosition(int& x, int& y) const; void setLastPosition(int x, int y); bool isLastPositionSet() const; protected: /** * Distributes an action event to all action listeners * of the widget. * */ void distributeActionEvent(); /** * Distributes resized events to all of the widget's listeners. * */ void distributeResizedEvent(); /** * Distributes moved events to all of the widget's listeners. * */ void distributeMovedEvent(); /** * Distributes hidden events to all of the widget's listeners. * */ void distributeHiddenEvent(); /** * Distributes shown events to all of the widget's listeners. * */ void distributeShownEvent(); /** * Distributes ancestor moved events to all of the widget's listeners. * All children will also distribute the same event. * * @param ancestor Ancestor widget that was moved. */ void distributeAncestorMovedEvent(Widget* ancestor); /** * Distributes ancestor hidden events to all of the widget's listeners. * All children will also distribute the same event. * * @param ancestor Ancestor widget that was hidden. */ void distributeAncestorHiddenEvent(Widget* ancestor); /** * Distributes ancestor shown events to all of the widget's listeners. * All children will also distribute the same event. * * @param ancestor Ancestor widget that was shown. */ void distributeAncestorShownEvent(Widget* ancestor); /** * Adds a child to the widget. * * THIS METHOD IS NOT SAFE TO CALL INSIDE A WIDGETS LOGIC FUNCTION * INSIDE ANY LISTER FUNCTIONS! * * @param widget The widget to add. * @see remove, clear */ void add(Widget* widget); /** * Removes a child from the widget. * * THIS METHOD IS NOT SAFE TO CALL INSIDE A WIDGETS LOGIC FUNCTION * INSIDE ANY LISTER FUNCTIONS! * * @param widget The widget to remove. * @see add, clear */ virtual void remove(Widget* widget); /** * Clears the widget from all its children. * * THIS METHOD IS NOT SAFE TO CALL INSIDE A WIDGETS LOGIC FUNCTION * INSIDE ANY LISTER FUNCTIONS! * * @see remove, clear */ virtual void clear(); /** * Finds a widget given an id. This function can be useful * when implementing a GUI generator for Guichan, such as * the ability to create a Guichan GUI from an XML file. * * @param id The id to find a widget by. * @return The widget with the corrosponding id, * NULL of no widget is found. * */ virtual Widget* findWidgetById(const std::string& id); /** * Resizes the widget to fit it's children exactly. * */ void resizeToChildren(); /** * Checks the size against the size constraints. Used by setDimension. * */ void calculateSize(); /** * Gets the children of the widget. * * @return A list of the widgets children. */ const std::list& getChildren() const; /** * Holds the mouse listeners of the widget. */ std::list mMouseListeners; /** * Holds the key listeners of the widget. */ std::list mKeyListeners; /** * Holds the action listeners of the widget. */ std::list mActionListeners; /** * Holds the death listeners of the widget. */ std::list mDeathListeners; /** * Holds the focus listeners of the widget. */ std::list mFocusListeners; /** * Holds the widget listeners of the widget. */ std::list mWidgetListeners; /** * Holds the foreground color of the widget. */ Color mForegroundColor; /** * Holds the background color of the widget. */ Color mBackgroundColor; /** * Holds the base color of the widget. */ Color mBaseColor; /** * Holds the selection color of the widget. */ Color mSelectionColor; /** * Holds the outline color of the widget. */ Color mOutlineColor; /** * Holds the border color of the widget. */ Color mBorderColor; /** * Holds the focus handler used by the widget. */ FocusHandler* mFocusHandler; /** * Holds the focus handler used by the widget. NULL * if no internal focus handler is used. */ FocusHandler* mInternalFocusHandler; /** * Holds the parent of the widget. NULL if the widget * has no parent. */ Widget* mParent; /** * Holds the dimension of the widget. */ Rectangle mDimension; /** * Holds the offset dimension of the widget. */ Rectangle mOffsetRect; /** * Holds the outline size of the widget. */ unsigned int mOutlineSize; /** * Holds the border size of the widget. */ unsigned int mBorderSize; /** * Holds the selection mode. */ SelectionMode mSelectionMode; /** * Holds the top margin of the widget. */ int mMarginTop; /** * Holds the top right of the widget. */ int mMarginRight; /** * Holds the bottom margin of the widget. */ int mMarginBottom; /** * Holds the left margin of the widget. */ int mMarginLeft; /** * Holds the top padding of the widget. */ unsigned int mPaddingTop; /** * Holds the right padding of the widget. */ unsigned int mPaddingRight; /** * Holds the bottom padding of the widget. */ unsigned int mPaddingBottom; /** * Holds the left padding of the widget. */ unsigned int mPaddingLeft; /** * Holds the action event of the widget. */ std::string mActionEventId; /** * True if the widget focusable, false otherwise. */ bool mFocusable; /** * True if the widget visible, false otherwise. */ bool mVisible; /** * True if the widget has tab in enabled, false otherwise. */ bool mTabIn; /** * True if the widget has tab in enabled, false otherwise. */ bool mTabOut; /** * True if the widget is enabled, false otherwise. */ bool mEnabled; /** * Holds the id of the widget. */ std::string mId; /** * Holds the font used by the widget. */ Font* mCurrentFont; /** * Holds the min size. */ Size mMinSize; /** * Holds the min size. */ Size mMaxSize; /** * Holds the fixed size. */ Size mFixedSize; /** * True if the widget used a fixed size. */ bool mIsFixedSize; /** * True if the widget can be vertical expanded. */ bool mVExpand; /** * True if the widget can be horizontal expanded. */ bool mHExpand; /** * Holds the default font used by the widget. */ static DefaultFont mDefaultFont; /** * Holds the global font used by the widget. */ static Font* mGlobalFont; /** * Holds a list of all instances of widgets. */ static std::list mWidgetInstances; /** * Holds the visibility event handler used by the widgets. * * FIXME We don't like the visibility handler being static * but we leave it as is for the moment, until we * come up a better solution. */ static VisibilityEventHandler* mVisibilityEventHandler; static DeathListener* mGuiDeathListener; /** * Holds all children of the widget. */ std::list mChildren; int mLastX; int mLastY; }; } #endif // end FCN_WIDGET_HPP fifechan-0.1.5/include/fifechan/widgetlistener.hpp000066400000000000000000000137661341577075500222430ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_WIDGETLISTENER_HPP #define FCN_WIDGETLISTENER_HPP #include #include "fifechan/event.hpp" #include "fifechan/platform.hpp" namespace fcn { /** * Interface for listening for events from widgets. When a widget's size, * location or visibility changes, the relevant method of the listener is * invoked. * * @see Widget::addWidgetListener, Widget::removeWidgetListener * @author Olof Naessn */ class FCN_CORE_DECLSPEC WidgetListener { public: /** * Destructor. */ virtual ~WidgetListener() { } /** * Invoked when a widget changes its size. * * @param event Describes the event. */ virtual void widgetResized(const Event& event) { } /** * Invoked when a widget is moved. * * @param event Describes the event. */ virtual void widgetMoved(const Event& event) { } /** * Invoked when a widget is hidden, i.e it's set to be * not visible. * * @param event Describes the event. */ virtual void widgetHidden(const Event& event) { } /** * Invoked when a widget is shown, i.e it's set to be * visible. * * @param event Describes the event. */ virtual void widgetShown(const Event& event) { } /** * Invoked when an ancestor of a widget is moved. * * @Param event Describes the event. */ virtual void ancestorMoved(const Event& event) { } /** * Invoked when an ancestor of a widget is hidden, i.e its * set to be not visible. * * @param event Describes the event. */ virtual void ancestorHidden(const Event& event) { } /** * Invoked when an ancestor of a widget is shown, i.e its * set to be visible. * * @param event Describes the event. */ virtual void ancestorShown(const Event& event) { } protected: /** * Constructor. * * You should not be able to make an instance of WidgetListener, * therefore its constructor is protected. */ WidgetListener() { } }; } #endif // end FCN_WIDGETLISTENER_HPP fifechan-0.1.5/include/fifechan/widgets/000077500000000000000000000000001341577075500201325ustar00rootroot00000000000000fifechan-0.1.5/include/fifechan/widgets/adjustingcontainer.hpp000066400000000000000000000230361341577075500245420ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2007 - 2008 Josh Matthews and Olof Naessn * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_ADJUSTINGCONTAINER_HPP #define FCN_ADJUSTINGCONTAINER_HPP #include "fifechan/widgets/container.hpp" #include namespace fcn { /** * Self-adjusting Container class. AdjustingContainers are an easy way to * have Fifechan position a group of widgets for you. It organizes elements * in a table layout, with fixed columns and variable rows. The user specifies * * @verbitam *
    *
  • the number of columns
  • *
  • horizontal spacing between columns
  • *
  • vertical spacing between rows
  • *
  • padding around the sides of the container
  • *
  • each column's alignment
  • *
* @endverbitam * * These properties give the user a lot of flexibility to make the * widgets look just right. * @code * AdjustingContainer *adjust = new AdjustingContainer; * adjust->setPadding(5, 5, 5, 5); //left, right, top, bottom * adjust->setHorizontalSpacing(3); * adjust->setVerticalSpacing(3); * adjust->setColumns(3); * adjust->setColumnAlignment(0, AdjustingContainer::LEFT); * adjust->setColumnAlignment(1, AdjustingContainer::CENTER); * adjust->setColumnAlignment(2, AdjustingContainer::RIGHT); * top->add(adjust); * * for(int j = 0; j < 9; j++) * { * fcn::Label *l; * int r = rand() % 3; * if(r == 0) * l = new fcn::Label("Short"); * else if(r == 1) * l = new fcn::Label("A longer phrase"); * else * l = new fcn::Label("Extravagent and wordy text"); * adjust->add(l); * @endcode * * Output: * @verbitam *
     *+---------------------------------------------------------------------------+
     *|                                                                           |
     *| A longer phrase              Short             Extravagent and wordy text |
     *|                                                                           |
     *| Short             Extravagent and wordy text                        Short |
     *|                                                                           |
     *| Short                   A longer phrase                   A longer phrase |
     *|                                                                           |
     *+---------------------------------------------------------------------------+
     * 
* @endverbitam * As you can see, each column is only as big as its largest element. * The AdjustingContainer will resize itself and rearrange its contents * based on whatever widgets it contains, allowing dynamic addition and * removal while the program is running. It also plays nicely with ScrollAreas, * allowing you to show a fixed, maximum size while not limiting the actual * container. * * For more help with using AdjustingContainers, try the Guichan forums * (http://guichan.sourceforge.net/forum/) or email mrlachatte@gmail.com. * * @author Josh Matthews */ class FCN_CORE_DECLSPEC AdjustingContainer : public Container { public: /** * Constructor. */ AdjustingContainer(); /** * Destructor. */ virtual ~AdjustingContainer(); /** * Set the number of columns to divide the widgets into. * The number of rows is derived automatically from the number * of widgets based on the number of columns. Default column * alignment is left. * * @param numberOfColumns the number of columns. */ virtual void setNumberOfColumns(unsigned int numberOfColumns); /** * Get the number of columns the widget is divided. * The number of rows is derived automatically from the number * of widgets based on the number of columns. * * @return The number of columns. */ virtual unsigned int getNumberOfColumns() const; /** * Set a specific column's alignment. * * @param column the column number, starting from 0. * @param alignment the column's alignment. See enum with alignments. */ virtual void setColumnAlignment(unsigned int column, unsigned int alignment); /** * Get a specific column's alignment. * * @param column the column number, starting from 0. * @return The column's alignment. See enum with alignments. */ virtual unsigned int getColumnAlignment(unsigned int column) const; /** * Rearrange the widgets and resize the container. */ virtual void adjustContent(); // Inherited from Container virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); virtual void expandContent(bool recursiv=true); virtual Rectangle getChildrenArea(); //virtual void logic(); virtual void add(Widget *widget); virtual void add(Widget *widget, int x, int y); virtual void remove(Widget *widget); virtual void clear(); /** * Possible alignment values for each column. * * LEFT - Align content to the left of the column. * MIDDLE - Align content to the middle of the column. * RIGHT - Align content to the right of the column. */ enum { LEFT = 0, CENTER, RIGHT }; protected: std::vector mContainedWidgets; std::vector mColumnWidths; std::vector mColumnAlignment; std::vector mRowHeights; unsigned int mWidth; unsigned int mHeight; unsigned int mNumberOfColumns; unsigned int mNumberOfRows; }; } #endif fifechan-0.1.5/include/fifechan/widgets/bargraph.hpp000066400000000000000000000054361341577075500224410ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_BARGRAPH_HPP #define FCN_BARGRAPH_HPP #include "fifechan/point.hpp" #include "fifechan/widget.hpp" namespace fcn { class Graphics; class FCN_CORE_DECLSPEC BarGraph : public Widget { public: /** * Default constructor. */ BarGraph(); BarGraph(int x, int y, int w, int h); /** * Destructor. */ virtual ~BarGraph() { }; void setBarX(int x); int getBarX() const; void setBarY(int y); int getBarY() const; void setBarPosition(int x, int y); void setBarPosition(const Point& pos); void setBarWidth(int w); int getBarWidth() const; void setBarHeight(int h); int getBarHeight() const; void setBarSize(int w, int h); /** * Sets the opacity of the graph. * * @param opaque True if opaque, false otherwise. */ void setOpaque(bool opaque); /** * @return Whether this graph is opaque or not. */ bool isOpaque() const; /** * Draws this widget. */ virtual void draw(Graphics* graphics); protected: bool m_opaque; Rectangle m_rec; }; }; #endif //FCN_BARGRAPH_HPP fifechan-0.1.5/include/fifechan/widgets/button.hpp000066400000000000000000000226231341577075500221630ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_BUTTON_HPP #define FCN_BUTTON_HPP #include #include "fifechan/focuslistener.hpp" #include "fifechan/graphics.hpp" #include "fifechan/keylistener.hpp" #include "fifechan/mouseevent.hpp" #include "fifechan/mouselistener.hpp" #include "fifechan/platform.hpp" #include "fifechan/widget.hpp" #include "fifechan/widgetlistener.hpp" namespace fcn { /** * An implementation of a regular clickable button. A button is capable of * displaying a caption. * * If a button is clicked an action event will be sent to all action listener's * of the button. * * @see ImageButton */ class FCN_CORE_DECLSPEC Button : public Widget, public MouseListener, public KeyListener, public FocusListener, public WidgetListener { public: /** * Constructor. */ Button(); /** * Constructor. The button will be automatically resized * to fit the caption. * * @param caption The caption of the button. */ Button(const std::string& caption); /** * Destructor. */ virtual ~Button(); /** * Sets the caption of the button. * * @param caption The caption of the button. * @see getCaption, adjustSize */ void setCaption(const std::string& caption); /** * Gets the caption of the button. * * @return The caption of the button. */ const std::string& getCaption() const; /** * Sets the button state. * If the button is inactiv it looks gray. * * @param state True to activate the button or false to deactivate it. */ void setActive(bool state); /** * Returns the button state. * * @return True if the button is active otherwise false. */ bool isActive() const; /** * Sets the alignment of the caption. The alignment is relative * to the center of the button. * * @param alignment The alignment of the caption. * @see getAlignment, Graphics */ void setAlignment(Graphics::Alignment alignment); /** * Gets the alignment of the caption. * * @return The alignment of the caption. * @see setAlignment, Graphics */ Graphics::Alignment getAlignment() const; /** * Sets the number of pixels the image or text will be offset from * the top left corner of button when the button is pressed or toggled. * * @param offset The x offset. */ void setDownXOffset(int offset); /** * Gets the number of pixels the image or text will be offset. * * @return The x offset. */ int getDownXOffset() const; /** * Sets the number of pixels the image or text will be offset from * the top left corner of button when the button is pressed or toggled. * * @param offset The y offset. */ void setDownYOffset(int offset); /** * Gets the number of pixels the image or text will be offset. * * @return The y offset. */ int getDownYOffset() const; /** * Sets the number of pixels the image or text will be offset from * the top left corner of button when the button is pressed or toggled. * * @param x The x offset. * @param y The y offset. */ void setDownOffset(int x, int y); // Inherited from Widget virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); virtual void draw(Graphics* graphics); virtual void fontChanged(); // Inherited from FocusListener virtual void focusLost(const Event& event); // Inherited from MouseListener virtual void mousePressed(MouseEvent& mouseEvent); virtual void mouseReleased(MouseEvent& mouseEvent); virtual void mouseEntered(MouseEvent& mouseEvent); virtual void mouseExited(MouseEvent& mouseEvent); virtual void mouseDragged(MouseEvent& mouseEvent); // Inherited from KeyListener virtual void keyPressed(KeyEvent& keyEvent); virtual void keyReleased(KeyEvent& keyEvent); // Inherited from WidgetListener virtual void ancestorHidden(const Event& e); protected: /** * Checks if the button is pressed. Convenient method to use * when overloading the draw method of the button. * * @return True if the button is pressed, false otherwise. */ virtual bool isPressed() const; /** * Holds the caption of the button. */ std::string mCaption; /** * True if the mouse is ontop of the button, false otherwise. */ bool mHasMouse; /** * True if a key has been pressed, false otherwise. */ bool mKeyPressed; /** * True if a mouse has been pressed, false otherwise. */ bool mMousePressed; /** * True if the button is active. */ bool mState; /** * Holds the alignment of the caption. */ Graphics::Alignment mAlignment; /** * Holds the x down offset of the caption. */ int mXOffset; /** * Holds the y down offset of the caption. */ int mYOffset; }; } #endif // end FCN_BUTTON_HPP fifechan-0.1.5/include/fifechan/widgets/checkbox.hpp000066400000000000000000000222651341577075500224400ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CHECKBOX_HPP #define FCN_CHECKBOX_HPP #include #include "fifechan/platform.hpp" #include "fifechan/widgets/imagebutton.hpp" namespace fcn { class Image; /** * An implementation of a check box where a user can select or deselect * the check box and where the status of the check box is displayed to the user. * A check box is capable of displaying a caption. * * If a check box's state changes an action event will be sent to all action * listeners of the check box. */ class FCN_CORE_DECLSPEC CheckBox : public fcn::ImageButton { public: /** * Marker style. */ enum MarkerStyle { Marker_Checkmark = 0, Marker_Cross, Marker_Dot, Marker_Rhombus, Marker_Image }; /** * Contructor. */ CheckBox(); /** * Constructor. The check box will be automatically resized * to fit the caption. * * @param caption The caption of the check box. * @param marked True if the check box is selected, false otherwise. */ CheckBox(const std::string& caption, bool selected = false); /** * Destructor. */ virtual ~CheckBox(); /** * Checks if the check box is selected. * * @return True if the check box is selected, false otherwise. * @see setSelected */ virtual bool isSelected() const; /** * Sets the check box to be selected or not. * * @param selected True if the check box should be set as selected. * @see isSelected */ virtual void setSelected(bool selected); /** * Toggles the check box between being selected and * not being selected. It distribute a ActionEvent. */ virtual void toggleSelected(); /** * Sets the background image to display, that includes the caption region. * Existing Image is freed automatically, if it was loaded internally. * * @param filename The filename of the up image to display. */ void setBackgroundImage(const std::string& filename); /** * Sets the background image to display, that includes the caption region. * Existing Image is freed automatically, if it was loaded internally. * * @param image The up image to display. */ void setBackgroundImage(const Image* image); /** * Gets background image. * * @return The background image. */ const Image* getBackgroundImage() const; /** * Gets the marker mode of the check box. * @return The mode of the check box. * @see setMarkerStyle, MarkerStyle */ MarkerStyle getMarkerStyle() const; /** * Set the marker style of the check box. * @param mode The style of the check box. * @see getMarkerStyle, MarkerStyle */ void setMarkerStyle(MarkerStyle mode); // Inherited from Widget virtual void adjustSize(); virtual void draw(Graphics* graphics); // Inherited from KeyListener virtual void keyPressed(KeyEvent& keyEvent); virtual void keyReleased(KeyEvent& keyEvent); // Inherited from MouseListener virtual void mousePressed(MouseEvent& mouseEvent); virtual void mouseReleased(MouseEvent& mouseEvent); virtual void mouseClicked(MouseEvent& mouseEvent); protected: /** * Draws the box of the check box. * * @param graphics A Graphics object to draw with. */ virtual void drawBox(Graphics *graphics); /** * Draws the checkmark. * * @param graphics A Graphics object to draw with. * @param rec The rectangle that defines the position and size. */ void drawCheckmark(Graphics* graphics, const Rectangle& rec); /** * Draws the cross. * * @param graphics A Graphics object to draw with. * @param rec The rectangle that defines the position and size. */ void drawCross(Graphics* graphics, const Rectangle& rec); /** * Draws the dot. * * @param graphics A Graphics object to draw with. * @param rec The rectangle that defines the position and size. */ void drawDot(Graphics* graphics, const Rectangle& rec); /** * Draws the marker image. * * @param graphics A Graphics object to draw with. * @param rec The rectangle that defines the position and size. */ void drawMarkerImage(Graphics* graphics, const Rectangle& rec); /** * Draws the rhombus. Box, marker and selection. * * @param graphics A Graphics object to draw with. */ void drawRhombus(Graphics* graphics); /** * Holds the background image, that includes the caption region. */ const Image* mBackgroundImage; /** * True if the image has been loaded internally. */ bool mInternalBackgroundImage; /** * True if the check box is selected, false otherwise. */ bool mSelected; /** * Holds the marker style of the check box. */ MarkerStyle mMode; }; } #endif // end FCN_CHECKBOX_HPP fifechan-0.1.5/include/fifechan/widgets/container.hpp000066400000000000000000000271371341577075500226370ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_CONTAINER_HPP #define FCN_CONTAINER_HPP #include #include "fifechan/containerlistener.hpp" #include "fifechan/graphics.hpp" #include "fifechan/platform.hpp" #include "fifechan/widget.hpp" namespace fcn { /** * An implementation of a container able to contain other widgets. A widget's * position in the container is relative to the container itself and not the screen. * A container is the most common widget to use as the Gui's top widget as makes the Gui * able to contain more than one widget. * * @see Gui::setTop */ class FCN_CORE_DECLSPEC Container: public Widget { public: enum LayoutPolicy { Absolute, AutoSize, Vertical, Horizontal, Circular }; /** * Constructor. A container is opauqe as default, if you want a * none opaque container call setQpaque(false). * * @see setOpaque, isOpaque */ Container(); /** * Destructor. */ virtual ~Container(); /** * Sets the container to be opaque or not. If the container * is opaque its background will be drawn, if it's not opaque * its background will not be drawn, and thus making the container * completely transparent. * * NOTE: This is not the same as to set visibility. A non visible * container will not itself nor will it draw its content. * * @param opaque True if the container should be opaque, false otherwise. * @see isOpaque */ virtual void setOpaque(bool opaque); /** * Checks if the container is opaque or not. * * @return True if the container is opaque, false otherwise. * @see setOpaque */ virtual bool isOpaque() const; /** * Adds a widget to the container. * * @param widget The widget to add. * @see remove, clear */ virtual void add(Widget* widget); /** * Adds a widget to the container and also specifies the widget's * position in the container. The position is relative to the container * and not relative to the screen. * * @param widget The widget to add. * @param x The x coordinate for the widget. * @param y The y coordinate for the widget. * @see remove, clear */ virtual void add(Widget* widget, int x, int y); /** * Removes a widget from the Container. * * @param widget The widget to remove. * @throws Exception when the widget has not been added to the * container. * @see add, clear */ virtual void remove(Widget* widget); /** * Clears the container of all widgets. * * @see add, remove */ virtual void clear(); /** * Finds a widget given an id. * * @param id The id to find a widget by. * @return A widget with a corrosponding id, NULL if no widget * is found. * @see Widget::setId */ virtual Widget* findWidgetById(const std::string &id); /** * Adds a container listener to the container. When a widget is * added or removed an event will be sent to all container * listeners of the container * * @param containerListener The container listener to add. */ void addContainerListener(ContainerListener* containerListener); /** * Removes a container listener from the container. * * @param containerListener The container listener to remove. */ void removeContainerListener(ContainerListener* containerListener); /** * Returns the children of the container. * * @return The children of the container. */ const std::list& getChildren() const; // Inherited from Widget virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); virtual void expandContent(bool recursiv=true); virtual void draw(Graphics* graphics); virtual Rectangle getChildrenArea(); virtual bool isLayouted() { return mLayout != Absolute; }; /** * Sets the layout of the container. * @see LayoutPolicy * * @param policy The LayoutPolicy of the container. * @see getLayout */ virtual void setLayout(LayoutPolicy policy); /** * Gets the layout of the container. * @see LayoutPolicy * * @return The LayoutPolicy of the container. * @see setLayout */ virtual LayoutPolicy getLayout() const; /** * If enabled, the free space is distributed in a way that the size of the * childrens will be equal (if possible). * Otherwise the free space will evenly distributed. * * @param uniform Indicates if uniform size is enabled or not. * @see isUniformSize */ virtual void setUniformSize(bool uniform); /** * True if the container tries to expand the childs * to a uniform size. * * @return True if uniform size is set, otherwise false. * @see setUniformSize */ virtual bool isUniformSize() const; /** * Set the vertical spacing between rows. * * @param verticalSpacing spacing in pixels. * @see getVerticalSpacing */ virtual void setVerticalSpacing(unsigned int spacing); /** * Get the vertical spacing between rows. * * @return vertical spacing in pixels. * @see setVerticalSpacing */ virtual unsigned int getVerticalSpacing() const; /** * Set the horizontal spacing between columns. * * @param horizontalSpacing spacing in pixels. * @see getHorizontalSpacing */ virtual void setHorizontalSpacing(unsigned int spacing); /** * Get the horizontal spacing between rows. * * @return horizontal spacing in pixels. * @see setHorizontalSpacing */ virtual unsigned int getHorizontalSpacing() const; void setBackgroundWidget(Widget* widget); Widget* getBackgroundWidget(); protected: /** * Distributes a widget added container event to all container listeners * of the container. * * @param source The source widget of the event. */ void distributeWidgetAddedEvent(Widget* source); /** * Distributes a widget removed container event to all container listeners * of the container. * * @param source The source widget of the event. */ void distributeWidgetRemovedEvent(Widget* source); /** * True if the container is opaque, false otherwise. */ bool mOpaque; /** * Typdef. */ typedef std::list ContainerListenerList; /** * The container listeners of the container. */ ContainerListenerList mContainerListeners; /** * Typedef. */ typedef ContainerListenerList::iterator ContainerListenerIterator; /** * Layout */ LayoutPolicy mLayout; /** * Indicates if the childs should be expanded to a uniform size */ bool mUniform; /** * VerticalSpacing */ unsigned int mVerticalSpacing; /** * HorizontalSpacing */ unsigned int mHorizontalSpacing; Widget* mBackgroundWidget; }; } #endif // end FCN_CONTAINER_HPP fifechan-0.1.5/include/fifechan/widgets/curvegraph.hpp000066400000000000000000000063601341577075500230160ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_CURVEGRAPH_HPP #define FCN_CURVEGRAPH_HPP #include "fifechan/point.hpp" #include "fifechan/widget.hpp" namespace fcn { class Graphics; class FCN_CORE_DECLSPEC CurveGraph : public Widget { public: /** * Default constructor. */ CurveGraph(); CurveGraph(const PointVector& data); /** * Destructor. */ virtual ~CurveGraph() { }; void setPointVector(const PointVector& data); const PointVector& getPointVector() const; void resetPointVector(); void setThickness(unsigned int thickness); unsigned int getThickness() const; void setAutomaticControllPoints(bool acp); bool isAutomaticControllPoints() const; /** * Sets the opacity of the graph. * * @param opaque True if opaque, false otherwise. */ void setOpaque(bool opaque); /** * @return Whether this graph is opaque or not. */ bool isOpaque() const; /** * Draws this widget. */ virtual void draw(Graphics* graphics); protected: /** Precalculate bezier curve. */ void update(); /** Helper that returns an interpolated Point */ Point getBezierPoint(const PointVector& points, int elements, float t); /** Helper that adds the control points for bezier curves. */ void addControlPoints(const PointVector& points, PointVector& newPoints); bool m_opaque; bool m_acp; bool m_needUpdate; unsigned int m_thickness; PointVector m_data; PointVector m_curveData; }; }; #endif //FCN_CURVEGRAPH_HPP fifechan-0.1.5/include/fifechan/widgets/dropdown.hpp000066400000000000000000000264111341577075500225030ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_DROPDOWN_HPP #define FCN_DROPDOWN_HPP #include "fifechan/actionlistener.hpp" #include "fifechan/focushandler.hpp" #include "fifechan/focuslistener.hpp" #include "fifechan/keylistener.hpp" #include "fifechan/mouselistener.hpp" #include "fifechan/platform.hpp" #include "fifechan/selectionlistener.hpp" #include "fifechan/widget.hpp" namespace fcn { class ListBox; class ListModel; class ScrollArea; /** * An implementation of a drop downable list from which an item can be * selected. The drop down consists of an internal ScrollArea and an * internal ListBox. The drop down also uses an internal FocusHandler to * handle the focus of the internal ScollArea and the internal ListBox. The * scroll area and the list box can be passed to the drop down if a custom * scroll area and or a custom list box is preferable. * * To be able display a list the drop down uses a user provided list model. * A list model can be any class that implements the ListModel interface. * * If an item is selected in the drop down a select event will be sent to * all selection listeners of the drop down. If an item is selected by * using a mouse click or by using the enter or space key an action event * will be sent to all action listeners of the drop down. */ class FCN_CORE_DECLSPEC DropDown : public ActionListener, public KeyListener, public MouseListener, public FocusListener, public SelectionListener, public Widget { public: /** * Contructor. * * @param listModel the ListModel to use. * @param scrollArea the ScrollArea to use. * @param listBox the listBox to use. * @see ListModel, ScrollArea, ListBox. */ DropDown(ListModel *listModel = NULL, ScrollArea *scrollArea = NULL, ListBox *listBox = NULL); /** * Destructor. */ virtual ~DropDown(); /** * Gets the selected item as an index in the list model. * * @return the selected item as an index in the list model. * @see setSelected */ int getSelected() const; /** * Sets the selected item. The selected item is represented by * an index from the list model. * * @param selected the selected item as an index from the list model. * @see getSelected */ void setSelected(int selected); /** * Sets the list model to use when displaying the list. * * @param listModel the list model to use. * @see getListModel */ void setListModel(ListModel *listModel); /** * Gets the list model used. * * @return the ListModel used. * @see setListModel */ ListModel *getListModel() const; /** * Adjusts the height of the drop down to fit the height of the * drop down's parent's height. It's used to not make the drop down * draw itself outside of it's parent if folded down. */ void adjustHeight(); /** * Adds a selection listener to the drop down. When the selection * changes an event will be sent to all selection listeners of the * drop down. * * If you delete your selection listener, be sure to also remove it * using removeSelectionListener(). * * @param selectionListener the selection listener to add. */ void addSelectionListener(SelectionListener* selectionListener); /** * Removes a selection listener from the drop down. * * @param selectionListener the selection listener to remove. */ void removeSelectionListener(SelectionListener* selectionListener); // Inherited from Widget virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); virtual void draw(Graphics* graphics); void setBaseColor(const Color& color); void setBackgroundColor(const Color& color); void setForegroundColor(const Color& color); void setFont(Font *font); void setSelectionColor(const Color& color); // Inherited from BasicContainer virtual Rectangle getChildrenArea(); // Inherited from FocusListener virtual void focusLost(const Event& event); // Inherited from ActionListener virtual void action(const ActionEvent& actionEvent); // Inherited from DeathListener virtual void death(const Event& event); // Inherited from KeyListener virtual void keyPressed(KeyEvent& keyEvent); // Inherited from MouseListener virtual void mousePressed(MouseEvent& mouseEvent); virtual void mouseReleased(MouseEvent& mouseEvent); virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); virtual void mouseDragged(MouseEvent& mouseEvent); // Inherited from SelectionListener virtual void valueChanged(const SelectionEvent& event); protected: /** * Draws the button of the drop down. * * @param graphics a Graphics object to draw with. */ virtual void drawButton(Graphics *graphics); /** * Sets the drop down to be dropped down. */ virtual void dropDown(); /** * Sets the drop down to be folded up. */ virtual void foldUp(); /** * Distributes a value changed event to all selection listeners * of the drop down. * */ void distributeValueChangedEvent(); /** * True if the drop down is dropped down, false otherwise. */ bool mDroppedDown; /** * True if the drop down has been pushed with the mouse, false * otherwise. */ bool mPushed; /** * Holds what the height is if the drop down is folded up. Used when * checking if the list of the drop down was clicked or if the upper * part of the drop down was clicked on a mouse click. */ int mFoldedUpHeight; /** * The scroll area used. */ ScrollArea* mScrollArea; /** * The list box used. */ ListBox* mListBox; /** * The internal focus handler used to keep track of focus for the * internal list box. */ FocusHandler mInternalFocusHandler; /** * True if an internal scroll area is used, false if a scroll area * has been passed to the drop down which the drop down should not * deleted in it's destructor. */ bool mInternalScrollArea; /** * True if an internal list box is used, false if a list box * has been passed to the drop down which the drop down should not * deleted in it's destructor. */ bool mInternalListBox; /** * True if the drop down is dragged. */ bool mIsDragged; /** * Typedef. */ typedef std::list SelectionListenerList; /** * The selection listener's of the drop down. */ SelectionListenerList mSelectionListeners; /** * Typedef. */ typedef SelectionListenerList::iterator SelectionListenerIterator; }; } #endif // end FCN_DROPDOWN_HPP fifechan-0.1.5/include/fifechan/widgets/flowcontainer.hpp000066400000000000000000000071111341577075500235150ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_FLOWCONTAINER_HPP #define FCN_FLOWCONTAINER_HPP #include "fifechan/platform.hpp" #include "fifechan/widgets/container.hpp" namespace fcn { /** * An implementation of a flow container that can contain other widgets. * The widgets can be sorted vertical per row or horizontal per column. If the space in the container * is too small to put all the components in one row or column, it uses multiple rows or columns. */ class FCN_CORE_DECLSPEC FlowContainer : public Container { public: /** * Alignments for widgets. Useful if widgets with different sizes * are in the same row or column. For horizontal layout top, center * and bottom can be used, for vertical left, center and right. */ enum Alignment { Left = 0, Right, Top, Bottom, Center }; /** * Constructor. */ FlowContainer(); /** * Destructor. */ virtual ~FlowContainer(); /** * Sets the alignment of the widgets. * * @param alignemnt The alignment of the widgets. * @see getAlignment */ virtual void setAlignment(FlowContainer::Alignment alignment); /** * Gets the alignment of the widgets. * * @return The alignment of caption of the widgets. * @see setAlignmentm */ virtual FlowContainer::Alignment getAlignment() const; /** * Sets the size of the container and sorts the children. * If no size is set the parent or max size is used. * This is also used by resizeToContent() and expandContent(). */ virtual void adjustContent(); // Inherited from Container virtual void setLayout(Container::LayoutPolicy policy); virtual void resizeToContent(bool recursiv=true); virtual void expandContent(bool recursiv=true); protected: Alignment mAlignment; }; } #endif // end FCN_FLOWCONTAINER_HPP fifechan-0.1.5/include/fifechan/widgets/icon.hpp000066400000000000000000000154751341577075500216070ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_ICON_HPP #define FCN_ICON_HPP #include "fifechan/image.hpp" #include "fifechan/platform.hpp" #include "fifechan/widget.hpp" namespace fcn { /** * Implements an icon capable of displaying an image. */ class FCN_CORE_DECLSPEC Icon: public Widget { public: /** * Default constructor. */ Icon(); /** * Constructor. * * @param filename The filename of the image to display. */ Icon(const std::string& filename); /** * Constructor. * * @param image The image to display. */ Icon(const Image* image); /** * Descructor. */ virtual ~Icon(); /** * Sets the image to display. Existing image is freed automatically * if it was loaded internally. * * @param image The image to display. */ void setImage(const std::string& filename); /** * Sets the image to display. Existing image is freed automatically * if it was loaded internally. * * @param image The image to display. */ void setImage(const Image* image); /** * Gets the current image. * * @return The current image. */ const Image* getImage() const; /** * Sets if the image should be scaled to widget size. * * @param scale True if the image should be scaled. */ void setScaling(bool scale); /** * Gets if the image is scaled to widget size. * * @return True if the image is scaled to widget size, otherwise false. */ bool isScaling() const; /** * Sets if the image should be tiled to widget size. * * @param tile True if the image should be tiled. */ void setTiling(bool tile); /** * Gets if the image is tiled to widget size. * * @return True if the image is tiled to widget size, otherwise false. */ bool isTiling() const; /** * Sets the opacity of the background. * * @param opaque True if opaque, false otherwise. */ void setOpaque(bool opaque); /** * @return Whether this icons background is opaque or not. */ bool isOpaque() const; // Inherited from Widget virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); virtual void draw(Graphics* graphics); protected: /** * The image to display. */ const Image* mImage; /** * True if the image has been loaded internally, false otherwise. * An image not loaded internally should not be deleted in the * destructor. */ bool mInternalImage; // True if scaling is enabled, otherwise false. bool mScale; // True if tiling is enabled, otherwise false. bool mTile; // True if opaque, otherwise false. bool mOpaque; }; } #endif // end FCN_ICON_HPP fifechan-0.1.5/include/fifechan/widgets/iconprogressbar.hpp000066400000000000000000000134741341577075500240560ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_ICONPROGRESSBAR_HPP #define FCN_ICONPROGRESSBAR_HPP #include #include namespace fcn { class Graphics; class Image; class FCN_CORE_DECLSPEC IconProgressBar : public Widget { public: enum Orientation { HORIZONTAL = 0, VERTICAL }; /** * Default constructor. */ IconProgressBar(); /** * Constructor. The image passed is not owned by this object. * * @param image Image used by the progress bar's icons. * @param maxIcons Count of icons when the progress bar is full. */ IconProgressBar(Image* image, int maxIcons); /** * Constructor. The image indicated by filename is opened and it's * owned by this object. * * @param filename Filename of the image to be used by the progress bar's icons. * @param maxIcons Count of icons when the progress bar is full. */ IconProgressBar(const std::string& filename, int maxIcons); /** * Destructor. */ virtual ~IconProgressBar(); /** * Draws this IconProgressBar. */ virtual void draw(Graphics* graphics); /** * Sets the opacity of the IconProgressBar. * * @param opaque True if opaque, false otherwise. */ void setOpaque(bool opaque); /** * @return Whether this IconProgressBar is opaque or not. */ bool isOpaque() const; /** * Sets the IconProgressBar's image. The image passed is not owned by * this object. * * @param image Image used by the progress bar's icons. * @see setMaxIcons */ void setImage(Image* image); /** * @return The image used by this IconProgressBar. */ const Image* getImage() const; /** * Sets count of icons when the progress bar is full. * Also creates enough icons to represent that. * * @param maxIcons desired maximum count of icons. */ void setMaxIcons(int maxIcons); /** * @return Maximum count of icons for this IconProgressBar. */ int getMaxIcons() const; /** * Sets the IconProgressBar's orientation. * * @param orientation Desired orientation. */ void setOrientation(Orientation orientation); /** * @return Orientation of this IconProgressBar. */ Orientation getOrientation() const; /** * Advances the progress bar to use one more icon. If there can be no advancement * (maxIcons is reached), then the counter is reset to 0, useful if client wishes * to make the IconProgressBar looping. */ void advance(); /** * Resets the progress bar. */ void reset(); /** * Sets count of icons. * @param counter The count of the active icons. */ void setIconCount(int icons); /** * @return Current count of icons for this IconProgressBar. */ int getIconCount() const; // Inherited from Widget virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); protected: /** * Image used by the progress bar. */ const Image* mImage; /** * True if the image has been loaded internally, false otherwise. * An image not loaded internally should not be deleted in the * destructor. */ bool mInternalImage; /** * Count of icons when progress bar is full. */ int mMaxIcons; /** * Holds how many icons are currently displayed. */ int mIconCounter; /** * IconProgressBar's orientation. */ Orientation mOrientation; /** * True if the widget is opaque, false otherwise. */ bool mOpaque; }; }; #endif //FCN_ICONPROGRESSBAR_HPPfifechan-0.1.5/include/fifechan/widgets/imagebutton.hpp000066400000000000000000000254251341577075500231710ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_IMAGEBUTTON_HPP #define FCN_IMAGEBUTTON_HPP #include #include "fifechan/platform.hpp" #include "fifechan/widgets/button.hpp" namespace fcn { class Image; /** * An implementation of a regular clickable button. Unlike a normal button an image * button is capable of displaying images instead of only a simple text caption. * It is possible to define images for button up, down and hover. * Also the same 3 images for a inactive button so that it's possible to visualize the inactivity. * As minimum the button up image should be set. All other 5 images are optional. * Whenever an image button is clicked an action event will be sent to the action * listener's of the image button. * * @see Button */ class FCN_CORE_DECLSPEC ImageButton : public fcn::Button { public: /** * Default constructor. */ ImageButton(); /** * Constructor. * * @param filename The filename of the up image to display. */ ImageButton(const std::string& filename); /** * Constructor. * * @param image The up image to display. */ ImageButton(const Image* image); /** * Destructor. * Existing Images are freed automatically, if they were loaded internally. */ virtual ~ImageButton(); /** * Sets the up image to display. That is the basic image that is also used if other images are not set. * Existing Image is freed automatically, if it was loaded internally. * * @param filename The filename of the up image to display. */ void setUpImage(const std::string& filename); /** * Sets the up image to display. That is the basic image that is also used if other images are not set. * Existing Image is freed automatically, if it was loaded internally. * * @param image The up image to display. */ void setUpImage(const Image* image); /** * Gets current up image. * * @return The current up image. */ const Image* getUpImage() const; /** * Sets the down image to display. That is the image that is used if the button is pressed. * Existing Image is freed automatically, if it was loaded internally. * * @param filename The filename of the down image to display. */ void setDownImage(const std::string& filename); /** * Sets the down image to display. That is the image that is used if the button is pressed. * Existing Image is freed automatically, if it was loaded internally. * * @param image The down image to display. */ void setDownImage(const Image* image); /** * Gets current down image. * * @return The current down image. */ const Image* getDownImage() const; /** * Sets the hover image to display. That is the image that is used if the mouse is over the button. * Existing Image is freed automatically, if it was loaded internally. * * @param filename The filename of the hover image to display. */ void setHoverImage(const std::string& filename); /** * Sets the hover image to display. That is the image that is used if the mouse is over the button. * Existing Image is freed automatically, if it was loaded internally. * * @param image The hover image to display. */ void setHoverImage(const Image* image); /** * Gets current hover image. * * @return The current hover image. */ const Image* getHoverImage() const; /** * Sets the up image to display if the button is inactive. If not provided the active up image is used. * Existing Image is freed automatically, if it was loaded internally. * * @param filename The filename of the inactive up image to display. */ void setInactiveUpImage(const std::string& filename); /** * Sets the up image to display if the button is inactive. If not provided the active up image is used. * Existing Image is freed automatically, if it was loaded internally. * * @param image The inactive up image to display. */ void setInactiveUpImage(const Image* image); /** * Gets inactive up image. * * @return The inactive up image. */ const Image* getInactiveUpImage() const; /** * Sets the down image to display if the button is inactive. * Existing Image is freed automatically, if it was loaded internally. * * @param filename The filename of the inactive down image to display. */ void setInactiveDownImage(const std::string& filename); /** * Sets the down image to display if the button is inactive. * Existing Image is freed automatically, if it was loaded internally. * * @param image The inactive down image to display. */ void setInactiveDownImage(const Image* image); /** * Gets inactive down image. * * @return The inactive down image. */ const Image* getInactiveDownImage() const; /** * Sets the hover image to display if the button is inactive. * Existing Image is freed automatically, if it was loaded internally. * * @param filename The filename of the inactive hover image to display. */ void setInactiveHoverImage(const std::string& filename); /** * Sets the hover image to display if the button is inactive. * Existing Image is freed automatically, if it was loaded internally. * * @param image The inactive hover image to display. */ void setInactiveHoverImage(const Image* image); /** * Gets inactive hover image. * * @return The inactive hover image. */ const Image* getInactiveHoverImage() const; // Inherited from Widget virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); virtual void draw(fcn::Graphics* graphics); protected: // enum for easy image access enum ImageType { Image_Up = 0, Image_Down = 1, Image_Hover = 2, Image_Up_De = 3, Image_Down_De = 4, Image_Hover_De = 5 }; void setImage(const std::string& filename, ImageType type); void setImage(const Image* image, ImageType type); /** * The images to display. */ std::vector mImages; /** * True if the image has been loaded internally, false otherwise. * An image not loaded internally should not be deleted in the * destructor. */ std::vector mInternalImages; }; } #endif fifechan-0.1.5/include/fifechan/widgets/imageprogressbar.hpp000066400000000000000000000133671341577075500242110ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_IMAGEPROGRESSBAR_HPP #define FCN_IMAGEPROGRESSBAR_HPP #include #include namespace fcn { class Graphics; class Image; class FCN_CORE_DECLSPEC ImageProgressBar : public Widget { public: enum Orientation { HORIZONTAL = 0, VERTICAL }; /** * Default constructor. */ ImageProgressBar(); /** * Constructor. The image passed is not owned by this object. * * @param image Image used by the progress bar. * @param maxValue Value when the progress bar is full. */ ImageProgressBar(Image* image, int maxValue); /** * Constructor. The image indicated by filename is opened and it's * owned by this object. * * @param filename Filename of the image to be used by the progress bar. * @param maxValue Value when the progress bar is full. */ ImageProgressBar(const std::string& filename, int maxValue); /** * Destructor. */ virtual ~ImageProgressBar(); /** * Draws this ImageProgressBar. */ virtual void draw(Graphics* graphics); /** * Sets the opacity of the ImageProgressBar. * * @param opaque True if opaque, false otherwise. */ void setOpaque(bool opaque); /** * @return Whether this ImageProgressBar is opaque or not. */ bool isOpaque() const; /** * Sets the Bar image. The image passed is not owned by * this object. * * @param image Image used by the progress bar. */ void setBarImage(Image* image); /** * @return The image used by this Bar. */ const Image* getBarImage() const; /** * Sets the foreground image. The image passed is not owned by * this object. * * @param image Image used as overlay by the progress bar. */ void setForegroundImage(Image* image); /** * @return The image used as overlay by this Bar. */ const Image* getForegroundImage() const; /** * Sets the ImageProgressBar's orientation. * * @param orientation Desired orientation. */ void setOrientation(Orientation orientation); /** * @return Orientation of this ImageProgressBar. */ Orientation getOrientation() const; /** * Gets the max value of the bar * * @return The max value of the bar. */ int getMaxValue() const; /** * Sets the max value of the bar * * @param value The max value of the bar. */ void setMaxValue(int value); /** * Gets the value of the bar * * @return The value of the bar. */ int getValue() const; /** * Sets the value of the bar * * @param value In the range of 0-max. */ void setValue(int value); // Inherited from Widget virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); protected: /** * Bar image. */ const Image* mBarImage; /** * Foreground image. */ const Image* mForegroundImage; /** * True if the image has been loaded internally, false otherwise. * An image not loaded internally should not be deleted in the * destructor. */ bool mInternalImage; /** * Value when progress bar is full. */ int mMaxValue; /** * Holds the current progress bar value. */ int mValue; /** * ImageProgressBar's orientation. */ Orientation mOrientation; /** * True if the widget is opaque, false otherwise. */ bool mOpaque; }; }; #endif //FCN_IMAGEPROGRESSBAR_HPP fifechan-0.1.5/include/fifechan/widgets/label.hpp000066400000000000000000000135021341577075500217230ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_LABEL_HPP #define FCN_LABEL_HPP #include #include "fifechan/graphics.hpp" #include "fifechan/platform.hpp" #include "fifechan/widget.hpp" namespace fcn { /** * Implementation of a label capable of displaying a caption. */ class FCN_CORE_DECLSPEC Label: public Widget { public: /** * Constructor. */ Label(); /** * Constructor. The label will be automatically resized * to fit the caption. * * @param caption The caption of the label. */ Label(const std::string& caption); /** * Gets the caption of the label. * * @return The caption of the label. * @see setCaption */ const std::string &getCaption() const; /** * Sets the caption of the label. It's advisable to call * adjustSize after setting of the caption to adjust the * label's size to fit the caption. * * @param caption The caption of the label. * @see getCaption, adjustSize */ void setCaption(const std::string& caption); /** * Sets the alignment of the caption. The alignment is relative * to the center of the label. * * @param alignemnt The alignment of the caption of the label. * @see getAlignment, Graphics */ void setAlignment(Graphics::Alignment alignment); /** * Gets the alignment of the caption. The alignment is relative to * the center of the label. * * @return The alignment of caption of the label. * @see setAlignmentm Graphics */ Graphics::Alignment getAlignment() const; // Inherited from Widget virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); virtual void draw(Graphics* graphics); protected: /** * Holds the caption of the label. */ std::string mCaption; /** * Holds the alignment of the caption. */ Graphics::Alignment mAlignment; }; } #endif // end FCN_LABEL_HPP fifechan-0.1.5/include/fifechan/widgets/linegraph.hpp000066400000000000000000000052651341577075500226240ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_LINEGRAPH_HPP #define FCN_LINEGRAPH_HPP #include "fifechan/point.hpp" #include "fifechan/widget.hpp" namespace fcn { class Graphics; class FCN_CORE_DECLSPEC LineGraph : public Widget { public: /** * Default constructor. */ LineGraph(); LineGraph(const PointVector& data); /** * Destructor. */ virtual ~LineGraph() { }; void setPointVector(const PointVector& data); const PointVector& getPointVector() const; void resetPointVector(); void setThickness(unsigned int thickness); unsigned int getThickness() const; /** * Sets the opacity of the graph. * * @param opaque True if opaque, false otherwise. */ void setOpaque(bool opaque); /** * @return Whether this graph is opaque or not. */ bool isOpaque() const; /** * Draws this widget. */ virtual void draw(Graphics* graphics); protected: bool m_opaque; unsigned int m_thickness; PointVector m_data; }; }; #endif //FCN_LINEGRAPH_HPP fifechan-0.1.5/include/fifechan/widgets/listbox.hpp000066400000000000000000000223561341577075500223370ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_LISTBOX_HPP #define FCN_LISTBOX_HPP #include #include "fifechan/keylistener.hpp" #include "fifechan/listmodel.hpp" #include "fifechan/mouselistener.hpp" #include "fifechan/platform.hpp" #include "fifechan/widget.hpp" namespace fcn { class SelectionListener; /** * An implementation of a list box where an item can be selected. * * To be able display a list the list box uses a user provided list model. * A list model can be any class that implements the ListModel interface. * * If an item is selected in the list box a select event will be sent to * all selection listeners of the list box. If an item is selected by using * a mouse click or by using the enter or space key an action event will be * sent to all action listeners of the list box. */ class FCN_CORE_DECLSPEC ListBox : public Widget, public MouseListener, public KeyListener { public: /** * Constructor. */ ListBox(); /** * Constructor. * * @param listModel the list model to use. */ ListBox(ListModel *listModel); /** * Destructor. */ virtual ~ListBox() { } /** * Gets the selected item as an index in the list model. * * @return the selected item as an index in the list model. * @see setSelected */ int getSelected() const; /** * Sets the selected item. The selected item is represented by * an index from the list model. * * @param selected the selected item as an index from the list model. * @see getSelected */ void setSelected(int selected); /** * Sets the list model to use. * * @param listModel the list model to use. * @see getListModel */ void setListModel(ListModel *listModel); /** * Gets the list model used. * * @return the list model used. * @see setListModel */ ListModel *getListModel() const; /** * Checks whether the list box wraps when selecting items with a * keyboard. * * Wrapping means that the selection of items will be wrapped. That is, * if the first item is selected and up is pressed, the last item will * get selected. If the last item is selected and down is pressed, the * first item will get selected. * * @return true if wrapping is enabled, fasle otherwise. * @see setWrappingEnabled */ bool isWrappingEnabled() const; /** * Sets the list box to wrap or not when selecting items with a * keyboard. * * Wrapping means that the selection of items will be wrapped. That is, * if the first item is selected and up is pressed, the last item will * get selected. If the last item is selected and down is pressed, the * first item will get selected. * * @see isWrappingEnabled */ void setWrappingEnabled(bool wrappingEnabled); /** * Adds a selection listener to the list box. When the selection * changes an event will be sent to all selection listeners of the * list box. * * If you delete your selection listener, be sure to also remove it * using removeSelectionListener(). * * @param selectionListener The selection listener to add. */ void addSelectionListener(SelectionListener* selectionListener); /** * Removes a selection listener from the list box. * * @param selectionListener The selection listener to remove. */ void removeSelectionListener(SelectionListener* selectionListener); /** * Gets the height of a row. Should be overridden if another row * height than the font height is preferred. * * @return The height of a row. */ virtual unsigned int getRowHeight() const; // Inherited from Widget virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); virtual void draw(Graphics* graphics); virtual void logic(); // Inherited from KeyListener virtual void keyPressed(KeyEvent& keyEvent); // Inherited from MouseListener virtual void mousePressed(MouseEvent& mouseEvent); virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); virtual void mouseDragged(MouseEvent& mouseEvent); protected: /** * Distributes a value changed event to all selection listeners * of the list box. * */ void distributeValueChangedEvent(); /** * The selected item as an index in the list model. */ int mSelected; /** * The list model to use. */ ListModel *mListModel; /** * True if wrapping is enabled, false otherwise. */ bool mWrappingEnabled; /** * Typdef. */ typedef std::list SelectionListenerList; /** * The selection listeners of the list box. */ SelectionListenerList mSelectionListeners; /** * Typedef. */ typedef SelectionListenerList::iterator SelectionListenerIterator; }; } #endif // end FCN_LISTBOX_HPP fifechan-0.1.5/include/fifechan/widgets/passwordfield.hpp000066400000000000000000000053341341577075500235160ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_PASSWORDFIELD_HPP #define FCN_PASSWORDFIELD_HPP #include namespace fcn { class Text; /** * Password input widget. */ class FCN_CORE_DECLSPEC PasswordField : public TextField { public: /** * Constructor. * * @param text Initializes password field's text. */ PasswordField(const std::string& text = ""); ~PasswordField(); // Inherited from TextField virtual void keyPressed(KeyEvent& keyEvent); virtual void setText(const std::string& text); virtual std::string getText() const; private: /** * @return Caret position of the actual text. */ unsigned int getActualTextCaretPosition() const; /** * Sets the caret position of the actual text. */ void setActualTextCaretPosition(unsigned int position); /** * Holds the actual text of the password field. The standard text * will hold asterisks instead. */ Text* mActualText; }; }; #endif //FCN_PASSWORDFIELD_HPP fifechan-0.1.5/include/fifechan/widgets/piegraph.hpp000066400000000000000000000060121341577075500224410ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_PIEGRAPH_HPP #define FCN_PIEGRAPH_HPP #include "fifechan/point.hpp" #include "fifechan/widget.hpp" namespace fcn { class Graphics; class FCN_CORE_DECLSPEC PieGraph : public Widget { public: /** * Default constructor. */ PieGraph(); PieGraph(const Point& center); /** * Destructor. */ virtual ~PieGraph() { }; void setCenterX(int x); void setCenterY(int y); void setCenter(int x, int y); int getCenterX() const; int getCenterY() const; void setCenter(const Point& center); const Point& getCenter() const; void setRadius(int radius); int getRadius() const; void addSegment(int startAngle, int stopAngle, const Color& color); void clearSegments(); /** * Sets the opacity of the graph. * * @param opaque True if opaque, false otherwise. */ void setOpaque(bool opaque); /** * @return Whether this graph is opaque or not. */ bool isOpaque() const; /** * Draws this widget. */ virtual void draw(Graphics* graphics); protected: bool m_opaque; Point m_center; int m_radius; struct PieGraphSegment { int startAngle; int stopAngle; Color color; }; std::vector m_segments; }; }; #endif //FCN_PieGraph_HPP fifechan-0.1.5/include/fifechan/widgets/pointgraph.hpp000066400000000000000000000052741341577075500230260ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_POINTGRAPH_HPP #define FCN_POINTGRAPH_HPP #include "fifechan/point.hpp" #include "fifechan/widget.hpp" namespace fcn { class Graphics; class FCN_CORE_DECLSPEC PointGraph : public Widget { public: /** * Default constructor. */ PointGraph(); PointGraph(const PointVector& data); /** * Destructor. */ virtual ~PointGraph() { }; void setPointVector(const PointVector& data); const PointVector& getPointVector() const; void resetPointVector(); void setThickness(unsigned int thickness); unsigned int getThickness() const; /** * Sets the opacity of the graph. * * @param opaque True if opaque, false otherwise. */ void setOpaque(bool opaque); /** * @return Whether this graph is opaque or not. */ bool isOpaque() const; /** * Draws this widget. */ virtual void draw(Graphics* graphics); protected: bool m_opaque; unsigned int m_thickness; PointVector m_data; }; }; #endif //FCN_POINTGRAPH_HPP fifechan-0.1.5/include/fifechan/widgets/radiobutton.hpp000066400000000000000000000142671341577075500232070ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_RADIOBUTTON_HPP #define FCN_RADIOBUTTON_HPP #include #include #include "fifechan/platform.hpp" #include "fifechan/widgets/checkbox.hpp" namespace fcn { /** * An implementation of a radio button where a user can select or deselect * the radio button and where the status of the radio button is displayed to the user. * A radio button can belong to a group and when a radio button belongs to a * group only one radio button can be selected in the group. A radio button is * capable of displaying a caption. * * If a radio button's state changes an action event will be sent to all action * listeners of the radio button. */ class FCN_CORE_DECLSPEC RadioButton : public fcn::CheckBox { public: /** * Constructor. */ RadioButton(); /** * Constructor. The radio button will be automatically resized * to fit the caption. * * @param caption The caption of the radio button. * @param group The group the radio button should belong to. * @param selected True if the radio button should be selected. */ RadioButton(const std::string &caption, const std::string &group, bool selected = false); /** * Destructor. */ virtual ~RadioButton(); /** * Sets the group the radio button should belong to. Note that * a radio button group is unique per application, not per Gui object * as the group is stored in a static map. * * @param group The name of the group. * @see getGroup */ void setGroup(const std::string &group); /** * Gets the group the radio button belongs to. * * @return The group the radio button belongs to. * @see setGroup */ const std::string &getGroup() const; // Inherited from CheckBox virtual void setSelected(bool selected); virtual void toggleSelected(); protected: /** * Holds the group of the radio button. */ std::string mGroup; /** * Typdef. */ typedef std::multimap GroupMap; /** * Typdef. */ typedef GroupMap::iterator GroupIterator; /** * Holds all available radio button groups. */ static GroupMap mGroupMap; }; } #endif // end FCN_RADIOBUTTON_HPP fifechan-0.1.5/include/fifechan/widgets/scrollarea.hpp000066400000000000000000000451051341577075500227770ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_SCROLLAREA_HPP #define FCN_SCROLLAREA_HPP #include #include "fifechan/mouselistener.hpp" #include "fifechan/platform.hpp" #include "fifechan/widget.hpp" namespace fcn { /** * Implementation if a scrollable area used to view widgets larger than the scroll area. * A scroll area can be customized to always show scroll bars or to show them only when * necessary. */ class FCN_CORE_DECLSPEC ScrollArea: public MouseListener, public Widget { public: /** * Scrollpolicies for the horizontal and vertical scrollbar. * The policies are: * * SHOW_ALWAYS - Always show the scrollbars no matter what. * SHOW_NEVER - Never show the scrollbars no matter waht. * SHOW_AUTO - Show the scrollbars only when needed. That is if the * content grows larger then the ScrollArea. */ enum ScrollPolicy { ShowAlways = 0, ShowNever, ShowAuto }; /** * Constructor. */ ScrollArea(); /** * Constructor. * * @param content The content of the scroll area. */ ScrollArea(Widget *content); /** * Constructor. * * @param content The content of the scroll area. * @param hPolicy The policy for the horizontal scrollbar. See enum with * policies. * @param vPolicy The policy for the vertical scrollbar. See enum with * policies. */ ScrollArea(Widget *content, ScrollPolicy hPolicy, ScrollPolicy vPolicy); /** * Destructor. */ virtual ~ScrollArea(); /** * Sets the content. * * @param widget The content of the scroll area. */ void setContent(Widget* widget); /** * Gets the content. * * @return The content of the scroll area. */ Widget* getContent() const; /** * Sets the horizontal scrollbar policy. See enum with policies. * * @param hPolicy The policy for the horizontal scrollbar. * @see getHorizontalScrollPolicy */ void setHorizontalScrollPolicy(ScrollPolicy hPolicy); /** * Gets the horizontal scrollbar policy. See enum with policies. * * @return The policy for the horizontal scrollbar policy. * @see setHorizontalScrollPolicy, setScrollPolicy */ ScrollPolicy getHorizontalScrollPolicy() const; /** * Sets the vertical scrollbar policy. See enum with policies. * * @param vPolicy The policy for the vertical scrollbar. * @see getVerticalScrollPolicy */ void setVerticalScrollPolicy(ScrollPolicy vPolicy); /** * Gets the vertical scrollbar policy. See enum with policies. * * @return The policy for the vertical scrollbar. * @see setVerticalScrollPolicy, setScrollPolicy */ ScrollPolicy getVerticalScrollPolicy() const; /** * Sets the horizontal and vertical scrollbar policy. * * @param hPolicy The policy for the horizontal scrollbar. * @param vPolicy The policy for the vertical scrollbar. * @see getVerticalScrollPolicy, getHorizontalScrollPolicy */ void setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy); /** * Sets the amount to scroll vertically. * * @param vScroll The amount to scroll. * @see getVerticalScrollAmount */ void setVerticalScrollAmount(int vScroll); /** * Gets the amount that is scrolled vertically. * * @return The scroll amount on vertical scroll. * @see setVerticalScrollAmount, setScrollAmount */ int getVerticalScrollAmount() const; /** * Sets the amount to scroll horizontally. * * @param hScroll The amount to scroll. * @see getHorizontalScrollAmount */ void setHorizontalScrollAmount(int hScroll); /** * Gets the amount that is scrolled horizontally. * * @return The scroll amount on horizontal scroll. * @see setHorizontalScrollAmount, setScrollAmount */ int getHorizontalScrollAmount() const; /** * Sets the amount to scroll horizontally and vertically. * * @param hScroll The amount to scroll on horizontal scroll. * @param vScroll The amount to scroll on vertical scroll. * @see getHorizontalScrollAmount, getVerticalScrollAmount */ void setScrollAmount(int hScroll, int vScroll); /** * Gets the maximum amount of horizontal scroll. * * @return The horizontal max scroll. */ int getHorizontalMaxScroll(); /** * Gets the maximum amount of vertical scroll. * * @return The vertical max scroll. */ int getVerticalMaxScroll(); /** * Sets the width of the scroll bars. * * @param width The width of the scroll bars. * @see getScrollbarWidth */ void setScrollbarWidth(int width); /** * Gets the width of the scroll bars. * * @return the width of the ScrollBar. * @see setScrollbarWidth */ int getScrollbarWidth() const; /** * Sets the amount to scroll in pixels when the left scroll button is * pushed. * * @param amount The amount to scroll in pixels. * @see getLeftButtonScrollAmount */ void setLeftButtonScrollAmount(int amount); /** * Sets the amount to scroll in pixels when the right scroll button is * pushed. * * @param amount The amount to scroll in pixels. * @see getRightButtonScrollAmount */ void setRightButtonScrollAmount(int amount); /** * Sets the amount to scroll in pixels when the up scroll button is * pushed. * * @param amount The amount to scroll in pixels. * @see getUpButtonScrollAmount */ void setUpButtonScrollAmount(int amount); /** * Sets the amount to scroll in pixels when the down scroll button is * pushed. * * @param amount The amount to scroll in pixels. * @see getDownButtonScrollAmount */ void setDownButtonScrollAmount(int amount); /** * Gets the amount to scroll in pixels when the left scroll button is * pushed. * * @return The amount to scroll in pixels. * @see setLeftButtonScrollAmount */ int getLeftButtonScrollAmount() const; /** * Gets the amount to scroll in pixels when the right scroll button is * pushed. * * @return The amount to scroll in pixels. * @see setRightButtonScrollAmount */ int getRightButtonScrollAmount() const; /** * Gets the amount to scroll in pixels when the up scroll button is * pushed. * * @return The amount to scroll in pixels. * @see setUpButtonScrollAmount */ int getUpButtonScrollAmount() const; /** * Gets the amount to scroll in pixels when the down scroll button is * pushed. * * @return The amount to scroll in pixels. * @see setDownButtonScrollAmount */ int getDownButtonScrollAmount() const; /** * Sets the scroll area to be opaque, that is sets the scoll area * to display its background. * * @param opaque True if the scoll area should be opaque, false otherwise. */ void setOpaque(bool opaque); /** * Checks if the scroll area is opaque, that is if the scroll area * displays its background. * * @return True if the scroll area is opaque, false otherwise. */ bool isOpaque() const; // Inherited from BasicContainer virtual void showWidgetPart(Widget* widget, Rectangle area); virtual Rectangle getChildrenArea(); virtual Widget *getWidgetAt(int x, int y); // Inherited from Widget virtual void draw(Graphics *graphics); virtual void logic(); void setWidth(int width); void setHeight(int height); void setDimension(const Rectangle& dimension); virtual void resizeToContent(bool recursiv=true); virtual void adjustSize(); virtual void expandContent(bool recursiv=true); // Inherited from MouseListener virtual void mousePressed(MouseEvent& mouseEvent); virtual void mouseReleased(MouseEvent& mouseEvent); virtual void mouseDragged(MouseEvent& mouseEvent); virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); virtual void mouseWheelMovedRight(MouseEvent& mouseEvent); virtual void mouseWheelMovedLeft(MouseEvent& mouseEvent); protected: /** * Draws the background of the scroll area, that is * the area behind the content. * * @param graphics a Graphics object to draw with. */ virtual void drawBackground(Graphics *graphics); /** * Draws the up button. * * @param graphics a Graphics object to draw with. */ virtual void drawUpButton(Graphics *graphics); /** * Draws the down button. * * @param graphics a Graphics object to draw with. */ virtual void drawDownButton(Graphics *graphics); /** * Draws the left button. * * @param graphics a Graphics object to draw with. */ virtual void drawLeftButton(Graphics *graphics); /** * Draws the right button. * * @param graphics a Graphics object to draw with. */ virtual void drawRightButton(Graphics *graphics); /** * Draws the vertical scroll bar. * * @param graphics a Graphics object to draw with. */ virtual void drawVBar(Graphics* graphics); /** * Draws the horizontal scroll bar. * * @param graphics a Graphics object to draw with. */ virtual void drawHBar(Graphics* graphics); /** * Draws the vertical marker. * * @param graphics a Graphics object to draw with. */ virtual void drawVMarker(Graphics* graphics); /** * Draws the horizontal marker. * * @param graphics a Graphics object to draw with. */ virtual void drawHMarker(Graphics* graphics); /** * Checks the policies for the scroll bars. */ virtual void checkPolicies(); /** * Gets the up button dimension. * * @return the dimension of the up button. */ Rectangle getUpButtonDimension(); /** * Gets the down button dimension. * * @return the dimension of the down button. */ Rectangle getDownButtonDimension(); /** * Gets the left button dimension. * * @return the dimension of the left button. */ Rectangle getLeftButtonDimension(); /** * Gets the right button dimension. * * @return the dimension of the right button. */ Rectangle getRightButtonDimension(); /** * Gets the vertical scrollbar dimension. * * @return the dimension of the vertical scrollbar. */ Rectangle getVerticalBarDimension(); /** * Gets the horizontal scrollbar dimension. * * @return the dimension of the horizontal scrollbar. */ Rectangle getHorizontalBarDimension(); /** * Gets the vertical marker dimension. * * @return the dimension of the vertical marker. */ Rectangle getVerticalMarkerDimension(); /** * Gets the horizontal marker dimension. * * @return the dimension of the horizontal marker. */ Rectangle getHorizontalMarkerDimension(); /** * Holds the vertical scroll amount. */ int mVScroll; /** * Holds the horizontal scroll amount. */ int mHScroll; /** * Holds the width of the scroll bars. */ int mScrollbarWidth; /** * Holds the horizontal scroll bar policy. */ ScrollPolicy mHPolicy; /** * Holds the vertical scroll bar policy. */ ScrollPolicy mVPolicy; /** * True if the vertical scroll bar is visible, false otherwise. */ bool mVBarVisible; /** * True if the horizontal scroll bar is visible, false otherwise. */ bool mHBarVisible; /** * True if the up button is pressed, false otherwise. */ bool mUpButtonPressed; /** * True if the down button is pressed, false otherwise. */ bool mDownButtonPressed; /** * True if the left button is pressed, false otherwise. */ bool mLeftButtonPressed; /** * True if the right button is pressed, false otherwise. */ bool mRightButtonPressed; /** * Holds the up button scroll amount. */ int mUpButtonScrollAmount; /** * Holds the down button scroll amount. */ int mDownButtonScrollAmount; /** * Holds the left button scroll amount. */ int mLeftButtonScrollAmount; /** * Holds the right button scroll amount. */ int mRightButtonScrollAmount; /** * True if the vertical marked is dragged. */ bool mIsVerticalMarkerDragged; /** * True if the horizontal marked is dragged. */ bool mIsHorizontalMarkerDragged; /** * Holds the horizontal markers drag offset. */ int mHorizontalMarkerDragOffset; /** * Holds the vertical markers drag offset. */ int mVerticalMarkerDragOffset; /** * True if the scroll area should be opaque (that is * display its background), false otherwise. */ bool mOpaque; }; } #endif // end FCN_SCROLLAREA_HPP fifechan-0.1.5/include/fifechan/widgets/slider.hpp000066400000000000000000000246451341577075500221400ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_SLIDER_HPP #define FCN_SLIDER_HPP #include "fifechan/keylistener.hpp" #include "fifechan/mouselistener.hpp" #include "fifechan/platform.hpp" #include "fifechan/widget.hpp" namespace fcn { /** * An implementation of a slider where a user can select different values by * sliding between a start value and an end value of a scale. * * If the selected value is changed an action event will be sent to all * action listeners of the slider. */ class FCN_CORE_DECLSPEC Slider : public Widget, public MouseListener, public KeyListener { public: /** * Draw orientations for the slider. A slider can be drawn vertically or * horizontally. */ enum Orientation { Horizontal = 0, Vertical }; /** * Constructor. The default start value of the slider scale is zero. * * @param scaleEnd The end value of the slider scale. */ Slider(double scaleEnd = 1.0); /** * Constructor. * * @param scaleStart The start value of the slider scale. * @param scaleEnd The end value of the slider scale. */ Slider(double scaleStart, double scaleEnd); /** * Destructor. */ virtual ~Slider() { } /** * Sets the scale of the slider. * * @param scaleStart The start value of the scale. * @param scaleEnd tThe end of value the scale. * @see getScaleStart, getScaleEnd */ void setScale(double scaleStart, double scaleEnd); /** * Gets the start value of the scale. * * @return The start value of the scale. * @see setScaleStart, setScale */ double getScaleStart() const; /** * Sets the start value of the scale. * * @param scaleStart The start value of the scale. * @see getScaleStart */ void setScaleStart(double scaleStart); /** * Gets the end value of the scale. * * @return The end value of the scale. * @see setScaleEnd, setScale */ double getScaleEnd() const; /** * Sets the end value of the scale. * * @param scaleEnd The end value of the scale. * @see getScaleEnd */ void setScaleEnd(double scaleEnd); /** * Gets the current selected value. * * @return The current selected value. * @see setValue */ double getValue() const; /** * Sets the current selected value. * * @param value The current selected value. * @see getValue */ void setValue(double value); /** * Sets the length of the marker. * * @param length The length for the marker. * @see getMarkerLength */ void setMarkerLength(int length); /** * Gets the length of the marker. * * @return The length of the marker. * @see setMarkerLength */ int getMarkerLength() const; /** * Sets the orientation of the slider. A slider can be drawn vertically * or horizontally. * * @param orientation The orientation of the slider. * @see getOrientation */ void setOrientation(Orientation orientation); /** * Gets the orientation of the slider. A slider can be drawn vertically * or horizontally. * * @return The orientation of the slider. * @see setOrientation */ Orientation getOrientation() const; /** * Sets the step length. The step length is used when the keys LEFT * and RIGHT are pressed to step in the scale. * * @param length The step length. * @see getStepLength */ void setStepLength(double length); /** * Gets the step length. The step length is used when the keys LEFT * and RIGHT are pressed to step in the scale. * * @return the step length. * @see setStepLength */ double getStepLength() const; // Inherited from Widget virtual void draw(Graphics* graphics); // Inherited from MouseListener. virtual void mousePressed(MouseEvent& mouseEvent); virtual void mouseDragged(MouseEvent& mouseEvent); virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); virtual void mouseWheelMovedRight(MouseEvent& mouseEvent); virtual void mouseWheelMovedLeft(MouseEvent& mouseEvent); // Inherited from KeyListener virtual void keyPressed(KeyEvent& keyEvent); protected: /** * Draws the marker. * * @param graphics A graphics object to draw with. */ virtual void drawMarker(fcn::Graphics* graphics); /** * Converts a marker position to a value in the scale. * * @param position The position to convert. * @return A scale value corresponding to the position. * @see valueToMarkerPosition */ virtual double markerPositionToValue(int position) const; /** * Converts a value to a marker position. * * @param value The value to convert. * @return A marker position corresponding to the value. * @see markerPositionToValue */ virtual int valueToMarkerPosition(double value) const; /** * Gets the marker position of the current selected value. * * @return The marker position of the current selected value. */ virtual int getMarkerPosition() const; /** * True if the slider is dragged, false otherwise. */ bool mDragged; /** * Holds the current selected value. */ double mValue; /** * Holds the step length. The step length is used when the keys LEFT * and RIGHT are pressed to step in the scale. */ double mStepLength; /** * Holds the length of the marker. */ int mMarkerLength; /** * Holds the start value of the scale. */ double mScaleStart; /** * Holds the end value of the scale. */ double mScaleEnd; /** * Holds the orientation of the slider. A slider can be drawn * vertically or horizontally. */ Orientation mOrientation; }; } #endif // end FCN_SLIDER_HPP fifechan-0.1.5/include/fifechan/widgets/spacer.hpp000066400000000000000000000041551341577075500221250ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_SPACER_HPP #define FCN_SPACER_HPP #include "fifechan/widget.hpp" namespace fcn { class Graphics; class FCN_CORE_DECLSPEC Spacer : public Widget { public: /** * Initializes the spacer. */ Spacer(); ~Spacer(); // Inherited from Widget virtual void resizeToContent(bool recursiv=true); /** * Overrides this so that the spacer doesn't draw nothing. * * @param graphics A graphics object to draw with. */ virtual void draw(Graphics *graphics); }; }; #endif fifechan-0.1.5/include/fifechan/widgets/tab.hpp000066400000000000000000000126741341577075500214230ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_TAB_HPP #define FCN_TAB_HPP #include #include #include "fifechan/mouselistener.hpp" #include "fifechan/platform.hpp" #include "fifechan/widgets/container.hpp" namespace fcn { class TabbedArea; /** * An implementation of a simple tab to be used in a tabbed area. * * @see TabbedArea */ class FCN_CORE_DECLSPEC Tab: public MouseListener, public Container { public: /** * Constructor. */ Tab(); /** * Destructor. */ virtual ~Tab(); /** * Sets the tabbed area the tab should be a part of. * * @param tabbedArea The tabbed area the tab should be a part of. * @see getTabbedArea */ void setTabbedArea(TabbedArea* tabbedArea); /** * Gets the tabbed are the tab is a part of. * * @return The tabbed are the tab is a part of. * @see setTabbedArea */ TabbedArea* getTabbedArea(); // Inherited from Widget /** * Adjusts the size of the tab to fit the caption. If this tab was * added to a TabbedArea, it will also adjust the tab positions. */ virtual void adjustSize(); virtual Rectangle getChildrenArea(); virtual void draw(Graphics *graphics); // Inherited from MouseListener virtual void mouseEntered(MouseEvent& mouseEvent); virtual void mouseExited(MouseEvent& mouseEvent); protected: /** * True if the tab has the mouse, false otherwise. */ bool mHasMouse; /** * Holds the tabbed area the tab is a part of. */ TabbedArea* mTabbedArea; }; } #endif // end FCN_TABBEDAREA_HPP fifechan-0.1.5/include/fifechan/widgets/tabbedarea.hpp000066400000000000000000000273771341577075500227350ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_TABBEDAREA_HPP #define FCN_TABBEDAREA_HPP #include #include #include #include "fifechan/actionlistener.hpp" #include "fifechan/keylistener.hpp" #include "fifechan/mouselistener.hpp" #include "fifechan/platform.hpp" #include "fifechan/widget.hpp" #include "fifechan/widgets/container.hpp" namespace fcn { class Tab; /** * An implementation of a tabbed area where a user can display a widget by * selecting a tab. * */ class FCN_CORE_DECLSPEC TabbedArea: public ActionListener, public KeyListener, public MouseListener, public Widget { friend class Tab; public: /** * Constructor. */ TabbedArea(); /** * Destructor. */ virtual ~TabbedArea(); /** * Sets the tabbed area to be opaque or not. If the tabbed area is * opaque its background will be drawn, if it's not opaque its * background will not be drawn. By default, a tabbed area is not * opaque. * * The tabbed area's background is normally only visible behind the * tabs, since the container holding the tab contents is opaque by * default. * * @param opaque True if the tabbed area should be opaque, false * otherwise. * @see isOpaque */ void setOpaque(bool opaque); /** * Checks if the tabbed area is opaque or not. * * @return true if the tabbed area is opaque, false otherwise. * @see setOpaque */ bool isOpaque() const; /** * Adds a tab to the tabbed area. The tab will not be deleted by the * tabbed area when it is removed. * * @param tab The tab widget for the tab. * @param widget The widget to view when the tab is selected. * @see removeTab, removeTabWithIndex */ virtual void addTab(Tab* tab, Widget* widget); /** * Removes a tab from the tabbed area. * * @param index The index of the tab to remove. * @see addTab */ virtual void removeTabWithIndex(unsigned int index); /** * Removes a tab from the tabbed area. * * @param index The tab to remove. * @see addTab */ virtual void removeTab(Tab* tab); /** * Returns the number of tabs in this tabbed area. * */ int getNumberOfTabs() const; /** * Checks if a tab given an index is selected or not. * * @param index The index of the tab to check. * @return True if the tab is selected, false otherwise. * @see setSelectedTab */ virtual bool isTabSelected(unsigned int index) const; /** * Checks if a tab is selected or not. * * @param index The tab to check. * @return True if the tab is selected, false otherwise. * @see setSelectedTab */ virtual bool isTabSelected(Tab* tab) const; /** * Sets a tab given an index to be selected. * * @param index The index of the tab to be selected. * @see isTabSelected, getSelectedTab */ virtual void setSelectedTab(unsigned int index); /** * Sets a tab to be selected or not. * * @param index The tab to be selected. * @see isTabSelected, getSelectedTab */ virtual void setSelectedTab(Tab* tab); /** * Gets the index of the selected tab. * * @return The undex of the selected tab. * If no tab is selected -1 will be returned. * @see isTabSelected, setSelectedTab */ virtual int getSelectedTabIndex() const; /** * Gets the selected tab. * * @return The selected tab. * @see isTabSelected, setSelectedTab */ Tab* getSelectedTab() const; // Inherited from Widget virtual void resizeToContent(bool recursiv=true); virtual void expandContent(bool recursiv=true); /** * Adjusts the size of the tab container and the widget container. */ virtual void adjustSize(); virtual Rectangle getChildrenArea(); virtual void draw(Graphics *graphics); void setWidth(int width); void setHeight(int height); void setSize(int width, int height); void setDimension(const Rectangle& dimension); void setBaseColor(const Color& color); void setBackgroundWidget(Widget* widget); Widget* getBackgroundWidget(); /** * Sets the layout of the tabbedarea. * @see LayoutPolicy * * @param policy The LayoutPolicy of the tabbedarea. * @see getLayout */ void setLayout(Container::LayoutPolicy policy); /** * Gets the layout of the tabbedarea. * @see LayoutPolicy * * @return The LayoutPolicy of the tabbedarea. * @see setLayout */ Container::LayoutPolicy getLayout() const; /** * If enabled, the free space is distributed in a way that the size of the * childrens will be equal (if possible). * Otherwise the free space will evenly distributed. * * @param uniform Indicates if uniform size is enabled or not. * @see isUniformSize */ virtual void setUniformSize(bool uniform); /** * True if the tab container tries to expand the childs * to a uniform size. * * @return True if uniform size is set, otherwise false. * @see setUniformSize */ virtual bool isUniformSize() const; /** * Set the vertical spacing between rows. * * @param verticalSpacing spacing in pixels. * @see getVerticalSpacing */ virtual void setVerticalSpacing(unsigned int spacing); /** * Get the vertical spacing between rows. * * @return vertical spacing in pixels. * @see setVerticalSpacing */ virtual unsigned int getVerticalSpacing() const; /** * Set the horizontal spacing between columns. * * @param horizontalSpacing spacing in pixels. * @see getHorizontalSpacing */ virtual void setHorizontalSpacing(unsigned int spacing); /** * Get the horizontal spacing between rows. * * @return horizontal spacing in pixels. * @see setHorizontalSpacing */ virtual unsigned int getHorizontalSpacing() const; // Inherited from ActionListener void action(const ActionEvent& actionEvent); // Inherited from DeathListener virtual void death(const Event& event); // Inherited from KeyListener virtual void keyPressed(KeyEvent& keyEvent); // Inherited from MouseListener virtual void mousePressed(MouseEvent& mouseEvent); protected: /** * Adjusts the positions of the tabs. */ void adjustTabPositions(); /** * Holds the selected tab. */ Tab* mSelectedTab; /** * Holds the container for the tabs. */ Container* mTabContainer; /** * Holds the container for the widgets. */ Container* mWidgetContainer; /** * Holds a vector of tabs to delete in the destructor. * A tab that is to be deleted is a tab that has been * internally created by the tabbed area. */ std::vector mTabsToDelete; /** * A map between a tab and a widget to display when the * tab is selected. */ std::vector > mTabs; /** * True if the tabbed area is opaque, false otherwise. */ bool mOpaque; }; } #endif // end FCN_TABBEDAREA_HPP fifechan-0.1.5/include/fifechan/widgets/textbox.hpp000066400000000000000000000247541341577075500223540ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_TEXTBOX_HPP #define FCN_TEXTBOX_HPP #include #include #include #include "fifechan/keylistener.hpp" #include "fifechan/mouselistener.hpp" #include "fifechan/platform.hpp" #include "fifechan/widget.hpp" namespace fcn { class Text; class UTF8StringEditor; /** * An implementation of a text box where a user can enter text that contains of many lines. */ class FCN_CORE_DECLSPEC TextBox: public Widget, public MouseListener, public KeyListener { public: /** * Constructor. * * @param text The default text of the text box. */ TextBox(const std::string& text = ""); ~TextBox(); /** * Sets the text of the text box. * * @param text The text of the text box. * @see getText */ void setText(const std::string& text); /** * Gets the text of the text box. * * @return The text of the text box. * @see setText */ std::string getText() const; /** * Gets a certain row from the text. * * @param row The number of the row to get from the text. * @return A row from the text of the text box. * @see setTextRow */ std::string getTextRow(int row) const; /** * Sets the text of a certain row of the text. * * @param row The number of the row to set in the text. * @param text The text to set in the given row number. * @see getTextRow */ void setTextRow(int row, const std::string& text); /** * Gets the number of rows in the text. * * @return The number of rows in the text. */ unsigned int getNumberOfRows() const; /** * Gets the caret position in the text. * * @return The caret position in the text. * @see setCaretPosition */ unsigned int getCaretPosition() const; /** * Sets the position of the caret in the text. * * @param position the positon of the caret. * @see getCaretPosition */ void setCaretPosition(unsigned int position); /** * Gets the row number where the caret is currently located. * * @return The row number where the caret is currently located. * @see setCaretRow */ unsigned int getCaretRow() const; /** * Sets the row where the caret should be currently located. * * @param The row where the caret should be currently located. * @see getCaretRow */ void setCaretRow(int row); /** * Gets the column where the caret is currently located. * * @return The column where the caret is currently located. * @see setCaretColumn */ unsigned int getCaretColumn() const; /** * Sets the column where the caret should be currently located. * * @param The column where the caret should be currently located. * @see getCaretColumn */ void setCaretColumn(int column); /** * Sets the row and the column where the caret should be curretly * located. * * @param row The row where the caret should be currently located. * @param column The column where the caret should be currently located. * @see getCaretRow, getCaretColumn */ void setCaretRowColumn(int row, int column); /** * Scrolls the text to the caret if the text box is in a scroll area. * * @see ScrollArea */ virtual void scrollToCaret(); /** * Checks if the text box is editable. * * @return True it the text box is editable, false otherwise. * @see setEditable */ bool isEditable() const; /** * Sets the text box to be editable or not. * * @param editable True if the text box should be editable, false otherwise. */ void setEditable(bool editable); /** * Adds a row of text to the end of the text. * * @param row The row to add. */ virtual void addRow(const std::string &row); /** * Checks if the text box is opaque. An opaque text box will draw * it's background and it's text. A non opaque text box only draw it's * text making it transparent. * * @return True if the text box is opaque, false otherwise. * @see setOpaque */ bool isOpaque(); /** * Sets the text box to be opaque or not. An opaque text box will draw * it's background and it's text. A non opaque text box only draw it's * text making it transparent. * * @param opaque True if the text box should be opaque, false otherwise. * @see isOpaque */ void setOpaque(bool opaque); // Inherited from Widget virtual void draw(Graphics* graphics); virtual void fontChanged(); virtual void resizeToContent(bool recursiv=true); /** * Adjusts the text box's size to fit the text. */ virtual void adjustSize(); // Inherited from KeyListener virtual void keyPressed(KeyEvent& keyEvent); // Inherited from MouseListener virtual void mousePressed(MouseEvent& mouseEvent); virtual void mouseDragged(MouseEvent& mouseEvent); protected: /** * Sets caret column (UTF-8 aware). * @param column Caret column. */ void setCaretColumnUTF8(int column); /** * Sets caret row (UTF-8 aware). * @param row Caret row. */ void setCaretRowUTF8(int row); void setCaretRowColumnUTF8(int row, int column); /** * Draws the caret. Overloaded this method if you want to * change the style of the caret. * * @param graphics a Graphics object to draw with. * @param x the x position. * @param y the y position. */ virtual void drawCaret(Graphics* graphics, int x, int y); /** * Holds the text of the text box. */ Text* mText; /** * True if the text box is editable, false otherwise. */ bool mEditable; /** * True if the text box is editable, false otherwise. */ bool mOpaque; /** * UTF8StringEditor for UTF8 support. */ UTF8StringEditor* mStringEditor; }; } #endif // end FCN_TEXTBOX_HPP fifechan-0.1.5/include/fifechan/widgets/textfield.hpp000066400000000000000000000174731341577075500226470ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_TEXTFIELD_HPP #define FCN_TEXTFIELD_HPP #include "fifechan/keylistener.hpp" #include "fifechan/mouselistener.hpp" #include "fifechan/platform.hpp" #include "fifechan/widget.hpp" #include namespace fcn { class Text; class UTF8StringEditor; /** * An implementation of a text field where a user can enter a line of text. */ class FCN_CORE_DECLSPEC TextField: public Widget, public MouseListener, public KeyListener { public: /** * Constructor. */ TextField(); /** * Constructor. The text field will be automatically resized * to fit the text. * * @param text The default text of the text field. */ TextField(const std::string& text); /** * Destructor. */ ~TextField(); /** * Sets the text of the text field. * * @param text The text of the text field. * @see getText */ virtual void setText(const std::string& text); /** * Gets the text of the text field. * * @return The text of the text field. * @see setText */ virtual std::string getText() const; /** * Adjusts the height of the text field to fit caption. */ void adjustHeight(); /** * Checks if the text field is editable. * * @return True it the text field is editable, false otherwise. * @see setEditable */ bool isEditable() const; /** * Sets the text field to be editable or not. A text field is editable * by default. * * @param editable True if the text field should be editable, false * otherwise. */ void setEditable(bool editable); /** * Sets the caret position. As there is only one line of text * in a text field the position is the caret's x coordinate. * * @param position The caret position. * @see getCaretPosition */ void setCaretPosition(unsigned int position); /** * Gets the caret position. As there is only one line of text * in a text field the position is the caret's x coordinate. * * @return The caret position. * @see setCaretPosition */ unsigned int getCaretPosition() const; // Inherited from Widget virtual void resizeToContent(bool recursiv=true); /** * Adjusts the size of the text field to fit the text. */ virtual void adjustSize(); virtual void draw(Graphics* graphics); // Inherited from MouseListener virtual void mousePressed(MouseEvent& mouseEvent); virtual void mouseDragged(MouseEvent& mouseEvent); // Inherited from KeyListener virtual void keyPressed(KeyEvent& keyEvent); protected: /** * Draws the caret. Overloaded this method if you want to * change the style of the caret. * * @param graphics the Graphics object to draw with. * @param x the caret's x-position. */ virtual void drawCaret(Graphics* graphics, int x); /** * Scrolls the text horizontally so that the caret shows if needed. * The method is used any time a user types in the text field so the * caret always will be shown. */ void fixScroll(); /** * True if the text field is editable, false otherwise. */ bool mEditable; /** * Holds the text of the text field. */ Text* mText; /** * Holds the amount scrolled in x. If a user types more characters than * the text field can display, due to the text field being to small, the * text needs to scroll in order to show the last type character. */ int mXScroll; /** * String editor for UTF8 support. */ UTF8StringEditor* mStringEditor; }; } #endif // end FCN_TEXTFIELD_HPP fifechan-0.1.5/include/fifechan/widgets/togglebutton.hpp000066400000000000000000000114621341577075500233640ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef FCN_TOGGLEBUTTON_HPP #define FCN_TOGGLEBUTTON_HPP #include #include #include "fifechan/platform.hpp" #include "fifechan/widgets/imagebutton.hpp" namespace fcn { /** * An implementation of a toggleable button. * * If the button is in a group, all other buttons in that group will be untoggled * when a button gets toggled. If the button is already toggled, you can untoggle * it by clicking on it. * * If a toggle button's state changes an action event will be sent to all action * listeners of the toggle button. */ class FCN_CORE_DECLSPEC ToggleButton : public fcn::ImageButton { public: /** * Constructor. */ ToggleButton(); /** * Constructor. The toggle button will be automatically resized * to fit the caption. * * @param caption The caption of the toggle button. * @param group The group the toggle button should belong to. * @param selected True if the toggle button should be selected. */ ToggleButton(const std::string &caption, const std::string &group, bool selected = false); /** * Destructor. */ virtual ~ToggleButton(); /** * Checks if the check box is selected. * * @return True if the check box is selected, false otherwise. * @see setSelected */ virtual bool isSelected() const; /** * Sets the check box to be selected or not. * * @param selected True if the check box should be set as selected. * @see isSelected */ virtual void setSelected(bool selected); /** * Toggles the check box between being selected and * not being selected. It distribute a ActionEvent. */ virtual void toggleSelected(); /** * Sets the group the toggle button should belong to. Note that * a toggle button group is unique per application, not per Gui object * as the group is stored in a static map. * * @param group The name of the group. * @see getGroup */ void setGroup(const std::string &group); /** * Gets the group the toggle button belongs to. * * @return The group the toggle button belongs to. * @see setGroup */ const std::string &getGroup() const; // Inherited from KeyListener virtual void keyReleased(KeyEvent& keyEvent); // Inherited from MouseListener virtual void mouseReleased(MouseEvent& mouseEvent); protected: // Inherited from Button virtual bool isPressed() const; /** * True if the check box is selected, false otherwise. */ bool mSelected; /** * Holds the group of the toggle button. */ std::string mGroup; /** * Typdef. */ typedef std::multimap GroupMap; /** * Typdef. */ typedef GroupMap::iterator GroupIterator; /** * Holds all available toggle button groups. */ static GroupMap mGroupMap; }; } #endif // end FCN_TOGGLEBUTTON_HPP fifechan-0.1.5/include/fifechan/widgets/window.hpp000066400000000000000000000211001341577075500221440ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FCN_WINDOW_HPP #define FCN_WINDOW_HPP #include #include "fifechan/mouselistener.hpp" #include "fifechan/platform.hpp" #include "fifechan/widgets/container.hpp" namespace fcn { /** * An implementation of a movable window that can contain other widgets. */ class FCN_CORE_DECLSPEC Window : public Container, public MouseListener { public: /** * Constructor. */ Window(); /** * Constructor. The window will be automatically resized in height * to fit the caption. * * @param caption the caption of the window. */ Window(const std::string& caption); /** * Destructor. */ virtual ~Window(); /** * Sets the caption of the window. * * @param caption The caption of the window. * @see getCaption */ void setCaption(const std::string& caption); /** * Gets the caption of the window. * * @return the caption of the window. * @see setCaption */ const std::string& getCaption() const; /** * Sets the alignment of the caption. * * @param alignment The alignment of the caption. * @see getAlignment, Graphics */ void setAlignment(Graphics::Alignment alignment); /** * Gets the alignment of the caption. * * @return The alignment of caption. * @see setAlignment, Graphics */ Graphics::Alignment getAlignment() const; /** * Sets the title bar height. * * @param height The title height value. * @see getTitleBarHeight */ void setTitleBarHeight(unsigned int height); /** * Gets the title bar height. * * @return The title bar height. * @see setTitleBarHeight */ unsigned int getTitleBarHeight() const; void setInnerBorderSize(unsigned int border); unsigned int getInnerBorderSize() const; /** * Sets the window to be moveble or not. * * @param movable True if the window should be movable, false otherwise. * @see isMovable */ void setMovable(bool movable); /** * Checks if the window is movable. * * @return True if the window is movable, false otherwise. * @see setMovable */ bool isMovable() const; /** * Sets the window to be opaque or not. An opaque window will draw it's background * and it's content. A non opaque window will only draw it's content. * * @param opaque True if the window should be opaque, false otherwise. * @see isOpaque */ void setOpaque(bool opaque); /** * Checks if the window is opaque. * * @return True if the window is opaque, false otherwise. * @see setOpaque */ bool isOpaque() const; virtual void drawInnerBorder(Graphics* graphics); // Inherited from BasicContainer //virtual void resizeToContent(); virtual void adjustSize(); //virtual void expandContent(); virtual Rectangle getChildrenArea(); // Inherited from Widget virtual void draw(Graphics* graphics); // Inherited from MouseListener virtual void mousePressed(MouseEvent& mouseEvent); virtual void mouseDragged(MouseEvent& mouseEvent); virtual void mouseReleased(MouseEvent& mouseEvent); protected: /** * Holds the caption of the window. */ std::string mCaption; /** * Holds the alignment of the caption. */ Graphics::Alignment mAlignment; /** * Holds the title bar height of the window. */ unsigned int mTitleBarHeight; /** * Holds the size of the inner border. */ unsigned int mInnerBorder; /** * True if the window is movable, false otherwise. */ bool mMovable; /** * True if the window is opaque, false otherwise. */ bool mOpaque; /** * Holds a drag offset as an x coordinate where the drag of the window * started if the window is being dragged. It's used to move the window * correctly when dragged. */ int mDragOffsetX; /** * Holds a drag offset as an y coordinate where the drag of the window * started if the window is being dragged. It's used to move the window * correctly when dragged. */ int mDragOffsetY; /** * True if the window is being moved, false otherwise. */ bool mMoved; }; } #endif // end FCN_WINDOW_HPP fifechan-0.1.5/src/000077500000000000000000000000001341577075500140655ustar00rootroot00000000000000fifechan-0.1.5/src/actionevent.cpp000066400000000000000000000100341341577075500171060ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/actionevent.hpp" namespace fcn { ActionEvent::ActionEvent(Widget* source, const std::string& id) :Event(source), mId(id) { } ActionEvent::~ActionEvent() { } const std::string& ActionEvent::getId() const { return mId; } } fifechan-0.1.5/src/allegro/000077500000000000000000000000001341577075500155125ustar00rootroot00000000000000fifechan-0.1.5/src/allegro/allegro.cpp000066400000000000000000000074531341577075500176540ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/allegro.hpp" extern "C" { void fcnAllegro() { } } fifechan-0.1.5/src/allegro/allegrofont.cpp000066400000000000000000000127741341577075500205450ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "fifechan/allegro/allegrofont.hpp" #include "fifechan/allegro/allegrographics.hpp" #include "fifechan/exception.hpp" namespace fcn { AllegroFont::AllegroFont(FONT* font) :mAutoFree(false), mAllegroFont(font) { if (font == NULL) { throw FCN_EXCEPTION("Allegro font is not usable. Have you forgotten to load it?"); } } AllegroFont::AllegroFont(const std::string& filename) :mAutoFree(true), mAllegroFont(load_font(filename.c_str(), 0, 0)) { if (mAllegroFont == NULL) { throw FCN_EXCEPTION("Unable to load Allegro font from file."); } } AllegroFont::~AllegroFont() { if (mAutoFree) { if (mAllegroFont != NULL) { destroy_font(mAllegroFont); } mAllegroFont = NULL; } } int AllegroFont::getWidth(const std::string& text) const { return text_length(mAllegroFont, text.c_str()); } int AllegroFont::getHeight() const { return text_height(mAllegroFont); } void AllegroFont::drawString(fcn::Graphics* graphics, const std::string& text, int x, int y) { fcn::AllegroGraphics* const allegroGraphics = dynamic_cast(graphics); if (!allegroGraphics) { throw FCN_EXCEPTION("Graphics is not of type AllegroGraphics"); } BITMAP* const db = allegroGraphics->getTarget(); const fcn::ClipRectangle& rec = graphics->getCurrentClipArea(); textout_ex(db, mAllegroFont, text.c_str(), x + rec.x, y + rec.y, allegroGraphics->getAllegroColor(), -1); } } fifechan-0.1.5/src/allegro/allegrographics.cpp000066400000000000000000000265531341577075500213770ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/allegro/allegrographics.hpp" #include "fifechan/allegro/allegroimage.hpp" #include "fifechan/rectangle.hpp" #include "fifechan/exception.hpp" #include "fifechan/cliprectangle.hpp" #include "fifechan/color.hpp" namespace fcn { AllegroGraphics::AllegroGraphics() { mTarget = NULL; mClipNull = false; } AllegroGraphics::AllegroGraphics(BITMAP *target) { mTarget = target; } AllegroGraphics::~AllegroGraphics() { } void AllegroGraphics::setTarget(BITMAP *target) { mTarget = target; } BITMAP *AllegroGraphics::getTarget() { return mTarget; } void AllegroGraphics::_beginDraw() { if (mTarget == NULL) { throw FCN_EXCEPTION("Target BITMAP is null, set it with setTarget first."); } // push a clip area the size of the target bitmap pushClipArea(Rectangle(0, 0, mTarget->w, mTarget->h)); } void AllegroGraphics::_endDraw() { // pop the clip area pushed in _beginDraw popClipArea(); } bool AllegroGraphics::pushClipArea(Rectangle area) { bool result = Graphics::pushClipArea(area); const ClipRectangle& cr = mClipStack.top(); // Allegro won't let you set clip areas // that have zero width or height // so we have to check for that. if (cr.width == 0 || cr.height == 0) { mClipNull = true; } else { mClipNull = false; #if ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION == 0 set_clip(mTarget, cr.x, cr.y, cr.x + cr.width - 1, cr.y + cr.height - 1); #else set_clip_rect(mTarget, cr.x, cr.y, cr.x + cr.width - 1, cr.y + cr.height - 1); #endif } return result; } void AllegroGraphics::popClipArea() { Graphics::popClipArea(); if (mClipStack.empty()) { return; } const ClipRectangle& cr = mClipStack.top(); // Allegro won't let you set clip areas //that have zero width or height // so we have to check for that. if (cr.width == 0 || cr.height == 0) { mClipNull = true; } else { mClipNull = false; #if ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION == 0 set_clip(mTarget, cr.x, cr.y, cr.x + cr.width - 1, cr.y + cr.height - 1); #else set_clip_rect(mTarget, cr.x, cr.y, cr.x + cr.width - 1, cr.y + cr.height - 1); #endif } } void AllegroGraphics::drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height) { if (mClipNull) { return; } if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion " "outside of _beginDraw() and _endDraw()?"); } const int xOffset = mClipStack.top().xOffset; const int yOffset = mClipStack.top().yOffset; const AllegroImage* srcImage = dynamic_cast(image); if (srcImage == NULL) { throw FCN_EXCEPTION("Trying to draw an image of unknown format, must be an AllegroImage."); } masked_blit(srcImage->getBitmap(), mTarget, srcX, srcY, dstX + xOffset, dstY + yOffset, width, height); } void AllegroGraphics::drawPoint(int x, int y) { if (mClipNull) { return; } if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion " "outside of _beginDraw() and _endDraw()?"); } const int xOffset = mClipStack.top().xOffset; const int yOffset = mClipStack.top().yOffset; putpixel(mTarget, x + xOffset, y + yOffset, mAllegroColor); } void AllegroGraphics::drawLine(int x1, int y1, int x2, int y2) { if (mClipNull) { return; } if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion " "outside of _beginDraw() and _endDraw()?"); } const int xOffset = mClipStack.top().xOffset; const int yOffset = mClipStack.top().yOffset; line(mTarget, x1 + xOffset, y1 + yOffset, x2 + xOffset, y2 + yOffset, mAllegroColor); } void AllegroGraphics::drawRectangle(const Rectangle& rectangle) { if (mClipNull) { return; } if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion " "outside of _beginDraw() and _endDraw()?"); } const int xOffset = mClipStack.top().xOffset; const int yOffset = mClipStack.top().yOffset; rect(mTarget, rectangle.x + xOffset, rectangle.y + yOffset, rectangle.x + rectangle.width - 1 + xOffset, rectangle.y + rectangle.height - 1 + yOffset, mAllegroColor); } void AllegroGraphics::fillRectangle(const Rectangle& rectangle) { if (mClipNull) { return; } if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion " "outside of _beginDraw() and _endDraw()?"); } const int xOffset = mClipStack.top().xOffset; const int yOffset = mClipStack.top().yOffset; rectfill(mTarget, rectangle.x + xOffset, rectangle.y + yOffset, rectangle.x + rectangle.width - 1 + xOffset, rectangle.y + rectangle.height - 1 + yOffset, mAllegroColor); } void AllegroGraphics::setColor(const Color& color) { mColor = color; mAllegroColor = makecol(color.r, color.g, color.b); if (color.a != 255) { set_trans_blender(255, 255, 255, color.a); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); } else { solid_mode(); } } const Color& AllegroGraphics::getColor() const { return mColor; } int AllegroGraphics::getAllegroColor() const { return mAllegroColor; } void AllegroGraphics::drawBitmap(BITMAP* bitmap, int dstX, int dstY) { const int xOffset = mClipStack.top().xOffset; const int yOffset = mClipStack.top().yOffset; masked_blit(bitmap, mTarget, 0, 0, dstX + xOffset, dstY + yOffset, bitmap->w, bitmap->h); } } fifechan-0.1.5/src/allegro/allegroimage.cpp000066400000000000000000000131701341577075500206500ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/allegro/allegroimage.hpp" #include "fifechan/exception.hpp" namespace fcn { AllegroImage::AllegroImage(BITMAP* bitmap, bool autoFree) { mAutoFree = autoFree; mBitmap = bitmap; } AllegroImage::~AllegroImage() { if (mAutoFree) { free(); } } BITMAP* AllegroImage::getBitmap() const { return mBitmap; } void AllegroImage::free() { if (mBitmap) { destroy_bitmap(mBitmap); mBitmap = 0; } } int AllegroImage::getWidth() const { if (!mBitmap) { throw FCN_EXCEPTION("Trying to get the width of a non loaded image."); } return mBitmap->w; } int AllegroImage::getHeight() const { if (!mBitmap) { FCN_EXCEPTION("Trying to get the height of a non loaded image."); } return mBitmap->h; } Color AllegroImage::getPixel(int x, int y) { if (!mBitmap) { throw FCN_EXCEPTION("Trying to get a pixel from a non loaded image."); } int c = getpixel(mBitmap, x, y); return Color(getr32(c), getg32(c), getb32(c), geta(32)); } void AllegroImage::putPixel(int x, int y, const Color& color) { if (!mBitmap) { throw FCN_EXCEPTION("Trying to put a pixel in a non loaded image."); } int c = makeacol_depth(32, color.r, color.g, color.b, color.a); putpixel(mBitmap, x, y, c); } void AllegroImage::convertToDisplayFormat() { if (!mBitmap) { FCN_EXCEPTION("Trying to convert a non loaded image to display format."); } BITMAP *bmp = create_bitmap(mBitmap->w, mBitmap->h); blit(mBitmap, bmp, 0, 0, 0, 0, bmp->w, bmp->h); destroy_bitmap(mBitmap); mBitmap = bmp; } } fifechan-0.1.5/src/allegro/allegroimageloader.cpp000066400000000000000000000121241341577075500220350ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/allegro/allegroimageloader.hpp" #include "fifechan/allegro/allegroimage.hpp" #include "fifechan/exception.hpp" namespace fcn { Image* AllegroImageLoader::load(const std::string& filename, bool convertToDisplayFormat) { #if !(ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION == 0) int colconv = get_color_conversion(); #endif set_color_conversion(COLORCONV_NONE); PALETTE pal; BITMAP *bmp = loadBitmap(filename, pal); if (bmp == NULL) { throw FCN_EXCEPTION(std::string("Unable to load: ") + filename); } BITMAP *bmp2 = create_bitmap_ex(32, bmp->w, bmp->h); if (bmp2 == NULL) { throw FCN_EXCEPTION(std::string("Not enough memory to load: ") + filename); } set_palette(pal); blit(bmp, bmp2, 0, 0, 0, 0, bmp->w, bmp->h); destroy_bitmap(bmp); #if (ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION == 0) set_color_conversion(COLORCONV_TOTAL); #else set_color_conversion(colconv); #endif Image *image = new AllegroImage(bmp2, true); if (convertToDisplayFormat) { image->convertToDisplayFormat(); } return image; } BITMAP* AllegroImageLoader::loadBitmap(const std::string& filename, PALETTE pal) { return load_bitmap(filename.c_str(), pal); } } fifechan-0.1.5/src/allegro/allegroinput.cpp000066400000000000000000000374031341577075500207320ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/allegro/allegroinput.hpp" #include #include "fifechan/exception.hpp" namespace fcn { AllegroInput::AllegroInput() { mMouseButton1 = mMouseButton2 = mMouseButton3 = false; mLastMouseZ = 0; mLastMouseX = 0; mLastMouseY = 0; } bool AllegroInput::isKeyQueueEmpty() { return mKeyQueue.empty(); } KeyInput AllegroInput::dequeueKeyInput() { if (isKeyQueueEmpty()) { throw FCN_EXCEPTION("Key queue is empty."); } KeyInput ki = mKeyQueue.front(); mKeyQueue.pop(); return ki; } bool AllegroInput::isMouseQueueEmpty() { return mMouseQueue.empty(); } MouseInput AllegroInput::dequeueMouseInput() { if (isMouseQueueEmpty()) { throw FCN_EXCEPTION("Mouse queue is empty."); } MouseInput mi = mMouseQueue.front(); mMouseQueue.pop(); return mi; } void AllegroInput::_pollInput() { pollMouseInput(); pollKeyInput(); } void AllegroInput::pollMouseInput() { if (mouse_needs_poll()) { poll_mouse(); } int mouseX = mouse_x; int mouseY = mouse_y; int mouseZ = mouse_z; int mouseB1 = mouse_b & 1; int mouseB2 = mouse_b & 2; int mouseB3 = mouse_b & 4; // Check mouse movement if (mouseX != mLastMouseX || mouseY != mLastMouseY) { mMouseQueue.push(MouseInput(MouseInput::Empty, MouseInput::Moved, mouseX, mouseY, 0)); mLastMouseX = mouseX; mLastMouseY = mouseY; } // Check mouse Wheel while (mLastMouseZ < mouseZ) { mMouseQueue.push(MouseInput(MouseInput::Empty, MouseInput::WheelMovedUp, mouseX, mouseY, 0)); mLastMouseZ++; } while (mLastMouseZ > mouseZ) { mMouseQueue.push(MouseInput(MouseInput::Empty, MouseInput::WheelMovedDown, mouseX, mouseY, 0)); mLastMouseZ--; } // Check mouse buttons if (!mMouseButton1 && mouseB1) { mMouseQueue.push(MouseInput(MouseInput::Left, MouseInput::Pressed, mouseX, mouseY, 0)); } if (mMouseButton1 && !mouseB1) { mMouseQueue.push(MouseInput(MouseInput::Left, MouseInput::Released, mouseX, mouseY, 0)); } if (!mMouseButton2 && mouseB2) { mMouseQueue.push(MouseInput(MouseInput::Right, MouseInput::Pressed, mouseX, mouseY, 0)); } if (mMouseButton2 && !mouseB2) { mMouseQueue.push(MouseInput(MouseInput::Right, MouseInput::Released, mouseX, mouseY, 0)); } if (!mMouseButton3 && mouseB3) { mMouseQueue.push(MouseInput(MouseInput::Middle, MouseInput::Pressed, mouseX, mouseY, 0)); } if (mMouseButton3 && !mouseB3) { mMouseQueue.push(MouseInput(MouseInput::Middle, MouseInput::Released, mouseX, mouseY, 0)); } mMouseButton1 = mouseB1; mMouseButton2 = mouseB2; mMouseButton3 = mouseB3; } void AllegroInput::pollKeyInput() { int unicode, scancode; if (keyboard_needs_poll()) { poll_keyboard(); } while (keypressed()) { unicode = ureadkey(&scancode); Key keyObj = convertToKey(scancode, unicode); KeyInput keyInput(keyObj, KeyInput::Pressed); keyInput.setNumericPad(isNumericPad(scancode)); keyInput.setShiftPressed(key_shifts & KB_SHIFT_FLAG); keyInput.setAltPressed(key_shifts & KB_ALT_FLAG); keyInput.setControlPressed(key_shifts & KB_CTRL_FLAG); #ifdef KB_COMMAND_FLAG keyInput.setMetaPressed(key_shifts & (KB_COMMAND_FLAG | KB_LWIN_FLAG | KB_RWIN_FLAG)); #else keyInput.setMetaPressed(key_shifts & (KB_LWIN_FLAG | KB_RWIN_FLAG)); #endif mKeyQueue.push(keyInput); mPressedKeys[scancode] = keyInput; } if (key[KEY_ALT] && mPressedKeys.find(KEY_ALT) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_ALT, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_ALT] = keyInput; } if (key[KEY_ALTGR] && mPressedKeys.find(KEY_ALTGR) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_ALTGR, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_ALTGR] = keyInput; } if (key[KEY_LSHIFT] && mPressedKeys.find(KEY_LSHIFT) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_LSHIFT, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_LSHIFT] = keyInput; } if (key[KEY_RSHIFT] && mPressedKeys.find(KEY_RSHIFT) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_RSHIFT, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_RSHIFT] = keyInput; } if (key[KEY_LCONTROL] && mPressedKeys.find(KEY_LCONTROL) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_LCONTROL, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_LCONTROL] = keyInput; } if (key[KEY_RCONTROL] && mPressedKeys.find(KEY_RCONTROL) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_RCONTROL, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_RCONTROL] = keyInput; } // Check for released keys std::map::iterator iter, tempIter; for (iter = mPressedKeys.begin(); iter != mPressedKeys.end(); ) { if (!key[iter->first]) { KeyInput keyInput(iter->second.getKey(), KeyInput::Released); keyInput.setNumericPad(iter->second.isNumericPad()); keyInput.setShiftPressed(iter->second.isShiftPressed()); keyInput.setAltPressed(iter->second.isAltPressed()); keyInput.setControlPressed(iter->second.isControlPressed()); mKeyQueue.push(keyInput); tempIter = iter; iter++; mPressedKeys.erase(tempIter); } else { iter++; } } } Key AllegroInput::convertToKey(int scancode, int unicode) { int keysym; bool pad = false; switch(scancode) { case KEY_ESC: keysym = Key::Escape; break; case KEY_ALT: keysym = Key::LeftAlt; break; case KEY_ALTGR: keysym = Key::RightAlt; break; case KEY_LSHIFT: keysym = Key::LeftShift; break; case KEY_RSHIFT: keysym = Key::RightShift; break; case KEY_LCONTROL: keysym = Key::LeftControl; break; case KEY_RCONTROL: keysym = Key::RightControl; break; case KEY_LWIN: keysym = Key::LeftMeta; break; case KEY_RWIN: keysym = Key::RightMeta; break; case KEY_INSERT: keysym = Key::Insert; break; case KEY_HOME: keysym = Key::Home; break; case KEY_PGUP: keysym = Key::PageUp; break; case KEY_PGDN: keysym = Key::PageDown; break; case KEY_DEL: keysym = Key::Delete; break; case KEY_DEL_PAD: keysym = Key::Delete; pad = true; break; case KEY_END: keysym = Key::End; break; case KEY_CAPSLOCK: keysym = Key::CapsLock; break; case KEY_BACKSPACE: keysym = Key::Backspace; break; case KEY_F1: keysym = Key::F1; break; case KEY_F2: keysym = Key::F2; break; case KEY_F3: keysym = Key::F3; break; case KEY_F4: keysym = Key::F4; break; case KEY_F5: keysym = Key::F5; break; case KEY_F6: keysym = Key::F6; break; case KEY_F7: keysym = Key::F7; break; case KEY_F8: keysym = Key::F8; break; case KEY_F9: keysym = Key::F9; break; case KEY_F10: keysym = Key::F10; break; case KEY_F11: keysym = Key::F11; break; case KEY_F12: keysym = Key::F12; break; case KEY_PRTSCR: keysym = Key::PrintScreen; break; case KEY_PAUSE: keysym = Key::Pause; break; case KEY_SCRLOCK: keysym = Key::ScrollLock; break; case KEY_NUMLOCK: keysym = Key::NumLock; break; case KEY_LEFT: keysym = Key::Left; break; case KEY_RIGHT: keysym = Key::Right; break; case KEY_UP: keysym = Key::Up; break; case KEY_DOWN: keysym = Key::Down; break; case KEY_ENTER_PAD: pad = true; case KEY_ENTER: keysym = Key::Enter; break; default: keysym = unicode; } Key k = Key(keysym); return k; } bool AllegroInput::isNumericPad(int scancode) { switch (scancode) { case KEY_0_PAD: case KEY_1_PAD: case KEY_2_PAD: case KEY_3_PAD: case KEY_4_PAD: case KEY_5_PAD: case KEY_6_PAD: case KEY_7_PAD: case KEY_8_PAD: case KEY_9_PAD: case KEY_SLASH_PAD: case KEY_MINUS_PAD: case KEY_PLUS_PAD: return true; default: return false; } } } fifechan-0.1.5/src/cairo/000077500000000000000000000000001341577075500151625ustar00rootroot00000000000000fifechan-0.1.5/src/cairo/cairo.cpp000066400000000000000000000074341341577075500167730ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2008 Mehdi Abbad a.k.a slyf0x * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/cairo.hpp" extern "C" { void fcnCairo() { } } fifechan-0.1.5/src/cairo/cairofont.cpp000066400000000000000000000125161341577075500176570ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2008 Mehdi Abbad a.k.a slyf0x * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "fifechan/cairo/cairofont.hpp" #include "fifechan/cairo/cairographics.hpp" #include "fifechan/exception.hpp" namespace fcn { CairoFont::CairoFont(cairo_scaled_font_t* fontface) { mFontFace=fontface; cairo_scaled_font_reference(mFontFace); cairo_scaled_font_extents(mFontFace,&mFontExtents); SetFontColor(Color(0,0,0,255)); } /*void CairoFont::SetFontFace(cairo_font_face_t* fontface) { }*/ void CairoFont::drawString(fcn::Graphics* graphics, const std::string& text, int x, int y) { CairoGraphics* gr=dynamic_cast(graphics); if (gr==NULL) { FCN_EXCEPTION("The graphics object passed as parameter is not of type CairoGraphics"); } cairo_t* target=gr->GetContext(); ClipRectangle r=gr->getCurrentClipArea(); cairo_set_scaled_font(target,mFontFace); cairo_move_to(target,r.xOffset+x,mFontExtents.ascent+r.yOffset+y); cairo_set_source_rgba(target,mColorR,mColorG,mColorB,mColorA); cairo_show_text(target,text.c_str()); } int CairoFont::getHeight() const { return (int)mFontExtents.height; } int CairoFont::getWidth(const std::string& text) const { cairo_text_extents_t textext; cairo_scaled_font_text_extents(mFontFace,text.c_str(),&textext); return (int)textext.width; } CairoFont::~CairoFont() { cairo_scaled_font_destroy(mFontFace); } void CairoFont::SetFontColor(const Color& color) { mColor = color; mColorR= mColor.r/255.0; mColorG= mColor.g/255.0; mColorB= mColor.b/255.0; mColorA= mColor.a/255.0; } } fifechan-0.1.5/src/cairo/cairographics.cpp000066400000000000000000000216731341577075500205150ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2008 Mehdi Abbad a.k.a slyf0x * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "fifechan/cairo/cairographics.hpp" #include "fifechan/exception.hpp" #include "fifechan/cairo/cairofont.hpp" #include "fifechan/cairo/cairoimage.hpp" namespace fcn { CairoGraphics::CairoGraphics(cairo_surface_t* TargetSurface,int Width,int Height) { if (!TargetSurface) { FCN_EXCEPTION("Specified reference to target cairo surface is null!"); } mCairoContext=cairo_create(TargetSurface); mTargetSurface=TargetSurface; mHeight=Height; mWidth=Width; } CairoGraphics::~CairoGraphics() { cairo_destroy(mCairoContext); } void CairoGraphics::_beginDraw() { pushClipArea(Rectangle(0,0,mWidth,mHeight)); cairo_push_group(mCairoContext); } void CairoGraphics::_endDraw() { cairo_pop_group_to_source(mCairoContext); cairo_paint(mCairoContext); popClipArea(); } bool CairoGraphics::pushClipArea(Rectangle area) { bool result=Graphics::pushClipArea(area); ClipRectangle& mCurrentDrawingArea=mClipStack.top(); //saves the current context options including clipping area // ! Actualy saves all drawing options. cairo_save(mCairoContext); //create a rectangle corresponding to the clipping area cairo_rectangle(mCairoContext, mCurrentDrawingArea.xOffset, mCurrentDrawingArea.yOffset, area.width, area.height); cairo_clip(mCairoContext); return result; } void CairoGraphics::popClipArea() { Graphics::popClipArea(); //restore drawing options cairo_restore(mCairoContext); } void CairoGraphics::drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height) { const CairoImage *srcImage=dynamic_cast(image); if (!srcImage) { throw FCN_EXCEPTION("Passed image reference is null or not of type fcn::CairoImage*."); } const ClipRectangle& top=mClipStack.top(); cairo_save(mCairoContext); cairo_set_source_surface(mCairoContext, srcImage->mCairoSurface, top.xOffset + (dstX - srcX), top.yOffset + (dstY - srcY)); //sets the clipping area cairo_rectangle(mCairoContext, top.xOffset + dstX, top.yOffset + dstY, width,height); cairo_clip(mCairoContext); //paint and restore the context cairo_paint(mCairoContext); cairo_restore (mCairoContext); } void CairoGraphics::drawRectangle(const Rectangle& rectangle) { ClipRectangle& mCurrentDrawingArea=mClipStack.top(); cairo_rectangle(mCairoContext, mCurrentDrawingArea.xOffset+rectangle.x, mCurrentDrawingArea.yOffset+rectangle.y, rectangle.width, rectangle.height); SetCurrentColorAsSource(); cairo_stroke(mCairoContext); } void CairoGraphics::fillRectangle(const Rectangle& rectangle) { ClipRectangle& mCurrentDrawingArea=mClipStack.top(); cairo_rectangle(mCairoContext, mCurrentDrawingArea.xOffset+rectangle.x, mCurrentDrawingArea.yOffset+rectangle.y, rectangle.width, rectangle.height); SetCurrentColorAsSource(); cairo_fill(mCairoContext); } void CairoGraphics::drawPoint(int x, int y) { ClipRectangle& mCurrentDrawingArea=mClipStack.top(); cairo_rectangle(mCairoContext, mCurrentDrawingArea.xOffset+x, mCurrentDrawingArea.yOffset+y, 1,1); SetCurrentColorAsSource(); cairo_fill(mCairoContext); } void CairoGraphics::drawLine(int x1, int y1, int x2, int y2) { ClipRectangle& mCurrentDrawingArea=mClipStack.top(); cairo_move_to(mCairoContext, mCurrentDrawingArea.xOffset+x1, mCurrentDrawingArea.yOffset+y1); cairo_line_to(mCairoContext, mCurrentDrawingArea.xOffset+x2, mCurrentDrawingArea.yOffset+y2); SetCurrentColorAsSource(); cairo_set_line_width(mCairoContext,1.0f); cairo_set_line_cap(mCairoContext, CAIRO_LINE_CAP_SQUARE); cairo_stroke(mCairoContext); } void CairoGraphics::setColor(const Color& color) { mColor = color; mColorR= mColor.r/255.0; mColorG= mColor.g/255.0; mColorB= mColor.b/255.0; mColorA= mColor.a/255.0; } const Color& CairoGraphics::getColor() const { return mColor; } void CairoGraphics::SetCurrentColorAsSource() { cairo_set_source_rgba(mCairoContext, mColorR, mColorG, mColorB, mColorA); } cairo_t* CairoGraphics::GetContext() { return mCairoContext; } } fifechan-0.1.5/src/cairo/cairoimage.cpp000066400000000000000000000203751341577075500177750ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2008 Mehdi Abbad a.k.a slyf0x * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "fifechan/cairo/cairoimage.hpp" #include "fifechan/exception.hpp" namespace fcn { CairoImage::CairoImage(cairo_surface_t* surface) { mCairoSurface=surface; } CairoImage::~CairoImage() { if (mCairoSurface) { cairo_surface_destroy(mCairoSurface); } } int CairoImage::getWidth() const { if (!mCairoSurface) { throw FCN_EXCEPTION("Trying to get the width of a non loaded image."); } int i=cairo_image_surface_get_width(mCairoSurface); return i; } int CairoImage::getHeight() const { if (!mCairoSurface) { throw FCN_EXCEPTION("Trying to get the height of a non loaded image."); } int i=cairo_image_surface_get_height(mCairoSurface); return i; } void CairoImage::free() { if (!mCairoSurface) { throw FCN_EXCEPTION("Trying to free a non loaded image."); } cairo_surface_destroy(mCairoSurface); mCairoSurface=NULL; } unsigned long CairoImage::PrecomputeAlpha(const Color& color) { #warning FIXME (slyf0x#1#): Must deal with both big & little endian platforms double a=color.a/255.0; int r=(int)(a*color.r), g=(int)(a*color.g), b=(int)(a*color.b); return (color.a<<24 + r<<16 + g<<8 + b); } unsigned long CairoImage::GetRGB(const Color& color) { return (color.r<<16 + color.g<<8 + color.b); } Color CairoImage::GetColorFromRGB(unsigned long color) { return (Color(color>>16,(color>>8)&0x0000FF,(color&0xFF),0xFF)); } Color CairoImage::GetColorFromARGB(unsigned long color) { // pixel data are stored with precomputed alpha values ex : // red with 50% alpha is not stored 0x80FF0000 but 0x80800000 Color c; c.a=color >> 24; if (c.a==0) { c.b=c.r=c.g=0; } else { c.b=( (color & 0xFF) * 255) / c.a; c.g=( ( (color >> 8) & 0xFF) * 255) / c.a; c.r=( ( (color >> 16) & 0xFF) *255) / c.a; } return c; } Color CairoImage::getPixel(int x, int y) { if (!mCairoSurface) { throw FCN_EXCEPTION("Trying to get a pixel from a non loaded image."); } int stride=cairo_image_surface_get_stride(mCairoSurface); int yindex=y*stride; unsigned char *imagePixels=cairo_image_surface_get_data(mCairoSurface); if (!imagePixels) { throw FCN_EXCEPTION("Surface data are not available (surface is not of type cairo_image_surface or has been finished)"); } // deal differently with each surface format switch(cairo_image_surface_get_format(mCairoSurface)) { case CAIRO_FORMAT_ARGB32: return GetColorFromARGB(*((unsigned long*)(&imagePixels[x*4 + yindex]))); break; case CAIRO_FORMAT_RGB24: return GetColorFromRGB(*((unsigned long*)(&imagePixels[x*4 + yindex]))); break; case CAIRO_FORMAT_A8: return Color(0,0,0,imagePixels[x + yindex]); break; default : return Color(0,0,0); //do nothing break; } } void CairoImage::putPixel(int x, int y, const Color& color) { if (!mCairoSurface) { throw FCN_EXCEPTION("Trying to write a pixel on a non loaded image."); } int stride=cairo_image_surface_get_stride(mCairoSurface); unsigned char *imagePixels=cairo_image_surface_get_data(mCairoSurface); if (!imagePixels) { throw FCN_EXCEPTION("Surface data are not available (surface is not of type Image or has been finished)"); } // deal differently with each surface format switch(cairo_image_surface_get_format(mCairoSurface)) { case CAIRO_FORMAT_ARGB32: *((unsigned long*)(&imagePixels[x*4 + y*stride]))=PrecomputeAlpha(color); break; case CAIRO_FORMAT_RGB24: *((unsigned long*)(&imagePixels[x*4 + y*stride]))=GetRGB(color); break; case CAIRO_FORMAT_A8: imagePixels[x + y*stride]=(unsigned char)color.a; break; default : //do nothing break; } } cairo_surface_t* CairoImage::GetSurface() { return mCairoSurface; } void CairoImage::convertToDisplayFormat() { } } fifechan-0.1.5/src/cairo/cairoimageloader.cpp000066400000000000000000000105351341577075500211610ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2008 Mehdi Abbad a.k.a slyf0x * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "fifechan/cairo/cairoimage.hpp" #include "fifechan/exception.hpp" #include "fifechan/cairo/cairoimageloader.hpp" namespace fcn { Image* CairoImageLoader::load(const std::string& filename, bool convertToDisplayFormat) { cairo_surface_t* loadedSurface = cairo_image_surface_create_from_png(filename.c_str()); if (loadedSurface == NULL) { throw FCN_EXCEPTION( std::string("Unable to load image file: ") + filename); } Image *image = new CairoImage(loadedSurface); if ( convertToDisplayFormat ) { image->convertToDisplayFormat(); } return image; } } fifechan-0.1.5/src/cliprectangle.cpp000066400000000000000000000105531341577075500174110ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/cliprectangle.hpp" namespace fcn { ClipRectangle::ClipRectangle() { x = y = width = height = xOffset = yOffset = 0; } ClipRectangle::ClipRectangle(int x, int y, int width, int height, int xOffset, int yOffset) { this->x = x; this->y = y; this->width = width; this->height = height; this->xOffset = xOffset; this->yOffset = yOffset; } const ClipRectangle& ClipRectangle::operator=(const Rectangle& other) { x = other.x; y = other.y; width = other.width; height = other.height; return *this; } } fifechan-0.1.5/src/color.cpp000066400000000000000000000137501341577075500157150ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/color.hpp" namespace fcn { Color::Color() : r(0), g(0), b(0), a(255) { } Color::Color(int color) : r( (color >> 16) & 0xFF), g( (color >> 8) & 0xFF), b( color & 0xFF), a(255) { } Color::Color(int ar, int ag, int ab, int aa) : r(ar), g(ag), b(ab), a(aa) { } Color Color::operator+(const Color& color) const { Color result(r + color.r, g + color.g, b + color.b, 255); result.r = (result.r>255?255:(result.r<0?0:result.r)); result.g = (result.g>255?255:(result.g<0?0:result.g)); result.b = (result.b>255?255:(result.b<0?0:result.b)); return result; } Color Color::operator-(const Color& color) const { Color result(r - color.r, g - color.g, b - color.b, 255); result.r = (result.r>255?255:(result.r<0?0:result.r)); result.g = (result.g>255?255:(result.g<0?0:result.g)); result.b = (result.b>255?255:(result.b<0?0:result.b)); return result; } Color Color::operator*(float value) const { Color result((int)(r * value), (int)(g * value), (int)(b * value), a); result.r = (result.r>255?255:(result.r<0?0:result.r)); result.g = (result.g>255?255:(result.g<0?0:result.g)); result.b = (result.b>255?255:(result.b<0?0:result.b)); return result; } bool Color::operator==(const Color& color) const { return r == color.r && g == color.g && b == color.b && a == color.a; } bool Color::operator!=(const Color& color) const { return !(r == color.r && g == color.g && b == color.b && a == color.a); } std::ostream& operator<<(std::ostream& out, const Color& color) { out << "Color [r = " << color.r << ", g = " << color.g << ", b = " << color.b << ", a = " << color.a << "]"; return out; } } fifechan-0.1.5/src/containerevent.cpp000066400000000000000000000101011341577075500176060ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/containerevent.hpp" namespace fcn { ContainerEvent::ContainerEvent(Widget* source, Container* container) :Event(source), mContainer(container) { } ContainerEvent::~ContainerEvent() { } Container* ContainerEvent::getContainer() const { return mContainer; } } fifechan-0.1.5/src/contrib/000077500000000000000000000000001341577075500155255ustar00rootroot00000000000000fifechan-0.1.5/src/contrib/allegro/000077500000000000000000000000001341577075500171525ustar00rootroot00000000000000fifechan-0.1.5/src/contrib/allegro/allegroglyphkeeperfont.cpp000066400000000000000000000156141341577075500244410ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/contrib/allegro/allegroglyphkeeperfont.hpp" #include "fifechan/allegro.hpp" #include "fifechan/exception.hpp" #include "fifechan/graphics.hpp" #include namespace fcn { namespace contrib { void AllegroGlyphKeeperFont::load(const std::string& filename, int w, int h) { mKeeper = gk_create_keeper(0,0); if (mKeeper == NULL) { throw FCN_EXCEPTION("Can't create keeper."); } mFace = gk_load_face_from_file(filename.c_str(), 0); if (mFace == NULL) { throw FCN_EXCEPTION("Can't load font from file."); } mRend = gk_create_renderer(mFace,mKeeper); if (mRend == NULL) { throw FCN_EXCEPTION("Can't create renderer."); } gk_rend_set_hinting_off(mRend); gk_rend_set_size_pixels(mRend, w, h); gk_rend_set_text_color_rgb(mRend, 0, 0, 0); } AllegroGlyphKeeperFont::AllegroGlyphKeeperFont(const std::string& filename, int size) : mFace(0), mRend(0), mKeeper(0) { load(filename, size, size); } AllegroGlyphKeeperFont::AllegroGlyphKeeperFont(const std::string& filename, int w, int h) : mFace(0), mRend(0), mKeeper(0) { load(filename, w, h); } AllegroGlyphKeeperFont::~AllegroGlyphKeeperFont() { if (mRend != NULL) { gk_done_renderer(mRend); } mRend = NULL; if (mFace != NULL) { gk_unload_face(mFace); } mFace = NULL; if (mKeeper != NULL) { gk_done_keeper(mKeeper); } mKeeper = NULL; } int AllegroGlyphKeeperFont::getWidth(const std::string& text) const { return gk_text_width_utf8(mRend, text.c_str()); } int AllegroGlyphKeeperFont::getHeight() const { return gk_rend_height_pixels(mRend); } void AllegroGlyphKeeperFont::drawString(fcn::Graphics* graphics, const std::string& text, int x, int y) { fcn::AllegroGraphics* const allegroGraphics = dynamic_cast(graphics); if (!allegroGraphics) { throw FCN_EXCEPTION("Graphics is not of type AllegroGraphics"); } BITMAP* const target = allegroGraphics->getTarget(); gk_rend_set_text_color_combined(mRend, allegroGraphics->getAllegroColor()); gk_rend_set_text_alpha(mRend, allegroGraphics->getColor().a); const fcn::ClipRectangle& rec = graphics->getCurrentClipArea(); gk_render_line_utf8(target, mRend, text.c_str(), x + rec.xOffset, y + rec.yOffset + gk_rend_ascender_pixels(mRend)); } } } fifechan-0.1.5/src/contrib/opengl/000077500000000000000000000000001341577075500170115ustar00rootroot00000000000000fifechan-0.1.5/src/contrib/opengl/oglftfont.cpp000066400000000000000000000140101341577075500215130ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/contrib/opengl/oglftfont.hpp" #include "fifechan/exception.hpp" #include "fifechan/opengl/openglgraphics.hpp" #include namespace fcn { namespace contrib { OGLFTFont::OGLFTFont (const std::string& filename, int size) { mRowSpacing = 0; mFilename = filename; mFont = NULL; mSize = size; mFont = new OGLFT::TranslucentTexture(filename.c_str(), size, 72); if(mFont == NULL || !mFont->isValid()) { throw FCN_EXCEPTION("Invalid True Type Font."); } glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); } OGLFTFont::~OGLFTFont() { delete mFont; } int OGLFTFont::getWidth(const std::string& text) const { OGLFT::BBox bbox = mFont->measure(text.c_str()); return (int)ceil(bbox.x_max_) + (int)ceil(bbox.x_min_); } int OGLFTFont::getHeight() const { return mSize + mRowSpacing; } void OGLFTFont::setRowSpacing(int spacing) { mRowSpacing = spacing; } int OGLFTFont::getRowSpacing() { return mRowSpacing; } void OGLFTFont::drawString(fcn::Graphics* graphics, const std::string& text, int x, int y) { if (text == "") { return; } fcn::OpenGLGraphics* glGraphics = dynamic_cast(graphics); if(glGraphics == NULL) { throw FCN_EXCEPTION("Graphics object not an OpenGL graphics object!"); } const fcn::ClipRectangle& top = glGraphics->getCurrentClipArea(); Color col = glGraphics->getColor(); mFont->setForegroundColor(col.r/255, col.g/255, col.b/255); glPushMatrix(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTranslated(x + top.xOffset, y + top.yOffset + (mSize/2)+5, 0.); glRotatef(180., 1., 0., 0.); mFont->draw(text.c_str()); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); glPopMatrix(); } } } fifechan-0.1.5/src/contrib/sdl/000077500000000000000000000000001341577075500163075ustar00rootroot00000000000000fifechan-0.1.5/src/contrib/sdl/sdltruetypefont.cpp000066400000000000000000000157141341577075500222760ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/contrib/sdl/sdltruetypefont.hpp" #include "fifechan/exception.hpp" #include "fifechan/image.hpp" #include "fifechan/graphics.hpp" #include "fifechan/sdl/sdlgraphics.hpp" namespace fcn { namespace contrib { SDLTrueTypeFont::SDLTrueTypeFont (const std::string& filename, int size) { mRowSpacing = 0; mGlyphSpacing = 0; mAntiAlias = true; mFilename = filename; mFont = NULL; mFont = TTF_OpenFont(filename.c_str(), size); if (mFont == NULL) { throw FCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont. "+std::string(TTF_GetError())); } } SDLTrueTypeFont::~SDLTrueTypeFont() { TTF_CloseFont(mFont); } int SDLTrueTypeFont::getWidth(const std::string& text) const { int w, h; TTF_SizeText(mFont, text.c_str(), &w, &h); return w; } int SDLTrueTypeFont::getHeight() const { return TTF_FontHeight(mFont) + mRowSpacing; } void SDLTrueTypeFont::drawString(fcn::Graphics* graphics, const std::string& text, int x, int y) { if (text == "") { return; } fcn::SDLGraphics *sdlGraphics = dynamic_cast(graphics); if (sdlGraphics == NULL) { throw FCN_EXCEPTION("SDLTrueTypeFont::drawString. Graphics object not an SDL graphics object!"); return; } // This is needed for drawing the Glyph in the middle if we have spacing int yoffset = getRowSpacing() / 2; Color col = sdlGraphics->getColor(); SDL_Color sdlCol; sdlCol.b = col.b; sdlCol.r = col.r; sdlCol.g = col.g; SDL_Surface *textSurface; if (mAntiAlias) { textSurface = TTF_RenderText_Blended(mFont, text.c_str(), sdlCol); } else { textSurface = TTF_RenderText_Solid(mFont, text.c_str(), sdlCol); } SDL_Rect dst, src; dst.x = x; dst.y = y + yoffset; src.w = textSurface->w; src.h = textSurface->h; src.x = 0; src.y = 0; sdlGraphics->drawSDLSurface(textSurface, src, dst); SDL_FreeSurface(textSurface); } void SDLTrueTypeFont::setRowSpacing(int spacing) { mRowSpacing = spacing; } int SDLTrueTypeFont::getRowSpacing() { return mRowSpacing; } void SDLTrueTypeFont::setGlyphSpacing(int spacing) { mGlyphSpacing = spacing; } int SDLTrueTypeFont::getGlyphSpacing() { return mGlyphSpacing; } void SDLTrueTypeFont::setAntiAlias(bool antiAlias) { mAntiAlias = antiAlias; } bool SDLTrueTypeFont::isAntiAlias() { return mAntiAlias; } } } fifechan-0.1.5/src/defaultfont.cpp000066400000000000000000000112361341577075500171070ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/defaultfont.hpp" #include #include "fifechan/graphics.hpp" #include "fifechan/rectangle.hpp" namespace fcn { int DefaultFont::getHeight() const { return 8; } int DefaultFont::getWidth(const std::string& text) const { return 8 * text.size(); } int DefaultFont::drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y) { graphics->drawRectangle(x, y, 8, 8); return 8; } void DefaultFont::drawString(Graphics* graphics, const std::string& text, int x, int y) { unsigned int i; for (i = 0; i< text.size(); ++i) { drawGlyph(graphics, text.at(i), x, y); x += getWidth(text); } } int DefaultFont::getStringIndexAt(const std::string& text, int x) const { if (x > (int)text.size() * 8) { return text.size(); } return x / 8; } } fifechan-0.1.5/src/directx3d/000077500000000000000000000000001341577075500157565ustar00rootroot00000000000000fifechan-0.1.5/src/directx3d/directx3dgraphics.cpp000066400000000000000000000337671341577075500221140ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/directx3d/directx3dgraphics.hpp" #include #include "fifechan/exception.hpp" #include "fifechan/image.hpp" #include "fifechan/directx3d/directx3dimage.hpp" namespace fcn { DirectX3DGraphics::DirectX3DGraphics(LPDIRECT3DDEVICE9 device) : mAlpha(false), mDevice(device) { DirectX3DGraphics::setTargetPlane(640, 480); } DirectX3DGraphics::DirectX3DGraphics(LPDIRECT3DDEVICE9 device, int width, int height) : mAlpha(false), mDevice(device) { DirectX3DGraphics::setTargetPlane(width, height); } DirectX3DGraphics::~DirectX3DGraphics() { } void DirectX3DGraphics::_beginDraw() { D3DXMATRIX identity; D3DXMATRIX ortho; D3DXMatrixIdentity(&identity); D3DXMatrixOrthoLH(&ortho, (float)mWidth, (float)mHeight, 0.0f, 1.0f); mDevice->SetTransform(D3DTS_VIEW, &identity); mDevice->SetTransform(D3DTS_WORLD, &identity); mDevice->SetTransform(D3DTS_PROJECTION, &ortho); mDevice->SetRenderState(D3DRS_DITHERENABLE, FALSE); mDevice->SetRenderState(D3DRS_ZENABLE, FALSE); mDevice->SetRenderState(D3DRS_LIGHTING, FALSE); mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE); mDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); mDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); mDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); mDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); mDevice->SetTexture(0, 0); pushClipArea(Rectangle(0, 0, mWidth, mHeight)); } void DirectX3DGraphics::_endDraw() { popClipArea(); } bool DirectX3DGraphics::pushClipArea(Rectangle area) { bool result = Graphics::pushClipArea(area); const ClipRectangle& carea = mClipStack.top(); RECT rect; rect.left = carea.x; rect.top = carea.y; rect.right = carea.x + carea.width; rect.bottom = carea.y + carea.height; mDevice->SetScissorRect(&rect); return result; } void DirectX3DGraphics::popClipArea() { Graphics::popClipArea(); if (mClipStack.empty()) { return; } const ClipRectangle& carea = mClipStack.top(); RECT rect; rect.left = carea.x; rect.top = carea.y; rect.right = carea.x + carea.width; rect.bottom = carea.y + carea.height; mDevice->SetScissorRect(&rect); } void DirectX3DGraphics::setTargetPlane(int width, int height) { mWidth = width; mHeight = height; } void DirectX3DGraphics::drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height) { const DirectX3DImage* srcImage = dynamic_cast(image); if (srcImage == NULL) { throw FCN_EXCEPTION("Trying to draw an image of unknown format, must be a DirectXImage."); } if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); dstX += top.xOffset; dstY += top.yOffset; // Find DirectX texture coordinates float texX1 = srcX / (float)srcImage->getTextureWidth(); float texY1 = srcY / (float)srcImage->getTextureHeight(); float texX2 = (srcX+width) / (float)srcImage->getTextureWidth(); float texY2 = (srcY+height) / (float)srcImage->getTextureHeight(); // Check if blending already is enabled if (!mAlpha) { mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); } DWORD color = 0xFFFFFFFF; VertexWithTexture vertices[]= { {(float)dstX, (float)dstY + height, 0.0f, 1.0f, color, texX1, texY2}, {(float)dstX, (float)dstY, 0.0f, 1.0f, color, texX1, texY1}, {(float)dstX + width, (float)dstY + height, 0.0f, 1.0f, color, texX2, texY2}, {(float)dstX + width, (float)dstY, 0.0f, 1.0f, color, texX2, texY1}, }; mDevice->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1); mDevice->SetTexture(0, srcImage->getTexture()); mDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(VertexWithTexture)); mDevice->SetTexture(0, 0); if (!mAlpha) { mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); } } void DirectX3DGraphics::drawPoint(int x, int y) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); DWORD color = D3DCOLOR_RGBA(mColor.r, mColor.g, mColor.b, mColor.a); Vertex vertices[]= { {(float)x, (float)y, 0.0f, 1.0f, color}, {(float)x + 1, (float)y + 1, 0.0f, 1.0f, color} }; mDevice->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE); mDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, vertices, sizeof(Vertex)); } void DirectX3DGraphics::drawLine(int x1, int y1, int x2, int y2) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); x1 += top.xOffset; y1 += top.yOffset; x2 += top.xOffset; y2 += top.yOffset; // Add the last point on the line as it is excluded // when drawing with DirectX 9 if (x1 < x2 && y1 > y2) { x2++; y2--; } else if (x1 < x2 && y1 < y2) { x2++; y2++; } else if (x1 > x2 && y1 > y2) { x1++; y1++; } else if (x1 > x2 && y1 < y2) { x1++; y1--; } DWORD color = D3DCOLOR_RGBA(mColor.r, mColor.g, mColor.b, mColor.a); Vertex vertices[]= { {(float)x1, (float)y1, 0.0f, 1.0f, color}, {(float)x2, (float)y2, 0.0f, 1.0f, color} }; mDevice->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE); mDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, vertices, sizeof(Vertex)); } void DirectX3DGraphics::drawRectangle(const Rectangle& rectangle) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); DWORD color = D3DCOLOR_RGBA(mColor.r, mColor.g, mColor.b, mColor.a); Vertex vertices[]= { {(float)rectangle.x + top.xOffset, (float)rectangle.y + top.yOffset, 0.0f, 1.0f, color}, {(float)rectangle.x + rectangle.width - 1 + top.xOffset, (float)rectangle.y + top.yOffset, 0.0f, 1.0f, color}, {(float)rectangle.x + rectangle.width - 1 + top.xOffset, (float)rectangle.y + top.yOffset, 0.0f, 1.0f, color}, {(float)rectangle.x + rectangle.width - 1 + top.xOffset, (float)rectangle.y + rectangle.height - 1 + top.yOffset, 0.0f, 1.0f, color}, {(float)rectangle.x + rectangle.width - 1 + top.xOffset, (float)rectangle.y + rectangle.height - 1 + top.yOffset, 0.0f, 1.0f, color}, {(float)rectangle.x + top.xOffset, (float)rectangle.y + rectangle.height - 1 + top.yOffset, 0.0f, 1.0f, color}, {(float)rectangle.x + top.xOffset, (float)rectangle.y + rectangle.height - 1 + top.yOffset, 0.0f, 1.0f, color}, {(float)rectangle.x + top.xOffset, (float)rectangle.y + top.yOffset, 0.0f, 1.0f, color} }; mDevice->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE); mDevice->DrawPrimitiveUP(D3DPT_LINELIST, 4, vertices, sizeof(Vertex)); } void DirectX3DGraphics::fillRectangle(const Rectangle& rectangle) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); DWORD color = D3DCOLOR_RGBA(mColor.r, mColor.g, mColor.b, mColor.a); Vertex vertices[]= { {(float)rectangle.x + top.xOffset, (float)rectangle.y + rectangle.height + top.yOffset, 0.0f, 1.0f, color}, {(float)rectangle.x + top.xOffset, (float)rectangle.y + top.yOffset, 0.0f, 1.0f, color}, {(float)rectangle.x + rectangle.width + top.xOffset, (float)rectangle.y + rectangle.height + top.yOffset, 0.0f, 1.0f, color}, {(float)rectangle.x + rectangle.width + top.xOffset, (float)rectangle.y + top.yOffset, 0.0f, 1.0f, color} }; mDevice->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE); mDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(Vertex)); } void DirectX3DGraphics::setColor(const Color& color) { mColor = color; mAlpha = color.a != 255; if (mAlpha) { mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); } else { mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); } } const Color& DirectX3DGraphics::getColor() const { return mColor; } void DirectX3DGraphics::setDevice(LPDIRECT3DDEVICE9 device) { mDevice = device; } LPDIRECT3DDEVICE9 DirectX3DGraphics::getDevice() const { return mDevice; } int DirectX3DGraphics::getTargetPlaneWidth() const { return mWidth; } int DirectX3DGraphics::getTargetPlaneHeight() const { return mHeight; } } fifechan-0.1.5/src/directx3d/directx3dimage.cpp000066400000000000000000000177771341577075500214010ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/directx3d/directx3dimage.hpp" #include "fifechan/exception.hpp" namespace fcn { DirectX3DImage::DirectX3DImage(LPDIRECT3DSURFACE9 surface, LPDIRECT3DDEVICE9 device, int width, int height, bool convertToDisplayFormat) { mTexture = NULL; mSurface = surface; mDevice = device; mWidth = width; mHeight = height; mTextureWidth = 1; mTextureHeight = 1; while(mTextureWidth < mWidth) { mTextureWidth *= 2; } while(mTextureHeight < mHeight) { mTextureHeight *= 2; } if (convertToDisplayFormat) { DirectX3DImage::convertToDisplayFormat(); } } DirectX3DImage::~DirectX3DImage() { if (mAutoFree) { free(); } } LPDIRECT3DTEXTURE9 DirectX3DImage::getTexture() const { return mTexture; } void DirectX3DImage::free() { if (mSurface != NULL) mSurface->Release(); if (mTexture != NULL) mTexture->Release(); } int DirectX3DImage::getWidth() const { return mWidth; } int DirectX3DImage::getHeight() const { return mHeight; } Color DirectX3DImage::getPixel(int x, int y) { if (mSurface == NULL) { throw FCN_EXCEPTION("Image has been converted to display format"); } if (x < 0 || x >= mWidth || y < 0 || y >= mHeight) { throw FCN_EXCEPTION("Coordinates outside of the image"); } D3DLOCKED_RECT lockedRect; mSurface->LockRect(&lockedRect, NULL, D3DLOCK_READONLY); DWORD* pixels = (DWORD*)lockedRect.pBits; D3DXCOLOR color = pixels[lockedRect.Pitch / sizeof(DWORD) * y + x]; mSurface->UnlockRect(); return Color(color.r*255, color.g*255, color.b*255, color.a*255); } void DirectX3DImage::putPixel(int x, int y, const Color& color) { if (mSurface == NULL) { throw FCN_EXCEPTION("Image has been converted to display format"); } if (x < 0 || x >= mWidth || y < 0 || y >= mHeight) { throw FCN_EXCEPTION("Coordinates outside of the image"); } D3DLOCKED_RECT lockedRect; mSurface->LockRect(&lockedRect, NULL, 0); DWORD* pixels = (DWORD*)lockedRect.pBits; pixels[lockedRect.Pitch / sizeof(DWORD) * y + x] = D3DCOLOR_RGBA(color.r, color.g, color.b, color.a); mSurface->UnlockRect(); } void DirectX3DImage::convertToDisplayFormat() { HRESULT result; result = D3DXCreateTexture(mDevice, mTextureWidth, mTextureHeight, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &mTexture); if (result != D3D_OK) { throw FCN_EXCEPTION("Unable to convert image to display format!"); } LPDIRECT3DSURFACE9 textureSurface; mTexture->GetSurfaceLevel(0, &textureSurface); RECT dest; dest.left = 0; dest.top = 0; dest.right = mWidth; dest.bottom = mHeight; result = D3DXLoadSurfaceFromSurface(textureSurface, NULL, &dest, mSurface, NULL, NULL, D3DX_FILTER_NONE, 0); if (result != D3D_OK) { throw FCN_EXCEPTION("Unable to convert image to display format!"); } mSurface->Release(); mSurface = NULL; } int DirectX3DImage::getTextureWidth() const { return mTextureWidth; } int DirectX3DImage::getTextureHeight() const { return mTextureHeight; } } fifechan-0.1.5/src/directx3d/directx3dimageloader.cpp000066400000000000000000000133341341577075500225510ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/directx3d/directx3dimageloader.hpp" #include "fifechan/exception.hpp" #include "fifechan/directx3d/directx3dimage.hpp" #include namespace fcn { DirectX3DImageLoader::DirectX3DImageLoader(LPDIRECT3DDEVICE9 device) : mDevice(device) {} Image* DirectX3DImageLoader::load(const std::string& filename, bool convertToDisplayFormat) { LPDIRECT3DSURFACE9 surface = NULL; D3DXIMAGE_INFO imageInfo; HRESULT result; result = D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo); if (result != D3D_OK) { throw FCN_EXCEPTION("Unable to load image " + filename); } result = mDevice->CreateOffscreenPlainSurface(imageInfo.Width, imageInfo.Height, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL); if (result != D3D_OK) { throw FCN_EXCEPTION("Unable to load image " + filename); } result = D3DXLoadSurfaceFromFile(surface, NULL, NULL, filename.c_str(), NULL, D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255), &imageInfo); if (result != D3D_OK) { throw FCN_EXCEPTION("Unable to load image " + filename); } return new DirectX3DImage(surface, mDevice, imageInfo.Width, imageInfo.Height, convertToDisplayFormat); } void DirectX3DImageLoader::setDevice(LPDIRECT3DDEVICE9 device) { mDevice = device; } } fifechan-0.1.5/src/directx3d/directx3dinput.cpp000066400000000000000000000454471341577075500214510ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/directx3d/directx3dinput.hpp" #include "fifechan/exception.hpp" namespace fcn { DirectX3DInput::DirectX3DInput() : mLastMouseZ(0), mMouseDown(false), mMouseInWindow(true) { } bool DirectX3DInput::isKeyQueueEmpty() { return mKeyInputQueue.empty(); } KeyInput DirectX3DInput::dequeueKeyInput() { KeyInput keyInput; if (mKeyInputQueue.empty()) { throw FCN_EXCEPTION("The queue is empty."); } keyInput = mKeyInputQueue.front(); mKeyInputQueue.pop(); return keyInput; } bool DirectX3DInput::isMouseQueueEmpty() { return mMouseInputQueue.empty(); } MouseInput DirectX3DInput::dequeueMouseInput() { MouseInput mouseInput; if (mMouseInputQueue.empty()) { throw FCN_EXCEPTION("The queue is empty."); } mouseInput = mMouseInputQueue.front(); mMouseInputQueue.pop(); return mouseInput; } void DirectX3DInput:: dispatchMessage(HWND window, MSG message) { KeyInput keyInput; MouseInput mouseInput; WPARAM wParam = message.wParam; LPARAM lParam = message.lParam; switch (message.message) { case WM_SYSKEYDOWN: case WM_KEYDOWN: { unsigned char kbstate[256]; GetKeyboardState(kbstate); keyInput.setKey(Key(convertKeyCharacter(wParam, lParam, kbstate))); keyInput.setType(KeyInput::Pressed); keyInput.setShiftPressed(kbstate[VK_SHIFT] & 0x80); keyInput.setControlPressed(kbstate[VK_CONTROL] & 0x80); keyInput.setAltPressed(kbstate[VK_MENU] & 0x80); keyInput.setNumericPad(wParam >= VK_NUMPAD0 && wParam <= VK_DIVIDE); mKeyInputQueue.push(keyInput); } break; case WM_SYSKEYUP: case WM_KEYUP: { unsigned char kbstate[256]; GetKeyboardState(kbstate); keyInput.setKey(Key(convertKeyCharacter(wParam, lParam, kbstate))); keyInput.setType(KeyInput::Released); keyInput.setShiftPressed(kbstate[VK_SHIFT] & 0x80); keyInput.setControlPressed(kbstate[VK_CONTROL] & 0x80); keyInput.setAltPressed(kbstate[VK_MENU] & 0x80); keyInput.setNumericPad(wParam >= VK_NUMPAD0 && wParam <= VK_DIVIDE); mKeyInputQueue.push(keyInput); } break; case WM_LBUTTONDOWN: { int x = (int)((signed short)(LOWORD(lParam))); int y = (int)((signed short)(HIWORD(lParam))); mouseInput.setX(x); mouseInput.setY(y); mouseInput.setButton(MouseInput::Left); mouseInput.setType(MouseInput::Pressed); mouseInput.setTimeStamp(GetTickCount()); mMouseInputQueue.push(mouseInput); mMouseDown = true; SetCapture(window); break; } case WM_MBUTTONDOWN: { int x = (int)((signed short)(LOWORD(lParam))); int y = (int)((signed short)(HIWORD(lParam))); mouseInput.setX(x); mouseInput.setY(y); mouseInput.setButton(MouseInput::Middle); mouseInput.setType(MouseInput::Pressed); mouseInput.setTimeStamp(GetTickCount()); mMouseInputQueue.push(mouseInput); mMouseDown = true; SetCapture(window); break; } case WM_RBUTTONDOWN: { int x = (int)((signed short)(LOWORD(lParam))); int y = (int)((signed short)(HIWORD(lParam))); mouseInput.setX(x); mouseInput.setY(y); mouseInput.setButton(MouseInput::Right); mouseInput.setType(MouseInput::Pressed); mouseInput.setTimeStamp(GetTickCount()); mMouseInputQueue.push(mouseInput); mMouseDown = true; SetCapture(window); break; } case WM_LBUTTONUP: { int x = (int)((signed short)(LOWORD(lParam))); int y = (int)((signed short)(HIWORD(lParam))); mouseInput.setX(x); mouseInput.setY(y); mouseInput.setButton(MouseInput::Left); mouseInput.setType(MouseInput::Released); mouseInput.setTimeStamp(GetTickCount()); mMouseInputQueue.push(mouseInput); mMouseDown = false; ReleaseCapture(); break; } case WM_MBUTTONUP: { int x = (int)((signed short)(LOWORD(lParam))); int y = (int)((signed short)(HIWORD(lParam))); mouseInput.setX(x); mouseInput.setY(y); mouseInput.setButton(MouseInput::Middle); mouseInput.setType(MouseInput::Released); mouseInput.setTimeStamp(GetTickCount()); mMouseInputQueue.push(mouseInput); mMouseDown = false; ReleaseCapture(); break; } case WM_RBUTTONUP: { int x = (int)((signed short)(LOWORD(lParam))); int y = (int)((signed short)(HIWORD(lParam))); mouseInput.setX(x); mouseInput.setY(y); mouseInput.setButton(MouseInput::Right); mouseInput.setType(MouseInput::Released); mouseInput.setTimeStamp(GetTickCount()); mMouseInputQueue.push(mouseInput); mMouseDown = false; ReleaseCapture(); break; } case WM_MOUSEMOVE: { int x = (int)((signed short)(LOWORD(lParam))); int y = (int)((signed short)(HIWORD(lParam))); /* POINT point = {x,y}; ScreenToClient(hWnd, &point); RECT rect; GetClientRect(hWnd, &rect);*/ /* if (!mMouseDown && mMouseInWindow && (point.x < 0 || point.y < 0 || point.x > rect.right || point.y > rect.bottom)) { mouseInput.setX(-1); mouseInput.setY(-1); mouseInput.setButton(MouseInput::Empty); mouseInput.setType(MouseInput::Moved); mouseInput.setTimeStamp(GetTickCount()); mMouseInputQueue.push(mouseInput); mMouseInWindow = false; } else if (mMouseDown || (point.x >= 0 && point.y >= 0 && point.x < rect.right && point.y < rect.bottom)) { mouseInput.setX(point.x); mouseInput.setY(point.y); mouseInput.setButton(MouseInput::Empty); mouseInput.setType(MouseInput::Moved); mouseInput.setTimeStamp(GetTickCount()); mMouseInputQueue.push(mouseInput); } mMouseInWindow = point.x >= 0 && point.y >= 0 && point.x < rect.right && point.y < rect.bottom; */ mouseInput.setX(x); mouseInput.setY(y); mouseInput.setButton(MouseInput::Empty); mouseInput.setType(MouseInput::Moved); mouseInput.setTimeStamp(GetTickCount()); mMouseInputQueue.push(mouseInput); break; } // For some reason WM_MOUSEWHEEL isn't defined at some systems // (including mine), but 0x020A should be equal to the WM_MOUSEWHEEL // value. case 0x020A: // WM_MOUSEWHEEL int mouseZ = (short)HIWORD(wParam); int x = (int)((signed short)(LOWORD(lParam))); int y = (int)((signed short)(HIWORD(lParam))); POINT point = {x,y}; ScreenToClient(window, &point); RECT rect; GetClientRect(window, &rect); if (point.x < 0 || point.y < 0 || point.x > rect.right || point.y > rect.bottom) { break; } // Mouse wheels doesn't have to move 120 units anymore, new // mouses can move less than 120, therefore we need to check // that the mouse has at least moved 120 units before we push // an input event. if (mLastMouseZ + mouseZ >= 120) { mMouseInputQueue.push(MouseInput(MouseInput::Empty, MouseInput::WheelMovedUp, point.x, point.y, GetTickCount())); mLastMouseZ = 0; } else if (mLastMouseZ + mouseZ <= -120) { mMouseInputQueue.push(MouseInput(MouseInput::Empty, MouseInput::WheelMovedDown, point.x, point.y, GetTickCount())); mLastMouseZ = 0; } else { mLastMouseZ += mouseZ; } break; } // end switch } int DirectX3DInput::convertKeyCharacter(WPARAM wParam, LPARAM lParam, unsigned char* kbstate) { int value = -1; switch (wParam) { //VK_CLEAR //VK_EXECUTE //VK_PRINT //VK_HELP case VK_TAB: value = Key::Tab; break; case VK_LMENU: value = Key::LeftAlt; break; case VK_RMENU: value = Key::RightAlt; break; case VK_LSHIFT: value = Key::LeftShift; break; case VK_RSHIFT: value = Key::RightShift; break; case VK_LCONTROL: value = Key::LeftControl; break; case VK_RCONTROL: value = Key::RightControl; break; case VK_BACK: value = Key::Backspace; break; case VK_PAUSE: value = Key::Pause; break; case VK_SPACE: value = Key::Space; break; case VK_ESCAPE: value = Key::Escape; break; case VK_DELETE: value = Key::Delete; break; case VK_INSERT: value = Key::Insert; break; case VK_HOME: value = Key::Home; break; case VK_END: value = Key::End; break; case VK_PRIOR: value = Key::PageUp; break; case VK_SNAPSHOT: value = Key::PrintScreen; break; case VK_NEXT: value = Key::PageDown; break; case VK_F1: value = Key::F1; break; case VK_F2: value = Key::F2; break; case VK_F3: value = Key::F3; break; case VK_F4: value = Key::F4; break; case VK_F5: value = Key::F5; break; case VK_F6: value = Key::F6; break; case VK_F7: value = Key::F7; break; case VK_F8: value = Key::F8; break; case VK_F9: value = Key::F9; break; case VK_F10: value = Key::F10; break; case VK_F11: value = Key::F11; break; case VK_F12: value = Key::F12; break; case VK_F13: value = Key::F13; break; case VK_F14: value = Key::F14; break; case VK_F15: value = Key::F15; break; case VK_NUMLOCK: value = Key::NumLock; break; case VK_CAPITAL: value = Key::CapsLock; break; case VK_SCROLL: value = Key::ScrollLock; break; case VK_RWIN: value = Key::RightMeta; break; case VK_LWIN: value = Key::LeftMeta; break; case VK_UP: value = Key::Up; break; case VK_DOWN: value = Key::Down; break; case VK_LEFT: value = Key::Left; break; case VK_RIGHT: value = Key::Right; break; case VK_RETURN: value = Key::Enter; break; default: ToAscii(wParam, HIWORD(lParam) & 0xff, // Gets the scan code. kbstate, (unsigned short*)&value, 0); value = (char)value; break; } return value; } } fifechan-0.1.5/src/event.cpp000066400000000000000000000077121341577075500157210ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/event.hpp" namespace fcn { Event::Event(Widget* source) :mSource(source) { } Event::~Event() { } Widget* Event::getSource() const { return mSource; } } fifechan-0.1.5/src/exception.cpp000066400000000000000000000114701341577075500165720ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/exception.hpp" namespace fcn { Exception::Exception() : mFunction("?"), mMessage(""), mFilename("?"), mLine(0) { } Exception::Exception(const std::string& message) : mFunction("?"), mMessage(message), mFilename("?"), mLine(0) { } Exception::Exception(const std::string& message, const std::string& function, const std::string& filename, unsigned int line) : mFunction(function), mMessage(message), mFilename(filename), mLine(line) { } const std::string& Exception::getFunction() const { return mFunction; } const std::string& Exception::getMessage() const { return mMessage; } const std::string& Exception::getFilename() const { return mFilename; } unsigned int Exception::getLine() const { return mLine; } } fifechan-0.1.5/src/fifechan.cpp000066400000000000000000000074711341577075500163450ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ extern "C" { const char* fcnFifechanVersion() { return "0.1.5"; } } fifechan-0.1.5/src/focushandler.cpp000066400000000000000000000412161341577075500172520ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/focushandler.hpp" #include "fifechan/focuslistener.hpp" #include "fifechan/exception.hpp" #include "fifechan/widget.hpp" namespace fcn { FocusHandler::FocusHandler() :mFocusedWidget(NULL), mModalFocusedWidget(NULL), mModalMouseInputFocusedWidget(NULL), mDraggedWidget(NULL), mLastWidgetWithMouse(NULL), mLastWidgetWithModalFocus(NULL), mLastWidgetWithModalMouseInputFocus(NULL), mLastWidgetPressed(NULL) { } void FocusHandler::requestFocus(Widget* widget) { if (widget == NULL || widget == mFocusedWidget) { return; } unsigned int i = 0; int toBeFocusedIndex = -1; for (i = 0; i < mWidgets.size(); ++i) { if (mWidgets[i] == widget) { toBeFocusedIndex = i; break; } } if (toBeFocusedIndex < 0) { throw FCN_EXCEPTION("Trying to focus a none existing widget."); } Widget *oldFocused = mFocusedWidget; if (oldFocused != widget) { mFocusedWidget = mWidgets.at(toBeFocusedIndex); if (oldFocused != NULL) { Event focusEvent(oldFocused); distributeFocusLostEvent(focusEvent); } Event focusEvent(mWidgets.at(toBeFocusedIndex)); distributeFocusGainedEvent(focusEvent); } } void FocusHandler::requestModalFocus(Widget* widget) { if (mModalFocusedWidget != NULL && mModalFocusedWidget != widget) { throw FCN_EXCEPTION("Another widget already has modal focus."); } mModalFocusedWidget = widget; if (mFocusedWidget != NULL && !mFocusedWidget->isModalFocused()) { focusNone(); } } void FocusHandler::requestModalMouseInputFocus(Widget* widget) { if (mModalMouseInputFocusedWidget != NULL && mModalMouseInputFocusedWidget != widget) { throw FCN_EXCEPTION("Another widget already has modal input focus."); } mModalMouseInputFocusedWidget = widget; } void FocusHandler::releaseModalFocus(Widget* widget) { if (mModalFocusedWidget == widget) { mModalFocusedWidget = NULL; } } void FocusHandler::releaseModalMouseInputFocus(Widget* widget) { if (mModalMouseInputFocusedWidget == widget) { mModalMouseInputFocusedWidget = NULL; } } Widget* FocusHandler::getFocused() const { return mFocusedWidget; } Widget* FocusHandler::getModalFocused() const { return mModalFocusedWidget; } Widget* FocusHandler::getModalMouseInputFocused() const { return mModalMouseInputFocusedWidget; } void FocusHandler::focusNext() { int i; int focusedWidget = -1; for (i = 0; i < (int)mWidgets.size(); ++i) { if (mWidgets[i] == mFocusedWidget) { focusedWidget = i; } } int focused = focusedWidget; // i is a counter that ensures that the following loop // won't get stuck in an infinite loop i = (int)mWidgets.size(); do { ++focusedWidget; if (i==0) { focusedWidget = -1; break; } --i; if (focusedWidget >= (int)mWidgets.size()) { focusedWidget = 0; } if (focusedWidget == focused) { return; } } while (!mWidgets.at(focusedWidget)->isFocusable()); if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } } void FocusHandler::focusPrevious() { if (mWidgets.size() == 0) { mFocusedWidget = NULL; return; } int i; int focusedWidget = -1; for (i = 0; i < (int)mWidgets.size(); ++i) { if (mWidgets[i] == mFocusedWidget) { focusedWidget = i; } } int focused = focusedWidget; // i is a counter that ensures that the following loop // won't get stuck in an infinite loop i = (int)mWidgets.size(); do { --focusedWidget; if (i==0) { focusedWidget = -1; break; } --i; if (focusedWidget <= 0) { focusedWidget = mWidgets.size() - 1; } if (focusedWidget == focused) { return; } } while (!mWidgets.at(focusedWidget)->isFocusable()); if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } } bool FocusHandler::isFocused(const Widget* widget) const { return mFocusedWidget == widget; } void FocusHandler::add(Widget* widget) { mWidgets.push_back(widget); } void FocusHandler::remove(Widget* widget) { if (isFocused(widget)) { mFocusedWidget = NULL; } WidgetIterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) { if ((*iter) == widget) { mWidgets.erase(iter); break; } } if (mDraggedWidget == widget) { mDraggedWidget = NULL; return; } if (mLastWidgetWithMouse == widget) { mLastWidgetWithMouse = NULL; return; } if (mLastWidgetWithModalFocus == widget) { mLastWidgetWithModalFocus = NULL; return; } if (mLastWidgetWithModalMouseInputFocus == widget) { mLastWidgetWithModalMouseInputFocus = NULL; return; } if (mLastWidgetPressed == widget) { mLastWidgetPressed = NULL; return; } } void FocusHandler::focusNone() { if (mFocusedWidget != NULL) { Widget* focused = mFocusedWidget; mFocusedWidget = NULL; Event focusEvent(focused); distributeFocusLostEvent(focusEvent); } } void FocusHandler::tabNext() { if (mFocusedWidget != NULL) { if (!mFocusedWidget->isTabOutEnabled()) { return; } } if (mWidgets.size() == 0) { mFocusedWidget = NULL; return; } int i; int focusedWidget = -1; for (i = 0; i < (int)mWidgets.size(); ++i) { if (mWidgets[i] == mFocusedWidget) { focusedWidget = i; } } int focused = focusedWidget; bool done = false; // i is a counter that ensures that the following loop // won't get stuck in an infinite loop i = (int)mWidgets.size(); do { ++focusedWidget; if (i==0) { focusedWidget = -1; break; } --i; if (focusedWidget >= (int)mWidgets.size()) { focusedWidget = 0; } if (focusedWidget == focused) { return; } if (mWidgets.at(focusedWidget)->isFocusable() && mWidgets.at(focusedWidget)->isTabInEnabled() && (mModalFocusedWidget == NULL || mWidgets.at(focusedWidget)->isModalFocused())) { done = true; } } while (!done); if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } } void FocusHandler::tabPrevious() { if (mFocusedWidget != NULL) { if (!mFocusedWidget->isTabOutEnabled()) { return; } } if (mWidgets.size() == 0) { mFocusedWidget = NULL; return; } int i; int focusedWidget = -1; for (i = 0; i < (int)mWidgets.size(); ++i) { if (mWidgets[i] == mFocusedWidget) { focusedWidget = i; } } int focused = focusedWidget; bool done = false; // i is a counter that ensures that the following loop // won't get stuck in an infinite loop i = (int)mWidgets.size(); do { --focusedWidget; if (i==0) { focusedWidget = -1; break; } --i; if (focusedWidget <= 0) { focusedWidget = mWidgets.size() - 1; } if (focusedWidget == focused) { return; } if (mWidgets.at(focusedWidget)->isFocusable() && mWidgets.at(focusedWidget)->isTabInEnabled() && (mModalFocusedWidget == NULL || mWidgets.at(focusedWidget)->isModalFocused())) { done = true; } } while (!done); if (focusedWidget >= 0) { mFocusedWidget = mWidgets.at(focusedWidget); Event focusEvent(mFocusedWidget); distributeFocusGainedEvent(focusEvent); } if (focused >= 0) { Event focusEvent(mWidgets.at(focused)); distributeFocusLostEvent(focusEvent); } } void FocusHandler::distributeFocusLostEvent(const Event& focusEvent) { Widget* sourceWidget = focusEvent.getSource(); std::list focusListeners = sourceWidget->_getFocusListeners(); // Send the event to all focus listeners of the widget. for (std::list::iterator it = focusListeners.begin(); it != focusListeners.end(); ++it) { (*it)->focusLost(focusEvent); } } void FocusHandler::distributeFocusGainedEvent(const Event& focusEvent) { Widget* sourceWidget = focusEvent.getSource(); std::list focusListeners = sourceWidget->_getFocusListeners(); // Send the event to all focus listeners of the widget. for (std::list::iterator it = focusListeners.begin(); it != focusListeners.end(); ++it) { (*it)->focusGained(focusEvent); } } Widget* FocusHandler::getDraggedWidget() { return mDraggedWidget; } void FocusHandler::setDraggedWidget(Widget* draggedWidget) { mDraggedWidget = draggedWidget; } Widget* FocusHandler::getLastWidgetWithMouse() { return mLastWidgetWithMouse; } void FocusHandler::setLastWidgetWithMouse(Widget* lastWidgetWithMouse) { mLastWidgetWithMouse = lastWidgetWithMouse; } Widget* FocusHandler::getLastWidgetWithModalFocus() { return mLastWidgetWithModalFocus; } void FocusHandler::setLastWidgetWithModalFocus(Widget* lastWidgetWithModalFocus) { mLastWidgetWithModalFocus = lastWidgetWithModalFocus; } Widget* FocusHandler::getLastWidgetWithModalMouseInputFocus() { return mLastWidgetWithModalMouseInputFocus; } void FocusHandler::setLastWidgetWithModalMouseInputFocus(Widget* lastWidgetWithModalMouseInputFocus) { mLastWidgetWithModalMouseInputFocus = lastWidgetWithModalMouseInputFocus; } Widget* FocusHandler::getLastWidgetPressed() { return mLastWidgetPressed; } void FocusHandler::setLastWidgetPressed(Widget* lastWidgetPressed) { mLastWidgetPressed = lastWidgetPressed; } void FocusHandler::widgetHidden(Widget* widget) { } } fifechan-0.1.5/src/font.cpp000066400000000000000000000101771341577075500155450ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/font.hpp" #include namespace fcn { int Font::getStringIndexAt(const std::string& text, int x) const { unsigned int i; int size = 0; for (i = 0; i < text.size(); ++i) { size = getWidth(text.substr(0,i)); if (size > x) { return i; } } return text.size(); } } fifechan-0.1.5/src/genericinput.cpp000066400000000000000000000154461341577075500172770ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/genericinput.hpp" #include "fifechan/exception.hpp" namespace fcn { GenericInput::GenericInput() { } void GenericInput::pushKeyPressed(int unicode) { // TODO } void GenericInput::pushKeyReleased(int unicode) { // TODO } void GenericInput::pushMouseButtonPressed(int x, int y, int button) { MouseInput mouseInput; mouseInput.setX(x); mouseInput.setY(y); mouseInput.setButton(button); mouseInput.setType(MouseInput::Pressed); mMouseInputQueue.push(mouseInput); } void GenericInput::pushMouseButtonReleased(int x, int y, int button) { MouseInput mouseInput; mouseInput.setX(x); mouseInput.setY(y); mouseInput.setButton(button); mouseInput.setType(MouseInput::Released); mMouseInputQueue.push(mouseInput); } void GenericInput::pushMouseWheelMovedUp(int x, int y) { MouseInput mouseInput; mouseInput.setX(x); mouseInput.setY(y); mouseInput.setType(MouseInput::WheelMovedUp); mMouseInputQueue.push(mouseInput); } void GenericInput::pushMouseWheelMovedDown(int x, int y) { MouseInput mouseInput; mouseInput.setX(x); mouseInput.setY(y); mouseInput.setType(MouseInput::WheelMovedDown); mMouseInputQueue.push(mouseInput); } void GenericInput::pushMouseWheelMovedRight(int x, int y) { MouseInput mouseInput; mouseInput.setX(x); mouseInput.setY(y); mouseInput.setType(MouseInput::WheelMovedRight); mMouseInputQueue.push(mouseInput); } void GenericInput::pushMouseWheelMovedLeft(int x, int y) { MouseInput mouseInput; mouseInput.setX(x); mouseInput.setY(y); mouseInput.setType(MouseInput::WheelMovedLeft); mMouseInputQueue.push(mouseInput); } void GenericInput::pushMouseMoved(int x, int y) { MouseInput mouseInput; mouseInput.setX(x); mouseInput.setY(y); mouseInput.setType(MouseInput::Moved); mMouseInputQueue.push(mouseInput); } bool GenericInput::isKeyQueueEmpty() { return mKeyInputQueue.empty(); } KeyInput GenericInput::dequeueKeyInput() { KeyInput keyInput; if (mKeyInputQueue.empty()) { throw FCN_EXCEPTION("The queue is empty."); } keyInput = mKeyInputQueue.front(); mKeyInputQueue.pop(); return keyInput; } bool GenericInput::isMouseQueueEmpty() { return mMouseInputQueue.empty(); } MouseInput GenericInput::dequeueMouseInput() { MouseInput mouseInput; if (mMouseInputQueue.empty()) { throw FCN_EXCEPTION("The queue is empty."); } mouseInput = mMouseInputQueue.front(); mMouseInputQueue.pop(); return mouseInput; } void GenericInput::_pollInput() { // Does nothing. } } fifechan-0.1.5/src/glut/000077500000000000000000000000001341577075500150405ustar00rootroot00000000000000fifechan-0.1.5/src/glut/glutinput.cpp000066400000000000000000000251341341577075500176040ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // /* // * For comments regarding functions please see the header file. // */ // #include "fifechan/glut/glutinput.hpp" // #include "fifechan/exception.hpp" // namespace fcn // { // GLUTInput::GLUTInput() // { // } // bool GLUTInput::isKeyQueueEmpty() // { // return mKeyInputQueue.empty(); // } // KeyInput GLUTInput::dequeueKeyInput() // { // KeyInput keyInput; // if (mKeyInputQueue.empty()) // { // throw FCN_EXCEPTION("The queue is empty."); // } // keyInput = mKeyInputQueue.front(); // mKeyInputQueue.pop(); // return keyInput; // } // bool GLUTInput::isMouseQueueEmpty() // { // return mMouseInputQueue.empty(); // } // MouseInput GLUTInput::dequeueMouseInput() // { // MouseInput mouseInput; // if (mMouseInputQueue.empty()) // { // throw FCN_EXCEPTION("The queue is empty."); // } // mouseInput = mMouseInputQueue.front(); // mMouseInputQueue.pop(); // return mouseInput; // } // void GLUTInput::pushKeyDownInput(unsigned char key) // { // KeyInput keyInput; // keyInput.setKey(convertKeyCharacter(key)); // keyInput.setType(KeyInput::PRESS); // mKeyInputQueue.push(keyInput); // } // void GLUTInput::pushKeyUpInput(unsigned char key) // { // KeyInput keyInput; // keyInput.setKey(convertKeyCharacter(key)); // keyInput.setType(KeyInput::RELEASE); // mKeyInputQueue.push(keyInput); // } // void GLUTInput::pushSpecialDownInput(unsigned char key) // { // KeyInput keyInput; // keyInput.setKey(convertSpecialCharacter(key)); // keyInput.setType(KeyInput::PRESS); // mKeyInputQueue.push(keyInput); // } // void GLUTInput::pushSpecialUpInput(unsigned char key) // { // KeyInput keyInput; // keyInput.setKey(convertSpecialCharacter(key)); // keyInput.setType(KeyInput::RELEASE); // mKeyInputQueue.push(keyInput); // } // void GLUTInput::pushMouseInput(int button, int state, int x, int y) // { // MouseInput mouseInput; // mouseInput.x = x; // mouseInput.y = y; // mouseInput.setButton(convertMouseButton(button)); // if (state == GLUT_DOWN) // { // mouseInput.setType(MouseInput::PRESS); // } // else // { // mouseInput.setType(MouseInput::RELEASE); // } // mMouseInputQueue.push(mouseInput); // } // void GLUTInput::pushMotionInput(int x, int y) // { // MouseInput mouseInput; // mouseInput.x = x; // mouseInput.y = y; // mouseInput.setButton(MouseInput::EMPTY); // mouseInput.setType(MouseInput::MOTION); // mMouseInputQueue.push(mouseInput); // } // void GLUTInput::pushPassiveMotionInput(int x, int y) // { // pushMotionInput(x, y); // } // Key GLUTInput::convertKeyCharacter(unsigned char key) // { // int value = 0; // Key fcnKey; // value = (int)key; // switch(key) // { // case 8: // value = Key::BACKSPACE; // break; // case 13: // value = Key::ENTER; // break; // case 27: // value = Key::ESCAPE; // break; // case 127: // value = Key::DELETE; // break; // } // int modifiers = glutGetModifiers(); // fcnKey.setShiftPressed(modifiers & GLUT_ACTIVE_SHIFT); // fcnKey.setControlPressed(modifiers & GLUT_ACTIVE_CTRL); // fcnKey.setAltPressed(modifiers & GLUT_ACTIVE_ALT); // fcnKey.setValue(value); // return fcnKey; // } // Key GLUTInput::convertSpecialCharacter(unsigned char key) // { // int value = 0; // Key fcnKey; // value = (int)key; // switch(key) // { // case GLUT_KEY_UP: // value = Key::UP; // break; // case GLUT_KEY_DOWN: // value = Key::DOWN; // break; // case GLUT_KEY_RIGHT: // value = Key::RIGHT; // break; // case GLUT_KEY_LEFT: // value = Key::LEFT; // break; // case GLUT_KEY_F1: // value = Key::F1; // break; // case GLUT_KEY_F2: // value = Key::F2; // break; // case GLUT_KEY_F3: // value = Key::F3; // break; // case GLUT_KEY_F4: // value = Key::F4; // break; // case GLUT_KEY_F5: // value = Key::F5; // break; // case GLUT_KEY_F6: // value = Key::F6; // break; // case GLUT_KEY_F7: // value = Key::F7; // break; // case GLUT_KEY_F8: // value = Key::F8; // break; // case GLUT_KEY_F9: // value = Key::F9; // break; // case GLUT_KEY_F10: // value = Key::F10; // break; // case GLUT_KEY_F11: // value = Key::F11; // break; // case GLUT_KEY_F12: // value = Key::F12; // break; // case GLUT_KEY_PAGE_UP: // value = Key::PAGE_UP; // break; // case GLUT_KEY_PAGE_DOWN: // value = Key::PAGE_DOWN; // break; // case GLUT_KEY_HOME: // value = Key::HOME; // break; // case GLUT_KEY_END: // value = Key::END; // break; // case GLUT_KEY_INSERT: // value = Key::INSERT; // break; // default: // break; // } // int modifiers = glutGetModifiers(); // fcnKey.setShiftPressed(modifiers & GLUT_ACTIVE_SHIFT); // fcnKey.setControlPressed(modifiers & GLUT_ACTIVE_CTRL); // fcnKey.setAltPressed(modifiers & GLUT_ACTIVE_ALT); // fcnKey.setValue(value); // return fcnKey; // } // int GLUTInput::convertMouseButton(int button) // { // switch (button) // { // case GLUT_LEFT_BUTTON: // return MouseInput::LEFT; // break; // case GLUT_RIGHT_BUTTON: // return MouseInput::RIGHT; // break; // case GLUT_MIDDLE_BUTTON: // return MouseInput::MIDDLE; // break; // } // throw FCN_EXCEPTION("Unknown GLUT mouse type."); // return 0; // } // } fifechan-0.1.5/src/graphics.cpp000066400000000000000000000144571341577075500164040ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/graphics.hpp" #include "fifechan/exception.hpp" #include "fifechan/font.hpp" #include "fifechan/image.hpp" namespace fcn { Graphics::Graphics() { mFont = NULL; } bool Graphics::pushClipArea(Rectangle area) { // Ignore area with a negate width or height // by simple pushing an empty clip area // to the stack. if (area.isEmpty()) { ClipRectangle carea; mClipStack.push(carea); return true; } if (mClipStack.empty()) { ClipRectangle carea; carea.x = area.x; carea.y = area.y; carea.width = area.width; carea.height = area.height; carea.xOffset = area.x; carea.yOffset = area.y; mClipStack.push(carea); return true; } const ClipRectangle &top = mClipStack.top(); ClipRectangle carea; carea = area; carea.xOffset = top.xOffset + carea.x; carea.yOffset = top.yOffset + carea.y; carea.x += top.xOffset; carea.y += top.yOffset; carea = top.intersection(carea); mClipStack.push(carea); return !carea.isEmpty(); } void Graphics::popClipArea() { if (mClipStack.empty()) { throw FCN_EXCEPTION("Tried to pop clip area from empty stack."); } mClipStack.pop(); } const ClipRectangle& Graphics::getCurrentClipArea() { if (mClipStack.empty()) { throw FCN_EXCEPTION("The clip area stack is empty."); } return mClipStack.top(); } void Graphics::drawImage(const Image* image, int dstX, int dstY) { drawImage(image, 0, 0, dstX, dstY, image->getWidth(), image->getHeight()); } void Graphics::setFont(Font* font) { mFont = font; } void Graphics::drawText(const std::string& text, int x, int y, Alignment alignment) { if (mFont == NULL) { throw FCN_EXCEPTION("No font set."); } switch (alignment) { case Left: mFont->drawString(this, text, x, y); break; case Center: mFont->drawString(this, text, x - mFont->getWidth(text) / 2, y); break; case Right: mFont->drawString(this, text, x - mFont->getWidth(text), y); break; default: throw FCN_EXCEPTION("Unknown alignment."); } } } fifechan-0.1.5/src/gui.cpp000066400000000000000000001172621341577075500153660ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/gui.hpp" #include "fifechan/deathlistener.hpp" #include "fifechan/exception.hpp" #include "fifechan/focushandler.hpp" #include "fifechan/graphics.hpp" #include "fifechan/input.hpp" #include "fifechan/keyinput.hpp" #include "fifechan/keylistener.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/mouselistener.hpp" #include "fifechan/rectangle.hpp" #include "fifechan/visibilityeventhandler.hpp" #include "fifechan/widget.hpp" #include #include namespace fcn { class GuiDeathListener : public DeathListener { public: GuiDeathListener(Gui* gui) { mGui = gui; } virtual ~GuiDeathListener() { } virtual void death(const Event& event) { mGui->widgetDied(event.getSource()); } private: Gui* mGui; }; Gui::Gui() :mTop(NULL), mGraphics(NULL), mInput(NULL), mTabbing(true), mShiftPressed(false), mMetaPressed(false), mControlPressed(false), mAltPressed(false), mLastMousePressButton(0), mLastMousePressTimeStamp(0), mLastMouseX(0), mLastMouseY(0), mClickCount(1), mLastMouseDragButton(0) { mFocusHandler = new FocusHandler(); mVisibilityEventHandler = new VisibilityEventHandler(this); mDeathListener = new GuiDeathListener(this); Widget::_setVisibilityEventHandler(mVisibilityEventHandler); Widget::_setGuiDeathListener(mDeathListener); } Gui::~Gui() { if (Widget::widgetExists(mTop)) { setTop(NULL); } Widget::_setVisibilityEventHandler(NULL); Widget::_setGuiDeathListener(NULL); delete mFocusHandler; delete mVisibilityEventHandler; delete mDeathListener; } void Gui::setTop(Widget* top) { if (mTop != NULL) { mTop->_setFocusHandler(NULL); } if (top != NULL) { top->_setFocusHandler(mFocusHandler); } mTop = top; } Widget* Gui::getTop() const { return mTop; } void Gui::setGraphics(Graphics* graphics) { mGraphics = graphics; } Graphics* Gui::getGraphics() const { return mGraphics; } void Gui::setInput(Input* input) { mInput = input; } Input* Gui::getInput() const { return mInput; } void Gui::logic() { if (mTop == NULL) throw FCN_EXCEPTION("No top widget set"); handleModalFocus(); handleModalMouseInputFocus(); if (mInput != NULL) { mInput->_pollInput(); handleKeyInput(); handleMouseInput(); } mTop->_logic(); handleHiddenWidgets(); handleShownWidgets(); } void Gui::draw() { if (mTop == NULL) throw FCN_EXCEPTION("No top widget set"); if (mGraphics == NULL) throw FCN_EXCEPTION("No graphics set"); if (!mTop->isVisible()) return; mGraphics->_beginDraw(); mTop->_draw(mGraphics); mGraphics->_endDraw(); } void Gui::focusNone() { mFocusHandler->focusNone(); } void Gui::setTabbingEnabled(bool tabbing) { mTabbing = tabbing; } bool Gui::isTabbingEnabled() { return mTabbing; } void Gui::addGlobalKeyListener(KeyListener* keyListener) { mKeyListeners.push_back(keyListener); } void Gui::removeGlobalKeyListener(KeyListener* keyListener) { mKeyListeners.remove(keyListener); } void Gui::enqueueHiddenWidget(Widget* hidden) { mHiddenWidgets.push(hidden); } void Gui::enqueueShownWidget(Widget* shown) { mShownWidgets.push(shown); } void Gui::widgetDied(Widget* widget) { std::queue tmp; while(!mShownWidgets.empty()) { Widget* shownWidget = mShownWidgets.front(); if (shownWidget != widget) { tmp.push(shownWidget); } mShownWidgets.pop(); } mShownWidgets = tmp; tmp = std::queue(); while(!mHiddenWidgets.empty()) { Widget* hiddenWidget = mHiddenWidgets.front(); if (hiddenWidget != widget) { tmp.push(hiddenWidget); } mHiddenWidgets.pop(); } mHiddenWidgets = tmp; } void Gui::handleMouseInput() { while (!mInput->isMouseQueueEmpty()) { MouseInput mouseInput = mInput->dequeueMouseInput(); switch (mouseInput.getType()) { case MouseInput::Pressed: handleMousePressed(mouseInput); break; case MouseInput::Released: handleMouseReleased(mouseInput); break; case MouseInput::Moved: handleMouseMoved(mouseInput); break; case MouseInput::WheelMovedDown: handleMouseWheelMovedDown(mouseInput); break; case MouseInput::WheelMovedUp: handleMouseWheelMovedUp(mouseInput); break; case MouseInput::WheelMovedRight: handleMouseWheelMovedRight(mouseInput); break; case MouseInput::WheelMovedLeft: handleMouseWheelMovedLeft(mouseInput); break; default: throw FCN_EXCEPTION("Unknown mouse input type."); break; } // Save the current mouse state. It's needed to send // mouse exited events and mouse entered events when // the mouse exits a widget and when a widget releases // modal mouse input focus. mLastMouseX = mouseInput.getX(); mLastMouseY = mouseInput.getY(); } } void Gui::handleKeyInput() { while (!mInput->isKeyQueueEmpty()) { KeyInput keyInput = mInput->dequeueKeyInput(); // Save modifiers state mShiftPressed = keyInput.isShiftPressed(); mMetaPressed = keyInput.isMetaPressed(); mControlPressed = keyInput.isControlPressed(); mAltPressed = keyInput.isAltPressed(); KeyEvent keyEventToGlobalKeyListeners(NULL, NULL, mShiftPressed, mControlPressed, mAltPressed, mMetaPressed, keyInput.getType(), keyInput.isNumericPad(), keyInput.getKey()); distributeKeyEventToGlobalKeyListeners(keyEventToGlobalKeyListeners); // If a global key listener consumes the event it will not be // sent further to the source of the event. if (keyEventToGlobalKeyListeners.isConsumed()) { continue; } bool keyEventConsumed = false; // Send key inputs to the focused widgets if (mFocusHandler->getFocused() != NULL) { Widget* source = getKeyEventSource(); KeyEvent keyEvent(source, source, mShiftPressed, mControlPressed, mAltPressed, mMetaPressed, keyInput.getType(), keyInput.isNumericPad(), keyInput.getKey()); if (!mFocusHandler->getFocused()->isFocusable()) mFocusHandler->focusNone(); else distributeKeyEvent(keyEvent); keyEventConsumed = keyEvent.isConsumed(); } // If the key event hasn't been consumed and // tabbing is enable check for tab press and // change focus. if (!keyEventConsumed && mTabbing && keyInput.getKey().getValue() == Key::Tab && keyInput.getType() == KeyInput::Pressed) { if (keyInput.isShiftPressed()) mFocusHandler->tabPrevious(); else mFocusHandler->tabNext(); } } } void Gui::handleMouseMoved(const MouseInput& mouseInput) { // Get tha last widgets with the mouse using the // last known mouse position. std::set mLastWidgetsWithMouse = getWidgetsAt(mLastMouseX, mLastMouseY); // Check if the mouse has left the application window. if (mouseInput.getX() < 0 || mouseInput.getY() < 0 || !mTop->getDimension().isContaining(mouseInput.getX(), mouseInput.getY())) { std::set::const_iterator iter; for (iter = mLastWidgetsWithMouse.begin(); iter != mLastWidgetsWithMouse.end(); iter++) { distributeMouseEvent((*iter), MouseEvent::Exited, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY(), true, true); } } // The mouse is in the application window. else { // Calculate which widgets should receive a mouse exited event // and which should receive a mouse entered event by using the // last known mouse position and the latest mouse position. std::set mWidgetsWithMouse = getWidgetsAt(mouseInput.getX(), mouseInput.getY()); std::set mWidgetsWithMouseExited; std::set mWidgetsWithMouseEntered; std::set_difference(mLastWidgetsWithMouse.begin(), mLastWidgetsWithMouse.end(), mWidgetsWithMouse.begin(), mWidgetsWithMouse.end(), std::inserter(mWidgetsWithMouseExited, mWidgetsWithMouseExited.begin())); std::set_difference(mWidgetsWithMouse.begin(), mWidgetsWithMouse.end(), mLastWidgetsWithMouse.begin(), mLastWidgetsWithMouse.end(), std::inserter(mWidgetsWithMouseEntered, mWidgetsWithMouseEntered.begin())); std::set::const_iterator iter; for (iter = mWidgetsWithMouseExited.begin(); iter != mWidgetsWithMouseExited.end(); iter++) { distributeMouseEvent((*iter), MouseEvent::Exited, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY(), true, true); // As the mouse has exited a widget we need // to reset the click count and the last mouse // press time stamp. mClickCount = 1; mLastMousePressTimeStamp = 0; } for (iter = mWidgetsWithMouseEntered.begin(); iter != mWidgetsWithMouseEntered.end(); iter++) { Widget* widget = (*iter); // If a widget has modal mouse input focus we // only want to send entered events to that widget // and the widget's parents. if ((mFocusHandler->getModalMouseInputFocused() != NULL && widget->isModalMouseInputFocused()) || mFocusHandler->getModalMouseInputFocused() == NULL) { distributeMouseEvent(widget, MouseEvent::Entered, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY(), true, true); } } } if (mFocusHandler->getDraggedWidget() != NULL) { distributeMouseEvent(mFocusHandler->getDraggedWidget(), MouseEvent::Dragged, mLastMouseDragButton, mouseInput.getX(), mouseInput.getY()); } else { Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); distributeMouseEvent(sourceWidget, MouseEvent::Moved, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); } } void Gui::handleMousePressed(const MouseInput& mouseInput) { Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); if (mFocusHandler->getDraggedWidget() != NULL) sourceWidget = mFocusHandler->getDraggedWidget(); int sourceWidgetX, sourceWidgetY; sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); if ((mFocusHandler->getModalFocused() != NULL && sourceWidget->isModalFocused()) || mFocusHandler->getModalFocused() == NULL) { sourceWidget->requestFocus(); } if (mouseInput.getTimeStamp() - mLastMousePressTimeStamp < 250 && mLastMousePressButton == mouseInput.getButton()) mClickCount++; else mClickCount = 1; distributeMouseEvent(sourceWidget, MouseEvent::Pressed, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); mFocusHandler->setLastWidgetPressed(sourceWidget); mFocusHandler->setDraggedWidget(sourceWidget); mLastMouseDragButton = mouseInput.getButton(); mLastMousePressButton = mouseInput.getButton(); mLastMousePressTimeStamp = mouseInput.getTimeStamp(); } void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput) { Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); if (mFocusHandler->getDraggedWidget() != NULL) sourceWidget = mFocusHandler->getDraggedWidget(); int sourceWidgetX, sourceWidgetY; sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); distributeMouseEvent(sourceWidget, MouseEvent::WheelMovedDown, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); } void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput) { Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); if (mFocusHandler->getDraggedWidget() != NULL) sourceWidget = mFocusHandler->getDraggedWidget(); int sourceWidgetX, sourceWidgetY; sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); distributeMouseEvent(sourceWidget, MouseEvent::WheelMovedUp, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); } void Gui::handleMouseWheelMovedRight(const MouseInput& mouseInput) { Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); if (mFocusHandler->getDraggedWidget() != NULL) sourceWidget = mFocusHandler->getDraggedWidget(); int sourceWidgetX, sourceWidgetY; sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); distributeMouseEvent(sourceWidget, MouseEvent::WheelMovedRight, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); } void Gui::handleMouseWheelMovedLeft(const MouseInput& mouseInput) { Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); if (mFocusHandler->getDraggedWidget() != NULL) sourceWidget = mFocusHandler->getDraggedWidget(); int sourceWidgetX, sourceWidgetY; sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); distributeMouseEvent(sourceWidget, MouseEvent::WheelMovedLeft, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); } void Gui::handleMouseReleased(const MouseInput& mouseInput) { Widget* sourceWidget = getMouseEventSource(mouseInput.getX(), mouseInput.getY()); if (mFocusHandler->getDraggedWidget() != NULL) { if (sourceWidget != mFocusHandler->getLastWidgetPressed()) mFocusHandler->setLastWidgetPressed(NULL); sourceWidget = mFocusHandler->getDraggedWidget(); } int sourceWidgetX, sourceWidgetY; sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); distributeMouseEvent(sourceWidget, MouseEvent::Released, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); if (mouseInput.getButton() == mLastMousePressButton && mFocusHandler->getLastWidgetPressed() == sourceWidget) { distributeMouseEvent(sourceWidget, MouseEvent::Clicked, mouseInput.getButton(), mouseInput.getX(), mouseInput.getY()); mFocusHandler->setLastWidgetPressed(NULL); } else { mLastMousePressButton = 0; mClickCount = 0; } if (mFocusHandler->getDraggedWidget() != NULL) mFocusHandler->setDraggedWidget(NULL); } Widget* Gui::getWidgetAt(int x, int y, Widget* exclude) { // If the widget's parent has no child then we have found the widget.. Widget* parent = mTop; Widget* child = mTop; while (child != NULL) { Widget* swap = child; int parentX, parentY; parent->getAbsolutePosition(parentX, parentY); child = parent->getWidgetAt(x - parentX, y - parentY, exclude); parent = swap; } return parent; } std::set Gui::getWidgetsAt(int x, int y) { std::set result; Widget* widget = mTop; while (widget != NULL) { result.insert(widget); int absoluteX, absoluteY; widget->getAbsolutePosition(absoluteX, absoluteY); widget = widget->getWidgetAt(x - absoluteX, y - absoluteY); } return result; } Widget* Gui::getMouseEventSource(int x, int y) { Widget* widget = getWidgetAt(x, y); if (mFocusHandler->getModalMouseInputFocused() != NULL && !widget->isModalMouseInputFocused()) return mFocusHandler->getModalMouseInputFocused(); return widget; } Widget* Gui::getKeyEventSource() { Widget* widget = mFocusHandler->getFocused(); while (widget->_getInternalFocusHandler() != NULL && widget->_getInternalFocusHandler()->getFocused() != NULL) { widget = widget->_getInternalFocusHandler()->getFocused(); } return widget; } void Gui::distributeMouseEvent(Widget* source, int type, int button, int x, int y, bool force, bool toSourceOnly) { Widget* parent = source; Widget* widget = source; if (mFocusHandler->getModalFocused() != NULL && !widget->isModalFocused() && !force) return; if (mFocusHandler->getModalMouseInputFocused() != NULL && !widget->isModalMouseInputFocused() && !force) return; MouseEvent mouseEvent(source, source, mShiftPressed, mControlPressed, mAltPressed, mMetaPressed, type, button, x, y, mClickCount); while (parent != NULL) { // If the widget has been removed due to input // cancel the distribution. if (!Widget::widgetExists(widget)) break; parent = widget->getParent(); if (widget->isEnabled() || force) { int widgetX, widgetY; widget->getAbsolutePosition(widgetX, widgetY); mouseEvent.mX = x - widgetX; mouseEvent.mY = y - widgetY; mouseEvent.mDistributor = widget; std::list mouseListeners = widget->_getMouseListeners(); // Send the event to all mouse listeners of the widget. for (std::list::iterator it = mouseListeners.begin(); it != mouseListeners.end(); ++it) { switch (mouseEvent.getType()) { case MouseEvent::Entered: (*it)->mouseEntered(mouseEvent); break; case MouseEvent::Exited: (*it)->mouseExited(mouseEvent); break; case MouseEvent::Moved: (*it)->mouseMoved(mouseEvent); break; case MouseEvent::Pressed: (*it)->mousePressed(mouseEvent); break; case MouseEvent::Released: (*it)->mouseReleased(mouseEvent); break; case MouseEvent::WheelMovedUp: (*it)->mouseWheelMovedUp(mouseEvent); break; case MouseEvent::WheelMovedDown: (*it)->mouseWheelMovedDown(mouseEvent); break; case MouseEvent::WheelMovedRight: (*it)->mouseWheelMovedRight(mouseEvent); break; case MouseEvent::WheelMovedLeft: (*it)->mouseWheelMovedLeft(mouseEvent); break; case MouseEvent::Dragged: (*it)->mouseDragged(mouseEvent); break; case MouseEvent::Clicked: (*it)->mouseClicked(mouseEvent); break; default: throw FCN_EXCEPTION("Unknown mouse event type."); } } if (toSourceOnly) break; } Widget* swap = widget; widget = parent; parent = swap->getParent(); // If a non modal focused widget has been reach // and we have modal focus cancel the distribution. if (mFocusHandler->getModalFocused() != NULL && widget != NULL && !widget->isModalFocused()) break; // If a non modal mouse input focused widget has been reach // and we have modal mouse input focus cancel the distribution. if (mFocusHandler->getModalMouseInputFocused() != NULL && widget != NULL && !widget->isModalMouseInputFocused()) break; } } void Gui::distributeKeyEvent(KeyEvent& keyEvent) { Widget* parent = keyEvent.getSource(); Widget* widget = keyEvent.getSource(); if (mFocusHandler->getModalFocused() != NULL && !widget->isModalFocused()) return; while (parent != NULL) { // If the widget has been removed due to input // cancel the distribution. if (!Widget::widgetExists(widget)) break; parent = widget->getParent(); if (widget->isEnabled()) { keyEvent.mDistributor = widget; std::list keyListeners = widget->_getKeyListeners(); // Send the event to all key listeners of the source widget. for (std::list::iterator it = keyListeners.begin(); it != keyListeners.end(); ++it) { switch (keyEvent.getType()) { case KeyEvent::Pressed: (*it)->keyPressed(keyEvent); break; case KeyEvent::Released: (*it)->keyReleased(keyEvent); break; default: throw FCN_EXCEPTION("Unknown key event type."); } } } Widget* swap = widget; widget = parent; parent = swap->getParent(); // If a non modal focused widget has been reach // and we have modal focus cancel the distribution. if (mFocusHandler->getModalFocused() != NULL && !widget->isModalFocused()) break; } } void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent) { KeyListenerListIterator it; for (it = mKeyListeners.begin(); it != mKeyListeners.end(); it++) { switch (keyEvent.getType()) { case KeyEvent::Pressed: (*it)->keyPressed(keyEvent); break; case KeyEvent::Released: (*it)->keyReleased(keyEvent); break; default: throw FCN_EXCEPTION("Unknown key event type."); } if (keyEvent.isConsumed()) break; } } void Gui::handleModalMouseInputFocus() { // Check if modal mouse input focus has been gained by a widget. if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() != mFocusHandler->getModalMouseInputFocused()) && (mFocusHandler->getLastWidgetWithModalMouseInputFocus() == NULL)) { handleModalMouseInputFocusGained(); } // Check if modal mouse input focus has been released. else if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() != mFocusHandler->getModalMouseInputFocused()) && (mFocusHandler->getLastWidgetWithModalMouseInputFocus() != NULL)) { handleModalMouseInputFocusReleased(); } } void Gui::handleModalFocus() { // Check if modal focus has been gained by a widget. if ((mFocusHandler->getLastWidgetWithModalFocus() != mFocusHandler->getModalFocused()) && (mFocusHandler->getLastWidgetWithModalFocus() == NULL)) { handleModalFocusGained(); } // Check if modal focus has been released. else if ((mFocusHandler->getLastWidgetWithModalFocus() != mFocusHandler->getModalFocused()) && (mFocusHandler->getLastWidgetWithModalFocus() != NULL)) { handleModalFocusReleased(); } } void Gui::handleModalFocusGained() { // Get all widgets at the last known mouse position // and send them a mouse exited event. std::set mWidgetsWithMouse = getWidgetsAt(mLastMouseX, mLastMouseY); std::set::const_iterator iter; for (iter = mWidgetsWithMouse.begin(); iter != mWidgetsWithMouse.end(); iter++) { if ((*iter)->isModalFocused() || (*iter)->isModalMouseInputFocused()) { continue; } distributeMouseEvent((*iter), MouseEvent::Exited, mLastMousePressButton, mLastMouseX, mLastMouseY, true, true); } mFocusHandler->setLastWidgetWithModalFocus(mFocusHandler->getModalFocused()); } void Gui::handleModalFocusReleased() { // Get all widgets at the last known mouse position // and send them a mouse entered event. std::set mWidgetsWithMouse = getWidgetsAt(mLastMouseX, mLastMouseY); std::set::const_iterator iter; for (iter = mWidgetsWithMouse.begin(); iter != mWidgetsWithMouse.end(); iter++) { distributeMouseEvent((*iter), MouseEvent::Entered, mLastMousePressButton, mLastMouseX, mLastMouseY, false, true); } mFocusHandler->setLastWidgetWithModalFocus(NULL); } void Gui::handleModalMouseInputFocusGained() { // Get all widgets at the last known mouse position // and send them a mouse exited event. std::set mWidgetsWithMouse = getWidgetsAt(mLastMouseX, mLastMouseY); std::set::const_iterator iter; for (iter = mWidgetsWithMouse.begin(); iter != mWidgetsWithMouse.end(); iter++) { if ((*iter)->isModalMouseInputFocused()) { continue; } distributeMouseEvent((*iter), MouseEvent::Exited, mLastMousePressButton, mLastMouseX, mLastMouseY, true, true); } mFocusHandler->setLastWidgetWithModalMouseInputFocus(mFocusHandler->getModalMouseInputFocused()); } void Gui::handleModalMouseInputFocusReleased() { // Get all widgets at the last known mouse position // and send them a mouse entered event. std::set mWidgetsWithMouse = getWidgetsAt(mLastMouseX, mLastMouseY); std::set::const_iterator iter; for (iter = mWidgetsWithMouse.begin(); iter != mWidgetsWithMouse.end(); iter++) { distributeMouseEvent((*iter), MouseEvent::Entered, mLastMousePressButton, mLastMouseX, mLastMouseY, false, true); } mFocusHandler->setLastWidgetWithModalMouseInputFocus(NULL); } void Gui::handleHiddenWidgets() { //process each hidden widget in queue while(!mHiddenWidgets.empty()) { //if the hidden widget had the mouse cursor inside Widget* hiddenWidget = mHiddenWidgets.front(); //make sure that the widget wasn't freed after hiding if(Widget::widgetExists(hiddenWidget) && hiddenWidget->isEnabled()) { int hiddenWidgetX, hiddenWidgetY; hiddenWidget->getAbsolutePosition(hiddenWidgetX, hiddenWidgetY); Rectangle r(hiddenWidgetX, hiddenWidgetY, hiddenWidget->getWidth(), hiddenWidget->getHeight()); if(r.isContaining(mLastMouseX, mLastMouseY)) { //get the widget that has the cursor now and distribute that the mouse entered it Widget* underMouseCursor = getWidgetAt(mLastMouseX, mLastMouseY); distributeMouseEvent(underMouseCursor, MouseEvent::Entered, MouseEvent::Empty, mLastMouseX, mLastMouseY, true, true); } } mHiddenWidgets.pop(); } } void Gui::handleShownWidgets() { //process each shown widget in queue while(!mShownWidgets.empty()) { Widget* shownWidget = mShownWidgets.front(); //if the shown widget has the mouse cursor inside it int shownWidgetX, shownWidgetY; shownWidget->getAbsolutePosition(shownWidgetX, shownWidgetY); Rectangle r(shownWidgetX, shownWidgetY, shownWidget->getWidth(), shownWidget->getHeight()); if(r.isContaining(mLastMouseX, mLastMouseY) && shownWidget->isEnabled()) { //find which widget had the mouse before and distribute that the mouse exited it Widget* underMouseCursorBefore = getWidgetAt(mLastMouseX, mLastMouseY, shownWidget); distributeMouseEvent(underMouseCursorBefore, MouseEvent::Exited, MouseEvent::Empty, mLastMouseX, mLastMouseY, true, true ); //find which specific widget in the shown widget had the mouse before //and distribute that the mouse exited it Widget* underMouseCursorNow = getWidgetAt(mLastMouseX, mLastMouseY); distributeMouseEvent(underMouseCursorNow, MouseEvent::Entered, MouseEvent::Empty, mLastMouseX, mLastMouseY, true, true ); } mShownWidgets.pop(); } } } fifechan-0.1.5/src/hge/000077500000000000000000000000001341577075500146305ustar00rootroot00000000000000fifechan-0.1.5/src/hge/hgegraphics.cpp000066400000000000000000000261721341577075500176300ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/hge/hgegraphics.hpp" #include "fifechan/cliprectangle.hpp" #include "fifechan/exception.hpp" #include "fifechan/rectangle.hpp" #include "fifechan/hge/hgeimage.hpp" namespace fcn { HGE *HGEGraphics::mHGE = NULL; HGEGraphics::HGEGraphics() :mClipNull(false) { mHGE = hgeCreate(HGE_VERSION); mHardwareColor = 0; } HGEGraphics::~HGEGraphics() { mHGE->Release(); } void HGEGraphics::_beginDraw() { pushClipArea(Rectangle(0, 0, mHGE->System_GetState(HGE_SCREENWIDTH), mHGE->System_GetState(HGE_SCREENHEIGHT))); } void HGEGraphics::_endDraw() { // pop the clip area pushed in _beginDraw popClipArea(); } bool HGEGraphics::pushClipArea(Rectangle area) { bool result = Graphics::pushClipArea(area); const ClipRectangle top = mClipStack.top(); // HGE won't let you set clip areas // that have zero width or height // so we have to check for that. if (top.width == 0 || top.height == 0) { mClipNull = true; } else { mClipNull = false; mHGE->Gfx_SetTransform(top.xOffset, top.yOffset); mHGE->Gfx_SetClipping(top.x, top.y, top.width, top.height); } return result; } void HGEGraphics::popClipArea() { Graphics::popClipArea(); if (mClipStack.empty()) { mHGE->Gfx_SetClipping(); return; } else { const ClipRectangle top = mClipStack.top(); // HGE won't let you set clip areas //that have zero width or height // so we have to check for that. if (top.width == 0 || top.height == 0) { mClipNull = true; } else { mClipNull = false; mHGE->Gfx_SetTransform(top.xOffset, top.yOffset); mHGE->Gfx_SetClipping(top.x, top.y, top.width, top.height); } } } void HGEGraphics::drawImage(const Image *image, int srcX, int srcY, int dstX, int dstY, int width, int height) { if (mClipNull) { return; } const HGEImage *hgeImage = static_cast(image); if (hgeImage == NULL) { throw FCN_EXCEPTION("Trying to draw an image of unknown format, must be an HGEImage."); } ClipRectangle const top = mClipStack.top(); dstX += top.xOffset; dstY += top.yOffset; hgeImage->getSprite()->SetTextureRect(srcX, srcY, width, height); hgeImage->getSprite()->Render(dstX, dstY); } void HGEGraphics::drawImage(const Image *image, int dstX, int dstY) { if (mClipNull) { return; } drawImage(image, 0, 0, dstX, dstY, image->getWidth(), image->getHeight()); } void HGEGraphics::drawPoint(int x, int y) { if (mClipNull) { return; } ClipRectangle const top = mClipStack.top(); x += top.xOffset; y += top.yOffset; mHGE->Gfx_RenderLine(x, y, x + 1, y, mHardwareColor); } void HGEGraphics::drawLine(int x1, int y1, int x2, int y2) { if (mClipNull) { return; } // As HGE omits the last pixel we need to adjust the coordinates // before drawing the line. If it's a vertical or horizontal line // all we have to do is add the omitted pixel. if (y1 == y2 || x1 == x2) { x2++; y2++; } // If it's not a vertical or horizontal line it gets a little bit // trickier. else { // If y2 is greater than y1 then we know y2 will be omitted as // it will be a part of the last pixel coordinate. if (y2 > y1) { y2++; } // Else will y1 be omitted. else { y1++; } // The same thing applies for the x coordinates. If x2 is greater // than x1 then we know x2 will be omitted as it will be a part of // the last pixel coordinate. if (x2 > x1) { x2++; } // Else will x1 be omitted. else { x1++; } } ClipRectangle const top = mClipStack.top(); x1 += top.xOffset; y1 += top.yOffset; x2 += top.xOffset; y2 += top.yOffset; mHGE->Gfx_RenderLine(x1, y1, x2, y2, mHardwareColor); } void HGEGraphics::drawRectangle(const Rectangle &rectangle) { if (mClipNull) { return; } int x1 = rectangle.x; int y1 = rectangle.y; int x2 = rectangle.x + rectangle.width; int y2 = rectangle.y + rectangle.height; ClipRectangle const top = mClipStack.top(); x1 += top.xOffset; y1 += top.yOffset; x2 += top.xOffset; y2 += top.yOffset; mHGE->Gfx_RenderLine(x1, y1 + 1, x2, y1, mHardwareColor); mHGE->Gfx_RenderLine(x2, y1 + 1, x2, y2 - 1, mHardwareColor); mHGE->Gfx_RenderLine(x2, y2, x1 + 1, y2, mHardwareColor); mHGE->Gfx_RenderLine(x1 + 1, y2, x1 + 1, y1 + 1, mHardwareColor); } void HGEGraphics::fillRectangle(const Rectangle &rectangle) { if (mClipNull) { return; } // We need to compensate for the fact that HGE doesn't // seem to include the the coordinate pixels when rendering // a quad. int x1 = rectangle.x; int y1 = rectangle.y; int x2 = rectangle.x + rectangle.width; int y2 = rectangle.y + rectangle.height; ClipRectangle const top = mClipStack.top(); x1 += top.xOffset; y1 += top.yOffset; x2 += top.xOffset; y2 += top.yOffset; hgeQuad quad; quad.tex = NULL; quad.v[0].x = x1; quad.v[0].y = y1; quad.v[0].col = mHardwareColor; quad.v[1].x = x2; quad.v[1].y = y1; quad.v[1].col = mHardwareColor; quad.v[2].x = x2; quad.v[2].y = y2; quad.v[2].col = mHardwareColor; quad.v[3].x = x1; quad.v[3].y = y2; quad.v[3].col = mHardwareColor; int i; for (i = 0; i < 4; ++i) { quad.v[i].z = 0.5f; } quad.blend = BLEND_DEFAULT; mHGE->Gfx_RenderQuad(&quad); } void HGEGraphics::setColor(const Color &color) { mColor = color; mHardwareColor = ARGB(color.a, color.r, color.g, color.b); } const Color& HGEGraphics::getColor() const { return mColor; } } fifechan-0.1.5/src/hge/hgeimage.cpp000066400000000000000000000151561341577075500171120ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/hge/hgeimage.hpp" #include "fifechan/exception.hpp" namespace fcn { HGE *HGEImage::mHGE = NULL; HGEImage::HGEImage(HTEXTURE texture, bool autoFree) : mTexture(texture), mAutoFree(autoFree) { mHGE = hgeCreate(HGE_VERSION); } HGEImage::~HGEImage() { if (mAutoFree) { free(); } mHGE->Release(); } void HGEImage::free() { if (mHGESprite != NULL) { delete mHGESprite; mHGESprite = NULL; } mHGE->Texture_Free(mTexture); } hgeSprite *HGEImage::getSprite() const { return mHGESprite; } int HGEImage::getWidth() const { return mHGE->Texture_GetWidth(mTexture, true); } int HGEImage::getHeight() const { return mHGE->Texture_GetHeight(mTexture, true); } Color HGEImage::getPixel(int x, int y) { DWORD *pLockPtr = mHGE->Texture_Lock(mTexture); if (pLockPtr == NULL) { throw FCN_EXCEPTION("Locking of the texture failed. HGE only support locking of 32bit textures."); } DWORD color = pLockPtr[x + y * mHGE->Texture_GetWidth(mTexture, true)]; mHGE->Texture_Unlock(mTexture); return Color(GETR(color), GETG(color), GETB(color), GETA(color )); } void HGEImage::putPixel(int x, int y, const Color& color) { DWORD hardwareColor = ARGB(color.a, color.r, color.g, color.b); DWORD *pLockPtr = mHGE->Texture_Lock(mTexture, false); if (pLockPtr == NULL) { throw FCN_EXCEPTION("Locking of the texture failed. HGE only support locking of 32bit textures."); } pLockPtr[x + y * mHGE->Texture_GetWidth(mTexture, true)] = hardwareColor; mHGE->Texture_Unlock(mTexture); } void HGEImage::convertToDisplayFormat() { DWORD *pLockPtr = mHGE->Texture_Lock(mTexture); if (pLockPtr == NULL) { throw FCN_EXCEPTION("Locking of the texture failed. HGE only support locking of 32bit textures."); } int i; int end = mHGE->Texture_GetWidth(mTexture, true) * mHGE->Texture_GetHeight(mTexture, true); for (i = 0; i < end; i++) { DWORD color = pLockPtr[i]; if (GETR(color) == 0xFF && GETG(color) == 0x00 && GETB(color) == 0xFF) { pLockPtr[i] = ARGB(0x00, 0x00, 0x00, 0x00); } } mHGE->Texture_Unlock(mTexture); mHGESprite = new hgeSprite(mTexture, 0, 0, mHGE->Texture_GetWidth(mTexture, true), mHGE->Texture_GetHeight(mTexture, true)); } } fifechan-0.1.5/src/hge/hgeimagefont.cpp000066400000000000000000000124271341577075500177770ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/hge/hgeimagefont.hpp" #include "fifechan/color.hpp" #include "fifechan/graphics.hpp" namespace fcn { HGEImageFont::HGEImageFont(const std::string& filename) { mHGEFont = new hgeFont(filename.c_str()); } HGEImageFont::~HGEImageFont() { delete mHGEFont; } hgeFont *HGEImageFont::getFont() const { return mHGEFont; } int HGEImageFont::getWidth(const std::string &text) const { return static_cast(mHGEFont->GetStringWidth(text.c_str())) + 1; } int HGEImageFont::getWidth(char character) const { char buf[2]; sprintf(buf, "%c", character); return mHGEFont->GetStringWidth(buf); } int HGEImageFont::getHeight() const { return static_cast(mHGEFont->GetHeight()); } int HGEImageFont::getStringIndexAt(const std::string& text, int x) const { unsigned int i; int size = 0; for (i = 0; i < text.size(); ++i) { size += getWidth(text.at(i)); if (size > x) { return i; } } return text.size(); } void HGEImageFont::drawString(Graphics *graphics, const std::string &text, int x, int y) { ClipRectangle const &top = graphics->getCurrentClipArea(); x += top.xOffset; y += top.yOffset; Color color = graphics->getColor(); mHGEFont->SetColor(ARGB(color.a, color.r, color.g, color.b)); mHGEFont->Render(x, y, HGETEXT_LEFT, text.c_str()); } } fifechan-0.1.5/src/hge/hgeimageloader.cpp000066400000000000000000000120011341577075500202630ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/hge/hgeimage.hpp" #include "fifechan/hge/hgeimageloader.hpp" #include "fifechan/exception.hpp" namespace fcn { HGE *HGEImageLoader::mHGE = NULL; HGEImageLoader::HGEImageLoader() { mHGE = hgeCreate(HGE_VERSION); } HGEImageLoader::~HGEImageLoader() { mHGE->Release(); } Image *HGEImageLoader::load(const std::string &filename, bool convertToDisplayFormat) { HTEXTURE texture = mHGE->Texture_Load(filename.c_str()); if (texture == NULL) { throw FCN_EXCEPTION(std::string("Unable to load: ") + filename); } HGEImage *image = new HGEImage(texture, true); if (convertToDisplayFormat) { image->convertToDisplayFormat(); } return image; } Image *HGEImageLoader::load(hgeResourceManager* manager, char* name, int resgroup, bool convertToDisplayFormat) { HTEXTURE texture = manager->GetTexture(name, resgroup); if (texture == NULL) { throw FCN_EXCEPTION(std::string("Unable to load: ") + name); } HGEImage *image = new HGEImage(texture, true); if (convertToDisplayFormat) { image->convertToDisplayFormat(); } return image; } } fifechan-0.1.5/src/hge/hgeinput.cpp000066400000000000000000000332311341577075500171610ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/hge/hgeinput.hpp" #include "fifechan/exception.hpp" namespace fcn { HGE *HGEInput::mHGE = NULL; HGEInput::HGEInput() { mHGE = hgeCreate(HGE_VERSION); mMouseX = 0; mMouseY = 0; mLeftMouseButtonDown = false; mRightMouseButtonDown = false; mMiddleMouseButtonDown = false; } HGEInput::~HGEInput() { mHGE->Release(); } bool HGEInput::isKeyQueueEmpty() { return mKeyInputQueue.empty(); } bool HGEInput::isMouseQueueEmpty() { return mMouseInputQueue.empty(); } KeyInput HGEInput::dequeueKeyInput() { if (isKeyQueueEmpty()) { throw FCN_EXCEPTION("Key queue is empty."); } KeyInput keyInput; keyInput = mKeyInputQueue.front(); mKeyInputQueue.pop(); return keyInput; } MouseInput HGEInput::dequeueMouseInput() { if (isMouseQueueEmpty()) { throw FCN_EXCEPTION("Mouse queue is empty."); } MouseInput mouseInput; mouseInput = mMouseInputQueue.front(); mMouseInputQueue.pop(); return mouseInput; } void HGEInput::_pollInput() { hgeInputEvent ie; while (mHGE->Input_GetEvent(&ie) pollKeyInput(ie); pollMouseInput(); } void HGEInput::pollMouseInput() { float curMouseX, curMouseY; int mouseWheel; bool leftBtn, rightBtn, centerBtn; mHGE->Input_GetMousePos(&curMouseX, &curMouseY); mouseWheel = mHGE->Input_GetMouseWheel(); leftBtn = mHGE->Input_GetKeyState(HGEK_LBUTTON); rightBtn = mHGE->Input_GetKeyState(HGEK_RBUTTON); centerBtn = mHGE->Input_GetKeyState(HGEK_MBUTTON); // Check mouse movement if (mMouseX != curMouseX || mMouseY != curMouseY) { mMouseInputQueue.push(MouseInput(MouseInput::Empty, MouseInput::Moved, curMouseX, curMouseY, 0)); mMouseX = curMouseX; mMouseY = curMouseY; } // Check mouse wheel if (mouseWheel > 0) { mMouseInputQueue.push(MouseInput(MouseInput::Empty, MouseInput::WheelMovedUp, curMouseX, curMouseY, 0)); } else if (mouseWheel < 0) { mMouseInputQueue.push(MouseInput(MouseInput::Empty, MouseInput::WheelMovedDown, curMouseX, curMouseY, 0)); } //check mouse buttons if (!mLeftMouseButtonDown && leftBtn) { mMouseInputQueue.push(MouseInput(MouseInput::Left, MouseInput::Pressed, curMouseX, curMouseY, 0)); } else if (mLeftMouseButtonDown && !leftBtn ) { mMouseInputQueue.push(MouseInput(MouseInput::Left, MouseInput::Released, curMouseX, curMouseY, 0)); } else if (!mRightMouseButtonDown && rightBtn) { mMouseInputQueue.push(MouseInput(MouseInput::Right, MouseInput::Pressed, curMouseX, curMouseY, 0)); } else if (mRightMouseButtonDown && !rightBtn) { mMouseInputQueue.push(MouseInput(MouseInput::Right, MouseInput::Released, curMouseX, curMouseY, 0)); } else if (!mMiddleMouseButtonDown && centerBtn) { mMouseInputQueue.push(MouseInput(MouseInput::Middle, MouseInput::Pressed, curMouseX, curMouseY, 0)); } else if (mMiddleMouseButtonDown && !centerBtn) { mMouseInputQueue.push(MouseInput(MouseInput::Middle, MouseInput::Released, curMouseX, curMouseY, 0)); } mLeftMouseButtonDown = leftBtn; mRightMouseButtonDown = rightBtn; mMiddleMouseButtonDown = centerBtn; } void HGEInput::pollKeyInput(hgeInputEvent &ki) { if (ki.type != INPUT_KEYDOWN && ki.type != INPUT_KEYUP ) { return ; } if (ki.type == INPUT_KEYDOWN) { Key keyObj = convertToKey(ki.key, ki.chr); KeyInput keyInput(keyObj, KeyInput::Pressed); keyInput.setNumericPad(isNumericPad(ki.key)); keyInput.setShiftPressed(ki.flags & HGEINP_SHIFT); keyInput.setAltPressed(ki.flags & HGEINP_ALT); keyInput.setControlPressed(ki.flags & HGEINP_CTRL); mKeyInputQueue.push(keyInput); } if (ki.type == INPUT_KEYUP) { Key keyObj = convertToKey(ki.key, ki.chr); KeyInput keyInput(keyObj, KeyInput::Released); keyInput.setNumericPad(isNumericPad(ki.key)); keyInput.setShiftPressed(ki.flags & HGEINP_SHIFT); keyInput.setAltPressed(ki.flags & HGEINP_ALT); keyInput.setControlPressed(ki.flags & HGEINP_CTRL); mKeyInputQueue.push(keyInput); } } Key HGEInput::convertToKey(int key, int chr) { int keysym; switch(key) { case HGEK_TAB: keysym = Key::Tab; break; case HGEK_ESCAPE: keysym = Key::Escape; break; case HGEK_ALT: keysym = Key::LeftAlt; break; case HGEK_SHIFT: keysym = Key::LeftShift; break; case HGEK_CTRL: keysym = Key::LeftControl; break; case HGEK_LWIN: keysym = Key::LeftMeta; break; case HGEK_RWIN: keysym = Key::RightMeta; break; case HGEK_INSERT: keysym = Key::Insert; break; case HGEK_HOME: keysym = Key::Home; break; case HGEK_PGUP: keysym = Key::PageUp; break; case HGEK_PGDN: keysym = Key::PageDown; break; case HGEK_DELETE: keysym = Key::Delete; break; case HGEK_END: keysym = Key::End; break; case HGEK_CAPSLOCK: keysym = Key::CapsLock; break; case HGEK_BACKSPACE: keysym = Key::Backspace; break; case HGEK_F1: keysym = Key::F1; break; case HGEK_F2: keysym = Key::F2; break; case HGEK_F3: keysym = Key::F3; break; case HGEK_F4: keysym = Key::F4; break; case HGEK_F5: keysym = Key::F5; break; case HGEK_F6: keysym = Key::F6; break; case HGEK_F7: keysym = Key::F7; break; case HGEK_F8: keysym = Key::F8; break; case HGEK_F9: keysym = Key::F9; break; case HGEK_F10: keysym = Key::F10; break; case HGEK_F11: keysym = Key::F11; break; case HGEK_F12: keysym = Key::F12; break; case HGEK_PAUSE: keysym = Key::Pause; break; case HGEK_SCROLLLOCK: keysym = Key::ScrollLock; break; case HGEK_NUMLOCK: keysym = Key::NumLock; break; case HGEK_LEFT: keysym = Key::Left; break; case HGEK_RIGHT: keysym = Key::Right; break; case HGEK_UP: keysym = Key::Up; break; case HGEK_DOWN: keysym = Key::Down; break; case HGEK_ENTER: keysym = Key::Enter; break; default: keysym = chr; } Key k = Key(keysym); return k; } bool HGEInput::isNumericPad(int keyCode) { switch(keyCode) { case HGEK_NUMPAD0: case HGEK_NUMPAD1: case HGEK_NUMPAD2: case HGEK_NUMPAD3: case HGEK_NUMPAD4: case HGEK_NUMPAD5: case HGEK_NUMPAD6: case HGEK_NUMPAD7: case HGEK_NUMPAD8: case HGEK_NUMPAD9: return true; default: return false; } } } fifechan-0.1.5/src/image.cpp000066400000000000000000000106671341577075500156650ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/image.hpp" #include "fifechan/exception.hpp" #include "fifechan/imageloader.hpp" namespace fcn { ImageLoader* Image::mImageLoader = NULL; Image::Image() { } Image::~Image() { } void Image::setImageLoader(ImageLoader* imageLoader) { mImageLoader = imageLoader; } ImageLoader* Image::getImageLoader() { return mImageLoader; } Image* Image::load(const std::string& filename, bool convertToDisplayFormat) { if (mImageLoader == NULL) { throw FCN_EXCEPTION("Trying to load an image but no image loader is set."); } return mImageLoader->load(filename, convertToDisplayFormat); } } fifechan-0.1.5/src/imagefont.cpp000066400000000000000000000267531341577075500165570ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/imagefont.hpp" #include #include "fifechan/color.hpp" #include "fifechan/exception.hpp" #include "fifechan/graphics.hpp" #include "fifechan/image.hpp" namespace fcn { ImageFont::ImageFont(const std::string& filename, const std::string& glyphs) { mFilename = filename; mImage = Image::load(filename, false); Color separator = mImage->getPixel(0, 0); int i = 0; for (i = 0; i < mImage->getWidth() && separator == mImage->getPixel(i, 0); ++i) { } if (i >= mImage->getWidth()) { throw FCN_EXCEPTION("Corrupt image."); } int j = 0; for (j = 0; j < mImage->getHeight(); ++j) { if (separator == mImage->getPixel(i, j)) { break; } } mHeight = j; int x = 0, y = 0; unsigned char k; for (i = 0; i < (int)glyphs.size(); ++i) { k = glyphs.at(i); mGlyph[k] = scanForGlyph(k, x, y, separator); // Update x och y with new coordinates. x = mGlyph[k].x + mGlyph[k].width; y = mGlyph[k].y; } mImage->convertToDisplayFormat(); mRowSpacing = 0; mGlyphSpacing = 0; } ImageFont::ImageFont(Image* image, const std::string& glyphs) { mFilename = "Image*"; if (image == NULL) { FCN_EXCEPTION("Font image is NULL"); } mImage = image; Color separator = mImage->getPixel(0, 0); int i = 0; for (i = 0; i < mImage->getWidth() && separator == mImage->getPixel(i, 0); ++i) { } if (i >= mImage->getWidth()) { throw FCN_EXCEPTION("Corrupt image."); } int j = 0; for (j = 0; j < mImage->getHeight(); ++j) { if (separator == mImage->getPixel(i, j)) { break; } } mHeight = j; int x = 0, y = 0; unsigned char k; for (i = 0; i < (int)glyphs.size(); ++i) { k = glyphs.at(i); mGlyph[k] = scanForGlyph(k, x, y, separator); // Update x och y with new coordinates. x = mGlyph[k].x + mGlyph[k].width; y = mGlyph[k].y; } mImage->convertToDisplayFormat(); mRowSpacing = 0; mGlyphSpacing = 0; } ImageFont::ImageFont(const std::string& filename, unsigned char glyphsFrom, unsigned char glyphsTo) { mFilename = filename; mImage = Image::load(filename, false); Color separator = mImage->getPixel(0, 0); int i = 0; for (i=0; separator == mImage->getPixel(i, 0) && i < mImage->getWidth(); ++i) { } if (i >= mImage->getWidth()) { throw FCN_EXCEPTION("Corrupt image."); } int j = 0; for (j = 0; j < mImage->getHeight(); ++j) { if (separator == mImage->getPixel(i, j)) { break; } } mHeight = j; int x = 0, y = 0; for (i = glyphsFrom; i < glyphsTo + 1; i++) { mGlyph[i] = scanForGlyph(i, x, y, separator); // Update x och y with new coordinates. x = mGlyph[i].x + mGlyph[i].width; y = mGlyph[i].y; } mImage->convertToDisplayFormat(); mRowSpacing = 0; mGlyphSpacing = 0; } ImageFont::~ImageFont() { delete mImage; } int ImageFont::getWidth(unsigned char glyph) const { if (mGlyph[glyph].width == 0) { return mGlyph[(int)(' ')].width + mGlyphSpacing; } return mGlyph[glyph].width + mGlyphSpacing; } int ImageFont::getHeight() const { return mHeight + mRowSpacing; } int ImageFont::drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y) { // This is needed for drawing the glyph in the middle // if we have spacing. int yoffset = getRowSpacing() / 2; if (mGlyph[glyph].width == 0) { graphics->drawRectangle(x, y + 1 + yoffset, mGlyph[(int)(' ')].width - 1, mGlyph[(int)(' ')].height - 2); return mGlyph[(int)(' ')].width + mGlyphSpacing; } graphics->drawImage(mImage, mGlyph[glyph].x, mGlyph[glyph].y, x, y + yoffset, mGlyph[glyph].width, mGlyph[glyph].height); return mGlyph[glyph].width + mGlyphSpacing; } void ImageFont::drawString(Graphics* graphics, const std::string& text, int x, int y) { unsigned int i; for (i = 0; i < text.size(); ++i) { drawGlyph(graphics, text.at(i), x, y); x += getWidth(text.at(i)); } } void ImageFont::setRowSpacing(int spacing) { mRowSpacing = spacing; } int ImageFont::getRowSpacing() { return mRowSpacing; } void ImageFont::setGlyphSpacing(int spacing) { mGlyphSpacing = spacing; } int ImageFont::getGlyphSpacing() { return mGlyphSpacing; } Rectangle ImageFont::scanForGlyph(unsigned char glyph, int x, int y, const Color& separator) { Color color; do { ++x; if (x >= mImage->getWidth()) { y += mHeight + 1; x = 0; if (y >= mImage->getHeight()) { std::string str; std::ostringstream os(str); os << "Image "; os << mFilename; os << " with font is corrupt near character '"; os << glyph; os << "'"; throw FCN_EXCEPTION(os.str()); } } color = mImage->getPixel(x, y); } while (color == separator); int width = 0; do { ++width; if (x + width >= mImage->getWidth()) { std::string str; std::ostringstream os(str); os << "Image "; os << mFilename; os << " with font is corrupt near character '"; os << glyph; os << "'"; throw FCN_EXCEPTION(os.str()); } color = mImage->getPixel(x + width, y); } while (color != separator); return Rectangle(x, y, width, mHeight); } int ImageFont::getWidth(const std::string& text) const { unsigned int i; int size = 0; for (i = 0; i < text.size(); ++i) { size += getWidth(text.at(i)); } return size - mGlyphSpacing; } int ImageFont::getStringIndexAt(const std::string& text, int x) const { unsigned int i; int size = 0; for (i = 0; i < text.size(); ++i) { size += getWidth(text.at(i)); if (size > x) { return i; } } return text.size(); } } fifechan-0.1.5/src/inputevent.cpp000066400000000000000000000116531341577075500170000ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/inputevent.hpp" namespace fcn { InputEvent::InputEvent(Widget* source, Widget* distributor, bool isShiftPressed, bool isControlPressed, bool isAltPressed, bool isMetaPressed) :Event(source), mShiftPressed(isShiftPressed), mControlPressed(isControlPressed), mAltPressed(isAltPressed), mMetaPressed(isMetaPressed), mIsConsumed(false), mDistributor(distributor) { } bool InputEvent::isShiftPressed() const { return mShiftPressed; } bool InputEvent::isControlPressed() const { return mControlPressed; } bool InputEvent::isAltPressed() const { return mAltPressed; } bool InputEvent::isMetaPressed() const { return mMetaPressed; } void InputEvent::consume() { mIsConsumed = true; } bool InputEvent::isConsumed() const { return mIsConsumed; } Widget* InputEvent::getDistributor() const { return mDistributor; } } fifechan-0.1.5/src/irrlicht/000077500000000000000000000000001341577075500157055ustar00rootroot00000000000000fifechan-0.1.5/src/irrlicht/irrlicht.cpp000066400000000000000000000074551341577075500202440ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/irrlicht.hpp" extern "C" { void fcnIrrlicht() { } } fifechan-0.1.5/src/irrlicht/irrlichtgraphics.cpp000066400000000000000000000212541341577075500217560ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/irrlicht/irrlichtgraphics.hpp" #include "fifechan/exception.hpp" #include "fifechan/font.hpp" #include "fifechan/image.hpp" #include "fifechan/irrlicht/irrlichtimage.hpp" namespace fcn { IrrlichtGraphics::IrrlichtGraphics(irr::video::IVideoDriver* driver) : mDriver(driver) { if (mDriver) mDriver->grab(); } IrrlichtGraphics::~IrrlichtGraphics() { if (mDriver) { mDriver->drop(); mDriver = 0; } } void IrrlichtGraphics::_beginDraw() { Rectangle area; area.x = 0; area.y = 0; area.width = mDriver->getScreenSize().Width; area.height = mDriver->getScreenSize().Height; pushClipArea(area); } void IrrlichtGraphics::_endDraw() { popClipArea(); } bool IrrlichtGraphics::pushClipArea(Rectangle area) { return Graphics::pushClipArea(area); } void IrrlichtGraphics::popClipArea() { Graphics::popClipArea(); if (mClipStack.empty()) { return; } } void IrrlichtGraphics::drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); const IrrlichtImage* srcImage = dynamic_cast(image); if (srcImage == NULL) { throw FCN_EXCEPTION("Trying to draw an image of unknown format, must be an IrrlichtImage."); } irr::core::position2d destPos(dstX + top.xOffset, dstY + top.yOffset); irr::core::rect sourceRect(srcX, srcY, srcX + width, srcY + height); irr::core::rect clipRect(top.x, top.y, top.x + top.width, top.y + top.height); irr::video::SColor color(255, 255, 255, 255); mDriver->draw2DImage(srcImage->getTexture(), destPos, sourceRect, &clipRect, color, true); } void IrrlichtGraphics::fillRectangle(const Rectangle& rectangle) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); Rectangle area = rectangle; area.x += top.xOffset; area.y += top.yOffset; if(!area.isIntersecting(top)) { return; } irr::video::SColor color(mColor.a, mColor.r, mColor.g, mColor.b); irr::core::rect pos(area.x, area.y, area.x + area.width, area.y + area.height); irr::core::rect clip(top.x, top.y, top.x + top.width, top.y + top.height); mDriver->draw2DRectangle(color, pos, &clip); } void IrrlichtGraphics::drawPoint(int x, int y) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); x += top.xOffset; y += top.yOffset; if(!top.isContaining(x,y)) return; irr::video::SColor color(mColor.a, mColor.r, mColor.g, mColor.b); mDriver->drawPixel(x, y, color); } void IrrlichtGraphics::drawRectangle(const Rectangle& rectangle) { int x1 = rectangle.x; int x2 = rectangle.x + rectangle.width - 1; int y1 = rectangle.y; int y2 = rectangle.y + rectangle.height - 1; drawLine(x1, y1, x2, y1); drawLine(x2, y1, x2, y2); drawLine(x1, y1, x1, y2); drawLine(x1, y2, x2, y2); } void IrrlichtGraphics::drawLine(int x1, int y1, int x2, int y2) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); x1 += top.xOffset; y1 += top.yOffset; x2 += top.xOffset; y2 += top.yOffset; if(x2 > top.x + top.width) x2 = top.x + top.width; if(y2 > top.y + top.height) y2 = top.y + top.height; irr::core::position2d start(x1, y1); irr::core::position2d end(x2, y2); irr::video::SColor color(mColor.a, mColor.r, mColor.g, mColor.b); mDriver->draw2DLine(start, end, color); } void IrrlichtGraphics::setColor(const Color& color) { mColor = color; } const Color& IrrlichtGraphics::getColor() const { return mColor; } } fifechan-0.1.5/src/irrlicht/irrlichtimage.cpp000066400000000000000000000161331341577075500212400ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessén a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/irrlicht/irrlichtimage.hpp" #include "fifechan/exception.hpp" namespace fcn { IrrlichtImage::IrrlichtImage(irr::video::IImage* image, irr::video::IVideoDriver* driver, const std::string& name, bool autoFree, bool convertToDisplayFormat) { mTexture = NULL; mImage = image; mDriver = driver; mName = name; mAutoFree = autoFree; if (mDriver) { driver->grab(); } if (convertToDisplayFormat) { IrrlichtImage::convertToDisplayFormat(); } } IrrlichtImage::~IrrlichtImage() { if (mAutoFree) { free(); } if (mDriver) { mDriver->drop(); } } irr::video::ITexture* IrrlichtImage::getTexture() const { return mTexture; } int IrrlichtImage::getWidth() const { if (mTexture) { return mTexture->getSize().Width; } else if (mImage) { return mImage->getDimension().Width; } throw FCN_EXCEPTION("Trying to get the width of a non loaded image."); } int IrrlichtImage::getHeight() const { if (mTexture) { return mTexture->getSize().Height; } else if (mImage) { return mImage->getDimension().Height; } throw FCN_EXCEPTION("Trying to get the height of a non loaded image."); } Color IrrlichtImage::getPixel(int x, int y) { if (mImage == NULL) { throw FCN_EXCEPTION("Image has been converted to display format."); } irr::video::SColor color = mImage->getPixel(x, y); return Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); } void IrrlichtImage::putPixel(int x, int y, const Color& color) { if (mImage == NULL) { throw FCN_EXCEPTION("Image has been converted to display format."); } mImage->setPixel(x, y, irr::video::SColor(color.a, color.r, color.g, color.b)); } void IrrlichtImage::convertToDisplayFormat() { if (mTexture != NULL) { return; } if (mImage == NULL) { throw FCN_EXCEPTION("Trying to convert a non loaded image to display format."); } bool hasPink = false; irr::video::SColor pink(255, 255, 0, 255); for (int i = 0; i < mImage->getDimension().Width; ++i) { for (int j = 0; j < mImage->getDimension().Height; ++j) { if(mImage->getPixel(i, j) == pink) { hasPink = true; break; } } } mTexture = mDriver->addTexture(mName.c_str(), mImage); if (mTexture == NULL) { throw FCN_EXCEPTION("Unable to convert image to display format!"); } if(hasPink == true) { mDriver->makeColorKeyTexture(mTexture, irr::video::SColor(0,255,0,255)); } mImage->drop(); mImage = NULL; } void IrrlichtImage::free() { if (mImage != NULL) { mImage->drop(); } } } fifechan-0.1.5/src/irrlicht/irrlichtimageloader.cpp000066400000000000000000000111301341577075500224170ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/irrlicht/irrlichtimageloader.hpp" #include "fifechan/exception.hpp" #include "fifechan/irrlicht/irrlichtimage.hpp" namespace fcn { IrrlichtImageLoader::IrrlichtImageLoader(irr::video::IVideoDriver* driver) : mDriver(driver) { if (mDriver) { mDriver->grab(); } } IrrlichtImageLoader::~IrrlichtImageLoader() { if (mDriver) { mDriver->drop(); } } Image* IrrlichtImageLoader::load(const std::string& filename, bool convertToDisplayFormat) { irr::video::IImage* image = mDriver->createImageFromFile(filename.c_str()); if (image == NULL) { throw FCN_EXCEPTION(std::string("Unable to load image file: ") + filename); } return new IrrlichtImage(image, mDriver, filename, true, convertToDisplayFormat); } } fifechan-0.1.5/src/irrlicht/irrlichtinput.cpp000066400000000000000000000342551341577075500213220ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/irrlicht/irrlichtinput.hpp" #include "fifechan/exception.hpp" namespace fcn { IrrlichtInput::IrrlichtInput(irr::IrrlichtDevice* device) : mIrrlichtDevice(device), mAltKeyDown(false), mMetaKeyDown(false) { } bool IrrlichtInput::isKeyQueueEmpty() { return mKeyInputQueue.empty(); } KeyInput IrrlichtInput::dequeueKeyInput() { KeyInput keyInput; if (mKeyInputQueue.empty()) { throw FCN_EXCEPTION("The queue is empty."); } keyInput = mKeyInputQueue.front(); mKeyInputQueue.pop(); return keyInput; } bool IrrlichtInput::isMouseQueueEmpty() { return mMouseInputQueue.empty(); } MouseInput IrrlichtInput::dequeueMouseInput() { MouseInput mouseInput; if (mMouseInputQueue.empty()) { throw FCN_EXCEPTION("The queue is empty."); } mouseInput = mMouseInputQueue.front(); mMouseInputQueue.pop(); return mouseInput; } void IrrlichtInput::pushInput(const irr::SEvent& event) { KeyInput keyInput; MouseInput mouseInput; if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) { mouseInput.setX(event.MouseInput.X); mouseInput.setY(event.MouseInput.Y); irr::u32 ticks = mIrrlichtDevice->getTimer()->getRealTime(); switch(event.MouseInput.Event) { case irr::EMIE_LMOUSE_PRESSED_DOWN: mouseInput.setButton(MouseInput::Left); mouseInput.setType(MouseInput::Pressed); mouseInput.setTimeStamp(ticks); mMouseInputQueue.push(mouseInput); break; case irr::EMIE_RMOUSE_PRESSED_DOWN: mouseInput.setButton(MouseInput::Right); mouseInput.setType(MouseInput::Pressed); mouseInput.setTimeStamp(ticks); mMouseInputQueue.push(mouseInput); break; case irr::EMIE_MMOUSE_PRESSED_DOWN: mouseInput.setButton(MouseInput::Middle); mouseInput.setType(MouseInput::Pressed); mouseInput.setTimeStamp(ticks); mMouseInputQueue.push(mouseInput); break; case irr::EMIE_LMOUSE_LEFT_UP: mouseInput.setButton(MouseInput::Left); mouseInput.setType(MouseInput::Released); mouseInput.setTimeStamp(ticks); mMouseInputQueue.push(mouseInput); break; case irr::EMIE_RMOUSE_LEFT_UP: mouseInput.setButton(MouseInput::Right); mouseInput.setType(MouseInput::Released); mouseInput.setTimeStamp(ticks); mMouseInputQueue.push(mouseInput); break; case irr::EMIE_MMOUSE_LEFT_UP: mouseInput.setButton(MouseInput::Middle); mouseInput.setType(MouseInput::Released); mouseInput.setTimeStamp(ticks); mMouseInputQueue.push(mouseInput); break; case irr::EMIE_MOUSE_MOVED: mouseInput.setButton(MouseInput::Empty); mouseInput.setType(MouseInput::Moved); mouseInput.setTimeStamp(ticks); mMouseInputQueue.push(mouseInput); break; case irr::EMIE_MOUSE_WHEEL: mouseInput.setButton(MouseInput::Middle); mouseInput.setType(event.MouseInput.Wheel > 0 ? MouseInput::WheelMovedUp : MouseInput::WheelMovedDown); mouseInput.setTimeStamp(ticks); mMouseInputQueue.push(mouseInput); break; default: break; } } else if(event.EventType == irr::EET_KEY_INPUT_EVENT) { int value = convertIrrlichtEventToFifechanKeyValue(event); if (value == -1) { value = (int)event.KeyInput.Char; } keyInput.setKey(Key(value)); keyInput.setType(event.KeyInput.PressedDown ? KeyInput::Pressed : KeyInput::Released); keyInput.setShiftPressed(event.KeyInput.Shift); keyInput.setControlPressed(event.KeyInput.Control); keyInput.setAltPressed(mAltKeyDown); keyInput.setMetaPressed(mMetaKeyDown); keyInput.setNumericPad(event.KeyInput.Key >= irr::KEY_NUMPAD0 && event.KeyInput.Key <= irr::KEY_DIVIDE); mKeyInputQueue.push(keyInput); } } int IrrlichtInput::convertIrrlichtEventToFifechanKeyValue(const irr::SEvent& event) { int value = -1; switch (event.KeyInput.Key) { case irr::KEY_LBUTTON: break; case irr::KEY_RBUTTON: break; case irr::KEY_CANCEL: break; case irr::KEY_MBUTTON: break; case irr::KEY_XBUTTON1: break; case irr::KEY_XBUTTON2: break; case irr::KEY_BACK: value = Key::Backspace; break; case irr::KEY_TAB: value = Key::Tab; break; case irr::KEY_CLEAR: break; case irr::KEY_RETURN: value = Key::Enter; break; case irr::KEY_SHIFT: break; case irr::KEY_CONTROL: break; case irr::KEY_MENU: mAltKeyDown = event.KeyInput.PressedDown; value = Key::LeftAlt; // is this right? break; case irr::KEY_PAUSE: value = Key::Pause; break; case irr::KEY_CAPITAL: value = Key::CapsLock; break; case irr::KEY_KANA: break; case irr::KEY_JUNJA: break; case irr::KEY_FINAL: break; case irr::KEY_KANJI: break; case irr::KEY_ESCAPE: value = Key::Escape; break; case irr::KEY_CONVERT: break; case irr::KEY_NONCONVERT: break; case irr::KEY_ACCEPT: break; case irr::KEY_MODECHANGE: value = Key::AltGr; break; case irr::KEY_SPACE: value = Key::Space; break; case irr::KEY_PRIOR: value = Key::PageUp; break; case irr::KEY_NEXT: value = Key::PageDown; break; case irr::KEY_END: value = Key::End; break; case irr::KEY_HOME: value = Key::Home; break; case irr::KEY_LEFT: value = Key::Left; break; case irr::KEY_UP: value = Key::Up; break; case irr::KEY_RIGHT: value = Key::Right; break; case irr::KEY_DOWN: value = Key::Down; break; case irr::KEY_SELECT: break; case irr::KEY_PRINT: value = Key::PrintScreen; // is this right? break; case irr::KEY_EXECUT: break; case irr::KEY_SNAPSHOT: value = Key::PrintScreen; // is this right? break; case irr::KEY_INSERT: value = Key::Insert; break; case irr::KEY_DELETE: value = Key::Delete; break; case irr::KEY_HELP: break; case irr::KEY_LWIN: mMetaKeyDown = event.KeyInput.PressedDown; value = Key::LeftMeta; break; case irr::KEY_RWIN: value = Key::RightMeta; break; case irr::KEY_APPS: break; case irr::KEY_SLEEP: break; case irr::KEY_F1: value = Key::F1; break; case irr::KEY_F2: value = Key::F2; break; case irr::KEY_F3: value = Key::F3; break; case irr::KEY_F4: value = Key::F4; break; case irr::KEY_F5: value = Key::F5; break; case irr::KEY_F6: value = Key::F6; break; case irr::KEY_F7: value = Key::F7; break; case irr::KEY_F8: value = Key::F8; break; case irr::KEY_F9: value = Key::F9; break; case irr::KEY_F10: value = Key::F10; break; case irr::KEY_F11: value = Key::F11; break; case irr::KEY_F12: value = Key::F12; break; case irr::KEY_F13: value = Key::F13; break; case irr::KEY_F14: value = Key::F14; break; case irr::KEY_F15: value = Key::F15; break; case irr::KEY_NUMLOCK: value = Key::NumLock; break; case irr::KEY_SCROLL: value = Key::ScrollLock; break; case irr::KEY_LSHIFT: value = Key::LeftShift; break; case irr::KEY_RSHIFT: value = Key::RightShift; break; case irr::KEY_LCONTROL: value = Key::LeftControl; break; case irr::KEY_RCONTROL: value = Key::RightControl; break; case irr::KEY_LMENU: value = Key::LeftSuper; break; case irr::KEY_RMENU: value = Key::RightSuper; break; default: break; } return value; } } fifechan-0.1.5/src/key.cpp000066400000000000000000000110741341577075500153640ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/key.hpp" namespace fcn { Key::Key(int value) :mValue(value) { } bool Key::isCharacter() const { return (mValue >= 32 && mValue <= 126) || (mValue >= 162 && mValue <= 255) || (mValue == 9); } bool Key::isNumber() const { return mValue >= 48 && mValue <= 57; } bool Key::isLetter() const { return (((mValue >= 65 && mValue <= 90) || (mValue >= 97 && mValue <= 122) || (mValue >= 192 && mValue <= 255)) && (mValue != 215) && (mValue != 247)); } int Key::getValue() const { return mValue; } bool Key::operator==(const Key& key) const { return mValue == key.mValue; } bool Key::operator!=(const Key& key) const { return (mValue != key.mValue); } } fifechan-0.1.5/src/keyevent.cpp000066400000000000000000000113621341577075500164260ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/keyevent.hpp" namespace fcn { KeyEvent::KeyEvent(Widget* source, Widget* distributor, bool isShiftPressed, bool isControlPressed, bool isAltPressed, bool isMetaPressed, unsigned int type, bool isNumericPad, const Key& key) :InputEvent(source, distributor, isShiftPressed, isControlPressed, isAltPressed, isMetaPressed), mType(type), mIsNumericPad(isNumericPad), mKey(key) { } KeyEvent::~KeyEvent() { } unsigned int KeyEvent::getType() const { return mType; } bool KeyEvent::isNumericPad() const { return mIsNumericPad; } const Key& KeyEvent::getKey() const { return mKey; } } fifechan-0.1.5/src/keyinput.cpp000066400000000000000000000123331341577075500164430ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/keyinput.hpp" namespace fcn { KeyInput::KeyInput(const Key& key, unsigned int type) :mKey(key), mType(type), mShiftPressed(false), mControlPressed(false), mAltPressed(false), mMetaPressed(false), mNumericPad(false) { } void KeyInput::setType(unsigned int type) { mType = type; } int KeyInput::getType() const { return mType; } void KeyInput::setKey(const Key& key) { mKey = key; } const Key& KeyInput::getKey() const { return mKey; } bool KeyInput::isShiftPressed() const { return mShiftPressed; } void KeyInput::setShiftPressed(bool pressed) { mShiftPressed = pressed; } bool KeyInput::isControlPressed() const { return mControlPressed; } void KeyInput::setControlPressed(bool pressed) { mControlPressed = pressed; } bool KeyInput::isAltPressed() const { return mAltPressed; } void KeyInput::setAltPressed(bool pressed) { mAltPressed = pressed; } bool KeyInput::isMetaPressed() const { return mMetaPressed; } void KeyInput::setMetaPressed(bool pressed) { mMetaPressed = pressed; } bool KeyInput::isNumericPad() const { return mNumericPad; } void KeyInput::setNumericPad(bool numpad) { mNumericPad = numpad; } } fifechan-0.1.5/src/mouseevent.cpp000066400000000000000000000117561341577075500167750ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/mouseevent.hpp" namespace fcn { MouseEvent::MouseEvent(Widget* source, Widget* distributor, bool isShiftPressed, bool isControlPressed, bool isAltPressed, bool isMetaPressed, unsigned int type, unsigned int button, int x, int y, int clickCount) :InputEvent(source, distributor, isShiftPressed, isControlPressed, isAltPressed, isMetaPressed), mType(type), mButton(button), mX(x), mY(y), mClickCount(clickCount) { } unsigned int MouseEvent::getButton() const { return mButton; } int MouseEvent::getX() const { return mX; } int MouseEvent::getY() const { return mY; } int MouseEvent::getClickCount() const { return mClickCount; } unsigned int MouseEvent::getType() const { return mType; } } fifechan-0.1.5/src/mouseinput.cpp000066400000000000000000000115661341577075500170120ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/mouseinput.hpp" namespace fcn { MouseInput::MouseInput(unsigned int button, unsigned int type, int x, int y, int timeStamp) : mType(type), mButton(button), mTimeStamp(timeStamp), mX(x), mY(y) { } void MouseInput::setType(unsigned int type) { mType = type; } unsigned int MouseInput::getType() const { return mType; } void MouseInput::setButton(unsigned int button) { mButton = button; } unsigned int MouseInput::getButton() const { return mButton; } int MouseInput::getTimeStamp() const { return mTimeStamp; } void MouseInput::setTimeStamp(int timeStamp) { mTimeStamp = timeStamp; } void MouseInput::setX(int x) { mX = x; } int MouseInput::getX() const { return mX; } void MouseInput::setY(int y) { mY = y; } int MouseInput::getY() const { return mY; } } fifechan-0.1.5/src/opengl/000077500000000000000000000000001341577075500153515ustar00rootroot00000000000000fifechan-0.1.5/src/opengl/opengl.cpp000066400000000000000000000074511341577075500173500ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/opengl.hpp" extern "C" { void fcnOpenGL() { } } fifechan-0.1.5/src/opengl/openglgraphics.cpp000066400000000000000000000302571341577075500210710ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/opengl/openglgraphics.hpp" #if defined (_WIN32) #define WIN32_LEAN_AND_MEAN #include #endif #if defined (__amigaos4__) #include #define glVertex3i glVertex3f #elif defined(__APPLE__) #include #else #include #endif #include "fifechan/exception.hpp" #include "fifechan/image.hpp" #include "fifechan/opengl/openglimage.hpp" namespace fcn { OpenGLGraphics::OpenGLGraphics() { setTargetPlane(640, 480); mAlpha = false; } OpenGLGraphics::OpenGLGraphics(int width, int height) { setTargetPlane(width, height); } OpenGLGraphics::~OpenGLGraphics() { } void OpenGLGraphics::_beginDraw() { glPushAttrib( GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_FOG_BIT | GL_LIGHTING_BIT | GL_LINE_BIT | GL_POINT_BIT | GL_POLYGON_BIT | GL_SCISSOR_BIT | GL_STENCIL_BUFFER_BIT | GL_TEXTURE_BIT | GL_TRANSFORM_BIT | GL_POINT_BIT | GL_LINE_BIT ); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, (double)mWidth, (double)mHeight, 0.0, -1.0, 1.0); glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); glEnable(GL_SCISSOR_TEST); glPointSize(1.0); glLineWidth(1.0); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); pushClipArea(Rectangle(0, 0, mWidth, mHeight)); } void OpenGLGraphics::_endDraw() { glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glPopAttrib(); popClipArea(); } bool OpenGLGraphics::pushClipArea(Rectangle area) { bool result = Graphics::pushClipArea(area); glScissor(mClipStack.top().x, mHeight - mClipStack.top().y - mClipStack.top().height, mClipStack.top().width, mClipStack.top().height); return result; } void OpenGLGraphics::popClipArea() { Graphics::popClipArea(); if (mClipStack.empty()) { return; } glScissor(mClipStack.top().x, mHeight - mClipStack.top().y - mClipStack.top().height, mClipStack.top().width, mClipStack.top().height); } void OpenGLGraphics::setTargetPlane(int width, int height) { mWidth = width; mHeight = height; } void OpenGLGraphics::drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height) { const OpenGLImage* srcImage = dynamic_cast(image); if (srcImage == NULL) { throw FCN_EXCEPTION("Trying to draw an image of unknown format, must be an OpenGLImage."); } if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); dstX += top.xOffset; dstY += top.yOffset; // Find OpenGL texture coordinates float texX1 = srcX / (float)srcImage->getTextureWidth(); float texY1 = srcY / (float)srcImage->getTextureHeight(); float texX2 = (srcX+width) / (float)srcImage->getTextureWidth(); float texY2 = (srcY+height) / (float)srcImage->getTextureHeight(); glBindTexture(GL_TEXTURE_2D, srcImage->getTextureHandle()); glEnable(GL_TEXTURE_2D); // Check if blending already is enabled if (!mAlpha) { glEnable(GL_BLEND); } // Draw a textured quad -- the image glBegin(GL_QUADS); glTexCoord2f(texX1, texY1); glVertex3i(dstX, dstY, 0); glTexCoord2f(texX1, texY2); glVertex3i(dstX, dstY + height, 0); glTexCoord2f(texX2, texY2); glVertex3i(dstX + width, dstY + height, 0); glTexCoord2f(texX2, texY1); glVertex3i(dstX + width, dstY, 0); glEnd(); glDisable(GL_TEXTURE_2D); // Don't disable blending if the color has alpha if (!mAlpha) { glDisable(GL_BLEND); } } void OpenGLGraphics::drawPoint(int x, int y) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); x += top.xOffset; y += top.yOffset; glBegin(GL_POINTS); glVertex2i(x, y); glEnd(); } void OpenGLGraphics::drawLine(int x1, int y1, int x2, int y2) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); x1 += top.xOffset; y1 += top.yOffset; x2 += top.xOffset; y2 += top.yOffset; glBegin(GL_LINES); glVertex2f(x1 + 0.375f, y1 + 0.375f); glVertex2f(x2 + 1.0f - 0.375f, y2 + 1.0f - 0.375f); glEnd(); glBegin(GL_POINTS); glVertex2f(x2 + 1.0f - 0.375f, y2 + 1.0f - 0.375f); glEnd(); glBegin(GL_POINTS); glVertex2f(x1 + 0.375f, y1 + 0.375f); glEnd(); } void OpenGLGraphics::drawRectangle(const Rectangle& rectangle) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); glBegin(GL_LINE_LOOP); glVertex2f(rectangle.x + top.xOffset, rectangle.y + top.yOffset); glVertex2f(rectangle.x + rectangle.width + top.xOffset - 1.0f, rectangle.y + top.yOffset + 0.375f); glVertex2f(rectangle.x + rectangle.width + top.xOffset - 1.0f, rectangle.y + rectangle.height + top.yOffset); glVertex2f(rectangle.x + top.xOffset, rectangle.y + rectangle.height + top.yOffset); glEnd(); } void OpenGLGraphics::fillRectangle(const Rectangle& rectangle) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); glBegin(GL_QUADS); glVertex2i(rectangle.x + top.xOffset, rectangle.y + top.yOffset); glVertex2i(rectangle.x + rectangle.width + top.xOffset, rectangle.y + top.yOffset); glVertex2i(rectangle.x + rectangle.width + top.xOffset, rectangle.y + rectangle.height + top.yOffset); glVertex2i(rectangle.x + top.xOffset, rectangle.y + rectangle.height + top.yOffset); glEnd(); } void OpenGLGraphics::setColor(const Color& color) { mColor = color; glColor4ub((GLubyte) color.r, (GLubyte) color.g, (GLubyte) color.b, (GLubyte) color.a); mAlpha = color.a != 255; if (mAlpha) { glEnable(GL_BLEND); } } const Color& OpenGLGraphics::getColor() const { return mColor; } int OpenGLGraphics::getTargetPlaneWidth() const { return mWidth; } int OpenGLGraphics::getTargetPlaneHeight() const { return mHeight; } } fifechan-0.1.5/src/opengl/openglimage.cpp000066400000000000000000000232731341577075500203530ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/opengl/openglimage.hpp" #include "fifechan/exception.hpp" namespace fcn { OpenGLImage::OpenGLImage(const unsigned int* pixels, int width, int height, bool convertToDisplayFormat) { mAutoFree = true; mWidth = width; mHeight = height; mTextureWidth = 1, mTextureHeight = 1; while(mTextureWidth < mWidth) { mTextureWidth *= 2; } while(mTextureHeight < mHeight) { mTextureHeight *= 2; } // Create a new pixel array and copy the pixels into it mPixels = new unsigned int[mTextureWidth * mTextureHeight]; #ifdef __BIG_ENDIAN__ const unsigned int magicPink = 0xff00ffff; #else const unsigned int magicPink = 0xffff00ff; #endif int x, y; for (y = 0; y < mTextureHeight; y++) { for (x = 0; x < mTextureWidth; x++) { if (x < mWidth && y < mHeight) { unsigned int c = pixels[x + y * mWidth]; // Magic pink to transparent if (c == magicPink) { c = 0x00000000; } mPixels[x + y * mTextureWidth] = c; } else { mPixels[x + y * mTextureWidth] = 0x00000000; } } } if (convertToDisplayFormat) { OpenGLImage::convertToDisplayFormat(); } } OpenGLImage::OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree) { mTextureHandle = textureHandle; mAutoFree = autoFree; mPixels = NULL; mWidth = width; mHeight = height; mTextureWidth = 1, mTextureHeight = 1; while(mTextureWidth < mWidth) { mTextureWidth *= 2; } while(mTextureHeight < mHeight) { mTextureHeight *= 2; } } OpenGLImage::~OpenGLImage() { if (mAutoFree) { free(); } } GLuint OpenGLImage::getTextureHandle() const { return mTextureHandle; } int OpenGLImage::getTextureWidth() const { return mTextureWidth; } int OpenGLImage::getTextureHeight() const { return mTextureHeight; } void OpenGLImage::free() { if (mPixels == NULL) { glDeleteTextures(1, &mTextureHandle); } else { delete[] mPixels; mPixels = NULL; } } int OpenGLImage::getWidth() const { return mWidth; } int OpenGLImage::getHeight() const { return mHeight; } Color OpenGLImage::getPixel(int x, int y) { if (mPixels == NULL) { throw FCN_EXCEPTION("Image has been converted to display format"); } if (x < 0 || x >= mWidth || y < 0 || y >= mHeight) { throw FCN_EXCEPTION("Coordinates outside of the image"); } unsigned int c = mPixels[x + y * mTextureWidth]; #ifdef __BIG_ENDIAN__ unsigned char r = (unsigned char) ((c >> 24) & 0xff); unsigned char g = (unsigned char) ((c >> 16) & 0xff); unsigned char b = (unsigned char) ((c >> 8) & 0xff); unsigned char a = (unsigned char) (c & 0xff); #else unsigned char a = (unsigned char) ((c >> 24) & 0xff); unsigned char b = (unsigned char) ((c >> 16) & 0xff); unsigned char g = (unsigned char) ((c >> 8) & 0xff); unsigned char r = (unsigned char) (c & 0xff); #endif return Color(r, g, b, a); } void OpenGLImage::putPixel(int x, int y, const Color& color) { if (mPixels == NULL) { throw FCN_EXCEPTION("Image has been converted to display format"); } if (x < 0 || x >= mWidth || y < 0 || y >= mHeight) { throw FCN_EXCEPTION("Coordinates outside of the image"); } #ifdef __BIG_ENDIAN__ unsigned int c = color.a | color.b << 8 | color.g << 16 | color.r << 24; #else unsigned int c = color.r | color.g << 8 | color.b << 16 | color.a << 24; #endif mPixels[x + y * mTextureWidth] = c; } void OpenGLImage::convertToDisplayFormat() { if (mPixels == NULL) { throw FCN_EXCEPTION("Image has already been converted to display format"); } glGenTextures(1, &mTextureHandle); glBindTexture(GL_TEXTURE_2D, mTextureHandle); glTexImage2D(GL_TEXTURE_2D, 0, 4, mTextureWidth, mTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mPixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); delete[] mPixels; mPixels = NULL; GLenum error = glGetError(); if (error) { std::string errmsg; switch (error) { case GL_INVALID_ENUM: errmsg = "GL_INVALID_ENUM"; break; case GL_INVALID_VALUE: errmsg = "GL_INVALID_VALUE"; break; case GL_INVALID_OPERATION: errmsg = "GL_INVALID_OPERATION"; break; case GL_STACK_OVERFLOW: errmsg = "GL_STACK_OVERFLOW"; break; case GL_STACK_UNDERFLOW: errmsg = "GL_STACK_UNDERFLOW"; break; case GL_OUT_OF_MEMORY: errmsg = "GL_OUT_OF_MEMORY"; break; } throw FCN_EXCEPTION(std::string("Unable to convert to OpenGL display format, glGetError said: ") + errmsg); } } } fifechan-0.1.5/src/openlayer/000077500000000000000000000000001341577075500160635ustar00rootroot00000000000000fifechan-0.1.5/src/openlayer/openlayer.cpp000066400000000000000000000074571341577075500206020ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/openlayer.hpp" extern "C" { void fcnOpenLayer() { } } fifechan-0.1.5/src/openlayer/openlayerfont.cpp000066400000000000000000000123401341577075500214540ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "fifechan/openlayer/openlayerfont.hpp" #include "fifechan/openlayer/openlayergraphics.hpp" #include "fifechan/exception.hpp" namespace fcn { OpenLayerTTFont::OpenLayerTTFont(const std::string& filename, int size) : mTextRenderer(filename.c_str(), size, size) { if (!mTextRenderer.IsValid()) { throw FCN_EXCEPTION("Unable to load font."); } } OpenLayerTTFont::OpenLayerTTFont(const std::string& filename, int width, int height) : mTextRenderer(filename.c_str(), width, height) { if (!mTextRenderer.IsValid()) { throw FCN_EXCEPTION("Unable to load font."); } } OpenLayerTTFont::~OpenLayerTTFont() { } int OpenLayerTTFont::getWidth(const std::string& text) const { return mTextRenderer.Width(text); } int OpenLayerTTFont::getHeight() const { return mTextRenderer.FontTotalHeight(); } void OpenLayerTTFont::drawString(Graphics* graphics, const std::string& text, int x, int y) { const ClipRectangle& rec = graphics->getCurrentClipArea(); OpenLayerGraphics* const openLayerGraphics = dynamic_cast(graphics); if (!openLayerGraphics) { throw FCN_EXCEPTION("Graphics is not of type OpenLayerGraphics"); } mTextRenderer.SetColor(openLayerGraphics->getOpenLayerColor()); mTextRenderer.Print(text, x + rec.xOffset, y + rec.yOffset + mTextRenderer.Height(text)); } } fifechan-0.1.5/src/openlayer/openlayergraphics.cpp000066400000000000000000000204451341577075500223130ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/openlayer/openlayergraphics.hpp" #include #include #include "fifechan/exception.hpp" #include "fifechan/openlayer/openlayerimage.hpp" namespace fcn { OpenLayerGraphics::OpenLayerGraphics() { setTargetPlane(640, 480); } OpenLayerGraphics::OpenLayerGraphics(int width, int height) { setTargetPlane(width, height); } OpenLayerGraphics::~OpenLayerGraphics() { } void OpenLayerGraphics::_beginDraw() { pushClipArea(Rectangle(0, 0, mWidth, mHeight)); } void OpenLayerGraphics::_endDraw() { popClipArea(); } bool OpenLayerGraphics::pushClipArea(Rectangle area) { bool result = Graphics::pushClipArea(area); ol::Transforms::SetPosition(mClipStack.top().xOffset, mClipStack.top().yOffset); ol::Canvas::SetClipping(mClipStack.top().x, mClipStack.top().y, mClipStack.top().width, mClipStack.top().height); return result; } void OpenLayerGraphics::popClipArea() { Graphics::popClipArea(); if (mClipStack.empty()) { ol::Transforms::SetPosition(0, 0); ol::Canvas::DisableClipping(); } else { const ClipRectangle top = mClipStack.top(); ol::Transforms::SetPosition(top.xOffset, top.yOffset); ol::Canvas::SetClipping(top.x, top.y, top.width, top.height); } } void OpenLayerGraphics::setTargetPlane(int width, int height) { mWidth = width; mHeight = height; } void OpenLayerGraphics::drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height) { const OpenLayerImage* srcImage = dynamic_cast(image); if (srcImage == NULL) { throw FCN_EXCEPTION("Trying to draw an image of unknown format, must be an OpenLayerImage."); } srcImage->getBitmap()->Blit(dstX - srcX, dstY - srcY, ol::ClippedMode(srcX, srcY, width, height), 1.0f); } void OpenLayerGraphics::drawPoint(int x, int y) { ol::GfxRend::Point(x + 0.5f, y - 0.5f, mRgba); } void OpenLayerGraphics::drawLine(int x1, int y1, int x2, int y2) { mRgba.Select(); glDisable(GL_TEXTURE_2D); glLineWidth(1.0f); glBegin(GL_LINES); glVertex2f(x1+0.5f, y1+0.5f); glVertex2f(x2+0.5f, y2+0.5f); glEnd(); glBegin(GL_POINTS); glVertex2f(x1+0.5f, y1+0.5f); glEnd(); glBegin(GL_POINTS); glVertex2f(x2+0.5f, y2+0.5f); glEnd(); if (ol::Settings::TextureMappingUsed()) { glEnable(GL_TEXTURE_2D); } } void OpenLayerGraphics::drawRectangle(const Rectangle& rectangle) { ol::GfxRend::RectOutline(rectangle.x + 0.5f, rectangle.y + 0.5f, rectangle.width - 0.5f, rectangle.height - 0.5f, mRgba); } void OpenLayerGraphics::fillRectangle(const Rectangle& rectangle) { ol::GfxRend::Rect(rectangle.x, rectangle.y, rectangle.width, rectangle.height, mRgba); } void OpenLayerGraphics::setColor(const Color& color) { mColor = color; mRgba.r = color.r / 255.0f; mRgba.g = color.g / 255.0f; mRgba.b = color.b / 255.0f; mRgba.a = color.a / 255.0f; mRgba.Select(); } const Color& OpenLayerGraphics::getColor() const { return mColor; } const ol::Rgba& OpenLayerGraphics::getOpenLayerColor() const { return mRgba; } } fifechan-0.1.5/src/openlayer/openlayerimage.cpp000066400000000000000000000155521341577075500216000ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/openlayer/openlayerimage.hpp" #include "fifechan/exception.hpp" namespace fcn { OpenLayerImage::OpenLayerImage(BITMAP* allegroBitmap, bool autoFree) : mOpenLayerBitmap(NULL), mAllegroBitmap(allegroBitmap), mAutoFree(autoFree) { if (mAllegroBitmap == NULL) { throw FCN_EXCEPTION(std::string("Unable to load bitmap.")); } } OpenLayerImage::~OpenLayerImage() { if (mAutoFree) { free(); } } ol::Bitmap* OpenLayerImage::getBitmap() const { return mOpenLayerBitmap; } void OpenLayerImage::free() { if (mOpenLayerBitmap != NULL) { delete mOpenLayerBitmap; mOpenLayerBitmap = NULL; } if (mAllegroBitmap != NULL) { destroy_bitmap(mAllegroBitmap); mAllegroBitmap = NULL; } } int OpenLayerImage::getWidth() const { if (mAllegroBitmap == NULL && mOpenLayerBitmap == NULL) { throw FCN_EXCEPTION("Trying to get the width of a non loaded image."); } if (mOpenLayerBitmap == NULL) { return mAllegroBitmap->w; } return mOpenLayerBitmap->Width(); } int OpenLayerImage::getHeight() const { if (mAllegroBitmap == NULL && mOpenLayerBitmap == NULL) { throw FCN_EXCEPTION("Trying to get the height of a non loaded image."); } if (mOpenLayerBitmap == NULL) { return mAllegroBitmap->h; } return mOpenLayerBitmap->Height(); } Color OpenLayerImage::getPixel(int x, int y) { if (mAllegroBitmap == NULL && mOpenLayerBitmap == NULL) { throw FCN_EXCEPTION("Trying to get a pixel from a non loaded image."); } if (mOpenLayerBitmap == NULL) { int color = getpixel(mAllegroBitmap, x, y); return Color(getr(color), getg(color), getb(color), 255); } return Color(mOpenLayerBitmap->GetPixelPacked(x, y)); } void OpenLayerImage::putPixel(int x, int y, const Color& color) { if (mAllegroBitmap == NULL && mOpenLayerBitmap == NULL) { throw FCN_EXCEPTION("Trying to put a pixel in a non loaded image."); } if (mAllegroBitmap == NULL) { return; } int c = makeacol_depth(32, color.r, color.g, color.b, color.a); putpixel(mAllegroBitmap, x, y, c); } void OpenLayerImage::convertToDisplayFormat() { if (mAllegroBitmap == NULL) { throw FCN_EXCEPTION("Trying to convert a non loaded image to display format."); } if (mOpenLayerBitmap != NULL) { throw FCN_EXCEPTION("Trying to convert an image to display format which has already been converted."); } mOpenLayerBitmap = new ol::Bitmap(mAllegroBitmap, false, true); mOpenLayerBitmap->SendToGPU(); destroy_bitmap(mAllegroBitmap); mAllegroBitmap = NULL; } } fifechan-0.1.5/src/openlayer/openlayerimageloader.cpp000066400000000000000000000117641341577075500227700ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/openlayer/openlayerimageloader.hpp" #include "fifechan/exception.hpp" #include "fifechan/openlayer/openlayerimage.hpp" namespace fcn { Image* OpenLayerImageLoader::load(const std::string& filename, bool convertToDisplayFormat) { #if !(ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION == 0) int colconv = get_color_conversion(); #endif set_color_conversion(COLORCONV_NONE); PALETTE pal; BITMAP *bmp = load_bitmap(filename.c_str(), pal); if (bmp == NULL) { throw FCN_EXCEPTION(std::string("Unable to load: ") + filename); } BITMAP *bmp2 = create_bitmap_ex(32, bmp->w, bmp->h); if (bmp2 == NULL) { throw FCN_EXCEPTION(std::string("Not enough memory to load: ") + filename); } set_palette(pal); blit(bmp, bmp2, 0, 0, 0, 0, bmp->w, bmp->h); destroy_bitmap(bmp); #if (ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION == 0) set_color_conversion(COLORCONV_TOTAL); #else set_color_conversion(colconv); #endif Image *image = new OpenLayerImage(bmp2, true); if (convertToDisplayFormat) { image->convertToDisplayFormat(); } return image; } } fifechan-0.1.5/src/openlayer/openlayerinput.cpp000066400000000000000000000374351341577075500216610ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/openlayer/openlayerinput.hpp" #include #include "fifechan/exception.hpp" namespace fcn { OpenLayerInput::OpenLayerInput() { mMouseButton1 = mMouseButton2 = mMouseButton3 = false; mLastMouseZ = 0; mLastMouseX = 0; mLastMouseY = 0; } bool OpenLayerInput::isKeyQueueEmpty() { return mKeyQueue.empty(); } KeyInput OpenLayerInput::dequeueKeyInput() { if (isKeyQueueEmpty()) { throw FCN_EXCEPTION("Key queue is empty."); } KeyInput ki = mKeyQueue.front(); mKeyQueue.pop(); return ki; } bool OpenLayerInput::isMouseQueueEmpty() { return mMouseQueue.empty(); } MouseInput OpenLayerInput::dequeueMouseInput() { if (isMouseQueueEmpty()) { throw FCN_EXCEPTION("Mouse queue is empty."); } MouseInput mi = mMouseQueue.front(); mMouseQueue.pop(); return mi; } void OpenLayerInput::_pollInput() { pollMouseInput(); pollKeyInput(); } void OpenLayerInput::pollMouseInput() { if (mouse_needs_poll()) { poll_mouse(); } int mouseX = mouse_x; int mouseY = mouse_y; int mouseZ = mouse_z; int mouseB1 = mouse_b & 1; int mouseB2 = mouse_b & 2; int mouseB3 = mouse_b & 4; // Check mouse movement if (mouseX != mLastMouseX || mouseY != mLastMouseY) { mMouseQueue.push(MouseInput(MouseInput::Empty, MouseInput::Moved, mouseX, mouseY, 0)); mLastMouseX = mouseX; mLastMouseY = mouseY; } // Check mouse Wheel while (mLastMouseZ < mouseZ) { mMouseQueue.push(MouseInput(MouseInput::Empty, MouseInput::WheelMovedUp, mouseX, mouseY, 0)); mLastMouseZ++; } while (mLastMouseZ > mouseZ) { mMouseQueue.push(MouseInput(MouseInput::Empty, MouseInput::WheelMovedDown, mouseX, mouseY, 0)); mLastMouseZ--; } // Check mouse buttons if (!mMouseButton1 && mouseB1) { mMouseQueue.push(MouseInput(MouseInput::Left, MouseInput::Pressed, mouseX, mouseY, 0)); } if (mMouseButton1 && !mouseB1) { mMouseQueue.push(MouseInput(MouseInput::Left, MouseInput::Released, mouseX, mouseY, 0)); } if (!mMouseButton2 && mouseB2) { mMouseQueue.push(MouseInput(MouseInput::Right, MouseInput::Pressed, mouseX, mouseY, 0)); } if (mMouseButton2 && !mouseB2) { mMouseQueue.push(MouseInput(MouseInput::Right, MouseInput::Released, mouseX, mouseY, 0)); } if (!mMouseButton3 && mouseB3) { mMouseQueue.push(MouseInput(MouseInput::Middle, MouseInput::Pressed, mouseX, mouseY, 0)); } if (mMouseButton3 && !mouseB3) { mMouseQueue.push(MouseInput(MouseInput::Middle, MouseInput::Released, mouseX, mouseY, 0)); } mMouseButton1 = mouseB1; mMouseButton2 = mouseB2; mMouseButton3 = mouseB3; } void OpenLayerInput::pollKeyInput() { int unicode, scancode; if (keyboard_needs_poll()) { poll_keyboard(); } while (keypressed()) { unicode = ureadkey(&scancode); Key keyObj = convertToKey(scancode, unicode); KeyInput keyInput(keyObj, KeyInput::Pressed); keyInput.setNumericPad(isNumericPad(scancode)); keyInput.setShiftPressed(key_shifts & KB_SHIFT_FLAG); keyInput.setAltPressed(key_shifts & KB_ALT_FLAG); keyInput.setControlPressed(key_shifts & KB_CTRL_FLAG); #ifdef KB_COMMAND_FLAG keyInput.setMetaPressed(key_shifts & (KB_COMMAND_FLAG | KB_LWIN_FLAG | KB_RWIN_FLAG)); #else keyInput.setMetaPressed(key_shifts & (KB_LWIN_FLAG | KB_RWIN_FLAG)); #endif mKeyQueue.push(keyInput); mPressedKeys[scancode] = keyInput; } if (key[KEY_ALT] && mPressedKeys.find(KEY_ALT) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_ALT, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_ALT] = keyInput; } if (key[KEY_ALTGR] && mPressedKeys.find(KEY_ALTGR) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_ALTGR, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_ALTGR] = keyInput; } if (key[KEY_LSHIFT] && mPressedKeys.find(KEY_LSHIFT) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_LSHIFT, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_LSHIFT] = keyInput; } if (key[KEY_RSHIFT] && mPressedKeys.find(KEY_RSHIFT) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_RSHIFT, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_RSHIFT] = keyInput; } if (key[KEY_LCONTROL] && mPressedKeys.find(KEY_LCONTROL) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_LCONTROL, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_LCONTROL] = keyInput; } if (key[KEY_RCONTROL] && mPressedKeys.find(KEY_RCONTROL) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_RCONTROL, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_RCONTROL] = keyInput; } // Check for released keys std::map::iterator iter, tempIter; for (iter = mPressedKeys.begin(); iter != mPressedKeys.end(); ) { if (!key[iter->first]) { KeyInput keyInput(iter->second.getKey(), KeyInput::Released); keyInput.setNumericPad(iter->second.isNumericPad()); keyInput.setShiftPressed(iter->second.isShiftPressed()); keyInput.setAltPressed(iter->second.isAltPressed()); keyInput.setControlPressed(iter->second.isControlPressed()); mKeyQueue.push(keyInput); tempIter = iter; iter++; mPressedKeys.erase(tempIter); } else { iter++; } } } Key OpenLayerInput::convertToKey(int scancode, int unicode) { int keysym; bool pad = false; switch(scancode) { case KEY_ESC: keysym = Key::Escape; break; case KEY_ALT: keysym = Key::LeftAlt; break; case KEY_ALTGR: keysym = Key::RightAlt; break; case KEY_LSHIFT: keysym = Key::LeftShift; break; case KEY_RSHIFT: keysym = Key::RightShift; break; case KEY_LCONTROL: keysym = Key::LeftControl; break; case KEY_RCONTROL: keysym = Key::RightControl; break; case KEY_LWIN: keysym = Key::LeftMeta; break; case KEY_RWIN: keysym = Key::RightMeta; break; case KEY_INSERT: keysym = Key::Insert; break; case KEY_HOME: keysym = Key::Home; break; case KEY_PGUP: keysym = Key::PageUp; break; case KEY_PGDN: keysym = Key::PageDown; break; case KEY_DEL: keysym = Key::Delete; break; case KEY_DEL_PAD: keysym = Key::Delete; pad = true; break; case KEY_END: keysym = Key::End; break; case KEY_CAPSLOCK: keysym = Key::CapsLock; break; case KEY_BACKSPACE: keysym = Key::Backspace; break; case KEY_F1: keysym = Key::F1; break; case KEY_F2: keysym = Key::F2; break; case KEY_F3: keysym = Key::F3; break; case KEY_F4: keysym = Key::F4; break; case KEY_F5: keysym = Key::F5; break; case KEY_F6: keysym = Key::F6; break; case KEY_F7: keysym = Key::F7; break; case KEY_F8: keysym = Key::F8; break; case KEY_F9: keysym = Key::F9; break; case KEY_F10: keysym = Key::F10; break; case KEY_F11: keysym = Key::F11; break; case KEY_F12: keysym = Key::F12; break; case KEY_PRTSCR: keysym = Key::PrintScreen; break; case KEY_PAUSE: keysym = Key::Pause; break; case KEY_SCRLOCK: keysym = Key::ScrollLock; break; case KEY_NUMLOCK: keysym = Key::NumLock; break; case KEY_LEFT: keysym = Key::Left; break; case KEY_RIGHT: keysym = Key::Right; break; case KEY_UP: keysym = Key::Up; break; case KEY_DOWN: keysym = Key::Down; break; case KEY_ENTER_PAD: pad = true; case KEY_ENTER: keysym = Key::Enter; break; default: keysym = unicode; } Key k = Key(keysym); return k; } bool OpenLayerInput::isNumericPad(int scancode) { switch (scancode) { case KEY_0_PAD: case KEY_1_PAD: case KEY_2_PAD: case KEY_3_PAD: case KEY_4_PAD: case KEY_5_PAD: case KEY_6_PAD: case KEY_7_PAD: case KEY_8_PAD: case KEY_9_PAD: case KEY_SLASH_PAD: case KEY_MINUS_PAD: case KEY_PLUS_PAD: return true; default: return false; } } } fifechan-0.1.5/src/rectangle.cpp000066400000000000000000000163701341577075500165440ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/rectangle.hpp" namespace fcn { Rectangle::Rectangle() : x(0), y(0), width(0), height(0) { } Rectangle::Rectangle(int x_, int y_, int width_, int height_) : x(x_), y(y_), width(width_), height(height_) { } void Rectangle::setAll(int x_, int y_, int width_, int height_) { x = x_; y = y_; width = width_; height = height_; } bool Rectangle::isIntersecting(const Rectangle& rectangle) const { int x_ = x; int y_ = y; int width_ = width; int height_ = height; x_ -= rectangle.x; y_ -= rectangle.y; if (x_ < 0) { width_ += x_; x_ = 0; } else if (x_ + width_ > rectangle.width) { width_ = rectangle.width - x_; } if (y_ < 0) { height_ += y_; y_ = 0; } else if (y_ + height_ > rectangle.height) { height_ = rectangle.height - y_; } if (width_ <= 0 || height_ <= 0) { return false; } return true; } bool Rectangle::isContaining(int x_, int y_) const { return x_ >= x && y_ >= y && x_ < x + width && y_ < y + height; } bool Rectangle::isContaining(const Rectangle& other) const { if (other.isEmpty()) return false; return other.x >= x && other.y >= y && other.x + other.width <= x + width && other.y + other.height <= y + height; } bool Rectangle::isEmpty() const { return width <= 0 || height <= 0; } Rectangle Rectangle::operator+(const Rectangle& rh) const { if (rh.isEmpty()) return Rectangle(x, y, width, height); int nx = x < rh.x ? x : rh.x; int ny = y < rh.y ? y : rh.y; int nx2 = x + width > rh.x + rh.width ? x + width : rh.x + rh.width; int ny2 = y + height > rh.y + rh.height ? y + height : rh.y + rh.height; return Rectangle(nx, ny, nx2 - nx, ny2 - ny); } const Rectangle& Rectangle::operator+=(const Rectangle& rh) { if (rh.isEmpty()) return *(this); if (isEmpty()) return rh; x = x < rh.x ? x : rh.x; y = y < rh.y ? y : rh.y; int x2 = x + width > rh.x + rh.width ? x + width : rh.x + rh.width; int y2 = y + height > rh.y + rh.height ? y + height : rh.y + rh.height; width = x2 - x; height = y2 - y; return *(this); } Rectangle Rectangle::intersection(const Rectangle& rh) const { int nx = x > rh.x ? x : rh.x; int ny = y > rh.y ? y : rh.y; if (rh.isEmpty() || isEmpty()) return Rectangle(nx, ny, 0, 0); int nx2 = x + width < rh.x + rh.width ? x + width : rh.x + rh.width; int ny2 = y + height < rh.y + rh.height ? y + height : rh.y + rh.height; Rectangle result(nx, ny, nx2 - nx, ny2 - ny); if (result.isEmpty()) return Rectangle(nx, ny, 0, 0); return result; } std::ostream& operator<<(std::ostream& out, const Rectangle& rectangle) { out << "Rectangle [x = " << rectangle.x << ", y = " << rectangle.y << ", width = " << rectangle.width << ", height = " << rectangle.height << "]"; return out; } } fifechan-0.1.5/src/sdl/000077500000000000000000000000001341577075500146475ustar00rootroot00000000000000fifechan-0.1.5/src/sdl/sdl.cpp000066400000000000000000000074431341577075500161450ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/sdl.hpp" extern "C" { void fcnSDL() { } } fifechan-0.1.5/src/sdl/sdlgraphics.cpp000066400000000000000000000467171341577075500176750ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/sdl/sdlgraphics.hpp" #include "fifechan/exception.hpp" #include "fifechan/font.hpp" #include "fifechan/image.hpp" #include "fifechan/sdl/sdlimage.hpp" #include "fifechan/sdl/sdlpixel.hpp" // For some reason an old version of MSVC did not like std::abs, // so we added this macro. #ifndef ABS #define ABS(x) ((x)<0?-(x):(x)) #endif namespace fcn { SDLGraphics::SDLGraphics() { mAlpha = false; } void SDLGraphics::_beginDraw() { Rectangle area; area.x = 0; area.y = 0; area.width = mTarget->w; area.height = mTarget->h; pushClipArea(area); } void SDLGraphics::_endDraw() { popClipArea(); } void SDLGraphics::setTarget(SDL_Surface* target) { mTarget = target; } bool SDLGraphics::pushClipArea(Rectangle area) { SDL_Rect rect; bool result = Graphics::pushClipArea(area); const ClipRectangle& carea = mClipStack.top(); rect.x = carea.x; rect.y = carea.y; rect.w = carea.width; rect.h = carea.height; SDL_SetClipRect(mTarget, &rect); return result; } void SDLGraphics::popClipArea() { Graphics::popClipArea(); if (mClipStack.empty()) { return; } const ClipRectangle& carea = mClipStack.top(); SDL_Rect rect; rect.x = carea.x; rect.y = carea.y; rect.w = carea.width; rect.h = carea.height; SDL_SetClipRect(mTarget, &rect); } SDL_Surface* SDLGraphics::getTarget() const { return mTarget; } void SDLGraphics::drawImage(const Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); SDL_Rect src; SDL_Rect dst; src.x = srcX; src.y = srcY; src.w = width; src.h = height; dst.x = dstX + top.xOffset; dst.y = dstY + top.yOffset; const SDLImage* srcImage = dynamic_cast(image); if (srcImage == NULL) { throw FCN_EXCEPTION("Trying to draw an image of unknown format, must be an SDLImage."); } SDL_BlitSurface(srcImage->getSurface(), &src, mTarget, &dst); } void SDLGraphics::fillRectangle(const Rectangle& rectangle) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); Rectangle area = rectangle; area.x += top.xOffset; area.y += top.yOffset; if(!area.isIntersecting(top)) { return; } if (mAlpha) { int x1 = area.x > top.x ? area.x : top.x; int y1 = area.y > top.y ? area.y : top.y; int x2 = area.x + area.width < top.x + top.width ? area.x + area.width : top.x + top.width; int y2 = area.y + area.height < top.y + top.height ? area.y + area.height : top.y + top.height; int x, y; SDL_LockSurface(mTarget); for (y = y1; y < y2; y++) { for (x = x1; x < x2; x++) { SDLputPixelAlpha(mTarget, x, y, mColor); } } SDL_UnlockSurface(mTarget); } else { SDL_Rect rect; rect.x = area.x; rect.y = area.y; rect.w = area.width; rect.h = area.height; Uint32 color = SDL_MapRGBA(mTarget->format, mColor.r, mColor.g, mColor.b, mColor.a); SDL_FillRect(mTarget, &rect, color); } } void SDLGraphics::drawPoint(int x, int y) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); x += top.xOffset; y += top.yOffset; if(!top.isContaining(x,y)) return; if (mAlpha) { SDLputPixelAlpha(mTarget, x, y, mColor); } else { SDLputPixel(mTarget, x, y, mColor); } } void SDLGraphics::drawHLine(int x1, int y, int x2) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); x1 += top.xOffset; y += top.yOffset; x2 += top.xOffset; if (y < top.y || y >= top.y + top.height) { return; } if (x1 > x2) { x1 ^= x2; x2 ^= x1; x1 ^= x2; } if (top.x > x1) { if (top.x > x2) { return; } x1 = top.x; } if (top.x + top.width <= x2) { if (top.x + top.width <= x1) { return; } x2 = top.x + top.width -1; } int bpp = mTarget->format->BytesPerPixel; SDL_LockSurface(mTarget); Uint8 *p = (Uint8 *)mTarget->pixels + y * mTarget->pitch + x1 * bpp; Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); switch(bpp) { case 1: for (;x1 <= x2; ++x1) { *(p++) = pixel; } break; case 2: { Uint16* q = (Uint16*)p; for (;x1 <= x2; ++x1) { *(q++) = pixel; } break; } case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { for (;x1 <= x2; ++x1) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; p += 3; } } else { for (;x1 <= x2; ++x1) { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; p += 3; } } break; case 4: { Uint32* q = (Uint32*)p; for (;x1 <= x2; ++x1) { if (mAlpha) { *q = SDLAlpha32(pixel,*q,mColor.a); q++; } else { *(q++) = pixel; } } break; } } // end switch SDL_UnlockSurface(mTarget); } void SDLGraphics::drawVLine(int x, int y1, int y2) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); x += top.xOffset; y1 += top.yOffset; y2 += top.yOffset; if (x < top.x || x >= top.x + top.width) { return; } if (y1 > y2) { y1 ^= y2; y2 ^= y1; y1 ^= y2; } if (top.y > y1) { if (top.y > y2) { return; } y1 = top.y; } if (top.y + top.height <= y2) { if (top.y + top.height <= y1) { return; } y2 = top.y + top.height - 1; } int bpp = mTarget->format->BytesPerPixel; SDL_LockSurface(mTarget); Uint8 *p = (Uint8 *)mTarget->pixels + y1 * mTarget->pitch + x * bpp; Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); switch(bpp) { case 1: for (;y1 <= y2; ++y1) { *p = pixel; p += mTarget->pitch; } break; case 2: for (;y1 <= y2; ++y1) { *(Uint16*)p = pixel; p += mTarget->pitch; } break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { for (;y1 <= y2; ++y1) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; p += mTarget->pitch; } } else { for (;y1 <= y2; ++y1) { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; p += mTarget->pitch; } } break; case 4: for (;y1 <= y2; ++y1) { if (mAlpha) { *(Uint32*)p = SDLAlpha32(pixel,*(Uint32*)p,mColor.a); } else { *(Uint32*)p = pixel; } p += mTarget->pitch; } break; } // end switch SDL_UnlockSurface(mTarget); } void SDLGraphics::drawRectangle(const Rectangle& rectangle) { int x1 = rectangle.x; int x2 = rectangle.x + rectangle.width - 1; int y1 = rectangle.y; int y2 = rectangle.y + rectangle.height - 1; drawHLine(x1, y1, x2); drawHLine(x1, y2, x2); drawVLine(x1, y1, y2); drawVLine(x2, y1, y2); } void SDLGraphics::drawLine(int x1, int y1, int x2, int y2) { if (x1 == x2) { drawVLine(x1, y1, y2); return; } if (y1 == y2) { drawHLine(x1, y1, x2); return; } if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); x1 += top.xOffset; y1 += top.yOffset; x2 += top.xOffset; y2 += top.yOffset; // Draw a line with Bresenham int dx = ABS(x2 - x1); int dy = ABS(y2 - y1); if (dx > dy) { if (x1 > x2) { // swap x1, x2 x1 ^= x2; x2 ^= x1; x1 ^= x2; // swap y1, y2 y1 ^= y2; y2 ^= y1; y1 ^= y2; } if (y1 < y2) { int y = y1; int p = 0; for (int x = x1; x <= x2; x++) { if (top.isContaining(x, y)) { if (mAlpha) { SDLputPixelAlpha(mTarget, x, y, mColor); } else { SDLputPixel(mTarget, x, y, mColor); } } p += dy; if (p * 2 >= dx) { y++; p -= dx; } } } else { int y = y1; int p = 0; for (int x = x1; x <= x2; x++) { if (top.isContaining(x, y)) { if (mAlpha) { SDLputPixelAlpha(mTarget, x, y, mColor); } else { SDLputPixel(mTarget, x, y, mColor); } } p += dy; if (p * 2 >= dx) { y--; p -= dx; } } } } else { if (y1 > y2) { // swap y1, y2 y1 ^= y2; y2 ^= y1; y1 ^= y2; // swap x1, x2 x1 ^= x2; x2 ^= x1; x1 ^= x2; } if (x1 < x2) { int x = x1; int p = 0; for (int y = y1; y <= y2; y++) { if (top.isContaining(x, y)) { if (mAlpha) { SDLputPixelAlpha(mTarget, x, y, mColor); } else { SDLputPixel(mTarget, x, y, mColor); } } p += dx; if (p * 2 >= dy) { x++; p -= dy; } } } else { int x = x1; int p = 0; for (int y = y1; y <= y2; y++) { if (top.isContaining(x, y)) { if (mAlpha) { SDLputPixelAlpha(mTarget, x, y, mColor); } else { SDLputPixel(mTarget, x, y, mColor); } } p += dx; if (p * 2 >= dy) { x--; p -= dy; } } } } } void SDLGraphics::setColor(const Color& color) { mColor = color; mAlpha = color.a != 255; } const Color& SDLGraphics::getColor() const { return mColor; } void SDLGraphics::drawSDLSurface(SDL_Surface* surface, SDL_Rect source, SDL_Rect destination) { if (mClipStack.empty()) { throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?"); } const ClipRectangle& top = mClipStack.top(); destination.x += top.xOffset; destination.y += top.yOffset; SDL_BlitSurface(surface, &source, mTarget, &destination); } } fifechan-0.1.5/src/sdl/sdlimage.cpp000066400000000000000000000143411341577075500171430ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/sdl/sdlimage.hpp" #include "fifechan/exception.hpp" #include "fifechan/sdl/sdlimageloader.hpp" #include "fifechan/sdl/sdlpixel.hpp" namespace fcn { SDLImage::SDLImage(SDL_Surface* surface, bool autoFree) { mAutoFree = autoFree; mSurface = surface; } SDLImage::~SDLImage() { if (mAutoFree) { free(); } } SDL_Surface* SDLImage::getSurface() const { return mSurface; } int SDLImage::getWidth() const { if (mSurface == NULL) { throw FCN_EXCEPTION("Trying to get the width of a non loaded image."); } return mSurface->w; } int SDLImage::getHeight() const { if (mSurface == NULL) { throw FCN_EXCEPTION("Trying to get the height of a non loaded image."); } return mSurface->h; } Color SDLImage::getPixel(int x, int y) { if (mSurface == NULL) { throw FCN_EXCEPTION("Trying to get a pixel from a non loaded image."); } return SDLgetPixel(mSurface, x, y); } void SDLImage::putPixel(int x, int y, const Color& color) { if (mSurface == NULL) { throw FCN_EXCEPTION("Trying to put a pixel in a non loaded image."); } SDLputPixel(mSurface, x, y, color); } void SDLImage::convertToDisplayFormat() { if (mSurface == NULL) { throw FCN_EXCEPTION("Trying to convert a non loaded image to display format."); } SDLImageLoader* loader = static_cast(mImageLoader); const SDL_PixelFormat& format = loader->getSDLPixelFormat(); int i; bool hasPink = false; bool hasAlpha = false; for (i = 0; i < mSurface->w * mSurface->h; ++i) { if (((unsigned int*)mSurface->pixels)[i] == SDL_MapRGB(mSurface->format,255,0,255)) { hasPink = true; break; } } for (i = 0; i < mSurface->w * mSurface->h; ++i) { Uint8 r, g, b, a; SDL_GetRGBA(((unsigned int*)mSurface->pixels)[i], mSurface->format, &r, &g, &b, &a); if (a != 255) { hasAlpha = true; break; } } SDL_Surface* tmp = SDL_ConvertSurface(mSurface, &format, 0); SDL_FreeSurface(mSurface); mSurface = NULL; if (tmp == NULL) { throw FCN_EXCEPTION("Unable to convert image to display format."); } if (hasPink) { SDL_SetColorKey(tmp, SDL_TRUE, SDL_MapRGB(tmp->format,255,0,255)); } if (hasAlpha) { // I'm not sure about this, maybe we should change // SDL_SetSurfaceBlendMode() instead e.g. to disable alpha blending // if hasAlpha is false. //SDL_SetAlpha(tmp, SDL_SRCALPHA, 255); SDL_SetSurfaceAlphaMod(tmp, 255); } mSurface = tmp; } void SDLImage::free() { SDL_FreeSurface(mSurface); } } fifechan-0.1.5/src/sdl/sdlimageloader.cpp000066400000000000000000000127041341577075500203330ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/sdl/sdlimage.hpp" #include "SDL_image.h" #include "fifechan/exception.hpp" #include "fifechan/sdl/sdlimageloader.hpp" namespace fcn { Image* SDLImageLoader::load(const std::string& filename, bool convertToDisplayFormat) { SDL_Surface *loadedSurface = loadSDLSurface(filename); if (loadedSurface == NULL) { throw FCN_EXCEPTION( std::string("Unable to load image file: ") + filename); } SDL_Surface *surface = convertToStandardFormat(loadedSurface); SDL_FreeSurface(loadedSurface); if (surface == NULL) { throw FCN_EXCEPTION( std::string("Not enough memory to load: ") + filename); } Image *image = new SDLImage(surface, true); if (convertToDisplayFormat) { image->convertToDisplayFormat(); } return image; } SDL_Surface* SDLImageLoader::loadSDLSurface(const std::string& filename) { return IMG_Load(filename.c_str()); } SDL_Surface* SDLImageLoader::convertToStandardFormat(SDL_Surface* surface) { Uint32 rmask, gmask, bmask, 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 *colorSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32, rmask, gmask, bmask, amask); SDL_Surface *tmp = NULL; if (colorSurface != NULL) { tmp = SDL_ConvertSurface(surface, colorSurface->format, SDL_SWSURFACE); SDL_FreeSurface(colorSurface); } return tmp; } const SDL_PixelFormat& SDLImageLoader::getSDLPixelFormat() { return mPixelFormat; } void SDLImageLoader::setSDLPixelFormat(const SDL_PixelFormat& format) { mPixelFormat = format; } } fifechan-0.1.5/src/sdl/sdlinput.cpp000066400000000000000000000417521341577075500172260ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/sdl/sdlinput.hpp" #include "fifechan/exception.hpp" #include "fifechan/util/utf8/utf8.hpp" #include #include namespace fcn { SDLInput::SDLInput() { mMouseInWindow = true; mMouseDown = false; } bool SDLInput::isKeyQueueEmpty() { return mKeyInputQueue.empty(); } KeyInput SDLInput::dequeueKeyInput() { KeyInput keyInput; if (mKeyInputQueue.empty()) { throw FCN_EXCEPTION("The queue is empty."); } keyInput = mKeyInputQueue.front(); mKeyInputQueue.pop(); return keyInput; } bool SDLInput::isMouseQueueEmpty() { return mMouseInputQueue.empty(); } MouseInput SDLInput::dequeueMouseInput() { MouseInput mouseInput; if (mMouseInputQueue.empty()) { throw FCN_EXCEPTION("The queue is empty."); } mouseInput = mMouseInputQueue.front(); mMouseInputQueue.pop(); return mouseInput; } void SDLInput::pushInput(SDL_Event event) { KeyInput keyInput; MouseInput mouseInput; switch (event.type) { case SDL_KEYDOWN: { int value = convertSDLEventToFifechanKeyValue(event); keyInput.setKey(Key(value)); keyInput.setType(KeyInput::Pressed); keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI); keyInput.setNumericPad(event.key.keysym.mod & KMOD_NUM); mKeyInputQueue.push(keyInput); break; } case SDL_KEYUP: { int value = convertSDLEventToFifechanKeyValue(event); if (value == -1) { value = (int)event.key.keysym.sym; } keyInput.setKey(Key(value)); keyInput.setType(KeyInput::Released); keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI); keyInput.setNumericPad(event.key.keysym.mod & KMOD_NUM); mKeyInputQueue.push(keyInput); break; } case SDL_MOUSEBUTTONDOWN: { mMouseDown = true; mouseInput.setX(event.button.x); mouseInput.setY(event.button.y); mouseInput.setButton(convertMouseButton(event.button.button)); mouseInput.setType(MouseInput::Pressed); mouseInput.setTimeStamp(SDL_GetTicks()); mMouseInputQueue.push(mouseInput); break; } case SDL_MOUSEBUTTONUP: { mMouseDown = false; mouseInput.setX(event.button.x); mouseInput.setY(event.button.y); mouseInput.setButton(convertMouseButton(event.button.button)); mouseInput.setType(MouseInput::Released); mouseInput.setTimeStamp(SDL_GetTicks()); mMouseInputQueue.push(mouseInput); break; } case SDL_MOUSEMOTION: { mouseInput.setX(event.motion.x); mouseInput.setY(event.motion.y); mouseInput.setButton(MouseInput::Empty); mouseInput.setType(MouseInput::Moved); mouseInput.setTimeStamp(SDL_GetTicks()); mMouseInputQueue.push(mouseInput); break; } case SDL_MOUSEWHEEL: { /*if (event.wheel.y > 0 || (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED && event.wheel.y < 0)) { mouseInput.setType(MouseInput::WheelMovedUp); } else if (event.wheel.y < 0 || (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED && event.wheel.y > 0)) { mouseInput.setType(MouseInput::WheelMovedDown); }*/ /*if (event.wheel.x > 0 || (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED && event.wheel.x < 0)) { mouseInput.setType(MouseInput::WheelMovedRight); } else if (event.wheel.x < 0 || (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED && event.wheel.x > 0)) { mouseInput.setType(MouseInput::WheelMovedLeft); }*/ if (event.wheel.y > 0) { mouseInput.setType(MouseInput::WheelMovedUp); } else if (event.wheel.y < 0) { mouseInput.setType(MouseInput::WheelMovedDown); } if (event.wheel.x > 0) { mouseInput.setType(MouseInput::WheelMovedRight); } else if (event.wheel.x < 0) { mouseInput.setType(MouseInput::WheelMovedLeft); } int x, y; SDL_GetMouseState(&x, &y); mouseInput.setX(x); mouseInput.setY(y); mouseInput.setButton(convertMouseButton(SDL_BUTTON_LEFT)); mouseInput.setTimeStamp(SDL_GetTicks()); mMouseInputQueue.push(mouseInput); break; } //case SDL_TEXTEDITING: case SDL_TEXTINPUT: { std::string text(event.text.text); if (!text.empty()) { // hack to transport text std::vector result; utf8::utf8to16(text.begin(), text.end(), std::back_inserter(result)); int value = result[0]; keyInput.setKey(Key(value)); keyInput.setType(KeyInput::Pressed); keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI); keyInput.setNumericPad(event.key.keysym.mod & KMOD_NUM); mKeyInputQueue.push(keyInput); } break; } case SDL_WINDOWEVENT: { /* * This occurs when the mouse enters/leaves the window and the fifechan * application gains/loses its mousefocus. */ if (event.window.event == SDL_WINDOWEVENT_ENTER) { mMouseInWindow = true; } else if (event.window.event == SDL_WINDOWEVENT_LEAVE) { mMouseInWindow = false; // Why??? /*if (!mMouseDown) { mouseInput.setX(-1); mouseInput.setY(-1); mouseInput.setButton(MouseInput::Empty); mouseInput.setType(MouseInput::Moved); mMouseInputQueue.push(mouseInput); }*/ } break; } } // end switch } int SDLInput::convertMouseButton(int button) { switch (button) { case SDL_BUTTON_LEFT: return MouseInput::Left; break; case SDL_BUTTON_RIGHT: return MouseInput::Right; break; case SDL_BUTTON_MIDDLE: return MouseInput::Middle; break; case SDL_BUTTON_X1: return MouseInput::X1; break; case SDL_BUTTON_X2: return MouseInput::X2; break; default: // We have an unknown mouse type which is ignored. return button; } } int SDLInput::convertSDLEventToFifechanKeyValue(SDL_Event event) { int value = -1; switch (event.key.keysym.sym) { case SDLK_TAB: value = Key::Tab; break; case SDLK_LALT: value = Key::LeftAlt; break; case SDLK_RALT: value = Key::RightAlt; break; case SDLK_LSHIFT: value = Key::LeftShift; break; case SDLK_RSHIFT: value = Key::RightShift; break; case SDLK_LCTRL: value = Key::LeftControl; break; case SDLK_RCTRL: value = Key::RightControl; break; case SDLK_BACKSPACE: value = Key::Backspace; break; case SDLK_PAUSE: value = Key::Pause; break; case SDLK_SPACE: // Special characters like ~ (tilde) ends up // with the keysym.sym SDLK_SPACE which // without this check would be lost. The check // is only valid on key up events in SDL. //if (event.type == SDL_KEYUP || event.key.keysym.unicode == ' ') if (event.type == SDL_KEYUP) { value = Key::Space; } break; case SDLK_ESCAPE: value = Key::Escape; break; case SDLK_DELETE: value = Key::Delete; break; case SDLK_INSERT: value = Key::Insert; break; case SDLK_HOME: value = Key::Home; break; case SDLK_END: value = Key::End; break; case SDLK_PAGEUP: value = Key::PageUp; break; case SDLK_PRINTSCREEN: value = Key::PrintScreen; break; case SDLK_PAGEDOWN: value = Key::PageDown; break; case SDLK_F1: value = Key::F1; break; case SDLK_F2: value = Key::F2; break; case SDLK_F3: value = Key::F3; break; case SDLK_F4: value = Key::F4; break; case SDLK_F5: value = Key::F5; break; case SDLK_F6: value = Key::F6; break; case SDLK_F7: value = Key::F7; break; case SDLK_F8: value = Key::F8; break; case SDLK_F9: value = Key::F9; break; case SDLK_F10: value = Key::F10; break; case SDLK_F11: value = Key::F11; break; case SDLK_F12: value = Key::F12; break; case SDLK_F13: value = Key::F13; break; case SDLK_F14: value = Key::F14; break; case SDLK_F15: value = Key::F15; break; case SDLK_NUMLOCKCLEAR: value = Key::NumLock; break; case SDLK_CAPSLOCK: value = Key::CapsLock; break; case SDLK_SCROLLLOCK: value = Key::ScrollLock; break; case SDLK_LGUI: value = Key::LeftSuper; break; case SDLK_RGUI: value = Key::RightSuper; break; case SDLK_MODE: value = Key::AltGr; break; case SDLK_UP: value = Key::Up; break; case SDLK_DOWN: value = Key::Down; break; case SDLK_LEFT: value = Key::Left; break; case SDLK_RIGHT: value = Key::Right; break; case SDLK_RETURN: value = Key::Enter; break; case SDLK_KP_ENTER: value = Key::Enter; break; default: break; } if (!(event.key.keysym.mod & KMOD_NUM)) { switch (event.key.keysym.sym) { case SDLK_KP_0: value = Key::Insert; break; case SDLK_KP_1: value = Key::End; break; case SDLK_KP_2: value = Key::Down; break; case SDLK_KP_3: value = Key::PageDown; break; case SDLK_KP_4: value = Key::Left; break; case SDLK_KP_5: value = 0; break; case SDLK_KP_6: value = Key::Right; break; case SDLK_KP_7: value = Key::Home; break; case SDLK_KP_8: value = Key::Up; break; case SDLK_KP_9: value = Key::PageUp; break; default: break; } } return value; } } fifechan-0.1.5/src/selectionevent.cpp000066400000000000000000000076531341577075500176330ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/selectionevent.hpp" namespace fcn { SelectionEvent::SelectionEvent(Widget* source) :Event(source) { } SelectionEvent::~SelectionEvent() { } } fifechan-0.1.5/src/size.cpp000066400000000000000000000037441341577075500155530ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "fifechan/size.hpp" namespace fcn { Size::Size(int width, int height): mWidth(width), mHeight(height) { } Size::~Size() { } int Size::getWidth() const { return mWidth; } int Size::getHeight() const { return mHeight; } void Size::setWidth(int width) { mWidth = width; } void Size::setHeight(int height) { mHeight = height; } }; fifechan-0.1.5/src/text.cpp000066400000000000000000000341661341577075500155670ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/text.hpp" #include "fifechan/exception.hpp" #include "fifechan/font.hpp" namespace fcn { Text::Text() :mCaretPosition(0), mCaretRow(0), mCaretColumn(0) { } Text::Text(const std::string& content) :mCaretPosition(0), mCaretRow(0), mCaretColumn(0) { std::string::size_type pos, lastPos = 0; int length; do { pos = content.find("\n", lastPos); if (pos != std::string::npos) length = pos - lastPos; else length = content.size() - lastPos; std::string sub = content.substr(lastPos, length); mRows.push_back(sub); lastPos = pos + 1; } while (pos != std::string::npos); } Text::~Text() { } void Text::setContent(const std::string& content) { //reset caret mCaretPosition = 0; mCaretRow = 0; mCaretColumn = 0; mRows.clear(); std::string::size_type pos, lastPos = 0; int length; do { pos = content.find("\n", lastPos); if (pos != std::string::npos) length = pos - lastPos; else length = content.size() - lastPos; std::string sub = content.substr(lastPos, length); mRows.push_back(sub); lastPos = pos + 1; } while (pos != std::string::npos); } std::string Text::getContent() const { if (mRows.empty()) return std::string(""); std::string result; unsigned int i; for (i = 0; i < mRows.size() - 1; ++i) result = result + mRows[i] + "\n"; result = result + mRows[i]; return result; } void Text::setRow(unsigned int row, const std::string& content) { if (row >= mRows.size()) throw FCN_EXCEPTION("Row out of bounds!"); mRows[row] = content; } void Text::addRow(const std::string& row) { unsigned int i; for (i = 0; i < row.size(); i++) { if (row[i] == '\n') throw FCN_EXCEPTION("Line feed not allowed in the row to be added!"); } mRows.push_back(row); } void Text::insertRow(const std::string& row, unsigned int position) { unsigned int totalRows = mRows.size(); if(position >= totalRows) { if(position == totalRows) { addRow(row); return; } else { throw FCN_EXCEPTION("Position out of bounds!"); } } unsigned int i; for(i = 0; i < row.size(); i++) { if(row[i] == '\n') throw FCN_EXCEPTION("Line feed not allowed in the row to be inserted!"); } mRows.insert(mRows.begin() + position, row); } void Text::eraseRow(unsigned int row) { if(row >= mRows.size()) throw FCN_EXCEPTION("Row to be erased out of bounds!"); mRows.erase(mRows.begin() + row); } std::string& Text::getRow(unsigned int row) { if (row >= mRows.size()) throw FCN_EXCEPTION("Row out of bounds!"); return mRows[row]; } void Text::insert(int character) { char c = (char)character; if (mRows.empty()) { if (c == '\n') mRows.push_back(""); else mRows.push_back(std::string(1, c)); } else { if (c == '\n') { mRows.insert(mRows.begin() + mCaretRow + 1, mRows[mCaretRow].substr(mCaretColumn, mRows[mCaretRow].size() - mCaretColumn)); mRows[mCaretRow].resize(mCaretColumn); } else mRows[mCaretRow].insert(mCaretColumn, std::string(1, c)); } setCaretPosition(getCaretPosition() + 1); } void Text::remove(int numberOfCharacters) { if (mRows.empty() || numberOfCharacters == 0) return; // We should remove characters left of the caret position. if (numberOfCharacters < 0) { while (numberOfCharacters != 0) { // If the caret position is zero there is nothing // more to do. if (mCaretPosition == 0) break; // If we are at the end of the row // and the row is not the first row we // need to merge two rows. if (mCaretColumn == 0 && mCaretRow != 0) { mRows[mCaretRow - 1] += mRows[mCaretRow]; mRows.erase(mRows.begin() + mCaretRow); setCaretRow(mCaretRow - 1); setCaretColumn(getNumberOfCharacters(mCaretRow)); } else { mRows[mCaretRow].erase(mCaretColumn - 1, 1); setCaretPosition(mCaretPosition - 1); } numberOfCharacters++; } } // We should remove characters right of the caret position. else if (numberOfCharacters > 0) { while (numberOfCharacters != 0) { // If all rows have been removed there is nothing // more to do. if (mRows.empty()) break; // If we are at the end of row and the row // is not the last row we need to merge two // rows. if (mCaretColumn == mRows[mCaretRow].size() && mCaretRow < (mRows.size() - 1)) { mRows[mCaretRow] += mRows[mCaretRow + 1]; mRows.erase(mRows.begin() + mCaretRow + 1); } else { mRows[mCaretRow].erase(mCaretColumn, 1); } numberOfCharacters--; } } } int Text::getCaretPosition() const { return mCaretPosition; } void Text::setCaretPosition(int position) { if (mRows.empty() || position < 0) { mCaretPosition = 0; mCaretRow = 0; mCaretColumn = 0; return; } // Loop through all rows until we find the // position of the caret. unsigned int i; unsigned int total = 0; for (i = 0; i < mRows.size(); i++) { if (position <= (int)(total + mRows[i].size())) { mCaretRow = i; mCaretColumn = position - total; mCaretPosition = position; return; } // Add one for the line feed. total += mRows[i].size() + 1; } // The position is beyond the content. // Remove one as the last line doesn't have a line feed. mCaretPosition = total - 1; mCaretRow = mRows.size() - 1; mCaretColumn = mRows[mCaretRow].size(); } void Text::setCaretPosition(int x, int y, Font* font) { if (mRows.empty()) return; setCaretRow(y / font->getHeight()); setCaretColumn(font->getStringIndexAt(mRows[mCaretRow], x)); } int Text::getCaretColumn() const { return mCaretColumn; } int Text::getCaretRow() const { return mCaretRow; } void Text::setCaretColumn(int column) { if (mRows.empty() || column < 0) mCaretColumn = 0; else if (column > (int)mRows[mCaretRow].size()) mCaretColumn = mRows[mCaretRow].size(); else mCaretColumn = column; calculateCaretPositionFromRowAndColumn(); } void Text::setCaretRow(int row) { if (mRows.empty() || row < 0) mCaretRow = 0; else if (row >= (int)mRows.size()) mCaretRow = mRows.size() - 1; else mCaretRow = row; setCaretColumn(mCaretColumn); } int Text::getCaretX(Font* font) const { if (mRows.empty()) return 0; return font->getWidth(mRows[mCaretRow].substr(0, mCaretColumn)); } int Text::getCaretY(Font* font) const { return mCaretRow * font->getHeight();; } Rectangle Text::getDimension(Font* font) const { if (mRows.empty()) return Rectangle(0, 0, font->getWidth(" "), font->getHeight()); int width = 0; unsigned int i; for (i = 0; i < mRows.size(); ++i) { int w = font->getWidth(mRows[i]); if (width < w) width = w; } return Rectangle(0, 0, width + font->getWidth(" "), font->getHeight() * mRows.size()); } Rectangle Text::getCaretDimension(Font* font) const { Rectangle dim; dim.x = !mRows.empty() ? font->getWidth(mRows[mCaretRow].substr(0, mCaretColumn)) : 0; dim.y = font->getHeight() * mCaretRow; dim.width = font->getWidth(" "); // We add two for some extra spacing to be sure the whole caret is visible. dim.height = font->getHeight() + 2; return dim; } int Text::getWidth(int row, Font* font) const { return 0; } unsigned int Text::getMaximumCaretRow() const { return 0; } unsigned int Text::getMaximumCaretRow(unsigned int row) const { return 0; } unsigned int Text::getNumberOfCharacters() const { unsigned int result = 0; unsigned int i; for (i = 0; i < mRows.size(); ++i) result += mRows[i].size() + 1; return result; } unsigned int Text::getNumberOfRows() const { return mRows.size(); } unsigned int Text::getNumberOfCharacters(unsigned int row) const { if (row >= mRows.size()) return 0; return mRows[row].size(); } void Text::calculateCaretPositionFromRowAndColumn() { unsigned int i; unsigned int total = 0; for (i = 0; i < mCaretRow; i++) // Add one for the line feed. total += mRows[i].size() + 1; mCaretPosition = total + mCaretColumn; } } fifechan-0.1.5/src/utf8stringeditor.cpp000066400000000000000000000070171341577075500201220ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include #include #include namespace fcn { int UTF8StringEditor::nextChar(const std::string & text, int byteOffset) { std::string::const_iterator c, e; c = text.begin() + byteOffset; e = text.end(); utf8::next(c, e); return std::string(text.begin(), c).size(); } int UTF8StringEditor::prevChar(const std::string & text, int byteOffset) { std::string::const_iterator c, b; c = text.begin() + byteOffset; b = text.begin(); utf8::prior(c, b); return std::string(b, c).size(); } int UTF8StringEditor::eraseChar(std::string & text, int byteOffset) { std::string::iterator begin, cur; begin = text.begin() + byteOffset; cur = begin; utf8::next(cur, text.end()); text = std::string(text.begin(), begin) + std::string(cur, text.end()); return byteOffset; // this shouldn't change! } int UTF8StringEditor::insertChar(std::string & text, int byteOffset, int ch) { std::string newText; std::string::iterator cut; int newOffset; // make a temp string from left part of the caret (+6 extra chars) newText = text.substr(0, byteOffset) + " "; // append character utf8::append(ch, newText.begin() + byteOffset); // calculate newText real length cut = newText.begin() + byteOffset; utf8::next(cut, newText.end()); // cut the string to real length newText = std::string(newText.begin(), cut); newOffset = newText.size(); // make new text text = newText + text.substr(byteOffset); return newOffset; } int UTF8StringEditor::countChars(const std::string & text, int byteOffset) { return utf8::distance(text.begin(), text.begin() + byteOffset); } int UTF8StringEditor::getOffset(const std::string & text, int charIndex) { std::string::const_iterator cur, end; int bytes = 0, i; if (charIndex < 0) return 0; cur = text.begin(); end = text.end(); for(i = 0; i < charIndex && cur != end; i++) { utf8::next(cur, end); } return std::string(text.begin(), cur).size(); } }; fifechan-0.1.5/src/visibilityeventhandler.cpp000066400000000000000000000037741341577075500213730ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "fifechan/visibilityeventhandler.hpp" #include "fifechan/event.hpp" #include "fifechan/gui.hpp" #include namespace fcn { VisibilityEventHandler::VisibilityEventHandler(Gui *gui) : mGui(gui) { } void VisibilityEventHandler::widgetHidden(const Event& e) { mGui->enqueueHiddenWidget(e.getSource()); } void VisibilityEventHandler::widgetShown(const Event& e) { mGui->enqueueShownWidget(e.getSource()); } };fifechan-0.1.5/src/widget.cpp000066400000000000000000001222671341577075500160660ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widget.hpp" #include "fifechan/actionevent.hpp" #include "fifechan/actionlistener.hpp" #include "fifechan/deathlistener.hpp" #include "fifechan/defaultfont.hpp" #include "fifechan/event.hpp" #include "fifechan/exception.hpp" #include "fifechan/focushandler.hpp" #include "fifechan/graphics.hpp" #include "fifechan/keyinput.hpp" #include "fifechan/keylistener.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/mouselistener.hpp" #include "fifechan/visibilityeventhandler.hpp" #include "fifechan/widgetlistener.hpp" #include namespace fcn { Font* Widget::mGlobalFont = NULL; DefaultFont Widget::mDefaultFont; std::list Widget::mWidgetInstances; VisibilityEventHandler* Widget::mVisibilityEventHandler = NULL; DeathListener* Widget::mGuiDeathListener = NULL; Widget::Widget() : mForegroundColor(0x000000), mBackgroundColor(0xffffff), mBaseColor(0x808090), mSelectionColor(0xc3d9ff), mOutlineColor(0x808090), mBorderColor(0x808090), mFocusHandler(NULL), mInternalFocusHandler(NULL), mParent(NULL), mOutlineSize(0), mBorderSize(0), mSelectionMode(Selection_None), mMarginTop(0), mMarginRight(0), mMarginBottom(0), mMarginLeft(0), mPaddingTop(0), mPaddingRight(0), mPaddingBottom(0), mPaddingLeft(0), mFocusable(false), mVisible(true), mTabIn(true), mTabOut(true), mEnabled(true), mCurrentFont(NULL), mMinSize(0, 0), mMaxSize(50000, 50000), mFixedSize(-1, -1), mIsFixedSize(false), mVExpand(false), mHExpand(false), mLastX(0), mLastY(0) { mWidgetInstances.push_back(this); } Widget::~Widget() { if (mParent != NULL) mParent->remove(this); std::list::const_iterator childrenIter; for (childrenIter = mChildren.begin(); childrenIter != mChildren.end(); childrenIter++) (*childrenIter)->_setParent(NULL); std::list::const_iterator deathIter; for (deathIter = mDeathListeners.begin(); deathIter != mDeathListeners.end(); ++deathIter) { Event event(this); (*deathIter)->death(event); } if (mGuiDeathListener) { Event event(this); mGuiDeathListener->death(event); } _setFocusHandler(NULL); mWidgetInstances.remove(this); } void Widget::drawOutline(Graphics* graphics) { Color outlineColor = getOutlineColor(); Color highlightColor, shadowColor; int alpha = getBaseColor().a; int width = getWidth() + getOutlineSize() * 2 - 1; int height = getHeight() + getOutlineSize() * 2 - 1; highlightColor = outlineColor + 0x303030; highlightColor.a = alpha; shadowColor = outlineColor - 0x303030; shadowColor.a = alpha; unsigned int i; for (i = 0; i < getOutlineSize(); ++i) { graphics->setColor(shadowColor); graphics->drawLine(i,i, width - i, i); graphics->drawLine(i,i + 1, i, height - i - 1); graphics->setColor(highlightColor); graphics->drawLine(width - i,i + 1, width - i, height - i); graphics->drawLine(i,height - i, width - i - 1, height - i); } } void Widget::drawBorder(Graphics* graphics) { Color borderColor = getBorderColor(); Color highlightColor, shadowColor; int alpha = getBaseColor().a; int width = getWidth() - 1; int height = getHeight() - 1; highlightColor = borderColor + 0x303030; highlightColor.a = alpha; shadowColor = borderColor - 0x303030; shadowColor.a = alpha; unsigned int i; for (i = 0; i < getBorderSize(); ++i) { graphics->setColor(shadowColor); graphics->drawLine(i, i, width-i, i); graphics->drawLine(i, i+1, i, height-i-1); graphics->setColor(highlightColor); graphics->drawLine(width-i, i+1, width-i, height-i); graphics->drawLine(i, height-i, width-i-1, height-i); } } void Widget::drawSelectionFrame(Graphics* graphics) { int width = getWidth() - 1; int height = getHeight() - 1; graphics->setColor(getSelectionColor()); unsigned int i; // currently border size is used here too, not sure an extra frame size is really needed. for (i = 0; i < getBorderSize(); ++i) { // would be better but causes problems with OpenGL //graphics->drawRectangle(i, i, width - 2 * i, height - 2 * i); graphics->drawLine(i, i, width-i, i); graphics->drawLine(i, i+1, i, height-i-1); graphics->drawLine(width-i, i+1, width-i, height-i); graphics->drawLine(i, height-i, width-i-1, height-i); } } void Widget::_setParent(Widget* parent) { mParent = parent; } Widget* Widget::getParent() const { return mParent; } void Widget::setWidth(int width) { Rectangle newDimension = mDimension; newDimension.width = width; setDimension(newDimension); } int Widget::getWidth() const { return mDimension.width; } void Widget::setHeight(int height) { Rectangle newDimension = mDimension; newDimension.height = height; setDimension(newDimension); } int Widget::getHeight() const { return mDimension.height; } void Widget::setX(int x) { Rectangle newDimension = mDimension; newDimension.x = x; setDimension(newDimension); } int Widget::getX() const { return mDimension.x; } void Widget::setY(int y) { Rectangle newDimension = mDimension; newDimension.y = y; setDimension(newDimension); } int Widget::getY() const { return mDimension.y; } void Widget::setPosition(int x, int y) { Rectangle newDimension = mDimension; newDimension.x = x; newDimension.y = y; setDimension(newDimension); } void Widget::setDimension(const Rectangle& dimension) { Rectangle oldDimension = mDimension; mDimension = dimension; if (mDimension.width != oldDimension.width || mDimension.height != oldDimension.height) { calculateSize(); if (mDimension.width != oldDimension.width || mDimension.height != oldDimension.height) { distributeResizedEvent(); } } if (mDimension.x != oldDimension.x || mDimension.y != oldDimension.y) { distributeMovedEvent(); std::list::iterator currChild(mChildren.begin()); std::list::iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { (*currChild)->distributeAncestorMovedEvent(this); } } } unsigned int Widget::getChildrenCount() const { unsigned int childs = 0; std::list::const_iterator currChild(mChildren.begin()); std::list::const_iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { ++childs; } return childs; } unsigned int Widget::getVisibleChildrenCount() const { unsigned int childs = 0; std::list::const_iterator currChild(mChildren.begin()); std::list::const_iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { if (isVisible()) { ++childs; } } return childs; } void Widget::setMinSize(const Size& size) { mMinSize = size; calculateSize(); } const Size& Widget::getMinSize() const { return mMinSize; } void Widget::setMaxSize(const Size& size) { mMaxSize = size; calculateSize(); } const Size& Widget::getMaxSize() const { return mMaxSize; } void Widget::setFixedSize(const Size& size) { mFixedSize = size; if (mFixedSize.getWidth() < 0 || mFixedSize.getHeight() < 0) { mIsFixedSize = false; } else { mIsFixedSize = true; calculateSize(); } } const Size& Widget::getFixedSize() const { return mFixedSize; } bool Widget::isFixedSize() const { return mIsFixedSize; } void Widget::calculateSize() { if (isFixedSize()) { mDimension.width = mFixedSize.getWidth(); mDimension.height = mFixedSize.getHeight(); return; } int minWidth = mMinSize.getWidth(); int minHeight = mMinSize.getHeight(); int maxWidth = mMaxSize.getWidth(); int maxHeight = mMaxSize.getHeight(); int currWidth = mDimension.width; int currHeight = mDimension.height; mDimension.width = std::max(std::min(currWidth, maxWidth), minWidth); mDimension.height = std::max(std::min(currHeight, maxHeight), minHeight); } void Widget::setVerticalExpand(bool expand) { mVExpand = expand; } bool Widget::isVerticalExpand() const { return mVExpand; } void Widget::setHorizontalExpand(bool expand) { mHExpand = expand; } bool Widget::isHorizontalExpand() const { return mHExpand; } void Widget::adaptLayout(bool top) { Widget* widget = this; while (widget->getParent() && top) { Widget* parent = widget->getParent(); if (!parent->isLayouted()) { break; } widget = parent; } widget->resizeToContent(); widget->expandContent(); } void Widget::setOutlineSize(unsigned int size) { mOutlineSize = size; } unsigned int Widget::getOutlineSize() const { return mOutlineSize; } void Widget::setBorderSize(unsigned int size) { mBorderSize = size; } unsigned int Widget::getBorderSize() const { return mBorderSize; } void Widget::setMargin(int margin) { mMarginTop = margin; mMarginRight = margin; mMarginBottom = margin; mMarginLeft = margin; } void Widget::setMarginTop(int margin) { mMarginTop = margin; } int Widget::getMarginTop() const { return mMarginTop; } void Widget::setMarginRight(int margin) { mMarginRight = margin; } int Widget::getMarginRight() const { return mMarginRight; } void Widget::setMarginBottom(int margin) { mMarginBottom = margin; } int Widget::getMarginBottom() const { return mMarginBottom; } void Widget::setMarginLeft(int margin) { mMarginLeft = margin; } int Widget::getMarginLeft() const { return mMarginLeft; } void Widget::setPadding(unsigned int padding) { mPaddingTop = padding; mPaddingRight = padding; mPaddingBottom = padding; mPaddingLeft = padding; } void Widget::setPaddingTop(unsigned int padding) { mPaddingTop = padding; } unsigned int Widget::getPaddingTop() const { return mPaddingTop; } void Widget::setPaddingRight(unsigned int padding) { mPaddingRight = padding; } unsigned int Widget::getPaddingRight() const { return mPaddingRight; } void Widget::setPaddingBottom(unsigned int padding) { mPaddingBottom = padding; } unsigned int Widget::getPaddingBottom() const { return mPaddingBottom; } void Widget::setPaddingLeft(unsigned int padding) { mPaddingLeft = padding; } unsigned int Widget::getPaddingLeft() const { return mPaddingLeft; } const Rectangle& Widget::getDimension() const { return mDimension; } const std::string& Widget::getActionEventId() const { return mActionEventId; } void Widget::setActionEventId(const std::string& actionEventId) { mActionEventId = actionEventId; } bool Widget::isFocused() const { if (!mFocusHandler) { return false; } return (mFocusHandler->isFocused(this)); } void Widget::setFocusable(bool focusable) { if (!focusable && isFocused()) { mFocusHandler->focusNone(); } mFocusable = focusable; } bool Widget::isFocusable() const { return mFocusable && isVisible() && isEnabled(); } void Widget::requestFocus() { if (mFocusHandler == NULL) throw FCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); if (isFocusable()) mFocusHandler->requestFocus(this); } void Widget::requestMoveToTop() { if (mParent != NULL) mParent->moveToTop(this); } void Widget::requestMoveToBottom() { if (mParent != NULL) mParent->moveToBottom(this); } void Widget::setVisible(bool visible) { VisibilityEventHandler *visibilityEventHandler = _getVisibilityEventHandler(); if (!visible && isFocused()) mFocusHandler->focusNone(); if (visible) { visibilityEventHandler->widgetShown(Event(this)); distributeShownEvent(); std::list::iterator currChild(mChildren.begin()); std::list::iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { (*currChild)->distributeAncestorShownEvent(this); } } else if(!visible) { visibilityEventHandler->widgetHidden(Event(this)); distributeHiddenEvent(); std::list::iterator currChild(mChildren.begin()); std::list::iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { (*currChild)->distributeAncestorHiddenEvent(this); } } mVisible = visible; } bool Widget::isVisible() const { if (getParent() == NULL) return mVisible; else return mVisible && getParent()->isVisible(); } bool Widget::isSetVisible() const { return mVisible; } void Widget::setBaseColor(const Color& color) { mBaseColor = color; } const Color& Widget::getBaseColor() const { return mBaseColor; } void Widget::setForegroundColor(const Color& color) { mForegroundColor = color; } const Color& Widget::getForegroundColor() const { return mForegroundColor; } void Widget::setBackgroundColor(const Color& color) { mBackgroundColor = color; } const Color& Widget::getBackgroundColor() const { return mBackgroundColor; } void Widget::setSelectionColor(const Color& color) { mSelectionColor = color; } const Color& Widget::getSelectionColor() const { return mSelectionColor; } void Widget::setOutlineColor(const Color& color) { mOutlineColor = color; } const Color& Widget::getOutlineColor() const { return mOutlineColor; } void Widget::setBorderColor(const Color& color) { mBorderColor = color; } const Color& Widget::getBorderColor() const { return mBorderColor; } void Widget::setSelectionMode(SelectionMode mode) { mSelectionMode = mode; } Widget::SelectionMode Widget::getSelectionMode() const { return mSelectionMode; } void Widget::_setFocusHandler(FocusHandler* focusHandler) { if (mFocusHandler) { releaseModalFocus(); if (mFocusHandler->getModalMouseInputFocused() == this) { releaseModalMouseInputFocus(); } mFocusHandler->remove(this); } if (focusHandler) focusHandler->add(this); mFocusHandler = focusHandler; if (mInternalFocusHandler != NULL) return; std::list::const_iterator iter; for (iter = mChildren.begin(); iter != mChildren.end(); iter++) { if (widgetExists(*iter)) (*iter)->_setFocusHandler(focusHandler); } } FocusHandler* Widget::_getFocusHandler() { return mFocusHandler; } void Widget::_setVisibilityEventHandler(VisibilityEventHandler* visibilityEventHandler) { mVisibilityEventHandler = visibilityEventHandler; } VisibilityEventHandler* Widget::_getVisibilityEventHandler() { return mVisibilityEventHandler; } void Widget::_setGuiDeathListener(DeathListener* deathListener) { mGuiDeathListener = deathListener; } DeathListener* Widget::_getGuiDeathListener() { return mGuiDeathListener; } void Widget::addActionListener(ActionListener* actionListener) { mActionListeners.push_back(actionListener); } void Widget::removeActionListener(ActionListener* actionListener) { mActionListeners.remove(actionListener); } void Widget::addDeathListener(DeathListener* deathListener) { mDeathListeners.push_back(deathListener); } void Widget::removeDeathListener(DeathListener* deathListener) { mDeathListeners.remove(deathListener); } void Widget::addKeyListener(KeyListener* keyListener) { mKeyListeners.push_back(keyListener); } void Widget::removeKeyListener(KeyListener* keyListener) { mKeyListeners.remove(keyListener); } void Widget::addFocusListener(FocusListener* focusListener) { mFocusListeners.push_back(focusListener); } void Widget::removeFocusListener(FocusListener* focusListener) { mFocusListeners.remove(focusListener); } void Widget::addMouseListener(MouseListener* mouseListener) { mMouseListeners.push_back(mouseListener); } void Widget::removeMouseListener(MouseListener* mouseListener) { mMouseListeners.remove(mouseListener); } void Widget::addWidgetListener(WidgetListener* widgetListener) { mWidgetListeners.push_back(widgetListener); } void Widget::removeWidgetListener(WidgetListener* widgetListener) { mWidgetListeners.remove(widgetListener); } void Widget::getAbsolutePosition(int& x, int& y) const { if (getParent() == NULL) { if (isLastPositionSet()) { x = mLastX; y = mLastY; } else { x = mDimension.x; y = mDimension.y; } return; } int parentX; int parentY; getParent()->getAbsolutePosition(parentX, parentY); x = parentX + mDimension.x + getParent()->getChildrenArea().x; y = parentY + mDimension.y + getParent()->getChildrenArea().y; } Font* Widget::getFont() const { if (mCurrentFont == NULL) { if (mGlobalFont == NULL) return &mDefaultFont; return mGlobalFont; } return mCurrentFont; } void Widget::setGlobalFont(Font* font) { mGlobalFont = font; std::list::iterator iter; for (iter = mWidgetInstances.begin(); iter != mWidgetInstances.end(); ++iter) { if ((*iter)->mCurrentFont == NULL) (*iter)->fontChanged(); } } void Widget::setFont(Font* font) { mCurrentFont = font; fontChanged(); } bool Widget::widgetExists(const Widget* widget) { std::list::const_iterator iter; for (iter = mWidgetInstances.begin(); iter != mWidgetInstances.end(); ++iter) { if (*iter == widget) return true; } return false; } bool Widget::isTabInEnabled() const { return mTabIn; } void Widget::setTabInEnabled(bool enabled) { mTabIn = enabled; } bool Widget::isTabOutEnabled() const { return mTabOut; } void Widget::setTabOutEnabled(bool enabled) { mTabOut = enabled; } void Widget::setSize(int width, int height) { Rectangle newDimension = mDimension; newDimension.width = width; newDimension.height = height; setDimension(newDimension); } void Widget::setEnabled(bool enabled) { mEnabled = enabled; } bool Widget::isEnabled() const { return mEnabled && isVisible(); } bool Widget::isModalFocusable() const { if (mFocusHandler == NULL) { throw FCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); return false; } return mFocusHandler->getModalFocused() == NULL; } bool Widget::isModalMouseInputFocusable() const { if (mFocusHandler == NULL) { throw FCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); return false; } return mFocusHandler->getModalMouseInputFocused() == NULL; } void Widget::requestModalFocus() { if (mFocusHandler == NULL) throw FCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); mFocusHandler->requestModalFocus(this); } void Widget::requestModalMouseInputFocus() { if (mFocusHandler == NULL) throw FCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); mFocusHandler->requestModalMouseInputFocus(this); } void Widget::releaseModalFocus() { if (mFocusHandler == NULL) return; mFocusHandler->releaseModalFocus(this); } void Widget::releaseModalMouseInputFocus() { if (mFocusHandler == NULL) return; mFocusHandler->releaseModalMouseInputFocus(this); } bool Widget::isModalFocused() const { if (mFocusHandler == NULL) throw FCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); if (getParent() != NULL) { return (mFocusHandler->getModalFocused() == this) || getParent()->isModalFocused(); } return mFocusHandler->getModalFocused() == this; } bool Widget::isModalMouseInputFocused() const { if (mFocusHandler == NULL) throw FCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); if (getParent() != NULL) { return (mFocusHandler->getModalMouseInputFocused() == this) || getParent()->isModalMouseInputFocused(); } return mFocusHandler->getModalMouseInputFocused() == this; } Widget *Widget::getWidgetAt(int x, int y, Widget* exclude) { Rectangle r = getChildrenArea(); if (!r.isContaining(x, y)) return NULL; x -= r.x; y -= r.y; std::list::reverse_iterator iter; for (iter = mChildren.rbegin(); iter != mChildren.rend(); iter++) { Widget* widget = (*iter); if (widget != exclude && widget->isVisible() && widget->getDimension().isContaining(x, y)) return widget; } return NULL; } const std::list& Widget::_getMouseListeners() { return mMouseListeners; } const std::list& Widget::_getKeyListeners() { return mKeyListeners; } const std::list& Widget::_getFocusListeners() { return mFocusListeners; } Rectangle Widget::getChildrenArea() { return Rectangle(0, 0, 0, 0); } FocusHandler* Widget::_getInternalFocusHandler() { return mInternalFocusHandler; } void Widget::setInternalFocusHandler(FocusHandler* focusHandler) { mInternalFocusHandler = focusHandler; std::list::const_iterator iter; for (iter = mChildren.begin(); iter != mChildren.end(); iter++) { if (mInternalFocusHandler == NULL) (*iter)->_setFocusHandler(_getFocusHandler()); else (*iter)->_setFocusHandler(mInternalFocusHandler); } } void Widget::setId(const std::string& id) { mId = id; } const std::string& Widget::getId() const { return mId; } void Widget::distributeResizedEvent() { std::list::const_iterator iter; for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) { Event event(this); (*iter)->widgetResized(event); } } void Widget::distributeMovedEvent() { std::list::const_iterator iter; for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) { Event event(this); (*iter)->widgetMoved(event); } } void Widget::distributeHiddenEvent() { std::list::const_iterator iter; for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) { Event event(this); (*iter)->widgetHidden(event); } } void Widget::distributeAncestorMovedEvent(Widget* ancestor) { std::list::iterator currWidgetListener(mWidgetListeners.begin()); std::list::iterator endWidgetListeners(mWidgetListeners.end()); Event event(ancestor); for(; currWidgetListener != endWidgetListeners; ++currWidgetListener) { (*currWidgetListener)->ancestorMoved(event); } std::list::iterator currChild(mChildren.begin()); std::list::iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { (*currChild)->distributeAncestorMovedEvent(ancestor); } } void Widget::distributeAncestorHiddenEvent(Widget* ancestor) { // additonal call VisibilityEventHandler, needed to get new focus / MouseEvent::Entered or Exited _getVisibilityEventHandler()->widgetHidden(Event(this)); std::list::iterator currWidgetListener(mWidgetListeners.begin()); std::list::iterator endWidgetListeners(mWidgetListeners.end()); Event event(ancestor); for(; currWidgetListener != endWidgetListeners; ++currWidgetListener) { (*currWidgetListener)->ancestorHidden(event); } std::list::iterator currChild(mChildren.begin()); std::list::iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { (*currChild)->distributeAncestorHiddenEvent(ancestor); } } void Widget::distributeAncestorShownEvent(Widget* ancestor) { // additonal call VisibilityEventHandler, needed to get new focus / MouseEvent::Entered or Exited _getVisibilityEventHandler()->widgetShown(Event(this)); std::list::iterator currWidgetListener(mWidgetListeners.begin()); std::list::iterator endWidgetListeners(mWidgetListeners.end()); Event event(ancestor); for(; currWidgetListener != endWidgetListeners; ++currWidgetListener) { (*currWidgetListener)->ancestorShown(event); } std::list::iterator currChild(mChildren.begin()); std::list::iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { (*currChild)->distributeAncestorShownEvent(ancestor); } } void Widget::distributeActionEvent() { std::list::const_iterator iter; for (iter = mActionListeners.begin(); iter != mActionListeners.end(); ++iter) { ActionEvent actionEvent(this, mActionEventId); (*iter)->action(actionEvent); } } void Widget::distributeShownEvent() { std::list::const_iterator iter; for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) { Event event(this); (*iter)->widgetShown(event); } } void Widget::showPart(Rectangle rectangle) { if (mParent != NULL) mParent->showWidgetPart(this, rectangle); } Widget* Widget::getTop() const { if (getParent() == NULL) return NULL; Widget* widget = getParent(); Widget* parent = getParent()->getParent(); while (parent != NULL) { widget = parent; parent = parent->getParent(); } return widget; } std::list Widget::getWidgetsIn(const Rectangle& area, Widget* ignore) { std::list result; std::list::const_iterator iter; for (iter = mChildren.begin(); iter != mChildren.end(); iter++) { Widget* widget = (*iter); if (ignore != widget && widget->getDimension().isIntersecting(area)) result.push_back(widget); } return result; } void Widget::resizeToChildren() { int w = 0, h = 0; std::list::const_iterator iter; for (iter = mChildren.begin(); iter != mChildren.end(); iter++) { Widget* widget = (*iter); if (widget->getX() + widget->getWidth() > w) w = widget->getX() + widget->getWidth(); if (widget->getY() + widget->getHeight() > h) h = widget->getY() + widget->getHeight(); } setSize(w, h); } Widget* Widget::findWidgetById(const std::string& id) { std::list::const_iterator iter; for (iter = mChildren.begin(); iter != mChildren.end(); iter++) { Widget* widget = (*iter); if (widget->getId() == id) return widget; Widget *child = widget->findWidgetById(id); if (child != NULL) return child; } return NULL; } void Widget::showWidgetPart(Widget* widget, Rectangle area) { Rectangle widgetArea = getChildrenArea(); area.x += widget->getX(); area.y += widget->getY(); if (area.x + area.width > widgetArea.width) widget->setX(widget->getX() - area.x - area.width + widgetArea.width); if (area.y + area.height > widgetArea.height) widget->setY(widget->getY() - area.y - area.height + widgetArea.height); if (area.x < 0) widget->setX(widget->getX() - area.x); if (area.y < 0) widget->setY(widget->getY() - area.y); } void Widget::clear() { std::list::const_iterator iter; for (iter = mChildren.begin(); iter != mChildren.end(); iter++) { Widget* widget = (*iter); int x = 0; int y = 0; widget->getAbsolutePosition(x, y); widget->setLastPosition(x, y); widget->_setFocusHandler(NULL); widget->_setParent(NULL); // thats more a hack but needed if (_getVisibilityEventHandler()) _getVisibilityEventHandler()->widgetHidden(Event(widget)); } mChildren.clear(); } void Widget::remove(Widget* widget) { std::list::iterator iter; for (iter = mChildren.begin(); iter != mChildren.end(); iter++) { if (*iter == widget) { int x = 0; int y = 0; widget->getAbsolutePosition(x, y); widget->setLastPosition(x, y); mChildren.erase(iter); widget->_setFocusHandler(NULL); widget->_setParent(NULL); // thats more a hack but needed if (_getVisibilityEventHandler()) _getVisibilityEventHandler()->widgetHidden(Event(widget)); return; } } throw FCN_EXCEPTION("There is no such widget in this container."); } void Widget::add(Widget* widget) { mChildren.push_back(widget); if (mInternalFocusHandler == NULL) widget->_setFocusHandler(_getFocusHandler()); else widget->_setFocusHandler(mInternalFocusHandler); widget->_setParent(this); setLastPosition(0, 0); // thats more a hack but needed if (_getVisibilityEventHandler()) _getVisibilityEventHandler()->widgetShown(Event(widget)); } void Widget::moveToTop(Widget* widget) { std::list::iterator iter; iter = std::find(mChildren.begin(), mChildren.end(), widget); if (iter == mChildren.end()) throw FCN_EXCEPTION("There is no such widget in this widget."); mChildren.remove(widget); mChildren.push_back(widget); } void Widget::moveToBottom(Widget* widget) { std::list::iterator iter; iter = find(mChildren.begin(), mChildren.end(), widget); if (iter == mChildren.end()) throw FCN_EXCEPTION("There is no such widget in this widget."); mChildren.remove(widget); mChildren.push_front(widget); } void Widget::focusNext() { std::list::const_iterator iter; for (iter = mChildren.begin(); iter != mChildren.end(); iter++) { if ((*iter)->isFocused()) break; } std::list::const_iterator end = iter; if (iter == mChildren.end()) iter = mChildren.begin(); iter++; for (; iter != end; iter++) { if (iter == mChildren.end()) iter = mChildren.begin(); if ((*iter)->isFocusable()) { (*iter)->requestFocus(); return; } } } void Widget::focusPrevious() { std::list::reverse_iterator iter; for (iter = mChildren.rbegin(); iter != mChildren.rend(); iter++) { if ((*iter)->isFocused()) break; } std::list::reverse_iterator end = iter; iter++; if (iter == mChildren.rend()) iter = mChildren.rbegin(); for (; iter != end; iter++) { if (iter == mChildren.rend()) iter = mChildren.rbegin(); if ((*iter)->isFocusable()) { (*iter)->requestFocus(); return; } } } void Widget::_draw(Graphics* graphics) { if (mOutlineSize > 0) { Rectangle rec = mDimension; rec.x -= mOutlineSize; rec.y -= mOutlineSize; rec.width += 2 * mOutlineSize; rec.height += 2 * mOutlineSize; graphics->pushClipArea(rec); drawOutline(graphics); graphics->popClipArea(); } graphics->pushClipArea(mDimension); draw(graphics); if (!mChildren.empty()) { const Rectangle& childrenArea = getChildrenArea(); graphics->pushClipArea(childrenArea); std::list::const_iterator iter; for (iter = mChildren.begin(); iter != mChildren.end(); iter++) { Widget* widget = (*iter); // Only draw a widget if it's visible and if it visible // inside the children area. //if (widget->isVisible() && childrenArea.isIntersecting(widget->getDimension())) if (widget->isVisible()) widget->_draw(graphics); } graphics->popClipArea(); } graphics->popClipArea(); } void Widget::_logic() { logic(); std::list::const_iterator iter; for (iter = mChildren.begin(); iter != mChildren.end(); iter++) (*iter)->_logic(); } const std::list& Widget::getChildren() const { return mChildren; } void Widget::getLastPosition(int& x, int& y) const { x = mLastX; y = mLastY; } void Widget::setLastPosition(int x, int y) { mLastX = x; mLastY = y; } bool Widget::isLastPositionSet() const { return mLastX != 0 || mLastY != 0; } } fifechan-0.1.5/src/widgets/000077500000000000000000000000001341577075500155335ustar00rootroot00000000000000fifechan-0.1.5/src/widgets/adjustingcontainer.cpp000066400000000000000000000236461341577075500221450ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2007 - 2008 Josh Matthews and Olof Naessn * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widgets/adjustingcontainer.hpp" #include "fifechan/exception.hpp" namespace fcn { AdjustingContainer::AdjustingContainer() : mWidth(0), mHeight(0), mNumberOfColumns(1), mNumberOfRows(1) { setPadding(0); setVerticalSpacing(0); setHorizontalSpacing(0); mColumnWidths.push_back(0); mRowHeights.push_back(0); } AdjustingContainer::~AdjustingContainer() { } void AdjustingContainer::setNumberOfColumns(unsigned int numberOfColumns) { mNumberOfColumns = numberOfColumns; if (mColumnAlignment.size() < numberOfColumns) { while (mColumnAlignment.size() < numberOfColumns) { mColumnAlignment.push_back(LEFT); } } else { while (mColumnAlignment.size() > numberOfColumns) { mColumnAlignment.pop_back(); } } } unsigned int AdjustingContainer::getNumberOfColumns() const { return mNumberOfColumns; } void AdjustingContainer::setColumnAlignment(unsigned int column, unsigned int alignment) { if (column < mColumnAlignment.size()) { mColumnAlignment[column] = alignment; } } unsigned int AdjustingContainer::getColumnAlignment(unsigned int column) const { if (column < mColumnAlignment.size()){ return mColumnAlignment[column]; } return 0; } void AdjustingContainer::resizeToContent(bool recursiv) { Container::resizeToContent(recursiv); adjustContent(); } void AdjustingContainer::expandContent(bool recursiv) { } Rectangle AdjustingContainer::getChildrenArea() { Rectangle rec; rec.x = getBorderSize(); rec.y = getBorderSize(); rec.width = getWidth() - 2 * getBorderSize(); rec.height = getHeight() - 2 * getBorderSize(); return rec; } //void AdjustingContainer::logic() //{ // Container::logic(); // adjustContent(); //} void AdjustingContainer::add(Widget *widget) { Container::add(widget); mContainedWidgets.push_back(widget); } void AdjustingContainer::add(Widget *widget, int x, int y) { add(widget); } void AdjustingContainer::clear() { Container::clear(); mContainedWidgets.clear(); } void AdjustingContainer::remove(Widget *widget) { Container::remove(widget); std::vector::iterator it; for(it = mContainedWidgets.begin(); it != mContainedWidgets.end(); it++) { if(*it == widget) { mContainedWidgets.erase(it); break; } } } void AdjustingContainer::adjustSize() { mNumberOfRows = mContainedWidgets.size() / mNumberOfColumns + mContainedWidgets.size() % mNumberOfColumns; mColumnWidths.clear(); unsigned int i; for (i = 0; i < mNumberOfColumns; i++) { mColumnWidths.push_back(0); } mRowHeights.clear(); for (i = 0; i < mNumberOfRows; i++) { mRowHeights.push_back(0); } for (i = 0; i < mNumberOfColumns; i++) { unsigned int j; for (j = 0; j < mNumberOfRows && mNumberOfColumns * j + i < mContainedWidgets.size(); j++) { if ((unsigned int)mContainedWidgets[mNumberOfColumns * j + i]->getWidth() > mColumnWidths[i]) { mColumnWidths[i] = mContainedWidgets[mNumberOfColumns * j + i]->getWidth(); } if ((unsigned int)mContainedWidgets[mNumberOfColumns * j + i]->getHeight() > mRowHeights[j]) { mRowHeights[j] = mContainedWidgets[mNumberOfColumns * j + i]->getHeight(); } } } mWidth = mPaddingLeft; for (i = 0; i < mColumnWidths.size(); i++) { mWidth += mColumnWidths[i] + mHorizontalSpacing; } mWidth -= mHorizontalSpacing; mWidth += mPaddingRight; mHeight = mPaddingTop; for (i = 0; i < mRowHeights.size(); i++) { mHeight += mRowHeights[i] + mVerticalSpacing; } mHeight -= mVerticalSpacing; mHeight += mPaddingBottom; setHeight(mHeight + 2 * getBorderSize()); setWidth(mWidth + 2 * getBorderSize()); } void AdjustingContainer::adjustContent() { adjustSize(); unsigned int columnCount = 0; unsigned int rowCount = 0; unsigned int y = mPaddingTop; for (unsigned int i = 0; i < mContainedWidgets.size(); i++) { unsigned basex; if (columnCount % mNumberOfColumns) { basex = mPaddingLeft; unsigned int j; for (j = 0; j < columnCount; j++) { basex += mColumnWidths[j] + mHorizontalSpacing; } } else { basex = mPaddingLeft; } switch (mColumnAlignment[columnCount]) { case LEFT: mContainedWidgets[i]->setX(basex); break; case CENTER: mContainedWidgets[i]->setX(basex + (mColumnWidths[columnCount] - mContainedWidgets[i]->getWidth()) / 2); break; case RIGHT: mContainedWidgets[i]->setX(basex + mColumnWidths[columnCount] - mContainedWidgets[i]->getWidth()); break; default: throw FCN_EXCEPTION("Unknown alignment."); } mContainedWidgets[i]->setY(y); columnCount++; if (columnCount == mNumberOfColumns) { columnCount = 0; y += mRowHeights[rowCount] + mVerticalSpacing; rowCount++; } } } } fifechan-0.1.5/src/widgets/bargraph.cpp000066400000000000000000000075641341577075500200410ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include #include #include namespace fcn { BarGraph::BarGraph(): m_opaque(false), m_rec() { } BarGraph::BarGraph(int x, int y, int w, int h): m_opaque(false), m_rec(Rectangle(x, y, w, h)) { } void BarGraph::setBarX(int x) { m_rec.x = x; } int BarGraph::getBarX() const { return m_rec.x; } void BarGraph::setBarY(int y) { m_rec.y = y; } int BarGraph::getBarY() const { return m_rec.y; } void BarGraph::setBarPosition(int x, int y) { m_rec.x = x; m_rec.y = y; } void BarGraph::setBarPosition(const Point& pos) { m_rec.x = pos.x; m_rec.y = pos.y; } void BarGraph::setBarWidth(int w) { m_rec.width = w; } int BarGraph::getBarWidth() const { return m_rec.width; } void BarGraph::setBarHeight(int h) { m_rec.height = h; } int BarGraph::getBarHeight() const { return m_rec.height; } void BarGraph::setBarSize(int w, int h) { m_rec.width = w; m_rec.height = h; } void BarGraph::setOpaque(bool opaque) { m_opaque = opaque; } bool BarGraph::isOpaque() const { return m_opaque; } void BarGraph::draw(Graphics* graphics) { bool active = isFocused(); if (isOpaque()) { // Fill the background around the content if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { graphics->setColor(getSelectionColor()); } else { graphics->setColor(getBackgroundColor()); } graphics->fillRectangle(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); } // draw border or frame if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } // draw bar graphics->setColor(getBaseColor()); // top left, bottom left, bottom right, top right graphics->fillRectangle(m_rec); } };fifechan-0.1.5/src/widgets/button.cpp000066400000000000000000000243471341577075500175640ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widgets/button.hpp" #include "fifechan/exception.hpp" #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" #include "fifechan/key.hpp" #include "fifechan/mouseevent.hpp" #include "fifechan/mouseinput.hpp" namespace fcn { Button::Button() : mHasMouse(false), mKeyPressed(false), mMousePressed(false), mState(true), mAlignment(Graphics::Center), mXOffset(1), mYOffset(1) { setFocusable(true); adjustSize(); addMouseListener(this); addKeyListener(this); addFocusListener(this); addWidgetListener(this); } Button::Button(const std::string& caption) : mCaption(caption), mHasMouse(false), mKeyPressed(false), mMousePressed(false), mState(true), mAlignment(Graphics::Center), mXOffset(1), mYOffset(1) { setFocusable(true); adjustSize(); addMouseListener(this); addKeyListener(this); addFocusListener(this); addWidgetListener(this); } Button::~Button() { } void Button::setCaption(const std::string& caption) { mCaption = caption; adjustSize(); } const std::string& Button::getCaption() const { return mCaption; } void Button::setActive(bool state) { mState = state; } bool Button::isActive() const { return mState; } void Button::setAlignment(Graphics::Alignment alignment) { mAlignment = alignment; } Graphics::Alignment Button::getAlignment() const { return mAlignment; } void Button::setDownXOffset(int offset) { mXOffset = offset; } int Button::getDownXOffset() const { return mXOffset; } void Button::setDownYOffset(int offset) { mYOffset = offset; } int Button::getDownYOffset() const { return mYOffset; } void Button::setDownOffset(int x, int y) { mXOffset = x; mYOffset = y; } void Button::fontChanged() { adjustSize(); } void Button::draw(Graphics* graphics) { bool active = isFocused(); Color faceColor = getBaseColor(); if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { faceColor = getSelectionColor(); } int alpha = faceColor.a; if (isPressed()) { faceColor = faceColor - 0x303030; faceColor.a = alpha; } if (!isActive()) { int color = static_cast(faceColor.r * 0.3 + faceColor.g * 0.59 + faceColor.b * 0.11); faceColor.r = color; faceColor.g = color; faceColor.b = color; } graphics->setColor(faceColor); Rectangle offsetRec(getBorderSize(), getBorderSize(), 2 * getBorderSize(), 2 * getBorderSize()); graphics->fillRectangle(offsetRec.x, offsetRec.y, getWidth() - offsetRec.width, getHeight() - offsetRec.height); if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } int textX; int textY = offsetRec.y + getPaddingTop() + (getHeight() - offsetRec.height - getPaddingTop() - getPaddingBottom() - getFont()->getHeight()) / 2; switch (getAlignment()) { case Graphics::Left: textX = offsetRec.x + getPaddingLeft(); break; case Graphics::Center: textX = offsetRec.x + getPaddingLeft() + (getWidth() - offsetRec.width - getPaddingLeft() - getPaddingRight()) / 2; break; case Graphics::Right: textX = getWidth() - offsetRec.x - getPaddingRight(); break; default: throw FCN_EXCEPTION("Unknown alignment."); } // set font and color graphics->setFont(getFont()); graphics->setColor(getForegroundColor()); if (isPressed()) { graphics->drawText(getCaption(), textX + getDownXOffset(), textY + getDownYOffset(), getAlignment()); } else { graphics->drawText(getCaption(), textX, textY, getAlignment()); } } void Button::resizeToContent(bool recursiv) { adjustSize(); } void Button::adjustSize() { int w = getFont()->getWidth(mCaption) + 2 * getBorderSize() + getPaddingLeft() + getPaddingRight(); int h = getFont()->getHeight() + 2 * getBorderSize() + getPaddingTop() + getPaddingBottom(); setSize(w, h); } bool Button::isPressed() const { if (mMousePressed) { return mHasMouse; } return mKeyPressed; } void Button::mousePressed(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == MouseEvent::Left) { mMousePressed = true; mouseEvent.consume(); } } void Button::mouseExited(MouseEvent& mouseEvent) { mHasMouse = false; } void Button::mouseEntered(MouseEvent& mouseEvent) { mHasMouse = true; } void Button::mouseReleased(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == MouseEvent::Left && mMousePressed && mHasMouse) { mMousePressed = false; distributeActionEvent(); mouseEvent.consume(); } else if (mouseEvent.getButton() == MouseEvent::Left) { mMousePressed = false; mouseEvent.consume(); } } void Button::mouseDragged(MouseEvent& mouseEvent) { mouseEvent.consume(); } void Button::keyPressed(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if (key.getValue() == Key::Enter || key.getValue() == Key::Space) { mKeyPressed = true; keyEvent.consume(); } } void Button::keyReleased(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if ((key.getValue() == Key::Enter || key.getValue() == Key::Space) && mKeyPressed) { mKeyPressed = false; distributeActionEvent(); keyEvent.consume(); } } void Button::focusLost(const Event& event) { mMousePressed = false; mKeyPressed = false; mHasMouse = false; } void Button::ancestorHidden(const Event& e) { mMousePressed = false; mKeyPressed = false; mHasMouse = false; } } fifechan-0.1.5/src/widgets/checkbox.cpp000066400000000000000000000371551341577075500200400ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include #include "fifechan/exception.hpp" #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" #include "fifechan/image.hpp" #include "fifechan/widgets/checkbox.hpp" namespace fcn { CheckBox::CheckBox(): mBackgroundImage(0), mInternalBackgroundImage(false), mSelected(false), mMode(Marker_Checkmark) { adjustSize(); } CheckBox::CheckBox(const std::string &caption, bool selected): mBackgroundImage(0), mInternalBackgroundImage(false), mSelected(selected), mMode(Marker_Checkmark) { setCaption(caption); adjustSize(); } CheckBox::~CheckBox() { if (mInternalBackgroundImage) { delete mBackgroundImage; } } void CheckBox::draw(Graphics* graphics) { if (mMode == Marker_Rhombus) { drawRhombus(graphics); } else { drawBox(graphics); } if (!getCaption().empty()) { graphics->setFont(getFont()); graphics->setColor(getForegroundColor()); int h = getHeight() - 2 * getBorderSize() - getPaddingTop() - getPaddingBottom(); int textX = getBorderSize() + getPaddingLeft() + h; int textY = getBorderSize() + getPaddingTop() + (h - getFont()->getHeight()) / 2; graphics->drawText(getCaption(), textX, textY); } } void CheckBox::drawBox(Graphics *graphics) { bool active = isFocused(); // draw background Rectangle background(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); if (mBackgroundImage) { graphics->drawImage(mBackgroundImage, 0, 0, background.x, background.y, background.width, background.height); } else { Color faceColor = getBaseColor(); if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { faceColor = getSelectionColor(); } graphics->setColor(faceColor); graphics->fillRectangle(background.x, background.y, background.width, background.height); } // rec for inner box int h = getHeight() - 2 * getBorderSize() - getPaddingTop() - getPaddingBottom(); Rectangle rec(getBorderSize() + getPaddingLeft(), getBorderSize() + getPaddingTop(), h, h); if (mMode == Marker_Image) { // draw marker image drawMarkerImage(graphics, rec); // draw border if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } } else { // draw inner box background graphics->setColor(getBackgroundColor()); graphics->fillRectangle(rec.x, rec.y, h, h); // draw border if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } Color faceColor = getBaseColor(); if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { faceColor = getSelectionColor(); } // border around the inner box background int alpha = getBaseColor().a; faceColor.a = alpha; Color highlightColor = faceColor + 0x303030; highlightColor.a = alpha; Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; graphics->setColor(shadowColor); graphics->drawLine(rec.x, rec.y, h-1, rec.y); graphics->drawLine(rec.x, rec.y, rec.x, h-1); graphics->setColor(highlightColor); graphics->drawLine(h-1, rec.x, h-1, h-1); graphics->drawLine(rec.y, h-1, h-1, h-1); // draws marker if (mSelected) { graphics->setColor(getForegroundColor()); switch(mMode) { case Marker_Checkmark: drawCheckmark(graphics, rec); break; case Marker_Cross: drawCross(graphics, rec); break; case Marker_Dot: drawDot(graphics, rec); break; default: throw FCN_EXCEPTION("Unknown marker."); } } } } void CheckBox::drawCheckmark(Graphics* graphics, const Rectangle& rec) { graphics->drawLine(rec.x+3, rec.y+3, rec.x+3, rec.height-3); graphics->drawLine(rec.x+4, rec.y+4, rec.x+4, rec.height-2); graphics->drawLine(rec.x+5, rec.height-3, rec.width-2, rec.y+4); graphics->drawLine(rec.x+5, rec.height-4, rec.width-4, rec.y+5); } void CheckBox::drawCross(Graphics* graphics, const Rectangle& rec) { graphics->drawLine(rec.x+2, rec.y+2, rec.width-3, rec.height-3); graphics->drawLine(rec.x+2, rec.y+3, rec.width-4, rec.height-3); graphics->drawLine(rec.x+2, rec.height-3, rec.width-3, rec.y+2); graphics->drawLine(rec.x+3, rec.height-3, rec.width-3, rec.y+3); } void CheckBox::drawDot(Graphics* graphics, const Rectangle& rec) { Point p(rec.x+rec.width/2, rec.y+rec.height/2); graphics->drawFillCircle(p, (rec.width-3)/2); } void CheckBox::drawMarkerImage(Graphics* graphics, const Rectangle& rec) { Rectangle rect = rec; const Image* img = 0; if (isSelected()) { rect.x += getDownXOffset(); rect.y += getDownYOffset(); if (!isActive()) { if (getInactiveDownImage()) { img = getInactiveDownImage(); } } else { img = getDownImage() ? getDownImage() : getUpImage(); } } else if(mHasMouse) { if (!isActive()) { if (getInactiveHoverImage()) { img = getInactiveHoverImage(); } } else { img = getHoverImage() ? getHoverImage() : getUpImage(); } } if (img) { graphics->drawImage(img, 0, 0, rect.x, rect.y, std::max(rect.width, img->getWidth()), rect.height); } } void CheckBox::drawRhombus(Graphics* graphics) { // ToDo: Rewrite this part, its only c&p from RadioButton graphics->pushClipArea(Rectangle(1, 1, getWidth() - 1, getHeight() - 1)); int h; if (getHeight()%2 == 0) { h = getHeight() - 4; } else { h = getHeight() - 3; } int alpha = getBaseColor().a; Color faceColor = getBaseColor(); faceColor.a = alpha; Color highlightColor = faceColor + 0x303030; highlightColor.a = alpha; Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; graphics->setColor(getBackgroundColor()); int i; int hh = (h + 1) / 2; for (i = 1; i <= hh; ++i) { graphics->drawLine(hh - i + 1, i, hh + i - 1, i); } for (i = 1; i < hh; ++i) { graphics->drawLine(hh - i + 1, h - i, hh + i - 1, h - i); } graphics->setColor(shadowColor); graphics->drawLine(hh, 0, 0, hh); graphics->drawLine(hh + 1, 1, h - 1, hh - 1); graphics->setColor(highlightColor); graphics->drawLine(1, hh + 1, hh, h); graphics->drawLine(hh + 1, h - 1, h, hh); graphics->setColor(getForegroundColor()); int hhh = hh - 3; if (mSelected) { for (i = 0; i < hhh; ++i) { graphics->drawLine(hh - i, 4 + i, hh + i, 4 + i); } for (i = 0; i < hhh; ++i) { graphics->drawLine(hh - i, h - 4 - i, hh + i, h - 4 - i); } } graphics->popClipArea(); if (isFocused()) { int fh; if (getHeight()%2 == 0) { fh = getHeight() - 4; } else { fh = getHeight() - 3; } int hh = (fh + 1) / 2; graphics->setColor(getSelectionColor()); graphics->drawLine(0, hh + 1, hh + 1, 0); graphics->drawLine(hh + 2, 1, fh + 2, hh + 1); graphics->drawLine(fh + 1, hh + 2, hh + 1, fh + 2); graphics->drawLine(hh + 1, fh + 2, 1, hh + 2); } } bool CheckBox::isSelected() const { return mSelected; } void CheckBox::setSelected(bool selected) { mSelected = selected; } void CheckBox::toggleSelected() { mSelected = !mSelected; } void CheckBox::setBackgroundImage(const std::string& filename) { if (mInternalBackgroundImage) { delete mBackgroundImage; } mBackgroundImage = Image::load(filename); mInternalBackgroundImage = true; adjustSize(); } void CheckBox::setBackgroundImage(const Image* image) { if (mInternalBackgroundImage) { delete mBackgroundImage; } mBackgroundImage = image; mInternalBackgroundImage = false; adjustSize(); } const Image* CheckBox::getBackgroundImage() const { return mBackgroundImage; } CheckBox::MarkerStyle CheckBox::getMarkerStyle() const { return mMode; } void CheckBox::setMarkerStyle(CheckBox::MarkerStyle mode) { mMode = mode; } void CheckBox::keyPressed(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if (key.getValue() == Key::Enter || key.getValue() == Key::Space) { toggleSelected(); keyEvent.consume(); distributeActionEvent(); } } void CheckBox::keyReleased(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if (key.getValue() == Key::Enter || key.getValue() == Key::Space) { keyEvent.consume(); } } void CheckBox::mousePressed(MouseEvent& mouseEvent) { if (mHasMouse) { mouseEvent.consume(); } } void CheckBox::mouseReleased(MouseEvent& mouseEvent) { if (mHasMouse) { mouseEvent.consume(); } } void CheckBox::mouseClicked(MouseEvent& mouseEvent) { if (mHasMouse && mouseEvent.getButton() == MouseEvent::Left) { toggleSelected(); mouseEvent.consume(); distributeActionEvent(); } } void CheckBox::adjustSize() { int w = 0; int h = 0; if (mBackgroundImage) { w += mBackgroundImage->getWidth() + 2 * getBorderSize(); h += mBackgroundImage->getHeight() + 2 * getBorderSize(); } else { if (!getCaption().empty()) { w = getFont()->getWidth(getCaption()); h = getFont()->getHeight(); } if (getUpImage()) { w += getUpImage()->getWidth(); h = std::max(getUpImage()->getHeight(), h); } else { // without image we need extra space for the mark w += h; } w += 2 * getBorderSize() + getPaddingLeft() + getPaddingRight(); h += 2 * getBorderSize() + getPaddingTop() + getPaddingBottom(); } setSize(w, h); } } fifechan-0.1.5/src/widgets/container.cpp000066400000000000000000000737551341577075500202420ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include #include "fifechan/widgets/container.hpp" #include "fifechan/exception.hpp" #include "fifechan/util/fcn_math.hpp" #include "fifechan/graphics.hpp" #include namespace fcn { Container::Container() { mOpaque = true; mLayout = Absolute; mUniform = false; mVerticalSpacing = 2; mHorizontalSpacing = 2; mBackgroundWidget = NULL; } Container::~Container() { } void Container::draw(Graphics* graphics) { bool active = isFocused(); if (isOpaque()) { if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { graphics->setColor(getSelectionColor()); } else { graphics->setColor(getBaseColor()); } graphics->fillRectangle(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); } if (mBackgroundWidget) { Rectangle rec(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); mBackgroundWidget->setDimension(rec); mBackgroundWidget->_draw(graphics); } if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } } void Container::setOpaque(bool opaque) { mOpaque = opaque; } bool Container::isOpaque() const { return mOpaque; } void Container::add(Widget* widget) { Widget::add(widget); distributeWidgetAddedEvent(widget); } void Container::add(Widget* widget, int x, int y) { widget->setPosition(x, y); Widget::add(widget); distributeWidgetAddedEvent(widget); } void Container::remove(Widget* widget) { Widget::remove(widget); distributeWidgetRemovedEvent(widget); } void Container::clear() { Widget::clear(); } Widget* Container::findWidgetById(const std::string &id) { return Widget::findWidgetById(id); } void Container::addContainerListener(ContainerListener* containerListener) { mContainerListeners.push_back(containerListener); } void Container::removeContainerListener(ContainerListener* containerListener) { mContainerListeners.remove(containerListener); } void Container::distributeWidgetAddedEvent(Widget* source) { ContainerListenerIterator iter; for (iter = mContainerListeners.begin(); iter != mContainerListeners.end(); ++iter) { ContainerEvent event(source, this); (*iter)->widgetAdded(event); } } void Container::distributeWidgetRemovedEvent(Widget* source) { ContainerListenerIterator iter; for (iter = mContainerListeners.begin(); iter != mContainerListeners.end(); ++iter) { ContainerEvent event(source, this); (*iter)->widgetRemoved(event); } } const std::list& Container::getChildren() const { return Widget::getChildren(); } void Container::resizeToContent(bool recursiv) { if (mLayout == Absolute) { if (recursiv) { std::list::const_iterator currChild(mChildren.begin()); std::list::const_iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } (*currChild)->resizeToContent(recursiv); } } return; } int childMaxW = 0; int childMaxH = 0; int layoutMaxW = 0; int layoutMaxH = 0; int totalW = 0; int totalH = 0; int visibleChilds = 0; std::list::const_iterator currChild(mChildren.begin()); std::list::const_iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } if (recursiv) { (*currChild)->resizeToContent(recursiv); } const Rectangle& rec = (*currChild)->getDimension(); childMaxW = std::max(childMaxW, rec.width); childMaxH = std::max(childMaxH, rec.height); layoutMaxW = std::max(layoutMaxW, rec.width + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight()); layoutMaxH = std::max(layoutMaxH, rec.height + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom()); ++visibleChilds; } // diff means border, padding, ... int diffW = getDimension().width - getChildrenArea().width; int diffH = getDimension().height - getChildrenArea().height; Rectangle dimensions(0, 0, childMaxW, childMaxH); if (mLayout == AutoSize && visibleChilds > 0) { currChild = mChildren.begin(); endChildren = mChildren.end(); for (; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } const Rectangle& rec = (*currChild)->getDimension(); int childW = rec.x + rec.width + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight(); int childH = rec.y + rec.height + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom(); totalW = std::max(totalW, childW); totalH = std::max(totalH, childH); } totalW += diffW; totalH += diffH; } else if (mLayout == Vertical && visibleChilds > 0) { currChild = mChildren.begin(); endChildren = mChildren.end(); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } dimensions.x = (*currChild)->getMarginLeft(); dimensions.y += (*currChild)->getMarginTop(); int layoutW = (*currChild)->getWidth() + (*currChild)->getMarginLeft() + ((*currChild)->getMarginRight() > 0 ? (*currChild)->getMarginRight() : 0); dimensions.width = (*currChild)->getWidth() + (layoutMaxW - layoutW); dimensions.height = (*currChild)->getHeight(); (*currChild)->setDimension(dimensions); dimensions.y += (*currChild)->getHeight() + (*currChild)->getMarginBottom() + getVerticalSpacing(); } // remove last spacing dimensions.y -= getVerticalSpacing(); totalW = std::max(layoutMaxW, childMaxW) + diffW; totalH = dimensions.y + diffH; } else if (mLayout == Horizontal && visibleChilds > 0) { currChild = mChildren.begin(); endChildren = mChildren.end(); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } dimensions.x += (*currChild)->getMarginLeft(); dimensions.y = (*currChild)->getMarginTop(); dimensions.width = (*currChild)->getWidth(); int layoutH = (*currChild)->getHeight() + (*currChild)->getMarginTop() + ((*currChild)->getMarginBottom() > 0 ? (*currChild)->getMarginBottom() : 0); dimensions.height = (*currChild)->getHeight() + (layoutMaxH - layoutH); (*currChild)->setDimension(dimensions); dimensions.x += (*currChild)->getWidth() + (*currChild)->getMarginRight() + getHorizontalSpacing(); } // remove last spacing dimensions.x -= getHorizontalSpacing(); totalW = dimensions.x + diffW; totalH = std::max(layoutMaxH, childMaxH) + diffH; } else if (mLayout == Circular && visibleChilds > 0) { const float angle = 360.0f / visibleChilds; float xRadius = static_cast(childMaxW * 2 + getHorizontalSpacing()); float yRadius = static_cast(childMaxH * 2 + getVerticalSpacing()); currChild = mChildren.begin(); endChildren = mChildren.end(); int w = 0; int h = 0; int i = 0; int minW = 50000; int minH = 50000; int maxW = -50000; int maxH = -50000; for (; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } const float tmpAngle = static_cast(int(angle * i + 270) % 360) / (180.0f / Mathf::pi()); int x = static_cast(xRadius * cos(tmpAngle) - (*currChild)->getWidth() / 2); int y = static_cast(yRadius * sin(tmpAngle) - (*currChild)->getHeight() / 2); minW = std::min(minW, x); maxW = std::max(maxW, x + (*currChild)->getWidth()); minH = std::min(minH, y); maxH = std::max(maxH, y + (*currChild)->getHeight()); (*currChild)->setPosition(x, y); ++i; } w = ABS(minW)+ABS(maxW); h = ABS(minH)+ABS(maxH); int centerX = w / 2; int centerY = h / 2; currChild = mChildren.begin(); endChildren = mChildren.end(); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } int x = (*currChild)->getX() + centerX; int y = (*currChild)->getY() + centerY; (*currChild)->setPosition(x, y); } totalW = w + diffW; totalH = h + diffH; } setSize(totalW, totalH); } void Container::adjustSize() { resizeToChildren(); int w = getWidth() + 2 * getBorderSize() + getPaddingLeft() + getPaddingRight(); int h = getHeight() + 2 * getBorderSize() + getPaddingTop() + getPaddingBottom(); setSize(w, h); } void Container::expandContent(bool recursiv) { if (mLayout == Absolute) { if (recursiv) { std::list::const_iterator currChild(mChildren.begin()); std::list::const_iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } (*currChild)->expandContent(recursiv); } } return; } else if (mLayout == AutoSize) { return; } Rectangle childrenArea = getChildrenArea(); int spaceW = childrenArea.width; int spaceH = childrenArea.height; int neededSpaceW = 0; int neededSpaceH = 0; int maxMinW = 0; int maxMinH = 0; int minMaxW = 50000; int minMaxH = 50000; int maxHExpander = 0; int maxVExpander = 0; int expanderNeededSpaceW = 0; int expanderNeededSpaceH = 0; unsigned int visibleChilds = 0; std::list hExpander; std::list vExpander; std::list::const_iterator currChild(mChildren.begin()); std::list::const_iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } ++visibleChilds; // get needed space neededSpaceW += (*currChild)->getWidth() + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight() + getHorizontalSpacing(); neededSpaceH += (*currChild)->getHeight() + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom() + getVerticalSpacing(); // get expander and expander max/min size if ((*currChild)->isVerticalExpand()) { maxVExpander = std::max(maxVExpander, (*currChild)->getHeight()); maxMinH = std::max(maxMinH, (*currChild)->getMinSize().getHeight()); minMaxH = std::min(minMaxH, (*currChild)->getMaxSize().getHeight()); expanderNeededSpaceH += (*currChild)->getHeight() + getVerticalSpacing(); vExpander.push_back((*currChild)); } if ((*currChild)->isHorizontalExpand()) { maxHExpander = std::max(maxHExpander, (*currChild)->getWidth()); maxMinW = std::max(maxMinW, (*currChild)->getMinSize().getWidth()); minMaxW = std::min(minMaxW, (*currChild)->getMaxSize().getWidth()); expanderNeededSpaceW += (*currChild)->getWidth() + getHorizontalSpacing(); hExpander.push_back((*currChild)); } } if (mLayout == Vertical && visibleChilds > 0) { bool hexpand = !(!isHorizontalExpand() && getParent()); neededSpaceH -= getVerticalSpacing(); int freeSpace = spaceH - neededSpaceH; if (freeSpace > 0) { if (vExpander.size() > 0) { expanderNeededSpaceH -= getVerticalSpacing(); } if (mUniform) { // check against the smallest maximal height if (minMaxH < maxVExpander) { maxVExpander = minMaxH; } // check against the largest minimal height if (maxMinH > maxVExpander) { maxVExpander = maxMinH; } int h = 0; // calculate maximal height if all expanders get this max height int maxNeeded = ((maxVExpander + getVerticalSpacing()) * vExpander.size()) - getVerticalSpacing(); int tmpSpace = (freeSpace + expanderNeededSpaceH) - maxNeeded; if (tmpSpace > 0) { h = maxVExpander; freeSpace = tmpSpace; } // distribute space if (freeSpace > 0 || h > 0) { std::list::iterator it = vExpander.begin(); int expanders = vExpander.size(); for (; it != vExpander.end(); ++it) { int layoutH = (*it)->getHeight() + (*it)->getMarginTop() + ((*it)->getMarginBottom() > 0 ? (*it)->getMarginBottom() : 0); // divide the space so that all expanders get the same size int diff = h > 0 ? 0 : (*it)->getHeight() + (maxVExpander - layoutH); int delta = ((freeSpace-diff) / expanders) + diff; if (delta == 0) { delta = 1; } if (delta > freeSpace) { delta = freeSpace; } int oldH = h > 0 ? h : (*it)->getHeight(); int tmpH = oldH + delta; (*it)->setHeight(tmpH); tmpH = (*it)->getHeight(); delta = tmpH - oldH; freeSpace -= delta; --expanders; } } } else { if (vExpander.size() > 0) { // simply add one to each expander until free space is empty // or all expanders reached the max height std::set maxExpanders; while (freeSpace && maxExpanders.size() < vExpander.size()) { std::list::iterator it = vExpander.begin(); for (; it != vExpander.end(); ++it) { int h = (*it)->getHeight(); (*it)->setHeight(h+1); if (h != (*it)->getHeight()) { --freeSpace; if (freeSpace == 0) { break; } } else { maxExpanders.insert(*it); } } } } } } // adapt position if (!hExpander.empty() || !vExpander.empty() || hexpand) { Rectangle rec(0, 0, spaceW, 0); currChild = mChildren.begin(); endChildren = mChildren.end(); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } if (hexpand || (*currChild)->isHorizontalExpand()) { int layoutW = (*currChild)->getMarginLeft() + ((*currChild)->getMarginRight() > 0 ? (*currChild)->getMarginRight() : 0); rec.width = spaceW-layoutW; } else { rec.width = (*currChild)->getWidth(); } rec.x = (*currChild)->getMarginLeft(); rec.y += (*currChild)->getMarginTop(); rec.height = (*currChild)->getHeight(); (*currChild)->setDimension(rec); rec.y += rec.height + (*currChild)->getMarginBottom() + getVerticalSpacing(); } } } else if (mLayout == Horizontal && visibleChilds > 0) { bool vexpand = !(!isVerticalExpand() && getParent()); neededSpaceW -= getHorizontalSpacing(); int freeSpace = spaceW - neededSpaceW; if (freeSpace > 0) { if (mUniform) { if (hExpander.size() > 0) { expanderNeededSpaceW -= getHorizontalSpacing(); } // check against the smallest maximal width if (minMaxW < maxHExpander) { maxHExpander = minMaxW; } // check against the largest minimal width if (maxMinW > maxHExpander) { maxHExpander = maxMinW; } int w = 0; // calculate maximal width if all expanders get this max width int maxNeeded = ((maxHExpander + getHorizontalSpacing()) * hExpander.size()) - getHorizontalSpacing(); int tmpSpace = (freeSpace + expanderNeededSpaceW) - maxNeeded; if (tmpSpace > 0) { w = maxHExpander; freeSpace = tmpSpace; } // distribute space if (freeSpace > 0 || w > 0) { std::list::iterator it = hExpander.begin(); int expanders = hExpander.size(); for (; it != hExpander.end(); ++it) { // divide the space so that all expanders get the same size int layoutW = (*it)->getWidth() + (*it)->getMarginLeft() + ((*it)->getMarginRight() > 0 ? (*it)->getMarginRight() : 0); int diff = w > 0 ? 0 : (*it)->getWidth() + (maxHExpander - layoutW); int delta = ((freeSpace-diff) / expanders) + diff; if (delta == 0) { delta = 1; } if (delta > freeSpace) { delta = freeSpace; } int oldW = w > 0 ? w : (*it)->getWidth(); int tmpW = oldW + delta; (*it)->setWidth(tmpW); tmpW = (*it)->getWidth(); delta = tmpW - oldW; freeSpace -= delta; --expanders; } } } else { if (hExpander.size() > 0) { // simply add one to each expander until free space is empty // or all expanders reached the max width std::set maxExpanders; while (freeSpace && maxExpanders.size() < hExpander.size()) { std::list::iterator it = hExpander.begin(); for (; it != hExpander.end(); ++it) { int w = (*it)->getWidth(); (*it)->setWidth(w+1); if (w != (*it)->getWidth()) { --freeSpace; if (freeSpace == 0) { break; } } else { maxExpanders.insert(*it); } } } } } } // adapt position if (!hExpander.empty() || !vExpander.empty() || vexpand) { Rectangle rec(0, 0, 0, spaceH); currChild = mChildren.begin(); endChildren = mChildren.end(); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } if (vexpand || (*currChild)->isVerticalExpand()) { int layoutH = (*currChild)->getMarginTop() + ((*currChild)->getMarginBottom() > 0 ? (*currChild)->getMarginBottom() : 0); rec.height= spaceH-layoutH; } else { rec.height = (*currChild)->getHeight(); } rec.x += (*currChild)->getMarginLeft(); rec.y = (*currChild)->getMarginTop(); rec.width = (*currChild)->getWidth(); (*currChild)->setDimension(rec); rec.x += rec.width + (*currChild)->getMarginRight() + getHorizontalSpacing(); } } }else if (mLayout == Circular && visibleChilds > 0) { const float angle = 360.0f / visibleChilds; int childMaxW = 0; int childMaxH = 0; currChild = mChildren.begin(); endChildren = mChildren.end(); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } childMaxW = std::max(childMaxW, (*currChild)->getWidth()); childMaxH = std::max(childMaxH, (*currChild)->getHeight()); } //childMaxW += getHorizontalSpacing(); //childMaxH += getVerticalSpacing(); float xRadius = (spaceW-childMaxW)/2.0f; float yRadius = (spaceH-childMaxH)/2.0f; float centerX = spaceW/2.0f; float centerY = spaceH/2.0f; if (xRadius < 1) { xRadius = static_cast(childMaxW); } if (yRadius < 1) { yRadius = static_cast(childMaxH); } // this forces a uniform circle //xRadius = std::max(xRadius, yRadius); //yRadius = xRadius; int i = 0; currChild = mChildren.begin(); endChildren = mChildren.end(); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } float tmpAngle = static_cast(int(angle * i + 270) % 360) / (180.0f / Mathf::pi()); int x = static_cast(centerX + xRadius * cos(tmpAngle)); int y = static_cast(centerY + yRadius * sin(tmpAngle)); x -= (*currChild)->getWidth() / 2; y -= (*currChild)->getHeight() / 2; (*currChild)->setPosition(x, y); ++i; } } if (recursiv) { currChild = mChildren.begin(); endChildren = mChildren.end(); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } (*currChild)->expandContent(recursiv); } } } void Container::setLayout(LayoutPolicy policy) { mLayout = policy; } Container::LayoutPolicy Container::getLayout() const { return mLayout; } void Container::setUniformSize(bool uniform) { mUniform = uniform; } bool Container::isUniformSize() const { return mUniform; } Rectangle Container::getChildrenArea() { Rectangle rec; rec.x = getBorderSize() + getPaddingLeft(); rec.y = getBorderSize() + getPaddingTop(); rec.width = getWidth() - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight(); rec.height = getHeight() - 2 * getBorderSize() - getPaddingTop() - getPaddingBottom(); return rec; } void Container::setVerticalSpacing(unsigned int spacing) { mVerticalSpacing = spacing; } unsigned int Container::getVerticalSpacing() const { return mVerticalSpacing; } void Container::setHorizontalSpacing(unsigned int spacing) { mHorizontalSpacing = spacing; } unsigned int Container::getHorizontalSpacing() const { return mHorizontalSpacing; } void Container::setBackgroundWidget(Widget* widget) { if (mBackgroundWidget != widget) { mBackgroundWidget = widget; } } Widget* Container::getBackgroundWidget() { return mBackgroundWidget; } } fifechan-0.1.5/src/widgets/curvegraph.cpp000066400000000000000000000231601341577075500204070ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include #include #include #include #include namespace fcn { CurveGraph::CurveGraph(): m_opaque(false), m_acp(true), m_needUpdate(false), m_thickness(1), m_data() { } CurveGraph::CurveGraph(const PointVector& data): m_opaque(false), m_acp(true), m_needUpdate(true), m_thickness(1), m_data(data) { } void CurveGraph::setPointVector(const PointVector& data) { m_needUpdate = true; m_data = data; } const PointVector& CurveGraph::getPointVector() const { return m_data; } void CurveGraph::resetPointVector() { m_needUpdate = true; m_data.clear(); } void CurveGraph::setThickness(unsigned int thickness) { m_needUpdate = true; m_thickness = thickness; } unsigned int CurveGraph::getThickness() const { return m_thickness; } void CurveGraph::setAutomaticControllPoints(bool acp) { m_needUpdate = true; m_acp = acp; } bool CurveGraph::isAutomaticControllPoints() const { return m_acp; } void CurveGraph::setOpaque(bool opaque) { m_opaque = opaque; } bool CurveGraph::isOpaque() const { return m_opaque; } void CurveGraph::draw(Graphics* graphics) { bool active = isFocused(); if (isOpaque()) { // Fill the background around the content if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { graphics->setColor(getSelectionColor()); } else { graphics->setColor(getBackgroundColor()); } graphics->fillRectangle(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); } // draw border or frame if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } if (m_needUpdate) { update(); } if (m_curveData.empty()) { return; } // draw bezier curve graphics->setColor(getBaseColor()); graphics->drawPolyLine(m_curveData, m_thickness); } void CurveGraph::update() { // calc steps and bezier points m_curveData.clear(); if (m_data.size() < 2) { return; } float distance = 0; PointVector newPoints; if (m_acp) { addControlPoints(m_data, newPoints); } else { newPoints = m_data; } int elements = newPoints.size(); std::vector::const_iterator it = newPoints.begin(); Point old = *it; ++it; for (; it != newPoints.end(); ++it) { const Point& next = *it; float rx = static_cast(old.x - next.x); float ry = static_cast(old.y - next.y); old = next; distance += Mathf::Sqrt(rx*rx + ry*ry); } int lines = static_cast(ceil((distance / elements) / m_thickness)); if (lines < 2) { lines = 2; } float step = 1.0f / static_cast(lines-1); float t = 0.0; m_curveData.push_back(getBezierPoint(newPoints, newPoints.size()+1, t)); for (int i = 0; i <= (elements*lines); ++i) { t += step; m_curveData.push_back(getBezierPoint(newPoints, newPoints.size(), t)); } m_needUpdate = false; } Point CurveGraph::getBezierPoint(const PointVector& points, int elements, float t) { if (t < 0.0) { return points[0]; } else if (t >= static_cast(elements)) { return points.back(); } // Interpolate double px = 0.0; double py = 0.0; int n = elements - 1; double muk = 1.0; double mu = static_cast(t) / static_cast(elements); double munk = Mathd::Pow(1.0 - mu, static_cast(n)); for (int i = 0; i <= n; ++i) { int tmpn = n; int tmpi = i; int diffn = n - i; double blend = muk * munk; muk *= mu; munk /= 1.0 - mu; while (tmpn) { blend *= static_cast(tmpn); tmpn--; if (tmpi > 1) { blend /= static_cast(tmpi); tmpi--; } if (diffn > 1) { blend /= static_cast(diffn); diffn--; } } px += static_cast(points[i].x) * blend; py += static_cast(points[i].y) * blend; } return Point(static_cast(px), static_cast(py)); } void CurveGraph::addControlPoints(const PointVector& points, PointVector& newPoints) { if (points.empty()) { return; } int n = points.size() - 1; // min 2 points if (n < 1) { return; } Point p; // straight line if (n == 1) { newPoints.push_back(points[0]); p.x = (2 * points[0].x + points[1].x) / 3; p.y = (2 * points[0].y + points[1].y) / 3; newPoints.push_back(p); p.x = 2 * p.x - points[0].x; p.y = 2 * p.y - points[0].y; newPoints.push_back(p); newPoints.push_back(points[1]); return; } // calculate x and y values float* xrhs = new float[n]; float* yrhs = new float[n]; // first xrhs[0] = static_cast(points[0].x + 2 * points[1].x); yrhs[0] = static_cast(points[0].y + 2 * points[1].y); // last xrhs[n - 1] = static_cast((8 * points[n - 1].x + points[n].x) / 2.0f); yrhs[n - 1] = static_cast((8 * points[n - 1].y + points[n].y) / 2.0f); // rest for (int i = 1; i < n - 1; ++i) { xrhs[i] = static_cast(4 * points[i].x + 2 * points[i + 1].x); yrhs[i] = static_cast(4 * points[i].y + 2 * points[i + 1].y); } float* x = new float[n]; float* y = new float[n]; float* xtmp = new float[n]; float* ytmp = new float[n]; float xb = 2.0; float yb = 2.0; x[0] = xrhs[0] / xb; y[0] = yrhs[0] / yb; // Decomposition and forward substitution. for (int i = 1; i < n; i++) { xtmp[i] = 1 / xb; ytmp[i] = 1 / yb; xb = (i < n - 1 ? 4.0f : 3.5f) - xtmp[i]; yb = (i < n - 1 ? 4.0f : 3.5f) - ytmp[i]; x[i] = (xrhs[i] - x[i - 1]) / xb; y[i] = (yrhs[i] - y[i - 1]) / yb; } // Backward substitution for (int i = 1; i < n; i++) { x[n - i - 1] -= xtmp[n - i] * x[n - i]; y[n - i - 1] -= ytmp[n - i] * y[n - i]; } // start point newPoints.push_back(points[0]); for (int i = 0; i < n - 1; ++i) { p.x = static_cast(x[i]); p.y = static_cast(y[i]); newPoints.push_back(p); p.x = static_cast(2 * points[i + 1].x - x[i + 1]); p.y = static_cast(2 * points[i + 1].y - y[i + 1]); newPoints.push_back(p); newPoints.push_back(points[i+1]); } p.x = static_cast(x[n - 1]); p.y = static_cast(y[n - 1]); newPoints.push_back(p); p.x = static_cast((points[n].x + x[n - 1]) / 2); p.y = static_cast((points[n].y + y[n - 1]) / 2); newPoints.push_back(p); // end point newPoints.push_back(points[n]); delete[] xrhs; delete[] yrhs; delete[] x; delete[] y; delete[] xtmp; delete[] ytmp; } };fifechan-0.1.5/src/widgets/dropdown.cpp000066400000000000000000000467121341577075500201050ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "fifechan/widgets/dropdown.hpp" #include "fifechan/exception.hpp" #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" #include "fifechan/key.hpp" #include "fifechan/listmodel.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/widgets/listbox.hpp" #include "fifechan/widgets/scrollarea.hpp" namespace fcn { DropDown::DropDown(ListModel *listModel, ScrollArea *scrollArea, ListBox *listBox) { setWidth(100); setFocusable(true); mDroppedDown = false; mPushed = false; mIsDragged = false; setInternalFocusHandler(&mInternalFocusHandler); mInternalScrollArea = (scrollArea == NULL); mInternalListBox = (listBox == NULL); if (mInternalScrollArea) { mScrollArea = new ScrollArea(); } else { mScrollArea = scrollArea; } if (mInternalListBox) { mListBox = new ListBox(); } else { mListBox = listBox; } mScrollArea->setContent(mListBox); add(mScrollArea); mListBox->addActionListener(this); mListBox->addSelectionListener(this); setListModel(listModel); addMouseListener(this); addKeyListener(this); addFocusListener(this); adjustHeight(); } DropDown::~DropDown() { if (widgetExists(mListBox)) { mListBox->removeActionListener(this); mListBox->removeSelectionListener(this); } if (mInternalScrollArea) { delete mScrollArea; } if (mInternalListBox) { delete mListBox; } setInternalFocusHandler(NULL); } void DropDown::draw(Graphics* graphics) { int h; if (mDroppedDown) { h = mFoldedUpHeight; } else { h = getHeight(); } Color faceColor = getBaseColor(); Color highlightColor, shadowColor; int alpha = getBaseColor().a; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; // Draw a border. graphics->setColor(shadowColor); graphics->drawLine(0, 0, getWidth() - 1, 0); graphics->drawLine(0, 1, 0, h - 2); graphics->setColor(highlightColor); graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, h - 1); graphics->drawLine(0, h - 1, getWidth() - 1, h - 1); // Push a clip area so the other drawings don't need to worry // about the border. graphics->pushClipArea(Rectangle(1, 1, getWidth() - 2, h - 2)); const Rectangle currentClipArea = graphics->getCurrentClipArea(); graphics->setColor(getBackgroundColor()); graphics->fillRectangle(0, 0, currentClipArea.width, currentClipArea.height); if (isFocused()) { graphics->setColor(getSelectionColor()); graphics->fillRectangle(0, 0, currentClipArea.width - currentClipArea.height, currentClipArea.height); graphics->setColor(getForegroundColor()); } if (mListBox->getListModel() && mListBox->getSelected() >= 0) { graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); graphics->drawText(mListBox->getListModel()->getElementAt(mListBox->getSelected()), 1, 0); } else if (mListBox->getListModel() && mListBox->getSelected() < 0) { graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); graphics->drawText("", 1, 0); } // Push a clip area before drawing the button. graphics->pushClipArea(Rectangle(currentClipArea.width - currentClipArea.height, 0, currentClipArea.height, currentClipArea.height)); drawButton(graphics); graphics->popClipArea(); graphics->popClipArea(); if (mDroppedDown) { // Draw a border around the children. graphics->setColor(shadowColor); graphics->drawRectangle(0, mFoldedUpHeight, getWidth(), getHeight() - mFoldedUpHeight); //drawChildren(graphics); } } void DropDown::drawButton(Graphics *graphics) { Color faceColor, highlightColor, shadowColor; int offset; int alpha = getBaseColor().a; if (mPushed) { faceColor = getBaseColor() - 0x303030; faceColor.a = alpha; highlightColor = faceColor - 0x303030; highlightColor.a = alpha; shadowColor = faceColor + 0x303030; shadowColor.a = alpha; offset = 1; } else { faceColor = getBaseColor(); faceColor.a = alpha; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; offset = 0; } const Rectangle currentClipArea = graphics->getCurrentClipArea(); graphics->setColor(highlightColor); graphics->drawLine(0, 0, currentClipArea.width - 1, 0); graphics->drawLine(0, 1, 0, currentClipArea.height - 1); graphics->setColor(shadowColor); graphics->drawLine(currentClipArea.width - 1, 1, currentClipArea.width - 1, currentClipArea.height - 1); graphics->drawLine(1, currentClipArea.height - 1, currentClipArea.width - 2, currentClipArea.height - 1); graphics->setColor(faceColor); graphics->fillRectangle(1, 1, currentClipArea.width - 2, currentClipArea.height - 2); graphics->setColor(getForegroundColor()); int i; int n = currentClipArea.height / 3; int dx = currentClipArea.height / 2; int dy = (currentClipArea.height * 2) / 3; for (i = 0; i < n; i++) { graphics->drawLine(dx - i + offset, dy - i + offset, dx + i + offset, dy - i + offset); } } int DropDown::getSelected() const { return mListBox->getSelected(); } void DropDown::setSelected(int selected) { mListBox->setSelected(selected); } void DropDown::keyPressed(KeyEvent& keyEvent) { if (keyEvent.isConsumed()) return; Key key = keyEvent.getKey(); if ((key.getValue() == Key::Enter || key.getValue() == Key::Space) && !mDroppedDown) { dropDown(); keyEvent.consume(); } else if (key.getValue() == Key::Up) { setSelected(getSelected() - 1); keyEvent.consume(); } else if (key.getValue() == Key::Down) { setSelected(getSelected() + 1); keyEvent.consume(); } } void DropDown::mousePressed(MouseEvent& mouseEvent) { // If we have a mouse press on the widget. if (0 <= mouseEvent.getY() && mouseEvent.getY() < getHeight() && mouseEvent.getX() >= 0 && mouseEvent.getX() < getWidth() && mouseEvent.getButton() == MouseEvent::Left && !mDroppedDown && mouseEvent.getSource() == this) { mPushed = true; dropDown(); requestModalMouseInputFocus(); } // Fold up the listbox if the upper part is clicked after fold down else if (0 <= mouseEvent.getY() && mouseEvent.getY() < mFoldedUpHeight && mouseEvent.getX() >= 0 && mouseEvent.getX() < getWidth() && mouseEvent.getButton() == MouseEvent::Left && mDroppedDown && mouseEvent.getSource() == this) { mPushed = false; foldUp(); releaseModalMouseInputFocus(); } // If we have a mouse press outside the widget else if (0 > mouseEvent.getY() || mouseEvent.getY() >= getHeight() || mouseEvent.getX() < 0 || mouseEvent.getX() >= getWidth()) { mPushed = false; foldUp(); } } void DropDown::mouseReleased(MouseEvent& mouseEvent) { if (mIsDragged) { mPushed = false; } // Released outside of widget. Can happen when we have modal input focus. if ((0 > mouseEvent.getY() || mouseEvent.getY() >= getHeight() || mouseEvent.getX() < 0 || mouseEvent.getX() >= getWidth()) && mouseEvent.getButton() == MouseEvent::Left && isModalMouseInputFocused()) { releaseModalMouseInputFocus(); if (mIsDragged) { foldUp(); } } else if (mouseEvent.getButton() == MouseEvent::Left) { mPushed = false; } mIsDragged = false; } void DropDown::mouseDragged(MouseEvent& mouseEvent) { mIsDragged = true; mouseEvent.consume(); } void DropDown::setListModel(ListModel *listModel) { mListBox->setListModel(listModel); adjustHeight(); } ListModel *DropDown::getListModel() const { return mListBox->getListModel(); } void DropDown::adjustHeight() { if (mScrollArea == NULL) { throw FCN_EXCEPTION("Scroll area has been deleted."); } if (mListBox == NULL) { throw FCN_EXCEPTION("List box has been deleted."); } int listBoxHeight = mListBox->getHeight(); // We add 2 for the border int h2 = getFont()->getHeight() + 2; setHeight(h2); // The addition/subtraction of 2 compensates for the seperation lines // seperating the selected element view and the scroll area. if (mDroppedDown && getParent()) { int h = getParent()->getChildrenArea().height - getY(); if (listBoxHeight > h - h2 - 2) { mScrollArea->setHeight(h - h2 - 2); setHeight(h); } else { setHeight(listBoxHeight + h2 + 2); mScrollArea->setHeight(listBoxHeight); } } mScrollArea->setWidth(getWidth()); // Resize the ListBox to exactly fit the ScrollArea. mListBox->setWidth(mScrollArea->getChildrenArea().width); mScrollArea->setPosition(0, 0); } void DropDown::resizeToContent(bool recursiv) { if (mScrollArea != NULL) { mScrollArea->resizeToContent(); } if (mListBox != NULL) { mScrollArea->resizeToContent(); } adjustHeight(); } void DropDown::adjustSize() { adjustHeight(); } void DropDown::dropDown() { if (!mDroppedDown) { mDroppedDown = true; mFoldedUpHeight = getHeight(); adjustHeight(); if (getParent()) { getParent()->moveToTop(this); } } mListBox->requestFocus(); } void DropDown::foldUp() { if (mDroppedDown) { mDroppedDown = false; adjustHeight(); mInternalFocusHandler.focusNone(); } } void DropDown::focusLost(const Event& event) { foldUp(); mInternalFocusHandler.focusNone(); } void DropDown::death(const Event& event) { if (event.getSource() == mScrollArea) { mScrollArea = NULL; } } void DropDown::action(const ActionEvent& actionEvent) { foldUp(); releaseModalMouseInputFocus(); distributeActionEvent(); } Rectangle DropDown::getChildrenArea() { if (mDroppedDown) { // Calculate the children area (with the one pixel border in mind) return Rectangle(1, mFoldedUpHeight + 1, getWidth() - 2, getHeight() - mFoldedUpHeight - 2); } return Rectangle(); } void DropDown::setBaseColor(const Color& color) { if (mInternalScrollArea) { mScrollArea->setBaseColor(color); } if (mInternalListBox) { mListBox->setBaseColor(color); } Widget::setBaseColor(color); } void DropDown::setBackgroundColor(const Color& color) { if (mInternalScrollArea) { mScrollArea->setBackgroundColor(color); } if (mInternalListBox) { mListBox->setBackgroundColor(color); } Widget::setBackgroundColor(color); } void DropDown::setForegroundColor(const Color& color) { if (mInternalScrollArea) { mScrollArea->setForegroundColor(color); } if (mInternalListBox) { mListBox->setForegroundColor(color); } Widget::setForegroundColor(color); } void DropDown::setFont(Font *font) { if (mInternalScrollArea) { mScrollArea->setFont(font); } if (mInternalListBox) { mListBox->setFont(font); } Widget::setFont(font); } void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent) { if (isFocused() && mouseEvent.getSource() == this) { mouseEvent.consume(); if (mListBox->getSelected() > 0) { mListBox->setSelected(mListBox->getSelected() - 1); } } } void DropDown::mouseWheelMovedDown(MouseEvent& mouseEvent) { if (isFocused() && mouseEvent.getSource() == this) { mouseEvent.consume(); mListBox->setSelected(mListBox->getSelected() + 1); } } void DropDown::setSelectionColor(const Color& color) { Widget::setSelectionColor(color); if (mInternalListBox) { mListBox->setSelectionColor(color); } } void DropDown::valueChanged(const SelectionEvent& event) { distributeValueChangedEvent(); } void DropDown::addSelectionListener(SelectionListener* selectionListener) { mSelectionListeners.push_back(selectionListener); } void DropDown::removeSelectionListener(SelectionListener* selectionListener) { mSelectionListeners.remove(selectionListener); } void DropDown::distributeValueChangedEvent() { SelectionListenerIterator iter; for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); ++iter) { SelectionEvent event(this); (*iter)->valueChanged(event); } } } fifechan-0.1.5/src/widgets/flowcontainer.cpp000066400000000000000000000245351341577075500211220ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* * For comments regarding functions please see the header file. */ #include #include "fifechan/widgets/flowcontainer.hpp" #include "fifechan/exception.hpp" namespace fcn { FlowContainer::FlowContainer(): mAlignment(Center) { setOpaque(true); } FlowContainer::~FlowContainer() { } void FlowContainer::setAlignment(FlowContainer::Alignment alignment) { mAlignment = alignment; } FlowContainer::Alignment FlowContainer::getAlignment() const { return mAlignment; } void FlowContainer::adjustContent() { // diff means border, padding, ... int diffW = ABS(getDimension().width - getChildrenArea().width); int diffH = ABS(getDimension().height - getChildrenArea().height); int containerW = getChildrenArea().width; int containerH = getChildrenArea().height; // calculates max layout size per column or row std::vector layoutMax; int tmpSize = 0; int x = 0; int y = 0; int visibleChilds = 0; std::list::const_iterator currChild(mChildren.begin()); std::list::const_iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { Widget* child = *currChild; if (!child->isVisible()) { continue; } ++visibleChilds; const Rectangle& rec = child->getDimension(); if (mLayout == Vertical) { // new column // negative bottom margin have no effect here if (y + child->getMarginTop() + rec.height + (child->getMarginBottom() > 0 ? child->getMarginBottom() : 0) > containerH) { y = 0; layoutMax.push_back(tmpSize); tmpSize = 0; } y += rec.height + child->getMarginTop() + child->getMarginBottom() + getVerticalSpacing(); tmpSize = std::max(tmpSize, rec.width + child->getMarginLeft() + (child->getMarginRight() > 0 ? child->getMarginRight() : 0)); } else { // new row // negative right margin have no effect here if (x + rec.width + child->getMarginLeft() + (child->getMarginRight() > 0 ? child->getMarginRight() : 0) > containerW) { x = 0; layoutMax.push_back(tmpSize); tmpSize = 0; } x += rec.width + child->getMarginLeft() + child->getMarginRight() + getHorizontalSpacing(); tmpSize = std::max(tmpSize, rec.height + child->getMarginTop() + (child->getMarginBottom() > 0 ? child->getMarginBottom() : 0)); } } if (tmpSize != 0) { layoutMax.push_back(tmpSize); } // places all widgets x = 0; y = 0; int totalW = 0; int totalH = 0; unsigned int layout = 0; if (mLayout == Vertical && visibleChilds > 0) { currChild = mChildren.begin(); endChildren = mChildren.end(); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } int columnW = layoutMax[layout]; int layoutW = (*currChild)->getWidth() + (*currChild)->getMarginLeft() + ((*currChild)->getMarginRight() > 0 ? (*currChild)->getMarginRight() : 0); Rectangle dim((*currChild)->getMarginLeft(), (*currChild)->getMarginTop(), layoutW, (*currChild)->getHeight()); // new column // negative bottom margin have no effect here if (y + (*currChild)->getMarginTop() + dim.height + ((*currChild)->getMarginBottom() > 0 ? (*currChild)->getMarginBottom() : 0) > containerH) { x += columnW + getHorizontalSpacing(); y = 0; ++layout; columnW = layoutMax[layout]; } dim.y += y; switch (getAlignment()) { case Left: dim.x += x; break; case Center: dim.x += x + (columnW - layoutW) / 2; break; case Right: dim.x += x + (columnW - layoutW); break; default: throw FCN_EXCEPTION("Unknown alignment."); } (*currChild)->setDimension(dim); y += (*currChild)->getHeight() + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom() + getVerticalSpacing(); totalW = std::max(totalW, dim.x + dim.width); totalH = std::max(totalH, y); } // remove last spacing totalH -= getVerticalSpacing(); // always expand height but width only if horizontal expand is enabled totalH = std::max(totalH, containerH); if (isHorizontalExpand()) { totalW = std::max(totalW, containerW); } } else if (mLayout == Horizontal && visibleChilds > 0) { currChild = mChildren.begin(); endChildren = mChildren.end(); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } int rowH = layoutMax[layout]; int layoutH = (*currChild)->getHeight() + (*currChild)->getMarginTop() + ((*currChild)->getMarginBottom() > 0 ? (*currChild)->getMarginBottom() : 0); Rectangle dim((*currChild)->getMarginLeft(), (*currChild)->getMarginTop(), (*currChild)->getWidth(), layoutH); // new row // negative right margin have no effect here if (x + (*currChild)->getMarginLeft() + dim.width + ((*currChild)->getMarginRight() > 0 ? (*currChild)->getMarginRight() : 0) > containerW) { x = 0; y += rowH + getVerticalSpacing(); ++layout; rowH = layoutMax[layout]; } dim.x += x; switch (getAlignment()) { case Top: dim.y += y; break; case Center: dim.y += y + (rowH - layoutH) / 2; break; case Bottom: dim.y += y + (rowH - layoutH); break; default: throw FCN_EXCEPTION("Unknown alignment."); } (*currChild)->setDimension(dim); x += (*currChild)->getWidth() + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight() + getHorizontalSpacing(); totalW = std::max(totalW, x); totalH = std::max(totalH, dim.y + dim.height); } // remove last spacing totalW -= getHorizontalSpacing(); // always expand width but height only if vertical expand is enabled totalW = std::max(totalW, containerW); if (isVerticalExpand()) { totalH = std::max(totalH, containerH); } } // resize container totalW += diffW; totalH += diffH; setSize(totalW, totalH); } void FlowContainer::setLayout(Container::LayoutPolicy policy) { if (policy == Circular) { throw FCN_EXCEPTION("Circular layout is not implemented for the FlowContainer."); } else { Container::setLayout(policy); } } void FlowContainer::resizeToContent(bool recursiv) { if (recursiv) { std::list::const_iterator currChild(mChildren.begin()); std::list::const_iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } (*currChild)->resizeToContent(recursiv); } } if (mLayout != Absolute) { if (getParent()) { setSize(getMinSize().getWidth(), getMinSize().getHeight()); } } } void FlowContainer::expandContent(bool recursiv) { if (mLayout != Absolute) { adjustContent(); } // not really needed if (recursiv) { std::list::const_iterator currChild(mChildren.begin()); std::list::const_iterator endChildren(mChildren.end()); for(; currChild != endChildren; ++currChild) { if (!(*currChild)->isVisible()) { continue; } (*currChild)->expandContent(recursiv); } } } } fifechan-0.1.5/src/widgets/icon.cpp000066400000000000000000000177671341577075500172110ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widgets/icon.hpp" #include "fifechan/graphics.hpp" #include "fifechan/image.hpp" #include "fifechan/rectangle.hpp" namespace fcn { Icon::Icon() : mImage(0), mInternalImage(false), mScale(false), mTile(false), mOpaque(true) { adjustSize(); } Icon::Icon(const std::string& filename) : mImage(0), mInternalImage(false), mScale(false), mTile(false), mOpaque(true) { mImage = Image::load(filename); mInternalImage = true; adjustSize(); } Icon::Icon(const Image* image) : mImage(image), mInternalImage(false), mScale(false), mTile(false), mOpaque(true) { adjustSize(); } Icon::~Icon() { if (mInternalImage) { delete mImage; } } void Icon::setImage(const std::string& filename) { if (mInternalImage) { delete mImage; } mImage = Image::load(filename); mInternalImage = true; adjustSize(); } void Icon::setImage(const Image* image) { if (mInternalImage) { delete mImage; } mImage = image; mInternalImage = false; adjustSize(); } const Image* Icon::getImage() const { return mImage; } bool Icon::isScaling() const { return mScale; } void Icon::setScaling(bool scale) { mScale = scale; } bool Icon::isTiling() const { return mTile; } void Icon::setTiling(bool tile) { mTile = tile; } void Icon::setOpaque(bool opaque) { mOpaque = opaque; } bool Icon::isOpaque() const { return mOpaque; } void Icon::resizeToContent(bool recursiv) { adjustSize(); } void Icon::adjustSize() { // workaround to avoid resizing if (mScale || mTile) { return; } int w = 2 * getBorderSize() + getPaddingLeft() + getPaddingRight(); int h = 2 * getBorderSize() + getPaddingTop() + getPaddingBottom(); if (mImage) { w += mImage->getWidth(); h += mImage->getHeight(); } setSize(w, h); } void Icon::draw(Graphics* graphics) { // draw icon background if (mOpaque) { Color color = getBackgroundColor(); if (isFocused() && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { color = getSelectionColor(); } graphics->setColor(color); graphics->fillRectangle(Rectangle(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize())); } // draw icon image if (mImage) { Rectangle contentRect(getBorderSize() + getPaddingLeft(), getBorderSize() + getPaddingTop(), getWidth() - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight(), getHeight() - 2 * getBorderSize() - getPaddingTop() - getPaddingBottom()); // draw with widget or image size int w = mScale ? contentRect.width : mImage->getWidth(); int h = mScale ? contentRect.height : mImage->getHeight(); if (mTile && !mScale) { Rectangle rect(contentRect.x, contentRect.y, w, h); int tmpW = getWidth() - getBorderSize() - getPaddingRight(); int tmpH = getHeight() - getBorderSize() - getPaddingBottom(); while (rect.x < tmpW) { rect.y = contentRect.y; while (rect.y < tmpH) { graphics->drawImage(mImage, 0, 0, rect.x, rect.y, rect.width, rect.height); rect.y += rect.height; } rect.x += rect.width; } } else { graphics->drawImage(mImage, 0, 0, contentRect.x, contentRect.y, w, h); } } // draw border or frame if (getBorderSize() > 0) { if (isFocused() && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } } } fifechan-0.1.5/src/widgets/iconprogressbar.cpp000066400000000000000000000142051341577075500214430ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include #include #include #include namespace fcn { IconProgressBar::IconProgressBar() : mImage(NULL), mInternalImage(false), mMaxIcons(0), mIconCounter(0), mOrientation(HORIZONTAL), mOpaque(true) { } IconProgressBar::IconProgressBar(Image* image, int maxIcons) : mImage(image), mInternalImage(false), mMaxIcons(maxIcons), mIconCounter(0), mOrientation(HORIZONTAL), mOpaque(true) { adjustSize(); } IconProgressBar::IconProgressBar(const std::string& filename, int maxIcons) : mImage(NULL), mInternalImage(true), mMaxIcons(maxIcons), mIconCounter(0), mOrientation(HORIZONTAL), mOpaque(true) { mImage = Image::load(filename); adjustSize(); } IconProgressBar::~IconProgressBar() { if(mInternalImage) { delete mImage; } } void IconProgressBar::draw(Graphics* graphics) { bool active = isFocused(); if (isOpaque()) { // Fill the background around the content if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { graphics->setColor(getSelectionColor()); } else { graphics->setColor(getBackgroundColor()); } graphics->fillRectangle(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); } // draw border or frame if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } if (!mImage) { return; } // draw "icons" int x = getBorderSize() + getPaddingLeft(); int y = getBorderSize() + getPaddingTop(); if (mOrientation == HORIZONTAL) { for (int i = 0; i < mIconCounter; i++) { graphics->drawImage(mImage, x, y); x += mImage->getWidth(); } } else { for (int i = 0; i < mIconCounter; i++) { graphics->drawImage(mImage, x, y); y += mImage->getHeight(); } } } void IconProgressBar::setOpaque(bool opaque) { mOpaque = opaque; } bool IconProgressBar::isOpaque() const { return mOpaque; } void IconProgressBar::setImage(Image* image) { if(mInternalImage) { delete mImage; } mInternalImage = false; mImage = image; adjustSize(); } const Image* IconProgressBar::getImage() const { return mImage; } void IconProgressBar::setMaxIcons(int maxIcons) { mMaxIcons = maxIcons; adjustSize(); } int IconProgressBar::getMaxIcons() const { return mMaxIcons; } void IconProgressBar::setOrientation(Orientation orientation) { if (mOrientation != orientation) { if (orientation != HORIZONTAL && orientation != VERTICAL) { throw FCN_EXCEPTION("Unknown orientation type in IconProgressBar object"); return; } mOrientation = orientation; adjustSize(); } } IconProgressBar::Orientation IconProgressBar::getOrientation() const { return mOrientation; } void IconProgressBar::advance() { mIconCounter = (mIconCounter + 1) % (mMaxIcons+1); } void IconProgressBar::reset() { mIconCounter = 0; } void IconProgressBar::setIconCount(int icons) { mIconCounter = icons % (mMaxIcons+1); } int IconProgressBar::getIconCount() const { return mIconCounter; } void IconProgressBar::resizeToContent(bool recursiv) { adjustSize(); } void IconProgressBar::adjustSize() { int w = 0; int h = 0; if (mImage) { w = mImage->getWidth(); h = mImage->getHeight(); if (mOrientation == HORIZONTAL) { w *= mMaxIcons; } else { h *= mMaxIcons; } } w += 2 * getBorderSize() + getPaddingLeft() + getPaddingRight(); h += 2 * getBorderSize() + getPaddingTop() + getPaddingBottom(); setSize(w, h); } };fifechan-0.1.5/src/widgets/imagebutton.cpp000066400000000000000000000265731341577075500205720ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include #include "fifechan/widgets/imagebutton.hpp" #include "fifechan/exception.hpp" #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" #include "fifechan/image.hpp" namespace fcn { ImageButton::ImageButton() { mImages = std::vector(6, static_cast(0)); mInternalImages = std::vector(6, false); adjustSize(); } ImageButton::ImageButton(const std::string& filename) { mImages = std::vector(6, static_cast(0)); mInternalImages = std::vector(6, false); setUpImage(filename); } ImageButton::ImageButton(const Image* image) { mImages = std::vector(6, static_cast(0)); mInternalImages = std::vector(6, false); setUpImage(image); } ImageButton::~ImageButton() { for (unsigned int i = 0; i < 6; ++i) { if (mInternalImages[i]) { delete mImages[i]; } } } void ImageButton::setImage(const std::string& filename, ImageType type) { if (mInternalImages[type]) { delete mImages[type]; } const Image* image = Image::load(filename); if (image) { mImages[type] = image; mInternalImages[type] = true; } else { mImages[type] = 0; mInternalImages[type] = false; } adjustSize(); } void ImageButton::setImage(const Image* image, ImageType type) { if (mInternalImages[type]) { delete mImages[type]; } mImages[type] = image; mInternalImages[type] = false; adjustSize(); } void ImageButton::setUpImage(const std::string& filename) { setImage(filename, Image_Up); } void ImageButton::setUpImage(const Image* image) { setImage(image, Image_Up); } const Image* ImageButton::getUpImage() const { return mImages[Image_Up]; } void ImageButton::setDownImage(const std::string& filename) { setImage(filename, Image_Down); } void ImageButton::setDownImage(const Image* image) { setImage(image, Image_Down); } const Image* ImageButton::getDownImage() const { return mImages[Image_Down]; } void ImageButton::setHoverImage(const std::string& filename) { setImage(filename, Image_Hover); } void ImageButton::setHoverImage(const Image* image) { setImage(image, Image_Hover); } const Image* ImageButton::getHoverImage() const { return mImages[Image_Hover]; } void ImageButton::setInactiveUpImage(const std::string& filename) { setImage(filename, Image_Up_De); } void ImageButton::setInactiveUpImage(const Image* image) { setImage(image, Image_Up_De); } const Image* ImageButton::getInactiveUpImage() const { return mImages[Image_Up_De]; } void ImageButton::setInactiveDownImage(const std::string& filename) { setImage(filename, Image_Down_De); } void ImageButton::setInactiveDownImage(const Image* image) { setImage(image, Image_Down_De); } const Image* ImageButton::getInactiveDownImage() const { return mImages[Image_Down_De]; } void ImageButton::setInactiveHoverImage(const std::string& filename) { setImage(filename, Image_Hover_De); } void ImageButton::setInactiveHoverImage(const Image* image) { setImage(image, Image_Hover_De); } const Image* ImageButton::getInactiveHoverImage() const { return mImages[Image_Hover_De]; } void ImageButton::resizeToContent(bool recursiv) { adjustSize(); } void ImageButton::adjustSize() { int w = 0; int h = 0; for (unsigned int i = 0; i < 6; ++i) { const Image* img = mImages[i]; if (img) { w = std::max(w, img->getWidth()); h = std::max(h, img->getHeight()); } } if (!getCaption().empty()) { w = std::max(getFont()->getWidth(getCaption()), w); h = std::max(getFont()->getHeight(), h); } w += 2 * getBorderSize() + getPaddingLeft() + getPaddingRight(); h += 2 * getBorderSize() + getPaddingTop() + getPaddingBottom(); setSize(w, h); } void ImageButton::draw(Graphics* graphics) { // draw border or frame if (getBorderSize() > 0) { if (isFocused() && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } Rectangle offsetRec(getBorderSize(), getBorderSize(), 2 * getBorderSize(), 2 * getBorderSize()); // fetch the image, down, hover or up const Image* img = !isActive() && getInactiveUpImage() ? getInactiveUpImage() : getUpImage(); if (isPressed()) { offsetRec.x += getDownXOffset(); offsetRec.y += getDownYOffset(); if (!isActive()) { if (getInactiveDownImage()) { img = getInactiveDownImage(); } } else { img = getDownImage() ? getDownImage() : getUpImage(); } } else if(mHasMouse) { if (!isActive()) { if (getInactiveHoverImage()) { img = getInactiveHoverImage(); } } else { img = getHoverImage() ? getHoverImage() : getUpImage(); } } // render foreground image or color rectangle if (img) { graphics->drawImage(img, 0, 0, offsetRec.x, offsetRec.y, getWidth() - offsetRec.width, getHeight() - offsetRec.height); } else { Color faceColor = getBaseColor(); if (isFocused() && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { faceColor = getSelectionColor(); } int alpha = faceColor.a; if (isPressed()) { faceColor = faceColor - 0x303030; faceColor.a = alpha; } if (!isActive()) { int color = static_cast(faceColor.r * 0.3 + faceColor.g * 0.59 + faceColor.b * 0.11); faceColor.r = color; faceColor.g = color; faceColor.b = color; } graphics->setColor(faceColor); graphics->fillRectangle(offsetRec.x, offsetRec.y, getWidth() - offsetRec.width, getHeight() - offsetRec.height); } // render caption if it exits if (!getCaption().empty()) { int textX; int textY = offsetRec.y + getPaddingTop() + (getHeight() - offsetRec.height - getPaddingTop() - getPaddingBottom() - getFont()->getHeight()) / 2; switch (getAlignment()) { case Graphics::Left: textX = offsetRec.x + getPaddingLeft(); break; case Graphics::Center: textX = offsetRec.x + getPaddingLeft() + (getWidth() - offsetRec.width - getPaddingLeft() - getPaddingRight()) / 2; break; case Graphics::Right: textX = getWidth() - offsetRec.x - getPaddingRight(); break; default: throw FCN_EXCEPTION("Unknown alignment."); } // set font and color graphics->setFont(getFont()); graphics->setColor(getForegroundColor()); graphics->drawText(getCaption(), textX, textY, getAlignment()); } } } fifechan-0.1.5/src/widgets/imageprogressbar.cpp000066400000000000000000000153301341577075500215750ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include #include #include #include #include namespace fcn { ImageProgressBar::ImageProgressBar() : mBarImage(NULL), mForegroundImage(NULL), mInternalImage(false), mMaxValue(100), mValue(0), mOrientation(HORIZONTAL), mOpaque(true) { } ImageProgressBar::ImageProgressBar(Image* image, int maxValue) : mBarImage(image), mForegroundImage(NULL), mInternalImage(false), mMaxValue(maxValue), mValue(0), mOrientation(HORIZONTAL), mOpaque(true) { adjustSize(); } ImageProgressBar::ImageProgressBar(const std::string& filename, int maxValue) : mBarImage(NULL), mForegroundImage(NULL), mInternalImage(true), mMaxValue(maxValue), mValue(0), mOrientation(HORIZONTAL), mOpaque(true) { mBarImage = Image::load(filename); adjustSize(); } ImageProgressBar::~ImageProgressBar() { if(mInternalImage) { delete mBarImage; } } void ImageProgressBar::draw(Graphics* graphics) { bool active = isFocused(); if (isOpaque()) { // Fill the background around the content if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { graphics->setColor(getSelectionColor()); } else { graphics->setColor(getBackgroundColor()); } graphics->fillRectangle(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); } // draw border or frame if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } if (mBarImage) { if (getOrientation() == HORIZONTAL) { Rectangle rec = Rectangle(getBorderSize() + getPaddingLeft(), getBorderSize() + getPaddingTop(), mBarImage->getWidth() * mValue/mMaxValue, mBarImage->getHeight()); graphics->pushClipArea(rec); graphics->drawImage(mBarImage, 0, 0); graphics->popClipArea(); } else { Rectangle rec = Rectangle(getBorderSize() + getPaddingLeft(), getBorderSize() + getPaddingTop() + (mBarImage->getHeight() - mBarImage->getHeight() * mValue/mMaxValue), mBarImage->getWidth(), mBarImage->getHeight() * mValue/mMaxValue); graphics->pushClipArea(rec); graphics->drawImage(mBarImage, 0, 0); graphics->popClipArea(); } } if (mForegroundImage) { int x = getBorderSize() + getPaddingLeft(); int y = getBorderSize() + getPaddingTop(); graphics->drawImage(mForegroundImage, x, y); } } void ImageProgressBar::setOpaque(bool opaque) { mOpaque = opaque; } bool ImageProgressBar::isOpaque() const { return mOpaque; } void ImageProgressBar::setBarImage(Image* image) { if(mInternalImage) { delete mBarImage; } mInternalImage = false; mBarImage = image; adjustSize(); } const Image* ImageProgressBar::getBarImage() const { return mBarImage; } void ImageProgressBar::setForegroundImage(Image* image) { mForegroundImage = image; adjustSize(); } const Image* ImageProgressBar::getForegroundImage() const { return mForegroundImage; } void ImageProgressBar::setOrientation(Orientation orientation) { if (mOrientation != orientation) { if (orientation != HORIZONTAL && orientation != VERTICAL) { throw FCN_EXCEPTION("Unknown orientation type in ImageProgressBar object"); return; } mOrientation = orientation; } } ImageProgressBar::Orientation ImageProgressBar::getOrientation() const { return mOrientation; } void ImageProgressBar::setMaxValue(int value) { mMaxValue = value; } int ImageProgressBar::getMaxValue() const { return mMaxValue; } void ImageProgressBar::setValue(int value) { if (value > mMaxValue) { mValue = mMaxValue; } else if (value < 0) { mValue = 0; } else { mValue = value; } } int ImageProgressBar::getValue() const { return mValue; } void ImageProgressBar::resizeToContent(bool recursiv) { adjustSize(); } void ImageProgressBar::adjustSize() { int w = 0; int h = 0; if (mBarImage) { w = mBarImage->getWidth(); h = mBarImage->getHeight(); } w += 2 * getBorderSize() + getPaddingLeft() + getPaddingRight(); h += 2 * getBorderSize() + getPaddingTop() + getPaddingBottom(); setSize(w, h); } };fifechan-0.1.5/src/widgets/label.cpp000066400000000000000000000141351341577075500173220ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widgets/label.hpp" #include "fifechan/exception.hpp" #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" namespace fcn { Label::Label() { mAlignment = Graphics::Left; adjustSize(); } Label::Label(const std::string& caption) { mCaption = caption; mAlignment = Graphics::Left; adjustSize(); } const std::string &Label::getCaption() const { return mCaption; } void Label::setCaption(const std::string& caption) { mCaption = caption; adjustSize(); } void Label::setAlignment(Graphics::Alignment alignment) { mAlignment = alignment; } Graphics::Alignment Label::getAlignment() const { return mAlignment; } void Label::resizeToContent(bool recursiv) { adjustSize(); } void Label::adjustSize() { setSize(2 * getBorderSize() + getPaddingLeft() + getPaddingRight() + getFont()->getWidth(mCaption), 2 * getBorderSize() + getPaddingTop() + getPaddingBottom() + getFont()->getHeight()); } void Label::draw(Graphics* graphics) { // draw border or frame if (getBorderSize() > 0) { if (isFocused() && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } Rectangle offsetRec(getBorderSize(), getBorderSize(), 2 * getBorderSize(), 2 * getBorderSize()); int textX; int textY = offsetRec.y + getPaddingTop() + (getHeight() - offsetRec.height - getPaddingTop() - getPaddingBottom() - getFont()->getHeight()) / 2; switch (getAlignment()) { case Graphics::Left: textX = offsetRec.x + getPaddingLeft(); break; case Graphics::Center: textX = offsetRec.x + getPaddingLeft() + (getWidth() - offsetRec.width - getPaddingLeft() - getPaddingRight()) / 2; break; case Graphics::Right: textX = getWidth() - offsetRec.x - getPaddingRight(); break; default: throw FCN_EXCEPTION("Unknown alignment."); } graphics->setFont(getFont()); graphics->setColor(getForegroundColor()); graphics->drawText(getCaption(), textX, textY, getAlignment()); } } fifechan-0.1.5/src/widgets/linegraph.cpp000066400000000000000000000101641341577075500202120ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include #include #include namespace fcn { LineGraph::LineGraph(): m_opaque(false), m_thickness(1), m_data() { } LineGraph::LineGraph(const PointVector& data): m_opaque(false), m_thickness(1), m_data(data) { } void LineGraph::setPointVector(const PointVector& data) { m_data = data; } const PointVector& LineGraph::getPointVector() const { return m_data; } void LineGraph::resetPointVector() { m_data.clear(); } void LineGraph::setThickness(unsigned int thickness) { m_thickness = thickness; } unsigned int LineGraph::getThickness() const { return m_thickness; } void LineGraph::setOpaque(bool opaque) { m_opaque = opaque; } bool LineGraph::isOpaque() const { return m_opaque; } void LineGraph::draw(Graphics* graphics) { bool active = isFocused(); if (isOpaque()) { // Fill the background around the content if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { graphics->setColor(getSelectionColor()); } else { graphics->setColor(getBackgroundColor()); } graphics->fillRectangle(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); } // draw border or frame if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } if (m_data.empty()) { return; } // draw lines graphics->setColor(getBaseColor()); bool thick = m_thickness > 1; PointVector::iterator pit = m_data.begin(); int x1 = (*pit).x; int y1 = (*pit).y; ++pit; if (thick) { for (; pit != m_data.end(); ++pit) { int x2 = (*pit).x; int y2 = (*pit).y; graphics->drawLine(x1, y1, x2, y2, m_thickness); x1 = x2; y1 = y2; } } else { for (; pit != m_data.end(); ++pit) { int x2 = (*pit).x; int y2 = (*pit).y; graphics->drawLine(x1, y1, x2, y2); x1 = x2; y1 = y2; } } } };fifechan-0.1.5/src/widgets/listbox.cpp000066400000000000000000000274431341577075500177350ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include #include "fifechan/widgets/listbox.hpp" #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" #include "fifechan/key.hpp" #include "fifechan/listmodel.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/selectionlistener.hpp" namespace fcn { ListBox::ListBox() : mSelected(-1), mListModel(NULL), mWrappingEnabled(false) { setWidth(100); setFocusable(true); addMouseListener(this); addKeyListener(this); } ListBox::ListBox(ListModel *listModel) : mSelected(-1), mWrappingEnabled(false) { setWidth(100); setListModel(listModel); setFocusable(true); addMouseListener(this); addKeyListener(this); } void ListBox::draw(Graphics* graphics) { graphics->setColor(getBackgroundColor()); graphics->fillRectangle(0, 0, getWidth(), getHeight()); if (mListModel == NULL) { return; } graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); // Check the current clip area so we don't draw unnecessary items // that are not visible. const ClipRectangle currentClipArea = graphics->getCurrentClipArea(); int rowHeight = getRowHeight(); // Calculate the number of rows to draw by checking the clip area. // The addition of two makes covers a partial visible row at the top // and a partial visible row at the bottom. int numberOfRows = currentClipArea.height / rowHeight + 2; if (numberOfRows > mListModel->getNumberOfElements()) { numberOfRows = mListModel->getNumberOfElements(); } // Calculate which row to start drawing. If the list box // has a negative y coordinate value we should check if // we should drop rows in the begining of the list as // they might not be visible. A negative y value is very // common if the list box for instance resides in a scroll // area and the user has scrolled the list box downwards. int startRow; if (getY() < 0) { startRow = -1 * (getY() / rowHeight); } else { startRow = 0; } int i; // The y coordinate where we start to draw the text is // simply the y coordinate multiplied with the font height. int y = rowHeight * startRow; for (i = startRow; i < startRow + numberOfRows; ++i) { if (i == mSelected) { graphics->setColor(getSelectionColor()); graphics->fillRectangle(0, y, getWidth(), rowHeight); graphics->setColor(getForegroundColor()); } // If the row height is greater than the font height we // draw the text with a center vertical alignment. if (rowHeight > getFont()->getHeight()) { graphics->drawText(mListModel->getElementAt(i), 1, y + rowHeight / 2 - getFont()->getHeight() / 2); } else { graphics->drawText(mListModel->getElementAt(i), 1, y); } y += rowHeight; } } void ListBox::logic() { adjustSize(); } int ListBox::getSelected() const { return mSelected; } void ListBox::setSelected(int selected) { if (mListModel == NULL) { mSelected = -1; } else { if (selected < 0) { mSelected = -1; } else if (selected >= mListModel->getNumberOfElements()) { mSelected = mListModel->getNumberOfElements() - 1; } else { mSelected = selected; } } Rectangle scroll; if (mSelected < 0) { scroll.y = 0; } else { scroll.y = getRowHeight() * mSelected; } scroll.height = getRowHeight(); showPart(scroll); distributeValueChangedEvent(); } void ListBox::keyPressed(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if (key.getValue() == Key::Enter || key.getValue() == Key::Space) { distributeActionEvent(); keyEvent.consume(); } else if (key.getValue() == Key::Up) { setSelected(mSelected - 1); if (mSelected == -1) { if (mWrappingEnabled) { setSelected(getListModel()->getNumberOfElements() - 1); } else { setSelected(0); } } keyEvent.consume(); } else if (key.getValue() == Key::Down) { if (mWrappingEnabled && getSelected() == getListModel()->getNumberOfElements() - 1) { setSelected(0); } else { setSelected(getSelected() + 1); } keyEvent.consume(); } else if (key.getValue() == Key::Home) { setSelected(0); keyEvent.consume(); } else if (key.getValue() == Key::End) { setSelected(getListModel()->getNumberOfElements() - 1); keyEvent.consume(); } } void ListBox::mousePressed(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == MouseEvent::Left) { setSelected(mouseEvent.getY() / getRowHeight()); distributeActionEvent(); } } void ListBox::mouseWheelMovedUp(MouseEvent& mouseEvent) { if (isFocused()) { if (getSelected() > 0 ) { setSelected(getSelected() - 1); } mouseEvent.consume(); } } void ListBox::mouseWheelMovedDown(MouseEvent& mouseEvent) { if (isFocused()) { setSelected(getSelected() + 1); mouseEvent.consume(); } } void ListBox::mouseDragged(MouseEvent& mouseEvent) { mouseEvent.consume(); } void ListBox::setListModel(ListModel *listModel) { mSelected = -1; mListModel = listModel; adjustSize(); } ListModel* ListBox::getListModel() const { return mListModel; } void ListBox::resizeToContent(bool recursiv) { adjustSize(); } void ListBox::adjustSize() { if (mListModel != NULL) { // min width in case the lit contains no element int w = getRowHeight(); int elements = mListModel->getNumberOfElements(); for (int i = 0; i < elements; ++i) { //std::string element = mListModel->getElementAt(i); w = std::max(w, getFont()->getWidth(mListModel->getElementAt(i))); } setWidth(w); setHeight(getRowHeight() * mListModel->getNumberOfElements()); } } bool ListBox::isWrappingEnabled() const { return mWrappingEnabled; } void ListBox::setWrappingEnabled(bool wrappingEnabled) { mWrappingEnabled = wrappingEnabled; } void ListBox::addSelectionListener(SelectionListener* selectionListener) { mSelectionListeners.push_back(selectionListener); } void ListBox::removeSelectionListener(SelectionListener* selectionListener) { mSelectionListeners.remove(selectionListener); } void ListBox::distributeValueChangedEvent() { SelectionListenerIterator iter; for (iter = mSelectionListeners.begin(); iter != mSelectionListeners.end(); ++iter) { SelectionEvent event(this); (*iter)->valueChanged(event); } } unsigned int ListBox::getRowHeight() const { return getFont()->getHeight(); } } fifechan-0.1.5/src/widgets/passwordfield.cpp000066400000000000000000000121071341577075500211060ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include #include #include #include namespace fcn { PasswordField::PasswordField(const std::string &text) : TextField(text) { mActualText = new Text; setText(text); } PasswordField::~PasswordField() { delete mActualText; } void PasswordField::keyPressed(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if (key.getValue() == Key::Left && getCaretPosition() > 0) { mText->setCaretPosition(mText->getCaretPosition() - 1); setActualTextCaretPosition(mStringEditor->prevChar(getText(), static_cast(getActualTextCaretPosition()))); } else if (key.getValue() == Key::Right && getCaretPosition() < getText().size()) { mText->setCaretPosition(mText->getCaretPosition() + 1); setActualTextCaretPosition(mStringEditor->nextChar(getText(), static_cast(getActualTextCaretPosition()))); } else if (mEditable && key.getValue() == Key::Delete && getCaretPosition() < getText().size() && mText->getNumberOfRows() > 0) { mText->remove(1); setActualTextCaretPosition(mStringEditor->eraseChar(mActualText->getRow(0), static_cast(getActualTextCaretPosition()))); } else if (mEditable && key.getValue() == Key::Backspace && getCaretPosition() > 0 && mText->getNumberOfRows() > 0) { mText->remove(-1); setActualTextCaretPosition(mStringEditor->prevChar(mActualText->getRow(0), static_cast(getActualTextCaretPosition()))); setActualTextCaretPosition(mStringEditor->eraseChar(mActualText->getRow(0), static_cast(getActualTextCaretPosition()))); } else if (key.getValue() == Key::Enter) { distributeActionEvent(); } else if (key.getValue() == Key::Home) { mText->setCaretColumn(0); setActualTextCaretPosition(0); } else if (key.getValue() == Key::End) { mText->setCaretColumn(mText->getNumberOfCharacters(0)); setActualTextCaretPosition(getText().size()); } // Add character to text, if key is realy a ASCII character // or is greater than 8bits long and the character is not // the tab key. else if ((key.isCharacter() || (key.getValue() > 255 && mText->getNumberOfRows() > 0)) && key.getValue() != Key::Tab) { mText->insert('*'); setActualTextCaretPosition(mStringEditor->insertChar(mActualText->getRow(0), getActualTextCaretPosition(), key.getValue())); } if (key.getValue() != Key::Tab) { // consume all characters except TAB which is needed // for traversing through widgets in a container. keyEvent.consume(); } fixScroll(); } void PasswordField::setText(const std::string& text) { std::string asterisks; asterisks.assign(text.size(), '*'); mText->setContent(asterisks); mActualText->setContent(text); } std::string PasswordField::getText() const { return mActualText->getContent(); } void PasswordField::setActualTextCaretPosition(unsigned int position) { mActualText->setCaretPosition(position); } unsigned int PasswordField::getActualTextCaretPosition() const { return mActualText->getCaretPosition(); } };fifechan-0.1.5/src/widgets/piegraph.cpp000066400000000000000000000104311341577075500200350ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include #include #include namespace fcn { PieGraph::PieGraph(): m_opaque(false), m_center(), m_radius(10) { } PieGraph::PieGraph(const Point& center): m_opaque(false), m_center(center), m_radius(10) { } void PieGraph::setCenterX(int x) { m_center.x = x; } void PieGraph::setCenterY(int y) { m_center.y = y; } void PieGraph::setCenter(int x, int y) { m_center.x = x; m_center.y = y; } int PieGraph::getCenterX() const { return m_center.x; } int PieGraph::getCenterY() const { return m_center.y; } void PieGraph::setCenter(const Point& center) { m_center = center; } const Point& PieGraph::getCenter() const { return m_center; } void PieGraph::setRadius(int radius) { m_radius = radius; } int PieGraph::getRadius() const { return m_radius; } void PieGraph::addSegment(int startAngle, int stopAngle, const Color& color) { PieGraphSegment segment; segment.startAngle = startAngle; segment.stopAngle = stopAngle; segment.color = color; m_segments.push_back(segment); } void PieGraph::clearSegments() { m_segments.clear(); } void PieGraph::setOpaque(bool opaque) { m_opaque = opaque; } bool PieGraph::isOpaque() const { return m_opaque; } void PieGraph::draw(Graphics* graphics) { bool active = isFocused(); if (isOpaque()) { // Fill the background around the content if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { graphics->setColor(getSelectionColor()); } else { graphics->setColor(getBackgroundColor()); } graphics->fillRectangle(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); } // draw border or frame if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } if (m_segments.empty() || m_radius < 1) { return; } // draw circle segments std::vector::iterator it = m_segments.begin(); for (; it != m_segments.end(); ++it) { graphics->setColor((*it).color); graphics->drawFillCircleSegment(m_center, m_radius, (*it).startAngle, (*it).stopAngle); } } };fifechan-0.1.5/src/widgets/pointgraph.cpp000066400000000000000000000075161341577075500204230ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include #include #include namespace fcn { PointGraph::PointGraph(): m_opaque(false), m_thickness(1), m_data() { } PointGraph::PointGraph(const PointVector& data): m_opaque(false), m_thickness(1), m_data(data) { } void PointGraph::setPointVector(const PointVector& data) { m_data = data; } const PointVector& PointGraph::getPointVector() const { return m_data; } void PointGraph::resetPointVector() { m_data.clear(); } void PointGraph::setThickness(unsigned int thickness) { m_thickness = thickness; } unsigned int PointGraph::getThickness() const { return m_thickness; } void PointGraph::setOpaque(bool opaque) { m_opaque = opaque; } bool PointGraph::isOpaque() const { return m_opaque; } void PointGraph::draw(Graphics* graphics) { bool active = isFocused(); if (isOpaque()) { // Fill the background around the content if (active && ((getSelectionMode() & Widget::Selection_Background) == Widget::Selection_Background)) { graphics->setColor(getSelectionColor()); } else { graphics->setColor(getBackgroundColor()); } graphics->fillRectangle(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); } // draw border or frame if (getBorderSize() > 0) { if (active && (getSelectionMode() & Widget::Selection_Border) == Widget::Selection_Border) { drawSelectionFrame(graphics); } else { drawBorder(graphics); } } if (m_data.empty()) { return; } // draw points graphics->setColor(getBaseColor()); bool thick = m_thickness > 1; PointVector::iterator pit = m_data.begin(); if (thick) { for (; pit != m_data.end(); ++pit) { graphics->drawFillCircle(*pit, m_thickness); } } else { for (; pit != m_data.end(); ++pit) { graphics->drawPoint((*pit).x, (*pit).y); } } } };fifechan-0.1.5/src/widgets/radiobutton.cpp000066400000000000000000000131371341577075500205760ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widgets/radiobutton.hpp" namespace fcn { RadioButton::GroupMap RadioButton::mGroupMap; RadioButton::RadioButton() { setMarkerStyle(Marker_Rhombus); setSelected(false); adjustSize(); } RadioButton::RadioButton(const std::string &caption, const std::string &group, bool selected) { setMarkerStyle(Marker_Rhombus); setCaption(caption); setGroup(group); setSelected(selected); adjustSize(); } RadioButton::~RadioButton() { // Remove us from the group list setGroup(""); } void RadioButton::setSelected(bool selected) { if (selected && mGroup != "") { // deselect all buttons in group GroupIterator iter, iterEnd; iterEnd = mGroupMap.upper_bound(mGroup); for (iter = mGroupMap.lower_bound(mGroup); iter != iterEnd; ++iter) { if (iter->second->isSelected()) { iter->second->setSelected(false); } } } mSelected = selected; } void RadioButton::toggleSelected() { setSelected(!isSelected()); } void RadioButton::setGroup(const std::string& group) { // Remove button from previous group if (mGroup != "") { GroupIterator iter, iterEnd; iterEnd = mGroupMap.upper_bound(mGroup); for (iter = mGroupMap.lower_bound(mGroup); iter != iterEnd; ++iter) { if (iter->second == this) { mGroupMap.erase(iter); break; } } } // Add button to new group if (group != "") { mGroupMap.insert(std::pair(group, this)); } mGroup = group; } const std::string& RadioButton::getGroup() const { return mGroup; } } fifechan-0.1.5/src/widgets/scrollarea.cpp000066400000000000000000001121641341577075500203730ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include #include "fifechan/widgets/scrollarea.hpp" #include "fifechan/exception.hpp" #include "fifechan/graphics.hpp" namespace fcn { ScrollArea::ScrollArea() { mVScroll = 0; mHScroll = 0; mHPolicy = ShowAuto; mVPolicy = ShowAuto; mScrollbarWidth = 12; mUpButtonPressed = false; mDownButtonPressed = false; mLeftButtonPressed = false; mRightButtonPressed = false; mUpButtonScrollAmount = 10; mDownButtonScrollAmount = 10; mLeftButtonScrollAmount = 10; mRightButtonScrollAmount = 10; mIsVerticalMarkerDragged = false; mIsHorizontalMarkerDragged =false; mOpaque = true; addMouseListener(this); } ScrollArea::ScrollArea(Widget *content) { mVScroll = 0; mHScroll = 0; mHPolicy = ShowAuto; mVPolicy = ShowAuto; mScrollbarWidth = 12; mUpButtonPressed = false; mDownButtonPressed = false; mLeftButtonPressed = false; mRightButtonPressed = false; mUpButtonScrollAmount = 10; mDownButtonScrollAmount = 10; mLeftButtonScrollAmount = 10; mRightButtonScrollAmount = 10; mIsVerticalMarkerDragged = false; mIsHorizontalMarkerDragged =false; mOpaque = true; setContent(content); addMouseListener(this); } ScrollArea::ScrollArea(Widget *content, ScrollPolicy hPolicy, ScrollPolicy vPolicy) { mVScroll = 0; mHScroll = 0; mHPolicy = hPolicy; mVPolicy = vPolicy; mScrollbarWidth = 12; mUpButtonPressed = false; mDownButtonPressed = false; mLeftButtonPressed = false; mRightButtonPressed = false; mUpButtonScrollAmount = 10; mDownButtonScrollAmount = 10; mLeftButtonScrollAmount = 10; mRightButtonScrollAmount = 10; mIsVerticalMarkerDragged = false; mIsHorizontalMarkerDragged =false; mOpaque = true; setContent(content); addMouseListener(this); } ScrollArea::~ScrollArea() { setContent(NULL); } void ScrollArea::setContent(Widget* widget) { if (widget != NULL) { clear(); add(widget); widget->setPosition(0,0); } else { clear(); } checkPolicies(); } Widget* ScrollArea::getContent() const { if (mChildren.size() > 0) return *mChildren.begin(); return NULL; } void ScrollArea::setHorizontalScrollPolicy(ScrollPolicy hPolicy) { mHPolicy = hPolicy; checkPolicies(); } ScrollArea::ScrollPolicy ScrollArea::getHorizontalScrollPolicy() const { return mHPolicy; } void ScrollArea::setVerticalScrollPolicy(ScrollPolicy vPolicy) { mVPolicy = vPolicy; checkPolicies(); } ScrollArea::ScrollPolicy ScrollArea::getVerticalScrollPolicy() const { return mVPolicy; } void ScrollArea::setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy) { mHPolicy = hPolicy; mVPolicy = vPolicy; checkPolicies(); } void ScrollArea::setVerticalScrollAmount(int vScroll) { int max = getVerticalMaxScroll(); mVScroll = vScroll; if (vScroll > max) mVScroll = max; if (vScroll < 0) mVScroll = 0; } int ScrollArea::getVerticalScrollAmount() const { return mVScroll; } void ScrollArea::setHorizontalScrollAmount(int hScroll) { int max = getHorizontalMaxScroll(); mHScroll = hScroll; if (hScroll > max) mHScroll = max; else if (hScroll < 0) mHScroll = 0; } int ScrollArea::getHorizontalScrollAmount() const { return mHScroll; } void ScrollArea::setScrollAmount(int hScroll, int vScroll) { setHorizontalScrollAmount(hScroll); setVerticalScrollAmount(vScroll); } int ScrollArea::getHorizontalMaxScroll() { checkPolicies(); if (getContent() == NULL) return 0; int value = getContent()->getWidth() - getChildrenArea().width + 2 * getContent()->getBorderSize(); if (value < 0) return 0; return value; } int ScrollArea::getVerticalMaxScroll() { checkPolicies(); if (getContent() == NULL) return 0; int value; value = getContent()->getHeight() - getChildrenArea().height + 2 * getContent()->getBorderSize(); if (value < 0) return 0; return value; } void ScrollArea::setScrollbarWidth(int width) { if (width <= 0) throw FCN_EXCEPTION("Width should be greater then 0."); mScrollbarWidth = width; } int ScrollArea::getScrollbarWidth() const { return mScrollbarWidth; } void ScrollArea::mousePressed(MouseEvent& mouseEvent) { int x = mouseEvent.getX(); int y = mouseEvent.getY(); if (getUpButtonDimension().isContaining(x, y)) { setVerticalScrollAmount(getVerticalScrollAmount() - mUpButtonScrollAmount); mUpButtonPressed = true; } else if (getDownButtonDimension().isContaining(x, y)) { setVerticalScrollAmount(getVerticalScrollAmount() + mDownButtonScrollAmount); mDownButtonPressed = true; } else if (getLeftButtonDimension().isContaining(x, y)) { setHorizontalScrollAmount(getHorizontalScrollAmount() - mLeftButtonScrollAmount); mLeftButtonPressed = true; } else if (getRightButtonDimension().isContaining(x, y)) { setHorizontalScrollAmount(getHorizontalScrollAmount() + mRightButtonScrollAmount); mRightButtonPressed = true; } else if (getVerticalMarkerDimension().isContaining(x, y)) { mIsHorizontalMarkerDragged = false; mIsVerticalMarkerDragged = true; mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y; } else if (getVerticalBarDimension().isContaining(x,y)) { if (y < getVerticalMarkerDimension().y) { setVerticalScrollAmount(getVerticalScrollAmount() - (int)(getChildrenArea().height * 0.95)); } else { setVerticalScrollAmount(getVerticalScrollAmount() + (int)(getChildrenArea().height * 0.95)); } } else if (getHorizontalMarkerDimension().isContaining(x, y)) { mIsHorizontalMarkerDragged = true; mIsVerticalMarkerDragged = false; mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x; } else if (getHorizontalBarDimension().isContaining(x,y)) { if (x < getHorizontalMarkerDimension().x) { setHorizontalScrollAmount(getHorizontalScrollAmount() - (int)(getChildrenArea().width * 0.95)); } else { setHorizontalScrollAmount(getHorizontalScrollAmount() + (int)(getChildrenArea().width * 0.95)); } } } void ScrollArea::mouseReleased(MouseEvent& mouseEvent) { mUpButtonPressed = false; mDownButtonPressed = false; mLeftButtonPressed = false; mRightButtonPressed = false; mIsHorizontalMarkerDragged = false; mIsVerticalMarkerDragged = false; mouseEvent.consume(); } void ScrollArea::mouseDragged(MouseEvent& mouseEvent) { if (mIsVerticalMarkerDragged) { int pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset; int length = getVerticalMarkerDimension().height; Rectangle barDim = getVerticalBarDimension(); if ((barDim.height - length) > 0) { setVerticalScrollAmount((getVerticalMaxScroll() * pos) / (barDim.height - length)); } else { setVerticalScrollAmount(0); } } if (mIsHorizontalMarkerDragged) { int pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset; int length = getHorizontalMarkerDimension().width; Rectangle barDim = getHorizontalBarDimension(); if ((barDim.width - length) > 0) { setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) / (barDim.width - length)); } else { setHorizontalScrollAmount(0); } } mouseEvent.consume(); } void ScrollArea::draw(Graphics *graphics) { drawBackground(graphics); if (mVBarVisible) { drawUpButton(graphics); drawDownButton(graphics); drawVBar(graphics); drawVMarker(graphics); } if (mHBarVisible) { drawLeftButton(graphics); drawRightButton(graphics); drawHBar(graphics); drawHMarker(graphics); } if (mHBarVisible && mVBarVisible) { graphics->setColor(getBaseColor()); graphics->fillRectangle(getWidth() - mScrollbarWidth, getHeight() - mScrollbarWidth, mScrollbarWidth, mScrollbarWidth); } } void ScrollArea::drawHBar(Graphics* graphics) { Rectangle dim = getHorizontalBarDimension(); graphics->pushClipArea(dim); int alpha = getBaseColor().a; Color trackColor = getBaseColor() - 0x101010; trackColor.a = alpha; Color shadowColor = getBaseColor() - 0x303030; shadowColor.a = alpha; graphics->setColor(trackColor); graphics->fillRectangle(0, 0, dim.width, dim.height); graphics->setColor(shadowColor); graphics->drawLine(0, 0, dim.width, 0); graphics->popClipArea(); } void ScrollArea::drawVBar(Graphics* graphics) { Rectangle dim = getVerticalBarDimension(); graphics->pushClipArea(dim); int alpha = getBaseColor().a; Color trackColor = getBaseColor() - 0x101010; trackColor.a = alpha; Color shadowColor = getBaseColor() - 0x303030; shadowColor.a = alpha; graphics->setColor(trackColor); graphics->fillRectangle(0, 0, dim.width, dim.height); graphics->setColor(shadowColor); graphics->drawLine(0, 0, 0, dim.height); graphics->popClipArea(); } void ScrollArea::drawBackground(Graphics *graphics) { if (isOpaque()) { graphics->setColor(getBackgroundColor()); graphics->fillRectangle(getChildrenArea()); } } void ScrollArea::drawUpButton(Graphics* graphics) { Rectangle dim = getUpButtonDimension(); graphics->pushClipArea(dim); Color highlightColor; Color shadowColor; Color faceColor; int offset; int alpha = getBaseColor().a; if (mUpButtonPressed) { faceColor = getBaseColor() - 0x303030; faceColor.a = alpha; highlightColor = faceColor - 0x303030; highlightColor.a = alpha; shadowColor = getBaseColor(); shadowColor.a = alpha; offset = 1; } else { faceColor = getBaseColor(); faceColor.a = alpha; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; offset = 0; } graphics->setColor(faceColor); graphics->fillRectangle(0, 0, dim.width, dim.height); graphics->setColor(highlightColor); graphics->drawLine(0, 0, dim.width - 1, 0); graphics->drawLine(0, 1, 0, dim.height - 1); graphics->setColor(shadowColor); graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); graphics->setColor(getForegroundColor()); int i; int w = dim.height / 2; int h = w / 2 + 2; for (i = 0; i < w / 2; ++i) { graphics->drawLine(w - i + offset, i + h + offset, w + i + offset, i + h + offset); } graphics->popClipArea(); } void ScrollArea::drawDownButton(Graphics* graphics) { Rectangle dim = getDownButtonDimension(); graphics->pushClipArea(dim); Color highlightColor; Color shadowColor; Color faceColor; int offset; int alpha = getBaseColor().a; if (mDownButtonPressed) { faceColor = getBaseColor() - 0x303030; faceColor.a = alpha; highlightColor = faceColor - 0x303030; highlightColor.a = alpha; shadowColor = getBaseColor(); shadowColor.a = alpha; offset = 1; } else { faceColor = getBaseColor(); faceColor.a = alpha; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; offset = 0; } graphics->setColor(faceColor); graphics->fillRectangle(0, 0, dim.width, dim.height); graphics->setColor(highlightColor); graphics->drawLine(0, 0, dim.width - 1, 0); graphics->drawLine(0, 1, 0, dim.height - 1); graphics->setColor(shadowColor); graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); graphics->setColor(getForegroundColor()); int i; int w = dim.height / 2; int h = w + 1; for (i = 0; i < w / 2; ++i) { graphics->drawLine(w - i + offset, -i + h + offset, w + i + offset, -i + h + offset); } graphics->popClipArea(); } void ScrollArea::drawLeftButton(Graphics* graphics) { Rectangle dim = getLeftButtonDimension(); graphics->pushClipArea(dim); Color highlightColor; Color shadowColor; Color faceColor; int offset; int alpha = getBaseColor().a; if (mLeftButtonPressed) { faceColor = getBaseColor() - 0x303030; faceColor.a = alpha; highlightColor = faceColor - 0x303030; highlightColor.a = alpha; shadowColor = getBaseColor(); shadowColor.a = alpha; offset = 1; } else { faceColor = getBaseColor(); faceColor.a = alpha; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; offset = 0; } graphics->setColor(faceColor); graphics->fillRectangle(0, 0, dim.width, dim.height); graphics->setColor(highlightColor); graphics->drawLine(0, 0, dim.width - 1, 0); graphics->drawLine(0, 1, 0, dim.height - 1); graphics->setColor(shadowColor); graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); graphics->setColor(getForegroundColor()); int i; int w = dim.width / 2; int h = w - 2; for (i = 0; i < w / 2; ++i) { graphics->drawLine(i + h + offset, w - i + offset, i + h + offset, w + i + offset); } graphics->popClipArea(); } void ScrollArea::drawRightButton(Graphics* graphics) { Rectangle dim = getRightButtonDimension(); graphics->pushClipArea(dim); Color highlightColor; Color shadowColor; Color faceColor; int offset; int alpha = getBaseColor().a; if (mRightButtonPressed) { faceColor = getBaseColor() - 0x303030; faceColor.a = alpha; highlightColor = faceColor - 0x303030; highlightColor.a = alpha; shadowColor = getBaseColor(); shadowColor.a = alpha; offset = 1; } else { faceColor = getBaseColor(); faceColor.a = alpha; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; offset = 0; } graphics->setColor(faceColor); graphics->fillRectangle(0, 0, dim.width, dim.height); graphics->setColor(highlightColor); graphics->drawLine(0, 0, dim.width - 1, 0); graphics->drawLine(0, 1, 0, dim.height - 1); graphics->setColor(shadowColor); graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); graphics->setColor(getForegroundColor()); int i; int w = dim.width / 2; int h = w + 1; for (i = 0; i < w / 2; ++i) { graphics->drawLine(-i + h + offset, w - i + offset, -i + h + offset, w + i + offset); } graphics->popClipArea(); } void ScrollArea::drawVMarker(Graphics* graphics) { Rectangle dim = getVerticalMarkerDimension(); graphics->pushClipArea(dim); int alpha = getBaseColor().a; Color faceColor = getBaseColor(); faceColor.a = alpha; Color highlightColor = faceColor + 0x303030; highlightColor.a = alpha; Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; graphics->setColor(faceColor); graphics->fillRectangle(1, 1, dim.width - 1, dim.height - 1); graphics->setColor(highlightColor); graphics->drawLine(0, 0, dim.width - 1, 0); graphics->drawLine(0, 1, 0, dim.height - 1); graphics->setColor(shadowColor); graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); graphics->popClipArea(); } void ScrollArea::drawHMarker(Graphics* graphics) { Rectangle dim = getHorizontalMarkerDimension(); graphics->pushClipArea(dim); int alpha = getBaseColor().a; Color faceColor = getBaseColor(); faceColor.a = alpha; Color highlightColor = faceColor + 0x303030; highlightColor.a = alpha; Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; graphics->setColor(faceColor); graphics->fillRectangle(1, 1, dim.width - 1, dim.height - 1); graphics->setColor(highlightColor); graphics->drawLine(0, 0, dim.width - 1, 0); graphics->drawLine(0, 1, 0, dim.height - 1); graphics->setColor(shadowColor); graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1); graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1); graphics->popClipArea(); } void ScrollArea::logic() { checkPolicies(); setVerticalScrollAmount(getVerticalScrollAmount()); setHorizontalScrollAmount(getHorizontalScrollAmount()); if (getContent() != NULL) { getContent()->setPosition(-mHScroll + getContent()->getBorderSize(), -mVScroll + getContent()->getBorderSize()); getContent()->logic(); } } void ScrollArea::checkPolicies() { int w = getWidth(); int h = getHeight(); mHBarVisible = false; mVBarVisible = false; if (!getContent()) { mHBarVisible = (mHPolicy == ShowAlways); mVBarVisible = (mVPolicy == ShowAlways); return; } if (mHPolicy == ShowAuto && mVPolicy == ShowAuto) { if (getContent()->getWidth() <= w && getContent()->getHeight() <= h) { mHBarVisible = false; mVBarVisible = false; } if (getContent()->getWidth() > w) mHBarVisible = true; if ((getContent()->getHeight() > h) || (mHBarVisible && getContent()->getHeight() > h - mScrollbarWidth)) { mVBarVisible = true; } if (mVBarVisible && getContent()->getWidth() > w - mScrollbarWidth) mHBarVisible = true; return; } switch (mHPolicy) { case ShowNever: mHBarVisible = false; break; case ShowAlways: mHBarVisible = true; break; case ShowAuto: if (mVPolicy == ShowNever) { mHBarVisible = getContent()->getWidth() > w; } else // (mVPolicy == ShowAlways) { mHBarVisible = getContent()->getWidth() > w - mScrollbarWidth; } break; default: throw FCN_EXCEPTION("Horizontal scroll policy invalid."); } switch (mVPolicy) { case ShowNever: mVBarVisible = false; break; case ShowAlways: mVBarVisible = true; break; case ShowAuto: if (mHPolicy == ShowNever) { mVBarVisible = getContent()->getHeight() > h; } else // (mHPolicy == ShowAlways) { mVBarVisible = getContent()->getHeight() > h - mScrollbarWidth; } break; default: throw FCN_EXCEPTION("Vertical scroll policy invalid."); } } Rectangle ScrollArea::getUpButtonDimension() { if (!mVBarVisible) return Rectangle(0, 0, 0, 0); return Rectangle(getWidth() - mScrollbarWidth, 0, mScrollbarWidth, mScrollbarWidth); } Rectangle ScrollArea::getDownButtonDimension() { if (!mVBarVisible) return Rectangle(0, 0, 0, 0); if (mVBarVisible && mHBarVisible) { return Rectangle(getWidth() - mScrollbarWidth, getHeight() - mScrollbarWidth*2, mScrollbarWidth, mScrollbarWidth); } return Rectangle(getWidth() - mScrollbarWidth, getHeight() - mScrollbarWidth, mScrollbarWidth, mScrollbarWidth); } Rectangle ScrollArea::getLeftButtonDimension() { if (!mHBarVisible) return Rectangle(0, 0, 0, 0); return Rectangle(0, getHeight() - mScrollbarWidth, mScrollbarWidth, mScrollbarWidth); } Rectangle ScrollArea::getRightButtonDimension() { if (!mHBarVisible) return Rectangle(0, 0, 0, 0); if (mVBarVisible && mHBarVisible) { return Rectangle(getWidth() - mScrollbarWidth*2, getHeight() - mScrollbarWidth, mScrollbarWidth, mScrollbarWidth); } return Rectangle(getWidth() - mScrollbarWidth, getHeight() - mScrollbarWidth, mScrollbarWidth, mScrollbarWidth); } Rectangle ScrollArea::getChildrenArea() { Rectangle area = Rectangle(0, 0, mVBarVisible ? getWidth() - mScrollbarWidth : getWidth(), mHBarVisible ? getHeight() - mScrollbarWidth : getHeight()); if (area.isEmpty()) return Rectangle(); return area; } Rectangle ScrollArea::getVerticalBarDimension() { if (!mVBarVisible) return Rectangle(0, 0, 0, 0); if (mHBarVisible) { return Rectangle(getWidth() - mScrollbarWidth, getUpButtonDimension().height, mScrollbarWidth, getHeight() - getUpButtonDimension().height - getDownButtonDimension().height - mScrollbarWidth); } return Rectangle(getWidth() - mScrollbarWidth, getUpButtonDimension().height, mScrollbarWidth, getHeight() - getUpButtonDimension().height - getDownButtonDimension().height); } Rectangle ScrollArea::getHorizontalBarDimension() { if (!mHBarVisible) return Rectangle(0, 0, 0, 0); if (mVBarVisible) { return Rectangle(getLeftButtonDimension().width, getHeight() - mScrollbarWidth, getWidth() - getLeftButtonDimension().width - getRightButtonDimension().width - mScrollbarWidth, mScrollbarWidth); } return Rectangle(getLeftButtonDimension().width, getHeight() - mScrollbarWidth, getWidth() - getLeftButtonDimension().width - getRightButtonDimension().width, mScrollbarWidth); } Rectangle ScrollArea::getVerticalMarkerDimension() { if (!mVBarVisible) return Rectangle(0, 0, 0, 0); int length, pos; Rectangle barDim = getVerticalBarDimension(); if (getContent() && getContent()->getHeight() != 0) { length = (barDim.height * getChildrenArea().height) / getContent()->getHeight(); } else { length = barDim.height; } if (length < mScrollbarWidth) length = mScrollbarWidth; if (length > barDim.height) length = barDim.height; if (getVerticalMaxScroll() != 0) { pos = ((barDim.height - length) * getVerticalScrollAmount()) / getVerticalMaxScroll(); } else { pos = 0; } return Rectangle(barDim.x, barDim.y + pos, mScrollbarWidth, length); } Rectangle ScrollArea::getHorizontalMarkerDimension() { if (!mHBarVisible) return Rectangle(0, 0, 0, 0); int length, pos; Rectangle barDim = getHorizontalBarDimension(); if (getContent() && getContent()->getWidth() != 0) { length = (barDim.width * getChildrenArea().width) / getContent()->getWidth(); } else { length = barDim.width; } if (length < mScrollbarWidth) length = mScrollbarWidth; if (length > barDim.width) length = barDim.width; if (getHorizontalMaxScroll() != 0) { pos = ((barDim.width - length) * getHorizontalScrollAmount()) / getHorizontalMaxScroll(); } else { pos = 0; } return Rectangle(barDim.x + pos, barDim.y, length, mScrollbarWidth); } void ScrollArea::showWidgetPart(Widget* widget, Rectangle area) { if (widget != getContent()) throw FCN_EXCEPTION("Widget not content widget"); Widget::showWidgetPart(widget, area); setHorizontalScrollAmount(getContent()->getBorderSize() - getContent()->getX()); setVerticalScrollAmount(getContent()->getBorderSize() - getContent()->getY()); } Widget *ScrollArea::getWidgetAt(int x, int y) { if (getChildrenArea().isContaining(x, y)) return getContent(); return NULL; } void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent) { if (mouseEvent.isConsumed()) return; if (!mVBarVisible) { mouseEvent.consume(); return; } setVerticalScrollAmount(getVerticalScrollAmount() - getChildrenArea().height / 8); mouseEvent.consume(); } void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent) { if (mouseEvent.isConsumed()) return; if (!mVBarVisible) { mouseEvent.consume(); return; } setVerticalScrollAmount(getVerticalScrollAmount() + getChildrenArea().height / 8); mouseEvent.consume(); } void ScrollArea::mouseWheelMovedRight(MouseEvent& mouseEvent) { if (mouseEvent.isConsumed()) return; if (!mHBarVisible) { mouseEvent.consume(); return; } setHorizontalScrollAmount(getHorizontalScrollAmount() + getChildrenArea().width / 8); mouseEvent.consume(); } void ScrollArea::mouseWheelMovedLeft(MouseEvent& mouseEvent) { if (mouseEvent.isConsumed()) return; if (!mHBarVisible) { mouseEvent.consume(); return; } setHorizontalScrollAmount(getHorizontalScrollAmount() - getChildrenArea().width / 8); mouseEvent.consume(); } void ScrollArea::setWidth(int width) { Widget::setWidth(width); Widget* content = getContent(); if (content) { int contW = std::max(getWidth(), content->getWidth()); content->setWidth(contW); } checkPolicies(); } void ScrollArea::setHeight(int height) { Widget::setHeight(height); Widget* content = getContent(); if (content) { int contH = std::max(getHeight(), content->getHeight()); content->setHeight(contH); } checkPolicies(); } void ScrollArea::setDimension(const Rectangle& dimension) { Widget::setDimension(dimension); Widget* content = getContent(); if (content) { int contW = std::max(getWidth(), content->getWidth()); content->setWidth(contW); int contH = std::max(getHeight(), content->getHeight()); content->setHeight(contH); } checkPolicies(); } void ScrollArea::resizeToContent(bool recursiv) { Widget* content = getContent(); if (content) { content->resizeToContent(); } const Size& min = getMinSize(); setWidth(min.getWidth()); setHeight(min.getHeight()); } void ScrollArea::adjustSize() { Widget* content = getContent(); if (content) { content->adjustSize(); } const Size& min = getMinSize(); setWidth(min.getWidth()); setHeight(min.getHeight()); } void ScrollArea::expandContent(bool recursiv) { // remove that hack setWidth(getWidth()); setHeight(getHeight()); Widget* content = getContent(); if (content) { content->expandContent(); } checkPolicies(); } void ScrollArea::setLeftButtonScrollAmount(int amount) { mLeftButtonScrollAmount = amount; } void ScrollArea::setRightButtonScrollAmount(int amount) { mRightButtonScrollAmount = amount; } void ScrollArea::setUpButtonScrollAmount(int amount) { mUpButtonScrollAmount = amount; } void ScrollArea::setDownButtonScrollAmount(int amount) { mDownButtonScrollAmount = amount; } int ScrollArea::getLeftButtonScrollAmount() const { return mLeftButtonScrollAmount; } int ScrollArea::getRightButtonScrollAmount() const { return mRightButtonScrollAmount; } int ScrollArea::getUpButtonScrollAmount() const { return mUpButtonScrollAmount; } int ScrollArea::getDownButtonScrollAmount() const { return mDownButtonScrollAmount; } void ScrollArea::setOpaque(bool opaque) { mOpaque = opaque; } bool ScrollArea::isOpaque() const { return mOpaque; } } /* * Wow! This is a looooong source file. */ fifechan-0.1.5/src/widgets/slider.cpp000066400000000000000000000313711341577075500175260ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widgets/slider.hpp" #include "fifechan/graphics.hpp" #include "fifechan/key.hpp" #include "fifechan/mouseinput.hpp" namespace fcn { Slider::Slider(double scaleEnd) { mDragged = false; mScaleStart = 0; mScaleEnd = scaleEnd; setFocusable(true); setBorderSize(1); setOrientation(Horizontal); setValue(0); setStepLength(scaleEnd / 10); setMarkerLength(10); addMouseListener(this); addKeyListener(this); } Slider::Slider(double scaleStart, double scaleEnd) { mDragged = false; mScaleStart = scaleStart; mScaleEnd = scaleEnd; setFocusable(true); setBorderSize(1); setOrientation(Horizontal); setValue(scaleStart); setStepLength((scaleEnd - scaleStart)/ 10); setMarkerLength(10); addMouseListener(this); addKeyListener(this); } void Slider::setScale(double scaleStart, double scaleEnd) { mScaleStart = scaleStart; mScaleEnd = scaleEnd; if (mScaleStart > mValue) { mValue = mScaleStart; } if (mScaleEnd < mValue) { mValue = mScaleEnd; } } double Slider::getScaleStart() const { return mScaleStart; } void Slider::setScaleStart(double scaleStart) { mScaleStart = scaleStart; if (mScaleStart > mValue) { mValue = mScaleStart; } } double Slider::getScaleEnd() const { return mScaleEnd; } void Slider::setScaleEnd(double scaleEnd) { mScaleEnd = scaleEnd; if (mScaleEnd < mValue) { mValue = mScaleEnd; } } void Slider::draw(fcn::Graphics* graphics) { Color shadowColor = getBaseColor() - 0x101010; int alpha = getBaseColor().a; shadowColor.a = alpha; graphics->setColor(shadowColor); graphics->fillRectangle(0, 0, getWidth(), getHeight()); drawMarker(graphics); } void Slider::drawMarker(fcn::Graphics* graphics) { fcn::Color faceColor = getBaseColor(); Color highlightColor, shadowColor; int alpha = getBaseColor().a; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; graphics->setColor(faceColor); if (getOrientation() == Horizontal) { int v = getMarkerPosition(); graphics->fillRectangle(v + 1, 1, getMarkerLength() - 2, getHeight() - 2); graphics->setColor(highlightColor); graphics->drawLine(v, 0, v + getMarkerLength() - 1,0); graphics->drawLine(v, 0, v, getHeight() - 1); graphics->setColor(shadowColor); graphics->drawLine(v + getMarkerLength() - 1, 1, v + getMarkerLength() - 1, getHeight() - 1); graphics->drawLine(v + 1, getHeight() - 1, v + getMarkerLength() - 1, getHeight() - 1); if (isFocused()) { graphics->setColor(getForegroundColor()); graphics->drawRectangle(v + 2, 2, getMarkerLength() - 4, getHeight() - 4); } } else { int v = (getHeight() - getMarkerLength()) - getMarkerPosition(); graphics->fillRectangle(1, v + 1, getWidth() - 2, getMarkerLength() - 2); graphics->setColor(highlightColor); graphics->drawLine(0, v, 0, v + getMarkerLength() - 1); graphics->drawLine(0, v, getWidth() - 1, v); graphics->setColor(shadowColor); graphics->drawLine(1, v + getMarkerLength() - 1, getWidth() - 1, v + getMarkerLength() - 1); graphics->drawLine(getWidth() - 1, v + 1, getWidth() - 1, v + getMarkerLength() - 1); if (isFocused()) { graphics->setColor(getForegroundColor()); graphics->drawRectangle(2, v + 2, getWidth() - 4, getMarkerLength() - 4); } } } void Slider::mousePressed(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == fcn::MouseEvent::Left && mouseEvent.getX() >= 0 && mouseEvent.getX() <= getWidth() && mouseEvent.getY() >= 0 && mouseEvent.getY() <= getHeight()) { if (getOrientation() == Horizontal) { setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2)); } else { setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2)); } distributeActionEvent(); } } void Slider::mouseDragged(MouseEvent& mouseEvent) { if (getOrientation() == Horizontal) { setValue(markerPositionToValue(mouseEvent.getX() - getMarkerLength() / 2)); } else { setValue(markerPositionToValue(getHeight() - mouseEvent.getY() - getMarkerLength() / 2)); } distributeActionEvent(); mouseEvent.consume(); } void Slider::setValue(double value) { if (value > getScaleEnd()) { mValue = getScaleEnd(); return; } if (value < getScaleStart()) { mValue = getScaleStart(); return; } mValue = value; } double Slider::getValue() const { return mValue; } int Slider::getMarkerLength() const { return mMarkerLength; } void Slider::setMarkerLength(int length) { mMarkerLength = length; } void Slider::keyPressed(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if (getOrientation() == Horizontal) { if (key.getValue() == Key::Right) { setValue(getValue() + getStepLength()); distributeActionEvent(); keyEvent.consume(); } else if (key.getValue() == Key::Left) { setValue(getValue() - getStepLength()); distributeActionEvent(); keyEvent.consume(); } } else { if (key.getValue() == Key::Up) { setValue(getValue() + getStepLength()); distributeActionEvent(); keyEvent.consume(); } else if (key.getValue() == Key::Down) { setValue(getValue() - getStepLength()); distributeActionEvent(); keyEvent.consume(); } } } void Slider::setOrientation(Slider::Orientation orientation) { mOrientation = orientation; } Slider::Orientation Slider::getOrientation() const { return mOrientation; } double Slider::markerPositionToValue(int v) const { int w; if (getOrientation() == Horizontal) { w = getWidth(); } else { w = getHeight(); } double pos = v / ((double)w - getMarkerLength()); return (1.0 - pos) * getScaleStart() + pos * getScaleEnd(); } int Slider::valueToMarkerPosition(double value) const { int v; if (getOrientation() == Horizontal) { v = getWidth(); } else { v = getHeight(); } int w = (int)((v - getMarkerLength()) * (value - getScaleStart()) / (getScaleEnd() - getScaleStart())); if (w < 0) { return 0; } if (w > v - getMarkerLength()) { return v - getMarkerLength(); } return w; } void Slider::setStepLength(double length) { mStepLength = length; } double Slider::getStepLength() const { return mStepLength; } int Slider::getMarkerPosition() const { return valueToMarkerPosition(getValue()); } void Slider::mouseWheelMovedUp(MouseEvent& mouseEvent) { if (getOrientation() == Vertical) { setValue(getValue() + getStepLength()); distributeActionEvent(); mouseEvent.consume(); } } void Slider::mouseWheelMovedDown(MouseEvent& mouseEvent) { if (getOrientation() == Vertical) { setValue(getValue() - getStepLength()); distributeActionEvent(); mouseEvent.consume(); } } void Slider::mouseWheelMovedRight(MouseEvent& mouseEvent) { if (getOrientation() == Horizontal) { setValue(getValue() + getStepLength()); distributeActionEvent(); mouseEvent.consume(); } } void Slider::mouseWheelMovedLeft(MouseEvent& mouseEvent) { if (getOrientation() == Horizontal) { setValue(getValue() - getStepLength()); distributeActionEvent(); mouseEvent.consume(); } } } fifechan-0.1.5/src/widgets/spacer.cpp000066400000000000000000000036371341577075500175250ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012-2019 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "fifechan/widgets/spacer.hpp" #include "fifechan/exception.hpp" namespace fcn { Spacer::Spacer() { setVerticalExpand(true); setHorizontalExpand(true); } Spacer::~Spacer() { } void Spacer::resizeToContent(bool recursiv) { setSize(getMinSize().getWidth(), getMinSize().getHeight()); } void Spacer::draw(Graphics *graphics) { } }; fifechan-0.1.5/src/widgets/tab.cpp000066400000000000000000000161141341577075500170100ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widgets/tab.hpp" #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" #include "fifechan/widgets/tabbedarea.hpp" namespace fcn { Tab::Tab() :mHasMouse(false), mTabbedArea(NULL) { addMouseListener(this); setLayout(Container::Horizontal); } Tab::~Tab() { } void Tab::adjustSize() { Container::adjustSize(); if (mTabbedArea != NULL) mTabbedArea->adjustTabPositions(); } void Tab::setTabbedArea(TabbedArea* tabbedArea) { mTabbedArea = tabbedArea; } TabbedArea* Tab::getTabbedArea() { return mTabbedArea; } Rectangle Tab::getChildrenArea() { Rectangle rec; rec.x = getBorderSize() + getPaddingLeft(); rec.y = getBorderSize() + getPaddingTop(); rec.width = getWidth() - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight(); rec.height = getHeight() - 2 * getBorderSize() - getPaddingTop() - getPaddingBottom(); return rec; } void Tab::draw(Graphics *graphics) { const Color &faceColor = getBaseColor(); const int alpha = getBaseColor().a; Color highlightColor = faceColor + 0x303030; highlightColor.a = alpha; Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; Color borderColor; Color baseColor; if ((mTabbedArea != NULL && mTabbedArea->isTabSelected(this)) || mHasMouse) { // Draw a border. graphics->setColor(highlightColor); graphics->drawLine(0, 0, getWidth() - 1, 0); graphics->drawLine(0, 1, 0, getHeight() - 1); graphics->setColor(shadowColor); graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); borderColor = highlightColor; baseColor = getBaseColor(); } else { // Draw a border. graphics->setColor(shadowColor); graphics->drawLine(0, 0, getWidth() - 1, 0); graphics->drawLine(0, 1, 0, getHeight() - 1); graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); baseColor = getBaseColor() - 0x151515; baseColor.a = alpha; } // Push a clip area so the other drawings don't need to worry // about the border. graphics->pushClipArea(Rectangle(1, 1, getWidth() - 2, getHeight() - 1)); const Rectangle currentClipArea = graphics->getCurrentClipArea(); graphics->setColor(baseColor); graphics->fillRectangle(0, 0, currentClipArea.width, currentClipArea.height); if (mTabbedArea != NULL && mTabbedArea->isFocused() && mTabbedArea->isTabSelected(this)) { graphics->setColor(Color(0x000000)); graphics->drawRectangle(2, 2, currentClipArea.width - 4, currentClipArea.height - 4); } graphics->popClipArea(); } void Tab::mouseEntered(MouseEvent& mouseEvent) { mHasMouse = true; } void Tab::mouseExited(MouseEvent& mouseEvent) { mHasMouse = false; } } fifechan-0.1.5/src/widgets/tabbedarea.cpp000066400000000000000000000460541341577075500203220ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widgets/tabbedarea.hpp" #include "fifechan/exception.hpp" #include "fifechan/focushandler.hpp" #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" #include "fifechan/widgets/tab.hpp" #include namespace fcn { TabbedArea::TabbedArea() :mSelectedTab(NULL), mOpaque(false) { setFocusable(true); addKeyListener(this); addMouseListener(this); mTabContainer = new Container(); mTabContainer->setOpaque(false); mTabContainer->setLayout(Container::Horizontal); mWidgetContainer = new Container(); mWidgetContainer->setLayout(Container::Vertical); add(mTabContainer); add(mWidgetContainer); } TabbedArea::~TabbedArea() { remove(mTabContainer); remove(mWidgetContainer); delete mTabContainer; delete mWidgetContainer; for (unsigned int i = 0; i < mTabsToDelete.size(); i++) { delete mTabsToDelete[i]; } } void TabbedArea::addTab(Tab* tab, Widget* widget) { tab->setTabbedArea(this); tab->addActionListener(this); if (tab->getLayout() == Container::Absolute) { tab->setLayout(getLayout()); } mTabContainer->add(tab); mTabs.push_back(std::pair(tab, widget)); if (mSelectedTab == NULL) { setSelectedTab(tab); } else { adaptLayout(); } } void TabbedArea::removeTabWithIndex(unsigned int index) { if (index >= mTabs.size()) { throw FCN_EXCEPTION("No such tab index."); } removeTab(mTabs[index].first); } void TabbedArea::removeTab(Tab* tab) { int tabIndexToBeSelected = - 1; if (tab == mSelectedTab) { int index = getSelectedTabIndex(); if (index == (int)mTabs.size() - 1 && mTabs.size() >= 2) { tabIndexToBeSelected = index-1; } else if (index == (int)mTabs.size() - 1 && mTabs.size() == 1) { tabIndexToBeSelected = -1; } else { tabIndexToBeSelected = index; } } std::vector >::iterator iter; for (iter = mTabs.begin(); iter != mTabs.end(); iter++) { if (iter->first == tab) { mTabContainer->remove(tab); mTabs.erase(iter); break; } } std::vector::iterator iter2; for (iter2 = mTabsToDelete.begin(); iter2 != mTabsToDelete.end(); iter2++) { if (*iter2 == tab) { mTabsToDelete.erase(iter2); delete tab; break; } } if (tabIndexToBeSelected == -1) { mSelectedTab = NULL; mWidgetContainer->clear(); adaptLayout(); } else { mWidgetContainer->clear(); setSelectedTab(tabIndexToBeSelected); } } int TabbedArea::getNumberOfTabs() const { return mTabs.size(); } bool TabbedArea::isTabSelected(unsigned int index) const { if (index >= mTabs.size()) { throw FCN_EXCEPTION("No such tab index."); } return mSelectedTab == mTabs[index].first; } bool TabbedArea::isTabSelected(Tab* tab) const { return mSelectedTab == tab; } void TabbedArea::setSelectedTab(unsigned int index) { if (index >= mTabs.size()) { throw FCN_EXCEPTION("No such tab index."); } setSelectedTab(mTabs[index].first); } void TabbedArea::setSelectedTab(Tab* tab) { if (tab == mSelectedTab) { return; } unsigned int i; for (i = 0; i < mTabs.size(); i++) { if (mTabs[i].first == mSelectedTab) { mWidgetContainer->remove(mTabs[i].second); } } for (i = 0; i < mTabs.size(); i++) { if (mTabs[i].first == tab) { mSelectedTab = tab; mWidgetContainer->add(mTabs[i].second); } } adaptLayout(); } int TabbedArea::getSelectedTabIndex() const { unsigned int i; for (i = 0; i < mTabs.size(); i++) { if (mTabs[i].first == mSelectedTab) { return i; } } return -1; } Tab* TabbedArea::getSelectedTab() const { return mSelectedTab; } void TabbedArea::setOpaque(bool opaque) { mOpaque = opaque; } bool TabbedArea::isOpaque() const { return mOpaque; } void TabbedArea::setBackgroundWidget(Widget* widget) { mTabContainer->setBackgroundWidget(widget); mWidgetContainer->setBackgroundWidget(widget); } Widget* TabbedArea::getBackgroundWidget() { return mTabContainer->getBackgroundWidget(); } void TabbedArea::draw(Graphics *graphics) { const Color &faceColor = getBaseColor(); const int alpha = getBaseColor().a; Color highlightColor = faceColor + 0x303030; highlightColor.a = alpha; Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; // Draw a border. graphics->setColor(highlightColor); graphics->drawLine(0, mTabContainer->getHeight(), 0, getHeight() - 2); graphics->setColor(shadowColor); graphics->drawLine(getWidth() - 1, mTabContainer->getHeight() + 1, getWidth() - 1, getHeight() - 1); graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1); if (isOpaque()) { graphics->setColor(getBaseColor()); graphics->fillRectangle(1, 1, getWidth() - 2, getHeight() - 2); } // Draw a line underneath the tabs. graphics->setColor(highlightColor); graphics->drawLine(1, mTabContainer->getHeight(), getWidth() - 1, mTabContainer->getHeight()); // If a tab is selected, remove the line right underneath // the selected tab. if (mSelectedTab != NULL) { graphics->setColor(getBaseColor()); graphics->drawLine(mSelectedTab->getX() + 1, mTabContainer->getHeight(), mSelectedTab->getX() + mSelectedTab->getWidth() - 2, mTabContainer->getHeight()); } //drawChildren(graphics); } Rectangle TabbedArea::getChildrenArea() { Rectangle rec; rec.x = getBorderSize() + getPaddingLeft(); rec.y = getBorderSize() + getPaddingTop(); rec.width = getWidth() - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight(); rec.height = getHeight() - 2 * getBorderSize() - getPaddingTop() - getPaddingBottom(); return rec; } void TabbedArea::resizeToContent(bool recursiv) { if (recursiv) { mTabContainer->resizeToContent(recursiv); mWidgetContainer->resizeToContent(recursiv); } resizeToChildren(); adjustSize(); adjustTabPositions(); } void TabbedArea::expandContent(bool recursiv) { if (recursiv) { mTabContainer->expandContent(recursiv); mWidgetContainer->expandContent(recursiv); } adjustSize(); adjustTabPositions(); } void TabbedArea::adjustSize() { int totalTabWidth = 0; int totalTabHeight = 0; int maxTabWidth = 0; int maxTabHeight = 0; Rectangle area = getChildrenArea(); for (unsigned int i = 0; i < mTabs.size(); i++) { totalTabWidth += mTabs[i].first->getWidth(); totalTabHeight += mTabs[i].first->getHeight(); if (mTabs[i].first->getWidth() > maxTabWidth) { maxTabWidth = mTabs[i].first->getWidth(); } if (mTabs[i].first->getHeight() > maxTabHeight) { maxTabHeight = mTabs[i].first->getHeight(); } } if (getLayout() == Container::Vertical) { mTabContainer->setSize(maxTabWidth, getHeight() - 2); mWidgetContainer->setSize(getWidth() - maxTabWidth - 2, getHeight() - 2); mWidgetContainer->setPosition(maxTabWidth + 1, 1); } else if (getLayout() == Container::Horizontal) { mTabContainer->setSize(getWidth() - 2, maxTabHeight); mWidgetContainer->setSize(getWidth() - 2, getHeight() - maxTabHeight - 2); mWidgetContainer->setPosition(1, maxTabHeight + 1); } } void TabbedArea::adjustTabPositions() { int maxTabWidth = 0; int maxTabHeight = 0; unsigned int i; for (i = 0; i < mTabs.size(); i++) { if (mTabs[i].first->getWidth() > maxTabWidth) { maxTabWidth = mTabs[i].first->getWidth(); } if (mTabs[i].first->getHeight() > maxTabHeight) { maxTabHeight = mTabs[i].first->getHeight(); } } if (getLayout() == Container::Vertical) { int y = 0; for (i = 0; i < mTabs.size(); i++) { Tab* tab = mTabs[i].first; tab->setPosition(maxTabWidth - tab->getWidth(), y); y += tab->getHeight(); } } else if (getLayout() == Container::Horizontal) { int x = 0; for (i = 0; i < mTabs.size(); i++) { Tab* tab = mTabs[i].first; tab->setPosition(x, maxTabHeight - tab->getHeight()); x += tab->getWidth(); } } } void TabbedArea::setWidth(int width) { // This may seem odd, but we want the TabbedArea to adjust // it's size properly before we call Widget::setWidth as // Widget::setWidth might distribute a resize event. fcn::Rectangle dim = mDimension; mDimension.width = width; adjustSize(); mDimension = dim; Widget::setWidth(width); } void TabbedArea::setHeight(int height) { // This may seem odd, but we want the TabbedArea to adjust // it's size properly before we call Widget::setHeight as // Widget::setHeight might distribute a resize event. fcn::Rectangle dim = mDimension; mDimension.height = height; adjustSize(); mDimension = dim; Widget::setHeight(height); } void TabbedArea::setSize(int width, int height) { // This may seem odd, but we want the TabbedArea to adjust // it's size properly before we call Widget::setSize as // Widget::setSize might distribute a resize event. fcn::Rectangle dim = mDimension; mDimension.width = width; mDimension.height = height; adjustSize(); mDimension = dim; Widget::setSize(width, height); } void TabbedArea::setDimension(const Rectangle& dimension) { // This may seem odd, but we want the TabbedArea to adjust // it's size properly before we call Widget::setDimension as // Widget::setDimension might distribute a resize event. fcn::Rectangle dim = mDimension; mDimension = dimension; adjustSize(); mDimension = dim; Widget::setDimension(dimension); } void TabbedArea::keyPressed(KeyEvent& keyEvent) { if (keyEvent.isConsumed() || !isFocused()) { return; } if (keyEvent.getKey().getValue() == Key::Left) { int index = getSelectedTabIndex(); index--; if (index < 0) { return; } else { setSelectedTab(mTabs[index].first); } keyEvent.consume(); } else if (keyEvent.getKey().getValue() == Key::Right) { int index = getSelectedTabIndex(); index++; if (index >= (int)mTabs.size()) { return; } else { setSelectedTab(mTabs[index].first); } keyEvent.consume(); } } void TabbedArea::mousePressed(MouseEvent& mouseEvent) { // we ignore that, otherwise the tab can not be pressed // because the content consumed the event //if (mouseEvent.isConsumed()) //{ // return; //} if (mouseEvent.getButton() == MouseEvent::Left) { Widget* widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY()); Tab* tab = dynamic_cast(widget); if (tab != NULL) { setSelectedTab(tab); } } // Request focus only if the source of the event // is not focusble. If the source of the event // is focused we don't want to steal the focus. if (!mouseEvent.getSource()->isFocusable()) { requestFocus(); } } void TabbedArea::death(const Event& event) { Tab* tab = dynamic_cast(event.getSource()); if (tab != NULL) { removeTab(tab); } else { //BasicContainer::death(event); } } void TabbedArea::action(const ActionEvent& actionEvent) { Widget* source = actionEvent.getSource(); Tab* tab = dynamic_cast(source); if (tab == NULL) { throw FCN_EXCEPTION("Received an action from a widget that's not a tab!"); } setSelectedTab(tab); } void TabbedArea::setBaseColor(const Color& color) { Widget::setBaseColor(color); mWidgetContainer->setBaseColor(color); mTabContainer->setBaseColor(color); } void TabbedArea::setLayout(Container::LayoutPolicy policy) { mTabContainer->setLayout(policy); } Container::LayoutPolicy TabbedArea::getLayout() const { return mTabContainer->getLayout(); } void TabbedArea::setUniformSize(bool uniform) { mTabContainer->setUniformSize(uniform); } bool TabbedArea::isUniformSize() const { return mTabContainer->isUniformSize(); } void TabbedArea::setVerticalSpacing(unsigned int spacing) { mTabContainer->setVerticalSpacing(spacing); } unsigned int TabbedArea::getVerticalSpacing() const { return mTabContainer->getVerticalSpacing(); } void TabbedArea::setHorizontalSpacing(unsigned int spacing) { mTabContainer->setHorizontalSpacing(spacing); } unsigned int TabbedArea::getHorizontalSpacing() const { return mTabContainer->getHorizontalSpacing(); } } fifechan-0.1.5/src/widgets/textbox.cpp000066400000000000000000000347071341577075500177470ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include #include #include #include #include #include #include #include #include namespace fcn { TextBox::TextBox(const std::string& text) :mEditable(true), mOpaque(true) { mText = new Text(text); setFocusable(true); addMouseListener(this); addKeyListener(this); adjustSize(); mStringEditor = new UTF8StringEditor; } TextBox::~TextBox() { delete mText; delete mStringEditor; } void TextBox::setText(const std::string& text) { mText->setContent(text); adjustSize(); } void TextBox::draw(Graphics* graphics) { if (mOpaque) { graphics->setColor(getBackgroundColor()); graphics->fillRectangle(0, 0, getWidth(), getHeight()); } if (isFocused() && isEditable()) { drawCaret(graphics, mText->getCaretX(getFont()), mText->getCaretY(getFont())); } graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); unsigned int i; for (i = 0; i < mText->getNumberOfRows(); i++) { // Move the text one pixel so we can have a caret before a letter. graphics->drawText(mText->getRow(i), 1, i * getFont()->getHeight()); } } void TextBox::drawCaret(Graphics* graphics, int x, int y) { graphics->setColor(getForegroundColor()); graphics->drawLine(x, y, x, y + getFont()->getHeight()); } void TextBox::mousePressed(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == MouseEvent::Left) { mText->setCaretPosition(mouseEvent.getX(), mouseEvent.getY(), getFont()); mouseEvent.consume(); } } void TextBox::mouseDragged(MouseEvent& mouseEvent) { mouseEvent.consume(); } void TextBox::keyPressed(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if (key.getValue() == Key::Left) { if (getCaretColumn() == 0) { if (getCaretRow() > 0) { setCaretRow(getCaretRow()-1); setCaretColumn(getTextRow(getCaretRow()).size()); } } else { setCaretColumn(mStringEditor->prevChar(getTextRow(getCaretRow()), getCaretColumn())); } } else if (key.getValue() == Key::Right) { if (getCaretColumn() < getTextRow(getCaretRow()).size()) { setCaretColumn(mStringEditor->nextChar(getTextRow(getCaretRow()), getCaretColumn())); } else { if (getCaretRow() < getNumberOfRows() - 1) { setCaretRow(getCaretRow()+1); setCaretColumn(0); } } } else if (key.getValue() == Key::Down) { setCaretRowUTF8(getCaretRow() + 1); } else if (key.getValue() == Key::Up) { setCaretRowUTF8(getCaretRow() - 1); } else if (key.getValue() == Key::Home) { setCaretColumn(0); } else if (key.getValue() == Key::End) { setCaretColumn(getTextRow(getCaretRow()).size()); } else if (key.getValue() == Key::Enter && mEditable) { mText->insertRow(getTextRow(getCaretRow()).substr(getCaretColumn(), getTextRow(getCaretRow()).size() - getCaretColumn()) ,getCaretRow() + 1); mText->getRow(getCaretRow()).resize(getCaretColumn()); setCaretRow(getCaretRow() + 1); setCaretColumn(0); } else if (key.getValue() == Key::Backspace && getCaretColumn() != 0 && mEditable) { std::string& currRow = mText->getRow(getCaretRow()); setCaretColumn(mStringEditor->prevChar(currRow, static_cast(getCaretColumn()))); setCaretColumn(mStringEditor->eraseChar(currRow, static_cast(getCaretColumn()))); } else if (key.getValue() == Key::Backspace && getCaretColumn() == 0 && getCaretRow() != 0 && mEditable) { /*setCaretColumn(mText->getRow(getCaretRow() - 1).size()); mText->getRow(getCaretRow() - 1) += getTextRow(getCaretRow()); mText->eraseRow(getCaretRow()); setCaretRow(getCaretRow() - 1);*/ unsigned newCaretColumn = getTextRow(getCaretRow() - 1).size(); //setCaretColumn(getTextRow(getCaretRow() - 1).size()); mText->getRow(getCaretRow() - 1) += getTextRow(getCaretRow()); mText->eraseRow(getCaretRow()); setCaretRow(getCaretRow() - 1); setCaretColumn(newCaretColumn); } else if (key.getValue() == Key::Delete && getCaretColumn() < (int)getTextRow(getCaretRow()).size() && mEditable) { setCaretColumn(mStringEditor->eraseChar(mText->getRow(getCaretRow()), getCaretColumn())); } else if (key.getValue() == Key::Delete && getCaretColumn() == (int)getTextRow(getCaretRow()).size() && getCaretRow() < ((int)getNumberOfRows() - 1) && mEditable) { mText->getRow(getCaretRow()) += getTextRow((getCaretRow() + 1)); mText->eraseRow(getCaretRow() + 1); } else if(key.getValue() == Key::PageUp) { Widget* par = getParent(); if (par != NULL) { int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); int chars = mStringEditor->countChars(getTextRow(getCaretRow()), getCaretColumn()); int newCaretRow = getCaretRow() - rowsPerPage; if (newCaretRow >= 0) { setCaretRow(newCaretRow); } else { setCaretRow(0); } setCaretColumn(mStringEditor->getOffset(getTextRow(getCaretRow()), chars)); } } else if(key.getValue() == Key::PageDown) { Widget* par = getParent(); if (par != NULL) { int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); int chars = mStringEditor->countChars(getTextRow(getCaretRow()), getCaretColumn()); setCaretRow(getCaretRow() + rowsPerPage); if (getCaretRow() >= (int)getNumberOfRows()) { setCaretRow(getNumberOfRows() - 1); } setCaretColumn(mStringEditor->getOffset(getTextRow(getCaretRow()), chars)); } } else if(key.getValue() == Key::Tab && mEditable) { // FIXME: jump X spaces, so getCaretColumn() % TAB_SIZE = 0 and X <= TAB_SIZE mText->getRow(getCaretRow()).insert(getCaretColumn(),std::string(" ")); setCaretColumn(getCaretColumn() + 4); } else if ((key.isCharacter() || key.getValue() > 255) && mEditable) { setCaretColumn(mStringEditor->insertChar(mText->getRow(getCaretRow()), getCaretColumn(), key.getValue())); } adjustSize(); scrollToCaret(); assert(utf8::is_valid(getTextRow(getCaretRow()).begin(),getTextRow(getCaretRow()).end()) == utf8::internal::UTF8_OK); assert(utf8::is_valid(getTextRow(getCaretRow()).begin(),getTextRow(getCaretRow()).begin() + getCaretColumn()) == utf8::internal::UTF8_OK); keyEvent.consume(); } void TextBox::resizeToContent(bool recursiv) { adjustSize(); } void TextBox::adjustSize() { const Rectangle& dim = mText->getDimension(getFont()); setSize(dim.width, dim.height); } void TextBox::setCaretPosition(unsigned int position) { mText->setCaretPosition(position); } unsigned int TextBox::getCaretPosition() const { return mText->getCaretPosition(); } void TextBox::setCaretRowColumn(int row, int column) { mText->setCaretRow(row); mText->setCaretColumn(column); } void TextBox::setCaretRow(int row) { mText->setCaretRow(row); } unsigned int TextBox::getCaretRow() const { return mText->getCaretRow(); } void TextBox::setCaretColumn(int column) { mText->setCaretColumn(column); } unsigned int TextBox::getCaretColumn() const { return mText->getCaretColumn(); } std::string TextBox::getTextRow(int row) const { return mText->getRow(row); } void TextBox::setTextRow(int row, const std::string& text) { mText->setRow(row, text); adjustSize(); } unsigned int TextBox::getNumberOfRows() const { return mText->getNumberOfRows(); } std::string TextBox::getText() const { return mText->getContent(); } void TextBox::fontChanged() { adjustSize(); } void TextBox::scrollToCaret() { showPart(mText->getCaretDimension(getFont())); } void TextBox::setEditable(bool editable) { mEditable = editable; } bool TextBox::isEditable() const { return mEditable; } void TextBox::addRow(const std::string &row) { mText->addRow(row); adjustSize(); } bool TextBox::isOpaque() { return mOpaque; } void TextBox::setOpaque(bool opaque) { mOpaque = opaque; } void TextBox::setCaretColumnUTF8(int column) { // no need to clip the column, mStringEditor handles it automaticly setCaretColumn(mStringEditor->getOffset(getTextRow(getCaretRow()), column)); } void TextBox::setCaretRowUTF8(int row) { int chars = mStringEditor->countChars(getTextRow(getCaretRow()), getCaretColumn()); if (row < 0) { row = 0; } else if (row >= getNumberOfRows()) { row = getNumberOfRows() - 1; } setCaretRow(row); setCaretColumn(mStringEditor->getOffset(getTextRow(getCaretRow()), chars)); } void TextBox::setCaretRowColumnUTF8(int row, int column) { setCaretRowUTF8(row); setCaretColumnUTF8(column); } } fifechan-0.1.5/src/widgets/textfield.cpp000066400000000000000000000252331341577075500202340ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widgets/textfield.hpp" #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" #include "fifechan/key.hpp" #include "fifechan/mouseinput.hpp" #include "fifechan/text.hpp" #include "fifechan/utf8stringeditor.hpp" namespace fcn { TextField::TextField(): mEditable(true), mXScroll(0) { mText = new Text(); mText->addRow(""); setFocusable(true); addMouseListener(this); addKeyListener(this); mStringEditor = new UTF8StringEditor; } TextField::TextField(const std::string& text): mEditable(true), mXScroll(0) { mText = new Text(text); adjustSize(); setFocusable(true); addMouseListener(this); addKeyListener(this); mStringEditor = new UTF8StringEditor; } TextField::~TextField() { delete mText; delete mStringEditor; } void TextField::setText(const std::string& text) { mText->setContent(text); } void TextField::draw(Graphics* graphics) { Color faceColor = getBaseColor(); Color highlightColor, shadowColor; int alpha = getBaseColor().a; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; // Draw a border. graphics->setColor(shadowColor); graphics->drawLine(0, 0, getWidth() - 1, 0); graphics->drawLine(0, 1, 0, getHeight() - 2); graphics->setColor(highlightColor); graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1); graphics->drawLine(0, getHeight() - 1, getWidth() - 1, getHeight() - 1); // Push a clip area so the other drawings don't need to worry // about the border. graphics->pushClipArea(Rectangle(1, 1, getWidth() - 2, getHeight() - 2)); graphics->setColor(getBackgroundColor()); graphics->fillRectangle(0, 0, getWidth(), getHeight()); if (isFocused()) { graphics->setColor(getSelectionColor()); graphics->drawRectangle(0, 0, getWidth() - 2, getHeight() - 2); graphics->drawRectangle(1, 1, getWidth() - 4, getHeight() - 4); } if (isFocused() && isEditable()) { drawCaret(graphics, mText->getCaretX(getFont()) - mXScroll); } graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); const Rectangle& dim = mText->getCaretDimension(getFont()); if (mText->getNumberOfRows() != 0) graphics->drawText(mText->getRow(0), 1 - mXScroll, 1); graphics->popClipArea(); } void TextField::drawCaret(Graphics* graphics, int x) { // Check the current clip area as a clip area with a different // size than the widget might have been pushed (which is the // case in the draw method when we push a clip area after we have // drawn a border). const Rectangle clipArea = graphics->getCurrentClipArea(); graphics->setColor(getForegroundColor()); graphics->drawLine(x, clipArea.height - 2, x, 1); } void TextField::mousePressed(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == MouseEvent::Left) { mText->setCaretPosition(mouseEvent.getX() + mXScroll, mouseEvent.getY(), getFont()); fixScroll(); } } void TextField::mouseDragged(MouseEvent& mouseEvent) { mouseEvent.consume(); } void TextField::keyPressed(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if (key.getValue() == Key::Left && getCaretPosition() > 0) { setCaretPosition(mStringEditor->prevChar(getText(), static_cast(getCaretPosition()))); } else if (key.getValue() == Key::Right && getCaretPosition() < getText().size()) { setCaretPosition(mStringEditor->nextChar(getText(), static_cast(getCaretPosition()))); } else if (key.getValue() == Key::Delete && getCaretPosition() < getText().size() && mText->getNumberOfRows() > 0) { setCaretPosition(mStringEditor->eraseChar(mText->getRow(0), static_cast(getCaretPosition()))); } else if (key.getValue() == Key::Backspace && getCaretPosition() > 0 && mText->getNumberOfRows() > 0) { setCaretPosition(mStringEditor->prevChar(mText->getRow(0), static_cast(getCaretPosition()))); setCaretPosition(mStringEditor->eraseChar(mText->getRow(0), static_cast(getCaretPosition()))); } else if (key.getValue() == Key::Enter) { distributeActionEvent(); } else if (key.getValue() == Key::Home) { setCaretPosition(0); } else if (key.getValue() == Key::End) { setCaretPosition(getText().size()); } // Add character to text, if key is really an ASCII character // or is greater than 8bits long and the character is not // the tab key. else if ((key.isCharacter() || (key.getValue() > 255 && mText->getNumberOfRows() > 0)) && key.getValue() != Key::Tab) { setCaretPosition(mStringEditor->insertChar(mText->getRow(0), getCaretPosition(), key.getValue())); } if (key.getValue() != Key::Tab) { // consume all characters except TAB which is needed // for traversing through widgets in a container. keyEvent.consume(); } fixScroll(); } void TextField::resizeToContent(bool recursiv) { adjustSize(); } void TextField::adjustSize() { const Rectangle& dim = mText->getDimension(getFont()); setWidth(dim.width + 8); adjustHeight(); fixScroll(); } void TextField::adjustHeight() { setHeight(getFont()->getHeight() + 4); } void TextField::fixScroll() { if (isFocused()) { int caretX = mText->getCaretDimension(getFont()).x; if (caretX - mXScroll >= getWidth() - 4) { mXScroll = caretX - getWidth() + 4; } else if (caretX - mXScroll <= 0) { mXScroll = caretX - getWidth() / 2; if (mXScroll < 0) { mXScroll = 0; } } } } void TextField::setCaretPosition(unsigned int position) { mText->setCaretPosition(position); } unsigned int TextField::getCaretPosition() const { return mText->getCaretPosition(); } std::string TextField::getText() const { return mText->getContent(); } bool TextField::isEditable() const { return mEditable; } void TextField::setEditable(bool editable) { mEditable = editable; } } fifechan-0.1.5/src/widgets/togglebutton.cpp000066400000000000000000000146221341577075500207610ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2012 by the fifechan team * * http://fifechan.github.com/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include "fifechan/widgets/togglebutton.hpp" namespace fcn { ToggleButton::GroupMap ToggleButton::mGroupMap; ToggleButton::ToggleButton() { setSelected(false); adjustSize(); } ToggleButton::ToggleButton(const std::string &caption, const std::string &group, bool selected) { setCaption(caption); setGroup(group); setSelected(selected); adjustSize(); } ToggleButton::~ToggleButton() { // Remove us from the group list setGroup(""); } bool ToggleButton::isSelected() const { return mSelected; } void ToggleButton::setSelected(bool selected) { if (selected && mGroup != "") { // deselect all buttons in group GroupIterator iter, iterEnd; iterEnd = mGroupMap.upper_bound(mGroup); for (iter = mGroupMap.lower_bound(mGroup); iter != iterEnd; ++iter) { if (iter->second->isSelected()) { iter->second->setSelected(false); } } } mSelected = selected; } void ToggleButton::toggleSelected() { setSelected(!isSelected()); distributeActionEvent(); } void ToggleButton::setGroup(const std::string& group) { // Remove button from previous group if (mGroup != "") { GroupIterator iter, iterEnd; iterEnd = mGroupMap.upper_bound(mGroup); for (iter = mGroupMap.lower_bound(mGroup); iter != iterEnd; ++iter) { if (iter->second == this) { mGroupMap.erase(iter); break; } } } // Add button to new group if (group != "") { mGroupMap.insert(std::pair(group, this)); } mGroup = group; } const std::string& ToggleButton::getGroup() const { return mGroup; } bool ToggleButton::isPressed() const { return isSelected(); } void ToggleButton::keyReleased(KeyEvent& keyEvent) { Key key = keyEvent.getKey(); if ((key.getValue() == Key::Enter || key.getValue() == Key::Space) && mKeyPressed) { mKeyPressed = false; toggleSelected(); keyEvent.consume(); } } void ToggleButton::mouseReleased(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == MouseEvent::Left && mMousePressed && mHasMouse) { mMousePressed = false; toggleSelected(); mouseEvent.consume(); } else if (mouseEvent.getButton() == MouseEvent::Left) { mMousePressed = false; mouseEvent.consume(); } } } fifechan-0.1.5/src/widgets/window.cpp000066400000000000000000000252111341577075500175470ustar00rootroot00000000000000/*************************************************************************** * Copyright (c) 2017-2019 by the fifechan team * * https://github.com/fifengine/fifechan * * This file is part of fifechan. * * * * fifechan is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ /* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson * * * Per Larsson a.k.a finalman * Olof Naessn a.k.a jansem/yakslem * * Visit: http://guichan.sourceforge.net * * License: (BSD) * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of Guichan nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * For comments regarding functions please see the header file. */ #include #include "fifechan/widgets/window.hpp" #include "fifechan/exception.hpp" #include "fifechan/font.hpp" #include "fifechan/graphics.hpp" #include "fifechan/mouseinput.hpp" namespace fcn { Window::Window() :mMoved(false) { setBorderSize(1); setInnerBorderSize(1); setPadding(2); setTitleBarHeight(16); setAlignment(Graphics::Center); addMouseListener(this); setMovable(true); setOpaque(true); } Window::Window(const std::string& caption) :mMoved(false) { setCaption(caption); setBorderSize(1); setInnerBorderSize(1); setPadding(2); setTitleBarHeight(16); setAlignment(Graphics::Center); addMouseListener(this); setMovable(true); setOpaque(true); } Window::~Window() { } void Window::setTitleBarHeight(unsigned int height) { mTitleBarHeight = height; } unsigned int Window::getTitleBarHeight() const { return mTitleBarHeight; } void Window::setInnerBorderSize(unsigned int border) { mInnerBorder = border; } unsigned int Window::getInnerBorderSize() const { return mInnerBorder; } void Window::setCaption(const std::string& caption) { mCaption = caption; } const std::string& Window::getCaption() const { return mCaption; } void Window::setAlignment(Graphics::Alignment alignment) { mAlignment = alignment; } Graphics::Alignment Window::getAlignment() const { return mAlignment; } void Window::drawInnerBorder(Graphics* graphics) { const Color &faceColor = getBaseColor(); Color highlightColor, shadowColor; const int alpha = getBaseColor().a; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; int x = getBorderSize() + getPaddingLeft(); int y = getBorderSize() + getPaddingTop() + getTitleBarHeight(); int width = getWidth() - getBorderSize() - getPaddingRight() - 1; int height = getHeight() - getBorderSize() - getPaddingBottom() - 1; unsigned int i; for (i = 0; i < getInnerBorderSize(); ++i) { graphics->setColor(shadowColor); graphics->drawLine(x+i, y+i, width-i, y+i); graphics->drawLine(x+i, y+i+1, x+i, height-i-1); graphics->setColor(highlightColor); graphics->drawLine(width-i, y+i+1, width-i, height-i); graphics->drawLine(x+i, height-i, width-i-1, height-i); } } void Window::draw(Graphics* graphics) { const Color &faceColor = getBaseColor(); Color highlightColor, shadowColor; const int alpha = getBaseColor().a; highlightColor = faceColor + 0x303030; highlightColor.a = alpha; shadowColor = faceColor - 0x303030; shadowColor.a = alpha; if (isOpaque()) { // Fill the background around the content graphics->setColor(faceColor); graphics->fillRectangle(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); } if (mBackgroundWidget) { Rectangle rec(getBorderSize(), getBorderSize(), getWidth() - 2 * getBorderSize(), getHeight() - 2 * getBorderSize()); mBackgroundWidget->setDimension(rec); mBackgroundWidget->_draw(graphics); } if (getBorderSize() > 0) { drawBorder(graphics); } // draw inner/content border if (getInnerBorderSize() > 0) { drawInnerBorder(graphics); } // draw text int textX; int textY = ((int)getTitleBarHeight() - getFont()->getHeight()) / 2; switch (getAlignment()) { case Graphics::Left: textX = 0; break; case Graphics::Center: textX = (getWidth() - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight()) / 2; break; case Graphics::Right: textX = getWidth() - getBorderSize() - getPaddingRight(); break; default: throw FCN_EXCEPTION("Unknown alignment."); } // text clip area Rectangle rec(getBorderSize() + getPaddingLeft(), getBorderSize() + getPaddingTop(), getWidth() - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight(), getTitleBarHeight() - 1); graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); graphics->pushClipArea(rec); graphics->drawText(getCaption(), textX, textY, getAlignment()); graphics->popClipArea(); } void Window::mousePressed(MouseEvent& mouseEvent) { if (mouseEvent.getSource() != this) { return; } if (getParent() != NULL) { getParent()->moveToTop(this); } mDragOffsetX = mouseEvent.getX(); mDragOffsetY = mouseEvent.getY(); int height = getBorderSize() + getPaddingTop() + getTitleBarHeight(); mMoved = mouseEvent.getY() <= height; } void Window::mouseReleased(MouseEvent& mouseEvent) { mMoved = false; } void Window::mouseDragged(MouseEvent& mouseEvent) { if (mouseEvent.isConsumed() || mouseEvent.getSource() != this) { return; } if (isMovable() && mMoved) { setPosition(mouseEvent.getX() - mDragOffsetX + getX(), mouseEvent.getY() - mDragOffsetY + getY()); } mouseEvent.consume(); } void Window::adjustSize() { resizeToChildren(); int w = std::max(getFont()->getWidth(mCaption), getWidth()) + 2 * getBorderSize() + getPaddingLeft() + getPaddingRight() + 2 * getInnerBorderSize(); int h = getHeight() + 2 * getBorderSize() + getPaddingTop() + getPaddingBottom() + 2 * getInnerBorderSize() + getTitleBarHeight(); setSize(w, h); } Rectangle Window::getChildrenArea() { Rectangle rec; rec.x = getBorderSize() + getPaddingLeft() + getInnerBorderSize(); rec.y = getBorderSize() + getPaddingTop() + getInnerBorderSize() + getTitleBarHeight(); rec.width = getWidth() - 2 * getBorderSize() - getPaddingLeft() - getPaddingRight() - 2*getInnerBorderSize(); rec.height = getHeight() - 2 * getBorderSize() - getPaddingTop() - getPaddingBottom() - 2*getInnerBorderSize() - getTitleBarHeight(); return rec; } void Window::setMovable(bool movable) { mMovable = movable; } bool Window::isMovable() const { return mMovable; } void Window::setOpaque(bool opaque) { mOpaque = opaque; } bool Window::isOpaque() const { return mOpaque; } }