├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake ├── Config.cmake ├── Macros.cmake ├── Modules │ ├── FindSFML.cmake │ └── FindSFML_UI.cmake └── toolchains │ └── android.toolchain.cmake ├── doc ├── CMakeLists.txt ├── doxyfile.in ├── doxygen.css ├── footer.htm ├── header.htm └── mainpage.hpp ├── examples ├── CMakeLists.txt ├── android │ ├── AndroidManifest.xml │ ├── assets │ │ ├── button.png │ │ ├── button_fired.png │ │ ├── button_focused.png │ │ ├── checkbox.png │ │ ├── checkbox_selected.png │ │ ├── hello_world.png │ │ └── sansation.ttf │ ├── jni │ │ ├── Android.mk │ │ ├── Application.mk │ │ └── src │ │ │ └── Main.cpp │ ├── project.properties │ └── res │ │ ├── drawable-hdpi │ │ └── sfml_logo.png │ │ ├── drawable-ldpi │ │ └── sfml_logo.png │ │ ├── drawable-mdpi │ │ └── sfml_logo.png │ │ ├── drawable-xhdpi │ │ └── sfml_logo.png │ │ ├── drawable-xxhdpi │ │ └── sfml_logo.png │ │ ├── values-v11 │ │ └── styles.xml │ │ ├── values-v14 │ │ └── styles.xml │ │ └── values │ │ ├── strings.xml │ │ └── styles.xml └── ui │ ├── CMakeLists.txt │ ├── Listener.cpp │ ├── Listener.hpp │ ├── Main.cpp │ └── resources │ ├── FreeSans.ttf │ ├── button.png │ ├── button_fired.png │ ├── button_focused.png │ ├── checkbox.png │ ├── checkbox_selected.png │ └── hello_world.png ├── include └── SFML │ ├── UI.hpp │ └── UI │ ├── AbstractButton.hpp │ ├── Button.hpp │ ├── CheckBox.hpp │ ├── CheckBoxGroup.hpp │ ├── Component.hpp │ ├── ComponentEvent.hpp │ ├── ComponentObservable.hpp │ ├── ComponentObserver.hpp │ ├── Focusable.hpp │ ├── Format │ ├── DoubleFormat.hpp │ ├── Format.hpp │ ├── LongFormat.hpp │ └── UnsignedLongFormat.hpp │ ├── FormattedTextField.hpp │ ├── IText.hpp │ ├── KeyField.hpp │ ├── Label.hpp │ ├── Model │ ├── AlphaNumericTextFieldModel.hpp │ ├── AlphaTextFieldModel.hpp │ ├── AsciiNoSpaceTextFieldModel.hpp │ ├── AsciiTextFieldModel.hpp │ ├── BlacklistTextFieldModel.hpp │ ├── DefaultTextFieldModel.hpp │ ├── NumericTextFieldModel.hpp │ ├── TextFieldModel.hpp │ └── WhitelistTextFieldModel.hpp │ ├── PasswordField.hpp │ ├── SFMLUtils.hpp │ └── TextField.hpp ├── src └── SFML │ ├── Android.mk │ ├── CMakeLists.txt │ └── UI │ ├── AbstractButton.cpp │ ├── Button.cpp │ ├── CMakeLists.txt │ ├── CheckBox.cpp │ ├── CheckBoxGroup.cpp │ ├── Component.cpp │ ├── ComponentObservable.cpp │ ├── ComponentObserver.cpp │ ├── Focusable.cpp │ ├── Format │ ├── DoubleFormat.cpp │ ├── Format.cpp │ ├── LongFormat.cpp │ └── UnsignedLongFormat.cpp │ ├── FormattedTextField.cpp │ ├── IText.cpp │ ├── KeyField.cpp │ ├── Label.cpp │ ├── Model │ ├── AlphaNumericTextFieldModel.cpp │ ├── AlphaTextFieldModel.cpp │ ├── AsciiNoSpaceTextFieldModel.cpp │ ├── AsciiTextFieldModel.cpp │ ├── BlacklistTextFieldModel.cpp │ ├── DefaultTextFieldModel.cpp │ ├── NumericTextFieldModel.cpp │ ├── TextFieldModel.cpp │ └── WhitelistTextFieldModel.cpp │ ├── PasswordField.cpp │ ├── SFMLUtils.cpp │ └── TextField.cpp └── tools └── pkg-config └── sfml-ui.pc.in /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | #Binaries folder 16 | Debug 17 | Release 18 | bin 19 | build 20 | build-static 21 | 22 | #Eclipse files 23 | .project 24 | .cproject 25 | .settings 26 | 27 | #IDE Files generated 28 | Eclipse 29 | CodeBlocks 30 | 31 | #Temporary files 32 | *~ 33 | 34 | #Vim files 35 | *.swp 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | sfml-ui 2 | ======= 3 | 4 | A simple UI library for SFML (2.2 at least). Works on GNU/Linux, Windows, Android. Currently not tested on Mac OS X and iOS. 5 | 6 | Website (including documentation) : [patatedev.github.io/sfml-ui](http://patatedev.github.io/sfml-ui) 7 | 8 | How to compile 9 | -------------- 10 | _Make sure you have already compiled SFML and CMake is installed_ 11 | 12 | ### Desktop OS (Win/Mac/Linux) ### 13 | If you use a graphical version of CMake : 14 | 15 | 1. Open CMake 16 | 2. If SFML is not found, add a SFML_ROOT setting and set it to the folder where SFML is installed 17 | 4. Click on the button configure and choose your generator 18 | 5. Set up the different settings (i.e change the path to your SFML libraries) 19 | 6. Click on generate button 20 | 7. If you choose 'Makefiles' as generator, open a terminal in your folder and type your system's make command, if you choose your IDE as generator, then open your IDE in your folder 21 | 22 | Else, enter these command in your terminal (Unix family OS) : 23 | 24 | + `mkdir build && cd build` 25 | + `cmake .. -G "Unix Makefiles"` replace "Unix Makefiles" by your makefile generator 26 | + `make` 27 | 28 | Don't forget to have set SFML_ROOT setting if SFML is installed in a custom directory : 29 | 30 | `export SFML_ROOT=` 31 | 32 | And to install : `sudo make install` 33 | 34 | ### Mobile OS - Android ### 35 | Same as desktop os, except you have to specify this custom toolchain : cmake/toolchains/android.toolchain.cmake. 36 | Once it is done, you can customize ANDROID_ABI setting for the target arch, and ANDROID_API for the Android target platform. 37 | -------------------------------------------------------------------------------- /cmake/Config.cmake: -------------------------------------------------------------------------------- 1 | # detect the OS 2 | if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 3 | set(SFML_OS_WINDOWS 1) 4 | 5 | # don't use the OpenGL ES implementation on Windows 6 | set(OPENGL_ES 0) 7 | 8 | # detect the architecture (note: this test won't work for cross-compilation) 9 | include(CheckTypeSize) 10 | check_type_size(void* SIZEOF_VOID_PTR) 11 | if("${SIZEOF_VOID_PTR}" STREQUAL "4") 12 | set(ARCH_32BITS 1) 13 | elseif("${SIZEOF_VOID_PTR}" STREQUAL "8") 14 | set(ARCH_64BITS 1) 15 | else() 16 | message(FATAL_ERROR "Unsupported architecture") 17 | return() 18 | endif() 19 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 20 | set(SFML_OS_UNIX 1) 21 | if(ANDROID) 22 | set(SFML_OS_ANDROID 1) 23 | # use the OpenGL ES implementation on Android 24 | set(OPENGL_ES 1) 25 | else() 26 | set(SFML_OS_LINUX 1) 27 | # don't use the OpenGL ES implementation on Linux 28 | set(OPENGL_ES 0) 29 | endif() 30 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 31 | set(SFML_OS_FREEBSD 1) 32 | # don't use the OpenGL ES implementation on FreeBSD 33 | set(OPENGL_ES 0) 34 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 35 | if(IOS) 36 | set(SFML_OS_IOS 1) 37 | 38 | # set the target framework and platforms 39 | set(CMAKE_OSX_SYSROOT "iphoneos") 40 | set(CMAKE_OSX_ARCHITECTURES "armv6;armv7;i386") 41 | set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator") 42 | 43 | # help the compiler detection script below 44 | set(CMAKE_COMPILER_IS_GNUCXX 1) 45 | 46 | # use the OpenGL ES implementation on iOS 47 | set(OPENGL_ES 1) 48 | else() 49 | set(SFML_OS_MACOSX 1) 50 | 51 | # don't use the OpenGL ES implementation on Mac OS X 52 | set(OPENGL_ES 0) 53 | 54 | # detect OS X version. (use '/usr/bin/sw_vers -productVersion' to extract V from '10.V.x'.) 55 | EXEC_PROGRAM(/usr/bin/sw_vers ARGS -productVersion OUTPUT_VARIABLE MACOSX_VERSION_RAW) 56 | STRING(REGEX REPLACE "10\\.([0-9]+).*" "\\1" MACOSX_VERSION "${MACOSX_VERSION_RAW}") 57 | if(${MACOSX_VERSION} LESS 7) 58 | message(FATAL_ERROR "Unsupported version of OS X: ${MACOSX_VERSION_RAW}") 59 | return() 60 | endif() 61 | endif() 62 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") 63 | set(SFML_OS_ANDROID 1) 64 | 65 | # use the OpenGL ES implementation on Android 66 | set(OPENGL_ES 1) 67 | else() 68 | message(FATAL_ERROR "Unsupported operating system") 69 | return() 70 | endif() 71 | 72 | # detect the compiler and its version 73 | # Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true 74 | # even when CLANG is used, therefore the Clang test is done first 75 | if(CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 76 | # CMAKE_CXX_COMPILER_ID is an internal CMake variable subject to change, 77 | # but there is no other way to detect CLang at the moment 78 | set(SFML_COMPILER_CLANG 1) 79 | execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE CLANG_VERSION_OUTPUT) 80 | string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" SFML_CLANG_VERSION "${CLANG_VERSION_OUTPUT}") 81 | elseif(CMAKE_COMPILER_IS_GNUCXX) 82 | set(SFML_COMPILER_GCC 1) 83 | execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_OUTPUT) 84 | string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" SFML_GCC_VERSION "${GCC_VERSION_OUTPUT}") 85 | execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE GCC_COMPILER_VERSION) 86 | string(REGEX MATCHALL ".*(tdm[64]*-[1-9]).*" SFML_COMPILER_GCC_TDM "${GCC_COMPILER_VERSION}") 87 | execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpmachine" OUTPUT_VARIABLE GCC_MACHINE) 88 | string(STRIP "${GCC_MACHINE}" GCC_MACHINE) 89 | if(${GCC_MACHINE} MATCHES ".*w64.*") 90 | set(SFML_COMPILER_GCC_W64 1) 91 | endif() 92 | elseif(MSVC) 93 | set(SFML_COMPILER_MSVC 1) 94 | if(MSVC_VERSION EQUAL 1400) 95 | set(SFML_MSVC_VERSION 8) 96 | elseif(MSVC_VERSION EQUAL 1500) 97 | set(SFML_MSVC_VERSION 9) 98 | elseif(MSVC_VERSION EQUAL 1600) 99 | set(SFML_MSVC_VERSION 10) 100 | elseif(MSVC_VERSION EQUAL 1700) 101 | set(SFML_MSVC_VERSION 11) 102 | elseif(MSVC_VERSION EQUAL 1800) 103 | set(SFML_MSVC_VERSION 12) 104 | endif() 105 | else() 106 | message(FATAL_ERROR "Unsupported compiler") 107 | return() 108 | endif() 109 | 110 | # define the install directory for miscellaneous files 111 | if(SFML_OS_WINDOWS OR SFML_OS_IOS) 112 | set(INSTALL_MISC_DIR .) 113 | elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX) 114 | set(INSTALL_MISC_DIR share/sfml-ui) 115 | elseif(SFML_OS_ANDROID) 116 | set(INSTALL_MISC_DIR ${ANDROID_NDK}/sources/sfml-ui) 117 | endif() 118 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # find doxygen 3 | if(SFML_OS_MACOSX) 4 | # Add some path to search doxygen in more directories. 5 | set(ADDITIONAL_PATHS 6 | /Developer/Applications/Doxygen.app/Contents/Resources 7 | /Developer/Applications/Doxygen.app/Contents/MacOS 8 | $ENV{HOME}/Applications/Doxygen.app/Contents/Resources 9 | $ENV{HOME}/Applications/Doxygen.app/Contents/MacOS 10 | $ENV{HOME}/Applications/Developer/Doxygen.app/Contents/Resources 11 | $ENV{HOME}/Applications/Developer/Doxygen.app/Contents/MacOS) 12 | 13 | set(CMAKE_PROGRAM_PATH ${CMAKE_PROGRAM_PATH} ${ADDITIONAL_PATHS}) 14 | endif() 15 | 16 | find_package(Doxygen REQUIRED) 17 | 18 | # set the input and output documentation paths 19 | set(DOXYGEN_INPUT_DIR ${PROJECT_SOURCE_DIR}) 20 | set(DOXYGEN_OUTPUT_DIR ${PROJECT_BINARY_DIR}/doc) 21 | 22 | # see if we can generate the CHM documentation 23 | if(SFML_OS_WINDOWS) 24 | # if HHC is found, we can generate the CHM (compressed HTML) output 25 | find_program(DOXYGEN_HHC_PROGRAM 26 | NAMES hhc.exe 27 | PATHS "c:/Program Files/HTML Help Workshop" 28 | DOC "HTML Help Compiler program") 29 | if(DOXYGEN_HHC_PROGRAM) 30 | set(DOXYGEN_GENERATE_HTMLHELP YES) 31 | else() 32 | set(DOXYGEN_GENERATE_HTMLHELP NO) 33 | endif() 34 | else() 35 | set(DOXYGEN_HHC_PROGRAM) 36 | set(DOXYGEN_GENERATE_HTMLHELP NO) 37 | endif() 38 | 39 | # configure the source Doxyfile by copying it and replacing all @variables@ 40 | set(DOXYGEN_CONFIGURED_INPUT ${DOXYGEN_OUTPUT_DIR}/doxyfile) 41 | configure_file(${DOXYGEN_INPUT_DIR}/doc/doxyfile.in ${DOXYGEN_CONFIGURED_INPUT} @ONLY) 42 | 43 | # copy the files needed by the documentation 44 | configure_file(${DOXYGEN_INPUT_DIR}/doc/doxygen.css ${DOXYGEN_OUTPUT_DIR}/html/doxygen.css COPYONLY) 45 | 46 | # target setup 47 | add_custom_target(doc ALL 48 | COMMAND ${CMAKE_COMMAND} -E echo_append "Building API Documentation..." 49 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_CONFIGURED_INPUT} 50 | COMMAND ${CMAKE_COMMAND} -E echo "Done." 51 | WORKING_DIRECTORY ${DOXYGEN_INPUT_DIR}) 52 | 53 | # setup install rules 54 | install(DIRECTORY ${DOXYGEN_OUTPUT_DIR}/html 55 | DESTINATION ${INSTALL_MISC_DIR}/doc 56 | COMPONENT doc) 57 | if(DOXYGEN_HHC_PROGRAM) 58 | install(FILES ${DOXYGEN_OUTPUT_DIR}/sfml.chm 59 | DESTINATION ${INSTALL_MISC_DIR}/doc 60 | COMPONENT doc) 61 | endif() 62 | -------------------------------------------------------------------------------- /doc/footer.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/doc/footer.htm -------------------------------------------------------------------------------- /doc/header.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SFML-UI - User Interface library for SFML 5 | 6 | 7 | 8 | 9 | 10 | 15 |
16 | -------------------------------------------------------------------------------- /doc/mainpage.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////// 2 | /// \mainpage 3 | /// 4 | /// \section welcome Welcome 5 | /// Welcome to the official SFML-UI documentation. Here you will find a detailed 6 | /// view of all the SFML-UI classes and functions. 7 | //////////////////////////////////////////////////////////// 8 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # add the examples directories 3 | add_subdirectory(ui) 4 | 5 | -------------------------------------------------------------------------------- /examples/android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 14 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /examples/android/assets/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/assets/button.png -------------------------------------------------------------------------------- /examples/android/assets/button_fired.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/assets/button_fired.png -------------------------------------------------------------------------------- /examples/android/assets/button_focused.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/assets/button_focused.png -------------------------------------------------------------------------------- /examples/android/assets/checkbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/assets/checkbox.png -------------------------------------------------------------------------------- /examples/android/assets/checkbox_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/assets/checkbox_selected.png -------------------------------------------------------------------------------- /examples/android/assets/hello_world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/assets/hello_world.png -------------------------------------------------------------------------------- /examples/android/assets/sansation.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/assets/sansation.ttf -------------------------------------------------------------------------------- /examples/android/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := sfml-ui-example 6 | 7 | LOCAL_SRC_FILES := src/Main.cpp 8 | 9 | LOCAL_SHARED_LIBRARIES := sfml-system 10 | LOCAL_SHARED_LIBRARIES += sfml-window 11 | LOCAL_SHARED_LIBRARIES += sfml-graphics 12 | LOCAL_SHARED_LIBRARIES += sfml-audio 13 | LOCAL_SHARED_LIBRARIES += sfml-network 14 | LOCAL_STATIC_LIBRARIES := sfml-ui 15 | LOCAL_WHOLE_STATIC_LIBRARIES := sfml-main 16 | 17 | include $(BUILD_SHARED_LIBRARY) 18 | 19 | $(call import-module,sfml) 20 | $(call import-module,sfml-ui) 21 | -------------------------------------------------------------------------------- /examples/android/jni/Application.mk: -------------------------------------------------------------------------------- 1 | NDK_TOOLCHAIN_VERSION := 4.8 2 | APP_STL := c++_shared 3 | APP_ABI := armeabi 4 | APP_MODULES := sfml-activity sfml-ui-example 5 | -------------------------------------------------------------------------------- /examples/android/jni/src/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void buttonFunction() 7 | { 8 | std::cout << "Button fired" << std::endl; 9 | } 10 | 11 | int main(int argc, char*argv[]) 12 | { 13 | std::cout << "Testing sfml-ui lib" << std::endl; 14 | std::cout << "Current Version : " << SFML_UI_VERSION_MAJOR << "." << SFML_UI_VERSION_MINOR << "." << SFML_UI_VERSION_PATCH << std::endl; 15 | 16 | 17 | std::cout << "Creating window" << std::endl; 18 | sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "Test SFML-UI"); 19 | sf::Event event; 20 | 21 | std::cout << "Creating label text" << std::endl; 22 | sf::Font font; 23 | font.loadFromFile("sansation.ttf"); 24 | sf::ui::Label text(font, "A text label"); 25 | text.setFontColor(sf::Color::Black); 26 | text.move(200, 200); 27 | 28 | std::cout << "Creating label image" << std::endl; 29 | sf::Texture lblImg; 30 | lblImg.loadFromFile("hello_world.png"); 31 | sf::ui::Label image(lblImg); 32 | image.move(window.getSize().x/2 - image.getSize().x/2, 300); 33 | 34 | std::cout << "Creating button" << std::endl; 35 | sf::Texture buttonImg; 36 | buttonImg.loadFromFile("button.png"); 37 | sf::Texture buttonFocImg; 38 | buttonFocImg.loadFromFile("button_focused.png"); 39 | sf::Texture buttonFirImg; 40 | buttonFirImg.loadFromFile("button_fired.png"); 41 | sf::ui::Button button(buttonImg, buttonFocImg, buttonFirImg); 42 | button.setFont(font); 43 | button.setFontSize(30); 44 | button.setText("Button"); 45 | button.move(window.getSize().x/2 - button.getSize().x/2, 240); 46 | button.setFontColor(sf::Color::Black); 47 | 48 | std::cout << "Creating check boxes" << std::endl; 49 | sf::Texture checkboxImg; 50 | checkboxImg.loadFromFile("checkbox.png"); 51 | sf::Texture checkboxSelImg; 52 | checkboxSelImg.loadFromFile("checkbox_selected.png"); 53 | sf::ui::CheckBox checkbox(checkboxImg, checkboxSelImg), checkbox2(checkboxImg, checkboxSelImg), checkbox3(checkboxImg, checkboxSelImg); 54 | checkbox.setFont(font); 55 | checkbox.setText("A checkbox"); 56 | checkbox.setFontColor(sf::Color::Black); 57 | checkbox.setFontSize(15); 58 | checkbox.move(0, 210); 59 | checkbox2.setFont(font); 60 | checkbox2.setText("Another checkbox"); 61 | checkbox2.setFontColor(sf::Color::Black); 62 | checkbox2.setFontSize(15); 63 | checkbox2.move(0, 230); 64 | checkbox3.setFont(font); 65 | checkbox3.setText("A last checkbox"); 66 | checkbox3.setFontColor(sf::Color::Black); 67 | checkbox3.setFontSize(15); 68 | checkbox3.move(0, 250); 69 | 70 | std::cout << "Creating a CheckBoxGroup" << std::endl; 71 | sf::ui::CheckBoxGroup group; 72 | group.addCheckBox(checkbox); 73 | group.addCheckBox(checkbox2); 74 | group.addCheckBox(checkbox3); 75 | 76 | std::cout << "Creating key field (does nothing in Android)" << std::endl; 77 | sf::ui::KeyField keyfield(buttonImg, buttonFocImg, font, sf::Keyboard::A); 78 | keyfield.setFontSize(30); 79 | keyfield.move(0, 280); 80 | keyfield.setFontColor(sf::Color::Black); 81 | 82 | std::cout << "Creating text field" << std::endl; 83 | sf::ui::TextField textfield(buttonImg, buttonFocImg, font, "A field"); 84 | textfield.setFontSize(30); 85 | textfield.move(0, 380); 86 | textfield.setFontColor(sf::Color::Black); 87 | textfield.setCanBeEmpty(false); 88 | textfield.setMaxLength(16); 89 | 90 | while (window.isOpen()) 91 | { 92 | window.waitEvent(event); 93 | 94 | if (event.type == sf::Event::Closed) 95 | window.close(); 96 | 97 | text.updateEvent(event); 98 | image.updateEvent(event); 99 | button.updateEvent(event); 100 | checkbox.updateEvent(event); 101 | checkbox2.updateEvent(event); 102 | checkbox3.updateEvent(event); 103 | keyfield.updateEvent(event); 104 | textfield.updateEvent(event); 105 | 106 | window.clear(sf::Color::White); 107 | window.draw(text); 108 | window.draw(image); 109 | window.draw(button); 110 | window.draw(checkbox); 111 | window.draw(checkbox2); 112 | window.draw(checkbox3); 113 | window.draw(keyfield); 114 | window.draw(textfield); 115 | window.display(); 116 | } 117 | 118 | return EXIT_SUCCESS; 119 | } 120 | -------------------------------------------------------------------------------- /examples/android/project.properties: -------------------------------------------------------------------------------- 1 | target=android-19 -------------------------------------------------------------------------------- /examples/android/res/drawable-hdpi/sfml_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/res/drawable-hdpi/sfml_logo.png -------------------------------------------------------------------------------- /examples/android/res/drawable-ldpi/sfml_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/res/drawable-ldpi/sfml_logo.png -------------------------------------------------------------------------------- /examples/android/res/drawable-mdpi/sfml_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/res/drawable-mdpi/sfml_logo.png -------------------------------------------------------------------------------- /examples/android/res/drawable-xhdpi/sfml_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/res/drawable-xhdpi/sfml_logo.png -------------------------------------------------------------------------------- /examples/android/res/drawable-xxhdpi/sfml_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/android/res/drawable-xxhdpi/sfml_logo.png -------------------------------------------------------------------------------- /examples/android/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/android/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | SFML UI Test 4 | 5 | -------------------------------------------------------------------------------- /examples/android/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/ui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/ui) 3 | 4 | # all source files 5 | set(SRC ${SRCROOT}/Main.cpp ${SRCROOT}/Listener.cpp ${SRCROOT}/Listener.hpp) 6 | 7 | # define the pong target 8 | sfml_add_example(ui GUI_APP 9 | SOURCES ${SRC} 10 | DEPENDS sfml-ui sfml-graphics sfml-window sfml-system) 11 | -------------------------------------------------------------------------------- /examples/ui/Listener.cpp: -------------------------------------------------------------------------------- 1 | #include "Listener.hpp" 2 | #include 3 | #include 4 | #include 5 | 6 | Listener::Listener() 7 | { 8 | //ctor 9 | } 10 | 11 | Listener::~Listener() 12 | { 13 | //dtor 14 | } 15 | 16 | void Listener::onComponentEvent(const sf::ui::ComponentEvent &event) 17 | { 18 | std::cout << "Listener" << std::endl; 19 | std::cout << "Component @" << event.source; 20 | switch (event.type) 21 | { 22 | case sf::ui::ComponentEvent::FocusGained: 23 | std::cout << " gain focus" << std::endl; 24 | break; 25 | case sf::ui::ComponentEvent::FocusLost: 26 | std::cout << " loose focus" << std::endl; 27 | break; 28 | case sf::ui::ComponentEvent::ButtonClicked: 29 | // Pour tester quel button a ete clique : 30 | /* 31 | * if (event.buttonClick.source == &button1) 32 | * { 33 | * // Bla Bla 34 | * } 35 | * else if (event.buttonClick.source == &button2) 36 | * { 37 | * // Bla Bla 38 | * } 39 | * else 40 | * { 41 | * std::cout << "Unknown button" << std::endl; 42 | * } 43 | */ 44 | std::cout << " has been clicked" << std::endl; 45 | break; 46 | case sf::ui::ComponentEvent::KeyFieldSet: 47 | std::cout << " has been set a new key : " << sf::String(sf::ui::SFMLUtils::keyToString(event.keyFieldSet.key)).toAnsiString() << std::endl; 48 | break; 49 | case sf::ui::ComponentEvent::TextEntered: 50 | std::cout << " has character \'" << sf::String(event.text.text).toAnsiString() << "\' entered at " << event.text.position << std::endl; 51 | break; 52 | case sf::ui::ComponentEvent::TextDeleted: 53 | std::cout << " has character \'" << sf::String(event.text.text).toAnsiString() << "\' deleted at " << event.text.position << std::endl; 54 | break; 55 | case sf::ui::ComponentEvent::CheckBoxChanged: 56 | std::cout << " has switched from " << (!event.checkBoxChange.selected ? "selected" : "unselected") << " to " << (event.checkBoxChange.selected ? "selected" : "unselected") << std::endl; 57 | break; 58 | case sf::ui::ComponentEvent::FormattedValueEntered: 59 | std::cout << " has a new formatted value entered : " << event.formattedValueEnter.format->toString().toAnsiString() << std::endl; 60 | break; 61 | default: 62 | std::cout << " has generated an unknown event" << std::endl; 63 | break; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /examples/ui/Listener.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LISTENER_H 2 | #define LISTENER_H 3 | 4 | #include 5 | 6 | class Listener : public sf::ui::ComponentObserver 7 | { 8 | public: 9 | Listener(); 10 | virtual ~Listener(); 11 | 12 | virtual void onComponentEvent(const sf::ui::ComponentEvent &event); 13 | protected: 14 | private: 15 | }; 16 | 17 | #endif // LISTENER_H 18 | -------------------------------------------------------------------------------- /examples/ui/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "Listener.hpp" 6 | 7 | void buttonFunction() 8 | { 9 | std::cout << "Button fired" << std::endl; 10 | } 11 | 12 | int main(int argc, char*argv[]) 13 | { 14 | std::cout << "SFML Version : " << SFML_VERSION_MAJOR << "." << SFML_VERSION_MINOR << std::endl; 15 | std::cout << "Testing sfml-ui lib" << std::endl; 16 | std::cout << "Current Version : " << SFML_UI_VERSION_MAJOR << "." << SFML_UI_VERSION_MINOR << "." << SFML_UI_VERSION_PATCH << std::endl; 17 | 18 | 19 | std::cout << "Creating window" << std::endl; 20 | sf::RenderWindow window(sf::VideoMode(640, 420), "Test SFML-UI", sf::Style::Close); 21 | sf::Event event; 22 | 23 | std::cout << "Creating label text" << std::endl; 24 | sf::Font font; 25 | font.loadFromFile("resources/FreeSans.ttf"); 26 | sf::ui::Label text(font, "A text label"); 27 | text.setFontColor(sf::Color::Black); 28 | text.move(200, 0); 29 | std::cout << "Label text size : " << text.getSize().x << ";" << text.getSize().y << std::endl; 30 | 31 | std::cout << "Creating label image" << std::endl; 32 | sf::Texture lblImg; 33 | lblImg.loadFromFile("resources/hello_world.png"); 34 | sf::ui::Label image(lblImg); 35 | image.move(window.getSize().x/2 - image.getSize().x/2, 100); 36 | std::cout << "Label image size : " << image.getSize().x << ";" << image.getSize().y << std::endl; 37 | 38 | std::cout << "Creating button" << std::endl; 39 | sf::Texture buttonImg; 40 | buttonImg.loadFromFile("resources/button.png"); 41 | sf::Texture buttonFocImg; 42 | buttonFocImg.loadFromFile("resources/button_focused.png"); 43 | sf::Texture buttonFirImg; 44 | buttonFirImg.loadFromFile("resources/button_fired.png"); 45 | sf::ui::Button button(buttonImg, buttonFocImg, buttonFirImg); 46 | button.setFont(font); 47 | button.setFontSize(30); 48 | button.setText("Button"); 49 | button.move(window.getSize().x/2 - button.getSize().x/2, 40); 50 | button.setFontColor(sf::Color::Black); 51 | 52 | std::cout << "Creating check boxes" << std::endl; 53 | sf::Texture checkboxImg; 54 | checkboxImg.loadFromFile("resources/checkbox.png"); 55 | sf::Texture checkboxSelImg; 56 | checkboxSelImg.loadFromFile("resources/checkbox_selected.png"); 57 | sf::ui::CheckBox checkbox(checkboxImg, checkboxSelImg), checkbox2(checkboxImg, checkboxSelImg), checkbox3(checkboxImg, checkboxSelImg); 58 | checkbox.setFont(font); 59 | checkbox.setText("A checkbox"); 60 | checkbox.setFontColor(sf::Color::Black); 61 | checkbox.setFontSize(15); 62 | checkbox.move(0, 10); 63 | checkbox2.setFont(font); 64 | checkbox2.setText("Another checkbox"); 65 | checkbox2.setFontColor(sf::Color::Black); 66 | checkbox2.setFontSize(15); 67 | checkbox2.move(0, 30); 68 | checkbox3.setFont(font); 69 | checkbox3.setText("A last checkbox"); 70 | checkbox3.setFontColor(sf::Color::Black); 71 | checkbox3.setFontSize(15); 72 | checkbox3.move(0, 50); 73 | 74 | std::cout << "Creating a CheckBoxGroup" << std::endl; 75 | sf::ui::CheckBoxGroup group; 76 | group.addCheckBox(checkbox); 77 | group.addCheckBox(checkbox2); 78 | group.addCheckBox(checkbox3); 79 | 80 | std::cout << "Creating key field" << std::endl; 81 | sf::ui::KeyField keyfield(buttonImg, buttonFocImg, font, sf::Keyboard::A); 82 | keyfield.setFontSize(30); 83 | keyfield.move(0, 80); 84 | keyfield.setFontColor(sf::Color::Black); 85 | 86 | std::cout << "Creating text field" << std::endl; 87 | sf::ui::TextField textfield(buttonImg, buttonFocImg, font, "Another text field"); 88 | textfield.setFontSize(30); 89 | textfield.move(0, 180); 90 | textfield.setFontColor(sf::Color::Black); 91 | textfield.setCanBeEmpty(false); 92 | textfield.setMaxLength(16); 93 | 94 | std::cout << "Creating password field" << std::endl; 95 | sf::ui::PasswordField pwfield(buttonImg, buttonFocImg, font); 96 | pwfield.setFontSize(30); 97 | pwfield.move(0, 240); 98 | pwfield.setFontColor(sf::Color::Black); 99 | pwfield.setMaxLength(16); 100 | 101 | std::cout << "Creating Formatted TextField" << std::endl; 102 | sf::ui::FormattedTextField intfield(buttonImg, buttonFocImg, font, new sf::ui::LongFormat, "0"); 103 | intfield.setFontSize(30); 104 | intfield.move(0, 300); 105 | intfield.setFontColor(sf::Color::Black); 106 | intfield.setMaxLength(16); 107 | intfield.setText("-128"); 108 | 109 | sf::ui::FormattedTextField doublefield(buttonImg, buttonFocImg, font, new sf::ui::DoubleFormat, "0.0"); 110 | doublefield.setFontSize(30); 111 | doublefield.move(0, 350); 112 | doublefield.setFontColor(sf::Color::Black); 113 | doublefield.setMaxLength(16); 114 | doublefield.setText("3.14"); 115 | 116 | sf::ui::FormattedTextField ulongfield(buttonImg, buttonFocImg, font, new sf::ui::UnsignedLongFormat, "0"); 117 | ulongfield.setFontSize(30); 118 | ulongfield.move(300, 350); 119 | ulongfield.setFontColor(sf::Color::Black); 120 | ulongfield.setMaxLength(16); 121 | ulongfield.setText("256"); 122 | 123 | std::cout << "Creating listener" << std::endl; 124 | Listener listener; 125 | textfield.addObserver(&listener); 126 | button.addObserver(&listener); 127 | keyfield.addObserver(&listener); 128 | intfield.addObserver(&listener); 129 | doublefield.addObserver(&listener); 130 | ulongfield.addObserver(&listener); 131 | /* checkbox.addObserver(&listener); 132 | checkbox2.addObserver(&listener); 133 | checkbox3.addObserver(&listener);*/ 134 | 135 | while (window.isOpen()) 136 | { 137 | window.waitEvent(event); 138 | 139 | if (event.type == sf::Event::Closed) 140 | window.close(); 141 | 142 | text.updateEvent(event); 143 | image.updateEvent(event); 144 | button.updateEvent(event); 145 | checkbox.updateEvent(event); 146 | checkbox2.updateEvent(event); 147 | checkbox3.updateEvent(event); 148 | keyfield.updateEvent(event); 149 | textfield.updateEvent(event); 150 | pwfield.updateEvent(event); 151 | intfield.updateEvent(event); 152 | doublefield.updateEvent(event); 153 | ulongfield.updateEvent(event); 154 | 155 | window.clear(sf::Color::White); 156 | window.draw(text); 157 | window.draw(image); 158 | window.draw(button); 159 | window.draw(checkbox); 160 | window.draw(checkbox2); 161 | window.draw(checkbox3); 162 | window.draw(keyfield); 163 | window.draw(textfield); 164 | window.draw(pwfield); 165 | window.draw(intfield); 166 | window.draw(doublefield); 167 | window.draw(ulongfield); 168 | window.display(); 169 | } 170 | 171 | return EXIT_SUCCESS; 172 | } 173 | -------------------------------------------------------------------------------- /examples/ui/resources/FreeSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/ui/resources/FreeSans.ttf -------------------------------------------------------------------------------- /examples/ui/resources/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/ui/resources/button.png -------------------------------------------------------------------------------- /examples/ui/resources/button_fired.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/ui/resources/button_fired.png -------------------------------------------------------------------------------- /examples/ui/resources/button_focused.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/ui/resources/button_focused.png -------------------------------------------------------------------------------- /examples/ui/resources/checkbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/ui/resources/checkbox.png -------------------------------------------------------------------------------- /examples/ui/resources/checkbox_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/ui/resources/checkbox_selected.png -------------------------------------------------------------------------------- /examples/ui/resources/hello_world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PatateDev/sfml-ui/a28463309e123c4bc4d9929a84913e9821e87526/examples/ui/resources/hello_world.png -------------------------------------------------------------------------------- /include/SFML/UI.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef UI_HPP_ 19 | #define UI_HPP_ 20 | 21 | #define SFML_UI_VERSION_MAJOR 0 22 | #define SFML_UI_VERSION_MINOR 4 23 | #define SFML_UI_VERSION_PATCH 2 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | #endif /* UI_HPP_ */ 57 | 58 | //////////////////////////////////////////////////////////// 59 | ///\file UI.hpp 60 | ///\ingroup ui 61 | ///\brief Main header which include all UI's header 62 | //////////////////////////////////////////////////////////// 63 | -------------------------------------------------------------------------------- /include/SFML/UI/AbstractButton.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef ABSTRACTBUTTON_H_ 19 | #define ABSTRACTBUTTON_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class AbstractButton : public Focusable 29 | { 30 | public: 31 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 32 | 33 | //////////////////////////////////////////////////////////// 34 | /// 35 | /// \brief Creates an empty abstract button that is implemented by buttons, check box ... 36 | /// 37 | //////////////////////////////////////////////////////////// 38 | AbstractButton(); 39 | 40 | //////////////////////////////////////////////////////////// 41 | /// 42 | /// \brief Creates an abstract button that is implemented by buttons, check box ... 43 | /// 44 | /// \param texture the basic texture of this abstract button 45 | /// \param textureFocused the texture when the abstract button is focused 46 | /// 47 | //////////////////////////////////////////////////////////// 48 | AbstractButton(sf::Texture const &texture, sf::Texture const &textureFocused); 49 | 50 | virtual ~AbstractButton(); 51 | //-------------------------------------------------------------------- 52 | 53 | //METHODS ------------------------------------------------------------ 54 | protected: 55 | //////////////////////////////////////////////////////////// 56 | /// 57 | /// \brief Called when the button is clicked 58 | /// 59 | /// This function defines what the button does 60 | /// 61 | //////////////////////////////////////////////////////////// 62 | virtual void onClick() = 0; 63 | 64 | public: 65 | //////////////////////////////////////////////////////////// 66 | /// 67 | /// \brief Update the component each time an event has been polled 68 | /// \param event the window's event polled 69 | /// 70 | //////////////////////////////////////////////////////////// 71 | virtual void updateEvent(sf::Event const &event); 72 | //-------------------------------------------------------------------- 73 | 74 | //GETTERS/SETTERS ---------------------------------------------------- 75 | 76 | //-------------------------------------------------------------------- 77 | 78 | //FIELDS ------------------------------------------------------------- 79 | 80 | //-------------------------------------------------------------------- 81 | }; 82 | 83 | } /* namespace ui */ 84 | } /* namespace sf */ 85 | #endif /* ABSTRACTBUTTON_H_ */ 86 | 87 | //////////////////////////////////////////////////////////// 88 | /// 89 | /// \class sf::ui::AbstractButton 90 | /// \brief Abstract class for all component that are button-like 91 | /// \ingroup ui 92 | /// 93 | //////////////////////////////////////////////////////////// 94 | -------------------------------------------------------------------------------- /include/SFML/UI/CheckBox.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef CHECKBOX_H_ 19 | #define CHECKBOX_H_ 20 | 21 | #include 22 | #include 23 | 24 | namespace sf 25 | { 26 | namespace ui 27 | { 28 | 29 | class CheckBox : public AbstractButton, public IText 30 | { 31 | public: 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief Creates a Check Box without texture 35 | /// 36 | /// \param selected if the check box is selected 37 | /// 38 | //////////////////////////////////////////////////////////// 39 | CheckBox(bool selected = false); 40 | 41 | //////////////////////////////////////////////////////////// 42 | /// 43 | /// \brief Creates a Check Box with texture 44 | /// If you add a name, do not forget to set the font 45 | /// 46 | /// \param texture the texture of the check box 47 | /// \param textureSelected the texture when the button is selected (same as focused) 48 | /// \param selected if the check box is selected 49 | /// 50 | //////////////////////////////////////////////////////////// 51 | CheckBox(sf::Texture const &texture, sf::Texture const &textureSelected, bool selected = false); 52 | 53 | //////////////////////////////////////////////////////////// 54 | /// 55 | /// \brief Creates a Check Box with texture and font 56 | /// 57 | /// \param texture the texture of the check box 58 | /// \param textureSelected the texture when the button is selected (same as focused) 59 | /// \param font the font of the text 60 | /// \param name the text displayed behind the check box 61 | /// \param selected if the check box is selected 62 | /// 63 | //////////////////////////////////////////////////////////// 64 | CheckBox(sf::Texture const &texture, sf::Texture const &textureSelected, sf::Font const& font, sf::String name = "", bool selected = false); 65 | 66 | virtual ~CheckBox(); 67 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 68 | 69 | //-------------------------------------------------------------------- 70 | 71 | //METHODS ------------------------------------------------------------ 72 | protected: 73 | //////////////////////////////////////////////////////////// 74 | /// 75 | /// \brief Called when the button is clicked 76 | /// That defines whether the check box is selected or not 77 | /// 78 | //////////////////////////////////////////////////////////// 79 | virtual void onClick(); 80 | 81 | //////////////////////////////////////////////////////////// 82 | /// 83 | /// \brief Called when the component need update its geometry 84 | /// Inherit when you need to update some sprite 85 | /// 86 | //////////////////////////////////////////////////////////// 87 | virtual void updateCoord(); 88 | 89 | //////////////////////////////////////////////////////////// 90 | /// 91 | /// \brief Draw the component to the render target 92 | /// 93 | //////////////////////////////////////////////////////////// 94 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; 95 | 96 | public: 97 | //////////////////////////////////////////////////////////// 98 | /// 99 | /// \brief Update the component with the main loop's frequency 100 | /// Can be useful for animation, or time's needed stuff 101 | /// 102 | /// \param delta the time between this update and the last 103 | /// 104 | //////////////////////////////////////////////////////////// 105 | virtual void updateFixed(sf::Time delta); 106 | //-------------------------------------------------------------------- 107 | 108 | //GETTERS/SETTERS ---------------------------------------------------- 109 | //////////////////////////////////////////////////////////// 110 | /// 111 | /// \return if the check box is selected or not 112 | /// Similar to isFocused 113 | //////////////////////////////////////////////////////////// 114 | bool isSelected() const; 115 | 116 | //////////////////////////////////////////////////////////// 117 | /// 118 | /// \brief Sets if the check box is selected or not 119 | /// 120 | /// \param selected - if the check box is selected 121 | /// 122 | //////////////////////////////////////////////////////////// 123 | void setSelected(bool selected); 124 | 125 | //////////////////////////////////////////////////////////// 126 | /// 127 | /// \return the size of the component 128 | /// 129 | ///////////////////////////////////////////////////////////// 130 | virtual sf::Vector2f getSize() const; 131 | 132 | //////////////////////////////////////////////////////////// 133 | /// 134 | /// \return the text's string 135 | /// 136 | //////////////////////////////////////////////////////////// 137 | virtual const sf::String& getText() const; 138 | 139 | //////////////////////////////////////////////////////////// 140 | /// 141 | /// \brief Sets the text's string of the component 142 | /// Don't forget to set the font 143 | /// 144 | /// \param text the new string of the component 145 | /// 146 | //////////////////////////////////////////////////////////// 147 | virtual void setText(sf::String const &text); 148 | 149 | //////////////////////////////////////////////////////////// 150 | /// 151 | /// \return the font of the component, or null if any 152 | /// 153 | //////////////////////////////////////////////////////////// 154 | virtual const sf::Font* getFont() const; 155 | 156 | //////////////////////////////////////////////////////////// 157 | /// 158 | /// \brief Sets the font of the component's text 159 | /// 160 | //////////////////////////////////////////////////////////// 161 | virtual void setFont(sf::Font const &font); 162 | 163 | //////////////////////////////////////////////////////////// 164 | /// 165 | /// \return the font's size of the component 166 | /// 167 | //////////////////////////////////////////////////////////// 168 | virtual unsigned int getFontSize() const; 169 | 170 | //////////////////////////////////////////////////////////// 171 | /// 172 | /// \brief Set the font's size of the component 173 | /// 174 | /// \param size - the font's size 175 | /// 176 | //////////////////////////////////////////////////////////// 177 | virtual void setFontSize(unsigned int size); 178 | 179 | //////////////////////////////////////////////////////////// 180 | /// 181 | /// \return the font's color of the text 182 | /// 183 | //////////////////////////////////////////////////////////// 184 | virtual sf::Color getFontColor() const; 185 | 186 | //////////////////////////////////////////////////////////// 187 | /// 188 | /// \brief Sets the color's font of the text 189 | /// 190 | /// \param color the text's color 191 | /// 192 | //////////////////////////////////////////////////////////// 193 | virtual void setFontColor(sf::Color color); 194 | //-------------------------------------------------------------------- 195 | 196 | //FIELDS ------------------------------------------------------------- 197 | protected: 198 | sf::Text m_text; 199 | //-------------------------------------------------------------------- 200 | }; 201 | 202 | } /* namespace ui */ 203 | } /* namespace sf */ 204 | #endif /* CHECKBOX_H_ */ 205 | 206 | //////////////////////////////////////////////////////////// 207 | /// 208 | /// \class sf::ui::CheckBox 209 | /// \brief A box which can be checked or not 210 | /// \ingroup ui 211 | /// 212 | //////////////////////////////////////////////////////////// 213 | -------------------------------------------------------------------------------- /include/SFML/UI/CheckBoxGroup.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef CHECKBOXGROUP_H_ 19 | #define CHECKBOXGROUP_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace sf 26 | { 27 | namespace ui 28 | { 29 | 30 | class CheckBoxGroup : public sf::ui::ComponentObserver 31 | { 32 | //CONSTRUCTORS - DESTRUCTOR ----------------------------------------------------------- 33 | public: 34 | //////////////////////////////////////////////////////////// 35 | /// 36 | /// \brief A group of check box. 37 | /// Only one of this check boxes can be selected 38 | /// at time. 39 | /// 40 | //////////////////////////////////////////////////////////// 41 | CheckBoxGroup(); 42 | 43 | virtual ~CheckBoxGroup(); 44 | //------------------------------------------------------------------------------------- 45 | 46 | //METHODS ----------------------------------------------------------------------------- 47 | public: 48 | //////////////////////////////////////////////////////////// 49 | /// 50 | /// \brief Add a checkbox to this group 51 | /// 52 | /// \param checkbox the checkbox to add 53 | /// 54 | //////////////////////////////////////////////////////////// 55 | void addCheckBox(CheckBox &checkbox); 56 | 57 | //////////////////////////////////////////////////////////// 58 | /// 59 | /// \return the begin of checkbox's iterator 60 | /// 61 | //////////////////////////////////////////////////////////// 62 | std::set::const_iterator getCheckboxBegin() const; 63 | 64 | //////////////////////////////////////////////////////////// 65 | /// 66 | /// \return the end of checkbox's iterator 67 | /// 68 | //////////////////////////////////////////////////////////// 69 | std::set::const_iterator getCheckboxEnd() const; 70 | 71 | //////////////////////////////////////////////////////////// 72 | /// 73 | /// \brief Remove a checkbox to this group; 74 | /// This function does NOT delete the checkbox 75 | /// 76 | /// \param checkbox - the checkbox to remove 77 | /// 78 | //////////////////////////////////////////////////////////// 79 | void removeCheckbox(CheckBox& checkbox); 80 | 81 | //////////////////////////////////////////////////////////// 82 | /// 83 | /// \return the number of checkboxes in this group 84 | /// 85 | //////////////////////////////////////////////////////////// 86 | unsigned int countCheckbox() const; 87 | 88 | //////////////////////////////////////////////////////////// 89 | /// 90 | /// \return if the check box is in this group 91 | /// 92 | /// \param checkbox the checkbox to check 93 | /// 94 | //////////////////////////////////////////////////////////// 95 | bool isCheckBoxInGroup(CheckBox *checkbox) const; 96 | 97 | //////////////////////////////////////////////////////////// 98 | /// 99 | /// \brief Called each time a component change 100 | /// 101 | //////////////////////////////////////////////////////////// 102 | virtual void onComponentEvent(const ComponentEvent &event); 103 | 104 | private: 105 | //////////////////////////////////////////////////////////// 106 | /// 107 | /// \return the first checkbox selected excluded the given one, 108 | /// or 0 if none 109 | /// 110 | /// \param excluded an extra checkbox which will be ignored 111 | /// 112 | //////////////////////////////////////////////////////////// 113 | CheckBox* firstSelected(CheckBox* excluded = 0) const; 114 | //------------------------------------------------------------------------------------- 115 | 116 | //GETTERS - SETTERS ------------------------------------------------------------------- 117 | 118 | //------------------------------------------------------------------------------------- 119 | 120 | //FIELDS ------------------------------------------------------------------------------ 121 | private: 122 | std::set m_checkBox; 123 | //------------------------------------------------------------------------------------- 124 | }; 125 | 126 | } /* namespace ui */ 127 | } /* namespace sf */ 128 | #endif /* CHECKBOXGROUP_H_ */ 129 | 130 | //////////////////////////////////////////////////////////// 131 | /// 132 | /// \class sf::ui::CheckBoxGroup 133 | /// \brief A group that allow only one check box selected in the same time 134 | /// \ingroup ui 135 | /// \see sf::ui::CheckBox 136 | /// 137 | //////////////////////////////////////////////////////////// 138 | -------------------------------------------------------------------------------- /include/SFML/UI/Component.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef COMPONENT_H_ 19 | #define COMPONENT_H_ 20 | 21 | #include 22 | #include 23 | 24 | namespace sf 25 | { 26 | namespace ui 27 | { 28 | 29 | class Component : public Drawable, public ComponentObservable 30 | { 31 | 32 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 33 | public: 34 | //////////////////////////////////////////////////////////// 35 | /// 36 | /// \brief Creates an empty component, without texture 37 | /// 38 | //////////////////////////////////////////////////////////// 39 | Component(); 40 | 41 | //////////////////////////////////////////////////////////// 42 | /// 43 | /// \brief Creates a component with the give texture 44 | /// 45 | /// \param texture - the texture displayed by the component 46 | /// 47 | //////////////////////////////////////////////////////////// 48 | Component(sf::Texture const &texture); 49 | 50 | virtual ~Component(); 51 | //-------------------------------------------------------------------- 52 | 53 | //METHODS ------------------------------------------------------------ 54 | public: 55 | //////////////////////////////////////////////////////////// 56 | /// 57 | /// \brief Update the component each time an event has been polled 58 | /// 59 | /// \param event the window's event polled 60 | /// 61 | //////////////////////////////////////////////////////////// 62 | virtual void updateEvent(sf::Event const &event) = 0; 63 | 64 | //////////////////////////////////////////////////////////// 65 | /// 66 | /// \brief Update the component with the main loop's frequency 67 | /// Can be useful for animation, or time's needed stuff 68 | /// 69 | /// \param delta the time between this update and the last one 70 | /// 71 | //////////////////////////////////////////////////////////// 72 | virtual void updateFixed(sf::Time delta) = 0; 73 | 74 | //////////////////////////////////////////////////////////// 75 | /// 76 | /// \brief Update the size of the component 77 | /// Call it when you update your texture 78 | /// after it was set, to recalculate the component's size 79 | /// with new texture loaded. 80 | /// 81 | /// Example: 82 | /// \code 83 | /// sf::Texture texture; 84 | /// sf::Label label(texture); // Now label has a pointer to texture, moreover its size is (0;0) 85 | /// texture.loadFromFile("texture.png"); // New texture loaded, and so its size has changed 86 | /// label.updateSize(); // Tell label that it have to change its size, and calculate it with the updated texture's size 87 | /// \endcode 88 | /// 89 | //////////////////////////////////////////////////////////// 90 | void updateSize(); 91 | 92 | //////////////////////////////////////////////////////////// 93 | /// 94 | /// \brief Move the component 95 | /// 96 | /// \param vector the move's vector 97 | /// 98 | //////////////////////////////////////////////////////////// 99 | void move(sf::Vector2f const &vector); 100 | 101 | //////////////////////////////////////////////////////////// 102 | /// 103 | /// \brief Move the component 104 | /// 105 | /// \param x the x movement 106 | /// \param y the y movement 107 | //////////////////////////////////////////////////////////// 108 | void move(float x, float y); 109 | 110 | protected: 111 | //////////////////////////////////////////////////////////// 112 | /// 113 | /// \brief Draw the component to the render target 114 | /// 115 | //////////////////////////////////////////////////////////// 116 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; 117 | 118 | //////////////////////////////////////////////////////////// 119 | /// 120 | /// \brief Called when the component need update its geometry 121 | /// Inherit when you need to update some sprite 122 | /// 123 | //////////////////////////////////////////////////////////// 124 | virtual void updateCoord(); 125 | //-------------------------------------------------------------------- 126 | 127 | //GETTERS/SETTERS ---------------------------------------------------- 128 | public: 129 | //////////////////////////////////////////////////////////// 130 | /// 131 | /// \return the texture of the component 132 | /// 133 | //////////////////////////////////////////////////////////// 134 | const sf::Texture* getTexture() const; 135 | 136 | //////////////////////////////////////////////////////////// 137 | /// 138 | /// \brief Set the texture of the component 139 | /// 140 | //////////////////////////////////////////////////////////// 141 | void setTexture(const sf::Texture& texture); 142 | 143 | //////////////////////////////////////////////////////////// 144 | /// 145 | /// \return the position of the component 146 | /// 147 | //////////////////////////////////////////////////////////// 148 | const sf::Vector2f& getPosition() const; 149 | 150 | //////////////////////////////////////////////////////////// 151 | /// 152 | /// \brief Set the component's position 153 | /// 154 | /// \param position - the position vector 155 | /// 156 | //////////////////////////////////////////////////////////// 157 | void setPosition(sf::Vector2f const &position); 158 | 159 | //////////////////////////////////////////////////////////// 160 | /// 161 | /// \brief Set the component's position 162 | /// 163 | /// 164 | /// \param x - the x coordinate 165 | /// \param y - the y coordinate 166 | /// 167 | //////////////////////////////////////////////////////////// 168 | void setPosition(float x, float y); 169 | 170 | //////////////////////////////////////////////////////////// 171 | /// 172 | /// \return the size of the component 173 | /// 174 | //////////////////////////////////////////////////////////// 175 | virtual sf::Vector2f getSize() const; 176 | //-------------------------------------------------------------------- 177 | 178 | //FIELDS ------------------------------------------------------------- 179 | protected: 180 | sf::Sprite m_sprite; // The component's sprite displayed 181 | sf::Texture const *m_texture; //The component's texture 182 | //-------------------------------------------------------------------- 183 | }; 184 | 185 | } /* namespace ui */ 186 | } /* namespace sf */ 187 | 188 | #endif /* COMPONENT_H_ */ 189 | 190 | //////////////////////////////////////////////////////////// 191 | /// 192 | /// \class sf::ui::Component 193 | /// \brief The base class for all UI components 194 | /// \ingroup ui 195 | /// 196 | //////////////////////////////////////////////////////////// 197 | -------------------------------------------------------------------------------- /include/SFML/UI/ComponentEvent.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef COMPONENT_EVENT_H_ 19 | #define COMPONENT_EVENT_H_ 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace sf 33 | { 34 | namespace ui 35 | { 36 | 37 | class ComponentEvent 38 | { 39 | public: 40 | //////////////////////////////////////////////////////////// 41 | /// 42 | /// \brief An event that is triggered each time a button is fired 43 | /// 44 | //////////////////////////////////////////////////////////// 45 | struct ButtonClickedEvent 46 | { 47 | AbstractButton* source; 48 | sf::Mouse::Button button; 49 | int x; 50 | int y; 51 | }; 52 | 53 | //////////////////////////////////////////////////////////// 54 | /// 55 | /// \brief An event that is triggered each time a button is fired, touched (on mobile OSs) 56 | /// 57 | //////////////////////////////////////////////////////////// 58 | struct ButtonTouchedEvent 59 | { 60 | AbstractButton* source; 61 | unsigned int finger; 62 | int x; 63 | int y; 64 | }; 65 | 66 | //////////////////////////////////////////////////////////// 67 | /// 68 | /// \brief An event that is triggered each time a check box switch from unselected to selected, and vice-versa 69 | /// 70 | //////////////////////////////////////////////////////////// 71 | struct CheckBoxChangeEvent 72 | { 73 | CheckBox* source; 74 | bool selected; 75 | }; 76 | 77 | 78 | //////////////////////////////////////////////////////////// 79 | /// 80 | /// \brief An event that is triggered each time a component change its focus status 81 | /// 82 | //////////////////////////////////////////////////////////// 83 | struct FocusedEvent 84 | { 85 | Focusable* source; 86 | bool focused; 87 | }; 88 | 89 | //////////////////////////////////////////////////////////// 90 | /// 91 | /// \brief An event related to a formatted value entered (e.g on sf::ui::FormattedTextField) 92 | /// 93 | //////////////////////////////////////////////////////////// 94 | struct FormattedValueEnteredEvent 95 | { 96 | FormattedTextField* source; 97 | Format* format; 98 | }; 99 | 100 | //////////////////////////////////////////////////////////// 101 | /// 102 | /// \brief An event that is triggered each time a key is set 103 | /// Triggered only with KeyField 104 | /// 105 | //////////////////////////////////////////////////////////// 106 | struct KeyFieldSetEvent 107 | { 108 | KeyField* source; 109 | sf::Keyboard::Key key; 110 | }; 111 | 112 | //////////////////////////////////////////////////////////// 113 | /// 114 | /// \brief An event that is triggered each time a text is entered/deleted 115 | /// Triggered only with TextField 116 | /// 117 | //////////////////////////////////////////////////////////// 118 | struct TextEvent 119 | { 120 | TextField* source; 121 | sf::Uint32 text; 122 | unsigned int position; 123 | }; 124 | 125 | //////////////////////////////////////////////////////////// 126 | /// 127 | /// \brief Enumeration of component events 128 | /// 129 | //////////////////////////////////////////////////////////// 130 | enum ComponentEventType 131 | { 132 | ButtonClicked, 133 | ButtonTouched, 134 | CheckBoxChanged, 135 | FocusGained, 136 | FocusLost, 137 | FormattedValueEntered, 138 | KeyFieldSet, 139 | TextEntered, 140 | TextDeleted 141 | }; 142 | 143 | ComponentEventType type; 144 | Component* source; 145 | 146 | union 147 | { 148 | ButtonClickedEvent buttonClick; 149 | ButtonTouchedEvent buttonTouch; 150 | CheckBoxChangeEvent checkBoxChange; 151 | FocusedEvent focus; 152 | FormattedValueEnteredEvent formattedValueEnter; 153 | KeyFieldSetEvent keyFieldSet; 154 | TextEvent text; 155 | }; 156 | 157 | }; 158 | 159 | 160 | } 161 | } 162 | 163 | #endif 164 | 165 | //////////////////////////////////////////////////////////// 166 | /// 167 | /// \class sf::ui::ComponentEvent 168 | /// \brief An event generate by a component 169 | /// \ingroup ui 170 | /// 171 | //////////////////////////////////////////////////////////// 172 | -------------------------------------------------------------------------------- /include/SFML/UI/ComponentObservable.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef COMPONENTOBSERVABLE_H_ 19 | #define COMPONENTOBSERVABLE_H_ 20 | 21 | #include 22 | #include 23 | 24 | 25 | namespace sf 26 | { 27 | namespace ui 28 | { 29 | class ComponentEvent; 30 | 31 | class ComponentObservable 32 | { 33 | //CONSTRUCTORS - DESTRUCTOR ----------------------------------------------------------- 34 | public: 35 | //////////////////////////////////////////////////////////// 36 | /// 37 | /// \brief The default constructor 38 | /// 39 | //////////////////////////////////////////////////////////// 40 | ComponentObservable(); 41 | 42 | virtual ~ComponentObservable(); 43 | //------------------------------------------------------------------------------------- 44 | 45 | //METHODS ----------------------------------------------------------------------------- 46 | public: 47 | //////////////////////////////////////////////////////////// 48 | /// 49 | /// \brief Add an observer 50 | /// 51 | //////////////////////////////////////////////////////////// 52 | void addObserver(sf::ui::ComponentObserver* observer); 53 | 54 | //////////////////////////////////////////////////////////// 55 | /// 56 | /// \return the begin of the observers' iterator 57 | /// 58 | //////////////////////////////////////////////////////////// 59 | std::set::const_iterator getObserversBegin() const; 60 | 61 | //////////////////////////////////////////////////////////// 62 | /// 63 | /// \return the end of the observers' iterator 64 | /// 65 | //////////////////////////////////////////////////////////// 66 | std::set::const_iterator getObserversEnd() const; 67 | 68 | //////////////////////////////////////////////////////////// 69 | /// 70 | /// \return the number of observers 71 | /// 72 | //////////////////////////////////////////////////////////// 73 | int countObservers(); 74 | 75 | //////////////////////////////////////////////////////////// 76 | /// 77 | /// \brief Remove the observer at the given index 78 | /// 79 | /// \param observer the observer to remove 80 | /// 81 | //////////////////////////////////////////////////////////// 82 | void removeObserver(sf::ui::ComponentObserver* observer); 83 | 84 | //////////////////////////////////////////////////////////// 85 | /// 86 | /// \brief Remove all the observers 87 | /// 88 | //////////////////////////////////////////////////////////// 89 | void removeAllObservers(); 90 | 91 | protected: 92 | //////////////////////////////////////////////////////////// 93 | /// 94 | /// \brief Triggers the event and notify all observers 95 | /// 96 | /// \param event - the event to push 97 | /// 98 | //////////////////////////////////////////////////////////// 99 | void triggerEvent(const sf::ui::ComponentEvent &event); 100 | //------------------------------------------------------------------------------------- 101 | 102 | //GETTERS - SETTERS ------------------------------------------------------------------- 103 | 104 | //------------------------------------------------------------------------------------- 105 | 106 | //FIELDS ------------------------------------------------------------------------------ 107 | protected: 108 | std::set m_observers; 109 | //------------------------------------------------------------------------------------- 110 | }; 111 | 112 | } /* namespace ui */ 113 | } /* namespace sf */ 114 | #endif /* COMPONENTOBSERVABLE_H_ */ 115 | 116 | //////////////////////////////////////////////////////////// 117 | /// 118 | /// \class sf::ui::ComponentObservable 119 | /// \brief The class who call the observers 120 | /// \ingroup ui 121 | /// 122 | //////////////////////////////////////////////////////////// 123 | -------------------------------------------------------------------------------- /include/SFML/UI/ComponentObserver.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef OBSERVER_H 19 | #define OBSERVER_H 20 | 21 | namespace sf 22 | { 23 | namespace ui 24 | { 25 | class ComponentEvent; 26 | 27 | class ComponentObserver 28 | { 29 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 30 | public: 31 | //////////////////////////////////////////////////////////// 32 | /// 33 | /// \brief Any object which extends of this can observe a component 34 | /// 35 | //////////////////////////////////////////////////////////// 36 | ComponentObserver(); 37 | 38 | virtual ~ComponentObserver(); 39 | //-------------------------------------------------------------------- 40 | 41 | //METHODS ------------------------------------------------------------ 42 | public: 43 | //////////////////////////////////////////////////////////// 44 | /// 45 | /// \brief Called each time a component change 46 | /// 47 | //////////////////////////////////////////////////////////// 48 | virtual void onComponentEvent(const ComponentEvent &event) = 0; 49 | //-------------------------------------------------------------------- 50 | }; 51 | 52 | } /* namespace ui */ 53 | } /* namespace sf */ 54 | 55 | #endif // OBSERVER_H 56 | //////////////////////////////////////////////////////////// 57 | /// 58 | /// \class sf::ui::ComponentObserver 59 | /// \brief A object updated each time a ComponentObservable change 60 | /// \ingroup ui 61 | /// \see sf::ui::ComponentObservable 62 | /// 63 | //////////////////////////////////////////////////////////// 64 | -------------------------------------------------------------------------------- /include/SFML/UI/Focusable.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef FOCUSABLE_H_ 19 | #define FOCUSABLE_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class Focusable: public Component 29 | { 30 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 31 | public: 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief Creates an empty Component Focusable, without textures. 35 | /// This class does NOT define when the component should be focused, 36 | /// You have to do that in the inherited class 37 | /// 38 | //////////////////////////////////////////////////////////// 39 | Focusable(); 40 | 41 | //////////////////////////////////////////////////////////// 42 | /// 43 | /// \brief Creates a Component Focusable with given textures. 44 | /// This class does NOT define when the component should be focused, 45 | /// You have to do that in the inherited class. 46 | /// 47 | /// \param texture the default texture of the component 48 | /// \param textureFocused the texture when the component is focused 49 | /// 50 | //////////////////////////////////////////////////////////// 51 | Focusable(sf::Texture const &texture, sf::Texture const &textureFocused); 52 | 53 | virtual ~Focusable(); 54 | //-------------------------------------------------------------------- 55 | 56 | //METHODS ------------------------------------------------------------ 57 | protected: 58 | //////////////////////////////////////////////////////////// 59 | /// 60 | /// \return whether the click should focus the component or not 61 | /// 62 | /// \param button - the mouse's button 63 | /// \param x - the x coord 64 | /// \param y - the y coord 65 | /// 66 | //////////////////////////////////////////////////////////// 67 | virtual bool checkClickOn(int x, int y) const; 68 | 69 | //////////////////////////////////////////////////////////// 70 | /// 71 | /// \return whether the given coordinate is on the component or out 72 | /// 73 | /// \param x - the x coord 74 | /// \param y - the y coord 75 | /// 76 | //////////////////////////////////////////////////////////// 77 | virtual bool isCoordOnComponent(int x, int y) const; 78 | 79 | //////////////////////////////////////////////////////////// 80 | /// 81 | /// \brief Called when the component gain focus 82 | /// 83 | //////////////////////////////////////////////////////////// 84 | virtual void gainFocus(); 85 | 86 | //////////////////////////////////////////////////////////// 87 | /// 88 | /// \brief Called when the component lost focus 89 | /// 90 | //////////////////////////////////////////////////////////// 91 | virtual void lostFocus(); 92 | //-------------------------------------------------------------------- 93 | 94 | //GETTERS/SETTERS ---------------------------------------------------- 95 | public: 96 | //////////////////////////////////////////////////////////// 97 | /// 98 | /// \return whether the component is focused or not 99 | /// 100 | //////////////////////////////////////////////////////////// 101 | bool isFocused() const; 102 | 103 | //////////////////////////////////////////////////////////// 104 | /// 105 | /// \brief Set if the component is focused 106 | /// 107 | /// \param focused - is focused 108 | /// 109 | //////////////////////////////////////////////////////////// 110 | void setFocused(bool focused); 111 | 112 | //////////////////////////////////////////////////////////// 113 | /// 114 | /// \return the texture when the component is focused 115 | /// 116 | //////////////////////////////////////////////////////////// 117 | const sf::Texture* getTextureFocused() const; 118 | 119 | //////////////////////////////////////////////////////////// 120 | /// 121 | /// \brief Set the texture that is displayed when the component is displayed 122 | /// 123 | /// \param textureFocused - the texture when the component is focused 124 | /// 125 | //////////////////////////////////////////////////////////// 126 | void setTextureFocused(const sf::Texture& textureFocused); 127 | //-------------------------------------------------------------------- 128 | 129 | //FIELDS ------------------------------------------------------------- 130 | protected: 131 | sf::Texture const *m_textureFocused; 132 | bool m_focused; 133 | //-------------------------------------------------------------------- 134 | }; 135 | 136 | } /* namespace ui */ 137 | } /* namespace sf */ 138 | #endif /* FOCUSABLE_H_ */ 139 | 140 | //////////////////////////////////////////////////////////// 141 | /// 142 | /// \class sf::ui::Focusable 143 | /// \brief The base class for all UI components that can be focused 144 | /// \ingroup ui 145 | /// 146 | //////////////////////////////////////////////////////////// 147 | -------------------------------------------------------------------------------- /include/SFML/UI/Format/DoubleFormat.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef DOUBLE_FORMAT_H 19 | #define DOUBLE_FORMAT_H 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class DoubleFormat : public Format 29 | { 30 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 31 | public: 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief Creates a double format 35 | /// 36 | //////////////////////////////////////////////////////////// 37 | DoubleFormat(); 38 | 39 | virtual ~DoubleFormat(); 40 | //-------------------------------------------------------------------- 41 | 42 | //METHODS ------------------------------------------------------------ 43 | public: 44 | //////////////////////////////////////////////////////////// 45 | /// 46 | /// \return the string with the value in this format 47 | /// 48 | //////////////////////////////////////////////////////////// 49 | virtual sf::String toString() const; 50 | 51 | //////////////////////////////////////////////////////////// 52 | /// 53 | /// \return if the given string matches with this format 54 | /// 55 | /// \param str the string to test 56 | /// 57 | //////////////////////////////////////////////////////////// 58 | virtual bool isAllowed(sf::String str) const; 59 | 60 | //////////////////////////////////////////////////////////// 61 | /// 62 | /// \brief parse the string to this format, and update the value 63 | /// 64 | /// \param str the string parsed 65 | /// 66 | //////////////////////////////////////////////////////////// 67 | virtual void parse(sf::String str); 68 | 69 | //-------------------------------------------------------------------- 70 | 71 | //GETTERS/SETTERS ---------------------------------------------------- 72 | public: 73 | //////////////////////////////////////////////////////////// 74 | /// 75 | /// \param value the new value 76 | /// 77 | //////////////////////////////////////////////////////////// 78 | void setValue(double value); 79 | 80 | //////////////////////////////////////////////////////////// 81 | /// 82 | /// \return the value of the last string parsed as a double 83 | /// 84 | //////////////////////////////////////////////////////////// 85 | double getValue() const; 86 | //-------------------------------------------------------------------- 87 | 88 | //FIELDS ------------------------------------------------------------- 89 | protected: 90 | double m_value; 91 | //-------------------------------------------------------------------- 92 | }; 93 | 94 | } 95 | } 96 | #endif 97 | 98 | //////////////////////////////////////////////////////////// 99 | /// 100 | /// \class sf::ui::DoubleFormat 101 | /// \brief Format to parse double 102 | /// \ingroup ui 103 | /// 104 | //////////////////////////////////////////////////////////// 105 | -------------------------------------------------------------------------------- /include/SFML/UI/Format/Format.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef FORMAT_H 19 | #define FORMAT_H 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class Format 29 | { 30 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 31 | public: 32 | virtual ~Format(); 33 | //-------------------------------------------------------------------- 34 | 35 | //METHODS ------------------------------------------------------------ 36 | public: 37 | //////////////////////////////////////////////////////////// 38 | /// 39 | /// \return the string with the value in this format 40 | /// 41 | //////////////////////////////////////////////////////////// 42 | virtual sf::String toString() const = 0; 43 | 44 | //////////////////////////////////////////////////////////// 45 | /// 46 | /// \return if the given string matches with this format 47 | /// 48 | /// \param str the string to test 49 | /// 50 | //////////////////////////////////////////////////////////// 51 | virtual bool isAllowed(sf::String str) const = 0; 52 | 53 | //////////////////////////////////////////////////////////// 54 | /// 55 | /// \brief parse the string to this format, and update the value 56 | /// 57 | /// \param str the string parsed 58 | /// 59 | //////////////////////////////////////////////////////////// 60 | virtual void parse(sf::String str) = 0; 61 | 62 | //-------------------------------------------------------------------- 63 | 64 | //GETTERS/SETTERS ---------------------------------------------------- 65 | 66 | //-------------------------------------------------------------------- 67 | 68 | //FIELDS ------------------------------------------------------------- 69 | 70 | //-------------------------------------------------------------------- 71 | }; 72 | 73 | } 74 | } 75 | #endif 76 | 77 | //////////////////////////////////////////////////////////// 78 | /// 79 | /// \class sf::ui::Format 80 | /// \brief The abstract class that defines format of various 81 | /// types, such as ints, double, objects ... 82 | /// \ingroup ui 83 | /// 84 | //////////////////////////////////////////////////////////// 85 | -------------------------------------------------------------------------------- /include/SFML/UI/Format/LongFormat.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef LONG_FORMAT_H 19 | #define LONG_FORMAT_H 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class LongFormat : public Format 29 | { 30 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 31 | public: 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief Creates a long format 35 | /// 36 | //////////////////////////////////////////////////////////// 37 | LongFormat(); 38 | 39 | virtual ~LongFormat(); 40 | //-------------------------------------------------------------------- 41 | 42 | //METHODS ------------------------------------------------------------ 43 | public: 44 | //////////////////////////////////////////////////////////// 45 | /// 46 | /// \return the string with the value in this format 47 | /// 48 | //////////////////////////////////////////////////////////// 49 | virtual sf::String toString() const; 50 | 51 | //////////////////////////////////////////////////////////// 52 | /// 53 | /// \return if the given string matches with this format 54 | /// 55 | /// \param str the string to test 56 | /// 57 | //////////////////////////////////////////////////////////// 58 | virtual bool isAllowed(sf::String str) const; 59 | 60 | //////////////////////////////////////////////////////////// 61 | /// 62 | /// \brief parse the string to this format, and update the value 63 | /// 64 | /// \param str the string parsed 65 | /// 66 | //////////////////////////////////////////////////////////// 67 | virtual void parse(sf::String str); 68 | 69 | //-------------------------------------------------------------------- 70 | 71 | //GETTERS/SETTERS ---------------------------------------------------- 72 | public: 73 | //////////////////////////////////////////////////////////// 74 | /// 75 | /// \param value the new value 76 | /// 77 | //////////////////////////////////////////////////////////// 78 | void setValue(sf::Int64 value); 79 | 80 | //////////////////////////////////////////////////////////// 81 | /// 82 | /// \return the value of the last string parsed 83 | /// 84 | //////////////////////////////////////////////////////////// 85 | sf::Int64 getValue() const; 86 | //-------------------------------------------------------------------- 87 | 88 | //FIELDS ------------------------------------------------------------- 89 | protected: 90 | sf::Int64 m_value; 91 | //-------------------------------------------------------------------- 92 | }; 93 | 94 | } 95 | } 96 | #endif 97 | 98 | //////////////////////////////////////////////////////////// 99 | /// 100 | /// \class sf::ui::LongFormat 101 | /// \brief Format to parse long (stored as sf::Int64) 102 | /// \ingroup ui 103 | /// 104 | //////////////////////////////////////////////////////////// 105 | -------------------------------------------------------------------------------- /include/SFML/UI/Format/UnsignedLongFormat.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef UNSIGNED_LONG_FORMAT_H 19 | #define UNSIGNED_LONG_FORMAT_H 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class UnsignedLongFormat : public Format 29 | { 30 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 31 | public: 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief Creates a long format 35 | /// 36 | //////////////////////////////////////////////////////////// 37 | UnsignedLongFormat(); 38 | 39 | virtual ~UnsignedLongFormat(); 40 | //-------------------------------------------------------------------- 41 | 42 | //METHODS ------------------------------------------------------------ 43 | public: 44 | //////////////////////////////////////////////////////////// 45 | /// 46 | /// \return the string with the value in this format 47 | /// 48 | //////////////////////////////////////////////////////////// 49 | virtual sf::String toString() const; 50 | 51 | //////////////////////////////////////////////////////////// 52 | /// 53 | /// \return if the given string matches with this format 54 | /// 55 | /// \param str the string to test 56 | /// 57 | //////////////////////////////////////////////////////////// 58 | virtual bool isAllowed(sf::String str) const; 59 | 60 | //////////////////////////////////////////////////////////// 61 | /// 62 | /// \brief parse the string to this format, and update the value 63 | /// 64 | /// \param str the string parsed 65 | /// 66 | //////////////////////////////////////////////////////////// 67 | virtual void parse(sf::String str); 68 | 69 | //-------------------------------------------------------------------- 70 | 71 | //GETTERS/SETTERS ---------------------------------------------------- 72 | public: 73 | //////////////////////////////////////////////////////////// 74 | /// 75 | /// \param value the new value 76 | /// 77 | //////////////////////////////////////////////////////////// 78 | void setValue(sf::Uint64 value); 79 | 80 | //////////////////////////////////////////////////////////// 81 | /// 82 | /// \return the value of the last string parsed 83 | /// 84 | //////////////////////////////////////////////////////////// 85 | sf::Uint64 getValue() const; 86 | //-------------------------------------------------------------------- 87 | 88 | //FIELDS ------------------------------------------------------------- 89 | protected: 90 | sf::Uint64 m_value; 91 | //-------------------------------------------------------------------- 92 | }; 93 | 94 | } 95 | } 96 | #endif 97 | 98 | //////////////////////////////////////////////////////////// 99 | /// 100 | /// \class sf::ui::UnsignedLongFormat 101 | /// \brief Format to parse unsigned long 102 | /// \ingroup ui 103 | /// 104 | //////////////////////////////////////////////////////////// 105 | -------------------------------------------------------------------------------- /include/SFML/UI/FormattedTextField.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef FORMATTED_TEXT_FIELD_H 19 | #define FORMATTED_TEXT_FIELD_H 20 | 21 | #include 22 | #include 23 | 24 | namespace sf 25 | { 26 | namespace ui 27 | { 28 | 29 | class FormattedTextField : public TextField 30 | { 31 | public: 32 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 33 | //////////////////////////////////////////////////////////// 34 | /// 35 | /// \brief Creates an empty text field without texture, font ... 36 | /// Then do not forget to set its before displaying it 37 | /// 38 | /// \param format the format of this formatted text field 39 | /// 40 | //////////////////////////////////////////////////////////// 41 | FormattedTextField(Format* format = 0); 42 | 43 | //////////////////////////////////////////////////////////// 44 | /// 45 | /// \brief Creates a text field without font 46 | /// Then do not forget to set the font before displaying it 47 | /// 48 | /// \param texture the texture of the text field 49 | /// \param textureFocused the texture when the text field is focused 50 | /// \param format the format of this formatted text field 51 | /// \param text the default text of the text field 52 | /// 53 | //////////////////////////////////////////////////////////// 54 | FormattedTextField(sf::Texture const &texture, sf::Texture const &textureFocused, Format* format = 0, sf::String const &text = ""); 55 | 56 | //////////////////////////////////////////////////////////// 57 | /// 58 | /// \brief Creates a text field 59 | /// 60 | /// \param texture the texture of the text field 61 | /// \param textureFocused the texture when the text field is focused 62 | /// \param font the text's font 63 | /// \param format the format of this formatted text field 64 | /// \param text the default text of the text field 65 | /// 66 | //////////////////////////////////////////////////////////// 67 | FormattedTextField(sf::Texture const &texture, sf::Texture const &textureFocused, sf::Font const &font, Format* format = 0, sf::String text = ""); 68 | 69 | virtual ~FormattedTextField(); 70 | //-------------------------------------------------------------------- 71 | 72 | //METHODS ------------------------------------------------------------ 73 | protected: 74 | //////////////////////////////////////////////////////////// 75 | /// 76 | /// \brief Called when the component lost focus 77 | /// 78 | //////////////////////////////////////////////////////////// 79 | virtual void lostFocus(); 80 | 81 | //////////////////////////////////////////////////////////// 82 | /// 83 | /// \brief Update the value with the field's text 84 | /// 85 | //////////////////////////////////////////////////////////// 86 | virtual void updateValue(); 87 | //-------------------------------------------------------------------- 88 | 89 | //GETTERS/SETTERS ---------------------------------------------------- 90 | public: 91 | //////////////////////////////////////////////////////////// 92 | /// 93 | /// \return the format 94 | /// 95 | //////////////////////////////////////////////////////////// 96 | const Format* getFormat() const; 97 | 98 | //////////////////////////////////////////////////////////// 99 | /// 100 | /// \return the format 101 | /// 102 | //////////////////////////////////////////////////////////// 103 | Format* getFormat(); 104 | 105 | //////////////////////////////////////////////////////////// 106 | /// 107 | /// \brief Sets the new format of this field, and delete the old one 108 | /// 109 | /// \param format the new format, automatically deleted by the field 110 | /// 111 | //////////////////////////////////////////////////////////// 112 | void setFormat(Format *format); 113 | //-------------------------------------------------------------------- 114 | 115 | //FIELDS ------------------------------------------------------------- 116 | protected: 117 | Format *m_format; 118 | //-------------------------------------------------------------------- 119 | }; 120 | 121 | } 122 | } 123 | #endif 124 | 125 | //////////////////////////////////////////////////////////// 126 | /// 127 | /// \class sf::ui::FormattedTextField 128 | /// \brief A formatted text field which stores a value defined by a sf::ui::Format 129 | /// It can be a sf::Int64, a double, or even a class ... 130 | /// \ingroup ui 131 | /// 132 | //////////////////////////////////////////////////////////// 133 | -------------------------------------------------------------------------------- /include/SFML/UI/IText.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef ITEXT_H_ 19 | #define ITEXT_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class IText 29 | { 30 | public: 31 | //METHODS ------------------------------------------------------------ 32 | virtual ~IText(); 33 | //-------------------------------------------------------------------- 34 | 35 | //GETTERS/SETTERS ---------------------------------------------------- 36 | //////////////////////////////////////////////////////////// 37 | /// 38 | /// \return the text's string 39 | /// 40 | //////////////////////////////////////////////////////////// 41 | virtual const sf::String& getText() const = 0; 42 | 43 | //////////////////////////////////////////////////////////// 44 | /// 45 | /// \brief Sets the text's string of the component 46 | /// Don't forget to set the font 47 | /// 48 | /// \param text the new string of the component 49 | /// 50 | //////////////////////////////////////////////////////////// 51 | virtual void setText(sf::String const &text) = 0; 52 | 53 | //////////////////////////////////////////////////////////// 54 | /// 55 | /// \return the font of the component, if any returns null 56 | /// 57 | //////////////////////////////////////////////////////////// 58 | virtual const sf::Font* getFont() const = 0; 59 | 60 | //////////////////////////////////////////////////////////// 61 | /// 62 | /// \brief Sets the font of the component's text 63 | /// 64 | //////////////////////////////////////////////////////////// 65 | virtual void setFont(sf::Font const &font) = 0; 66 | 67 | //////////////////////////////////////////////////////////// 68 | /// 69 | /// \return the font's size of the component 70 | /// 71 | //////////////////////////////////////////////////////////// 72 | virtual unsigned int getFontSize() const = 0; 73 | 74 | //////////////////////////////////////////////////////////// 75 | /// 76 | /// \brief Set the font's size of the component 77 | /// 78 | /// \param size the font's size 79 | /// 80 | //////////////////////////////////////////////////////////// 81 | virtual void setFontSize(unsigned int size) = 0; 82 | 83 | //////////////////////////////////////////////////////////// 84 | /// 85 | /// \return the font's color of the text 86 | /// 87 | //////////////////////////////////////////////////////////// 88 | virtual sf::Color getFontColor() const = 0; 89 | 90 | //////////////////////////////////////////////////////////// 91 | /// 92 | /// \brief Sets the color's font of the text 93 | /// 94 | /// \param color the text's color 95 | /// 96 | //////////////////////////////////////////////////////////// 97 | virtual void setFontColor(sf::Color color) = 0; 98 | //-------------------------------------------------------------------- 99 | }; 100 | 101 | } /* namespace ui */ 102 | } /* namespace sf */ 103 | #endif /* ITEXT_H_ */ 104 | 105 | //////////////////////////////////////////////////////////// 106 | /// 107 | /// \class sf::ui::IText 108 | /// \brief An interface that allow component to have a text. 109 | /// \ingroup ui 110 | /// 111 | /// Implement it in your component to make faster 112 | /// components that use text. 113 | /// 114 | //////////////////////////////////////////////////////////// 115 | -------------------------------------------------------------------------------- /include/SFML/UI/KeyField.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef KEYFIELD_H_ 19 | #define KEYFIELD_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace sf 26 | { 27 | namespace ui 28 | { 29 | 30 | class KeyField : public Focusable, public IText 31 | { 32 | public: 33 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 34 | //////////////////////////////////////////////////////////// 35 | /// 36 | /// \brief Creates a key field without textures, which store a (keyboard's) key 37 | /// Do not forget to set the textures and fonts later 38 | /// 39 | /// \param key the default key 40 | /// 41 | //////////////////////////////////////////////////////////// 42 | KeyField(sf::Keyboard::Key key); 43 | 44 | //////////////////////////////////////////////////////////// 45 | /// 46 | /// \brief Creates a key field, which store a (keyboard's) key 47 | /// 48 | /// \param texture the texture when the keyfield is not focused 49 | /// \param textureFocused the texture when the keyfield is focused 50 | /// \param font the font of the keyfield 51 | /// \param key the default key 52 | /// 53 | //////////////////////////////////////////////////////////// 54 | KeyField(sf::Texture const &texture, sf::Texture const &textureFocused, sf::Font const &font, sf::Keyboard::Key key); 55 | 56 | 57 | virtual ~KeyField(); 58 | //-------------------------------------------------------------------- 59 | 60 | //METHODS ------------------------------------------------------------ 61 | private: 62 | //////////////////////////////////////////////////////////// 63 | /// 64 | /// \brief Initialize the set of keys allowed 65 | /// 66 | //////////////////////////////////////////////////////////// 67 | void setKeys(); 68 | 69 | protected: 70 | //////////////////////////////////////////////////////////// 71 | /// 72 | /// \brief Draw the component to the render target 73 | /// 74 | //////////////////////////////////////////////////////////// 75 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; 76 | 77 | //////////////////////////////////////////////////////////// 78 | /// 79 | /// \brief Called when the component need update its geometry 80 | /// Inherit when you need to update some sprite 81 | /// 82 | //////////////////////////////////////////////////////////// 83 | virtual void updateCoord(); 84 | 85 | public: 86 | //////////////////////////////////////////////////////////// 87 | /// 88 | /// \brief Update the component each time an event has been polled 89 | /// 90 | /// \param event the window's event polled 91 | /// 92 | //////////////////////////////////////////////////////////// 93 | virtual void updateEvent(sf::Event const &event); 94 | 95 | //////////////////////////////////////////////////////////// 96 | /// 97 | /// \brief Update the component with the main loop's frequency. 98 | /// Can be useful for animation, or time's needed stuff 99 | /// 100 | /// \param delta the time between this update and the last 101 | /// 102 | //////////////////////////////////////////////////////////// 103 | virtual void updateFixed(sf::Time delta); 104 | //-------------------------------------------------------------------- 105 | 106 | //GETTERS/SETTERS ---------------------------------------------------- 107 | //////////////////////////////////////////////////////////// 108 | /// 109 | /// \return the set of the allowed keys 110 | /// 111 | //////////////////////////////////////////////////////////// 112 | const std::set& getAllowedKeys() const; 113 | 114 | //////////////////////////////////////////////////////////// 115 | /// 116 | /// \brief Add a key to the allowed keys set 117 | /// 118 | /// \param key key to allow 119 | /// 120 | //////////////////////////////////////////////////////////// 121 | void addKey(sf::Keyboard::Key key); 122 | 123 | //////////////////////////////////////////////////////////// 124 | /// 125 | /// \return if the key is in the allowed keys 126 | /// 127 | /// \param key key to check 128 | /// 129 | //////////////////////////////////////////////////////////// 130 | bool isKeyAllowed(sf::Keyboard::Key key) const; 131 | 132 | //////////////////////////////////////////////////////////// 133 | /// 134 | /// \brief Remove the key from the allowed keys set 135 | /// 136 | //////////////////////////////////////////////////////////// 137 | void removeKey(sf::Keyboard::Key key); 138 | 139 | //////////////////////////////////////////////////////////// 140 | /// 141 | /// \return the text's string 142 | /// 143 | //////////////////////////////////////////////////////////// 144 | virtual const sf::String& getText() const; 145 | 146 | private: 147 | //////////////////////////////////////////////////////////// 148 | /// 149 | /// \brief Sets the text's string of the component 150 | /// Don't forget to set the font 151 | /// 152 | /// \param text the new string of the component 153 | /// 154 | //////////////////////////////////////////////////////////// 155 | virtual void setText(sf::String const &text); 156 | 157 | public: 158 | //////////////////////////////////////////////////////////// 159 | /// 160 | /// \return the font of the component, or null if any 161 | /// 162 | //////////////////////////////////////////////////////////// 163 | virtual const sf::Font* getFont() const; 164 | 165 | //////////////////////////////////////////////////////////// 166 | /// 167 | /// \brief Sets the font of the component's text 168 | /// 169 | //////////////////////////////////////////////////////////// 170 | virtual void setFont(sf::Font const &font); 171 | 172 | //////////////////////////////////////////////////////////// 173 | /// 174 | /// \return Returns the font's size of the component 175 | /// 176 | //////////////////////////////////////////////////////////// 177 | virtual unsigned int getFontSize() const; 178 | 179 | //////////////////////////////////////////////////////////// 180 | /// 181 | /// \brief Set the font's size of the component 182 | /// 183 | /// \param size the font's size 184 | /// 185 | //////////////////////////////////////////////////////////// 186 | virtual void setFontSize(unsigned int size); 187 | 188 | //////////////////////////////////////////////////////////// 189 | /// 190 | /// \return the font's color of the text 191 | /// 192 | //////////////////////////////////////////////////////////// 193 | virtual sf::Color getFontColor() const; 194 | 195 | //////////////////////////////////////////////////////////// 196 | /// 197 | /// \brief Sets the color's font of the text 198 | /// 199 | /// \param color the text's color 200 | /// 201 | //////////////////////////////////////////////////////////// 202 | virtual void setFontColor(sf::Color color); 203 | //-------------------------------------------------------------------- 204 | 205 | //FIELDS ------------------------------------------------------------- 206 | protected: 207 | sf::Text m_text; 208 | sf::Keyboard::Key m_key; 209 | std::set m_keysAllowed; 210 | //-------------------------------------------------------------------- 211 | }; 212 | 213 | } /* namespace ui */ 214 | } /* namespace sf */ 215 | #endif /* KEYFIELD_H_ */ 216 | 217 | //////////////////////////////////////////////////////////// 218 | /// 219 | /// \class sf::ui::KeyField 220 | /// \brief A field that stores a keyboard's key 221 | /// Not supported on mobile platforms 222 | /// \ingroup ui 223 | /// 224 | //////////////////////////////////////////////////////////// 225 | -------------------------------------------------------------------------------- /include/SFML/UI/Label.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef LABEL_H_ 19 | #define LABEL_H_ 20 | 21 | #include 22 | #include 23 | 24 | namespace sf 25 | { 26 | namespace ui 27 | { 28 | 29 | class Label : public Component, public IText 30 | { 31 | public: 32 | 33 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 34 | 35 | //////////////////////////////////////////////////////////// 36 | /// 37 | /// \brief Creates an empty label 38 | /// 39 | //////////////////////////////////////////////////////////// 40 | Label(); 41 | 42 | //////////////////////////////////////////////////////////// 43 | /// 44 | /// \brief Creates a label-image 45 | /// 46 | /// \param image the label's image 47 | /// 48 | //////////////////////////////////////////////////////////// 49 | Label(sf::Texture const &image); 50 | 51 | //////////////////////////////////////////////////////////// 52 | /// 53 | /// \brief Creates a text label 54 | /// 55 | /// \param font the text's font 56 | /// \param text the text's string 57 | /// \param fontSize the fint's size 58 | /// 59 | //////////////////////////////////////////////////////////// 60 | Label(sf::Font const &font, sf::String const &text, int fontSize = 35); 61 | 62 | virtual ~Label(); 63 | //-------------------------------------------------------------------- 64 | 65 | //METHODS ------------------------------------------------------------ 66 | public: 67 | //////////////////////////////////////////////////////////// 68 | /// 69 | /// \brief Update the component each time an event has been polled 70 | /// 71 | /// \param event the window's event polled 72 | /// 73 | //////////////////////////////////////////////////////////// 74 | virtual void updateEvent(sf::Event const &event); 75 | 76 | //////////////////////////////////////////////////////////// 77 | /// 78 | /// \brief Update the component with the main loop's frequency 79 | /// Can be useful for animation, or time's needed stuff 80 | /// 81 | /// \param delta - the time between this update and the last 82 | /// 83 | //////////////////////////////////////////////////////////// 84 | virtual void updateFixed(sf::Time delta); 85 | 86 | protected: 87 | //////////////////////////////////////////////////////////// 88 | /// 89 | /// \brief Draw the component to the render target 90 | /// 91 | //////////////////////////////////////////////////////////// 92 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; 93 | 94 | //////////////////////////////////////////////////////////// 95 | /// 96 | /// \brief Called when the component need update its geometry 97 | ///Inherit when you need to update some sprite 98 | /// 99 | //////////////////////////////////////////////////////////// 100 | virtual void updateCoord(); 101 | //-------------------------------------------------------------------- 102 | 103 | //GETTERS/SETTERS ---------------------------------------------------- 104 | public: 105 | //////////////////////////////////////////////////////////// 106 | /// 107 | /// \return the text's string 108 | /// 109 | //////////////////////////////////////////////////////////// 110 | virtual const sf::String& getText() const; 111 | 112 | //////////////////////////////////////////////////////////// 113 | /// 114 | /// \brief Sets the text's string of the component 115 | /// Don't forget to set the font 116 | /// 117 | /// \param text the new string of the component 118 | /// 119 | //////////////////////////////////////////////////////////// 120 | virtual void setText(sf::String const &text); 121 | 122 | //////////////////////////////////////////////////////////// 123 | /// 124 | /// \return the font of the component, if any returns null 125 | /// 126 | //////////////////////////////////////////////////////////// 127 | virtual const sf::Font* getFont() const; 128 | 129 | //////////////////////////////////////////////////////////// 130 | /// 131 | /// \brief Sets the font of the component's text 132 | /// 133 | //////////////////////////////////////////////////////////// 134 | virtual void setFont(sf::Font const &font); 135 | 136 | //////////////////////////////////////////////////////////// 137 | /// 138 | /// \return the font's size of the component 139 | /// 140 | //////////////////////////////////////////////////////////// 141 | virtual unsigned int getFontSize() const; 142 | 143 | //////////////////////////////////////////////////////////// 144 | /// 145 | /// \brief Set the font's size of the component 146 | /// 147 | /// \param size the font's size 148 | /// 149 | //////////////////////////////////////////////////////////// 150 | virtual void setFontSize(unsigned int size); 151 | 152 | //////////////////////////////////////////////////////////// 153 | /// 154 | /// \return the font's color of the text 155 | /// 156 | //////////////////////////////////////////////////////////// 157 | virtual sf::Color getFontColor() const; 158 | 159 | //////////////////////////////////////////////////////////// 160 | /// 161 | /// \brief Sets the color's font of the text 162 | /// 163 | /// \param color the text's color 164 | /// 165 | //////////////////////////////////////////////////////////// 166 | virtual void setFontColor(sf::Color color); 167 | 168 | //////////////////////////////////////////////////////////// 169 | /// 170 | /// \return the label's image or null 171 | /// Similar to getTexture() 172 | /// 173 | //////////////////////////////////////////////////////////// 174 | const sf::Texture* getImage() const; 175 | 176 | //////////////////////////////////////////////////////////// 177 | /// 178 | /// \brief Sets the label's image 179 | /// Similar to setTexture(sf::Texture const&) 180 | /// 181 | //////////////////////////////////////////////////////////// 182 | void setImage(sf::Texture const &image); 183 | 184 | /////////////////////////////////////////////////////////// 185 | /// 186 | /// \return the size of the label 187 | /// 188 | //////////////////////////////////////////////////////////// 189 | virtual sf::Vector2f getSize() const; 190 | //-------------------------------------------------------------------- 191 | 192 | //FIELDS ------------------------------------------------------------- 193 | protected: 194 | sf::Text m_text; 195 | //-------------------------------------------------------------------- 196 | }; 197 | 198 | } /* namespace ui */ 199 | } /* namespace sf */ 200 | #endif /* LABEL_H_ */ 201 | 202 | //////////////////////////////////////////////////////////// 203 | /// 204 | /// \class sf::ui::Label 205 | /// \brief A label which show text or image 206 | /// \ingroup ui 207 | /// 208 | //////////////////////////////////////////////////////////// 209 | -------------------------------------------------------------------------------- /include/SFML/UI/Model/AlphaNumericTextFieldModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef ALPHANUMERICTEXTFIELDMODEL_H_ 19 | #define ALPHANUMERICTEXTFIELDMODEL_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class AlphaNumericTextFieldModel : public WhitelistTextFieldModel 29 | { 30 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 31 | public: 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief A text field model that allows letters and numbers, 35 | /// only character between 'A' - 'Z', 'a' - 'z', '0' - '9' and '-'. 36 | /// 37 | //////////////////////////////////////////////////////////// 38 | AlphaNumericTextFieldModel(); 39 | 40 | virtual ~AlphaNumericTextFieldModel(); 41 | //-------------------------------------------------------------------- 42 | 43 | //METHODS ------------------------------------------------------------ 44 | 45 | //-------------------------------------------------------------------- 46 | 47 | //GETTERS/SETTERS ---------------------------------------------------- 48 | 49 | //-------------------------------------------------------------------- 50 | 51 | //FIELDS ------------------------------------------------------------- 52 | 53 | //-------------------------------------------------------------------- 54 | }; 55 | 56 | } /* namespace ui */ 57 | } /* namespace sf */ 58 | #endif /* ALPHANUMERICTEXTFIELDMODEL_H_ */ 59 | 60 | //////////////////////////////////////////////////////////// 61 | /// 62 | /// \class sf::ui::AlphaNumericTextFieldModel 63 | /// \brief A textfield model that allows all alpha-numeric chars 64 | /// \ingroup ui 65 | /// 66 | //////////////////////////////////////////////////////////// 67 | -------------------------------------------------------------------------------- /include/SFML/UI/Model/AlphaTextFieldModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef ALPHATEXTFIELDMODEL_H_ 19 | #define ALPHATEXTFIELDMODEL_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class AlphaTextFieldModel : public WhitelistTextFieldModel 29 | { 30 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 31 | public: 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief An alphabetic text field model that allows 35 | /// only character in range 'A' - 'Z' and 'a' - 'z' 36 | /// 37 | //////////////////////////////////////////////////////////// 38 | AlphaTextFieldModel(); 39 | 40 | virtual ~AlphaTextFieldModel(); 41 | //-------------------------------------------------------------------- 42 | 43 | //METHODS ------------------------------------------------------------ 44 | 45 | //-------------------------------------------------------------------- 46 | 47 | //GETTERS/SETTERS ---------------------------------------------------- 48 | 49 | //-------------------------------------------------------------------- 50 | 51 | //FIELDS ------------------------------------------------------------- 52 | 53 | //-------------------------------------------------------------------- 54 | }; 55 | 56 | } /* namespace ui */ 57 | } /* namespace sf */ 58 | #endif /* ALPHATEXTFIELDMODEL_H_ */ 59 | 60 | //////////////////////////////////////////////////////////// 61 | /// 62 | /// \class sf::ui::AlphaTextFieldModel 63 | /// \brief A textfield model that allows only letters 64 | /// \ingroup ui 65 | /// 66 | //////////////////////////////////////////////////////////// 67 | -------------------------------------------------------------------------------- /include/SFML/UI/Model/AsciiNoSpaceTextFieldModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef ASCII_NO_SPACE_TEXT_FIELD_MODEL_H_ 19 | #define ASCII_NO_SPACE_TEXT_FIELD_MODEL_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class AsciiNoSpaceTextFieldModel : public TextFieldModel 29 | { 30 | public: 31 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief A textfield model which allow all ASCII characters 35 | /// i.e all characters between 32 (' ' exclude) and 126 (include) 36 | /// as 127 is backspace 37 | /// 38 | //////////////////////////////////////////////////////////// 39 | AsciiNoSpaceTextFieldModel(); 40 | virtual ~AsciiNoSpaceTextFieldModel(); 41 | //-------------------------------------------------------------------- 42 | 43 | //METHODS ------------------------------------------------------------ 44 | //////////////////////////////////////////////////////////// 45 | /// 46 | /// \return if the given character is allowed for the text field 47 | /// 48 | /// \param c the character to check 49 | /// 50 | //////////////////////////////////////////////////////////// 51 | virtual bool isCharAllowed(sf::Uint32 c) const; 52 | //-------------------------------------------------------------------- 53 | 54 | //GETTERS/SETTERS ---------------------------------------------------- 55 | 56 | //-------------------------------------------------------------------- 57 | 58 | //FIELDS ------------------------------------------------------------- 59 | 60 | //-------------------------------------------------------------------- 61 | }; 62 | 63 | } /* namespace ui */ 64 | } /* namespace sf */ 65 | #endif /* ASCII_NO_SPACE_TEXT_FIELD_MODEL_H_ */ 66 | 67 | //////////////////////////////////////////////////////////// 68 | /// 69 | /// \class sf::ui::AsciiNoSpaceTextFieldModel 70 | /// \brief A textfield model that allows only ASCII chars, without spaces 71 | /// \ingroup ui 72 | /// 73 | //////////////////////////////////////////////////////////// 74 | -------------------------------------------------------------------------------- /include/SFML/UI/Model/AsciiTextFieldModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef ASCIITEXTFIELDMODEL_H_ 19 | #define ASCIITEXTFIELDMODEL_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class AsciiTextFieldModel : public TextFieldModel 29 | { 30 | public: 31 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief A textfield model which allow all ASCII characters 35 | /// i.e all characters between 32 (include) and 126 (include) 36 | /// as 127 is backspace 37 | /// 38 | //////////////////////////////////////////////////////////// 39 | AsciiTextFieldModel(); 40 | virtual ~AsciiTextFieldModel(); 41 | //-------------------------------------------------------------------- 42 | 43 | //METHODS ------------------------------------------------------------ 44 | //////////////////////////////////////////////////////////// 45 | /// 46 | /// \return if the given character is allowed for the text field 47 | /// 48 | /// \param c the character to check 49 | /// 50 | //////////////////////////////////////////////////////////// 51 | virtual bool isCharAllowed(sf::Uint32 c) const; 52 | //-------------------------------------------------------------------- 53 | 54 | //GETTERS/SETTERS ---------------------------------------------------- 55 | 56 | //-------------------------------------------------------------------- 57 | 58 | //FIELDS ------------------------------------------------------------- 59 | 60 | //-------------------------------------------------------------------- 61 | }; 62 | 63 | } /* namespace ui */ 64 | } /* namespace sf */ 65 | #endif /* ASCIITEXTFIELDMODEL_H_ */ 66 | 67 | //////////////////////////////////////////////////////////// 68 | /// 69 | /// \class sf::ui::AsciiTextFieldModel 70 | /// \brief A textfield model that allows only ASCII chars 71 | /// \ingroup ui 72 | /// 73 | //////////////////////////////////////////////////////////// 74 | -------------------------------------------------------------------------------- /include/SFML/UI/Model/BlacklistTextFieldModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef BLACKLISTTEXTFIELDMODEL_H_ 19 | #define BLACKLISTTEXTFIELDMODEL_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace sf 26 | { 27 | namespace ui 28 | { 29 | 30 | class BlacklistTextFieldModel : public TextFieldModel 31 | { 32 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 33 | public: 34 | //////////////////////////////////////////////////////////// 35 | /// 36 | /// \brief Creates a text field model that denies character present in the blacklist 37 | /// Notice that the blacklist is empty in this class 38 | /// 39 | //////////////////////////////////////////////////////////// 40 | BlacklistTextFieldModel(); 41 | 42 | virtual ~BlacklistTextFieldModel(); 43 | //-------------------------------------------------------------------- 44 | 45 | //METHODS ------------------------------------------------------------ 46 | //////////////////////////////////////////////////////////// 47 | /// 48 | /// \return if the given character is allowed for the text field 49 | /// 50 | /// \param c the character to check 51 | /// 52 | //////////////////////////////////////////////////////////// 53 | virtual bool isCharAllowed(sf::Uint32 c) const; 54 | 55 | //////////////////////////////////////////////////////////// 56 | /// 57 | /// \brief Add a character to the blacklist 58 | /// 59 | /// \param c the character to deny 60 | /// 61 | //////////////////////////////////////////////////////////// 62 | void addCharDenied(sf::Uint32 c); 63 | 64 | //////////////////////////////////////////////////////////// 65 | /// 66 | /// \brief Removes a character to the blacklist 67 | /// 68 | /// \param c the character to allow 69 | /// 70 | //////////////////////////////////////////////////////////// 71 | void rmCharDenied(sf::Uint32 c); 72 | //-------------------------------------------------------------------- 73 | 74 | //GETTERS/SETTERS ---------------------------------------------------- 75 | public: 76 | //////////////////////////////////////////////////////////// 77 | /// 78 | /// \return all of the chars blacklisted 79 | /// 80 | //////////////////////////////////////////////////////////// 81 | std::vector getCharsDenied() const; 82 | //-------------------------------------------------------------------- 83 | 84 | //FIELDS ------------------------------------------------------------- 85 | protected: 86 | std::set m_blacklist; 87 | //-------------------------------------------------------------------- 88 | }; 89 | 90 | } /* namespace ui */ 91 | } /* namespace sf */ 92 | #endif /* BLACKLISTTEXTFIELDMODEL_H_ */ 93 | 94 | //////////////////////////////////////////////////////////// 95 | /// 96 | /// \class sf::ui::BlacklistTextFieldModel 97 | /// \brief A textfield model that denies some chars 98 | /// \ingroup ui 99 | /// 100 | //////////////////////////////////////////////////////////// 101 | -------------------------------------------------------------------------------- /include/SFML/UI/Model/DefaultTextFieldModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef DEFAULTTEXTFIELDMODEL_H_ 19 | #define DEFAULTTEXTFIELDMODEL_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class DefaultTextFieldModel : public BlacklistTextFieldModel 29 | { 30 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 31 | public: 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief The default text field model used 35 | /// It allows all character excluding 0(NUL) - 31(US) and 127(DEL) 36 | /// 37 | //////////////////////////////////////////////////////////// 38 | DefaultTextFieldModel(); 39 | 40 | virtual ~DefaultTextFieldModel(); 41 | //-------------------------------------------------------------------- 42 | 43 | //METHODS ------------------------------------------------------------ 44 | 45 | //-------------------------------------------------------------------- 46 | 47 | //GETTERS/SETTERS ---------------------------------------------------- 48 | 49 | //-------------------------------------------------------------------- 50 | 51 | //FIELDS ------------------------------------------------------------- 52 | 53 | //-------------------------------------------------------------------- 54 | }; 55 | 56 | } /* namespace ui */ 57 | } /* namespace sf */ 58 | #endif /* DEFAULTTEXTFIELDMODEL_H_ */ 59 | 60 | //////////////////////////////////////////////////////////// 61 | /// 62 | /// \class sf::ui::DefaultTextFieldModel 63 | /// \brief The default textfield model 64 | /// \ingroup ui 65 | /// 66 | //////////////////////////////////////////////////////////// 67 | -------------------------------------------------------------------------------- /include/SFML/UI/Model/NumericTextFieldModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef NUMERICTEXTFIELDMODEL_H_ 19 | #define NUMERICTEXTFIELDMODEL_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class NumericTextFieldModel : public WhitelistTextFieldModel 29 | { 30 | public: 31 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief A text field model that allows only number ('0' - '9') and point ('.') 35 | /// 36 | //////////////////////////////////////////////////////////// 37 | NumericTextFieldModel(); 38 | 39 | virtual ~NumericTextFieldModel(); 40 | //-------------------------------------------------------------------- 41 | 42 | //METHODS ------------------------------------------------------------ 43 | 44 | //-------------------------------------------------------------------- 45 | 46 | //GETTERS/SETTERS ---------------------------------------------------- 47 | 48 | //-------------------------------------------------------------------- 49 | 50 | //FIELDS ------------------------------------------------------------- 51 | 52 | //-------------------------------------------------------------------- 53 | }; 54 | 55 | } /* namespace ui */ 56 | } /* namespace sf */ 57 | #endif /* NUMERICTEXTFIELDMODEL_H_ */ 58 | 59 | //////////////////////////////////////////////////////////// 60 | /// 61 | /// \class sf::ui::NumericTextFieldModel 62 | /// \brief A textfield model that allows only numbers 63 | /// \ingroup ui 64 | /// 65 | //////////////////////////////////////////////////////////// 66 | -------------------------------------------------------------------------------- /include/SFML/UI/Model/TextFieldModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef TEXTFIELDMODEL_H_ 19 | #define TEXTFIELDMODEL_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class TextFieldModel 29 | { 30 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 31 | public: 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief An abstract class that controls if the text field should or not allow a given character 35 | /// 36 | //////////////////////////////////////////////////////////// 37 | TextFieldModel(); 38 | virtual ~TextFieldModel(); 39 | //-------------------------------------------------------------------- 40 | 41 | //METHODS ------------------------------------------------------------ 42 | //////////////////////////////////////////////////////////// 43 | /// 44 | /// \return if the given character is allowed for the text field 45 | /// 46 | /// \param c - the character to check 47 | /// 48 | //////////////////////////////////////////////////////////// 49 | virtual bool isCharAllowed(sf::Uint32 c) const = 0; 50 | //-------------------------------------------------------------------- 51 | 52 | //GETTERS/SETTERS ---------------------------------------------------- 53 | 54 | //-------------------------------------------------------------------- 55 | 56 | //FIELDS ------------------------------------------------------------- 57 | 58 | //-------------------------------------------------------------------- 59 | }; 60 | 61 | } /* namespace ui */ 62 | } /* namespace sf */ 63 | #endif /* TEXTFIELDMODEL_H_ */ 64 | 65 | //////////////////////////////////////////////////////////// 66 | /// 67 | /// \class sf::ui::TextFieldModel 68 | /// \brief The abstract class that defines what can be typed into the text field 69 | /// \ingroup ui 70 | /// 71 | //////////////////////////////////////////////////////////// 72 | -------------------------------------------------------------------------------- /include/SFML/UI/Model/WhitelistTextFieldModel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef WITHELISTTEXTFIELDMODEL_H_ 19 | #define WITHELISTTEXTFIELDMODEL_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace sf 26 | { 27 | namespace ui 28 | { 29 | 30 | class WhitelistTextFieldModel : public TextFieldModel 31 | { 32 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 33 | public: 34 | //////////////////////////////////////////////////////////// 35 | /// 36 | /// \brief Creates a text field model that allows only character present in the whitelist 37 | /// Notice that the whitelist is empty in this class 38 | /// 39 | //////////////////////////////////////////////////////////// 40 | WhitelistTextFieldModel(); 41 | 42 | virtual ~WhitelistTextFieldModel(); 43 | //-------------------------------------------------------------------- 44 | 45 | //METHODS ------------------------------------------------------------ 46 | public: 47 | //////////////////////////////////////////////////////////// 48 | /// 49 | /// \return if the given character is allowed for the text field 50 | /// 51 | /// \param c the character to check 52 | /// 53 | //////////////////////////////////////////////////////////// 54 | virtual bool isCharAllowed(sf::Uint32 c) const; 55 | 56 | //////////////////////////////////////////////////////////// 57 | /// 58 | /// \brief Add a character to the whitelist 59 | /// 60 | /// \param c the character to allow 61 | /// 62 | //////////////////////////////////////////////////////////// 63 | void addCharAllowed(sf::Uint32 c); 64 | 65 | //////////////////////////////////////////////////////////// 66 | /// 67 | /// \brief Remove a character to the whitelist 68 | /// 69 | /// \param c the character to disallow 70 | /// 71 | //////////////////////////////////////////////////////////// 72 | void rmCharAllowed(sf::Uint32 c); 73 | //-------------------------------------------------------------------- 74 | 75 | //GETTERS/SETTERS ---------------------------------------------------- 76 | public: 77 | //////////////////////////////////////////////////////////// 78 | /// 79 | /// \return all of the chars whitelisted 80 | /// 81 | //////////////////////////////////////////////////////////// 82 | std::vector getCharsAllowed() const; 83 | //-------------------------------------------------------------------- 84 | 85 | //FIELDS ------------------------------------------------------------- 86 | protected: 87 | std::set m_whitelist; 88 | //-------------------------------------------------------------------- 89 | }; 90 | 91 | } /* namespace ui */ 92 | } /* namespace sf */ 93 | #endif /* WHITELISTTEXTFIELDMODEL_H_ */ 94 | 95 | //////////////////////////////////////////////////////////// 96 | /// 97 | /// \class sf::ui::WhitelistTextFieldModel 98 | /// \brief A textfield model that allows some chars 99 | /// \ingroup ui 100 | /// 101 | //////////////////////////////////////////////////////////// 102 | -------------------------------------------------------------------------------- /include/SFML/UI/PasswordField.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef PASSWORD_FIELD_H 19 | #define PASSWORD_FIELD_H 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class PasswordField : public TextField 29 | { 30 | public: 31 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 32 | //////////////////////////////////////////////////////////// 33 | /// 34 | /// \brief Creates an empty password field without texture, font ... 35 | /// Then do not forget to set its before displaying it 36 | /// 37 | //////////////////////////////////////////////////////////// 38 | PasswordField(); 39 | 40 | //////////////////////////////////////////////////////////// 41 | /// 42 | /// \brief Creates a password field without font 43 | /// Then do not forget to set the font before displaying it 44 | /// 45 | /// \param texture the texture of the text field 46 | /// \param textureFocused the texture when the text field is focused 47 | /// 48 | //////////////////////////////////////////////////////////// 49 | PasswordField(sf::Texture const &texture, sf::Texture const &textureFocused); 50 | 51 | //////////////////////////////////////////////////////////// 52 | /// 53 | /// \brief Creates a password field 54 | /// 55 | /// \param texture the texture of the text field 56 | /// \param textureFocused the texture when the text field is focused 57 | /// \param font the text's font 58 | /// 59 | //////////////////////////////////////////////////////////// 60 | PasswordField(sf::Texture const &texture, sf::Texture const &textureFocused, sf::Font const &font); 61 | 62 | virtual ~PasswordField(); 63 | //-------------------------------------------------------------------- 64 | 65 | //METHODS ------------------------------------------------------------ 66 | protected: 67 | //////////////////////////////////////////////////////////// 68 | /// 69 | /// \brief Insert a char at the given index 70 | /// Trigger a TextEnteredEvent 71 | /// 72 | /// \param text the text to insert 73 | /// \param index the index of the insertion 74 | /// 75 | /// \return if the text has been successfully inserted 76 | /// 77 | //////////////////////////////////////////////////////////// 78 | virtual bool insertText(sf::Uint32 text, unsigned int index); 79 | 80 | //////////////////////////////////////////////////////////// 81 | /// 82 | /// \brief Delete the char at the given index 83 | /// Trigger a TextDeletedEvent 84 | /// 85 | /// \param index the index of the char to delete 86 | /// 87 | /// \return if the text has been successfully deleted 88 | /// 89 | //////////////////////////////////////////////////////////// 90 | virtual bool deleteText(unsigned int index); 91 | 92 | //////////////////////////////////////////////////////////// 93 | /// 94 | /// \brief Replace the TextField's chars by '•' 95 | /// 96 | //////////////////////////////////////////////////////////// 97 | void replaceTextDisplayed(); 98 | //-------------------------------------------------------------------- 99 | 100 | //GETTERS/SETTERS ---------------------------------------------------- 101 | public: 102 | 103 | //////////////////////////////////////////////////////////// 104 | /// 105 | /// \return the password stored 106 | /// 107 | //////////////////////////////////////////////////////////// 108 | const sf::String& getPassword() const; 109 | 110 | //////////////////////////////////////////////////////////// 111 | /// 112 | /// \brief Sets the password of the component 113 | /// Don't forget to set the font 114 | /// 115 | /// \param password the new password of the component 116 | /// 117 | //////////////////////////////////////////////////////////// 118 | void setPassword(sf::String const &password); 119 | 120 | //-------------------------------------------------------------------- 121 | 122 | //FIELDS ------------------------------------------------------------- 123 | protected: 124 | sf::String m_password; 125 | //-------------------------------------------------------------------- 126 | }; 127 | 128 | } 129 | } 130 | 131 | //////////////////////////////////////////////////////////// 132 | /// 133 | /// \class sf::ui::PasswordField 134 | /// \brief A text field which stores a password 135 | /// \ingroup ui 136 | /// 137 | //////////////////////////////////////////////////////////// 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /include/SFML/UI/SFMLUtils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef SFMLUTILS_H_ 19 | #define SFMLUTILS_H_ 20 | 21 | #include 22 | 23 | namespace sf 24 | { 25 | namespace ui 26 | { 27 | 28 | class SFMLUtils 29 | { 30 | //CONSTRUCTORS/DESTRUCTORS ------------------------------------------- 31 | private: 32 | SFMLUtils(); 33 | public: 34 | virtual ~SFMLUtils(); 35 | //-------------------------------------------------------------------- 36 | 37 | //METHODS ------------------------------------------------------------ 38 | public: 39 | //////////////////////////////////////////////////////////// 40 | /// 41 | /// \return the local size of the text 42 | /// 43 | /// \param text the text to check size 44 | /// 45 | //////////////////////////////////////////////////////////// 46 | static sf::Vector2f getLocalSize(const sf::Text& text); 47 | 48 | //////////////////////////////////////////////////////////// 49 | /// 50 | /// \return string that describes the key 51 | /// 52 | /// \param key the key to convert to string 53 | /// 54 | //////////////////////////////////////////////////////////// 55 | static sf::String keyToString(sf::Keyboard::Key key); 56 | //-------------------------------------------------------------------- 57 | 58 | //GETTERS/SETTERS ---------------------------------------------------- 59 | 60 | //-------------------------------------------------------------------- 61 | 62 | //FIELDS ------------------------------------------------------------- 63 | 64 | //-------------------------------------------------------------------- 65 | }; 66 | 67 | } /* namespace ui */ 68 | } /* namespace sf */ 69 | #endif /* SFMLUTILS_H_ */ 70 | 71 | //////////////////////////////////////////////////////////// 72 | /// 73 | /// \class sf::ui::SFMLUtils 74 | /// \brief A utility class 75 | /// \ingroup ui 76 | /// 77 | //////////////////////////////////////////////////////////// 78 | -------------------------------------------------------------------------------- /src/SFML/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | LOCAL_MODULE := sfml-ui 5 | LOCAL_SRC_FILES := lib/$(TARGET_ARCH_ABI)/libsfml-ui.a 6 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include 7 | LOCAL_SHARED_LIBRARIES += sfml-system sfml-window sfml-graphics 8 | include $(PREBUILT_STATIC_LIBRARY) 9 | 10 | $(call import-module,sfml) 11 | -------------------------------------------------------------------------------- /src/SFML/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # include the SFML specific macros 3 | include(${PROJECT_SOURCE_DIR}/cmake/Macros.cmake) 4 | 5 | # add the SFML sources path 6 | include_directories(${PROJECT_SOURCE_DIR}/src) 7 | 8 | # define the path of our additional CMake modules 9 | set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/") 10 | 11 | # set the output directory for SFML libraries 12 | set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib") 13 | 14 | # add the modules subdirectories 15 | add_subdirectory(UI) 16 | -------------------------------------------------------------------------------- /src/SFML/UI/AbstractButton.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | using namespace sf::ui; 22 | 23 | AbstractButton::AbstractButton() 24 | : Focusable() 25 | { 26 | 27 | } 28 | 29 | AbstractButton::AbstractButton(const sf::Texture& texture, const sf::Texture& textureFocused) 30 | : Focusable(texture, textureFocused) 31 | { 32 | 33 | } 34 | 35 | AbstractButton::~AbstractButton() 36 | { 37 | 38 | } 39 | 40 | void AbstractButton::updateEvent(const sf::Event& event) 41 | { 42 | switch(event.type) 43 | { 44 | case sf::Event::MouseButtonReleased: 45 | 46 | if (checkClickOn(event.mouseButton.x, event.mouseButton.y)) 47 | { 48 | sf::ui::ComponentEvent cevent; 49 | cevent.source = this; 50 | cevent.type = sf::ui::ComponentEvent::ButtonClicked; 51 | cevent.buttonClick.source = this; 52 | cevent.buttonClick.button = event.mouseButton.button; 53 | cevent.buttonClick.x = event.mouseButton.x; 54 | cevent.buttonClick.y = event.mouseButton.y; 55 | onClick(); 56 | triggerEvent(cevent); 57 | } 58 | 59 | break; 60 | case sf::Event::TouchEnded: 61 | 62 | if (checkClickOn(event.touch.x, event.touch.y)) 63 | { 64 | sf::ui::ComponentEvent cevent; 65 | cevent.source = this; 66 | cevent.type = sf::ui::ComponentEvent::ButtonTouched; 67 | cevent.buttonTouch.source = this; 68 | cevent.buttonTouch.finger = event.touch.finger; 69 | cevent.buttonTouch.x = event.touch.x; 70 | cevent.buttonTouch.y = event.touch.y; 71 | onClick(); 72 | triggerEvent(cevent); 73 | } 74 | 75 | break; 76 | default: 77 | break; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/SFML/UI/Button.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace sf::ui; 23 | 24 | Button::~Button() 25 | { 26 | delete m_task; 27 | } 28 | 29 | void Button::updateEvent(const sf::Event& event) 30 | { 31 | if (event.type == sf::Event::MouseMoved || event.type == sf::Event::TouchMoved) 32 | { 33 | int x = (event.type == sf::Event::MouseMoved ? event.mouseMove.x : event.touch.x); 34 | int y = (event.type == sf::Event::MouseMoved ? event.mouseMove.y : event.touch.y); 35 | 36 | setFocused(isCoordOnComponent(x, y)); 37 | 38 | if (m_focused && (event.type == sf::Event::MouseMoved ? sf::Mouse::isButtonPressed(sf::Mouse::Left) : true) && m_textureFired) 39 | m_sprite.setTexture(*m_textureFired, false); 40 | else if (m_focused && m_textureFocused) 41 | m_sprite.setTexture(*m_textureFocused, false); 42 | else 43 | m_sprite.setTexture(*m_texture, false); 44 | } 45 | else if (event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::TouchBegan) 46 | { 47 | int x = (event.type == sf::Event::MouseButtonPressed ? event.mouseButton.x : event.touch.x); 48 | int y = (event.type == sf::Event::MouseButtonPressed ? event.mouseButton.y : event.touch.y); 49 | 50 | 51 | if (event.type != sf::Event::MouseButtonPressed || event.mouseButton.button == sf::Mouse::Left) 52 | { 53 | m_clicked = checkClickOn(x, y); 54 | 55 | if (m_clicked && m_textureFired) 56 | m_sprite.setTexture(*m_textureFired, false); 57 | else if (m_clicked) 58 | m_sprite.setTexture(*m_textureFocused, false); 59 | } 60 | 61 | } 62 | else if (event.type == sf::Event::MouseButtonReleased || event.type == sf::Event::TouchEnded) 63 | { 64 | int x = (event.type == sf::Event::MouseButtonReleased ? event.mouseButton.x : event.touch.x); 65 | int y = (event.type == sf::Event::MouseButtonReleased ? event.mouseButton.y : event.touch.y); 66 | 67 | if (event.type != sf::Event::MouseButtonPressed || event.mouseButton.button == sf::Mouse::Left) 68 | { 69 | if (isCoordOnComponent(x, y) && m_textureFocused) 70 | { 71 | onClick(); 72 | if (event.type == sf::Event::MouseButtonReleased) 73 | { 74 | sf::ui::ComponentEvent cevent; 75 | cevent.source = this; 76 | cevent.type = sf::ui::ComponentEvent::ButtonClicked; 77 | cevent.buttonClick.source = this; 78 | cevent.buttonClick.button = event.mouseButton.button; 79 | cevent.buttonClick.x = event.mouseButton.x; 80 | cevent.buttonClick.y = event.mouseButton.y; 81 | triggerEvent(cevent); 82 | } 83 | else if (event.type == sf::Event::TouchEnded) 84 | { 85 | sf::ui::ComponentEvent cevent; 86 | cevent.source = this; 87 | cevent.type = sf::ui::ComponentEvent::ButtonTouched; 88 | cevent.buttonTouch.source = this; 89 | cevent.buttonTouch.finger = event.touch.finger; 90 | cevent.buttonTouch.x = event.touch.x; 91 | cevent.buttonTouch.y = event.touch.y; 92 | triggerEvent(cevent); 93 | } 94 | 95 | m_sprite.setTexture(*m_textureFocused, false); 96 | } 97 | else 98 | m_sprite.setTexture(*m_texture, false); 99 | } 100 | } 101 | 102 | } 103 | 104 | void Button::updateFixed(sf::Time delta) 105 | { 106 | 107 | } 108 | 109 | void Button::doClick() 110 | { 111 | m_clicked = true; 112 | onClick(); 113 | m_clicked = false; 114 | } 115 | 116 | void Button::draw(sf::RenderTarget& target, sf::RenderStates states) const 117 | { 118 | AbstractButton::draw(target, states); 119 | target.draw(m_text, states); 120 | } 121 | 122 | void Button::updateCoord() 123 | { 124 | sf::FloatRect spriteBounds(m_sprite.getGlobalBounds()); 125 | sf::Vector2f pos(m_sprite.getPosition()), size(SFMLUtils::getLocalSize(m_text)); 126 | 127 | m_text.setOrigin(size.x/2.f, size.y/2.f); 128 | m_text.setPosition(pos.x + spriteBounds.width/2.f, pos.y + spriteBounds.height/2.f); 129 | } 130 | 131 | void Button::onClick() 132 | { 133 | if (m_task) 134 | m_task->run(); 135 | } 136 | 137 | bool Button::isFired() const 138 | { 139 | return m_clicked; 140 | } 141 | 142 | const sf::Texture* Button::getTextureFired() const 143 | { 144 | return m_textureFired; 145 | } 146 | 147 | void Button::setTextureFired(const sf::Texture& textureFired) 148 | { 149 | m_textureFired = &textureFired; 150 | } 151 | 152 | const sf::String& Button::getText() const 153 | { 154 | return m_text.getString(); 155 | } 156 | 157 | void Button::setText(const sf::String& text) 158 | { 159 | m_text.setString(text); 160 | updateCoord(); 161 | } 162 | 163 | const sf::Font* Button::getFont() const 164 | { 165 | return m_text.getFont(); 166 | } 167 | 168 | void Button::setFont(const sf::Font& font) 169 | { 170 | m_text.setFont(font); 171 | updateCoord(); 172 | } 173 | 174 | unsigned int Button::getFontSize() const 175 | { 176 | return m_text.getCharacterSize(); 177 | } 178 | 179 | void Button::setFontSize(unsigned int size) 180 | { 181 | m_text.setCharacterSize(size); 182 | updateCoord(); 183 | } 184 | 185 | sf::Color Button::getFontColor() const 186 | { 187 | return m_text.getColor(); 188 | } 189 | 190 | void Button::setFontColor(sf::Color color) 191 | { 192 | m_text.setColor(color); 193 | } 194 | -------------------------------------------------------------------------------- /src/SFML/UI/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(INCROOT ${PROJECT_SOURCE_DIR}/include/SFML/UI) 3 | set(SRCROOT ${PROJECT_SOURCE_DIR}/src/SFML/UI) 4 | 5 | # all source files 6 | set(SRC 7 | ${SRCROOT}/AbstractButton.cpp 8 | ${INCROOT}/AbstractButton.hpp 9 | ${SRCROOT}/Button.cpp 10 | ${INCROOT}/Button.hpp 11 | ${SRCROOT}/CheckBox.cpp 12 | ${INCROOT}/CheckBox.hpp 13 | ${SRCROOT}/CheckBoxGroup.cpp 14 | ${INCROOT}/CheckBoxGroup.hpp 15 | ${SRCROOT}/Component.cpp 16 | ${INCROOT}/Component.hpp 17 | ${INCROOT}/ComponentEvent.hpp 18 | ${SRCROOT}/ComponentObservable.cpp 19 | ${INCROOT}/ComponentObservable.hpp 20 | ${SRCROOT}/ComponentObserver.cpp 21 | ${INCROOT}/ComponentObserver.hpp 22 | ${SRCROOT}/Focusable.cpp 23 | ${INCROOT}/Focusable.hpp 24 | ${SRCROOT}/FormattedTextField.cpp 25 | ${INCROOT}/FormattedTextField.hpp 26 | ${SRCROOT}/IText.cpp 27 | ${INCROOT}/IText.hpp 28 | ${SRCROOT}/KeyField.cpp 29 | ${INCROOT}/KeyField.hpp 30 | ${SRCROOT}/Label.cpp 31 | ${INCROOT}/Label.hpp 32 | ${SRCROOT}/PasswordField.cpp 33 | ${INCROOT}/PasswordField.hpp 34 | ${SRCROOT}/SFMLUtils.cpp 35 | ${INCROOT}/SFMLUtils.hpp 36 | ${SRCROOT}/TextField.cpp 37 | ${INCROOT}/TextField.hpp 38 | ) 39 | source_group("" FILES ${SRC}) 40 | 41 | # format sources 42 | set(FORMAT_SRC 43 | ${SRCROOT}/Format/DoubleFormat.cpp 44 | ${INCROOT}/Format/DoubleFormat.hpp 45 | ${SRCROOT}/Format/Format.cpp 46 | ${INCROOT}/Format/Format.hpp 47 | ${SRCROOT}/Format/LongFormat.cpp 48 | ${INCROOT}/Format/LongFormat.hpp 49 | ${SRCROOT}/Format/UnsignedLongFormat.cpp 50 | ${INCROOT}/Format/UnsignedLongFormat.hpp 51 | ) 52 | source_group("format" FILES ${FORMAT_SRC}) 53 | 54 | # model sources 55 | set(MODEL_SRC 56 | ${SRCROOT}/Model/AlphaNumericTextFieldModel.cpp 57 | ${INCROOT}/Model/AlphaNumericTextFieldModel.hpp 58 | ${SRCROOT}/Model/AlphaTextFieldModel.cpp 59 | ${INCROOT}/Model/AlphaTextFieldModel.hpp 60 | ${SRCROOT}/Model/AsciiNoSpaceTextFieldModel.cpp 61 | ${INCROOT}/Model/AsciiNoSpaceTextFieldModel.hpp 62 | ${SRCROOT}/Model/AsciiTextFieldModel.cpp 63 | ${INCROOT}/Model/AsciiTextFieldModel.hpp 64 | ${SRCROOT}/Model/BlacklistTextFieldModel.cpp 65 | ${INCROOT}/Model/BlacklistTextFieldModel.hpp 66 | ${SRCROOT}/Model/DefaultTextFieldModel.cpp 67 | ${INCROOT}/Model/DefaultTextFieldModel.hpp 68 | ${SRCROOT}/Model/NumericTextFieldModel.cpp 69 | ${INCROOT}/Model/NumericTextFieldModel.hpp 70 | ${SRCROOT}/Model/TextFieldModel.cpp 71 | ${INCROOT}/Model/TextFieldModel.hpp 72 | ${SRCROOT}/Model/WhitelistTextFieldModel.cpp 73 | ${INCROOT}/Model/WhitelistTextFieldModel.hpp 74 | ) 75 | source_group("model" FILES ${MODEL_SRC}) 76 | 77 | # find external libraries 78 | find_package(SFML 2.2 COMPONENTS graphics window system REQUIRED) 79 | if(NOT SFML_FOUND) 80 | message(FATAL_ERROR "SFML not found !") 81 | endif() 82 | 83 | include_directories(${SFML_INCLUDE_DIR}) 84 | 85 | # build the list of external libraries to link 86 | list(APPEND UI_EXT_LIBS ${SFML_LIBRARIES}) 87 | 88 | # define the sfml-ui target 89 | sfml_add_library(sfml-ui 90 | SOURCES ${SRC} ${FORMAT_SRC} ${MODEL_SRC} 91 | EXTERNAL_LIBS ${UI_EXT_LIBS}) 92 | -------------------------------------------------------------------------------- /src/SFML/UI/CheckBox.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace sf::ui; 23 | 24 | CheckBox::CheckBox(bool selected) 25 | : AbstractButton() 26 | { 27 | setSelected(selected); 28 | } 29 | 30 | CheckBox::CheckBox(const sf::Texture& texture, const sf::Texture& textureSelected, bool selected) 31 | : AbstractButton(texture, textureSelected) 32 | { 33 | setSelected(selected); 34 | } 35 | 36 | CheckBox::CheckBox(const sf::Texture& texture, const sf::Texture& textureSelected, const sf::Font& font, sf::String name, bool selected) 37 | : AbstractButton(texture, textureSelected) 38 | { 39 | setFont(font); 40 | setText(name); 41 | setSelected(selected); 42 | } 43 | 44 | CheckBox::~CheckBox() 45 | { 46 | 47 | } 48 | 49 | void CheckBox::draw(sf::RenderTarget& target, sf::RenderStates states) const 50 | { 51 | AbstractButton::draw(target, states); 52 | 53 | if (m_text.getFont()) 54 | target.draw(m_text, states); 55 | } 56 | 57 | void CheckBox::onClick() 58 | { 59 | setFocused(!m_focused); 60 | 61 | sf::ui::ComponentEvent cevent; 62 | cevent.source = this; 63 | cevent.type = sf::ui::ComponentEvent::CheckBoxChanged; 64 | cevent.checkBoxChange.source = this; 65 | cevent.checkBoxChange.selected = m_focused; 66 | 67 | m_sprite.setTexture(*(m_focused ? m_textureFocused : m_texture), false); 68 | triggerEvent(cevent); 69 | } 70 | 71 | bool CheckBox::isSelected() const 72 | { 73 | return isFocused(); 74 | } 75 | 76 | void CheckBox::updateCoord() 77 | { 78 | sf::Vector2f pos(m_sprite.getPosition()), size(SFMLUtils::getLocalSize(m_text)); 79 | 80 | m_text.setOrigin(0, size.y/2.f); 81 | m_text.setPosition(pos.x + m_sprite.getGlobalBounds().width, pos.y + m_sprite.getGlobalBounds().height/2.f); 82 | } 83 | 84 | void CheckBox::setSelected(bool selected) 85 | { 86 | setFocused(selected); 87 | } 88 | 89 | sf::Vector2f CheckBox::getSize() const 90 | { 91 | float x = m_text.getGlobalBounds().left + m_text.getGlobalBounds().width - m_sprite.getGlobalBounds().left; 92 | float y = 0; 93 | 94 | if (m_sprite.getGlobalBounds().height >= m_text.getGlobalBounds().height) 95 | y = m_sprite.getGlobalBounds().height; 96 | else 97 | y = m_text.getGlobalBounds().height; 98 | 99 | return sf::Vector2f(x, y); 100 | } 101 | 102 | const sf::String& CheckBox::getText() const 103 | { 104 | return m_text.getString(); 105 | } 106 | 107 | void CheckBox::setText(const sf::String& text) 108 | { 109 | m_text.setString(text); 110 | } 111 | 112 | const sf::Font* CheckBox::getFont() const 113 | { 114 | return m_text.getFont(); 115 | } 116 | 117 | void CheckBox::setFont(const sf::Font& font) 118 | { 119 | m_text.setFont(font); 120 | } 121 | 122 | unsigned int CheckBox::getFontSize() const 123 | { 124 | return m_text.getCharacterSize(); 125 | } 126 | 127 | void CheckBox::setFontSize(unsigned int size) 128 | { 129 | m_text.setCharacterSize(size); 130 | 131 | } 132 | 133 | sf::Color CheckBox::getFontColor() const 134 | { 135 | return m_text.getColor(); 136 | } 137 | 138 | void CheckBox::updateFixed(sf::Time delta) 139 | { 140 | 141 | } 142 | 143 | void CheckBox::setFontColor(sf::Color color) 144 | { 145 | m_text.setColor(color); 146 | } 147 | -------------------------------------------------------------------------------- /src/SFML/UI/CheckBoxGroup.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace sf::ui; 23 | 24 | CheckBoxGroup::CheckBoxGroup() 25 | : ComponentObserver(), 26 | m_checkBox() 27 | { 28 | 29 | } 30 | 31 | CheckBoxGroup::~CheckBoxGroup() 32 | { 33 | 34 | } 35 | 36 | void CheckBoxGroup::addCheckBox(CheckBox& checkbox) 37 | { 38 | m_checkBox.insert(&checkbox); 39 | checkbox.addObserver(this); 40 | } 41 | 42 | std::set::const_iterator CheckBoxGroup::getCheckboxBegin() const 43 | { 44 | return m_checkBox.begin(); 45 | } 46 | 47 | std::set::const_iterator CheckBoxGroup::getCheckboxEnd() const 48 | { 49 | return m_checkBox.end(); 50 | } 51 | 52 | 53 | void CheckBoxGroup::removeCheckbox(CheckBox& checkbox) 54 | { 55 | m_checkBox.erase(&checkbox); 56 | } 57 | 58 | unsigned int CheckBoxGroup::countCheckbox() const 59 | { 60 | return m_checkBox.size(); 61 | } 62 | 63 | bool CheckBoxGroup::isCheckBoxInGroup(CheckBox* checkbox) const 64 | { 65 | return m_checkBox.find(checkbox) != m_checkBox.end(); 66 | } 67 | 68 | void CheckBoxGroup::onComponentEvent(const ComponentEvent& event) 69 | { 70 | if (event.type == sf::ui::ComponentEvent::CheckBoxChanged) 71 | { 72 | if (isCheckBoxInGroup(event.checkBoxChange.source)) 73 | { 74 | if (event.checkBoxChange.selected) 75 | { 76 | CheckBox *newSelected = event.checkBoxChange.source; 77 | CheckBox *beforeSelected = firstSelected(newSelected); 78 | 79 | if (beforeSelected) 80 | beforeSelected->setSelected(false); 81 | } 82 | else 83 | { 84 | CheckBox *unselected = event.checkBoxChange.source; 85 | 86 | if (!firstSelected(unselected)) 87 | unselected->setSelected(true); 88 | } 89 | } 90 | } 91 | } 92 | 93 | CheckBox* CheckBoxGroup::firstSelected(CheckBox* excluded) const 94 | { 95 | for (std::set::iterator it = m_checkBox.begin(); it != m_checkBox.end(); it++) 96 | { 97 | CheckBox *c = *it; 98 | 99 | if (c->isSelected() && c != excluded) 100 | return c; 101 | } 102 | 103 | return 0; 104 | } 105 | 106 | -------------------------------------------------------------------------------- /src/SFML/UI/Component.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | Component::Component() 23 | : ComponentObservable(), 24 | m_sprite(), m_texture(0) 25 | { 26 | 27 | } 28 | 29 | Component::Component(sf::Texture const &texture) 30 | : m_sprite(), m_texture(0) 31 | { 32 | setTexture(texture); 33 | } 34 | 35 | Component::~Component() 36 | { 37 | 38 | } 39 | 40 | void Component::draw(sf::RenderTarget& target, sf::RenderStates states) const 41 | { 42 | target.draw(m_sprite, states); 43 | } 44 | 45 | void Component::updateCoord() 46 | { 47 | 48 | } 49 | 50 | const sf::Texture* Component::getTexture() const 51 | { 52 | return m_texture; 53 | } 54 | 55 | void Component::setTexture(const sf::Texture& texture) 56 | { 57 | m_texture = &texture; 58 | m_sprite.setTexture(texture, true); 59 | } 60 | 61 | void Component::move(const sf::Vector2f& vector) 62 | { 63 | setPosition(getPosition() + vector); 64 | } 65 | 66 | void Component::move(float x, float y) 67 | { 68 | move(sf::Vector2f(x, y)); 69 | } 70 | 71 | const sf::Vector2f& Component::getPosition() const 72 | { 73 | return m_sprite.getPosition(); 74 | } 75 | 76 | void Component::setPosition(sf::Vector2f const &position) 77 | { 78 | setPosition(position.x, position.y); 79 | } 80 | 81 | void Component::setPosition(float x, float y) 82 | { 83 | m_sprite.setPosition(x, y); 84 | updateCoord(); 85 | } 86 | 87 | void Component::updateSize() 88 | { 89 | setTexture(*m_texture); 90 | } 91 | 92 | sf::Vector2f Component::getSize() const 93 | { 94 | sf::FloatRect bounds = m_sprite.getGlobalBounds(); 95 | 96 | return sf::Vector2f(bounds.width, bounds.height); 97 | } 98 | -------------------------------------------------------------------------------- /src/SFML/UI/ComponentObservable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | using namespace sf::ui; 22 | 23 | ComponentObservable::ComponentObservable() 24 | : m_observers() 25 | { 26 | 27 | } 28 | 29 | ComponentObservable::~ComponentObservable() 30 | { 31 | 32 | } 33 | 34 | void ComponentObservable::addObserver(ComponentObserver* observer) 35 | { 36 | m_observers.insert(observer); 37 | } 38 | 39 | std::set::const_iterator ComponentObservable::getObserversBegin() const 40 | { 41 | return m_observers.begin(); 42 | } 43 | 44 | std::set::const_iterator ComponentObservable::getObserversEnd() const 45 | { 46 | return m_observers.begin(); 47 | } 48 | 49 | int ComponentObservable::countObservers() 50 | { 51 | return m_observers.size(); 52 | } 53 | 54 | void ComponentObservable::removeObserver(sf::ui::ComponentObserver* observer) 55 | { 56 | m_observers.erase(observer); 57 | } 58 | 59 | void sf::ui::ComponentObservable::removeAllObservers() 60 | { 61 | m_observers.clear(); 62 | } 63 | 64 | void ComponentObservable::triggerEvent(const sf::ui::ComponentEvent &event) 65 | { 66 | for (std::set::iterator it = m_observers.begin(); it != m_observers.end(); it++) 67 | (*it)->onComponentEvent(event); 68 | } 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/SFML/UI/ComponentObserver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | using namespace sf::ui; 22 | 23 | ComponentObserver::ComponentObserver() 24 | { 25 | 26 | } 27 | 28 | ComponentObserver::~ComponentObserver() 29 | { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/SFML/UI/Focusable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | using namespace sf::ui; 22 | 23 | Focusable::Focusable() 24 | : Component(), 25 | m_textureFocused(0), m_focused(false) 26 | { 27 | 28 | } 29 | 30 | Focusable::Focusable(const sf::Texture& texture, const sf::Texture& textureFocused) 31 | : Component(texture), 32 | m_textureFocused(0), m_focused(false) 33 | { 34 | setTextureFocused(textureFocused); 35 | } 36 | 37 | Focusable::~Focusable() 38 | { 39 | 40 | } 41 | 42 | void Focusable::gainFocus() 43 | { 44 | m_focused = true; 45 | sf::ui::ComponentEvent cevent; 46 | cevent.source = this; 47 | cevent.type = sf::ui::ComponentEvent::FocusGained; 48 | cevent.focus.source = this; 49 | cevent.focus.focused = true; 50 | triggerEvent(cevent); 51 | } 52 | 53 | void Focusable::lostFocus() 54 | { 55 | m_focused = false; 56 | sf::ui::ComponentEvent cevent; 57 | cevent.source = this; 58 | cevent.type = sf::ui::ComponentEvent::FocusLost; 59 | cevent.focus.source = this; 60 | cevent.focus.focused = false; 61 | triggerEvent(cevent); 62 | } 63 | 64 | bool Focusable::isFocused() const 65 | { 66 | return m_focused; 67 | } 68 | 69 | void Focusable::setFocused(bool focused) 70 | { 71 | if (focused && !m_focused) 72 | { 73 | gainFocus(); 74 | } 75 | else if (!focused && m_focused) 76 | { 77 | lostFocus(); 78 | } 79 | 80 | m_focused = focused; 81 | m_sprite.setTexture(*(m_focused ? m_textureFocused : m_texture), false); 82 | } 83 | 84 | const sf::Texture* Focusable::getTextureFocused() const 85 | { 86 | return m_textureFocused; 87 | } 88 | 89 | void Focusable::setTextureFocused(const sf::Texture& textureFocused) 90 | { 91 | m_textureFocused = &textureFocused; 92 | } 93 | 94 | bool Focusable::checkClickOn(int x, int y) const 95 | { 96 | return isCoordOnComponent(x, y); 97 | } 98 | 99 | bool Focusable::isCoordOnComponent(int x, int y) const 100 | { 101 | sf::Vector2f pos(x, y); 102 | 103 | return m_sprite.getGlobalBounds().contains(pos); 104 | } 105 | -------------------------------------------------------------------------------- /src/SFML/UI/Format/DoubleFormat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace sf::ui; 23 | 24 | DoubleFormat::DoubleFormat() 25 | : m_value(0) 26 | { 27 | 28 | } 29 | 30 | DoubleFormat::~DoubleFormat() 31 | { 32 | 33 | } 34 | 35 | sf::String DoubleFormat::toString() const 36 | { 37 | std::ostringstream stream; 38 | stream << m_value; 39 | return stream.str(); 40 | } 41 | 42 | bool DoubleFormat::isAllowed(sf::String str) const 43 | { 44 | return strtod(str.toAnsiString().c_str(), NULL) != 0 || str == "0" || str == "" || str == "-"; 45 | } 46 | 47 | void DoubleFormat::parse(sf::String str) 48 | { 49 | setValue(strtod(str.toAnsiString().c_str(), NULL)); 50 | } 51 | 52 | void DoubleFormat::setValue(double value) 53 | { 54 | m_value = value; 55 | } 56 | 57 | double DoubleFormat::getValue() const 58 | { 59 | return m_value; 60 | } 61 | -------------------------------------------------------------------------------- /src/SFML/UI/Format/Format.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | Format::~Format() 23 | { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/SFML/UI/Format/LongFormat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace sf::ui; 23 | 24 | LongFormat::LongFormat() 25 | : m_value(0) 26 | { 27 | 28 | } 29 | 30 | LongFormat::~LongFormat() 31 | { 32 | 33 | } 34 | 35 | sf::String LongFormat::toString() const 36 | { 37 | std::ostringstream stream; 38 | stream << m_value; 39 | return stream.str(); 40 | } 41 | 42 | bool LongFormat::isAllowed(sf::String str) const 43 | { 44 | return strtol(str.toAnsiString().c_str(), NULL, 10) != 0 || str == "0" || str == "" || str == "-"; 45 | } 46 | 47 | void LongFormat::parse(sf::String str) 48 | { 49 | setValue(strtol(str.toAnsiString().c_str(), NULL, 10)); 50 | } 51 | 52 | void LongFormat::setValue(sf::Int64 value) 53 | { 54 | m_value = value; 55 | } 56 | 57 | sf::Int64 LongFormat::getValue() const 58 | { 59 | return m_value; 60 | } 61 | -------------------------------------------------------------------------------- /src/SFML/UI/Format/UnsignedLongFormat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace sf::ui; 23 | 24 | UnsignedLongFormat::UnsignedLongFormat() 25 | : m_value(0) 26 | { 27 | 28 | } 29 | 30 | UnsignedLongFormat::~UnsignedLongFormat() 31 | { 32 | 33 | } 34 | 35 | sf::String UnsignedLongFormat::toString() const 36 | { 37 | std::ostringstream stream; 38 | stream << m_value; 39 | return stream.str(); 40 | } 41 | 42 | bool UnsignedLongFormat::isAllowed(sf::String str) const 43 | { 44 | return strtoul(str.toAnsiString().c_str(), NULL, 10) != 0 || str == "0" || str == ""; 45 | } 46 | 47 | void UnsignedLongFormat::parse(sf::String str) 48 | { 49 | std::size_t minusPos; 50 | while ((minusPos = str.find('-')) != sf::String::InvalidPos) 51 | { 52 | str.erase(minusPos); 53 | } 54 | 55 | setValue(strtoul(str.toAnsiString().c_str(), NULL, 10)); 56 | } 57 | 58 | void UnsignedLongFormat::setValue(sf::Uint64 value) 59 | { 60 | m_value = value; 61 | } 62 | 63 | sf::Uint64 UnsignedLongFormat::getValue() const 64 | { 65 | return m_value; 66 | } 67 | -------------------------------------------------------------------------------- /src/SFML/UI/FormattedTextField.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | using namespace sf::ui; 22 | 23 | FormattedTextField::FormattedTextField(Format* format) 24 | : TextField(), 25 | m_format(format) 26 | { 27 | 28 | } 29 | 30 | FormattedTextField::FormattedTextField(sf::Texture const &texture, sf::Texture const &textureFocused, Format* format, sf::String const &text) 31 | : TextField(texture, textureFocused, text), 32 | m_format(format) 33 | { 34 | 35 | } 36 | 37 | FormattedTextField::FormattedTextField(sf::Texture const &texture, sf::Texture const &textureFocused, sf::Font const &font, Format* format, sf::String text) 38 | : TextField(texture, textureFocused, font, text), 39 | m_format(format) 40 | { 41 | 42 | } 43 | 44 | FormattedTextField::~FormattedTextField() 45 | { 46 | if (m_format) 47 | { 48 | delete m_format; 49 | } 50 | } 51 | 52 | void FormattedTextField::lostFocus() 53 | { 54 | TextField::lostFocus(); 55 | 56 | updateValue(); 57 | } 58 | 59 | void FormattedTextField::updateValue() 60 | { 61 | if (m_format) 62 | { 63 | m_format->parse(getText()); 64 | setText(m_format->toString()); 65 | 66 | sf::ui::ComponentEvent cevent; 67 | cevent.source = this; 68 | cevent.type = sf::ui::ComponentEvent::FormattedValueEntered; 69 | cevent.formattedValueEnter.source = this; 70 | cevent.formattedValueEnter.format = m_format; 71 | triggerEvent(cevent); 72 | } 73 | } 74 | 75 | const Format* FormattedTextField::getFormat() const 76 | { 77 | return m_format; 78 | } 79 | 80 | Format* FormattedTextField::getFormat() 81 | { 82 | return m_format; 83 | } 84 | void FormattedTextField::setFormat(Format *format) 85 | { 86 | if (m_format != format) 87 | { 88 | if (!m_format) 89 | { 90 | delete m_format; 91 | m_format = 0; 92 | } 93 | 94 | m_format = format; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/SFML/UI/IText.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | IText::~IText() 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/SFML/UI/Label.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace sf::ui; 23 | 24 | Label::Label() 25 | : Component() 26 | { 27 | } 28 | 29 | Label::Label(const sf::Texture& image) 30 | : Component(image) 31 | { 32 | } 33 | 34 | Label::Label(const sf::Font& font, const sf::String& text, int fontSize) 35 | : Component() 36 | { 37 | setFont(font); 38 | setText(text); 39 | setFontSize(fontSize); 40 | } 41 | 42 | Label::~Label() 43 | { 44 | 45 | } 46 | 47 | void Label::updateEvent(const sf::Event& event) 48 | { 49 | } 50 | 51 | void Label::updateFixed(sf::Time delta) 52 | { 53 | } 54 | 55 | void Label::draw(sf::RenderTarget& target, sf::RenderStates states) const 56 | { 57 | if (m_text.getString() == "") 58 | target.draw(m_sprite, states); 59 | else 60 | target.draw(m_text, states); 61 | } 62 | 63 | void Label::updateCoord() 64 | { 65 | m_text.setPosition(m_sprite.getPosition()); 66 | } 67 | 68 | const sf::String& Label::getText() const 69 | { 70 | return m_text.getString(); 71 | } 72 | 73 | void Label::setText(const sf::String& text) 74 | { 75 | m_text.setString(text); 76 | } 77 | 78 | const sf::Font* Label::getFont() const 79 | { 80 | return m_text.getFont(); 81 | } 82 | 83 | void Label::setFont(const sf::Font& font) 84 | { 85 | m_text.setFont(font); 86 | } 87 | 88 | const sf::Texture* Label::getImage() const 89 | { 90 | return m_texture; 91 | } 92 | 93 | unsigned int Label::getFontSize() const 94 | { 95 | return m_text.getCharacterSize(); 96 | } 97 | 98 | void Label::setFontSize(unsigned int size) 99 | { 100 | m_text.setCharacterSize(size); 101 | } 102 | 103 | sf::Color Label::getFontColor() const 104 | { 105 | return m_text.getColor(); 106 | } 107 | 108 | void Label::setFontColor(sf::Color color) 109 | { 110 | m_text.setColor(color); 111 | } 112 | 113 | void Label::setImage(const sf::Texture& image) 114 | { 115 | m_texture = ℑ 116 | m_sprite.setTexture(image, true); 117 | } 118 | 119 | sf::Vector2f Label::getSize() const 120 | { 121 | float x = fmaxf(m_text.getLocalBounds().width, m_sprite.getLocalBounds().width); 122 | float y = fmaxf(m_text.getLocalBounds().height, m_sprite.getLocalBounds().height); 123 | 124 | return sf::Vector2f(x, y); 125 | } 126 | -------------------------------------------------------------------------------- /src/SFML/UI/Model/AlphaNumericTextFieldModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | AlphaNumericTextFieldModel::AlphaNumericTextFieldModel() 23 | { 24 | for (sf::Uint32 i = 'A'; i <= 'Z'; i++) 25 | m_whitelist.insert(i); 26 | 27 | for (sf::Uint32 i = 'a'; i <= 'z'; i++) 28 | m_whitelist.insert(i); 29 | 30 | m_whitelist.insert('-'); 31 | 32 | for (sf::Uint32 i = '0'; i <= '9'; i++) 33 | m_whitelist.insert(i); 34 | } 35 | 36 | AlphaNumericTextFieldModel::~AlphaNumericTextFieldModel() 37 | { 38 | } 39 | -------------------------------------------------------------------------------- /src/SFML/UI/Model/AlphaTextFieldModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | AlphaTextFieldModel::AlphaTextFieldModel() 23 | { 24 | for (sf::Uint32 i = 'A'; i <= 'Z'; i++) 25 | m_whitelist.insert(i); 26 | 27 | for (sf::Uint32 i = 'a'; i <= 'z'; i++) 28 | m_whitelist.insert(i); 29 | } 30 | 31 | AlphaTextFieldModel::~AlphaTextFieldModel() 32 | { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/SFML/UI/Model/AsciiNoSpaceTextFieldModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | AsciiNoSpaceTextFieldModel::AsciiNoSpaceTextFieldModel() 23 | { 24 | 25 | } 26 | 27 | AsciiNoSpaceTextFieldModel::~AsciiNoSpaceTextFieldModel() 28 | { 29 | 30 | } 31 | 32 | bool AsciiNoSpaceTextFieldModel::isCharAllowed(sf::Uint32 c) const 33 | { 34 | return c > 32 && c <= 126; 35 | } 36 | -------------------------------------------------------------------------------- /src/SFML/UI/Model/AsciiTextFieldModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | AsciiTextFieldModel::AsciiTextFieldModel() 23 | { 24 | 25 | } 26 | 27 | AsciiTextFieldModel::~AsciiTextFieldModel() 28 | { 29 | 30 | } 31 | 32 | bool AsciiTextFieldModel::isCharAllowed(sf::Uint32 c) const 33 | { 34 | return c >= 32 && c <= 126; 35 | } 36 | -------------------------------------------------------------------------------- /src/SFML/UI/Model/BlacklistTextFieldModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | BlacklistTextFieldModel::BlacklistTextFieldModel() 23 | { 24 | 25 | } 26 | 27 | BlacklistTextFieldModel::~BlacklistTextFieldModel() 28 | { 29 | 30 | } 31 | 32 | bool BlacklistTextFieldModel::isCharAllowed(sf::Uint32 c) const 33 | { 34 | return m_blacklist.find(c) == m_blacklist.end(); 35 | } 36 | 37 | void BlacklistTextFieldModel::addCharDenied(sf::Uint32 c) 38 | { 39 | m_blacklist.insert(c); 40 | } 41 | 42 | void BlacklistTextFieldModel::rmCharDenied(sf::Uint32 c) 43 | { 44 | m_blacklist.erase(c); 45 | } 46 | 47 | std::vector sf::ui::BlacklistTextFieldModel::getCharsDenied() const 48 | { 49 | std::vector blacklist; 50 | 51 | for (std::set::iterator it = m_blacklist.begin(); it != m_blacklist.end(); it++) 52 | blacklist.push_back(*it); 53 | 54 | return blacklist; 55 | } 56 | -------------------------------------------------------------------------------- /src/SFML/UI/Model/DefaultTextFieldModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | DefaultTextFieldModel::DefaultTextFieldModel() 23 | { 24 | for (sf::Uint32 i = 0x00; i < 0x20; i++) 25 | m_blacklist.insert(i); 26 | 27 | m_blacklist.insert(0x7F); //Basckspace 28 | } 29 | 30 | DefaultTextFieldModel::~DefaultTextFieldModel() 31 | { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/SFML/UI/Model/NumericTextFieldModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | NumericTextFieldModel::NumericTextFieldModel() 23 | { 24 | for (sf::Uint32 i = '0'; i <= '9'; i++) 25 | m_whitelist.insert(i); 26 | m_whitelist.insert('.'); 27 | } 28 | 29 | NumericTextFieldModel::~NumericTextFieldModel() 30 | { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/SFML/UI/Model/TextFieldModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | TextFieldModel::TextFieldModel() 23 | { 24 | 25 | } 26 | 27 | TextFieldModel::~TextFieldModel() 28 | { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/SFML/UI/Model/WhitelistTextFieldModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | WhitelistTextFieldModel::WhitelistTextFieldModel() 23 | { 24 | 25 | } 26 | 27 | WhitelistTextFieldModel::~WhitelistTextFieldModel() 28 | { 29 | 30 | } 31 | 32 | bool WhitelistTextFieldModel::isCharAllowed(sf::Uint32 c) const 33 | { 34 | return m_whitelist.find(c) != m_whitelist.end(); 35 | } 36 | 37 | void WhitelistTextFieldModel::addCharAllowed(sf::Uint32 c) 38 | { 39 | m_whitelist.insert(c); 40 | } 41 | 42 | void WhitelistTextFieldModel::rmCharAllowed(sf::Uint32 c) 43 | { 44 | m_whitelist.erase(c); 45 | } 46 | 47 | std::vector WhitelistTextFieldModel::getCharsAllowed() const 48 | { 49 | std::vector allowed; 50 | 51 | for (std::set::iterator it = m_whitelist.begin(); it != m_whitelist.end(); it++) 52 | allowed.push_back(*it); 53 | 54 | return allowed; 55 | } 56 | -------------------------------------------------------------------------------- /src/SFML/UI/PasswordField.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | using namespace sf::ui; 22 | 23 | PasswordField::PasswordField() 24 | : TextField(), m_password() 25 | { 26 | setModel(new AsciiNoSpaceTextFieldModel); 27 | } 28 | 29 | PasswordField::PasswordField(sf::Texture const &texture, sf::Texture const &textureFocused) 30 | : TextField(texture, textureFocused), m_password() 31 | { 32 | setModel(new AsciiNoSpaceTextFieldModel); 33 | } 34 | 35 | PasswordField::PasswordField(sf::Texture const &texture, sf::Texture const &textureFocused, sf::Font const &font) 36 | : TextField(texture, textureFocused, font), m_password() 37 | { 38 | setModel(new AsciiNoSpaceTextFieldModel); 39 | } 40 | 41 | PasswordField::~PasswordField() 42 | { 43 | 44 | } 45 | 46 | bool PasswordField::insertText(sf::Uint32 text, unsigned int index) 47 | { 48 | if (TextField::insertText(text, index)) 49 | { 50 | m_password.insert(index, text); 51 | replaceTextDisplayed(); 52 | return true; 53 | } 54 | else 55 | { 56 | return false; 57 | } 58 | } 59 | 60 | bool PasswordField::deleteText(unsigned int index) 61 | { 62 | if (TextField::deleteText(index)) 63 | { 64 | m_password.erase(index); 65 | replaceTextDisplayed(); 66 | return true; 67 | } 68 | else 69 | { 70 | return false; 71 | } 72 | } 73 | 74 | void PasswordField::replaceTextDisplayed() 75 | { 76 | sf::String text; 77 | 78 | for (size_t i = 0; i < m_password.getSize(); i++) 79 | { 80 | text.insert(i, sf::String(L"•")); 81 | } 82 | 83 | m_text.setString(text); 84 | } 85 | 86 | const sf::String& PasswordField::getPassword() const 87 | { 88 | return m_password; 89 | } 90 | 91 | void PasswordField::setPassword(sf::String const &password) 92 | { 93 | m_password = password; 94 | replaceTextDisplayed(); 95 | } 96 | -------------------------------------------------------------------------------- /src/SFML/UI/SFMLUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2013 mathdu07 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | using namespace sf::ui; 21 | 22 | SFMLUtils::SFMLUtils() 23 | { 24 | 25 | } 26 | 27 | SFMLUtils::~SFMLUtils() 28 | { 29 | 30 | 31 | } 32 | 33 | //From http://en.sfml-dev.org/forums/index.php?topic=7174 34 | sf::Vector2f SFMLUtils::getLocalSize(const sf::Text& text) 35 | { 36 | if (text.getFont() == 0) 37 | return sf::Vector2f(0, 0); 38 | 39 | const sf::String str = text.getString() + '\n'; 40 | 41 | float maxLineWidth = 0.f; 42 | float lineWidth = 0.f; 43 | unsigned int lines = 0; 44 | 45 | for (sf::String::ConstIterator itr = str.begin(); itr != str.end(); ++itr) 46 | { 47 | if (*itr == '\n') 48 | { 49 | ++lines; 50 | maxLineWidth = std::max(maxLineWidth, lineWidth); 51 | lineWidth = 0.f; 52 | } 53 | else 54 | { 55 | lineWidth += text.getFont()->getGlyph(*itr, text.getCharacterSize(), text.getStyle() & sf::Text::Bold).advance; 56 | } 57 | } 58 | 59 | const float lineHeight = static_cast(text.getFont()->getLineSpacing(text.getCharacterSize())); 60 | return sf::Vector2f(maxLineWidth, lines * lineHeight); 61 | } 62 | 63 | sf::String SFMLUtils::keyToString(sf::Keyboard::Key key) 64 | { 65 | switch (key) 66 | { 67 | case sf::Keyboard::A: 68 | return "A"; 69 | case sf::Keyboard::B: 70 | return "B"; 71 | case sf::Keyboard::C: 72 | return "C"; 73 | case sf::Keyboard::D: 74 | return "D"; 75 | case sf::Keyboard::E: 76 | return "E"; 77 | case sf::Keyboard::F: 78 | return "F"; 79 | case sf::Keyboard::G: 80 | return "G"; 81 | case sf::Keyboard::H: 82 | return "H"; 83 | case sf::Keyboard::I: 84 | return "I"; 85 | case sf::Keyboard::J: 86 | return "J"; 87 | case sf::Keyboard::K: 88 | return "K"; 89 | case sf::Keyboard::L: 90 | return "L"; 91 | case sf::Keyboard::M: 92 | return "M"; 93 | case sf::Keyboard::N: 94 | return "N"; 95 | case sf::Keyboard::O: 96 | return "O"; 97 | case sf::Keyboard::P: 98 | return "P"; 99 | case sf::Keyboard::Q: 100 | return "Q"; 101 | case sf::Keyboard::R: 102 | return "R"; 103 | case sf::Keyboard::S: 104 | return "S"; 105 | case sf::Keyboard::T: 106 | return "T"; 107 | case sf::Keyboard::U: 108 | return "U"; 109 | case sf::Keyboard::V: 110 | return "V"; 111 | case sf::Keyboard::W: 112 | return "W"; 113 | case sf::Keyboard::X: 114 | return "X"; 115 | case sf::Keyboard::Y: 116 | return "Y"; 117 | case sf::Keyboard::Z: 118 | return "Z"; 119 | case sf::Keyboard::Num0: 120 | return "0"; 121 | case sf::Keyboard::Num1: 122 | return "1"; 123 | case sf::Keyboard::Num2: 124 | return "2"; 125 | case sf::Keyboard::Num3: 126 | return "3"; 127 | case sf::Keyboard::Num4: 128 | return "4"; 129 | case sf::Keyboard::Num5: 130 | return "5"; 131 | case sf::Keyboard::Num6: 132 | return "6"; 133 | case sf::Keyboard::Num7: 134 | return "7"; 135 | case sf::Keyboard::Num8: 136 | return "8"; 137 | case sf::Keyboard::Num9: 138 | return "9"; 139 | case sf::Keyboard::Numpad0: 140 | return "N0"; 141 | case sf::Keyboard::Numpad1: 142 | return "N1"; 143 | case sf::Keyboard::Numpad2: 144 | return "N2"; 145 | case sf::Keyboard::Numpad3: 146 | return "N3"; 147 | case sf::Keyboard::Numpad4: 148 | return "N4"; 149 | case sf::Keyboard::Numpad5: 150 | return "N5"; 151 | case sf::Keyboard::Numpad6: 152 | return "N6"; 153 | case sf::Keyboard::Numpad7: 154 | return "N7"; 155 | case sf::Keyboard::Numpad8: 156 | return "N8"; 157 | case sf::Keyboard::Numpad9: 158 | return "N9"; 159 | case sf::Keyboard::Up: 160 | return "Up"; 161 | case sf::Keyboard::Down: 162 | return "Down"; 163 | case sf::Keyboard::Left: 164 | return "Left"; 165 | case sf::Keyboard::Right: 166 | return "Right"; 167 | case sf::Keyboard::RAlt: 168 | return "rAlt"; 169 | case sf::Keyboard::RControl: 170 | return "rCtrl"; 171 | case sf::Keyboard::RShift: 172 | return "rShift"; 173 | case sf::Keyboard::LAlt: 174 | return "Alt"; 175 | case sf::Keyboard::LControl: 176 | return "Ctrl"; 177 | case sf::Keyboard::LShift: 178 | return "Shift"; 179 | case sf::Keyboard::Space: 180 | return "Space"; 181 | case sf::Keyboard::Menu: 182 | return "Menu"; 183 | case sf::Keyboard::Tab: 184 | return "Tab"; 185 | case sf::Keyboard::Escape: 186 | return "Esc"; 187 | case sf::Keyboard::Tilde: 188 | return "~"; 189 | case sf::Keyboard::LBracket: 190 | return "["; 191 | case sf::Keyboard::RBracket: 192 | return "]"; 193 | case sf::Keyboard::Add: 194 | return "+"; 195 | case sf::Keyboard::Subtract: 196 | return "-"; 197 | case sf::Keyboard::Multiply: 198 | return "*"; 199 | case sf::Keyboard::Divide: 200 | return "/"; 201 | case sf::Keyboard::Equal: 202 | return "="; 203 | case sf::Keyboard::Dash: 204 | return "-"; 205 | case sf::Keyboard::BackSpace: 206 | return "Back"; 207 | case sf::Keyboard::Return: 208 | return "Return"; 209 | case sf::Keyboard::Slash: 210 | return "/"; 211 | case sf::Keyboard::BackSlash: 212 | return "\\"; 213 | case sf::Keyboard::Comma: 214 | return ","; 215 | case sf::Keyboard::SemiColon: 216 | return ";"; 217 | case sf::Keyboard::Period: 218 | return "."; 219 | case sf::Keyboard::Quote: 220 | return "'"; 221 | case sf::Keyboard::PageUp: 222 | return "PgUp"; 223 | case sf::Keyboard::PageDown: 224 | return "PgDown"; 225 | case sf::Keyboard::Insert: 226 | return "Insert"; 227 | case sf::Keyboard::Delete: 228 | return "Del"; 229 | case sf::Keyboard::Home: 230 | return "Home"; 231 | case sf::Keyboard::End: 232 | return "End"; 233 | case sf::Keyboard::F1: 234 | return "F1"; 235 | case sf::Keyboard::F2: 236 | return "F2"; 237 | case sf::Keyboard::F3: 238 | return "F3"; 239 | case sf::Keyboard::F4: 240 | return "F4"; 241 | case sf::Keyboard::F5: 242 | return "F5"; 243 | case sf::Keyboard::F6: 244 | return "F6"; 245 | case sf::Keyboard::F7: 246 | return "F7"; 247 | case sf::Keyboard::F8: 248 | return "F8"; 249 | case sf::Keyboard::F9: 250 | return "F9"; 251 | case sf::Keyboard::F10: 252 | return "F10"; 253 | case sf::Keyboard::F11: 254 | return "F11"; 255 | case sf::Keyboard::F12: 256 | return "F12"; 257 | case sf::Keyboard::F13: 258 | return "F13"; 259 | case sf::Keyboard::F14: 260 | return "F14"; 261 | case sf::Keyboard::F15: 262 | return "F15"; 263 | default: 264 | return ""; 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /tools/pkg-config/sfml-ui.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib@LIB_SUFFIX@ 4 | includedir=${prefix}/include 5 | 6 | Name: SFML-ui 7 | Description: The Simple and Fast Multimedia Library, non-official User Interface module. 8 | URL: http://www.sfml-dev.org 9 | Version: @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ 10 | Requires: sfml-graphics 11 | Libs: -L${libdir} -lsfml-ui 12 | Cflags: -I${includedir} 13 | --------------------------------------------------------------------------------