├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── Todo.md ├── cmake └── CPM.cmake ├── dependencies └── raylib │ └── src │ └── raygui.h ├── examples ├── ButtonCallbacks.cpp ├── ButtonChangePositionOnClick.cpp ├── ButtonColors.cpp ├── ButtonKeepInitialPosition.cpp ├── ButtonPlacement.cpp ├── CMakeLists.txt ├── ChildComponents.cpp ├── SimpleButton.cpp ├── assets │ └── TestImage.png └── extras │ └── ImageButton.cpp ├── include ├── raygui-cpp.h └── raygui-cpp │ ├── Bounds.h │ ├── Button.h │ ├── CheckBox.h │ ├── ColorBarAlpha.h │ ├── ColorBarHue.h │ ├── ColorPanel.h │ ├── ColorPanelHSV.h │ ├── ColorPicker.h │ ├── ColorPickerHSV.h │ ├── ComboBox.h │ ├── Component.h │ ├── Directives.h │ ├── DropdownBox.h │ ├── DummyRec.h │ ├── Globals.h │ ├── Grid.h │ ├── GroupBox.h │ ├── Label.h │ ├── LabelButton.h │ ├── Line.h │ ├── ListView.h │ ├── ListViewEx.h │ ├── Margin.h │ ├── MessageBox.h │ ├── Paintable.h │ ├── Panel.h │ ├── ProgressBar.h │ ├── ScrollPanel.h │ ├── Slider.h │ ├── SliderBar.h │ ├── Spinner.h │ ├── StatusBar.h │ ├── Style.h │ ├── TabBar.h │ ├── TextBox.h │ ├── TextInputBox.h │ ├── Toggle.h │ ├── ToggleGroup.h │ ├── ToggleSlider.h │ ├── Utils.h │ ├── ValueBox.h │ ├── WindowBox.h │ └── extras │ └── ImageButton.h ├── raygui_cpp_256x256.png └── src └── raygui-cpp ├── Bounds.cpp ├── Button.cpp ├── CheckBox.cpp ├── ColorBarAlpha.cpp ├── ColorBarHue.cpp ├── ColorPanel.cpp ├── ColorPanelHSV.cpp ├── ColorPicker.cpp ├── ColorPickerHSV.cpp ├── ComboBox.cpp ├── DropdownBox.cpp ├── DummyRec.cpp ├── Globals.cpp ├── Grid.cpp ├── GroupBox.cpp ├── Label.cpp ├── LabelButton.cpp ├── Line.cpp ├── ListView.cpp ├── ListViewEx.cpp ├── MessageBox.cpp ├── Paintable.cpp ├── Panel.cpp ├── ProgressBar.cpp ├── ScrollPanel.cpp ├── Slider.cpp ├── SliderBar.cpp ├── Spinner.cpp ├── StatusBar.cpp ├── Style.cpp ├── TabBar.cpp ├── TextBox.cpp ├── TextInputBox.cpp ├── Toggle.cpp ├── ToggleGroup.cpp ├── ToggleSlider.cpp ├── ValueBox.cpp ├── WindowBox.cpp └── extras └── ImageButton.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: LLVM 3 | Standard: c++20 4 | AccessModifierOffset: -4 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveAssignments: None 7 | AlignOperands: Align 8 | AllowAllArgumentsOnNextLine: false 9 | AllowAllConstructorInitializersOnNextLine: false 10 | AllowAllParametersOfDeclarationOnNextLine: false 11 | AllowShortBlocksOnASingleLine: Empty 12 | AllowShortCaseLabelsOnASingleLine: false 13 | AllowShortFunctionsOnASingleLine: Empty 14 | AllowShortIfStatementsOnASingleLine: Never 15 | AllowShortLambdasOnASingleLine: Empty 16 | AllowShortLoopsOnASingleLine: false 17 | AlwaysBreakAfterReturnType: None 18 | AlwaysBreakTemplateDeclarations: Yes 19 | BreakBeforeBraces: Custom 20 | BraceWrapping: 21 | AfterCaseLabel: false 22 | AfterClass: false 23 | AfterControlStatement: Never 24 | AfterEnum: false 25 | AfterFunction: false 26 | AfterNamespace: false 27 | AfterUnion: false 28 | BeforeCatch: false 29 | BeforeElse: false 30 | IndentBraces: false 31 | SplitEmptyFunction: false 32 | SplitEmptyRecord: true 33 | BreakBeforeBinaryOperators: None 34 | BreakBeforeTernaryOperators: true 35 | BreakConstructorInitializers: BeforeColon 36 | BreakInheritanceList: BeforeColon 37 | ColumnLimit: 120 38 | CompactNamespaces: false 39 | ContinuationIndentWidth: 8 40 | Cpp11BracedListStyle: false 41 | FixNamespaceComments: true 42 | IndentCaseLabels: true 43 | IndentPPDirectives: BeforeHash 44 | IndentWidth: 4 45 | KeepEmptyLinesAtTheStartOfBlocks: true 46 | MaxEmptyLinesToKeep: 2 47 | NamespaceIndentation: All 48 | ObjCSpaceAfterProperty: false 49 | ObjCSpaceBeforeProtocolList: true 50 | PointerAlignment: Right 51 | ReflowComments: false 52 | SeparateDefinitionBlocks: Always 53 | SortIncludes: CaseInsensitive 54 | SpaceAfterCStyleCast: true 55 | SpaceAfterLogicalNot: false 56 | SpaceAfterTemplateKeyword: false 57 | SpaceBeforeAssignmentOperators: true 58 | SpaceBeforeCpp11BracedList: false 59 | SpaceBeforeCtorInitializerColon: true 60 | SpaceBeforeInheritanceColon: true 61 | SpaceBeforeParens: ControlStatements 62 | SpaceBeforeRangeBasedForLoopColon: false 63 | SpaceInEmptyParentheses: false 64 | SpacesBeforeTrailingComments: 1 65 | SpacesInAngles: false 66 | SpacesInCStyleCastParentheses: false 67 | SpacesInContainerLiterals: false 68 | SpacesInParentheses: false 69 | SpacesInSquareBrackets: false 70 | TabWidth: 4 71 | UseTab: Never 72 | --- 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### C++ template 2 | # Prerequisites 3 | *.d 4 | 5 | # Compiled Object files 6 | *.slo 7 | *.lo 8 | *.o 9 | *.obj 10 | 11 | # Precompiled Headers 12 | *.gch 13 | *.pch 14 | 15 | # Compiled Dynamic libraries 16 | *.so 17 | *.dylib 18 | *.dll 19 | 20 | # Fortran module files 21 | *.mod 22 | *.smod 23 | 24 | # Compiled Static libraries 25 | *.lai 26 | *.la 27 | *.a 28 | *.lib 29 | 30 | # Executables 31 | *.exe 32 | *.out 33 | *.app 34 | 35 | ### JetBrains template 36 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 37 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 38 | 39 | # Ignore .idea folder 40 | .idea/ 41 | 42 | # User-specific stuff 43 | .idea/**/workspace.xml 44 | .idea/**/tasks.xml 45 | .idea/**/usage.statistics.xml 46 | .idea/**/dictionaries 47 | .idea/**/shelf 48 | 49 | # AWS User-specific 50 | .idea/**/aws.xml 51 | 52 | # Generated files 53 | .idea/**/contentModel.xml 54 | 55 | # Sensitive or high-churn files 56 | .idea/**/dataSources/ 57 | .idea/**/dataSources.ids 58 | .idea/**/dataSources.local.xml 59 | .idea/**/sqlDataSources.xml 60 | .idea/**/dynamic.xml 61 | .idea/**/uiDesigner.xml 62 | .idea/**/dbnavigator.xml 63 | 64 | # Gradle 65 | .idea/**/gradle.xml 66 | .idea/**/libraries 67 | 68 | # Gradle and Maven with auto-import 69 | # When using Gradle or Maven with auto-import, you should exclude module files, 70 | # since they will be recreated, and may cause churn. Uncomment if using 71 | # auto-import. 72 | # .idea/artifacts 73 | # .idea/compiler.xml 74 | # .idea/jarRepositories.xml 75 | # .idea/modules.xml 76 | # .idea/*.iml 77 | # .idea/modules 78 | # *.iml 79 | # *.ipr 80 | 81 | # CMake 82 | cmake-build-*/ 83 | 84 | # Mongo Explorer plugin 85 | .idea/**/mongoSettings.xml 86 | 87 | # File-based project format 88 | *.iws 89 | 90 | # IntelliJ 91 | out/ 92 | 93 | # mpeltonen/sbt-idea plugin 94 | .idea_modules/ 95 | 96 | # JIRA plugin 97 | atlassian-ide-plugin.xml 98 | 99 | # Cursive Clojure plugin 100 | .idea/replstate.xml 101 | 102 | # SonarLint plugin 103 | .idea/sonarlint/ 104 | 105 | # Crashlytics plugin (for Android Studio and IntelliJ) 106 | com_crashlytics_export_strings.xml 107 | crashlytics.properties 108 | crashlytics-build.properties 109 | fabric.properties 110 | 111 | # Editor-based Rest Client 112 | .idea/httpRequests 113 | 114 | # Android studio 3.1+ serialized cache file 115 | .idea/caches/build_file_checksums.ser 116 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | project(raygui_cpp 3 | LANGUAGES C CXX 4 | VERSION 0.1.0 5 | DESCRIPTION "C++ wrapper for raygui") 6 | 7 | set(CMAKE_CXX_STANDARD 17) 8 | 9 | # Add dependencies 10 | set(RAYGUI_CPP_SOURCE_FILES 11 | # C++ files 12 | src/raygui-cpp/Button.cpp 13 | src/raygui-cpp/CheckBox.cpp 14 | src/raygui-cpp/ColorBarAlpha.cpp 15 | src/raygui-cpp/ColorBarHue.cpp 16 | src/raygui-cpp/ColorPanel.cpp 17 | src/raygui-cpp/ColorPicker.cpp 18 | src/raygui-cpp/ComboBox.cpp 19 | src/raygui-cpp/DropdownBox.cpp 20 | src/raygui-cpp/DummyRec.cpp 21 | src/raygui-cpp/Globals.cpp 22 | src/raygui-cpp/Grid.cpp 23 | src/raygui-cpp/GroupBox.cpp 24 | src/raygui-cpp/LabelButton.cpp 25 | src/raygui-cpp/Label.cpp 26 | src/raygui-cpp/Line.cpp 27 | src/raygui-cpp/ListView.cpp 28 | src/raygui-cpp/ListViewEx.cpp 29 | src/raygui-cpp/MessageBox.cpp 30 | src/raygui-cpp/Panel.cpp 31 | src/raygui-cpp/ProgressBar.cpp 32 | src/raygui-cpp/ScrollPanel.cpp 33 | src/raygui-cpp/SliderBar.cpp 34 | src/raygui-cpp/Slider.cpp 35 | src/raygui-cpp/Spinner.cpp 36 | src/raygui-cpp/StatusBar.cpp 37 | src/raygui-cpp/TabBar.cpp 38 | src/raygui-cpp/TextBox.cpp 39 | src/raygui-cpp/TextInputBox.cpp 40 | src/raygui-cpp/Toggle.cpp 41 | src/raygui-cpp/ToggleGroup.cpp 42 | src/raygui-cpp/ValueBox.cpp 43 | src/raygui-cpp/WindowBox.cpp 44 | src/raygui-cpp/Bounds.cpp 45 | src/raygui-cpp/Style.cpp 46 | src/raygui-cpp/ToggleSlider.cpp 47 | src/raygui-cpp/ColorPickerHSV.cpp 48 | src/raygui-cpp/ColorPanelHSV.cpp 49 | src/raygui-cpp/Paintable.cpp 50 | src/raygui-cpp/extras/ImageButton.cpp 51 | ) 52 | 53 | set(RAYGUI_CPP_HEADER_FILES 54 | # C files 55 | dependencies/raylib/src/raygui.h 56 | # C++ files 57 | include/raygui-cpp/Button.h 58 | include/raygui-cpp/CheckBox.h 59 | include/raygui-cpp/ColorBarAlpha.h 60 | include/raygui-cpp/ColorBarHue.h 61 | include/raygui-cpp/ColorPanel.h 62 | include/raygui-cpp/ColorPicker.h 63 | include/raygui-cpp/ComboBox.h 64 | include/raygui-cpp/Directives.h 65 | include/raygui-cpp/DropdownBox.h 66 | include/raygui-cpp/DummyRec.h 67 | include/raygui-cpp/Globals.h 68 | include/raygui-cpp/Grid.h 69 | include/raygui-cpp/GroupBox.h 70 | include/raygui-cpp/LabelButton.h 71 | include/raygui-cpp/Label.h 72 | include/raygui-cpp/Line.h 73 | include/raygui-cpp/ListViewEx.h 74 | include/raygui-cpp/ListView.h 75 | include/raygui-cpp/MessageBox.h 76 | include/raygui-cpp/Panel.h 77 | include/raygui-cpp/ProgressBar.h 78 | include/raygui-cpp/ScrollPanel.h 79 | include/raygui-cpp/SliderBar.h 80 | include/raygui-cpp/Slider.h 81 | include/raygui-cpp/Spinner.h 82 | include/raygui-cpp/StatusBar.h 83 | include/raygui-cpp/TabBar.h 84 | include/raygui-cpp/TextBox.h 85 | include/raygui-cpp/TextInputBox.h 86 | include/raygui-cpp/ToggleGroup.h 87 | include/raygui-cpp/Toggle.h 88 | include/raygui-cpp/ValueBox.h 89 | include/raygui-cpp/WindowBox.h 90 | include/raygui-cpp.h 91 | include/raygui-cpp/Component.h 92 | include/raygui-cpp/Bounds.h 93 | include/raygui-cpp/Style.h 94 | include/raygui-cpp/Margin.h 95 | include/raygui-cpp/ToggleSlider.h 96 | include/raygui-cpp/ColorPickerHSV.h 97 | include/raygui-cpp/ColorPanelHSV.h 98 | include/raygui-cpp/Utils.h 99 | include/raygui-cpp/Paintable.h 100 | include/raygui-cpp/extras/ImageButton.h 101 | ) 102 | 103 | option(BUILD_SHARED_LIBS "Build raygui_cpp as shared library" OFF) 104 | 105 | if (BUILD_SHARED_LIBS) 106 | message(STATUS "Building raygui_cpp as shared library") 107 | add_library(raygui_cpp SHARED ${RAYGUI_CPP_SOURCE_FILES} ${RAYGUI_CPP_HEADER_FILES}) 108 | else () 109 | message(STATUS "Building raygui_cpp as static library") 110 | add_library(raygui_cpp STATIC ${RAYGUI_CPP_SOURCE_FILES} ${RAYGUI_CPP_HEADER_FILES}) 111 | endif () 112 | 113 | include(cmake/CPM.cmake) 114 | CPMAddPackage("gh:raysan5/raylib#5.5") 115 | 116 | target_link_libraries(raygui_cpp 117 | PUBLIC raylib 118 | ) 119 | 120 | target_include_directories(raygui_cpp 121 | PUBLIC $ 122 | PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/raylib/src 123 | ) 124 | 125 | set_target_properties(raygui_cpp PROPERTIES 126 | CXX_STANDARD 17 127 | CXX_STANDARD_REQUIRED YES 128 | CXX_EXTENSIONS NO 129 | VERSION ${PROJECT_VERSION} 130 | SOVERSION ${PROJECT_VERSION_MAJOR} 131 | ) 132 | 133 | # Examples 134 | option(BUILD_RAYGUI_EXAMPLES "Build examples" ON) 135 | 136 | if (BUILD_RAYGUI_EXAMPLES) 137 | message(STATUS "Building raygui examples") 138 | add_subdirectory(examples) 139 | endif () 140 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023 Samuel Castrillo Dominguez (@scastd) 2 | 3 | This software is provided ‘as-is’, without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must not be 17 | misrepresented as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source 20 | distribution. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![raygui_cpp_256x256.png](raygui_cpp_256x256.png) 2 | 3 | # Raygui-cpp 4 | 5 | Raygui-cpp is a C++ wrapper for [raygui](https://github.com/raysan5/raygui) library. 6 | Raygui was originally written in C, but this wrapper allows you to use it in C++ projects. 7 | 8 | NOTES: 9 | 10 | - This is a work in progress. Some functions are not yet implemented. 11 | - To ease the integration between raylib and raygui, the `raygui.h` file has been divided in two files: `raygui.h` and 12 | `raygui.cpp`. 13 | The raygui.cpp file contains the implementation of the functions, while the `raygui.h` file contains the 14 | declarations. 15 | This is done to avoid the multiple definition of the same functions when linking the raygui library 16 | with raylib. 17 | 18 | ## Usage 19 | 20 | To use raygui-cpp in your project, you need to download the source code and add it to your project. 21 | Add the folder containing the source code to your `include` path and add the next configuration to your CMakeLists.txt 22 | file: 23 | 24 | ```cmake 25 | add_subdirectory() 26 | target_link_libraries( raygui_cpp) 27 | ``` 28 | 29 | ## Implementation todo list 30 | 31 | - [x] Button ([header](include/raygui-cpp/Button.h), [source](src/raygui-cpp/Button.cpp)) 32 | - [x] CheckBox ([header](include/raygui-cpp/CheckBox.h), [source](src/raygui-cpp/CheckBox.cpp)) 33 | - [x] ColorBarAlpha ([header](include/raygui-cpp/ColorBarAlpha.h), [source](src/raygui-cpp/ColorBarAlpha.cpp)) 34 | - [x] ColorBarHue ([header](include/raygui-cpp/ColorBarHue.h), [source](src/raygui-cpp/ColorBarHue.cpp)) 35 | - [x] ColorPanel ([header](include/raygui-cpp/ColorPanel.h), [source](src/raygui-cpp/ColorPanel.cpp)) 36 | - [x] ColorPicker ([header](include/raygui-cpp/ColorPicker.h), [source](src/raygui-cpp/ColorPicker.cpp)) 37 | - [x] ComboBox ([header](include/raygui-cpp/ComboBox.h), [source](src/raygui-cpp/ComboBox.cpp)) 38 | - [x] DropdownBox ([header](include/raygui-cpp/DropdownBox.h), [source](src/raygui-cpp/DropdownBox.cpp)) 39 | - [x] DummyRec ([header](include/raygui-cpp/DummyRec.h), [source](src/raygui-cpp/DummyRec.cpp)) 40 | - [x] Globals ([header](include/raygui-cpp/Globals.h), [source](src/raygui-cpp/Globals.cpp)) 41 | - [x] Grid ([header](include/raygui-cpp/Grid.h), [source](src/raygui-cpp/Grid.cpp)) 42 | - [x] GroupBox ([header](include/raygui-cpp/GroupBox.h), [source](src/raygui-cpp/GroupBox.cpp)) 43 | - [x] Label ([header](include/raygui-cpp/Label.h), [source](src/raygui-cpp/Label.cpp)) 44 | - [x] LabelButton ([header](include/raygui-cpp/LabelButton.h), [source](src/raygui-cpp/LabelButton.cpp)) 45 | - [x] Line ([header](include/raygui-cpp/Line.h), [source](src/raygui-cpp/Line.cpp)) 46 | - [x] ListView ([header](include/raygui-cpp/ListView.h), [source](src/raygui-cpp/ListView.cpp)) 47 | - [x] ListViewEx ([header](include/raygui-cpp/ListViewEx.h), [source](src/raygui-cpp/ListViewEx.cpp)) 48 | - [x] MessageBox ([header](include/raygui-cpp/MessageBox.h), [source](src/raygui-cpp/MessageBox.cpp)) 49 | - [x] Panel ([header](include/raygui-cpp/Panel.h), [source](src/raygui-cpp/Panel.cpp)) 50 | - [x] ProgressBar ([header](include/raygui-cpp/ProgressBar.h), [source](src/raygui-cpp/ProgressBar.cpp)) 51 | - [x] ScrollPanel ([header](include/raygui-cpp/ScrollPanel.h), [source](src/raygui-cpp/ScrollPanel.cpp)) 52 | - [x] Slider ([header](include/raygui-cpp/Slider.h), [source](src/raygui-cpp/Slider.cpp)) 53 | - [x] SliderBar ([header](include/raygui-cpp/SliderBar.h), [source](src/raygui-cpp/SliderBar.cpp)) 54 | - [x] Spinner ([header](include/raygui-cpp/Spinner.h), [source](src/raygui-cpp/Spinner.cpp)) 55 | - [x] StatusBar ([header](include/raygui-cpp/StatusBar.h), [source](src/raygui-cpp/StatusBar.cpp)) 56 | - [x] TabBar ([header](include/raygui-cpp/TabBar.h), [source](src/raygui-cpp/TabBar.cpp)) 57 | - [x] TextBox ([header](include/raygui-cpp/TextBox.h), [source](src/raygui-cpp/TextBox.cpp)) 58 | - [x] TextInputBox ([header](include/raygui-cpp/TextInputBox.h), [source](src/raygui-cpp/TextInputBox.cpp)) 59 | - [x] Toggle ([header](include/raygui-cpp/Toggle.h), [source](src/raygui-cpp/Toggle.cpp)) 60 | - [x] ToggleGroup ([header](include/raygui-cpp/ToggleGroup.h), [source](src/raygui-cpp/ToggleGroup.cpp)) 61 | - [x] ValueBox ([header](include/raygui-cpp/ValueBox.h), [source](src/raygui-cpp/ValueBox.cpp)) 62 | - [x] WindowBox ([header](include/raygui-cpp/WindowBox.h), [source](src/raygui-cpp/WindowBox.cpp)) 63 | 64 | ## More info 65 | 66 | For more information about raygui, visit the [official raygui repository](https://github.com/raysan5/raygui). 67 | 68 | ## License 69 | 70 | Raygui-cpp is licensed under zlib/libpng license, same as raygui. See [LICENSE.txt](LICENSE.txt) for more information. 71 | 72 | ## Author 73 | 74 | Raygui-cpp is developed by: 75 | 76 | - [Samuel Castrillo](https://github.com/scastd) 77 | -------------------------------------------------------------------------------- /Todo.md: -------------------------------------------------------------------------------- 1 | # Todo list 2 | 3 | This file is a todo list for the project. It is not meant to be exhaustive, but 4 | rather to give a general idea of what needs to be done. 5 | 6 | ## Todo 7 | 8 | - [ ] Component positioning: 9 | - [ ] Left 10 | - [ ] Right 11 | - [ ] Top 12 | - [ ] Bottom 13 | - [ ] Center 14 | - Notes: 15 | - Create an enum for the options. 16 | - When showing the component, check the option and show it in the correct 17 | place using `MeasureTextEx` method and the position assigned to the component. 18 | 19 | - [ ] Component text padding: 20 | - [ ] Left 21 | - [ ] Right 22 | - [ ] Top 23 | - [ ] Bottom 24 | -------------------------------------------------------------------------------- /cmake/CPM.cmake: -------------------------------------------------------------------------------- 1 | # CPM.cmake - CMake's missing package manager 2 | # =========================================== 3 | # See https://github.com/cpm-cmake/CPM.cmake for usage and update instructions. 4 | # 5 | # MIT License 6 | # ----------- 7 | #[[ 8 | Copyright (c) 2019-2023 Lars Melchior and contributors 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | ]] 28 | 29 | cmake_minimum_required(VERSION 3.14 FATAL_ERROR) 30 | 31 | # Initialize logging prefix 32 | if (NOT CPM_INDENT) 33 | set(CPM_INDENT 34 | "CPM:" 35 | CACHE INTERNAL "" 36 | ) 37 | endif () 38 | 39 | if (NOT COMMAND cpm_message) 40 | function(cpm_message) 41 | message(${ARGV}) 42 | endfunction() 43 | endif () 44 | 45 | set(CURRENT_CPM_VERSION 0.40.5) 46 | 47 | get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH) 48 | if (CPM_DIRECTORY) 49 | if (NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY) 50 | if (CPM_VERSION VERSION_LESS CURRENT_CPM_VERSION) 51 | message( 52 | AUTHOR_WARNING 53 | "${CPM_INDENT} \ 54 | A dependency is using a more recent CPM version (${CURRENT_CPM_VERSION}) than the current project (${CPM_VERSION}). \ 55 | It is recommended to upgrade CPM to the most recent version. \ 56 | See https://github.com/cpm-cmake/CPM.cmake for more information." 57 | ) 58 | endif () 59 | if (${CMAKE_VERSION} VERSION_LESS "3.17.0") 60 | include(FetchContent) 61 | endif () 62 | return() 63 | endif () 64 | 65 | get_property( 66 | CPM_INITIALIZED GLOBAL "" 67 | PROPERTY CPM_INITIALIZED 68 | SET 69 | ) 70 | if (CPM_INITIALIZED) 71 | return() 72 | endif () 73 | endif () 74 | 75 | if (CURRENT_CPM_VERSION MATCHES "development-version") 76 | message( 77 | WARNING "${CPM_INDENT} Your project is using an unstable development version of CPM.cmake. \ 78 | Please update to a recent release if possible. \ 79 | See https://github.com/cpm-cmake/CPM.cmake for details." 80 | ) 81 | endif () 82 | 83 | set_property(GLOBAL PROPERTY CPM_INITIALIZED true) 84 | 85 | macro(cpm_set_policies) 86 | # the policy allows us to change options without caching 87 | cmake_policy(SET CMP0077 NEW) 88 | set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) 89 | 90 | # the policy allows us to change set(CACHE) without caching 91 | if (POLICY CMP0126) 92 | cmake_policy(SET CMP0126 NEW) 93 | set(CMAKE_POLICY_DEFAULT_CMP0126 NEW) 94 | endif () 95 | 96 | # The policy uses the download time for timestamp, instead of the timestamp in the archive. This 97 | # allows for proper rebuilds when a projects url changes 98 | if (POLICY CMP0135) 99 | cmake_policy(SET CMP0135 NEW) 100 | set(CMAKE_POLICY_DEFAULT_CMP0135 NEW) 101 | endif () 102 | 103 | # treat relative git repository paths as being relative to the parent project's remote 104 | if (POLICY CMP0150) 105 | cmake_policy(SET CMP0150 NEW) 106 | set(CMAKE_POLICY_DEFAULT_CMP0150 NEW) 107 | endif () 108 | endmacro() 109 | cpm_set_policies() 110 | 111 | option(CPM_USE_LOCAL_PACKAGES "Always try to use `find_package` to get dependencies" 112 | $ENV{CPM_USE_LOCAL_PACKAGES} 113 | ) 114 | option(CPM_LOCAL_PACKAGES_ONLY "Only use `find_package` to get dependencies" 115 | $ENV{CPM_LOCAL_PACKAGES_ONLY} 116 | ) 117 | option(CPM_DOWNLOAD_ALL "Always download dependencies from source" $ENV{CPM_DOWNLOAD_ALL}) 118 | option(CPM_DONT_UPDATE_MODULE_PATH "Don't update the module path to allow using find_package" 119 | $ENV{CPM_DONT_UPDATE_MODULE_PATH} 120 | ) 121 | option(CPM_DONT_CREATE_PACKAGE_LOCK "Don't create a package lock file in the binary path" 122 | $ENV{CPM_DONT_CREATE_PACKAGE_LOCK} 123 | ) 124 | option(CPM_INCLUDE_ALL_IN_PACKAGE_LOCK 125 | "Add all packages added through CPM.cmake to the package lock" 126 | $ENV{CPM_INCLUDE_ALL_IN_PACKAGE_LOCK} 127 | ) 128 | option(CPM_USE_NAMED_CACHE_DIRECTORIES 129 | "Use additional directory of package name in cache on the most nested level." 130 | $ENV{CPM_USE_NAMED_CACHE_DIRECTORIES} 131 | ) 132 | 133 | set(CPM_VERSION 134 | ${CURRENT_CPM_VERSION} 135 | CACHE INTERNAL "" 136 | ) 137 | set(CPM_DIRECTORY 138 | ${CPM_CURRENT_DIRECTORY} 139 | CACHE INTERNAL "" 140 | ) 141 | set(CPM_FILE 142 | ${CMAKE_CURRENT_LIST_FILE} 143 | CACHE INTERNAL "" 144 | ) 145 | set(CPM_PACKAGES 146 | "" 147 | CACHE INTERNAL "" 148 | ) 149 | set(CPM_DRY_RUN 150 | OFF 151 | CACHE INTERNAL "Don't download or configure dependencies (for testing)" 152 | ) 153 | 154 | if (DEFINED ENV{CPM_SOURCE_CACHE}) 155 | set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE}) 156 | else () 157 | set(CPM_SOURCE_CACHE_DEFAULT OFF) 158 | endif () 159 | 160 | set(CPM_SOURCE_CACHE 161 | ${CPM_SOURCE_CACHE_DEFAULT} 162 | CACHE PATH "Directory to download CPM dependencies" 163 | ) 164 | 165 | if (NOT CPM_DONT_UPDATE_MODULE_PATH AND NOT DEFINED CMAKE_FIND_PACKAGE_REDIRECTS_DIR) 166 | set(CPM_MODULE_PATH 167 | "${CMAKE_BINARY_DIR}/CPM_modules" 168 | CACHE INTERNAL "" 169 | ) 170 | # remove old modules 171 | file(REMOVE_RECURSE ${CPM_MODULE_PATH}) 172 | file(MAKE_DIRECTORY ${CPM_MODULE_PATH}) 173 | # locally added CPM modules should override global packages 174 | set(CMAKE_MODULE_PATH "${CPM_MODULE_PATH};${CMAKE_MODULE_PATH}") 175 | endif () 176 | 177 | if (NOT CPM_DONT_CREATE_PACKAGE_LOCK) 178 | set(CPM_PACKAGE_LOCK_FILE 179 | "${CMAKE_BINARY_DIR}/cpm-package-lock.cmake" 180 | CACHE INTERNAL "" 181 | ) 182 | file(WRITE ${CPM_PACKAGE_LOCK_FILE} 183 | "# CPM Package Lock\n# This file should be committed to version control\n\n" 184 | ) 185 | endif () 186 | 187 | include(FetchContent) 188 | 189 | # Try to infer package name from git repository uri (path or url) 190 | function(cpm_package_name_from_git_uri URI RESULT) 191 | if ("${URI}" MATCHES "([^/:]+)/?.git/?$") 192 | set(${RESULT} 193 | ${CMAKE_MATCH_1} 194 | PARENT_SCOPE 195 | ) 196 | else () 197 | unset(${RESULT} PARENT_SCOPE) 198 | endif () 199 | endfunction() 200 | 201 | # Try to infer package name and version from a url 202 | function(cpm_package_name_and_ver_from_url url outName outVer) 203 | if (url MATCHES "[/\\?]([a-zA-Z0-9_\\.-]+)\\.(tar|tar\\.gz|tar\\.bz2|zip|ZIP)(\\?|/|$)") 204 | # We matched an archive 205 | set(filename "${CMAKE_MATCH_1}") 206 | 207 | if (filename MATCHES "([a-zA-Z0-9_\\.-]+)[_-]v?(([0-9]+\\.)*[0-9]+[a-zA-Z0-9]*)") 208 | # We matched - (ie foo-1.2.3) 209 | set(${outName} 210 | "${CMAKE_MATCH_1}" 211 | PARENT_SCOPE 212 | ) 213 | set(${outVer} 214 | "${CMAKE_MATCH_2}" 215 | PARENT_SCOPE 216 | ) 217 | elseif (filename MATCHES "(([0-9]+\\.)+[0-9]+[a-zA-Z0-9]*)") 218 | # We couldn't find a name, but we found a version 219 | # 220 | # In many cases (which we don't handle here) the url would look something like 221 | # `irrelevant/ACTUAL_PACKAGE_NAME/irrelevant/1.2.3.zip`. In such a case we can't possibly 222 | # distinguish the package name from the irrelevant bits. Moreover if we try to match the 223 | # package name from the filename, we'd get bogus at best. 224 | unset(${outName} PARENT_SCOPE) 225 | set(${outVer} 226 | "${CMAKE_MATCH_1}" 227 | PARENT_SCOPE 228 | ) 229 | else () 230 | # Boldly assume that the file name is the package name. 231 | # 232 | # Yes, something like `irrelevant/ACTUAL_NAME/irrelevant/download.zip` will ruin our day, but 233 | # such cases should be quite rare. No popular service does this... we think. 234 | set(${outName} 235 | "${filename}" 236 | PARENT_SCOPE 237 | ) 238 | unset(${outVer} PARENT_SCOPE) 239 | endif () 240 | else () 241 | # No ideas yet what to do with non-archives 242 | unset(${outName} PARENT_SCOPE) 243 | unset(${outVer} PARENT_SCOPE) 244 | endif () 245 | endfunction() 246 | 247 | function(cpm_find_package NAME VERSION) 248 | string(REPLACE " " ";" EXTRA_ARGS "${ARGN}") 249 | find_package(${NAME} ${VERSION} ${EXTRA_ARGS} QUIET) 250 | if (${CPM_ARGS_NAME}_FOUND) 251 | if (DEFINED ${CPM_ARGS_NAME}_VERSION) 252 | set(VERSION ${${CPM_ARGS_NAME}_VERSION}) 253 | endif () 254 | cpm_message(STATUS "${CPM_INDENT} Using local package ${CPM_ARGS_NAME}@${VERSION}") 255 | CPMRegisterPackage(${CPM_ARGS_NAME} "${VERSION}") 256 | set(CPM_PACKAGE_FOUND 257 | YES 258 | PARENT_SCOPE 259 | ) 260 | else () 261 | set(CPM_PACKAGE_FOUND 262 | NO 263 | PARENT_SCOPE 264 | ) 265 | endif () 266 | endfunction() 267 | 268 | # Create a custom FindXXX.cmake module for a CPM package This prevents `find_package(NAME)` from 269 | # finding the system library 270 | function(cpm_create_module_file Name) 271 | if (NOT CPM_DONT_UPDATE_MODULE_PATH) 272 | if (DEFINED CMAKE_FIND_PACKAGE_REDIRECTS_DIR) 273 | # Redirect find_package calls to the CPM package. This is what FetchContent does when you set 274 | # OVERRIDE_FIND_PACKAGE. The CMAKE_FIND_PACKAGE_REDIRECTS_DIR works for find_package in CONFIG 275 | # mode, unlike the Find${Name}.cmake fallback. CMAKE_FIND_PACKAGE_REDIRECTS_DIR is not defined 276 | # in script mode, or in CMake < 3.24. 277 | # https://cmake.org/cmake/help/latest/module/FetchContent.html#fetchcontent-find-package-integration-examples 278 | string(TOLOWER ${Name} NameLower) 279 | file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config.cmake 280 | "include(\"${CMAKE_CURRENT_LIST_DIR}/${NameLower}-extra.cmake\" OPTIONAL)\n" 281 | "include(\"${CMAKE_CURRENT_LIST_DIR}/${Name}Extra.cmake\" OPTIONAL)\n" 282 | ) 283 | file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-version.cmake 284 | "set(PACKAGE_VERSION_COMPATIBLE TRUE)\n" "set(PACKAGE_VERSION_EXACT TRUE)\n" 285 | ) 286 | else () 287 | file(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake 288 | "include(\"${CPM_FILE}\")\n${ARGN}\nset(${Name}_FOUND TRUE)" 289 | ) 290 | endif () 291 | endif () 292 | endfunction() 293 | 294 | # Find a package locally or fallback to CPMAddPackage 295 | function(CPMFindPackage) 296 | set(oneValueArgs NAME VERSION GIT_TAG FIND_PACKAGE_ARGUMENTS) 297 | 298 | cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "" ${ARGN}) 299 | 300 | if (NOT DEFINED CPM_ARGS_VERSION) 301 | if (DEFINED CPM_ARGS_GIT_TAG) 302 | cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION) 303 | endif () 304 | endif () 305 | 306 | set(downloadPackage ${CPM_DOWNLOAD_ALL}) 307 | if (DEFINED CPM_DOWNLOAD_${CPM_ARGS_NAME}) 308 | set(downloadPackage ${CPM_DOWNLOAD_${CPM_ARGS_NAME}}) 309 | elseif (DEFINED ENV{CPM_DOWNLOAD_${CPM_ARGS_NAME}}) 310 | set(downloadPackage $ENV{CPM_DOWNLOAD_${CPM_ARGS_NAME}}) 311 | endif () 312 | if (downloadPackage) 313 | CPMAddPackage(${ARGN}) 314 | cpm_export_variables(${CPM_ARGS_NAME}) 315 | return() 316 | endif () 317 | 318 | cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS}) 319 | 320 | if (NOT CPM_PACKAGE_FOUND) 321 | CPMAddPackage(${ARGN}) 322 | cpm_export_variables(${CPM_ARGS_NAME}) 323 | endif () 324 | 325 | endfunction() 326 | 327 | # checks if a package has been added before 328 | function(cpm_check_if_package_already_added CPM_ARGS_NAME CPM_ARGS_VERSION) 329 | if ("${CPM_ARGS_NAME}" IN_LIST CPM_PACKAGES) 330 | CPMGetPackageVersion(${CPM_ARGS_NAME} CPM_PACKAGE_VERSION) 331 | if ("${CPM_PACKAGE_VERSION}" VERSION_LESS "${CPM_ARGS_VERSION}") 332 | message( 333 | WARNING 334 | "${CPM_INDENT} Requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION})." 335 | ) 336 | endif () 337 | cpm_get_fetch_properties(${CPM_ARGS_NAME}) 338 | set(${CPM_ARGS_NAME}_ADDED NO) 339 | set(CPM_PACKAGE_ALREADY_ADDED 340 | YES 341 | PARENT_SCOPE 342 | ) 343 | cpm_export_variables(${CPM_ARGS_NAME}) 344 | else () 345 | set(CPM_PACKAGE_ALREADY_ADDED 346 | NO 347 | PARENT_SCOPE 348 | ) 349 | endif () 350 | endfunction() 351 | 352 | # Parse the argument of CPMAddPackage in case a single one was provided and convert it to a list of 353 | # arguments which can then be parsed idiomatically. For example gh:foo/bar@1.2.3 will be converted 354 | # to: GITHUB_REPOSITORY;foo/bar;VERSION;1.2.3 355 | function(cpm_parse_add_package_single_arg arg outArgs) 356 | # Look for a scheme 357 | if ("${arg}" MATCHES "^([a-zA-Z]+):(.+)$") 358 | string(TOLOWER "${CMAKE_MATCH_1}" scheme) 359 | set(uri "${CMAKE_MATCH_2}") 360 | 361 | # Check for CPM-specific schemes 362 | if (scheme STREQUAL "gh") 363 | set(out "GITHUB_REPOSITORY;${uri}") 364 | set(packageType "git") 365 | elseif (scheme STREQUAL "gl") 366 | set(out "GITLAB_REPOSITORY;${uri}") 367 | set(packageType "git") 368 | elseif (scheme STREQUAL "bb") 369 | set(out "BITBUCKET_REPOSITORY;${uri}") 370 | set(packageType "git") 371 | # A CPM-specific scheme was not found. Looks like this is a generic URL so try to determine 372 | # type 373 | elseif (arg MATCHES ".git/?(@|#|$)") 374 | set(out "GIT_REPOSITORY;${arg}") 375 | set(packageType "git") 376 | else () 377 | # Fall back to a URL 378 | set(out "URL;${arg}") 379 | set(packageType "archive") 380 | 381 | # We could also check for SVN since FetchContent supports it, but SVN is so rare these days. 382 | # We just won't bother with the additional complexity it will induce in this function. SVN is 383 | # done by multi-arg 384 | endif () 385 | else () 386 | if (arg MATCHES ".git/?(@|#|$)") 387 | set(out "GIT_REPOSITORY;${arg}") 388 | set(packageType "git") 389 | else () 390 | # Give up 391 | message(FATAL_ERROR "${CPM_INDENT} Can't determine package type of '${arg}'") 392 | endif () 393 | endif () 394 | 395 | # For all packages we interpret @... as version. Only replace the last occurrence. Thus URIs 396 | # containing '@' can be used 397 | string(REGEX REPLACE "@([^@]+)$" ";VERSION;\\1" out "${out}") 398 | 399 | # Parse the rest according to package type 400 | if (packageType STREQUAL "git") 401 | # For git repos we interpret #... as a tag or branch or commit hash 402 | string(REGEX REPLACE "#([^#]+)$" ";GIT_TAG;\\1" out "${out}") 403 | elseif (packageType STREQUAL "archive") 404 | # For archives we interpret #... as a URL hash. 405 | string(REGEX REPLACE "#([^#]+)$" ";URL_HASH;\\1" out "${out}") 406 | # We don't try to parse the version if it's not provided explicitly. cpm_get_version_from_url 407 | # should do this at a later point 408 | else () 409 | # We should never get here. This is an assertion and hitting it means there's a problem with the 410 | # code above. A packageType was set, but not handled by this if-else. 411 | message(FATAL_ERROR "${CPM_INDENT} Unsupported package type '${packageType}' of '${arg}'") 412 | endif () 413 | 414 | set(${outArgs} 415 | ${out} 416 | PARENT_SCOPE 417 | ) 418 | endfunction() 419 | 420 | # Check that the working directory for a git repo is clean 421 | function(cpm_check_git_working_dir_is_clean repoPath gitTag isClean) 422 | 423 | find_package(Git REQUIRED) 424 | 425 | if (NOT GIT_EXECUTABLE) 426 | # No git executable, assume directory is clean 427 | set(${isClean} 428 | TRUE 429 | PARENT_SCOPE 430 | ) 431 | return() 432 | endif () 433 | 434 | # check for uncommitted changes 435 | execute_process( 436 | COMMAND ${GIT_EXECUTABLE} status --porcelain 437 | RESULT_VARIABLE resultGitStatus 438 | OUTPUT_VARIABLE repoStatus 439 | OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET 440 | WORKING_DIRECTORY ${repoPath} 441 | ) 442 | if (resultGitStatus) 443 | # not supposed to happen, assume clean anyway 444 | message(WARNING "${CPM_INDENT} Calling git status on folder ${repoPath} failed") 445 | set(${isClean} 446 | TRUE 447 | PARENT_SCOPE 448 | ) 449 | return() 450 | endif () 451 | 452 | if (NOT "${repoStatus}" STREQUAL "") 453 | set(${isClean} 454 | FALSE 455 | PARENT_SCOPE 456 | ) 457 | return() 458 | endif () 459 | 460 | # check for committed changes 461 | execute_process( 462 | COMMAND ${GIT_EXECUTABLE} diff -s --exit-code ${gitTag} 463 | RESULT_VARIABLE resultGitDiff 464 | OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_QUIET 465 | WORKING_DIRECTORY ${repoPath} 466 | ) 467 | 468 | if (${resultGitDiff} EQUAL 0) 469 | set(${isClean} 470 | TRUE 471 | PARENT_SCOPE 472 | ) 473 | else () 474 | set(${isClean} 475 | FALSE 476 | PARENT_SCOPE 477 | ) 478 | endif () 479 | 480 | endfunction() 481 | 482 | # Add PATCH_COMMAND to CPM_ARGS_UNPARSED_ARGUMENTS. This method consumes a list of files in ARGN 483 | # then generates a `PATCH_COMMAND` appropriate for `ExternalProject_Add()`. This command is appended 484 | # to the parent scope's `CPM_ARGS_UNPARSED_ARGUMENTS`. 485 | function(cpm_add_patches) 486 | # Return if no patch files are supplied. 487 | if (NOT ARGN) 488 | return() 489 | endif () 490 | 491 | # Find the patch program. 492 | find_program(PATCH_EXECUTABLE patch) 493 | if (CMAKE_HOST_WIN32 AND NOT PATCH_EXECUTABLE) 494 | # The Windows git executable is distributed with patch.exe. Find the path to the executable, if 495 | # it exists, then search `../usr/bin` and `../../usr/bin` for patch.exe. 496 | find_package(Git QUIET) 497 | if (GIT_EXECUTABLE) 498 | get_filename_component(extra_search_path ${GIT_EXECUTABLE} DIRECTORY) 499 | get_filename_component(extra_search_path_1up ${extra_search_path} DIRECTORY) 500 | get_filename_component(extra_search_path_2up ${extra_search_path_1up} DIRECTORY) 501 | find_program( 502 | PATCH_EXECUTABLE patch HINTS "${extra_search_path_1up}/usr/bin" 503 | "${extra_search_path_2up}/usr/bin" 504 | ) 505 | endif () 506 | endif () 507 | if (NOT PATCH_EXECUTABLE) 508 | message(FATAL_ERROR "Couldn't find `patch` executable to use with PATCHES keyword.") 509 | endif () 510 | 511 | # Create a temporary 512 | set(temp_list ${CPM_ARGS_UNPARSED_ARGUMENTS}) 513 | 514 | # Ensure each file exists (or error out) and add it to the list. 515 | set(first_item True) 516 | foreach (PATCH_FILE ${ARGN}) 517 | # Make sure the patch file exists, if we can't find it, try again in the current directory. 518 | if (NOT EXISTS "${PATCH_FILE}") 519 | if (NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/${PATCH_FILE}") 520 | message(FATAL_ERROR "Couldn't find patch file: '${PATCH_FILE}'") 521 | endif () 522 | set(PATCH_FILE "${CMAKE_CURRENT_LIST_DIR}/${PATCH_FILE}") 523 | endif () 524 | 525 | # Convert to absolute path for use with patch file command. 526 | get_filename_component(PATCH_FILE "${PATCH_FILE}" ABSOLUTE) 527 | 528 | # The first patch entry must be preceded by "PATCH_COMMAND" while the following items are 529 | # preceded by "&&". 530 | if (first_item) 531 | set(first_item False) 532 | list(APPEND temp_list "PATCH_COMMAND") 533 | else () 534 | list(APPEND temp_list "&&") 535 | endif () 536 | # Add the patch command to the list 537 | list(APPEND temp_list "${PATCH_EXECUTABLE}" "-p1" "<" "${PATCH_FILE}") 538 | endforeach () 539 | 540 | # Move temp out into parent scope. 541 | set(CPM_ARGS_UNPARSED_ARGUMENTS 542 | ${temp_list} 543 | PARENT_SCOPE 544 | ) 545 | 546 | endfunction() 547 | 548 | # method to overwrite internal FetchContent properties, to allow using CPM.cmake to overload 549 | # FetchContent calls. As these are internal cmake properties, this method should be used carefully 550 | # and may need modification in future CMake versions. Source: 551 | # https://github.com/Kitware/CMake/blob/dc3d0b5a0a7d26d43d6cfeb511e224533b5d188f/Modules/FetchContent.cmake#L1152 552 | function(cpm_override_fetchcontent contentName) 553 | cmake_parse_arguments(PARSE_ARGV 1 arg "" "SOURCE_DIR;BINARY_DIR" "") 554 | if (NOT "${arg_UNPARSED_ARGUMENTS}" STREQUAL "") 555 | message(FATAL_ERROR "${CPM_INDENT} Unsupported arguments: ${arg_UNPARSED_ARGUMENTS}") 556 | endif () 557 | 558 | string(TOLOWER ${contentName} contentNameLower) 559 | set(prefix "_FetchContent_${contentNameLower}") 560 | 561 | set(propertyName "${prefix}_sourceDir") 562 | define_property( 563 | GLOBAL 564 | PROPERTY ${propertyName} 565 | BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()" 566 | FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}" 567 | ) 568 | set_property(GLOBAL PROPERTY ${propertyName} "${arg_SOURCE_DIR}") 569 | 570 | set(propertyName "${prefix}_binaryDir") 571 | define_property( 572 | GLOBAL 573 | PROPERTY ${propertyName} 574 | BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()" 575 | FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}" 576 | ) 577 | set_property(GLOBAL PROPERTY ${propertyName} "${arg_BINARY_DIR}") 578 | 579 | set(propertyName "${prefix}_populated") 580 | define_property( 581 | GLOBAL 582 | PROPERTY ${propertyName} 583 | BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()" 584 | FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}" 585 | ) 586 | set_property(GLOBAL PROPERTY ${propertyName} TRUE) 587 | endfunction() 588 | 589 | # Download and add a package from source 590 | function(CPMAddPackage) 591 | cpm_set_policies() 592 | 593 | list(LENGTH ARGN argnLength) 594 | if (argnLength EQUAL 1) 595 | cpm_parse_add_package_single_arg("${ARGN}" ARGN) 596 | 597 | # The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM 598 | set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;") 599 | endif () 600 | 601 | set(oneValueArgs 602 | NAME 603 | FORCE 604 | VERSION 605 | GIT_TAG 606 | DOWNLOAD_ONLY 607 | GITHUB_REPOSITORY 608 | GITLAB_REPOSITORY 609 | BITBUCKET_REPOSITORY 610 | GIT_REPOSITORY 611 | SOURCE_DIR 612 | FIND_PACKAGE_ARGUMENTS 613 | NO_CACHE 614 | SYSTEM 615 | GIT_SHALLOW 616 | EXCLUDE_FROM_ALL 617 | SOURCE_SUBDIR 618 | CUSTOM_CACHE_KEY 619 | ) 620 | 621 | set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND PATCHES) 622 | 623 | cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}") 624 | 625 | # Set default values for arguments 626 | 627 | if (NOT DEFINED CPM_ARGS_VERSION) 628 | if (DEFINED CPM_ARGS_GIT_TAG) 629 | cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION) 630 | endif () 631 | endif () 632 | 633 | if (CPM_ARGS_DOWNLOAD_ONLY) 634 | set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY}) 635 | else () 636 | set(DOWNLOAD_ONLY NO) 637 | endif () 638 | 639 | if (DEFINED CPM_ARGS_GITHUB_REPOSITORY) 640 | set(CPM_ARGS_GIT_REPOSITORY "https://github.com/${CPM_ARGS_GITHUB_REPOSITORY}.git") 641 | elseif (DEFINED CPM_ARGS_GITLAB_REPOSITORY) 642 | set(CPM_ARGS_GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITLAB_REPOSITORY}.git") 643 | elseif (DEFINED CPM_ARGS_BITBUCKET_REPOSITORY) 644 | set(CPM_ARGS_GIT_REPOSITORY "https://bitbucket.org/${CPM_ARGS_BITBUCKET_REPOSITORY}.git") 645 | endif () 646 | 647 | if (DEFINED CPM_ARGS_GIT_REPOSITORY) 648 | list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY ${CPM_ARGS_GIT_REPOSITORY}) 649 | if (NOT DEFINED CPM_ARGS_GIT_TAG) 650 | set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION}) 651 | endif () 652 | 653 | # If a name wasn't provided, try to infer it from the git repo 654 | if (NOT DEFINED CPM_ARGS_NAME) 655 | cpm_package_name_from_git_uri(${CPM_ARGS_GIT_REPOSITORY} CPM_ARGS_NAME) 656 | endif () 657 | endif () 658 | 659 | set(CPM_SKIP_FETCH FALSE) 660 | 661 | if (DEFINED CPM_ARGS_GIT_TAG) 662 | list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG}) 663 | # If GIT_SHALLOW is explicitly specified, honor the value. 664 | if (DEFINED CPM_ARGS_GIT_SHALLOW) 665 | list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SHALLOW ${CPM_ARGS_GIT_SHALLOW}) 666 | endif () 667 | endif () 668 | 669 | if (DEFINED CPM_ARGS_URL) 670 | # If a name or version aren't provided, try to infer them from the URL 671 | list(GET CPM_ARGS_URL 0 firstUrl) 672 | cpm_package_name_and_ver_from_url(${firstUrl} nameFromUrl verFromUrl) 673 | # If we fail to obtain name and version from the first URL, we could try other URLs if any. 674 | # However multiple URLs are expected to be quite rare, so for now we won't bother. 675 | 676 | # If the caller provided their own name and version, they trump the inferred ones. 677 | if (NOT DEFINED CPM_ARGS_NAME) 678 | set(CPM_ARGS_NAME ${nameFromUrl}) 679 | endif () 680 | if (NOT DEFINED CPM_ARGS_VERSION) 681 | set(CPM_ARGS_VERSION ${verFromUrl}) 682 | endif () 683 | 684 | list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS URL "${CPM_ARGS_URL}") 685 | endif () 686 | 687 | # Check for required arguments 688 | 689 | if (NOT DEFINED CPM_ARGS_NAME) 690 | message( 691 | FATAL_ERROR 692 | "${CPM_INDENT} 'NAME' was not provided and couldn't be automatically inferred for package added with arguments: '${ARGN}'" 693 | ) 694 | endif () 695 | 696 | # Check if package has been added before 697 | cpm_check_if_package_already_added(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}") 698 | if (CPM_PACKAGE_ALREADY_ADDED) 699 | cpm_export_variables(${CPM_ARGS_NAME}) 700 | return() 701 | endif () 702 | 703 | # Check for manual overrides 704 | if (NOT CPM_ARGS_FORCE AND NOT "${CPM_${CPM_ARGS_NAME}_SOURCE}" STREQUAL "") 705 | set(PACKAGE_SOURCE ${CPM_${CPM_ARGS_NAME}_SOURCE}) 706 | set(CPM_${CPM_ARGS_NAME}_SOURCE "") 707 | CPMAddPackage( 708 | NAME "${CPM_ARGS_NAME}" 709 | SOURCE_DIR "${PACKAGE_SOURCE}" 710 | EXCLUDE_FROM_ALL "${CPM_ARGS_EXCLUDE_FROM_ALL}" 711 | SYSTEM "${CPM_ARGS_SYSTEM}" 712 | PATCHES "${CPM_ARGS_PATCHES}" 713 | OPTIONS "${CPM_ARGS_OPTIONS}" 714 | SOURCE_SUBDIR "${CPM_ARGS_SOURCE_SUBDIR}" 715 | DOWNLOAD_ONLY "${DOWNLOAD_ONLY}" 716 | FORCE True 717 | ) 718 | cpm_export_variables(${CPM_ARGS_NAME}) 719 | return() 720 | endif () 721 | 722 | # Check for available declaration 723 | if (NOT CPM_ARGS_FORCE AND NOT "${CPM_DECLARATION_${CPM_ARGS_NAME}}" STREQUAL "") 724 | set(declaration ${CPM_DECLARATION_${CPM_ARGS_NAME}}) 725 | set(CPM_DECLARATION_${CPM_ARGS_NAME} "") 726 | CPMAddPackage(${declaration}) 727 | cpm_export_variables(${CPM_ARGS_NAME}) 728 | # checking again to ensure version and option compatibility 729 | cpm_check_if_package_already_added(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}") 730 | return() 731 | endif () 732 | 733 | if (NOT CPM_ARGS_FORCE) 734 | if (CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY) 735 | cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS}) 736 | 737 | if (CPM_PACKAGE_FOUND) 738 | cpm_export_variables(${CPM_ARGS_NAME}) 739 | return() 740 | endif () 741 | 742 | if (CPM_LOCAL_PACKAGES_ONLY) 743 | message( 744 | SEND_ERROR 745 | "${CPM_INDENT} ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})" 746 | ) 747 | endif () 748 | endif () 749 | endif () 750 | 751 | CPMRegisterPackage("${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}") 752 | 753 | if (DEFINED CPM_ARGS_GIT_TAG) 754 | set(PACKAGE_INFO "${CPM_ARGS_GIT_TAG}") 755 | elseif (DEFINED CPM_ARGS_SOURCE_DIR) 756 | set(PACKAGE_INFO "${CPM_ARGS_SOURCE_DIR}") 757 | else () 758 | set(PACKAGE_INFO "${CPM_ARGS_VERSION}") 759 | endif () 760 | 761 | if (DEFINED FETCHCONTENT_BASE_DIR) 762 | # respect user's FETCHCONTENT_BASE_DIR if set 763 | set(CPM_FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR}) 764 | else () 765 | set(CPM_FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/_deps) 766 | endif () 767 | 768 | cpm_add_patches(${CPM_ARGS_PATCHES}) 769 | 770 | if (DEFINED CPM_ARGS_DOWNLOAD_COMMAND) 771 | list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND}) 772 | elseif (DEFINED CPM_ARGS_SOURCE_DIR) 773 | list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${CPM_ARGS_SOURCE_DIR}) 774 | if (NOT IS_ABSOLUTE ${CPM_ARGS_SOURCE_DIR}) 775 | # Expand `CPM_ARGS_SOURCE_DIR` relative path. This is important because EXISTS doesn't work 776 | # for relative paths. 777 | get_filename_component( 778 | source_directory ${CPM_ARGS_SOURCE_DIR} REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR} 779 | ) 780 | else () 781 | set(source_directory ${CPM_ARGS_SOURCE_DIR}) 782 | endif () 783 | if (NOT EXISTS ${source_directory}) 784 | string(TOLOWER ${CPM_ARGS_NAME} lower_case_name) 785 | # remove timestamps so CMake will re-download the dependency 786 | file(REMOVE_RECURSE "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild") 787 | endif () 788 | elseif (CPM_SOURCE_CACHE AND NOT CPM_ARGS_NO_CACHE) 789 | string(TOLOWER ${CPM_ARGS_NAME} lower_case_name) 790 | set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS}) 791 | list(SORT origin_parameters) 792 | if (CPM_ARGS_CUSTOM_CACHE_KEY) 793 | # Application set a custom unique directory name 794 | set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${CPM_ARGS_CUSTOM_CACHE_KEY}) 795 | elseif (CPM_USE_NAMED_CACHE_DIRECTORIES) 796 | string(SHA1 origin_hash "${origin_parameters};NEW_CACHE_STRUCTURE_TAG") 797 | set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash}/${CPM_ARGS_NAME}) 798 | else () 799 | string(SHA1 origin_hash "${origin_parameters}") 800 | set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash}) 801 | endif () 802 | # Expand `download_directory` relative path. This is important because EXISTS doesn't work for 803 | # relative paths. 804 | get_filename_component(download_directory ${download_directory} ABSOLUTE) 805 | list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory}) 806 | 807 | if (CPM_SOURCE_CACHE) 808 | file(LOCK ${download_directory}/../cmake.lock) 809 | endif () 810 | 811 | if (EXISTS ${download_directory}) 812 | if (CPM_SOURCE_CACHE) 813 | file(LOCK ${download_directory}/../cmake.lock RELEASE) 814 | endif () 815 | 816 | cpm_store_fetch_properties( 817 | ${CPM_ARGS_NAME} "${download_directory}" 818 | "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build" 819 | ) 820 | cpm_get_fetch_properties("${CPM_ARGS_NAME}") 821 | 822 | if (DEFINED CPM_ARGS_GIT_TAG AND NOT (PATCH_COMMAND IN_LIST CPM_ARGS_UNPARSED_ARGUMENTS)) 823 | # warn if cache has been changed since checkout 824 | cpm_check_git_working_dir_is_clean(${download_directory} ${CPM_ARGS_GIT_TAG} IS_CLEAN) 825 | if (NOT ${IS_CLEAN}) 826 | message( 827 | WARNING "${CPM_INDENT} Cache for ${CPM_ARGS_NAME} (${download_directory}) is dirty" 828 | ) 829 | endif () 830 | endif () 831 | 832 | cpm_add_subdirectory( 833 | "${CPM_ARGS_NAME}" 834 | "${DOWNLOAD_ONLY}" 835 | "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" 836 | "${${CPM_ARGS_NAME}_BINARY_DIR}" 837 | "${CPM_ARGS_EXCLUDE_FROM_ALL}" 838 | "${CPM_ARGS_SYSTEM}" 839 | "${CPM_ARGS_OPTIONS}" 840 | ) 841 | set(PACKAGE_INFO "${PACKAGE_INFO} at ${download_directory}") 842 | 843 | # As the source dir is already cached/populated, we override the call to FetchContent. 844 | set(CPM_SKIP_FETCH TRUE) 845 | cpm_override_fetchcontent( 846 | "${lower_case_name}" SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" 847 | BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}" 848 | ) 849 | 850 | else () 851 | # Enable shallow clone when GIT_TAG is not a commit hash. Our guess may not be accurate, but 852 | # it should guarantee no commit hash get mis-detected. 853 | if (NOT DEFINED CPM_ARGS_GIT_SHALLOW) 854 | cpm_is_git_tag_commit_hash("${CPM_ARGS_GIT_TAG}" IS_HASH) 855 | if (NOT ${IS_HASH}) 856 | list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SHALLOW TRUE) 857 | endif () 858 | endif () 859 | 860 | # remove timestamps so CMake will re-download the dependency 861 | file(REMOVE_RECURSE ${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild) 862 | set(PACKAGE_INFO "${PACKAGE_INFO} to ${download_directory}") 863 | endif () 864 | endif () 865 | 866 | cpm_create_module_file(${CPM_ARGS_NAME} "CPMAddPackage(\"${ARGN}\")") 867 | 868 | if (CPM_PACKAGE_LOCK_ENABLED) 869 | if ((CPM_ARGS_VERSION AND NOT CPM_ARGS_SOURCE_DIR) OR CPM_INCLUDE_ALL_IN_PACKAGE_LOCK) 870 | cpm_add_to_package_lock(${CPM_ARGS_NAME} "${ARGN}") 871 | elseif (CPM_ARGS_SOURCE_DIR) 872 | cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "local directory") 873 | else () 874 | cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "${ARGN}") 875 | endif () 876 | endif () 877 | 878 | cpm_message( 879 | STATUS "${CPM_INDENT} Adding package ${CPM_ARGS_NAME}@${CPM_ARGS_VERSION} (${PACKAGE_INFO})" 880 | ) 881 | 882 | if (NOT CPM_SKIP_FETCH) 883 | # CMake 3.28 added EXCLUDE, SYSTEM (3.25), and SOURCE_SUBDIR (3.18) to FetchContent_Declare. 884 | # Calling FetchContent_MakeAvailable will then internally forward these options to 885 | # add_subdirectory. Up until these changes, we had to call FetchContent_Populate and 886 | # add_subdirectory separately, which is no longer necessary and has been deprecated as of 3.30. 887 | # A Bug in CMake prevents us to use the non-deprecated functions until 3.30.3. 888 | set(fetchContentDeclareExtraArgs "") 889 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30.3") 890 | if (${CPM_ARGS_EXCLUDE_FROM_ALL}) 891 | list(APPEND fetchContentDeclareExtraArgs EXCLUDE_FROM_ALL) 892 | endif () 893 | if (${CPM_ARGS_SYSTEM}) 894 | list(APPEND fetchContentDeclareExtraArgs SYSTEM) 895 | endif () 896 | if (DEFINED CPM_ARGS_SOURCE_SUBDIR) 897 | list(APPEND fetchContentDeclareExtraArgs SOURCE_SUBDIR ${CPM_ARGS_SOURCE_SUBDIR}) 898 | endif () 899 | # For CMake version <3.28 OPTIONS are parsed in cpm_add_subdirectory 900 | if (CPM_ARGS_OPTIONS AND NOT DOWNLOAD_ONLY) 901 | foreach (OPTION ${CPM_ARGS_OPTIONS}) 902 | cpm_parse_option("${OPTION}") 903 | set(${OPTION_KEY} "${OPTION_VALUE}") 904 | endforeach () 905 | endif () 906 | endif () 907 | cpm_declare_fetch( 908 | "${CPM_ARGS_NAME}" ${fetchContentDeclareExtraArgs} "${CPM_ARGS_UNPARSED_ARGUMENTS}" 909 | ) 910 | 911 | cpm_fetch_package("${CPM_ARGS_NAME}" ${DOWNLOAD_ONLY} populated ${CPM_ARGS_UNPARSED_ARGUMENTS}) 912 | if (CPM_SOURCE_CACHE AND download_directory) 913 | file(LOCK ${download_directory}/../cmake.lock RELEASE) 914 | endif () 915 | if (${populated} AND ${CMAKE_VERSION} VERSION_LESS "3.30.3") 916 | cpm_add_subdirectory( 917 | "${CPM_ARGS_NAME}" 918 | "${DOWNLOAD_ONLY}" 919 | "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}" 920 | "${${CPM_ARGS_NAME}_BINARY_DIR}" 921 | "${CPM_ARGS_EXCLUDE_FROM_ALL}" 922 | "${CPM_ARGS_SYSTEM}" 923 | "${CPM_ARGS_OPTIONS}" 924 | ) 925 | endif () 926 | cpm_get_fetch_properties("${CPM_ARGS_NAME}") 927 | endif () 928 | 929 | set(${CPM_ARGS_NAME}_ADDED YES) 930 | cpm_export_variables("${CPM_ARGS_NAME}") 931 | endfunction() 932 | 933 | # Fetch a previously declared package 934 | macro(CPMGetPackage Name) 935 | if (DEFINED "CPM_DECLARATION_${Name}") 936 | CPMAddPackage(NAME ${Name}) 937 | else () 938 | message(SEND_ERROR "${CPM_INDENT} Cannot retrieve package ${Name}: no declaration available") 939 | endif () 940 | endmacro() 941 | 942 | # export variables available to the caller to the parent scope expects ${CPM_ARGS_NAME} to be set 943 | macro(cpm_export_variables name) 944 | set(${name}_SOURCE_DIR 945 | "${${name}_SOURCE_DIR}" 946 | PARENT_SCOPE 947 | ) 948 | set(${name}_BINARY_DIR 949 | "${${name}_BINARY_DIR}" 950 | PARENT_SCOPE 951 | ) 952 | set(${name}_ADDED 953 | "${${name}_ADDED}" 954 | PARENT_SCOPE 955 | ) 956 | set(CPM_LAST_PACKAGE_NAME 957 | "${name}" 958 | PARENT_SCOPE 959 | ) 960 | endmacro() 961 | 962 | # declares a package, so that any call to CPMAddPackage for the package name will use these 963 | # arguments instead. Previous declarations will not be overridden. 964 | macro(CPMDeclarePackage Name) 965 | if (NOT DEFINED "CPM_DECLARATION_${Name}") 966 | set("CPM_DECLARATION_${Name}" "${ARGN}") 967 | endif () 968 | endmacro() 969 | 970 | function(cpm_add_to_package_lock Name) 971 | if (NOT CPM_DONT_CREATE_PACKAGE_LOCK) 972 | cpm_prettify_package_arguments(PRETTY_ARGN false ${ARGN}) 973 | file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name}\nCPMDeclarePackage(${Name}\n${PRETTY_ARGN})\n") 974 | endif () 975 | endfunction() 976 | 977 | function(cpm_add_comment_to_package_lock Name) 978 | if (NOT CPM_DONT_CREATE_PACKAGE_LOCK) 979 | cpm_prettify_package_arguments(PRETTY_ARGN true ${ARGN}) 980 | file(APPEND ${CPM_PACKAGE_LOCK_FILE} 981 | "# ${Name} (unversioned)\n# CPMDeclarePackage(${Name}\n${PRETTY_ARGN}#)\n" 982 | ) 983 | endif () 984 | endfunction() 985 | 986 | # includes the package lock file if it exists and creates a target `cpm-update-package-lock` to 987 | # update it 988 | macro(CPMUsePackageLock file) 989 | if (NOT CPM_DONT_CREATE_PACKAGE_LOCK) 990 | get_filename_component(CPM_ABSOLUTE_PACKAGE_LOCK_PATH ${file} ABSOLUTE) 991 | if (EXISTS ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH}) 992 | include(${CPM_ABSOLUTE_PACKAGE_LOCK_PATH}) 993 | endif () 994 | if (NOT TARGET cpm-update-package-lock) 995 | add_custom_target( 996 | cpm-update-package-lock COMMAND ${CMAKE_COMMAND} -E copy ${CPM_PACKAGE_LOCK_FILE} 997 | ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH} 998 | ) 999 | endif () 1000 | set(CPM_PACKAGE_LOCK_ENABLED true) 1001 | endif () 1002 | endmacro() 1003 | 1004 | # registers a package that has been added to CPM 1005 | function(CPMRegisterPackage PACKAGE VERSION) 1006 | list(APPEND CPM_PACKAGES ${PACKAGE}) 1007 | set(CPM_PACKAGES 1008 | ${CPM_PACKAGES} 1009 | CACHE INTERNAL "" 1010 | ) 1011 | set("CPM_PACKAGE_${PACKAGE}_VERSION" 1012 | ${VERSION} 1013 | CACHE INTERNAL "" 1014 | ) 1015 | endfunction() 1016 | 1017 | # retrieve the current version of the package to ${OUTPUT} 1018 | function(CPMGetPackageVersion PACKAGE OUTPUT) 1019 | set(${OUTPUT} 1020 | "${CPM_PACKAGE_${PACKAGE}_VERSION}" 1021 | PARENT_SCOPE 1022 | ) 1023 | endfunction() 1024 | 1025 | # declares a package in FetchContent_Declare 1026 | function(cpm_declare_fetch PACKAGE) 1027 | if (${CPM_DRY_RUN}) 1028 | cpm_message(STATUS "${CPM_INDENT} Package not declared (dry run)") 1029 | return() 1030 | endif () 1031 | 1032 | FetchContent_Declare(${PACKAGE} ${ARGN}) 1033 | endfunction() 1034 | 1035 | # returns properties for a package previously defined by cpm_declare_fetch 1036 | function(cpm_get_fetch_properties PACKAGE) 1037 | if (${CPM_DRY_RUN}) 1038 | return() 1039 | endif () 1040 | 1041 | set(${PACKAGE}_SOURCE_DIR 1042 | "${CPM_PACKAGE_${PACKAGE}_SOURCE_DIR}" 1043 | PARENT_SCOPE 1044 | ) 1045 | set(${PACKAGE}_BINARY_DIR 1046 | "${CPM_PACKAGE_${PACKAGE}_BINARY_DIR}" 1047 | PARENT_SCOPE 1048 | ) 1049 | endfunction() 1050 | 1051 | function(cpm_store_fetch_properties PACKAGE source_dir binary_dir) 1052 | if (${CPM_DRY_RUN}) 1053 | return() 1054 | endif () 1055 | 1056 | set(CPM_PACKAGE_${PACKAGE}_SOURCE_DIR 1057 | "${source_dir}" 1058 | CACHE INTERNAL "" 1059 | ) 1060 | set(CPM_PACKAGE_${PACKAGE}_BINARY_DIR 1061 | "${binary_dir}" 1062 | CACHE INTERNAL "" 1063 | ) 1064 | endfunction() 1065 | 1066 | # adds a package as a subdirectory if viable, according to provided options 1067 | function( 1068 | cpm_add_subdirectory 1069 | PACKAGE 1070 | DOWNLOAD_ONLY 1071 | SOURCE_DIR 1072 | BINARY_DIR 1073 | EXCLUDE 1074 | SYSTEM 1075 | OPTIONS 1076 | ) 1077 | 1078 | if (NOT DOWNLOAD_ONLY AND EXISTS ${SOURCE_DIR}/CMakeLists.txt) 1079 | set(addSubdirectoryExtraArgs "") 1080 | if (EXCLUDE) 1081 | list(APPEND addSubdirectoryExtraArgs EXCLUDE_FROM_ALL) 1082 | endif () 1083 | if ("${SYSTEM}" AND "${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.25") 1084 | # https://cmake.org/cmake/help/latest/prop_dir/SYSTEM.html#prop_dir:SYSTEM 1085 | list(APPEND addSubdirectoryExtraArgs SYSTEM) 1086 | endif () 1087 | if (OPTIONS) 1088 | foreach (OPTION ${OPTIONS}) 1089 | cpm_parse_option("${OPTION}") 1090 | set(${OPTION_KEY} "${OPTION_VALUE}") 1091 | endforeach () 1092 | endif () 1093 | set(CPM_OLD_INDENT "${CPM_INDENT}") 1094 | set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:") 1095 | add_subdirectory(${SOURCE_DIR} ${BINARY_DIR} ${addSubdirectoryExtraArgs}) 1096 | set(CPM_INDENT "${CPM_OLD_INDENT}") 1097 | endif () 1098 | endfunction() 1099 | 1100 | # downloads a previously declared package via FetchContent and exports the variables 1101 | # `${PACKAGE}_SOURCE_DIR` and `${PACKAGE}_BINARY_DIR` to the parent scope 1102 | function(cpm_fetch_package PACKAGE DOWNLOAD_ONLY populated) 1103 | set(${populated} 1104 | FALSE 1105 | PARENT_SCOPE 1106 | ) 1107 | if (${CPM_DRY_RUN}) 1108 | cpm_message(STATUS "${CPM_INDENT} Package ${PACKAGE} not fetched (dry run)") 1109 | return() 1110 | endif () 1111 | 1112 | FetchContent_GetProperties(${PACKAGE}) 1113 | 1114 | string(TOLOWER "${PACKAGE}" lower_case_name) 1115 | 1116 | if (NOT ${lower_case_name}_POPULATED) 1117 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30.3") 1118 | if (DOWNLOAD_ONLY) 1119 | # MakeAvailable will call add_subdirectory internally which is not what we want when 1120 | # DOWNLOAD_ONLY is set. Populate will only download the dependency without adding it to the 1121 | # build 1122 | FetchContent_Populate( 1123 | ${PACKAGE} 1124 | SOURCE_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-src" 1125 | BINARY_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build" 1126 | SUBBUILD_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild" 1127 | ${ARGN} 1128 | ) 1129 | else () 1130 | FetchContent_MakeAvailable(${PACKAGE}) 1131 | endif () 1132 | else () 1133 | FetchContent_Populate(${PACKAGE}) 1134 | endif () 1135 | set(${populated} 1136 | TRUE 1137 | PARENT_SCOPE 1138 | ) 1139 | endif () 1140 | 1141 | cpm_store_fetch_properties( 1142 | ${CPM_ARGS_NAME} ${${lower_case_name}_SOURCE_DIR} ${${lower_case_name}_BINARY_DIR} 1143 | ) 1144 | 1145 | set(${PACKAGE}_SOURCE_DIR 1146 | ${${lower_case_name}_SOURCE_DIR} 1147 | PARENT_SCOPE 1148 | ) 1149 | set(${PACKAGE}_BINARY_DIR 1150 | ${${lower_case_name}_BINARY_DIR} 1151 | PARENT_SCOPE 1152 | ) 1153 | endfunction() 1154 | 1155 | # splits a package option 1156 | function(cpm_parse_option OPTION) 1157 | string(REGEX MATCH "^[^ ]+" OPTION_KEY "${OPTION}") 1158 | string(LENGTH "${OPTION}" OPTION_LENGTH) 1159 | string(LENGTH "${OPTION_KEY}" OPTION_KEY_LENGTH) 1160 | if (OPTION_KEY_LENGTH STREQUAL OPTION_LENGTH) 1161 | # no value for key provided, assume user wants to set option to "ON" 1162 | set(OPTION_VALUE "ON") 1163 | else () 1164 | math(EXPR OPTION_KEY_LENGTH "${OPTION_KEY_LENGTH}+1") 1165 | string(SUBSTRING "${OPTION}" "${OPTION_KEY_LENGTH}" "-1" OPTION_VALUE) 1166 | endif () 1167 | set(OPTION_KEY 1168 | "${OPTION_KEY}" 1169 | PARENT_SCOPE 1170 | ) 1171 | set(OPTION_VALUE 1172 | "${OPTION_VALUE}" 1173 | PARENT_SCOPE 1174 | ) 1175 | endfunction() 1176 | 1177 | # guesses the package version from a git tag 1178 | function(cpm_get_version_from_git_tag GIT_TAG RESULT) 1179 | string(LENGTH ${GIT_TAG} length) 1180 | if (length EQUAL 40) 1181 | # GIT_TAG is probably a git hash 1182 | set(${RESULT} 1183 | 0 1184 | PARENT_SCOPE 1185 | ) 1186 | else () 1187 | string(REGEX MATCH "v?([0123456789.]*).*" _ ${GIT_TAG}) 1188 | set(${RESULT} 1189 | ${CMAKE_MATCH_1} 1190 | PARENT_SCOPE 1191 | ) 1192 | endif () 1193 | endfunction() 1194 | 1195 | # guesses if the git tag is a commit hash or an actual tag or a branch name. 1196 | function(cpm_is_git_tag_commit_hash GIT_TAG RESULT) 1197 | string(LENGTH "${GIT_TAG}" length) 1198 | # full hash has 40 characters, and short hash has at least 7 characters. 1199 | if (length LESS 7 OR length GREATER 40) 1200 | set(${RESULT} 1201 | 0 1202 | PARENT_SCOPE 1203 | ) 1204 | else () 1205 | if (${GIT_TAG} MATCHES "^[a-fA-F0-9]+$") 1206 | set(${RESULT} 1207 | 1 1208 | PARENT_SCOPE 1209 | ) 1210 | else () 1211 | set(${RESULT} 1212 | 0 1213 | PARENT_SCOPE 1214 | ) 1215 | endif () 1216 | endif () 1217 | endfunction() 1218 | 1219 | function(cpm_prettify_package_arguments OUT_VAR IS_IN_COMMENT) 1220 | set(oneValueArgs 1221 | NAME 1222 | FORCE 1223 | VERSION 1224 | GIT_TAG 1225 | DOWNLOAD_ONLY 1226 | GITHUB_REPOSITORY 1227 | GITLAB_REPOSITORY 1228 | BITBUCKET_REPOSITORY 1229 | GIT_REPOSITORY 1230 | SOURCE_DIR 1231 | FIND_PACKAGE_ARGUMENTS 1232 | NO_CACHE 1233 | SYSTEM 1234 | GIT_SHALLOW 1235 | EXCLUDE_FROM_ALL 1236 | SOURCE_SUBDIR 1237 | ) 1238 | set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND) 1239 | cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 1240 | 1241 | foreach (oneArgName ${oneValueArgs}) 1242 | if (DEFINED CPM_ARGS_${oneArgName}) 1243 | if (${IS_IN_COMMENT}) 1244 | string(APPEND PRETTY_OUT_VAR "#") 1245 | endif () 1246 | if (${oneArgName} STREQUAL "SOURCE_DIR") 1247 | string(REPLACE ${CMAKE_SOURCE_DIR} "\${CMAKE_SOURCE_DIR}" CPM_ARGS_${oneArgName} 1248 | ${CPM_ARGS_${oneArgName}} 1249 | ) 1250 | endif () 1251 | string(APPEND PRETTY_OUT_VAR " ${oneArgName} ${CPM_ARGS_${oneArgName}}\n") 1252 | endif () 1253 | endforeach () 1254 | foreach (multiArgName ${multiValueArgs}) 1255 | if (DEFINED CPM_ARGS_${multiArgName}) 1256 | if (${IS_IN_COMMENT}) 1257 | string(APPEND PRETTY_OUT_VAR "#") 1258 | endif () 1259 | string(APPEND PRETTY_OUT_VAR " ${multiArgName}\n") 1260 | foreach (singleOption ${CPM_ARGS_${multiArgName}}) 1261 | if (${IS_IN_COMMENT}) 1262 | string(APPEND PRETTY_OUT_VAR "#") 1263 | endif () 1264 | string(APPEND PRETTY_OUT_VAR " \"${singleOption}\"\n") 1265 | endforeach () 1266 | endif () 1267 | endforeach () 1268 | 1269 | if (NOT "${CPM_ARGS_UNPARSED_ARGUMENTS}" STREQUAL "") 1270 | if (${IS_IN_COMMENT}) 1271 | string(APPEND PRETTY_OUT_VAR "#") 1272 | endif () 1273 | string(APPEND PRETTY_OUT_VAR " ") 1274 | foreach (CPM_ARGS_UNPARSED_ARGUMENT ${CPM_ARGS_UNPARSED_ARGUMENTS}) 1275 | string(APPEND PRETTY_OUT_VAR " ${CPM_ARGS_UNPARSED_ARGUMENT}") 1276 | endforeach () 1277 | string(APPEND PRETTY_OUT_VAR "\n") 1278 | endif () 1279 | 1280 | set(${OUT_VAR} 1281 | ${PRETTY_OUT_VAR} 1282 | PARENT_SCOPE 1283 | ) 1284 | 1285 | endfunction() 1286 | -------------------------------------------------------------------------------- /examples/ButtonCallbacks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //------------------------------------------------------------------------------------ 4 | // Program main entry point 5 | //------------------------------------------------------------------------------------ 6 | int main() { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | SetConfigFlags(FLAG_WINDOW_RESIZABLE); // To test the position update 13 | InitWindow(screenWidth, screenHeight, "raygui example - basic window"); 14 | 15 | // Load resources / Initialize variables at this point 16 | const char *buttonText = "Click me!"; 17 | auto button1 = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 18 | button1.SetStyle(rgc::Style(rgc::Style::Position::CENTER, { -100, 0 })); 19 | 20 | auto button2 = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 21 | button2.SetStyle(rgc::Style(rgc::Style::Position::CENTER, { 100, 0 })); 22 | 23 | button1.OnClick([&button1, &button2]() { 24 | TraceLog(LOG_INFO, "Button 1 clicked!"); 25 | button1.Disable(); 26 | button2.Enable(); 27 | }); 28 | button2.OnClick([&button1, &button2]() { 29 | TraceLog(LOG_INFO, "Button 2 clicked!"); 30 | button1.Enable(); 31 | button2.Disable(); 32 | }); 33 | 34 | button1.Enable(); 35 | button2.Disable(); 36 | // NOTE: the update callback is commented out because it outputs a message every frame, and it's annoying. 37 | // button.OnUpdate([]() { 38 | // TraceLog(LOG_INFO, "Button updated!"); 39 | // }); 40 | 41 | SetTargetFPS(60); 42 | //-------------------------------------------------------------------------------------- 43 | 44 | // Main game loop 45 | while (!WindowShouldClose()) // Detect window close button or ESC key 46 | { 47 | // Update 48 | //---------------------------------------------------------------------------------- 49 | // Update variables / Implement example logic at this point 50 | //---------------------------------------------------------------------------------- 51 | 52 | // Draw 53 | //---------------------------------------------------------------------------------- 54 | BeginDrawing(); 55 | 56 | ClearBackground(RAYWHITE); 57 | 58 | // Draw everything that requires to be drawn at this point: 59 | button1.Update(); 60 | button1.Show(); 61 | button2.Update(); 62 | button2.Show(); 63 | 64 | EndDrawing(); 65 | //---------------------------------------------------------------------------------- 66 | } 67 | 68 | // De-Initialization 69 | //-------------------------------------------------------------------------------------- 70 | 71 | // Unload all loaded resources at this point 72 | 73 | CloseWindow(); // Close window and OpenGL context 74 | //-------------------------------------------------------------------------------------- 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /examples/ButtonChangePositionOnClick.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | SetConfigFlags(FLAG_WINDOW_RESIZABLE); // To test the position update 6 | InitWindow(800, 450, "raygui example - basic window"); 7 | SetTargetFPS(60); 8 | 9 | const auto buttonText1 = "Change position"; 10 | const auto buttonText2 = "I change position"; 11 | auto button1 = rgc::Button(rgc::Bounds::WithText(buttonText1, 22, { 15, 15 }), buttonText1); 12 | button1.SetStyle(rgc::Style(rgc::Style::Position::CENTER, { -100, 0 })); 13 | 14 | auto button2 = rgc::Button(rgc::Bounds::WithPositionAndText( 100, 20, buttonText2, 22, { 15, 15 }), buttonText2); 15 | 16 | bool switchPositionButton2 = false; 17 | 18 | // Set the button on click event callback 19 | button1.OnClick([&switchPositionButton2, buttonText2, &button2] { 20 | std::cout << "Clicked!" << std::endl; 21 | 22 | if (switchPositionButton2) { 23 | button2.SetBounds(rgc::Bounds::WithPositionAndText( 100, 20, buttonText2, 22, { 15, 15 })); 24 | switchPositionButton2 = false; 25 | } else { 26 | button2.SetBounds(rgc::Bounds::WithPositionAndText( 100, 320, buttonText2, 22, { 15, 15 })); 27 | switchPositionButton2 = true; 28 | } 29 | }); 30 | 31 | // Main game loop 32 | while (!WindowShouldClose()) { 33 | BeginDrawing(); 34 | ClearBackground(RAYWHITE); 35 | 36 | button1.Update(); 37 | button2.Update(); 38 | RAYGUI_CPP_UNUSED(button1.Show()); 39 | RAYGUI_CPP_UNUSED(button2.Show()); 40 | 41 | EndDrawing(); 42 | } 43 | 44 | CloseWindow(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /examples/ButtonColors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | SetConfigFlags(FLAG_WINDOW_RESIZABLE); // To test the position update 6 | InitWindow(800, 450, "raygui example - basic window"); 7 | SetTargetFPS(60); 8 | 9 | const auto buttonText1 = "Switch colors"; 10 | const auto buttonText2 = "I change colors"; 11 | auto button1 = rgc::Button(rgc::Bounds::WithText(buttonText1, 22, { 15, 15 }), buttonText1); 12 | button1.SetStyle(rgc::Style(rgc::Style::Position::CENTER, { -100, 0 })); 13 | 14 | auto button2 = rgc::Button(rgc::Bounds::WithText(buttonText2, 22, { 15, 15 }), buttonText2); 15 | button2.SetStyle(rgc::Style(rgc::Style::Position::CENTER, { 100, 0 })); 16 | 17 | bool switchColorButton2 = false; 18 | button2.SetBaseColor(GOLD); 19 | 20 | // Set the button on click event callback 21 | button1.OnClick([&switchColorButton2, &button2] { 22 | std::cout << "Clicked!" << std::endl; 23 | 24 | if (switchColorButton2) { 25 | button2.SetBaseColor(GOLD); 26 | switchColorButton2 = false; 27 | } else { 28 | button2.SetBaseColor(PURPLE); 29 | switchColorButton2 = true; 30 | } 31 | }); 32 | 33 | // Main game loop 34 | while (!WindowShouldClose()) { 35 | BeginDrawing(); 36 | ClearBackground(RAYWHITE); 37 | 38 | button1.Update(); 39 | button2.Update(); 40 | RAYGUI_CPP_UNUSED(button1.Show()); 41 | RAYGUI_CPP_UNUSED(button2.Show()); 42 | 43 | EndDrawing(); 44 | } 45 | 46 | CloseWindow(); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /examples/ButtonKeepInitialPosition.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | SetConfigFlags(FLAG_WINDOW_RESIZABLE); // To test the position update 6 | InitWindow(800, 450, "raygui example - basic window"); 7 | SetTargetFPS(60); 8 | 9 | const auto buttonText = "Click me!"; 10 | auto button = rgc::Button(rgc::Bounds::WithPositionAndText(300, 20, buttonText, 22, { 15, 15 }), buttonText); 11 | 12 | // Set the button on click event callback 13 | button.OnClick([] { 14 | std::cout << "Clicked!" << std::endl; 15 | }); 16 | 17 | // Main game loop 18 | while (!WindowShouldClose()) { 19 | BeginDrawing(); 20 | ClearBackground(RAYWHITE); 21 | 22 | button.Update(); 23 | RAYGUI_CPP_UNUSED(button.Show()); 24 | 25 | EndDrawing(); 26 | } 27 | 28 | CloseWindow(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /examples/ButtonPlacement.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //------------------------------------------------------------------------------------ 4 | // Program main entry point 5 | //------------------------------------------------------------------------------------ 6 | int main() { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | SetConfigFlags(FLAG_WINDOW_RESIZABLE); // To test the position update 13 | InitWindow(screenWidth, screenHeight, "raygui example - basic window"); 14 | 15 | // Load resources / Initialize variables at this point 16 | const char *buttonText = "Click me!"; 17 | auto topLeftButton = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 18 | auto topCenterButton = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 19 | auto topRightButton = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 20 | auto centerLeftButton = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 21 | auto centerCenterButton = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 22 | auto centerRightButton = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 23 | auto bottomLeftButton = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 24 | auto bottomCenterButton = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 25 | auto bottomRightButton = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 26 | topLeftButton.SetStyle(rgc::Style(rgc::Style::Position::TOP_LEFT, { 5, 5 })); 27 | topCenterButton.SetStyle(rgc::Style(rgc::Style::Position::TOP_CENTER, { 0, 5 })); 28 | topRightButton.SetStyle(rgc::Style(rgc::Style::Position::TOP_RIGHT, { -5, 5 })); 29 | centerLeftButton.SetStyle(rgc::Style(rgc::Style::Position::CENTER_LEFT, { 5, 0 })); 30 | centerCenterButton.SetStyle(rgc::Style(rgc::Style::Position::CENTER, { 0, 0 })); 31 | centerRightButton.SetStyle(rgc::Style(rgc::Style::Position::CENTER_RIGHT, { -5, 0 })); 32 | bottomLeftButton.SetStyle(rgc::Style(rgc::Style::Position::BOTTOM_LEFT, { 5, -5 })); 33 | bottomCenterButton.SetStyle(rgc::Style(rgc::Style::Position::BOTTOM_CENTER, { 0, -5 })); 34 | bottomRightButton.SetStyle(rgc::Style(rgc::Style::Position::BOTTOM_RIGHT, { -5, -5 })); 35 | 36 | SetTargetFPS(60); 37 | //-------------------------------------------------------------------------------------- 38 | 39 | // Main game loop 40 | while (!WindowShouldClose()) // Detect window close button or ESC key 41 | { 42 | // Update 43 | //---------------------------------------------------------------------------------- 44 | // Update variables / Implement example logic at this point 45 | //---------------------------------------------------------------------------------- 46 | 47 | // Draw 48 | //---------------------------------------------------------------------------------- 49 | BeginDrawing(); 50 | 51 | ClearBackground(RAYWHITE); 52 | 53 | // Draw everything that requires to be drawn at this point: 54 | 55 | topLeftButton.Update(); 56 | topLeftButton.Show(); 57 | topCenterButton.Update(); 58 | topCenterButton.Show(); 59 | topRightButton.Update(); 60 | topRightButton.Show(); 61 | centerLeftButton.Update(); 62 | centerLeftButton.Show(); 63 | centerCenterButton.Update(); 64 | centerCenterButton.Show(); 65 | centerRightButton.Update(); 66 | centerRightButton.Show(); 67 | bottomLeftButton.Update(); 68 | bottomLeftButton.Show(); 69 | bottomCenterButton.Update(); 70 | bottomCenterButton.Show(); 71 | bottomRightButton.Update(); 72 | bottomRightButton.Show(); 73 | 74 | EndDrawing(); 75 | //---------------------------------------------------------------------------------- 76 | } 77 | 78 | // De-Initialization 79 | //-------------------------------------------------------------------------------------- 80 | 81 | // Unload all loaded resources at this point 82 | 83 | CloseWindow(); // Close window and OpenGL context 84 | //-------------------------------------------------------------------------------------- 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TEST_SOURCES 2 | ButtonPlacement.cpp 3 | ChildComponents.cpp 4 | ButtonCallbacks.cpp 5 | SimpleButton.cpp 6 | ButtonColors.cpp 7 | extras/ImageButton.cpp 8 | ButtonKeepInitialPosition.cpp 9 | ButtonChangePositionOnClick.cpp 10 | ) 11 | 12 | foreach (source ${TEST_SOURCES}) 13 | get_filename_component(name ${source} NAME_WE) 14 | add_executable(${name} ${source}) 15 | target_link_libraries(${name} raygui_cpp) 16 | add_dependencies(${name} copy_example_assets) 17 | endforeach () 18 | 19 | # Copy assets to build directory as a custom target to execute before running in CLion 20 | add_custom_target( 21 | copy_example_assets 22 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets ${CMAKE_CURRENT_BINARY_DIR}/assets 23 | ) 24 | message(STATUS "Copying assets from ${CMAKE_CURRENT_SOURCE_DIR}/assets to ${CMAKE_CURRENT_BINARY_DIR}/assets") 25 | -------------------------------------------------------------------------------- /examples/ChildComponents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //------------------------------------------------------------------------------------ 4 | // Program main entry point 5 | //------------------------------------------------------------------------------------ 6 | int main() { 7 | // Initialization 8 | //-------------------------------------------------------------------------------------- 9 | const int screenWidth = 800; 10 | const int screenHeight = 450; 11 | 12 | SetConfigFlags(FLAG_WINDOW_RESIZABLE); // To test the position update 13 | InitWindow(screenWidth, screenHeight, "raygui example - basic window"); 14 | 15 | // Load resources / Initialize variables at this point 16 | const char *buttonText = "Click me!"; 17 | const rgc::Bounds &bounds = rgc::Bounds::WithText(buttonText, 22, { 15, 15 }); 18 | auto topLeftButton = rgc::Button(bounds, buttonText); 19 | auto topCenterButton = rgc::Button(bounds, buttonText); 20 | auto bottomCenterButton = rgc::Button(bounds, buttonText); 21 | 22 | topLeftButton.SetStyle(rgc::Style(rgc::Style::Position::TOP_LEFT, { 15, 35 })); 23 | topCenterButton.SetStyle(rgc::Style(rgc::Style::Position::TOP_CENTER, { 0, 35 })); 24 | bottomCenterButton.SetStyle(rgc::Style(rgc::Style::Position::BOTTOM_CENTER, { 0, -5 })); 25 | 26 | auto smallWindowBox = rgc::WindowBox(rgc::Bounds({ 100, 100 }, { 200, 200 }), "Small Window Box"); 27 | smallWindowBox.SetStyle(rgc::Style(rgc::Style::Position::CENTER_RIGHT, { -40, 0 })); 28 | 29 | auto bigWindowBox = rgc::WindowBox(rgc::Bounds({ 20, 20 }, { 600, 400 }), "Big Window Box"); 30 | bigWindowBox.SetStyle(rgc::Style(rgc::Style::Position::CENTER, { 0, 0 })); 31 | 32 | // Ways for adding children to the window box 33 | // 1. Using verbose dynamic_cast 34 | bigWindowBox.AddChild(dynamic_cast *>(&topLeftButton)); 35 | // 2. Using the ToComponent function from Utils.h 36 | bigWindowBox.AddChild(rgc::ToComponent(&smallWindowBox)); 37 | smallWindowBox.AddChild(rgc::ToComponent(&bottomCenterButton)); 38 | smallWindowBox.AddChild(rgc::ToComponent(&topCenterButton)); 39 | 40 | SetTargetFPS(60); 41 | //-------------------------------------------------------------------------------------- 42 | 43 | // Main game loop 44 | while (!WindowShouldClose()) // Detect window close button or ESC key 45 | { 46 | // Update 47 | //---------------------------------------------------------------------------------- 48 | // Update variables / Implement example logic at this point 49 | //---------------------------------------------------------------------------------- 50 | bigWindowBox.Update(); 51 | 52 | // Draw 53 | //---------------------------------------------------------------------------------- 54 | BeginDrawing(); 55 | 56 | ClearBackground(RAYWHITE); 57 | 58 | // Draw everything that requires to be drawn at this point: 59 | bigWindowBox.Show(); 60 | 61 | EndDrawing(); 62 | //---------------------------------------------------------------------------------- 63 | } 64 | 65 | // De-Initialization 66 | //-------------------------------------------------------------------------------------- 67 | 68 | // Unload all loaded resources at this point 69 | 70 | CloseWindow(); // Close window and OpenGL context 71 | //-------------------------------------------------------------------------------------- 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /examples/SimpleButton.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | SetConfigFlags(FLAG_WINDOW_RESIZABLE); // To test the position update 6 | InitWindow(800, 450, "raygui example - basic window"); 7 | SetTargetFPS(60); 8 | 9 | const auto buttonText = "Click me!"; 10 | auto centerCenterButton = rgc::Button(rgc::Bounds::WithText(buttonText, 22, { 15, 15 }), buttonText); 11 | centerCenterButton.SetStyle(rgc::Style(rgc::Style::Position::CENTER, { 0, 0 })); 12 | 13 | // Set the button on click event callback 14 | centerCenterButton.OnClick([] { 15 | std::cout << "Clicked!" << std::endl; 16 | }); 17 | 18 | // Main game loop 19 | while (!WindowShouldClose()) { 20 | BeginDrawing(); 21 | ClearBackground(RAYWHITE); 22 | 23 | centerCenterButton.Update(); 24 | RAYGUI_CPP_UNUSED(centerCenterButton.Show()); 25 | 26 | EndDrawing(); 27 | } 28 | 29 | CloseWindow(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /examples/assets/TestImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scastd/raygui-cpp/78387c8230d661109e1ec2ddcaad9fb4cd9bdd6d/examples/assets/TestImage.png -------------------------------------------------------------------------------- /examples/extras/ImageButton.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | SetConfigFlags(FLAG_WINDOW_RESIZABLE); // To test the position update 6 | InitWindow(800, 450, "raygui example - basic window"); 7 | SetTargetFPS(60); 8 | 9 | const auto imageTexture = LoadTexture("assets/TestImage.png"); 10 | auto centerCenterButton = rgc::ImageButton(rgc::Bounds::OfSize(64, 64), imageTexture); 11 | centerCenterButton.SetStyle(rgc::Style(rgc::Style::Position::CENTER, { 0, 0 })); 12 | 13 | // Set the button on click event callback 14 | centerCenterButton.OnClick([] { 15 | std::cout << "Clicked!" << std::endl; 16 | }); 17 | 18 | // Main game loop 19 | while (!WindowShouldClose()) { 20 | BeginDrawing(); 21 | ClearBackground(GRAY); 22 | 23 | centerCenterButton.Update(); 24 | RAYGUI_CPP_UNUSED(centerCenterButton.Show()); 25 | 26 | EndDrawing(); 27 | } 28 | 29 | CloseWindow(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /include/raygui-cpp.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_RAYGUI_CPP_H 2 | #define RAYGUI_CPP_RAYGUI_CPP_H 3 | 4 | // ************************************************************************************************** 5 | // IMPORTANT NOTE: 6 | // 7 | // This section is included to make sure that the implementation of raygui is included only once 8 | // for the entire project. 9 | // This is necessary because raygui is implemented in raygui.h, and if it is 10 | // included in multiple files, the linker will complain about multiple definitions of the same 11 | // functions. 12 | // ************************************************************************************************** 13 | #define RAYGUI_IMPLEMENTATION 14 | #include 15 | #undef RAYGUI_IMPLEMENTATION 16 | 17 | #include "raygui-cpp/Button.h" 18 | #include "raygui-cpp/CheckBox.h" 19 | #include "raygui-cpp/ColorBarAlpha.h" 20 | #include "raygui-cpp/ColorBarHue.h" 21 | #include "raygui-cpp/ColorPanel.h" 22 | #include "raygui-cpp/ColorPicker.h" 23 | #include "raygui-cpp/ComboBox.h" 24 | #include "raygui-cpp/Directives.h" 25 | #include "raygui-cpp/DropdownBox.h" 26 | #include "raygui-cpp/DummyRec.h" 27 | #include "raygui-cpp/Globals.h" 28 | #include "raygui-cpp/Grid.h" 29 | #include "raygui-cpp/GroupBox.h" 30 | #include "raygui-cpp/Label.h" 31 | #include "raygui-cpp/LabelButton.h" 32 | #include "raygui-cpp/Line.h" 33 | #include "raygui-cpp/ListView.h" 34 | #include "raygui-cpp/ListViewEx.h" 35 | #include "raygui-cpp/MessageBox.h" 36 | #include "raygui-cpp/Panel.h" 37 | #include "raygui-cpp/ProgressBar.h" 38 | #include "raygui-cpp/ScrollPanel.h" 39 | #include "raygui-cpp/Slider.h" 40 | #include "raygui-cpp/SliderBar.h" 41 | #include "raygui-cpp/Spinner.h" 42 | #include "raygui-cpp/StatusBar.h" 43 | #include "raygui-cpp/TabBar.h" 44 | #include "raygui-cpp/TextBox.h" 45 | #include "raygui-cpp/TextInputBox.h" 46 | #include "raygui-cpp/Toggle.h" 47 | #include "raygui-cpp/ToggleGroup.h" 48 | #include "raygui-cpp/ValueBox.h" 49 | #include "raygui-cpp/WindowBox.h" 50 | #include "raygui-cpp/Utils.h" 51 | 52 | // Extras 53 | #include "raygui-cpp/extras/ImageButton.h" 54 | 55 | #endif // RAYGUI_CPP_RAYGUI_CPP_H 56 | -------------------------------------------------------------------------------- /include/raygui-cpp/Bounds.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_BOUNDS_H 2 | #define RAYGUI_CPP_BOUNDS_H 3 | 4 | #include "Directives.h" 5 | #include "Margin.h" 6 | #include "raygui.h" 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class Bounds { 11 | public: 12 | Bounds(); 13 | explicit Bounds(::Rectangle rectangle); 14 | Bounds(float x, float y, float width, float height); 15 | Bounds(::Vector2 position, ::Vector2 size); 16 | 17 | RAYGUI_CPP_NODISCARD ::Rectangle GetRectangle() const; 18 | void SetRectangle(::Rectangle newRectangle); 19 | 20 | RAYGUI_CPP_NODISCARD ::Vector2 GetPosition() const; 21 | void SetPosition(::Vector2 newPosition); 22 | void SetPosition(float x, float y); 23 | 24 | RAYGUI_CPP_NODISCARD ::Vector2 GetSize() const; 25 | void SetSize(::Vector2 newSize); 26 | void SetSize(float width, float height); 27 | 28 | RAYGUI_CPP_NODISCARD float GetX() const; 29 | void SetX(float newX); 30 | 31 | RAYGUI_CPP_NODISCARD float GetY() const; 32 | void SetY(float newY); 33 | 34 | RAYGUI_CPP_NODISCARD float GetWidth() const; 35 | void SetWidth(float newWidth); 36 | 37 | RAYGUI_CPP_NODISCARD float GetHeight() const; 38 | void SetHeight(float newHeight); 39 | 40 | RAYGUI_CPP_NODISCARD static Bounds WindowBounds(); 41 | 42 | /** 43 | * @brief Creates a Bounds object with the given width and height, 44 | * and with the position set to (0, 0). 45 | * 46 | * @param width The width of the Bounds object. 47 | * @param height The height of the Bounds object. 48 | * 49 | * @return A Bounds object with the given width and height. 50 | */ 51 | RAYGUI_CPP_NODISCARD static Bounds OfSize(float width, float height); 52 | 53 | RAYGUI_CPP_NODISCARD static Bounds WithText(const char *text); 54 | 55 | RAYGUI_CPP_NODISCARD static Bounds WithText(const char *text, int fontSize); 56 | 57 | RAYGUI_CPP_NODISCARD static Bounds WithText(const char *text, int fontSize, Margin textMargins); 58 | 59 | RAYGUI_CPP_NODISCARD static Bounds WithPositionAndText(float x, float y, const char *text); 60 | 61 | RAYGUI_CPP_NODISCARD static Bounds WithPositionAndText(float x, float y, const char *text, int fontSize); 62 | 63 | RAYGUI_CPP_NODISCARD static Bounds WithPositionAndText(float x, float y, const char *text, int fontSize, 64 | Margin textMargins); 65 | 66 | private: 67 | ::Rectangle m_rectangle; 68 | }; 69 | 70 | RAYGUI_CPP_END_NAMESPACE 71 | 72 | #endif // RAYGUI_CPP_BOUNDS_H 73 | -------------------------------------------------------------------------------- /include/raygui-cpp/Button.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_BUTTON_H 2 | #define RAYGUI_CPP_BUTTON_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include "Paintable.h" 7 | 8 | #include 9 | 10 | RAYGUI_CPP_BEGIN_NAMESPACE 11 | 12 | class Button : public Component, public Paintable { 13 | public: 14 | Button(); 15 | explicit Button(const char *text); 16 | Button(Bounds bounds, const char *text); 17 | 18 | RAYGUI_CPP_NODISCARD const char *GetText() const; 19 | void SetText(const char *newText); 20 | 21 | RAYGUI_CPP_NODISCARD bool Show() override; 22 | 23 | void OnClick(const Callback &onClick) override; 24 | void OnUpdate(const Callback &onUpdate) override; 25 | 26 | void SetPropertyColor(GuiControlProperty property, Color color) override; 27 | 28 | private: 29 | const char *text; 30 | }; 31 | 32 | RAYGUI_CPP_END_NAMESPACE 33 | 34 | #endif // RAYGUI_CPP_BUTTON_H 35 | -------------------------------------------------------------------------------- /include/raygui-cpp/CheckBox.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_CHECK_BOX_H 2 | #define RAYGUI_CPP_CHECK_BOX_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class CheckBox : public Component { 11 | public: 12 | CheckBox(); 13 | CheckBox(const char *text, bool checked); 14 | CheckBox(Bounds bounds, const char *text, bool checked = false); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD bool IsChecked() const; 20 | void SetChecked(bool newChecked); 21 | 22 | RAYGUI_CPP_NODISCARD bool Show() override; 23 | 24 | private: 25 | const char *text; 26 | bool checked; 27 | }; 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | 31 | #endif // RAYGUI_CPP_CHECK_BOX_H 32 | -------------------------------------------------------------------------------- /include/raygui-cpp/ColorBarAlpha.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_COLOR_BAR_ALPHA_H 2 | #define RAYGUI_CPP_COLOR_BAR_ALPHA_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ColorBarAlpha : public Component { 11 | public: 12 | ColorBarAlpha(); 13 | ColorBarAlpha(const char *text, float alpha = 1.0f); 14 | ColorBarAlpha(Bounds bounds, const char *text, float alpha = 1.0f); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD float GetAlpha() const; 20 | void SetAlpha(float newAlpha); 21 | 22 | RAYGUI_CPP_NODISCARD int Show() override; 23 | 24 | private: 25 | const char *text; 26 | float alpha; 27 | }; 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | 31 | #endif // RAYGUI_CPP_COLOR_BAR_ALPHA_H 32 | -------------------------------------------------------------------------------- /include/raygui-cpp/ColorBarHue.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_COLOR_BAR_HUE_H 2 | #define RAYGUI_CPP_COLOR_BAR_HUE_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ColorBarHue : public Component { 11 | public: 12 | ColorBarHue(); 13 | ColorBarHue(const char *text, float value); 14 | ColorBarHue(Bounds bounds, const char *text, float value); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD float GetValue() const; 20 | void SetValue(float newValue); 21 | 22 | RAYGUI_CPP_NODISCARD int Show() override; 23 | 24 | private: 25 | const char *text; 26 | float value; 27 | }; 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | 31 | #endif // RAYGUI_CPP_COLOR_BAR_HUE_H 32 | -------------------------------------------------------------------------------- /include/raygui-cpp/ColorPanel.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_COLOR_PANEL_H 2 | #define RAYGUI_CPP_COLOR_PANEL_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ColorPanel : public Component { 11 | public: 12 | ColorPanel(); 13 | ColorPanel(const char *text, ::Color color = ::BLACK); 14 | ColorPanel(Bounds bounds, const char *text, ::Color color = ::BLACK); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD ::Color GetColor() const; 20 | void SetColor(::Color newColor); 21 | 22 | RAYGUI_CPP_NODISCARD int Show() override; 23 | 24 | private: 25 | const char *text; 26 | ::Color color; 27 | }; 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | 31 | #endif // RAYGUI_CPP_COLOR_PANEL_H 32 | -------------------------------------------------------------------------------- /include/raygui-cpp/ColorPanelHSV.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_COLOR_PANEL_HSV_H 2 | #define RAYGUI_CPP_COLOR_PANEL_HSV_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ColorPanelHSV : public Component { 11 | public: 12 | ColorPanelHSV(); 13 | ColorPanelHSV(const char *text, ::Vector3 colorHsv); 14 | ColorPanelHSV(Bounds bounds, const char *text, ::Vector3 colorHsv); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD ::Vector3 GetColorHsv() const; 20 | void SetColorHsv(::Vector3 newColorHsv); 21 | 22 | RAYGUI_CPP_NODISCARD int Show() override; 23 | 24 | private: 25 | const char *text; 26 | ::Vector3 colorHsv; 27 | }; 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | 31 | #endif // RAYGUI_CPP_COLOR_PANEL_HSV_H 32 | -------------------------------------------------------------------------------- /include/raygui-cpp/ColorPicker.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_COLOR_PICKER_H 2 | #define RAYGUI_CPP_COLOR_PICKER_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ColorPicker : public Component { 11 | public: 12 | ColorPicker(); 13 | ColorPicker(const char *text, ::Color color = ::BLACK); 14 | ColorPicker(Bounds bounds, const char *text, ::Color color = ::BLACK); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD ::Color GetColor() const; 20 | void SetColor(::Color newColor); 21 | 22 | RAYGUI_CPP_NODISCARD int Show() override; 23 | 24 | void OnClick(const Callback &onClick) override; 25 | void OnUpdate(const Callback &onUpdate) override; 26 | 27 | private: 28 | const char *text; 29 | ::Color color; 30 | }; 31 | 32 | RAYGUI_CPP_END_NAMESPACE 33 | 34 | #endif // RAYGUI_CPP_COLOR_PICKER_H 35 | -------------------------------------------------------------------------------- /include/raygui-cpp/ColorPickerHSV.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_COLOR_PICKER_HSV_H 2 | #define RAYGUI_CPP_COLOR_PICKER_HSV_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ColorPickerHSV : public Component { 11 | public: 12 | ColorPickerHSV(); 13 | ColorPickerHSV(const char *text, ::Vector3 colorHsv); 14 | ColorPickerHSV(Bounds bounds, const char *text, ::Vector3 colorHsv); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD ::Vector3 GetColorHsv() const; 20 | void SetColorHsv(::Vector3 newColorHsv); 21 | 22 | RAYGUI_CPP_NODISCARD int Show() override; 23 | 24 | private: 25 | const char *text; 26 | ::Vector3 colorHsv; 27 | }; 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | 31 | #endif // RAYGUI_CPP_COLOR_PICKER_HSV_H 32 | -------------------------------------------------------------------------------- /include/raygui-cpp/ComboBox.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_COMBO_BOX_H 2 | #define RAYGUI_CPP_COMBO_BOX_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ComboBox : public Component { 11 | public: 12 | ComboBox(); 13 | ComboBox(const char *text, int active); 14 | ComboBox(Bounds bounds, const char *text, int active); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD int GetActive() const; 20 | void SetActive(int newActive); 21 | 22 | RAYGUI_CPP_NODISCARD int Show() override; 23 | 24 | private: 25 | const char *text; 26 | int active; 27 | }; 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | 31 | #endif // RAYGUI_CPP_COMBO_BOX_H 32 | -------------------------------------------------------------------------------- /include/raygui-cpp/Component.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_COMPONENT_H 2 | #define RAYGUI_CPP_COMPONENT_H 3 | 4 | #include "Bounds.h" 5 | #include "Directives.h" 6 | #include "Globals.h" 7 | #include "Style.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #define WITH_STATE_RENDER(__code__) \ 14 | Globals::GuiSetState(IsEnabled() ? STATE_NORMAL : STATE_DISABLED); \ 15 | __code__; \ 16 | Globals::GuiEnable(); 17 | 18 | RAYGUI_CPP_BEGIN_NAMESPACE 19 | 20 | template 21 | class Component { 22 | public: 23 | using Callback = std::function; 24 | 25 | Component() : m_bounds(0, 0, 0, 0) {} 26 | 27 | explicit Component(Bounds bounds) : m_bounds(bounds) {} 28 | 29 | virtual ~Component() = default; 30 | 31 | virtual T Show() = 0; 32 | 33 | RAYGUI_CPP_NODISCARD Bounds GetBounds() const { 34 | return m_bounds; 35 | } 36 | 37 | void SetBounds(Bounds newBounds) { 38 | m_bounds = newBounds; 39 | } 40 | 41 | RAYGUI_CPP_NODISCARD Component *GetParent() const { 42 | return m_parent; 43 | } 44 | 45 | void SetParent(Component *newParent) { 46 | m_parent = newParent; 47 | } 48 | 49 | void Update() { 50 | Bounds bounds; 51 | 52 | if (m_parent != nullptr) { 53 | bounds = m_parent->GetBounds(); 54 | } else { 55 | bounds = Bounds::WindowBounds(); 56 | } 57 | 58 | if (m_style.GetPosition() != Style::Position::NONE) { 59 | UpdateBounds(bounds); 60 | } 61 | 62 | // Update children 63 | for (const auto &child: children) { 64 | child->Update(); 65 | } 66 | 67 | CallOnUpdate(); 68 | } 69 | 70 | RAYGUI_CPP_NODISCARD Style GetStyle() const { 71 | return m_style; 72 | } 73 | 74 | void SetStyle(Style newStyle) { 75 | m_style = newStyle; 76 | } 77 | 78 | RAYGUI_CPP_NODISCARD std::any GetData() const { 79 | return m_data; 80 | } 81 | 82 | void SetData(std::any newData) { 83 | m_data = std::move(newData); 84 | } 85 | 86 | T ShowAndEnableOnCondition(bool condition) { 87 | Globals::GuiSetState(condition ? STATE_NORMAL : STATE_DISABLED); 88 | T result = Show(); 89 | Globals::GuiSetState(STATE_NORMAL); 90 | return result; 91 | } 92 | 93 | /** 94 | * @brief Adds a child to the component. 95 | * 96 | * @param child The child to add. 97 | * 98 | * @note This method must be implemented by the derived class that supports children. 99 | */ 100 | virtual void AddChild(Component *child) { 101 | (void) child; 102 | } 103 | 104 | void RemoveChild(Component *child) { 105 | if (children.empty()) { 106 | return; 107 | } 108 | 109 | children.remove(child); 110 | child->SetParent(nullptr); 111 | } 112 | 113 | void ClearChildren() { 114 | children.clear(); 115 | } 116 | 117 | virtual void OnClick(const Callback &onClick) { 118 | // Noop here. Should be overridden. 119 | } 120 | 121 | virtual void OnUpdate(const Callback &onUpdate) { 122 | // Noop here. Should be overridden. 123 | } 124 | 125 | RAYGUI_CPP_NODISCARD bool IsEnabled() const { 126 | return m_enabled; 127 | } 128 | 129 | void Enable() { 130 | m_enabled = true; 131 | } 132 | 133 | void Disable() { 134 | m_enabled = false; 135 | } 136 | 137 | protected: 138 | void AddChildInternal(Component *child) { 139 | children.push_back(child); 140 | child->SetParent(this); 141 | } 142 | 143 | void ShowChildren() { 144 | for (auto &child: children) { 145 | child->Show(); 146 | } 147 | } 148 | 149 | RAYGUI_CPP_NODISCARD bool HasOnClick() const { 150 | return m_onClick != nullptr; 151 | } 152 | 153 | void SetOnClick(Callback onClick) { 154 | m_onClick = std::move(onClick); 155 | } 156 | 157 | RAYGUI_CPP_NODISCARD bool HasOnUpdate() const { 158 | return m_onUpdate != nullptr; 159 | } 160 | 161 | void SetOnUpdate(Callback onUpdate) { 162 | m_onUpdate = std::move(onUpdate); 163 | } 164 | 165 | void CallOnClick() const { 166 | if (m_onClick && m_enabled) { 167 | m_onClick(); 168 | } 169 | } 170 | 171 | void CallOnUpdate() const { 172 | if (m_onUpdate) { 173 | m_onUpdate(); 174 | } 175 | } 176 | 177 | private: 178 | Bounds m_bounds; 179 | Component *m_parent = nullptr; 180 | Style m_style = Style(Style::Position::NONE); 181 | std::list children; 182 | std::any m_data = nullptr; 183 | bool m_enabled = true; 184 | 185 | Callback m_onClick; 186 | Callback m_onUpdate; 187 | 188 | void UpdateBounds(Bounds bounds) { 189 | auto [marginH, marginV] = m_style.GetMargin(); 190 | auto [boundsX, boundsY, boundsWidth, boundsHeight] = bounds.GetRectangle(); 191 | auto [mBoundsWidth, mBoundsHeight] = m_bounds.GetSize(); 192 | float newX; 193 | float newY; 194 | 195 | switch (m_style.GetPosition()) { 196 | case Style::Position::TOP_LEFT: 197 | newX = boundsX + marginH; 198 | newY = boundsY + marginV; 199 | break; 200 | case Style::Position::TOP_CENTER: 201 | newX = boundsX + boundsWidth / 2 - mBoundsWidth / 2 + marginH; 202 | newY = boundsY + marginV; 203 | break; 204 | case Style::Position::TOP_RIGHT: 205 | newX = boundsX + boundsWidth - mBoundsWidth + marginH; 206 | newY = boundsY + marginV; 207 | break; 208 | case Style::Position::CENTER_LEFT: 209 | newX = boundsX + marginH; 210 | newY = boundsY + boundsHeight / 2 - mBoundsHeight / 2 + marginV; 211 | break; 212 | case Style::Position::CENTER: 213 | newX = boundsX + boundsWidth / 2 - mBoundsWidth / 2 + marginH; 214 | newY = boundsY + boundsHeight / 2 - mBoundsHeight / 2 + marginV; 215 | break; 216 | case Style::Position::CENTER_RIGHT: 217 | newX = boundsX + boundsWidth - mBoundsWidth + marginH; 218 | newY = boundsY + boundsHeight / 2 - mBoundsHeight / 2 + marginV; 219 | break; 220 | case Style::Position::BOTTOM_LEFT: 221 | newX = boundsX + marginH; 222 | newY = boundsY + boundsHeight - mBoundsHeight + marginV; 223 | break; 224 | case Style::Position::BOTTOM_CENTER: 225 | newX = boundsX + boundsWidth / 2 - mBoundsWidth / 2 + marginH; 226 | newY = boundsY + boundsHeight - mBoundsHeight + marginV; 227 | break; 228 | case Style::Position::BOTTOM_RIGHT: 229 | newX = boundsX + boundsWidth - mBoundsWidth + marginH; 230 | newY = boundsY + boundsHeight - mBoundsHeight + marginV; 231 | break; 232 | case Style::Position::NONE: 233 | default: 234 | newX = boundsX + marginH; 235 | newY = boundsY + marginV; 236 | break; 237 | } 238 | 239 | m_bounds.SetPosition(newX, newY); 240 | } 241 | }; 242 | 243 | RAYGUI_CPP_END_NAMESPACE 244 | 245 | #endif // RAYGUI_CPP_COMPONENT_H 246 | -------------------------------------------------------------------------------- /include/raygui-cpp/Directives.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_DIRECTIVES_H 2 | #define RAYGUI_CPP_DIRECTIVES_H 3 | 4 | // Defines the namespace of the library as rgc (raylib gui cpp) 5 | // Less typing for the user 6 | #define RAYGUI_CPP_NAMESPACE rgc 7 | 8 | #define RAYGUI_CPP_BEGIN_NAMESPACE namespace RAYGUI_CPP_NAMESPACE { 9 | #define RAYGUI_CPP_END_NAMESPACE } 10 | 11 | #define RAYGUI_CPP_NODISCARD [[nodiscard]] 12 | 13 | #define RAYGUI_CPP_UNUSED(x) (void) (x) 14 | 15 | #endif // RAYGUI_CPP_DIRECTIVES_H 16 | -------------------------------------------------------------------------------- /include/raygui-cpp/DropdownBox.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_DROPDOWN_BOX_H 2 | #define RAYGUI_CPP_DROPDOWN_BOX_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class DropdownBox : public Component { 11 | public: 12 | DropdownBox(); 13 | DropdownBox(const char *text, int *active, bool editMode); 14 | DropdownBox(Bounds bounds, const char *text, int *active, bool editMode); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD int *GetActive() const; 20 | void SetActive(int *newActive); 21 | 22 | RAYGUI_CPP_NODISCARD bool GetEditMode() const; 23 | void SetEditMode(bool newEditMode); 24 | 25 | RAYGUI_CPP_NODISCARD bool Show() override; 26 | 27 | void OnClick(const Callback &onClick) override; 28 | void OnUpdate(const Callback &onUpdate) override; 29 | 30 | private: 31 | const char *text; 32 | int *active; 33 | bool editMode; 34 | }; 35 | 36 | RAYGUI_CPP_END_NAMESPACE 37 | 38 | #endif // RAYGUI_CPP_DROPDOWN_BOX_H 39 | -------------------------------------------------------------------------------- /include/raygui-cpp/DummyRec.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_DUMMY_REC_H 2 | #define RAYGUI_CPP_DUMMY_REC_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class DummyRec : public Component { 11 | public: 12 | DummyRec(); 13 | explicit DummyRec(const char *text); 14 | DummyRec(Bounds bounds, const char *text); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | void Show() override; 20 | 21 | private: 22 | const char *text; 23 | }; 24 | 25 | RAYGUI_CPP_END_NAMESPACE 26 | 27 | #endif // RAYGUI_CPP_DUMMY_REC_H 28 | -------------------------------------------------------------------------------- /include/raygui-cpp/Globals.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_GLOBALS_H 2 | #define RAYGUI_CPP_GLOBALS_H 3 | 4 | #include "Directives.h" 5 | #include 6 | 7 | RAYGUI_CPP_BEGIN_NAMESPACE 8 | 9 | class Globals { 10 | public: 11 | static void GuiEnable(); 12 | 13 | static void GuiDisable(); 14 | 15 | static void GuiLock(); 16 | 17 | static void GuiUnlock(); 18 | 19 | static bool GuiIsLocked(); 20 | 21 | static void GuiSetAlpha(float alpha); 22 | 23 | static void GuiSetState(int state); 24 | 25 | static int GuiGetState(); 26 | 27 | class Font { 28 | public: 29 | static void GuiSetFont(const ::Font &font); 30 | 31 | static ::Font GuiGetFont(); 32 | }; 33 | 34 | class Style { 35 | public: 36 | static void GuiSetStyle(::GuiControl control, int property, int value); 37 | 38 | static int GuiGetStyle(::GuiControl control, int property); 39 | 40 | static void GuiLoadStyle(const char *fileName); 41 | 42 | static void GuiLoadStyleDefault(); 43 | }; 44 | 45 | class Tooltip { 46 | public: 47 | static void GuiEnableTooltip(); 48 | 49 | static void GuiDisableTooltip(); 50 | 51 | static void GuiSetTooltip(const char *tooltip); 52 | }; 53 | 54 | class Icon { 55 | public: 56 | static const char *GuiIconText(int iconId, const char *text); 57 | 58 | #if !defined(RAYGUI_NO_ICONS) 59 | static void GuiSetIconScale(int scale); 60 | 61 | static unsigned int *GuiGetIcons(); 62 | 63 | static char **GuiLoadIcons(const char *fileName, bool loadIconsName); 64 | 65 | static void GuiDrawIcon(int iconId, int posX, int posY, int pixelSize, ::Color color); 66 | #endif 67 | }; 68 | }; 69 | 70 | RAYGUI_CPP_END_NAMESPACE 71 | 72 | #endif // RAYGUI_CPP_GLOBALS_H 73 | -------------------------------------------------------------------------------- /include/raygui-cpp/Grid.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_GRID_H 2 | #define RAYGUI_CPP_GRID_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class Grid : public Component { 11 | public: 12 | Grid(); 13 | Grid(const char *text, float spacing, int subdivisions, Vector2 mouseCell); 14 | Grid(Bounds bounds, const char *text, float spacing, int subdivisions, Vector2 mouseCell); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD float GetSpacing() const; 20 | void SetSpacing(float newSpacing); 21 | 22 | RAYGUI_CPP_NODISCARD int GetSubdivisions() const; 23 | void SetSubdivisions(int newSubdivisions); 24 | 25 | RAYGUI_CPP_NODISCARD ::Vector2 GetMouseCell() const; 26 | void SetMouseCell(::Vector2 newMouseCell); 27 | 28 | RAYGUI_CPP_NODISCARD int Show() override; 29 | 30 | private: 31 | const char *text; 32 | float spacing; 33 | int subdivisions; 34 | Vector2 mouseCell; 35 | }; 36 | 37 | RAYGUI_CPP_END_NAMESPACE 38 | 39 | #endif // RAYGUI_CPP_GRID_H 40 | -------------------------------------------------------------------------------- /include/raygui-cpp/GroupBox.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_GROUPBOX_H 2 | #define RAYGUI_CPP_GROUPBOX_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class GroupBox : public Component { 11 | public: 12 | GroupBox(); 13 | explicit GroupBox(const char *text); 14 | GroupBox(Bounds bounds, const char *text); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | void Show() override; 20 | 21 | private: 22 | const char *text; 23 | }; 24 | 25 | RAYGUI_CPP_END_NAMESPACE 26 | 27 | #endif // RAYGUI_CPP_GROUPBOX_H 28 | -------------------------------------------------------------------------------- /include/raygui-cpp/Label.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_LABEL_H 2 | #define RAYGUI_CPP_LABEL_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include "Paintable.h" 7 | #include 8 | 9 | RAYGUI_CPP_BEGIN_NAMESPACE 10 | 11 | class Label : public Component, public Paintable { 12 | public: 13 | Label(); 14 | explicit Label(const char *text); 15 | Label(Bounds bounds, const char *text); 16 | 17 | RAYGUI_CPP_NODISCARD const char *GetText() const; 18 | void SetText(const char *newText); 19 | 20 | void Show() override; 21 | 22 | void SetPropertyColor(GuiControlProperty property, Color color) override; 23 | 24 | private: 25 | const char *text; 26 | }; 27 | 28 | RAYGUI_CPP_END_NAMESPACE 29 | 30 | #endif // RAYGUI_CPP_LABEL_H 31 | -------------------------------------------------------------------------------- /include/raygui-cpp/LabelButton.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_LABEL_BUTTON_H 2 | #define RAYGUI_CPP_LABEL_BUTTON_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include "Paintable.h" 7 | #include 8 | 9 | RAYGUI_CPP_BEGIN_NAMESPACE 10 | 11 | class LabelButton : public Component, public Paintable { 12 | public: 13 | LabelButton(); 14 | explicit LabelButton(const char *text); 15 | LabelButton(Bounds bounds, const char *text); 16 | 17 | RAYGUI_CPP_NODISCARD const char *GetText() const; 18 | void SetText(const char *newText); 19 | 20 | RAYGUI_CPP_NODISCARD bool Show() override; 21 | 22 | void SetPropertyColor(GuiControlProperty property, Color color) override; 23 | 24 | private: 25 | const char *text; 26 | }; 27 | 28 | RAYGUI_CPP_END_NAMESPACE 29 | 30 | #endif // RAYGUI_CPP_LABEL_BUTTON_H 31 | -------------------------------------------------------------------------------- /include/raygui-cpp/Line.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_LINE_H 2 | #define RAYGUI_CPP_LINE_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class Line : public Component { 11 | public: 12 | Line(); 13 | explicit Line(const char *text); 14 | Line(Bounds bounds, const char *text); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | void Show() override; 20 | 21 | private: 22 | const char *text; 23 | }; 24 | 25 | RAYGUI_CPP_END_NAMESPACE 26 | 27 | #endif // RAYGUI_CPP_LINE_H 28 | -------------------------------------------------------------------------------- /include/raygui-cpp/ListView.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_LIST_VIEW_H 2 | #define RAYGUI_CPP_LIST_VIEW_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ListView : public Component { 11 | public: 12 | ListView(); 13 | ListView(const char *text, int *scrollIndex, int active); 14 | ListView(Bounds bounds, const char *text, int *scrollIndex, int active); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD int *GetScrollIndex() const; 20 | void SetScrollIndex(int *newScrollIndex); 21 | 22 | RAYGUI_CPP_NODISCARD int GetActive() const; 23 | void SetActive(int newActive); 24 | 25 | RAYGUI_CPP_NODISCARD int Show() override; 26 | 27 | private: 28 | const char *text; 29 | int *scrollIndex; 30 | int active; 31 | }; 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | 35 | #endif // RAYGUI_CPP_LIST_VIEW_H 36 | -------------------------------------------------------------------------------- /include/raygui-cpp/ListViewEx.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_LIST_VIEW_EX_H 2 | #define RAYGUI_CPP_LIST_VIEW_EX_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ListViewEx : public Component { 11 | public: 12 | ListViewEx(); 13 | ListViewEx(const char **text, int count, int *focus, int *scrollIndex, int active); 14 | ListViewEx(Bounds bounds, const char **text, int count, int *focus, int *scrollIndex, int active); 15 | 16 | RAYGUI_CPP_NODISCARD const char **GetText() const; 17 | void SetText(const char **newText); 18 | 19 | RAYGUI_CPP_NODISCARD int GetCount() const; 20 | void SetCount(int newCount); 21 | 22 | RAYGUI_CPP_NODISCARD int *GetFocus() const; 23 | void SetFocus(int *newFocus); 24 | 25 | RAYGUI_CPP_NODISCARD int *GetScrollIndex() const; 26 | void SetScrollIndex(int *newScrollIndex); 27 | 28 | RAYGUI_CPP_NODISCARD int GetActive() const; 29 | void SetActive(int newActive); 30 | 31 | RAYGUI_CPP_NODISCARD int Show() override; 32 | 33 | private: 34 | const char **text; 35 | int count; 36 | int *focus; 37 | int *scrollIndex; 38 | int active; 39 | }; 40 | 41 | RAYGUI_CPP_END_NAMESPACE 42 | 43 | #endif // RAYGUI_CPP_LIST_VIEW_EX_H 44 | -------------------------------------------------------------------------------- /include/raygui-cpp/Margin.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_MARGIN_H 2 | #define RAYGUI_CPP_MARGIN_H 3 | 4 | #include "Directives.h" 5 | 6 | RAYGUI_CPP_BEGIN_NAMESPACE 7 | 8 | struct Margin { 9 | float h; // Horizontal 10 | float v; // Vertical 11 | }; 12 | 13 | RAYGUI_CPP_END_NAMESPACE 14 | 15 | #endif // RAYGUI_CPP_MARGIN_H 16 | -------------------------------------------------------------------------------- /include/raygui-cpp/MessageBox.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_MESSAGE_BOX_H 2 | #define RAYGUI_CPP_MESSAGE_BOX_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class MessageBox : public Component { 11 | public: 12 | MessageBox(); 13 | MessageBox(const char *title, const char *message, const char *buttons); 14 | MessageBox(Bounds bounds, const char *title, const char *message, const char *buttons); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetTitle() const; 17 | void SetTitle(const char *newTitle); 18 | 19 | RAYGUI_CPP_NODISCARD const char *GetMessage() const; 20 | void SetMessage(const char *newMessage); 21 | 22 | RAYGUI_CPP_NODISCARD const char *GetButtons() const; 23 | void SetButtons(const char *newButtons); 24 | 25 | RAYGUI_CPP_NODISCARD int Show() override; 26 | 27 | private: 28 | const char *title; 29 | const char *message; 30 | const char *buttons; 31 | }; 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | 35 | #endif // RAYGUI_CPP_MESSAGE_BOX_H 36 | -------------------------------------------------------------------------------- /include/raygui-cpp/Paintable.h: -------------------------------------------------------------------------------- 1 | #ifndef PAINTABLE_H 2 | #define PAINTABLE_H 3 | 4 | #include "Directives.h" 5 | #include 6 | #include 7 | #include 8 | 9 | RAYGUI_CPP_BEGIN_NAMESPACE 10 | 11 | class Paintable { 12 | public: 13 | Paintable() = default; 14 | virtual ~Paintable() = default; 15 | 16 | void SetBaseColor(Color color); 17 | void SetTextColor(Color color); 18 | void SetBorderColor(Color color); 19 | virtual void SetPropertyColor(GuiControlProperty property, Color color) = 0; 20 | 21 | protected: 22 | void PreRender() const; 23 | void PostRender() const; 24 | 25 | void AddProperty(GuiControl control, GuiControlProperty property, const Color &color); 26 | 27 | private: 28 | struct PropColor { 29 | GuiControlProperty property; 30 | Color previous; 31 | Color current; 32 | 33 | void SetProperty(const GuiControlProperty p) { 34 | this->property = p; 35 | } 36 | 37 | void SetPrevious(const Color p) { 38 | this->previous = p; 39 | } 40 | 41 | void SetCurrent(const Color c) { 42 | this->current = c; 43 | } 44 | }; 45 | 46 | std::unordered_map> m_properties{}; 47 | }; 48 | 49 | RAYGUI_CPP_END_NAMESPACE 50 | 51 | #endif // PAINTABLE_H 52 | -------------------------------------------------------------------------------- /include/raygui-cpp/Panel.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_PANEL_H 2 | #define RAYGUI_CPP_PANEL_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class Panel : public Component { 11 | public: 12 | Panel(); 13 | explicit Panel(const char *text); 14 | Panel(Bounds bounds, const char *text); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | void Show() override; 20 | 21 | void AddChild(Component *child) override; 22 | 23 | private: 24 | const char *text; 25 | }; 26 | 27 | RAYGUI_CPP_END_NAMESPACE 28 | 29 | #endif // RAYGUI_CPP_PANEL_H 30 | -------------------------------------------------------------------------------- /include/raygui-cpp/ProgressBar.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_PROGRESS_BAR_H 2 | #define RAYGUI_CPP_PROGRESS_BAR_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include "Paintable.h" 7 | #include 8 | 9 | RAYGUI_CPP_BEGIN_NAMESPACE 10 | 11 | class ProgressBar : public Component, public Paintable { 12 | public: 13 | ProgressBar(); 14 | ProgressBar(const char *textLeft, const char *textRight, float value, float minValue, float maxValue); 15 | ProgressBar(Bounds bounds, const char *textLeft, const char *textRight, float value, float minValue, 16 | float maxValue); 17 | 18 | RAYGUI_CPP_NODISCARD const char *GetTextLeft() const; 19 | void SetTextLeft(const char *newTextLeft); 20 | 21 | RAYGUI_CPP_NODISCARD const char *GetTextRight() const; 22 | void SetTextRight(const char *newTextRight); 23 | 24 | RAYGUI_CPP_NODISCARD float GetValue() const; 25 | void SetValue(float newValue); 26 | 27 | RAYGUI_CPP_NODISCARD float GetMinValue() const; 28 | void SetMinValue(float newMinValue); 29 | 30 | RAYGUI_CPP_NODISCARD float GetMaxValue() const; 31 | void SetMaxValue(float newMaxValue); 32 | 33 | RAYGUI_CPP_NODISCARD int Show() override; 34 | 35 | void SetPropertyColor(GuiControlProperty property, Color color) override; 36 | 37 | private: 38 | const char *textLeft; 39 | const char *textRight; 40 | float value; 41 | float minValue; 42 | float maxValue; 43 | }; 44 | 45 | RAYGUI_CPP_END_NAMESPACE 46 | 47 | #endif // RAYGUI_CPP_PROGRESS_BAR_H 48 | -------------------------------------------------------------------------------- /include/raygui-cpp/ScrollPanel.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_SCROLL_PANEL_H 2 | #define RAYGUI_CPP_SCROLL_PANEL_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ScrollPanel : public Component { 11 | public: 12 | ScrollPanel(); 13 | ScrollPanel(const char *text, ::Rectangle content, ::Vector2 scroll, ::Rectangle view); 14 | ScrollPanel(Bounds bounds, const char *text, ::Rectangle content, ::Vector2 scroll, ::Rectangle view); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD ::Rectangle GetContent() const; 20 | void SetContent(::Rectangle newContent); 21 | 22 | RAYGUI_CPP_NODISCARD ::Vector2 GetScroll() const; 23 | void SetScroll(::Vector2 newScroll); 24 | 25 | RAYGUI_CPP_NODISCARD ::Rectangle GetView() const; 26 | void SetView(::Rectangle newView); 27 | 28 | RAYGUI_CPP_NODISCARD int Show() override; 29 | 30 | private: 31 | const char *text; 32 | ::Rectangle content; 33 | ::Vector2 scroll; 34 | ::Rectangle view; 35 | }; 36 | 37 | RAYGUI_CPP_END_NAMESPACE 38 | 39 | #endif // RAYGUI_CPP_SCROLL_PANEL_H 40 | -------------------------------------------------------------------------------- /include/raygui-cpp/Slider.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_SLIDER_H 2 | #define RAYGUI_CPP_SLIDER_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class Slider : public Component { 11 | public: 12 | Slider(); 13 | Slider(const char *textLeft, const char *textRight, float value, float minValue, float maxValue); 14 | Slider(Bounds bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetTextLeft() const; 17 | void SetTextLeft(const char *newTextLeft); 18 | 19 | RAYGUI_CPP_NODISCARD const char *GetTextRight() const; 20 | void SetTextRight(const char *newTextRight); 21 | 22 | RAYGUI_CPP_NODISCARD float GetValue() const; 23 | void SetValue(float newValue); 24 | 25 | RAYGUI_CPP_NODISCARD float GetMinValue() const; 26 | void SetMinValue(float newMinValue); 27 | 28 | RAYGUI_CPP_NODISCARD float GetMaxValue() const; 29 | void SetMaxValue(float newMaxValue); 30 | 31 | RAYGUI_CPP_NODISCARD int Show() override; 32 | 33 | private: 34 | const char *textLeft; 35 | const char *textRight; 36 | float value; 37 | float minValue; 38 | float maxValue; 39 | }; 40 | 41 | RAYGUI_CPP_END_NAMESPACE 42 | 43 | #endif // RAYGUI_CPP_SLIDER_H 44 | -------------------------------------------------------------------------------- /include/raygui-cpp/SliderBar.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_SLIDER_BAR_H 2 | #define RAYGUI_CPP_SLIDER_BAR_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class SliderBar : public Component { 11 | public: 12 | SliderBar(); 13 | SliderBar(const char *textLeft, const char *textRight, float value, float minValue, float maxValue); 14 | SliderBar(Bounds bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetTextLeft() const; 17 | void SetTextLeft(const char *newTextLeft); 18 | 19 | RAYGUI_CPP_NODISCARD const char *GetTextRight() const; 20 | void SetTextRight(const char *newTextRight); 21 | 22 | RAYGUI_CPP_NODISCARD float GetValue() const; 23 | void SetValue(float newValue); 24 | 25 | RAYGUI_CPP_NODISCARD float GetMinValue() const; 26 | void SetMinValue(float newMinValue); 27 | 28 | RAYGUI_CPP_NODISCARD float GetMaxValue() const; 29 | void SetMaxValue(float newMaxValue); 30 | 31 | RAYGUI_CPP_NODISCARD int Show() override; 32 | 33 | private: 34 | const char *textLeft; 35 | const char *textRight; 36 | float value; 37 | float minValue; 38 | float maxValue; 39 | }; 40 | 41 | RAYGUI_CPP_END_NAMESPACE 42 | 43 | #endif // RAYGUI_CPP_SLIDER_BAR_H 44 | -------------------------------------------------------------------------------- /include/raygui-cpp/Spinner.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_SPINNER_H 2 | #define RAYGUI_CPP_SPINNER_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class Spinner : public Component { 11 | public: 12 | Spinner(); 13 | Spinner(const char *text, int *value, int minValue, int maxValue, bool editMode); 14 | Spinner(Bounds bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD int *GetValue() const; 20 | void SetValue(int *newValue); 21 | 22 | RAYGUI_CPP_NODISCARD int GetMinValue() const; 23 | void SetMinValue(int newMinValue); 24 | 25 | RAYGUI_CPP_NODISCARD int GetMaxValue() const; 26 | void SetMaxValue(int newMaxValue); 27 | 28 | RAYGUI_CPP_NODISCARD bool IsEditMode() const; 29 | void SetEditMode(bool newEditMode); 30 | 31 | RAYGUI_CPP_NODISCARD bool Show() override; 32 | 33 | private: 34 | const char *text; 35 | int *value; 36 | int minValue; 37 | int maxValue; 38 | bool editMode; 39 | }; 40 | 41 | RAYGUI_CPP_END_NAMESPACE 42 | 43 | #endif // RAYGUI_CPP_SPINNER_H 44 | -------------------------------------------------------------------------------- /include/raygui-cpp/StatusBar.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_STATUS_BAR_H 2 | #define RAYGUI_CPP_STATUS_BAR_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class StatusBar : public Component { 11 | public: 12 | StatusBar(); 13 | explicit StatusBar(const char *text); 14 | StatusBar(Bounds bounds, const char *text); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | void Show() override; 20 | 21 | private: 22 | const char *text; 23 | }; 24 | 25 | RAYGUI_CPP_END_NAMESPACE 26 | 27 | #endif // RAYGUI_CPP_STATUS_BAR_H 28 | -------------------------------------------------------------------------------- /include/raygui-cpp/Style.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_STYLE_H 2 | #define RAYGUI_CPP_STYLE_H 3 | 4 | #include "Directives.h" 5 | #include "Margin.h" 6 | 7 | RAYGUI_CPP_BEGIN_NAMESPACE 8 | 9 | class Style { 10 | public: 11 | enum class Position { 12 | TOP_LEFT, 13 | TOP_CENTER, 14 | TOP_RIGHT, 15 | CENTER_LEFT, 16 | CENTER, 17 | CENTER_RIGHT, 18 | BOTTOM_LEFT, 19 | BOTTOM_CENTER, 20 | BOTTOM_RIGHT, 21 | NONE // To keep the component in a specific position 22 | }; 23 | 24 | Style(); 25 | explicit Style(Position position); 26 | Style(Position position, Margin margin); 27 | Style(Position position, float margin); 28 | Style(Position position, float horizontalMargin, float verticalMargin); 29 | 30 | RAYGUI_CPP_NODISCARD Position GetPosition() const; 31 | 32 | RAYGUI_CPP_NODISCARD Margin GetMargin() const; 33 | 34 | private: 35 | Position m_position; 36 | Margin m_margin; 37 | }; 38 | 39 | RAYGUI_CPP_END_NAMESPACE 40 | 41 | #endif // RAYGUI_CPP_STYLE_H 42 | -------------------------------------------------------------------------------- /include/raygui-cpp/TabBar.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_TAB_BAR_H 2 | #define RAYGUI_CPP_TAB_BAR_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class TabBar : public Component { 11 | public: 12 | TabBar(); 13 | TabBar(const char **text, int count, int *active); 14 | TabBar(Bounds bounds, const char **text, int count, int *active); 15 | 16 | RAYGUI_CPP_NODISCARD const char **GetText() const; 17 | void SetText(const char **newText); 18 | 19 | RAYGUI_CPP_NODISCARD int GetCount() const; 20 | void SetCount(int newCount); 21 | 22 | RAYGUI_CPP_NODISCARD int *GetActive() const; 23 | void SetActive(int *newActive); 24 | 25 | RAYGUI_CPP_NODISCARD int Show() override; 26 | 27 | private: 28 | const char **text; 29 | int count; 30 | int *active; 31 | }; 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | 35 | #endif // RAYGUI_CPP_TAB_BAR_H 36 | -------------------------------------------------------------------------------- /include/raygui-cpp/TextBox.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_TEXT_BOX_H 2 | #define RAYGUI_CPP_TEXT_BOX_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include "Paintable.h" 7 | #include 8 | 9 | RAYGUI_CPP_BEGIN_NAMESPACE 10 | 11 | class TextBox : public Component, public Paintable { 12 | public: 13 | TextBox(); 14 | TextBox(char *text, int textSize, bool editMode); 15 | TextBox(Bounds bounds, char *text, int textSize, bool editMode); 16 | 17 | RAYGUI_CPP_NODISCARD const char *GetText() const; 18 | void SetText(char *newText); 19 | 20 | RAYGUI_CPP_NODISCARD int GetTextSize() const; 21 | void SetTextSize(int newTextSize); 22 | 23 | RAYGUI_CPP_NODISCARD bool GetEditMode() const; 24 | void SetEditMode(bool newEditMode); 25 | 26 | RAYGUI_CPP_NODISCARD bool Show() override; 27 | 28 | void SetPropertyColor(GuiControlProperty property, Color color) override; 29 | 30 | private: 31 | char *text; 32 | int textSize; 33 | bool editMode; 34 | }; 35 | 36 | RAYGUI_CPP_END_NAMESPACE 37 | 38 | #endif // RAYGUI_CPP_TEXT_BOX_H 39 | -------------------------------------------------------------------------------- /include/raygui-cpp/TextInputBox.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_TEXT_INPUT_BOX_H 2 | #define RAYGUI_CPP_TEXT_INPUT_BOX_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class TextInputBox : public Component { 11 | public: 12 | TextInputBox(); 13 | TextInputBox(const char *title, const char *message, const char *buttons, char *text, int textMaxSize, 14 | bool secretViewActive); 15 | TextInputBox(Bounds bounds, const char *title, const char *message, const char *buttons, char *text, 16 | int textMaxSize, bool secretViewActive); 17 | 18 | RAYGUI_CPP_NODISCARD const char *GetTitle() const; 19 | void SetTitle(const char *newTitle); 20 | 21 | RAYGUI_CPP_NODISCARD const char *GetMessage() const; 22 | void SetMessage(const char *newMessage); 23 | 24 | RAYGUI_CPP_NODISCARD const char *GetButtons() const; 25 | void SetButtons(const char *newButtons); 26 | 27 | RAYGUI_CPP_NODISCARD char *GetText() const; 28 | void SetText(char *newText); 29 | 30 | RAYGUI_CPP_NODISCARD int GetTextMaxSize() const; 31 | void SetTextMaxSize(int newTextMaxSize); 32 | 33 | RAYGUI_CPP_NODISCARD bool GetSecretViewActive() const; 34 | void SetSecretViewActive(bool newSecretViewActive); 35 | 36 | RAYGUI_CPP_NODISCARD int Show() override; 37 | 38 | private: 39 | const char *title; 40 | const char *message; 41 | const char *buttons; 42 | char *text; 43 | int textMaxSize; 44 | bool secretViewActive; 45 | }; 46 | 47 | RAYGUI_CPP_END_NAMESPACE 48 | 49 | #endif // RAYGUI_CPP_TEXT_INPUT_BOX_H 50 | -------------------------------------------------------------------------------- /include/raygui-cpp/Toggle.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_TOGGLE_H 2 | #define RAYGUI_CPP_TOGGLE_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class Toggle : public Component { 11 | public: 12 | Toggle(); 13 | Toggle(const char *text, bool active = false); 14 | Toggle(Bounds bounds, const char *text, bool active = false); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD bool IsActive() const; 20 | void SetActive(bool newActive); 21 | 22 | RAYGUI_CPP_NODISCARD bool Show() override; 23 | 24 | private: 25 | const char *text; 26 | bool active; // Checked 27 | }; 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | 31 | #endif // RAYGUI_CPP_TOGGLE_H 32 | -------------------------------------------------------------------------------- /include/raygui-cpp/ToggleGroup.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_TOGGLE_GROUP_H 2 | #define RAYGUI_CPP_TOGGLE_GROUP_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ToggleGroup : public Component { 11 | public: 12 | ToggleGroup(); 13 | ToggleGroup(const char *text, int active); 14 | ToggleGroup(Bounds bounds, const char *text, int active); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD int GetActive() const; 20 | void SetActive(int newActive); 21 | 22 | RAYGUI_CPP_NODISCARD int Show() override; 23 | 24 | private: 25 | const char *text; 26 | int active; 27 | }; 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | 31 | #endif // RAYGUI_CPP_TOGGLE_GROUP_H 32 | -------------------------------------------------------------------------------- /include/raygui-cpp/ToggleSlider.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_TOGGLE_SLIDER_H 2 | #define RAYGUI_CPP_TOGGLE_SLIDER_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ToggleSlider : public Component { 11 | public: 12 | ToggleSlider(); 13 | ToggleSlider(const char *text, int active); 14 | ToggleSlider(Bounds bounds, const char *text, int active); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD int GetActive() const; 20 | void SetActive(int newActive); 21 | 22 | RAYGUI_CPP_NODISCARD int Show() override; 23 | 24 | private: 25 | const char *text; 26 | int active; 27 | }; 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | 31 | #endif // RAYGUI_CPP_TOGGLE_SLIDER_H 32 | -------------------------------------------------------------------------------- /include/raygui-cpp/Utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_UTILS_H 2 | #define RAYGUI_CPP_UTILS_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | 7 | RAYGUI_CPP_BEGIN_NAMESPACE 8 | 9 | /** 10 | * @brief Converts a component to a component of type T. 11 | * 12 | * @param component The component to convert. 13 | * @tparam T The type to cast to. 14 | */ 15 | template 16 | auto ToComponent(rgc::Component *component) { 17 | return component; 18 | } 19 | 20 | RAYGUI_CPP_END_NAMESPACE 21 | 22 | #endif // RAYGUI_CPP_UTILS_H 23 | -------------------------------------------------------------------------------- /include/raygui-cpp/ValueBox.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_VALUE_BOX_H 2 | #define RAYGUI_CPP_VALUE_BOX_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ValueBox : public Component { 11 | public: 12 | ValueBox(); 13 | ValueBox(const char *text, int *value, int minValue, int maxValue, bool editMode); 14 | ValueBox(Bounds bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetText() const; 17 | void SetText(const char *newText); 18 | 19 | RAYGUI_CPP_NODISCARD int *GetValue() const; 20 | void SetValue(int *newValue); 21 | 22 | RAYGUI_CPP_NODISCARD int GetMinValue() const; 23 | void SetMinValue(int newMinValue); 24 | 25 | RAYGUI_CPP_NODISCARD int GetMaxValue() const; 26 | void SetMaxValue(int newMaxValue); 27 | 28 | RAYGUI_CPP_NODISCARD bool IsEditMode() const; 29 | void SetEditMode(bool newEditMode); 30 | 31 | RAYGUI_CPP_NODISCARD bool Show() override; 32 | 33 | private: 34 | const char *text; 35 | int *value; 36 | int minValue; 37 | int maxValue; 38 | bool editMode; 39 | }; 40 | 41 | RAYGUI_CPP_END_NAMESPACE 42 | 43 | #endif // RAYGUI_CPP_VALUE_BOX_H 44 | -------------------------------------------------------------------------------- /include/raygui-cpp/WindowBox.h: -------------------------------------------------------------------------------- 1 | #ifndef RAYGUI_CPP_WINDOW_BOX_H 2 | #define RAYGUI_CPP_WINDOW_BOX_H 3 | 4 | #include "Component.h" 5 | #include "Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class WindowBox : public Component { 11 | public: 12 | WindowBox(); 13 | explicit WindowBox(const char *title); 14 | WindowBox(Bounds bounds, const char *title); 15 | 16 | RAYGUI_CPP_NODISCARD const char *GetTitle() const; 17 | void SetTitle(const char *newTitle); 18 | 19 | RAYGUI_CPP_NODISCARD bool Show() override; 20 | 21 | void AddChild(Component *child) override; 22 | 23 | private: 24 | const char *title; 25 | }; 26 | 27 | RAYGUI_CPP_END_NAMESPACE 28 | 29 | #endif // RAYGUI_CPP_WINDOW_BOX_H 30 | -------------------------------------------------------------------------------- /include/raygui-cpp/extras/ImageButton.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGE_BUTTON_H 2 | #define IMAGE_BUTTON_H 3 | 4 | #include "../Component.h" 5 | #include "../Directives.h" 6 | #include 7 | 8 | RAYGUI_CPP_BEGIN_NAMESPACE 9 | 10 | class ImageButton : public Component { 11 | public: 12 | ImageButton(); 13 | ImageButton(Bounds bounds, Texture2D texture); 14 | 15 | RAYGUI_CPP_NODISCARD Texture2D GetTexture() const; 16 | void SetTexture(Texture2D newTexture); 17 | 18 | RAYGUI_CPP_NODISCARD bool Show() override; 19 | 20 | void OnClick(const Callback &onClick) override; 21 | void OnUpdate(const Callback &onUpdate) override; 22 | 23 | private: 24 | Texture2D texture; 25 | }; 26 | 27 | RAYGUI_CPP_END_NAMESPACE 28 | 29 | #endif //IMAGE_BUTTON_H 30 | -------------------------------------------------------------------------------- /raygui_cpp_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scastd/raygui-cpp/78387c8230d661109e1ec2ddcaad9fb4cd9bdd6d/raygui_cpp_256x256.png -------------------------------------------------------------------------------- /src/raygui-cpp/Bounds.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Bounds.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | Bounds::Bounds() : m_rectangle({ 0, 0, 0, 0 }) {} 6 | 7 | Bounds::Bounds(::Rectangle rectangle) : m_rectangle(rectangle) {} 8 | 9 | Bounds::Bounds(float x, float y, float width, float height) : m_rectangle({ x, y, width, height }) {} 10 | 11 | Bounds::Bounds(::Vector2 position, ::Vector2 size) : m_rectangle({ position.x, position.y, size.x, size.y }) {} 12 | 13 | ::Rectangle Bounds::GetRectangle() const { 14 | return m_rectangle; 15 | } 16 | 17 | void Bounds::SetRectangle(::Rectangle newRectangle) { 18 | m_rectangle = newRectangle; 19 | } 20 | 21 | ::Vector2 Bounds::GetPosition() const { 22 | return { m_rectangle.x, m_rectangle.y }; 23 | } 24 | 25 | void Bounds::SetPosition(::Vector2 newPosition) { 26 | SetX(newPosition.x); 27 | SetY(newPosition.y); 28 | } 29 | 30 | void Bounds::SetPosition(float x, float y) { 31 | SetX(x); 32 | SetY(y); 33 | } 34 | 35 | Vector2 Bounds::GetSize() const { 36 | return { m_rectangle.width, m_rectangle.height }; 37 | } 38 | 39 | void Bounds::SetSize(Vector2 newSize) { 40 | SetWidth(newSize.x); 41 | SetHeight(newSize.y); 42 | } 43 | 44 | void Bounds::SetSize(float width, float height) { 45 | SetWidth(width); 46 | SetHeight(height); 47 | } 48 | 49 | float Bounds::GetX() const { 50 | return m_rectangle.x; 51 | } 52 | 53 | void Bounds::SetX(float newX) { 54 | m_rectangle.x = newX; 55 | } 56 | 57 | float Bounds::GetY() const { 58 | return m_rectangle.y; 59 | } 60 | 61 | void Bounds::SetY(float newY) { 62 | m_rectangle.y = newY; 63 | } 64 | 65 | float Bounds::GetWidth() const { 66 | return m_rectangle.width; 67 | } 68 | 69 | void Bounds::SetWidth(float newWidth) { 70 | m_rectangle.width = newWidth; 71 | } 72 | 73 | float Bounds::GetHeight() const { 74 | return m_rectangle.height; 75 | } 76 | 77 | void Bounds::SetHeight(float newHeight) { 78 | m_rectangle.height = newHeight; 79 | } 80 | 81 | Bounds Bounds::WindowBounds() { 82 | return { 0, 0, static_cast(GetScreenWidth()), static_cast(GetScreenHeight()) }; 83 | } 84 | 85 | Bounds Bounds::OfSize(float width, float height) { 86 | return { 0, 0, width, height }; 87 | } 88 | 89 | Bounds Bounds::WithText(const char *text) { 90 | return WithText(text, GuiGetStyle(DEFAULT, TEXT_SIZE)); 91 | } 92 | 93 | Bounds Bounds::WithText(const char *text, int fontSize) { 94 | return { 0, 0, static_cast(MeasureText(text, fontSize)), static_cast(fontSize) }; 95 | } 96 | 97 | Bounds Bounds::WithText(const char *text, int fontSize, Margin textMargins) { 98 | return { 0, 0, static_cast(MeasureText(text, fontSize)) + textMargins.h, 99 | static_cast(fontSize) + textMargins.v }; 100 | } 101 | 102 | Bounds Bounds::WithPositionAndText(float x, float y, const char *text) { 103 | Bounds bounds = WithText(text); 104 | bounds.SetPosition(x, y); 105 | return bounds; 106 | } 107 | 108 | Bounds Bounds::WithPositionAndText(float x, float y, const char *text, int fontSize) { 109 | Bounds bounds = WithText(text, fontSize); 110 | bounds.SetPosition(x, y); 111 | return bounds; 112 | } 113 | 114 | Bounds Bounds::WithPositionAndText(float x, float y, const char *text, int fontSize, Margin textMargins) { 115 | Bounds bounds = WithText(text, fontSize, textMargins); 116 | bounds.SetPosition(x, y); 117 | return bounds; 118 | } 119 | 120 | RAYGUI_CPP_END_NAMESPACE 121 | -------------------------------------------------------------------------------- /src/raygui-cpp/Button.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Button.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | Button::Button() : text("") {} 6 | 7 | Button::Button(const char *text) : text(text) {} 8 | 9 | Button::Button(Bounds bounds, const char *text) : Component(bounds), text(text) {} 10 | 11 | const char *Button::GetText() const { 12 | return text; 13 | } 14 | 15 | void Button::SetText(const char *newText) { 16 | this->text = newText; 17 | } 18 | 19 | bool Button::Show() { 20 | PreRender(); 21 | WITH_STATE_RENDER(const int buttonClicked = ::GuiButton(GetBounds().GetRectangle(), text)) 22 | PostRender(); 23 | 24 | if (buttonClicked && HasOnClick()) { 25 | CallOnClick(); 26 | } 27 | 28 | return buttonClicked; 29 | } 30 | 31 | void Button::OnClick(const Component::Callback &onClick) { 32 | SetOnClick(onClick); 33 | } 34 | 35 | void Button::OnUpdate(const Component::Callback &onUpdate) { 36 | SetOnUpdate(onUpdate); 37 | } 38 | 39 | void Button::SetPropertyColor(const GuiControlProperty property, const Color color) { 40 | AddProperty(BUTTON, property, color); 41 | } 42 | 43 | RAYGUI_CPP_END_NAMESPACE 44 | -------------------------------------------------------------------------------- /src/raygui-cpp/CheckBox.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/CheckBox.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | CheckBox::CheckBox() : text(""), checked(false) {} 6 | 7 | CheckBox::CheckBox(const char *text, bool checked) : text(text), checked(checked) {} 8 | 9 | CheckBox::CheckBox(Bounds bounds, const char *text, bool checked) 10 | : Component(bounds), text(text), checked(checked) {} 11 | 12 | const char *CheckBox::GetText() const { 13 | return text; 14 | } 15 | 16 | void CheckBox::SetText(const char *newText) { 17 | this->text = newText; 18 | } 19 | 20 | bool CheckBox::IsChecked() const { 21 | return checked; 22 | } 23 | 24 | void CheckBox::SetChecked(bool newChecked) { 25 | this->checked = newChecked; 26 | } 27 | 28 | bool CheckBox::Show() { 29 | WITH_STATE_RENDER(int ret = ::GuiCheckBox(GetBounds().GetRectangle(), text, &checked)) 30 | return ret; 31 | } 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | -------------------------------------------------------------------------------- /src/raygui-cpp/ColorBarAlpha.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ColorBarAlpha.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ColorBarAlpha::ColorBarAlpha() : text(""), alpha(0) {} 6 | 7 | ColorBarAlpha::ColorBarAlpha(const char *text, float alpha) : text(text), alpha(alpha) {} 8 | 9 | ColorBarAlpha::ColorBarAlpha(Bounds bounds, const char *text, float alpha) 10 | : Component(bounds), text(text), alpha(alpha) {} 11 | 12 | const char *ColorBarAlpha::GetText() const { 13 | return text; 14 | } 15 | 16 | void ColorBarAlpha::SetText(const char *newText) { 17 | this->text = newText; 18 | } 19 | 20 | float ColorBarAlpha::GetAlpha() const { 21 | return alpha; 22 | } 23 | 24 | void ColorBarAlpha::SetAlpha(float newAlpha) { 25 | this->alpha = newAlpha; 26 | } 27 | 28 | int ColorBarAlpha::Show() { 29 | WITH_STATE_RENDER(int ret = ::GuiColorBarAlpha(GetBounds().GetRectangle(), text, &alpha)) 30 | return ret; 31 | } 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | -------------------------------------------------------------------------------- /src/raygui-cpp/ColorBarHue.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ColorBarHue.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ColorBarHue::ColorBarHue() : text(""), value(0) {} 6 | 7 | ColorBarHue::ColorBarHue(const char *text, float value) : text(text), value(value) {} 8 | 9 | ColorBarHue::ColorBarHue(Bounds bounds, const char *text, float value) 10 | : Component(bounds), text(text), value(value) {} 11 | 12 | const char *ColorBarHue::GetText() const { 13 | return text; 14 | } 15 | 16 | void ColorBarHue::SetText(const char *newText) { 17 | this->text = newText; 18 | } 19 | 20 | float ColorBarHue::GetValue() const { 21 | return value; 22 | } 23 | 24 | void ColorBarHue::SetValue(float newValue) { 25 | this->value = newValue; 26 | } 27 | 28 | int ColorBarHue::Show() { 29 | WITH_STATE_RENDER(int ret = ::GuiColorBarHue(GetBounds().GetRectangle(), text, &value)) 30 | return ret; 31 | } 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | -------------------------------------------------------------------------------- /src/raygui-cpp/ColorPanel.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ColorPanel.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ColorPanel::ColorPanel() : text(""), color({ 0, 0, 0, 0 }) {} 6 | 7 | ColorPanel::ColorPanel(const char *text, Color color) : text(text), color(color) {} 8 | 9 | ColorPanel::ColorPanel(Bounds bounds, const char *text, ::Color color) 10 | : Component(bounds), text(text), color(color) {} 11 | 12 | const char *ColorPanel::GetText() const { 13 | return text; 14 | } 15 | 16 | void ColorPanel::SetText(const char *newText) { 17 | this->text = newText; 18 | } 19 | 20 | ::Color ColorPanel::GetColor() const { 21 | return color; 22 | } 23 | 24 | void ColorPanel::SetColor(::Color newColor) { 25 | this->color = newColor; 26 | } 27 | 28 | int ColorPanel::Show() { 29 | WITH_STATE_RENDER(int ret = ::GuiColorPanel(GetBounds().GetRectangle(), text, &color)) 30 | return ret; 31 | } 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | -------------------------------------------------------------------------------- /src/raygui-cpp/ColorPanelHSV.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ColorPanelHSV.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ColorPanelHSV::ColorPanelHSV() : text(""), colorHsv({}) {} 6 | 7 | ColorPanelHSV::ColorPanelHSV(const char *text, ::Vector3 colorHsv) : text(text), colorHsv(colorHsv) {} 8 | 9 | ColorPanelHSV::ColorPanelHSV(Bounds bounds, const char *text, ::Vector3 colorHsv) 10 | : Component(bounds), text(text), colorHsv(colorHsv) {} 11 | 12 | const char *ColorPanelHSV::GetText() const { 13 | return text; 14 | } 15 | 16 | void ColorPanelHSV::SetText(const char *newText) { 17 | this->text = newText; 18 | } 19 | 20 | ::Vector3 ColorPanelHSV::GetColorHsv() const { 21 | return colorHsv; 22 | } 23 | 24 | void ColorPanelHSV::SetColorHsv(::Vector3 newColorHsv) { 25 | this->colorHsv = newColorHsv; 26 | } 27 | 28 | int ColorPanelHSV::Show() { 29 | WITH_STATE_RENDER(int ret = ::GuiColorPanelHSV(GetBounds().GetRectangle(), text, &colorHsv)) 30 | return ret; 31 | } 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | -------------------------------------------------------------------------------- /src/raygui-cpp/ColorPicker.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ColorPicker.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ColorPicker::ColorPicker() : text(""), color({ 0, 0, 0, 0 }) {} 6 | 7 | ColorPicker::ColorPicker(const char *text, ::Color color) : text(text), color(color) {} 8 | 9 | ColorPicker::ColorPicker(Bounds bounds, const char *text, ::Color color) 10 | : Component(bounds), text(text), color(color) {} 11 | 12 | const char *ColorPicker::GetText() const { 13 | return text; 14 | } 15 | 16 | void ColorPicker::SetText(const char *newText) { 17 | this->text = newText; 18 | } 19 | 20 | ::Color ColorPicker::GetColor() const { 21 | return color; 22 | } 23 | 24 | void ColorPicker::SetColor(::Color newColor) { 25 | this->color = newColor; 26 | } 27 | 28 | int ColorPicker::Show() { 29 | WITH_STATE_RENDER(int ret = ::GuiColorPicker(GetBounds().GetRectangle(), text, &color)) 30 | return ret; 31 | } 32 | 33 | void ColorPicker::OnClick(const Callback &onClick) { 34 | SetOnClick(onClick); 35 | } 36 | 37 | void ColorPicker::OnUpdate(const Callback &onUpdate) { 38 | SetOnUpdate(onUpdate); 39 | } 40 | 41 | RAYGUI_CPP_END_NAMESPACE 42 | -------------------------------------------------------------------------------- /src/raygui-cpp/ColorPickerHSV.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ColorPickerHSV.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ColorPickerHSV::ColorPickerHSV() : text(""), colorHsv({}) {} 6 | 7 | ColorPickerHSV::ColorPickerHSV(const char *text, ::Vector3 colorHsv) : text(text), colorHsv(colorHsv) {} 8 | 9 | ColorPickerHSV::ColorPickerHSV(Bounds bounds, const char *text, ::Vector3 colorHsv) 10 | : Component(bounds), text(text), colorHsv(colorHsv) {} 11 | 12 | const char *ColorPickerHSV::GetText() const { 13 | return text; 14 | } 15 | 16 | void ColorPickerHSV::SetText(const char *newText) { 17 | this->text = newText; 18 | } 19 | 20 | ::Vector3 ColorPickerHSV::GetColorHsv() const { 21 | return colorHsv; 22 | } 23 | 24 | void ColorPickerHSV::SetColorHsv(::Vector3 newColorHsv) { 25 | this->colorHsv = newColorHsv; 26 | } 27 | 28 | int ColorPickerHSV::Show() { 29 | WITH_STATE_RENDER(int ret = ::GuiColorPickerHSV(GetBounds().GetRectangle(), text, &colorHsv)) 30 | return ret; 31 | } 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | -------------------------------------------------------------------------------- /src/raygui-cpp/ComboBox.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ComboBox.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ComboBox::ComboBox() : text(""), active(0) {} 6 | 7 | ComboBox::ComboBox(const char *text, int active) : text(text), active(active) {} 8 | 9 | ComboBox::ComboBox(Bounds bounds, const char *text, int active) : Component(bounds), text(text), active(active) {} 10 | 11 | const char *ComboBox::GetText() const { 12 | return text; 13 | } 14 | 15 | void ComboBox::SetText(const char *newText) { 16 | this->text = newText; 17 | } 18 | 19 | int ComboBox::GetActive() const { 20 | return active; 21 | } 22 | 23 | void ComboBox::SetActive(int newActive) { 24 | this->active = newActive; 25 | } 26 | 27 | int ComboBox::Show() { 28 | WITH_STATE_RENDER(int ret = ::GuiComboBox(GetBounds().GetRectangle(), text, &active)) 29 | return ret; 30 | } 31 | 32 | RAYGUI_CPP_END_NAMESPACE 33 | -------------------------------------------------------------------------------- /src/raygui-cpp/DropdownBox.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/DropdownBox.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | DropdownBox::DropdownBox() : text(""), active(nullptr), editMode(false) {} 6 | 7 | DropdownBox::DropdownBox(const char *text, int *active, bool editMode) 8 | : text(text), active(active), editMode(editMode) {} 9 | 10 | DropdownBox::DropdownBox(Bounds bounds, const char *text, int *active, bool editMode) 11 | : Component(bounds), text(text), active(active), editMode(editMode) {} 12 | 13 | const char *DropdownBox::GetText() const { 14 | return text; 15 | } 16 | 17 | void DropdownBox::SetText(const char *newText) { 18 | this->text = newText; 19 | } 20 | 21 | int *DropdownBox::GetActive() const { 22 | return active; 23 | } 24 | 25 | void DropdownBox::SetActive(int *newActive) { 26 | this->active = newActive; 27 | } 28 | 29 | bool DropdownBox::GetEditMode() const { 30 | return editMode; 31 | } 32 | 33 | void DropdownBox::SetEditMode(bool newEditMode) { 34 | this->editMode = newEditMode; 35 | } 36 | 37 | bool DropdownBox::Show() { 38 | WITH_STATE_RENDER(int dropDownClicked = ::GuiDropdownBox(GetBounds().GetRectangle(), text, active, editMode)) 39 | 40 | if (dropDownClicked && HasOnClick()) { 41 | CallOnClick(); 42 | } 43 | 44 | return dropDownClicked; 45 | } 46 | 47 | void DropdownBox::OnClick(const Component::Callback &onClick) { 48 | SetOnClick(onClick); 49 | } 50 | 51 | void DropdownBox::OnUpdate(const Component::Callback &onUpdate) { 52 | SetOnUpdate(onUpdate); 53 | } 54 | 55 | RAYGUI_CPP_END_NAMESPACE 56 | -------------------------------------------------------------------------------- /src/raygui-cpp/DummyRec.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/DummyRec.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | DummyRec::DummyRec() : text(nullptr) {} 6 | 7 | DummyRec::DummyRec(const char *text) : text(text) {} 8 | 9 | DummyRec::DummyRec(Bounds bounds, const char *text) : Component(bounds), text(text) {} 10 | 11 | const char *DummyRec::GetText() const { 12 | return text; 13 | } 14 | 15 | void DummyRec::SetText(const char *newText) { 16 | this->text = newText; 17 | } 18 | 19 | void DummyRec::Show() { WITH_STATE_RENDER(::GuiDummyRec(GetBounds().GetRectangle(), text)) } 20 | 21 | RAYGUI_CPP_END_NAMESPACE 22 | -------------------------------------------------------------------------------- /src/raygui-cpp/Globals.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Globals.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | void Globals::GuiEnable() { 6 | ::GuiEnable(); 7 | } 8 | 9 | void Globals::GuiDisable() { 10 | ::GuiDisable(); 11 | } 12 | 13 | void Globals::GuiLock() { 14 | ::GuiLock(); 15 | } 16 | 17 | void Globals::GuiUnlock() { 18 | ::GuiUnlock(); 19 | } 20 | 21 | bool Globals::GuiIsLocked() { 22 | return ::GuiIsLocked(); 23 | } 24 | 25 | void Globals::GuiSetAlpha(float alpha) { 26 | ::GuiSetAlpha(alpha); 27 | } 28 | 29 | void Globals::GuiSetState(int state) { 30 | ::GuiSetState(state); 31 | } 32 | 33 | int Globals::GuiGetState() { 34 | return ::GuiGetState(); 35 | } 36 | 37 | void Globals::Font::GuiSetFont(const ::Font &font) { 38 | ::GuiSetFont(font); 39 | } 40 | 41 | ::Font Globals::Font::GuiGetFont() { 42 | return ::GuiGetFont(); 43 | } 44 | 45 | void Globals::Style::GuiSetStyle(::GuiControl control, int property, int value) { 46 | ::GuiSetStyle(control, property, value); 47 | } 48 | 49 | int Globals::Style::GuiGetStyle(::GuiControl control, int property) { 50 | return ::GuiGetStyle(control, property); 51 | } 52 | 53 | void Globals::Style::GuiLoadStyle(const char *fileName) { 54 | ::GuiLoadStyle(fileName); 55 | } 56 | 57 | void Globals::Style::GuiLoadStyleDefault() { 58 | ::GuiLoadStyleDefault(); 59 | } 60 | 61 | void Globals::Tooltip::GuiEnableTooltip() { 62 | ::GuiEnableTooltip(); 63 | } 64 | 65 | void Globals::Tooltip::GuiDisableTooltip() { 66 | ::GuiDisableTooltip(); 67 | } 68 | 69 | void Globals::Tooltip::GuiSetTooltip(const char *tooltip) { 70 | ::GuiSetTooltip(tooltip); 71 | } 72 | 73 | const char *Globals::Icon::GuiIconText(int iconId, const char *text) { 74 | return ::GuiIconText(iconId, text); 75 | } 76 | 77 | #if !defined(RAYGUI_NO_ICONS) 78 | void Globals::Icon::GuiSetIconScale(int scale) { 79 | ::GuiSetIconScale(scale); 80 | } 81 | 82 | unsigned int *Globals::Icon::GuiGetIcons() { 83 | return ::GuiGetIcons(); 84 | } 85 | 86 | char **Globals::Icon::GuiLoadIcons(const char *fileName, bool loadIconsName) { 87 | return ::GuiLoadIcons(fileName, loadIconsName); 88 | } 89 | 90 | void Globals::Icon::GuiDrawIcon(int iconId, int posX, int posY, int pixelSize, ::Color color) { 91 | ::GuiDrawIcon(iconId, posX, posY, pixelSize, color); 92 | } 93 | #endif 94 | 95 | RAYGUI_CPP_END_NAMESPACE 96 | -------------------------------------------------------------------------------- /src/raygui-cpp/Grid.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Grid.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | Grid::Grid() : text(nullptr), spacing(0), subdivisions(0), mouseCell({}) {} 6 | 7 | Grid::Grid(const char *text, float spacing, int subdivisions, Vector2 mouseCell) 8 | : text(text), spacing(spacing), subdivisions(subdivisions), mouseCell(mouseCell) {} 9 | 10 | Grid::Grid(Bounds bounds, const char *text, float spacing, int subdivisions, Vector2 mouseCell) 11 | : Component(bounds), text(text), spacing(spacing), subdivisions(subdivisions), mouseCell(mouseCell) {} 12 | 13 | const char *Grid::GetText() const { 14 | return text; 15 | } 16 | 17 | void Grid::SetText(const char *newText) { 18 | this->text = newText; 19 | } 20 | 21 | float Grid::GetSpacing() const { 22 | return spacing; 23 | } 24 | 25 | void Grid::SetSpacing(float newSpacing) { 26 | this->spacing = newSpacing; 27 | } 28 | 29 | int Grid::GetSubdivisions() const { 30 | return subdivisions; 31 | } 32 | 33 | void Grid::SetSubdivisions(int newSubdivisions) { 34 | this->subdivisions = newSubdivisions; 35 | } 36 | 37 | Vector2 Grid::GetMouseCell() const { 38 | return mouseCell; 39 | } 40 | 41 | void Grid::SetMouseCell(Vector2 newMouseCell) { 42 | this->mouseCell = newMouseCell; 43 | } 44 | 45 | int Grid::Show() { 46 | WITH_STATE_RENDER(int ret = ::GuiGrid(GetBounds().GetRectangle(), text, spacing, subdivisions, &mouseCell)) 47 | return ret; 48 | } 49 | 50 | RAYGUI_CPP_END_NAMESPACE 51 | -------------------------------------------------------------------------------- /src/raygui-cpp/GroupBox.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/GroupBox.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | GroupBox::GroupBox() : text("") {} 6 | 7 | GroupBox::GroupBox(const char *text) : text(text) {} 8 | 9 | GroupBox::GroupBox(Bounds bounds, const char *text) : Component(bounds), text(text) {} 10 | 11 | const char *GroupBox::GetText() const { 12 | return text; 13 | } 14 | 15 | void GroupBox::SetText(const char *newText) { 16 | this->text = newText; 17 | } 18 | 19 | void GroupBox::Show() { WITH_STATE_RENDER(::GuiGroupBox(GetBounds().GetRectangle(), text)) } 20 | 21 | RAYGUI_CPP_END_NAMESPACE 22 | -------------------------------------------------------------------------------- /src/raygui-cpp/Label.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Label.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | Label::Label() : text("") {} 6 | 7 | Label::Label(const char *text) : text(text) {} 8 | 9 | Label::Label(Bounds bounds, const char *text) : Component(bounds), text(text) {} 10 | 11 | const char *Label::GetText() const { 12 | return text; 13 | } 14 | 15 | void Label::SetText(const char *newText) { 16 | this->text = newText; 17 | } 18 | 19 | void Label::Show() { 20 | WITH_STATE_RENDER(::GuiLabel(GetBounds().GetRectangle(), text)) 21 | } 22 | 23 | void Label::SetPropertyColor(const GuiControlProperty property, const Color color) { 24 | AddProperty(LABEL, property, color); 25 | } 26 | 27 | RAYGUI_CPP_END_NAMESPACE 28 | -------------------------------------------------------------------------------- /src/raygui-cpp/LabelButton.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/LabelButton.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | LabelButton::LabelButton() : text("") {} 6 | 7 | LabelButton::LabelButton(const char *text) : text(text) {} 8 | 9 | LabelButton::LabelButton(Bounds bounds, const char *text) : Component(bounds), text(text) {} 10 | 11 | const char *LabelButton::GetText() const { 12 | return text; 13 | } 14 | 15 | void LabelButton::SetText(const char *newText) { 16 | this->text = newText; 17 | } 18 | 19 | bool LabelButton::Show() { 20 | WITH_STATE_RENDER(int ret = ::GuiLabelButton(GetBounds().GetRectangle(), text)) 21 | return ret; 22 | } 23 | 24 | void LabelButton::SetPropertyColor(const GuiControlProperty property, const Color color) { 25 | AddProperty(LABEL, property, color); 26 | } 27 | 28 | RAYGUI_CPP_END_NAMESPACE 29 | -------------------------------------------------------------------------------- /src/raygui-cpp/Line.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Line.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | Line::Line() : text(nullptr) {} 6 | 7 | Line::Line(const char *text) : text(text) {} 8 | 9 | Line::Line(Bounds bounds, const char *text) : Component(bounds), text(text) {} 10 | 11 | const char *Line::GetText() const { 12 | return text; 13 | } 14 | 15 | void Line::SetText(const char *newText) { 16 | text = newText; 17 | } 18 | 19 | void Line::Show() { WITH_STATE_RENDER(::GuiLine(GetBounds().GetRectangle(), text)) } 20 | 21 | RAYGUI_CPP_END_NAMESPACE 22 | -------------------------------------------------------------------------------- /src/raygui-cpp/ListView.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ListView.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ListView::ListView() : text(""), scrollIndex(nullptr), active(0) {} 6 | 7 | ListView::ListView(const char *text, int *scrollIndex, int active) 8 | : text(text), scrollIndex(scrollIndex), active(active) {} 9 | 10 | ListView::ListView(Bounds bounds, const char *text, int *scrollIndex, int active) 11 | : Component(bounds), text(text), scrollIndex(scrollIndex), active(active) {} 12 | 13 | const char *ListView::GetText() const { 14 | return text; 15 | } 16 | 17 | void ListView::SetText(const char *newText) { 18 | this->text = newText; 19 | } 20 | 21 | int *ListView::GetScrollIndex() const { 22 | return scrollIndex; 23 | } 24 | 25 | void ListView::SetScrollIndex(int *newScrollIndex) { 26 | this->scrollIndex = newScrollIndex; 27 | } 28 | 29 | int ListView::GetActive() const { 30 | return active; 31 | } 32 | 33 | void ListView::SetActive(int newActive) { 34 | this->active = newActive; 35 | } 36 | 37 | int ListView::Show() { 38 | WITH_STATE_RENDER(int ret = ::GuiListView(GetBounds().GetRectangle(), text, scrollIndex, &active)) 39 | return ret; 40 | } 41 | 42 | RAYGUI_CPP_END_NAMESPACE 43 | -------------------------------------------------------------------------------- /src/raygui-cpp/ListViewEx.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ListViewEx.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ListViewEx::ListViewEx() : text(nullptr), count(0), focus(nullptr), scrollIndex(nullptr), active(0) {} 6 | 7 | ListViewEx::ListViewEx(const char **text, int count, int *focus, int *scrollIndex, int active) 8 | : text(text), count(count), focus(focus), scrollIndex(scrollIndex), active(active) {} 9 | 10 | ListViewEx::ListViewEx(Bounds bounds, const char **text, int count, int *focus, int *scrollIndex, int active) 11 | : Component(bounds), text(text), count(count), focus(focus), scrollIndex(scrollIndex), active(active) {} 12 | 13 | const char **ListViewEx::GetText() const { 14 | return text; 15 | } 16 | 17 | void ListViewEx::SetText(const char **newText) { 18 | this->text = newText; 19 | } 20 | 21 | int ListViewEx::GetCount() const { 22 | return count; 23 | } 24 | 25 | void ListViewEx::SetCount(int newCount) { 26 | this->count = newCount; 27 | } 28 | 29 | int *ListViewEx::GetFocus() const { 30 | return focus; 31 | } 32 | 33 | void ListViewEx::SetFocus(int *newFocus) { 34 | this->focus = newFocus; 35 | } 36 | 37 | int *ListViewEx::GetScrollIndex() const { 38 | return scrollIndex; 39 | } 40 | 41 | void ListViewEx::SetScrollIndex(int *newScrollIndex) { 42 | this->scrollIndex = newScrollIndex; 43 | } 44 | 45 | int ListViewEx::GetActive() const { 46 | return active; 47 | } 48 | 49 | void ListViewEx::SetActive(int newActive) { 50 | this->active = newActive; 51 | } 52 | 53 | int ListViewEx::Show() { 54 | WITH_STATE_RENDER(int ret = ::GuiListViewEx(GetBounds().GetRectangle(), text, count, scrollIndex, &active, focus)) 55 | return ret; 56 | } 57 | 58 | RAYGUI_CPP_END_NAMESPACE 59 | -------------------------------------------------------------------------------- /src/raygui-cpp/MessageBox.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/MessageBox.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | MessageBox::MessageBox() : title(""), message(""), buttons("") {} 6 | 7 | MessageBox::MessageBox(const char *title, const char *message, const char *buttons) 8 | : title(title), message(message), buttons(buttons) {} 9 | 10 | MessageBox::MessageBox(Bounds bounds, const char *title, const char *message, const char *buttons) 11 | : Component(bounds), title(title), message(message), buttons(buttons) {} 12 | 13 | const char *MessageBox::GetTitle() const { 14 | return title; 15 | } 16 | 17 | void MessageBox::SetTitle(const char *newTitle) { 18 | this->title = newTitle; 19 | } 20 | 21 | const char *MessageBox::GetMessage() const { 22 | return message; 23 | } 24 | 25 | void MessageBox::SetMessage(const char *newMessage) { 26 | this->message = newMessage; 27 | } 28 | 29 | const char *MessageBox::GetButtons() const { 30 | return buttons; 31 | } 32 | 33 | void MessageBox::SetButtons(const char *newButtons) { 34 | this->buttons = newButtons; 35 | } 36 | 37 | int MessageBox::Show() { 38 | WITH_STATE_RENDER(int ret = ::GuiMessageBox(GetBounds().GetRectangle(), title, message, buttons)) 39 | return ret; 40 | } 41 | 42 | RAYGUI_CPP_END_NAMESPACE 43 | -------------------------------------------------------------------------------- /src/raygui-cpp/Paintable.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Paintable.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | void Paintable::SetBaseColor(const Color color) { 6 | SetPropertyColor(BASE_COLOR_NORMAL, color); 7 | } 8 | 9 | void Paintable::SetTextColor(const Color color) { 10 | SetPropertyColor(TEXT_COLOR_NORMAL, color); 11 | } 12 | 13 | void Paintable::SetBorderColor(const Color color) { 14 | SetPropertyColor(BORDER_COLOR_NORMAL, color); 15 | } 16 | 17 | void Paintable::PreRender() const { 18 | for (auto const &[control, properties]: m_properties) { 19 | for (auto prop: properties) { 20 | prop.SetPrevious(GetColor(GuiGetStyle(control, prop.property))); 21 | GuiSetStyle(control, prop.property, ColorToInt(prop.current)); 22 | } 23 | } 24 | } 25 | 26 | void Paintable::PostRender() const { 27 | for (auto const &[control, properties]: m_properties) { 28 | for (const auto &prop: properties) { 29 | GuiSetStyle(control, prop.property, ColorToInt(prop.previous)); 30 | } 31 | } 32 | } 33 | 34 | void Paintable::AddProperty(const GuiControl control, const GuiControlProperty property, const Color &color) { 35 | m_properties[control].push_back( 36 | { .property = property, .previous = GetColor(GuiGetStyle(control, property)), .current = color }); 37 | } 38 | 39 | RAYGUI_CPP_END_NAMESPACE 40 | -------------------------------------------------------------------------------- /src/raygui-cpp/Panel.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Panel.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | Panel::Panel() : text("") {} 6 | 7 | Panel::Panel(const char *text) : text(text) {} 8 | 9 | Panel::Panel(Bounds bounds, const char *text) : Component(bounds), text(text) {} 10 | 11 | const char *Panel::GetText() const { 12 | return text; 13 | } 14 | 15 | void Panel::SetText(const char *newText) { 16 | this->text = newText; 17 | } 18 | 19 | void Panel::Show() { 20 | WITH_STATE_RENDER(::GuiPanel(GetBounds().GetRectangle(), text)) 21 | 22 | this->ShowChildren(); 23 | } 24 | 25 | void Panel::AddChild(Component *child) { 26 | this->AddChildInternal(child); 27 | } 28 | 29 | RAYGUI_CPP_END_NAMESPACE 30 | -------------------------------------------------------------------------------- /src/raygui-cpp/ProgressBar.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ProgressBar.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ProgressBar::ProgressBar() : textLeft(nullptr), textRight(nullptr), value(0), minValue(0), maxValue(0) {} 6 | 7 | ProgressBar::ProgressBar(const char *textLeft, const char *textRight, float value, float minValue, float maxValue) 8 | : textLeft(textLeft), textRight(textRight), value(value), minValue(minValue), maxValue(maxValue) {} 9 | 10 | ProgressBar::ProgressBar(Bounds bounds, const char *textLeft, const char *textRight, float value, float minValue, 11 | float maxValue) 12 | : Component(bounds), textLeft(textLeft), textRight(textRight), value(value), minValue(minValue), 13 | maxValue(maxValue) {} 14 | 15 | const char *ProgressBar::GetTextLeft() const { 16 | return textLeft; 17 | } 18 | 19 | void ProgressBar::SetTextLeft(const char *newTextLeft) { 20 | this->textLeft = newTextLeft; 21 | } 22 | 23 | const char *ProgressBar::GetTextRight() const { 24 | return textRight; 25 | } 26 | 27 | void ProgressBar::SetTextRight(const char *newTextRight) { 28 | this->textRight = newTextRight; 29 | } 30 | 31 | float ProgressBar::GetValue() const { 32 | return value; 33 | } 34 | 35 | void ProgressBar::SetValue(float newValue) { 36 | this->value = newValue; 37 | } 38 | 39 | float ProgressBar::GetMinValue() const { 40 | return minValue; 41 | } 42 | 43 | void ProgressBar::SetMinValue(float newMinValue) { 44 | this->minValue = newMinValue; 45 | } 46 | 47 | float ProgressBar::GetMaxValue() const { 48 | return maxValue; 49 | } 50 | 51 | void ProgressBar::SetMaxValue(float newMaxValue) { 52 | this->maxValue = newMaxValue; 53 | } 54 | 55 | int ProgressBar::Show() { 56 | WITH_STATE_RENDER( 57 | int ret = ::GuiProgressBar(GetBounds().GetRectangle(), textLeft, textRight, &value, minValue, maxValue)) 58 | return ret; 59 | } 60 | 61 | void ProgressBar::SetPropertyColor(const GuiControlProperty property, const Color color) { 62 | AddProperty(PROGRESSBAR, property, color); 63 | } 64 | 65 | RAYGUI_CPP_END_NAMESPACE 66 | -------------------------------------------------------------------------------- /src/raygui-cpp/ScrollPanel.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ScrollPanel.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ScrollPanel::ScrollPanel() : text(""), content({ 0, 0, 0, 0 }), scroll({}), view({}) {} 6 | 7 | ScrollPanel::ScrollPanel(const char *text, ::Rectangle content, ::Vector2 scroll, ::Rectangle view) 8 | : text(text), content(content), scroll(scroll), view(view) {} 9 | 10 | ScrollPanel::ScrollPanel(Bounds bounds, const char *text, ::Rectangle content, ::Vector2 scroll, ::Rectangle view) 11 | : Component(bounds), text(text), content(content), scroll(scroll), view(view) {} 12 | 13 | const char *ScrollPanel::GetText() const { 14 | return text; 15 | } 16 | 17 | void ScrollPanel::SetText(const char *newText) { 18 | this->text = newText; 19 | } 20 | 21 | ::Rectangle ScrollPanel::GetContent() const { 22 | return content; 23 | } 24 | 25 | void ScrollPanel::SetContent(::Rectangle newContent) { 26 | this->content = newContent; 27 | } 28 | 29 | ::Vector2 ScrollPanel::GetScroll() const { 30 | return scroll; 31 | } 32 | 33 | void ScrollPanel::SetScroll(::Vector2 newScroll) { 34 | this->scroll = newScroll; 35 | } 36 | 37 | ::Rectangle ScrollPanel::GetView() const { 38 | return view; 39 | } 40 | 41 | void ScrollPanel::SetView(::Rectangle newView) { 42 | this->view = newView; 43 | } 44 | 45 | int ScrollPanel::Show() { 46 | WITH_STATE_RENDER(int ret = ::GuiScrollPanel(GetBounds().GetRectangle(), text, content, &scroll, &view)) 47 | return ret; 48 | } 49 | 50 | RAYGUI_CPP_END_NAMESPACE 51 | -------------------------------------------------------------------------------- /src/raygui-cpp/Slider.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Slider.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | Slider::Slider() : textLeft(""), textRight(""), value(0), minValue(0), maxValue(0) {} 6 | 7 | Slider::Slider(const char *textLeft, const char *textRight, float value, float minValue, float maxValue) 8 | : textLeft(textLeft), textRight(textRight), value(value), minValue(minValue), maxValue(maxValue) {} 9 | 10 | Slider::Slider(Bounds bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue) 11 | : Component(bounds), textLeft(textLeft), textRight(textRight), value(value), minValue(minValue), 12 | maxValue(maxValue) {} 13 | 14 | const char *Slider::GetTextLeft() const { 15 | return textLeft; 16 | } 17 | 18 | void Slider::SetTextLeft(const char *newTextLeft) { 19 | this->textLeft = newTextLeft; 20 | } 21 | 22 | const char *Slider::GetTextRight() const { 23 | return textRight; 24 | } 25 | 26 | void Slider::SetTextRight(const char *newTextRight) { 27 | this->textRight = newTextRight; 28 | } 29 | 30 | float Slider::GetValue() const { 31 | return value; 32 | } 33 | 34 | void Slider::SetValue(float newValue) { 35 | this->value = newValue; 36 | } 37 | 38 | float Slider::GetMinValue() const { 39 | return minValue; 40 | } 41 | 42 | void Slider::SetMinValue(float newMinValue) { 43 | this->minValue = newMinValue; 44 | } 45 | 46 | float Slider::GetMaxValue() const { 47 | return maxValue; 48 | } 49 | 50 | void Slider::SetMaxValue(float newMaxValue) { 51 | this->maxValue = newMaxValue; 52 | } 53 | 54 | int Slider::Show() { 55 | WITH_STATE_RENDER(int ret = 56 | ::GuiSlider(GetBounds().GetRectangle(), textLeft, textRight, &value, minValue, maxValue)) 57 | return ret; 58 | } 59 | 60 | RAYGUI_CPP_END_NAMESPACE 61 | -------------------------------------------------------------------------------- /src/raygui-cpp/SliderBar.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/SliderBar.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | SliderBar::SliderBar() : textLeft(""), textRight(""), value(0), minValue(0), maxValue(0) {} 6 | 7 | SliderBar::SliderBar(const char *textLeft, const char *textRight, float value, float minValue, float maxValue) 8 | : textLeft(textLeft), textRight(textRight), value(value), minValue(minValue), maxValue(maxValue) {} 9 | 10 | SliderBar::SliderBar(Bounds bounds, const char *textLeft, const char *textRight, float value, float minValue, 11 | float maxValue) 12 | : Component(bounds), textLeft(textLeft), textRight(textRight), value(value), minValue(minValue), 13 | maxValue(maxValue) {} 14 | 15 | const char *SliderBar::GetTextLeft() const { 16 | return textLeft; 17 | } 18 | 19 | void SliderBar::SetTextLeft(const char *newTextLeft) { 20 | this->textLeft = newTextLeft; 21 | } 22 | 23 | const char *SliderBar::GetTextRight() const { 24 | return textRight; 25 | } 26 | 27 | void SliderBar::SetTextRight(const char *newTextRight) { 28 | this->textRight = newTextRight; 29 | } 30 | 31 | float SliderBar::GetValue() const { 32 | return value; 33 | } 34 | 35 | void SliderBar::SetValue(float newValue) { 36 | this->value = newValue; 37 | } 38 | 39 | float SliderBar::GetMinValue() const { 40 | return minValue; 41 | } 42 | 43 | void SliderBar::SetMinValue(float newMinValue) { 44 | this->minValue = newMinValue; 45 | } 46 | 47 | float SliderBar::GetMaxValue() const { 48 | return maxValue; 49 | } 50 | 51 | void SliderBar::SetMaxValue(float newMaxValue) { 52 | this->maxValue = newMaxValue; 53 | } 54 | 55 | int SliderBar::Show() { 56 | WITH_STATE_RENDER( 57 | int ret = ::GuiSliderBar(GetBounds().GetRectangle(), textLeft, textRight, &value, minValue, maxValue)) 58 | return ret; 59 | } 60 | 61 | RAYGUI_CPP_END_NAMESPACE 62 | -------------------------------------------------------------------------------- /src/raygui-cpp/Spinner.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Spinner.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | Spinner::Spinner() : text(""), value(nullptr), minValue(0), maxValue(0), editMode(false) {} 6 | 7 | Spinner::Spinner(const char *text, int *value, int minValue, int maxValue, bool editMode) 8 | : text(text), value(value), minValue(minValue), maxValue(maxValue), editMode(editMode) {} 9 | 10 | Spinner::Spinner(Bounds bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) 11 | : Component(bounds), text(text), value(value), minValue(minValue), maxValue(maxValue), editMode(editMode) {} 12 | 13 | const char *Spinner::GetText() const { 14 | return text; 15 | } 16 | 17 | void Spinner::SetText(const char *newText) { 18 | this->text = newText; 19 | } 20 | 21 | int *Spinner::GetValue() const { 22 | return value; 23 | } 24 | 25 | void Spinner::SetValue(int *newValue) { 26 | this->value = newValue; 27 | } 28 | 29 | int Spinner::GetMinValue() const { 30 | return minValue; 31 | } 32 | 33 | void Spinner::SetMinValue(int newMinValue) { 34 | this->minValue = newMinValue; 35 | } 36 | 37 | int Spinner::GetMaxValue() const { 38 | return maxValue; 39 | } 40 | 41 | void Spinner::SetMaxValue(int newMaxValue) { 42 | this->maxValue = newMaxValue; 43 | } 44 | 45 | bool Spinner::IsEditMode() const { 46 | return editMode; 47 | } 48 | 49 | void Spinner::SetEditMode(bool newEditMode) { 50 | this->editMode = newEditMode; 51 | } 52 | 53 | bool Spinner::Show() { 54 | WITH_STATE_RENDER(int ret = ::GuiSpinner(GetBounds().GetRectangle(), text, value, minValue, maxValue, editMode)) 55 | return ret; 56 | } 57 | 58 | RAYGUI_CPP_END_NAMESPACE 59 | -------------------------------------------------------------------------------- /src/raygui-cpp/StatusBar.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/StatusBar.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | StatusBar::StatusBar() : text(nullptr) {} 6 | 7 | StatusBar::StatusBar(const char *text) : text(text) {} 8 | 9 | StatusBar::StatusBar(Bounds bounds, const char *text) : Component(bounds), text(text) {} 10 | 11 | const char *StatusBar::GetText() const { 12 | return text; 13 | } 14 | 15 | void StatusBar::SetText(const char *newText) { 16 | this->text = newText; 17 | } 18 | 19 | void StatusBar::Show() { WITH_STATE_RENDER(::GuiStatusBar(GetBounds().GetRectangle(), text)) } 20 | 21 | RAYGUI_CPP_END_NAMESPACE 22 | -------------------------------------------------------------------------------- /src/raygui-cpp/Style.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Style.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | Style::Style() : m_position(Position::NONE), m_margin({ 0, 0 }) {} 6 | 7 | Style::Style(Position position) : m_position(position), m_margin({ 0, 0 }) {} 8 | 9 | Style::Style(Position position, Margin margin) : m_position(position), m_margin(margin) {} 10 | 11 | Style::Style(Position position, float margin) : m_position(position), m_margin({ margin, margin }) {} 12 | 13 | Style::Style(Position position, float horizontalMargin, float verticalMargin) 14 | : m_position(position), m_margin({ horizontalMargin, verticalMargin }) {} 15 | 16 | Style::Position Style::GetPosition() const { 17 | return m_position; 18 | } 19 | 20 | Margin Style::GetMargin() const { 21 | return m_margin; 22 | } 23 | 24 | RAYGUI_CPP_END_NAMESPACE 25 | -------------------------------------------------------------------------------- /src/raygui-cpp/TabBar.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/TabBar.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | TabBar::TabBar() : text(nullptr), count(0), active(nullptr) {} 6 | 7 | TabBar::TabBar(const char **text, int count, int *active) : text(text), count(count), active(active) {} 8 | 9 | TabBar::TabBar(Bounds bounds, const char **text, int count, int *active) 10 | : Component(bounds), text(text), count(count), active(active) {} 11 | 12 | const char **TabBar::GetText() const { 13 | return text; 14 | } 15 | 16 | void TabBar::SetText(const char **newText) { 17 | this->text = newText; 18 | } 19 | 20 | int TabBar::GetCount() const { 21 | return count; 22 | } 23 | 24 | void TabBar::SetCount(int newCount) { 25 | this->count = newCount; 26 | } 27 | 28 | int *TabBar::GetActive() const { 29 | return active; 30 | } 31 | 32 | void TabBar::SetActive(int *newActive) { 33 | this->active = newActive; 34 | } 35 | 36 | int TabBar::Show() { 37 | WITH_STATE_RENDER(int ret = ::GuiTabBar(GetBounds().GetRectangle(), text, count, active)) 38 | return ret; 39 | } 40 | 41 | RAYGUI_CPP_END_NAMESPACE 42 | -------------------------------------------------------------------------------- /src/raygui-cpp/TextBox.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/TextBox.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | TextBox::TextBox() : text(nullptr), textSize(0), editMode(false) {} 6 | 7 | TextBox::TextBox(char *text, int textSize, bool editMode) : text(text), textSize(textSize), editMode(editMode) {} 8 | 9 | TextBox::TextBox(Bounds bounds, char *text, int textSize, bool editMode) 10 | : Component(bounds), text(text), textSize(textSize), editMode(editMode) {} 11 | 12 | const char *TextBox::GetText() const { 13 | return text; 14 | } 15 | 16 | void TextBox::SetText(char *newText) { 17 | this->text = newText; 18 | } 19 | 20 | int TextBox::GetTextSize() const { 21 | return textSize; 22 | } 23 | 24 | void TextBox::SetTextSize(int newTextSize) { 25 | this->textSize = newTextSize; 26 | } 27 | 28 | bool TextBox::GetEditMode() const { 29 | return editMode; 30 | } 31 | 32 | void TextBox::SetEditMode(bool newEditMode) { 33 | this->editMode = newEditMode; 34 | } 35 | 36 | bool TextBox::Show() { 37 | WITH_STATE_RENDER(int ret = ::GuiTextBox(GetBounds().GetRectangle(), text, textSize, editMode)) 38 | return ret; 39 | } 40 | 41 | void TextBox::SetPropertyColor(const GuiControlProperty property, const Color color) { 42 | AddProperty(TEXTBOX, property, color); 43 | } 44 | 45 | RAYGUI_CPP_END_NAMESPACE 46 | -------------------------------------------------------------------------------- /src/raygui-cpp/TextInputBox.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/TextInputBox.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | TextInputBox::TextInputBox() 6 | : title(""), message(""), buttons(""), text(nullptr), textMaxSize(0), secretViewActive(false) {} 7 | 8 | TextInputBox::TextInputBox(const char *title, const char *message, const char *buttons, char *text, int textMaxSize, 9 | bool secretViewActive) 10 | : title(title), message(message), buttons(buttons), text(text), textMaxSize(textMaxSize), 11 | secretViewActive(secretViewActive) {} 12 | 13 | TextInputBox::TextInputBox(Bounds bounds, const char *title, const char *message, const char *buttons, char *text, 14 | int textMaxSize, bool secretViewActive) 15 | : Component(bounds), title(title), message(message), buttons(buttons), text(text), textMaxSize(textMaxSize), 16 | secretViewActive(secretViewActive) {} 17 | 18 | const char *TextInputBox::GetTitle() const { 19 | return title; 20 | } 21 | 22 | void TextInputBox::SetTitle(const char *newTitle) { 23 | this->title = newTitle; 24 | } 25 | 26 | const char *TextInputBox::GetMessage() const { 27 | return message; 28 | } 29 | 30 | void TextInputBox::SetMessage(const char *newMessage) { 31 | this->message = newMessage; 32 | } 33 | 34 | const char *TextInputBox::GetButtons() const { 35 | return buttons; 36 | } 37 | 38 | void TextInputBox::SetButtons(const char *newButtons) { 39 | this->buttons = newButtons; 40 | } 41 | 42 | char *TextInputBox::GetText() const { 43 | return text; 44 | } 45 | 46 | void TextInputBox::SetText(char *newText) { 47 | this->text = newText; 48 | } 49 | 50 | int TextInputBox::GetTextMaxSize() const { 51 | return textMaxSize; 52 | } 53 | 54 | void TextInputBox::SetTextMaxSize(int newTextMaxSize) { 55 | this->textMaxSize = newTextMaxSize; 56 | } 57 | 58 | bool TextInputBox::GetSecretViewActive() const { 59 | return secretViewActive; 60 | } 61 | 62 | void TextInputBox::SetSecretViewActive(bool newSecretViewActive) { 63 | this->secretViewActive = newSecretViewActive; 64 | } 65 | 66 | int TextInputBox::Show() { 67 | WITH_STATE_RENDER(int ret = ::GuiTextInputBox(GetBounds().GetRectangle(), title, message, buttons, text, 68 | textMaxSize, &secretViewActive)) 69 | return ret; 70 | } 71 | 72 | RAYGUI_CPP_END_NAMESPACE 73 | -------------------------------------------------------------------------------- /src/raygui-cpp/Toggle.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/Toggle.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | Toggle::Toggle() : text(""), active(false) {} 6 | 7 | Toggle::Toggle(const char *text, bool active) : text(text), active(active) {} 8 | 9 | Toggle::Toggle(Bounds bounds, const char *text, bool active) : Component(bounds), text(text), active(active) {} 10 | 11 | const char *Toggle::GetText() const { 12 | return text; 13 | } 14 | 15 | void Toggle::SetText(const char *newText) { 16 | this->text = newText; 17 | } 18 | 19 | bool Toggle::IsActive() const { 20 | return active; 21 | } 22 | 23 | void Toggle::SetActive(bool newActive) { 24 | this->active = newActive; 25 | } 26 | 27 | bool Toggle::Show() { 28 | WITH_STATE_RENDER(int ret = ::GuiToggle(GetBounds().GetRectangle(), text, &active)) 29 | return ret; 30 | } 31 | 32 | RAYGUI_CPP_END_NAMESPACE 33 | -------------------------------------------------------------------------------- /src/raygui-cpp/ToggleGroup.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ToggleGroup.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ToggleGroup::ToggleGroup() : text(""), active(0) {} 6 | 7 | ToggleGroup::ToggleGroup(const char *text, int active) : text(text), active(active) {} 8 | 9 | ToggleGroup::ToggleGroup(Bounds bounds, const char *text, int active) 10 | : Component(bounds), text(text), active(active) {} 11 | 12 | const char *ToggleGroup::GetText() const { 13 | return text; 14 | } 15 | 16 | void ToggleGroup::SetText(const char *newText) { 17 | this->text = newText; 18 | } 19 | 20 | int ToggleGroup::GetActive() const { 21 | return active; 22 | } 23 | 24 | void ToggleGroup::SetActive(int newActive) { 25 | this->active = newActive; 26 | } 27 | 28 | int ToggleGroup::Show() { 29 | WITH_STATE_RENDER(int ret = ::GuiToggleGroup(GetBounds().GetRectangle(), text, &active)) 30 | return ret; 31 | } 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | -------------------------------------------------------------------------------- /src/raygui-cpp/ToggleSlider.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ToggleSlider.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ToggleSlider::ToggleSlider() : text(""), active(0) {} 6 | 7 | ToggleSlider::ToggleSlider(const char *text, int active) : text(text), active(active) {} 8 | 9 | ToggleSlider::ToggleSlider(Bounds bounds, const char *text, int active) 10 | : Component(bounds), text(text), active(active) {} 11 | 12 | const char *ToggleSlider::GetText() const { 13 | return text; 14 | } 15 | 16 | void ToggleSlider::SetText(const char *newText) { 17 | this->text = newText; 18 | } 19 | 20 | int ToggleSlider::GetActive() const { 21 | return active; 22 | } 23 | 24 | void ToggleSlider::SetActive(int newActive) { 25 | this->active = newActive; 26 | } 27 | 28 | int ToggleSlider::Show() { 29 | WITH_STATE_RENDER(int ret = ::GuiToggleSlider(GetBounds().GetRectangle(), text, &active)) 30 | return ret; 31 | } 32 | 33 | RAYGUI_CPP_END_NAMESPACE 34 | -------------------------------------------------------------------------------- /src/raygui-cpp/ValueBox.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/ValueBox.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ValueBox::ValueBox() : text(""), value(nullptr), minValue(0), maxValue(0), editMode(false) {} 6 | 7 | ValueBox::ValueBox(const char *text, int *value, int minValue, int maxValue, bool editMode) 8 | : text(text), value(value), minValue(minValue), maxValue(maxValue), editMode(editMode) {} 9 | 10 | ValueBox::ValueBox(Bounds bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) 11 | : Component(bounds), text(text), value(value), minValue(minValue), maxValue(maxValue), editMode(editMode) {} 12 | 13 | const char *ValueBox::GetText() const { 14 | return text; 15 | } 16 | 17 | void ValueBox::SetText(const char *newText) { 18 | this->text = newText; 19 | } 20 | 21 | int *ValueBox::GetValue() const { 22 | return value; 23 | } 24 | 25 | void ValueBox::SetValue(int *newValue) { 26 | this->value = newValue; 27 | } 28 | 29 | int ValueBox::GetMinValue() const { 30 | return minValue; 31 | } 32 | 33 | void ValueBox::SetMinValue(int newMinValue) { 34 | this->minValue = newMinValue; 35 | } 36 | 37 | int ValueBox::GetMaxValue() const { 38 | return maxValue; 39 | } 40 | 41 | void ValueBox::SetMaxValue(int newMaxValue) { 42 | this->maxValue = newMaxValue; 43 | } 44 | 45 | bool ValueBox::IsEditMode() const { 46 | return editMode; 47 | } 48 | 49 | void ValueBox::SetEditMode(bool newEditMode) { 50 | this->editMode = newEditMode; 51 | } 52 | 53 | bool ValueBox::Show() { 54 | WITH_STATE_RENDER(int ret = ::GuiValueBox(GetBounds().GetRectangle(), text, value, minValue, maxValue, editMode)) 55 | return ret; 56 | } 57 | 58 | RAYGUI_CPP_END_NAMESPACE 59 | -------------------------------------------------------------------------------- /src/raygui-cpp/WindowBox.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/WindowBox.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | WindowBox::WindowBox() : title(nullptr) {} 6 | 7 | WindowBox::WindowBox(const char *title) : title(title) {} 8 | 9 | WindowBox::WindowBox(Bounds bounds, const char *title) : Component(bounds), title(title) {} 10 | 11 | const char *WindowBox::GetTitle() const { 12 | return title; 13 | } 14 | 15 | void WindowBox::SetTitle(const char *newTitle) { 16 | this->title = newTitle; 17 | } 18 | 19 | bool WindowBox::Show() { 20 | WITH_STATE_RENDER(int ret = ::GuiWindowBox(GetBounds().GetRectangle(), title)) 21 | 22 | this->ShowChildren(); 23 | 24 | return ret; 25 | } 26 | 27 | void WindowBox::AddChild(Component *child) { 28 | this->AddChildInternal(child); 29 | } 30 | 31 | RAYGUI_CPP_END_NAMESPACE 32 | -------------------------------------------------------------------------------- /src/raygui-cpp/extras/ImageButton.cpp: -------------------------------------------------------------------------------- 1 | #include "raygui-cpp/extras/ImageButton.h" 2 | 3 | RAYGUI_CPP_BEGIN_NAMESPACE 4 | 5 | ImageButton::ImageButton() : texture({}) {} 6 | 7 | ImageButton::ImageButton(Bounds bounds, Texture2D texture) : Component(bounds), texture(texture) {} 8 | 9 | Texture2D ImageButton::GetTexture() const { 10 | return texture; 11 | } 12 | 13 | void ImageButton::SetTexture(Texture2D newTexture) { 14 | this->texture = newTexture; 15 | } 16 | 17 | bool ImageButton::Show() { 18 | Rectangle textureSource = { 0, 0, (float) texture.width, (float) texture.height }; 19 | 20 | int state = GuiGetState(); 21 | bool clicked = false; 22 | 23 | if (state != STATE_DISABLED) { 24 | Vector2 mousePoint = GetMousePosition(); 25 | Rectangle bounds = GetBounds().GetRectangle(); 26 | 27 | if (CheckCollisionPointRec(mousePoint, bounds)) { 28 | if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) { 29 | state = STATE_PRESSED; 30 | } else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) { 31 | clicked = true; 32 | } else { 33 | state = STATE_FOCUSED; 34 | } 35 | } 36 | } 37 | 38 | // Draw only the texture if it's valid 39 | if (texture.id > 0) { 40 | DrawTexturePro(texture, textureSource, GetBounds().GetRectangle(), { 0, 0 }, 0.0f, WHITE); 41 | } 42 | 43 | if (clicked && HasOnClick()) { 44 | CallOnClick(); 45 | } 46 | 47 | return clicked; 48 | } 49 | 50 | void ImageButton::OnClick(const Component::Callback &onClick) { 51 | SetOnClick(onClick); 52 | } 53 | 54 | void ImageButton::OnUpdate(const Component::Callback &onUpdate) { 55 | SetOnUpdate(onUpdate); 56 | } 57 | 58 | RAYGUI_CPP_END_NAMESPACE --------------------------------------------------------------------------------