├── .gitignore ├── README.md ├── addon_config.mk ├── example ├── addons.make ├── bin │ └── data │ │ ├── .gitkeep │ │ ├── A new page_settings.xml │ │ ├── _settings.xml │ │ └── foo.xml ├── config.make ├── example.sln ├── example.vcxproj └── src │ └── example.cpp ├── license.md └── src ├── Controls ├── ofxSimpleGuiButton.cpp ├── ofxSimpleGuiButton.h ├── ofxSimpleGuiColorPicker.cpp ├── ofxSimpleGuiColorPicker.h ├── ofxSimpleGuiComboBox.cpp ├── ofxSimpleGuiComboBox.h ├── ofxSimpleGuiContent.cpp ├── ofxSimpleGuiContent.h ├── ofxSimpleGuiFPSCounter.cpp ├── ofxSimpleGuiFPSCounter.h ├── ofxSimpleGuiMovieSlider.cpp ├── ofxSimpleGuiMovieSlider.h ├── ofxSimpleGuiQuadWarp.cpp ├── ofxSimpleGuiQuadWarp.h ├── ofxSimpleGuiSlider2d.cpp ├── ofxSimpleGuiSlider2d.h ├── ofxSimpleGuiSliderBase.h ├── ofxSimpleGuiSliderFloat.h ├── ofxSimpleGuiSliderInt.h ├── ofxSimpleGuiTitle.cpp ├── ofxSimpleGuiTitle.h ├── ofxSimpleGuiToggle.cpp └── ofxSimpleGuiToggle.h ├── ofxSimpleGuiConfig.cpp ├── ofxSimpleGuiConfig.h ├── ofxSimpleGuiControl.cpp ├── ofxSimpleGuiControl.h ├── ofxSimpleGuiIncludes.h ├── ofxSimpleGuiPage.cpp ├── ofxSimpleGuiPage.h ├── ofxSimpleGuiToo.cpp ├── ofxSimpleGuiToo.h ├── ofxSimpleGuiValueControl.cpp └── ofxSimpleGuiValueControl.h /.gitignore: -------------------------------------------------------------------------------- 1 | ######################### 2 | # openFrameworks patterns 3 | ######################### 4 | 5 | # build files 6 | openFrameworks.a 7 | openFrameworksDebug.a 8 | openFrameworksUniversal.a 9 | libs/openFrameworksCompiled/lib/*/* 10 | !libs/openFrameworksCompiled/lib/*/.gitkeep 11 | 12 | # apothecary 13 | scripts/apothecary 14 | 15 | # rule to avoid non-official addons going into git 16 | # see addons/.gitignore 17 | addons/* 18 | 19 | # rule to avoid non-official apps going into git 20 | # see apps/.gitignore 21 | apps/* 22 | 23 | # rule to ignore compiled / downloaded libs 24 | /libs/* 25 | !/libs/openFrameworks 26 | !/libs/openFrameworksCompiled 27 | 28 | # also, see examples/.gitignore 29 | 30 | ######################### 31 | # general 32 | ######################### 33 | 34 | [Bb]uild/ 35 | [Oo]bj/ 36 | *.o 37 | examples/**/[Dd]ebug*/ 38 | examples/**/[Rr]elease*/ 39 | examples/**/gcc-debug/ 40 | examples/**/gcc-release/ 41 | tests/**/[Dd]ebug*/ 42 | tests/**/[Rr]elease*/ 43 | tests/**/gcc-debug/ 44 | tests/**/gcc-release/ 45 | *.mode* 46 | *.app/ 47 | *.pyc 48 | .svn/ 49 | *.log 50 | *.cpp.eep 51 | *.cpp.elf 52 | *.cpp.hex 53 | 54 | ######################### 55 | # IDE 56 | ######################### 57 | 58 | # XCode 59 | *.pbxuser 60 | *.perspective 61 | *.perspectivev3 62 | *.mode1v3 63 | *.mode2v3 64 | # XCode 4 65 | xcuserdata 66 | *.xcworkspace 67 | 68 | # Code::Blocks 69 | *.depend 70 | *.layout 71 | 72 | # Visual Studio 73 | *.sdf 74 | *.opensdf 75 | *.suo 76 | *.pdb 77 | *.ilk 78 | *.aps 79 | ipch/ 80 | **/.vs/* 81 | 82 | # Eclipse 83 | .metadata 84 | local.properties 85 | .externalToolBuilders 86 | 87 | # Android Studio 88 | .idea 89 | .gradle 90 | gradle 91 | gradlew 92 | gradlew.bat 93 | 94 | # QtCreator 95 | *.qbs.user 96 | *.pro.user 97 | *.pri 98 | 99 | 100 | ######################### 101 | # operating system 102 | ######################### 103 | 104 | # Linux 105 | *~ 106 | # KDE 107 | .directory 108 | .AppleDouble 109 | 110 | # OSX 111 | .DS_Store 112 | *.swp 113 | *~.nib 114 | # Thumbnails 115 | ._* 116 | examples/ios/**/mediaAssets 117 | 118 | # Windows 119 | # Windows image file caches 120 | Thumbs.db 121 | # Folder config file 122 | Desktop.ini 123 | 124 | # Android 125 | .csettings 126 | /libs/openFrameworksCompiled/project/android/paths.make 127 | 128 | # Android Studio 129 | *.iml 130 | 131 | ######################### 132 | # miscellaneous 133 | ######################### 134 | 135 | .mailmap 136 | /apps*/ 137 | 138 | ######################### 139 | # core examples 140 | ######################### 141 | 142 | bin/* 143 | !bin/data/ 144 | 145 | **/bin/* 146 | !**/bin/data/ 147 | 148 | ######################### 149 | # IDE 150 | ######################### 151 | 152 | # XCode 153 | *.xcodeproj 154 | Project.xcconfig 155 | openFrameworks-Info.plist 156 | ofxiOS-Info.plist 157 | ofxiOS_Prefix.pch 158 | */*/Default*.png 159 | */*/Icon*.png 160 | 161 | # Code::Blocks 162 | # *.cbp 163 | # *.workspace 164 | 165 | # Visual Studio 166 | # *.sln 167 | # *.vcxproj 168 | *.vcxproj.user 169 | *.vcxproj.filters 170 | icon.rc 171 | 172 | # Eclipse 173 | .cproject 174 | .project 175 | .settings/ 176 | 177 | # QtCreator 178 | # *.qbs 179 | *.qbs.user* 180 | *.pro 181 | *.pro.user 182 | qtc_Desktop_* 183 | 184 | ######################### 185 | # operating system 186 | ######################### 187 | 188 | # Linux 189 | # Makefile 190 | # config.make 191 | # Leave Android files in until project generation works 192 | !/android/*/Makefile 193 | !/android/*/config.make 194 | 195 | # Android 196 | android/*/test link 197 | android/*/gen 198 | android/*/res/raw 199 | libOFAndroidApp*.so 200 | gdbserver 201 | gdb.setup 202 | libneondetection.so 203 | Application.mk 204 | Android.mk 205 | 206 | !android/*/.cproject 207 | !android/*/.project 208 | !android/*/.settings 209 | !android/*/.settings/* 210 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ofxSimpleGuiToo 2 | ===================================== 3 | 4 | Introduction 5 | ------------ 6 | C++ openFrameworks addon for simple and very quick to setup GUI based on Todd Vanderlin's ofxSimpleGui. It uses a very similar (almost identical) API, but with a rewritten backend. 7 | 8 | Licence 9 | ------- 10 | The code in this repository is available under the [MIT License](https://secure.wikimedia.org/wikipedia/en/wiki/Mit_license). 11 | Copyright (c) 2008-2012 Memo Akten, [www.memo.tv](http://www.memo.tv) 12 | The Mega Super Awesome Visuals Company 13 | 14 | 15 | Installation 16 | ------------ 17 | Copy to your openFrameworks/addons folder. 18 | 19 | Dependencies 20 | ------------ 21 | - ofxMSAInteractiveObject 22 | - ofxXmlSettings 23 | 24 | Compatibility 25 | ------------ 26 | OF0072 27 | 28 | 29 | Known issues 30 | ------------ 31 | none 32 | 33 | Version history 34 | ------------ 35 | ### v1.4 23/09/2012 36 | - compatible with OF0072 37 | - renamed (uppercase) MSA namespace to (lowercase) msa. (kept MSA as an alias for backwards compatibility) 38 | 39 | ### v1.3 40 | - page::saveToXML() pushed the tag so control::saveToXML() didn't need to check that tag, 41 | whereas page::loadFromXML() didn't push the tag so control::loadFromXML() did. 42 | Wasn't consistent so now all controls can assume that we are already inside the tag. 43 | - fixed keyboard support (any control which the mouse is hovering over, now receives the events: 44 | keyPressed(int key), keyReleased(int key), onKeyUp(), onKeyDown(), onKeyLeft(), onKeyRight(), onKeyEnter() 45 | 46 | ### v1.2 47 | - lots of thing, can't remember. whoops. 48 | 49 | ### v1.1 07/04/2009 50 | - changed license to revised BSD (a lot more more permissive than GPL) 51 | 52 | ### v1.0 53 | - initial version 54 | - changes from original ofxSimpleGui 55 | - added pages (tabs), controls are added to pages 56 | - when controls reach bottom of page (customizable using page.height property) controls flow to the right 57 | - ability to customize spacing / sizes / colors etc. using a configuration class 58 | - everything on a grid 59 | - addFrame has been renamed to addContent and manages any class type which extends ofBaseDraws 60 | - saved in xml using 'keys', so you can add/remove/rename/reorder controls and still load values correctly 61 | - option to backup save 62 | - all controls inherit from ofxMSAInteractiveObject (for simpler event management) 63 | 64 | 65 | -------------------------------------------------------------------------------- /addon_config.mk: -------------------------------------------------------------------------------- 1 | meta: 2 | ADDON_NAME = ofxSimpleGuiToo 3 | ADDON_DESCRIPTION = C++ openFrameworks addon for simple and very quick to setup GUI 4 | ADDON_AUTHOR = Memo Akten, www.memo.tv 5 | ADDON_TAGS = "GUI" 6 | ADDON_URL = https://github.com/memo/ofxSimpleGuiToo 7 | 8 | common: 9 | # dependencies with other addons, a list of them separated by spaces 10 | # or use += in several lines 11 | ADDON_DEPENDENCIES = ofxMSAInteractiveObject ofxXmlSettings 12 | -------------------------------------------------------------------------------- /example/addons.make: -------------------------------------------------------------------------------- 1 | ofxMSAInteractiveObject 2 | ofxXmlSettings 3 | ofxSimpleGuiToo 4 | -------------------------------------------------------------------------------- /example/bin/data/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/memo/ofxSimpleGuiToo/fd652980aa8fe471c756077192f10f2408121934/example/bin/data/.gitkeep -------------------------------------------------------------------------------- /example/bin/data/A new page_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | myInt5 4 | 0 5 | 6 | 7 | myInt7 8 | 0 9 | 10 | 11 | myInt8 12 | 0 13 | 14 | 15 | myInt3 16 | 0 17 | 18 | 19 | myFloat7 20 | 0.000000000 21 | 22 | 23 | myFloat8 24 | 0.000000000 25 | 26 | 27 | myInt9 28 | 0 29 | 30 | 31 | myBool5 32 | 0 33 | 34 | 35 | myBool6 36 | 0 37 | 38 | 39 | myBool7 40 | 0 41 | 42 | 43 | myBool8 44 | 0 45 | 46 | 47 | -------------------------------------------------------------------------------- /example/bin/data/_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | myBool1 Animate 4 | 0 5 | 6 | 7 | <_noise> 8 | myFloat1: noise 9 | 0.000000000 10 | 11 | 12 | myInt1 13 | 0 14 | 15 | 16 | box1 17 | 0 18 | 19 | 20 | Randomize Background 21 | 1 22 | 23 | 24 | BG Color 25 | 1.000000000 26 | 1.000000000 27 | 1.000000000 28 | 1.000000000 29 | 30 | 31 | myFloat2 32 | 0.000000000 33 | 34 | 35 | myInt2 36 | 0 37 | 38 | 39 | myBool2 40 | 0 41 | 42 | 43 | box2 44 | 0 45 | 46 | 47 | myBool4 48 | 0 49 | 50 | 51 | myBool3 52 | 0 53 | 54 | 55 | myFloat3 56 | 0.000000000 57 | 58 | 59 | myFloat4 60 | 0.000000000 61 | 62 | 63 | myInt6 64 | 0 65 | 66 | 67 | myInt4 68 | 0 69 | 70 | 71 | -------------------------------------------------------------------------------- /example/bin/data/foo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | myFloat5 4 | 0.000000000 5 | 6 | 7 | myFloat6 8 | 0.000000000 9 | 10 | 11 | myFloat9 12 | 0.000000000 13 | 14 | 15 | myBool9 16 | 0 17 | 18 | 19 | -------------------------------------------------------------------------------- /example/config.make: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # CONFIGURE PROJECT MAKEFILE (optional) 3 | # This file is where we make project specific configurations. 4 | ################################################################################ 5 | 6 | ################################################################################ 7 | # OF ROOT 8 | # The location of your root openFrameworks installation 9 | # (default) OF_ROOT = ../../.. 10 | ################################################################################ 11 | # OF_ROOT = ../../.. 12 | 13 | ################################################################################ 14 | # PROJECT ROOT 15 | # The location of the project - a starting place for searching for files 16 | # (default) PROJECT_ROOT = . (this directory) 17 | # 18 | ################################################################################ 19 | # PROJECT_ROOT = . 20 | 21 | ################################################################################ 22 | # PROJECT SPECIFIC CHECKS 23 | # This is a project defined section to create internal makefile flags to 24 | # conditionally enable or disable the addition of various features within 25 | # this makefile. For instance, if you want to make changes based on whether 26 | # GTK is installed, one might test that here and create a variable to check. 27 | ################################################################################ 28 | # None 29 | 30 | ################################################################################ 31 | # PROJECT EXTERNAL SOURCE PATHS 32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder. 33 | # Like source folders in the PROJECT_ROOT, these paths are subject to 34 | # exlclusion via the PROJECT_EXLCUSIONS list. 35 | # 36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank) 37 | # 38 | # Note: Leave a leading space when adding list items with the += operator 39 | ################################################################################ 40 | # PROJECT_EXTERNAL_SOURCE_PATHS = 41 | 42 | ################################################################################ 43 | # PROJECT EXCLUSIONS 44 | # These makefiles assume that all folders in your current project directory 45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations 46 | # to look for source code. The any folders or files that match any of the 47 | # items in the PROJECT_EXCLUSIONS list below will be ignored. 48 | # 49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete 50 | # string unless teh user adds a wildcard (%) operator to match subdirectories. 51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is 52 | # treated literally. 53 | # 54 | # (default) PROJECT_EXCLUSIONS = (blank) 55 | # 56 | # Will automatically exclude the following: 57 | # 58 | # $(PROJECT_ROOT)/bin% 59 | # $(PROJECT_ROOT)/obj% 60 | # $(PROJECT_ROOT)/%.xcodeproj 61 | # 62 | # Note: Leave a leading space when adding list items with the += operator 63 | ################################################################################ 64 | # PROJECT_EXCLUSIONS = 65 | 66 | ################################################################################ 67 | # PROJECT LINKER FLAGS 68 | # These flags will be sent to the linker when compiling the executable. 69 | # 70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs 71 | # 72 | # Note: Leave a leading space when adding list items with the += operator 73 | # 74 | # Currently, shared libraries that are needed are copied to the 75 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to 76 | # add a runtime path to search for those shared libraries, since they aren't 77 | # incorporated directly into the final executable application binary. 78 | ################################################################################ 79 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs 80 | 81 | ################################################################################ 82 | # PROJECT DEFINES 83 | # Create a space-delimited list of DEFINES. The list will be converted into 84 | # CFLAGS with the "-D" flag later in the makefile. 85 | # 86 | # (default) PROJECT_DEFINES = (blank) 87 | # 88 | # Note: Leave a leading space when adding list items with the += operator 89 | ################################################################################ 90 | # PROJECT_DEFINES = 91 | 92 | ################################################################################ 93 | # PROJECT CFLAGS 94 | # This is a list of fully qualified CFLAGS required when compiling for this 95 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS 96 | # defined in your platform specific core configuration files. These flags are 97 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below. 98 | # 99 | # (default) PROJECT_CFLAGS = (blank) 100 | # 101 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in 102 | # your platform specific configuration file will be applied by default and 103 | # further flags here may not be needed. 104 | # 105 | # Note: Leave a leading space when adding list items with the += operator 106 | ################################################################################ 107 | # PROJECT_CFLAGS = 108 | 109 | ################################################################################ 110 | # PROJECT OPTIMIZATION CFLAGS 111 | # These are lists of CFLAGS that are target-specific. While any flags could 112 | # be conditionally added, they are usually limited to optimization flags. 113 | # These flags are added BEFORE the PROJECT_CFLAGS. 114 | # 115 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets. 116 | # 117 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank) 118 | # 119 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets. 120 | # 121 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank) 122 | # 123 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the 124 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration 125 | # file will be applied by default and further optimization flags here may not 126 | # be needed. 127 | # 128 | # Note: Leave a leading space when adding list items with the += operator 129 | ################################################################################ 130 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE = 131 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG = 132 | 133 | ################################################################################ 134 | # PROJECT COMPILERS 135 | # Custom compilers can be set for CC and CXX 136 | # (default) PROJECT_CXX = (blank) 137 | # (default) PROJECT_CC = (blank) 138 | # Note: Leave a leading space when adding list items with the += operator 139 | ################################################################################ 140 | # PROJECT_CXX = 141 | # PROJECT_CC = 142 | -------------------------------------------------------------------------------- /example/example.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 15 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "example.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" 4 | EndProject 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Win32 = Debug|Win32 10 | Debug|x64 = Debug|x64 11 | Release|Win32 = Release|Win32 12 | Release|x64 = Release|x64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32 17 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 18 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 19 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32 20 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32 21 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 22 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 23 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32 24 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32 25 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 26 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 27 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32 28 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32 29 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 30 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64 31 | EndGlobalSection 32 | GlobalSection(SolutionProperties) = preSolution 33 | HideSolutionNode = FALSE 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /example/example.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | $([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0')) 23 | $(LatestTargetPlatformVersion) 24 | $(WindowsTargetPlatformVersion) 25 | 26 | 27 | {7FD42DF7-442E-479A-BA76-D0022F99702A} 28 | Win32Proj 29 | example 30 | 31 | 32 | 33 | Application 34 | Unicode 35 | v141 36 | 37 | 38 | Application 39 | Unicode 40 | v141 41 | 42 | 43 | Application 44 | Unicode 45 | true 46 | v141 47 | 48 | 49 | Application 50 | Unicode 51 | true 52 | v141 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | bin\ 74 | obj\$(Platform)\$(Configuration)\ 75 | $(ProjectName)_debug 76 | true 77 | true 78 | 79 | 80 | bin\ 81 | obj\$(Platform)\$(Configuration)\ 82 | $(ProjectName)_debug 83 | true 84 | true 85 | 86 | 87 | bin\ 88 | obj\$(Platform)\$(Configuration)\ 89 | false 90 | 91 | 92 | bin\ 93 | obj\$(Platform)\$(Configuration)\ 94 | false 95 | 96 | 97 | 98 | Disabled 99 | EnableFastChecks 100 | %(PreprocessorDefinitions) 101 | MultiThreadedDebugDLL 102 | Level3 103 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxMSAInteractiveObject\src;..\..\..\addons\ofxXmlSettings\libs;..\..\..\addons\ofxXmlSettings\src;..\..\..\addons\ofxSimpleGuiToo\src;..\..\..\addons\ofxSimpleGuiToo\src\Controls 104 | CompileAsCpp 105 | $(IntDir) 106 | 107 | 108 | true 109 | Console 110 | false 111 | %(AdditionalDependencies) 112 | %(AdditionalLibraryDirectories) 113 | 114 | 115 | 116 | 117 | 118 | Disabled 119 | EnableFastChecks 120 | %(PreprocessorDefinitions) 121 | MultiThreadedDebugDLL 122 | Level3 123 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxMSAInteractiveObject\src;..\..\..\addons\ofxXmlSettings\libs;..\..\..\addons\ofxXmlSettings\src;..\..\..\addons\ofxSimpleGuiToo\src;..\..\..\addons\ofxSimpleGuiToo\src\Controls 124 | CompileAsCpp 125 | true 126 | $(IntDir) 127 | 128 | 129 | true 130 | Console 131 | false 132 | %(AdditionalDependencies) 133 | %(AdditionalLibraryDirectories) 134 | 135 | 136 | 137 | 138 | 139 | false 140 | %(PreprocessorDefinitions) 141 | MultiThreadedDLL 142 | Level3 143 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxMSAInteractiveObject\src;..\..\..\addons\ofxXmlSettings\libs;..\..\..\addons\ofxXmlSettings\src;..\..\..\addons\ofxSimpleGuiToo\src;..\..\..\addons\ofxSimpleGuiToo\src\Controls 144 | CompileAsCpp 145 | true 146 | $(IntDir) 147 | 148 | 149 | false 150 | false 151 | Console 152 | true 153 | true 154 | false 155 | %(AdditionalDependencies) 156 | %(AdditionalLibraryDirectories) 157 | 158 | 159 | 160 | 161 | 162 | false 163 | %(PreprocessorDefinitions) 164 | MultiThreadedDLL 165 | Level3 166 | %(AdditionalIncludeDirectories);src;..\..\..\addons\ofxMSAInteractiveObject\src;..\..\..\addons\ofxXmlSettings\libs;..\..\..\addons\ofxXmlSettings\src;..\..\..\addons\ofxSimpleGuiToo\src;..\..\..\addons\ofxSimpleGuiToo\src\Controls 167 | CompileAsCpp 168 | $(IntDir) 169 | 170 | 171 | false 172 | false 173 | Console 174 | true 175 | true 176 | false 177 | %(AdditionalDependencies) 178 | %(AdditionalLibraryDirectories) 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | {5837595d-aca9-485c-8e76-729040ce4b0b} 232 | 233 | 234 | 235 | 236 | /D_DEBUG %(AdditionalOptions) 237 | /D_DEBUG %(AdditionalOptions) 238 | $(OF_ROOT)\libs\openFrameworksCompiled\project\vs 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | -------------------------------------------------------------------------------- /example/src/example.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofxSimpleGuiToo.h" 3 | 4 | bool myBool1Animate; 5 | bool myBool2; 6 | bool myBool3; 7 | bool myBool4; 8 | bool myBool5; 9 | bool myBool6; 10 | bool myBool7; 11 | bool myBool8; 12 | bool myBool9; 13 | 14 | int myInt1; 15 | int myInt2; 16 | int myInt3; 17 | int myInt4; 18 | int myInt5; 19 | int myInt6; 20 | int myInt7; 21 | int myInt8; 22 | int myInt9; 23 | 24 | int box1; 25 | int box2; 26 | 27 | float myFloat1; 28 | float myFloat2; 29 | float myFloat3; 30 | float myFloat4; 31 | float myFloat5; 32 | float myFloat6; 33 | float myFloat7; 34 | float myFloat8; 35 | float myFloat9; 36 | 37 | ofFloatColor aColor; 38 | 39 | // for demonstrating adding any drawable object (that extends ofBaseDraw); 40 | ofVideoGrabber vidGrabber; 41 | unsigned char * videoInverted; 42 | ofTexture videoTexture; 43 | 44 | bool randomizeButton = true; 45 | 46 | ofPoint *points; 47 | ofPoint v[300]; 48 | 49 | class testApp : public ofBaseApp { 50 | public: 51 | 52 | //-------------------------------------------------------------- 53 | void setup() { 54 | ofBackground(0, 0, 0); 55 | ofSetVerticalSync(true); 56 | 57 | // for demonstrating adding any drawable object (that extends ofBaseDraw); 58 | vidGrabber.initGrabber(320, 240); 59 | videoInverted = new unsigned char[int(vidGrabber.getWidth() * vidGrabber.getHeight() * 3)]; 60 | videoTexture.allocate(vidGrabber.getWidth(), vidGrabber.getHeight(), GL_RGB); 61 | 62 | 63 | // 'gui' is a global variable declared in ofxSimpleGuiToo.h 64 | gui.addTitle("A group"); 65 | gui.addToggle("myBool1 Animate", myBool1Animate); 66 | gui.addSlider("myFloat1: noise", myFloat1, 0.0, 1); 67 | gui.addSlider("myInt1", myInt1, 100, 200); 68 | gui.addComboBox("box1", box1, 12, NULL); 69 | gui.addButton("Randomize Background", randomizeButton); 70 | gui.addColorPicker("BG Color", aColor); 71 | 72 | 73 | // start a new group 74 | gui.addTitle("Another group"); 75 | gui.addSlider("myFloat2", myFloat2, 0.0, 1).setSmoothing(0.5); 76 | gui.addSlider("myInt2", myInt2, 3, 8); 77 | gui.addToggle("myBool2", myBool2); 78 | string titleArray[] = { "Lame", "Alright", "Better", "Best" }; 79 | gui.addComboBox("box2", box2, 4, titleArray); 80 | gui.addFPSCounter(); 81 | 82 | // new group, this time separate into it's own column 83 | gui.addTitle("Yes one more group").setNewColumn(true); 84 | gui.addToggle("myBool4", myBool4); 85 | gui.addToggle("myBool3", myBool3); 86 | gui.addSlider("myFloat3", myFloat3, 0.0, 1).setSmoothing(0.8); 87 | gui.addSlider("myFloat4", myFloat4, 0.0, 20).setSmoothing(1); 88 | gui.addSlider("myInt6", myInt6, 0, 10); 89 | gui.addSlider("myInt4", myInt4, 320, 1280); 90 | gui.addContent("Camera feed", vidGrabber); 91 | gui.addContent("Inverted", videoTexture); 92 | 93 | 94 | gui.addPage("A new page"); // use '[' ']' to cycle through pages, or keys 1-9 95 | gui.addSlider("myInt5", myInt5, 2, 5); 96 | gui.addSlider("myInt7", myInt7, 0, 100); 97 | gui.addSlider("myInt8", myInt8, 10, 50); 98 | gui.addSlider("myInt3", myInt3, 0, 100); 99 | gui.addSlider("myFloat7", myFloat7, 0.0, 1).setSmoothing(0.0); // default 100 | gui.addSlider("myFloat8", myFloat8, 0.0, 0.1).setSmoothing(0.5); 101 | gui.addSlider("myInt9", myInt9, 0, 10).setSmoothing(0.9); 102 | 103 | gui.addTitle("Final group?"); 104 | gui.addToggle("myBool5", myBool5); 105 | gui.addToggle("myBool6", myBool6); 106 | gui.addToggle("myBool7", myBool7); 107 | gui.addToggle("myBool8", myBool8); 108 | 109 | 110 | // by default each page is saved in an xml with the same name as display name 111 | // you can override this with ofxSimpleGuiPage::setXMLName(string s); 112 | // ofxSimpleGuiToo::addPage() returns reference to the page, so you can do it directly on one line 113 | // of save it in a variable for use later 114 | gui.addPage("My 3rd page").setXMLName("foo.xml"); 115 | gui.addSlider("myFloat5", myFloat5, 0.0, 5); 116 | gui.addSlider("myFloat6", myFloat6, 0.0, 1); 117 | gui.addSlider("myFloat9", myFloat9, 0.0, 0.01); 118 | gui.addToggle("myBool9", myBool9); 119 | 120 | 121 | gui.loadFromXML(); 122 | 123 | printf("myint : %i\n", myInt1); 124 | 125 | gui.show(); 126 | } 127 | 128 | //-------------------------------------------------------------- 129 | void update() { 130 | if (myBool1Animate) myFloat1 = ofNoise(ofGetElapsedTimef()); 131 | 132 | if (randomizeButton) { 133 | randomizeButton = false; 134 | aColor.r = ofRandomuf(); 135 | aColor.g = ofRandomuf(); 136 | aColor.b = ofRandomuf(); 137 | } 138 | 139 | 140 | // from ofVideoGrabber example ( 141 | vidGrabber.update(); 142 | if (vidGrabber.isFrameNew()) { 143 | int totalPixels = vidGrabber.getWidth() * vidGrabber.getHeight() * 3; 144 | unsigned char * pixels = vidGrabber.getPixels().getData(); 145 | for (int i = 0; i < totalPixels; i++) videoInverted[i] = 255 - pixels[i]; 146 | videoTexture.loadData(videoInverted, vidGrabber.getWidth(), vidGrabber.getHeight(), GL_RGB); 147 | } 148 | } 149 | 150 | //-------------------------------------------------------------- 151 | void draw() { 152 | ofBackground(aColor.r * 255, aColor.g * 255.0f, aColor.b * 255.0); 153 | 154 | gui.draw(); 155 | } 156 | 157 | //-------------------------------------------------------------- 158 | void keyPressed(int key) { 159 | if (key >= '0' && key <= '9') { 160 | gui.setPage(key - '0'); 161 | gui.show(); 162 | } 163 | else { 164 | switch (key) { 165 | case ' ': gui.toggleDraw(); break; 166 | case '[': gui.prevPage(); break; 167 | case ']': gui.nextPage(); break; 168 | case 'p': gui.nextPageWithBlank(); break; 169 | } 170 | } 171 | } 172 | }; 173 | 174 | //======================================================================== 175 | int main() { 176 | 177 | // can be OF_WINDOW or OF_FULLSCREEN 178 | // pass in width and height too: 179 | ofSetupOpenGL(1024, 768, OF_WINDOW); // <-------- setup the GL context 180 | 181 | // this kicks off the running of my app 182 | ofRunApp(new testApp); 183 | 184 | } 185 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The code in this repository is available under the [MIT License](https://secure.wikimedia.org/wikipedia/en/wiki/Mit_license). 2 | 3 | Copyright (c) 2008-2012 Memo Akten, [www.memo.tv](http://www.memo.tv) 4 | The Mega Super Awesome Visuals Company 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiButton.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ofxSimpleGuiButton.h" 3 | 4 | 5 | ofxSimpleGuiButton::ofxSimpleGuiButton(string name, bool &value) : ofxSimpleGuiValueControl(name, value) { 6 | beToggle = false; 7 | beenPressed = false; 8 | controlType = "Button"; 9 | setup(); 10 | } 11 | 12 | void ofxSimpleGuiButton::setup() { 13 | setSize(config->gridSize.x - config->padding.x, config->buttonHeight); 14 | } 15 | 16 | #ifndef OFXMSAGUI_DONT_USE_XML 17 | void ofxSimpleGuiButton::loadFromXML(ofxXmlSettings &XML) { 18 | setValue(XML.getValue(controlType + "_" + key + ":value", getValue())); 19 | } 20 | 21 | void ofxSimpleGuiButton::saveToXML(ofxXmlSettings &XML) { 22 | XML.addTag(controlType + "_" + key); 23 | XML.pushTag(controlType + "_" + key); 24 | XML.addValue("name", name); 25 | XML.addValue("value", getValue()); 26 | XML.popTag(); 27 | } 28 | #endif 29 | 30 | void ofxSimpleGuiButton::keyPressed( int key ) { 31 | if(key==keyboardShortcut) toggle(); 32 | } 33 | 34 | 35 | 36 | bool ofxSimpleGuiButton::getValue() { 37 | return (*value); 38 | } 39 | 40 | void ofxSimpleGuiButton::setValue(bool b) { 41 | (*value) = b; 42 | } 43 | 44 | void ofxSimpleGuiButton::toggle() { 45 | (*value) = !(*value); 46 | } 47 | 48 | void ofxSimpleGuiButton::setToggleMode(bool b) { 49 | beToggle = b; 50 | } 51 | 52 | void ofxSimpleGuiButton::onPress(int x, int y, int button) { 53 | beenPressed = true; 54 | if(beToggle) (*value) = !(*value); 55 | else (*value) = true; 56 | } 57 | 58 | void ofxSimpleGuiButton::onRelease(int x, int y, int button) { 59 | if(!beToggle) (*value) = false; 60 | } 61 | 62 | void ofxSimpleGuiButton::draw(float x, float y) { 63 | setPosition(x, y); 64 | 65 | ofPushMatrix(); 66 | ofTranslate(x, y, 0); 67 | 68 | ofEnableAlphaBlending(); 69 | ofFill(); 70 | setTextBGColor(); 71 | ofDrawRectangle(0, 0, width, height); 72 | 73 | // if a toggle 74 | if((*value) && beToggle) { 75 | setTextColor(); 76 | //ofLine(0, 0, box.width, box.height); 77 | //ofLine(box.width, 0, 0, box.height); 78 | } 79 | 80 | setTextColor(); 81 | ofDrawBitmapString(name, 3, 15); 82 | 83 | ofDisableAlphaBlending(); 84 | 85 | ofPopMatrix(); 86 | } 87 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../ofxSimpleGuiValueControl.h" 4 | 5 | 6 | class ofxSimpleGuiButton : public ofxSimpleGuiValueControl { 7 | public: 8 | bool beToggle; 9 | bool beenPressed; 10 | 11 | ofxSimpleGuiButton(string name, bool &value); 12 | void setup(); 13 | 14 | #ifndef OFXMSAGUI_DONT_USE_XML 15 | void loadFromXML(ofxXmlSettings &XML); 16 | void saveToXML(ofxXmlSettings &XML); 17 | #endif 18 | 19 | void keyPressed( int key ); 20 | 21 | bool getValue(); 22 | void setValue(bool b); 23 | void toggle(); 24 | 25 | void setToggleMode(bool b); 26 | 27 | void onPress(int x, int y, int button); 28 | void onRelease(int x, int y, int button); 29 | void draw(float x, float y); 30 | }; 31 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiColorPicker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ofxSimpleGuiColorPicker.cpp 3 | * OpenCL Particles 3. single segment trails 4 | * 5 | * Created by Mehmet Akten on 01/11/2009. 6 | * Copyright 2009 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "ofxSimpleGuiColorPicker.h" 11 | 12 | ofxSimpleGuiColorPicker::ofxSimpleGuiColorPicker(string name, ofFloatColor& color, float max) : ofxSimpleGuiControl(name) { 13 | this->value = &color; 14 | this->min = 0; 15 | this->max = max; 16 | 17 | controlType = "ColorPicker"; 18 | setup(); 19 | } 20 | 21 | void ofxSimpleGuiColorPicker::setup() { 22 | setSize(config->gridSize.x - config->padding.x, config->sliderHeight * 8 + config->sliderTextHeight); 23 | for(int i=0; i<4; i++) { 24 | pct[i] = ofMap(getValue(i), 0, max, 0.0, width); 25 | barwidth[i] = pct[i]; 26 | } 27 | } 28 | 29 | #ifndef OFXMSAGUI_DONT_USE_XML 30 | void ofxSimpleGuiColorPicker::loadFromXML(ofxXmlSettings &XML) { 31 | for(int i=0; i<4; i++) { 32 | setValue(XML.getValue(controlType + "_" + key + ":values_" + ofToString(i), getValue(i)), i); 33 | } 34 | } 35 | 36 | void ofxSimpleGuiColorPicker::saveToXML(ofxXmlSettings &XML) { 37 | XML.addTag(controlType + "_" + key); 38 | XML.pushTag(controlType + "_" + key); 39 | XML.addValue("name", name); 40 | for(int i=0; i<4; i++) { 41 | XML.addValue("values_" + ofToString(i), getValue(i)); 42 | } 43 | XML.popTag(); 44 | } 45 | #endif 46 | 47 | 48 | float ofxSimpleGuiColorPicker::getValue(int i) { 49 | return value->v[i]; 50 | } 51 | 52 | 53 | void ofxSimpleGuiColorPicker::setValue(float f, int i) { 54 | if(f < min) f = min; 55 | else if(f > max) f = max; 56 | value->v[i] = f; 57 | } 58 | 59 | 60 | void ofxSimpleGuiColorPicker::updateSlider() { 61 | if(!enabled) return; 62 | 63 | int i= (getMouseY() - y) / config->sliderHeight/2; 64 | if(i<0 || i>=4) return; 65 | 66 | if(pct[i] > width) { 67 | pct[i] = width; 68 | } 69 | else { 70 | pct[i] = getMouseX() - x; 71 | setValue(ofMap(pct[i], 0.0, (float)width, 0, max), i); 72 | } 73 | } 74 | 75 | void ofxSimpleGuiColorPicker::onPress(int x, int y, int button) { 76 | updateSlider(); 77 | } 78 | 79 | void ofxSimpleGuiColorPicker::onDragOver(int x, int y, int button) { 80 | updateSlider(); 81 | } 82 | 83 | void ofxSimpleGuiColorPicker::onDragOutside(int x, int y, int button) { 84 | updateSlider(); 85 | } 86 | 87 | 88 | 89 | //--------------------------------------------------------------------- update 90 | void ofxSimpleGuiColorPicker::update() { 91 | if(!enabled) return; 92 | 93 | if(lock) { 94 | updateSlider(); 95 | } 96 | 97 | // enabled = false; 98 | } 99 | 100 | //--------------------------------------------------------------------- draw 101 | void ofxSimpleGuiColorPicker::draw(float x, float y) { 102 | 103 | // enabled = true; 104 | 105 | //update postion of gui object 106 | setPosition(x, y); 107 | ofPushMatrix(); 108 | ofTranslate(x, y, 0); 109 | 110 | int startY = 0; 111 | for(int i=0; i<4; i++) { 112 | 113 | barwidth[i] = ofMap(getValue(i), 0, max, 0.0, (float)width); 114 | if(barwidth[i] > width) barwidth[i] = width; 115 | else if(barwidth[i] < 0) barwidth[i] = 0; 116 | 117 | ofEnableAlphaBlending(); 118 | ofFill(); 119 | setEmptyColor(); 120 | ofDrawRectangle(0, startY, width, config->sliderHeight*1.8); 121 | 122 | 123 | switch(i) { 124 | case 0:ofSetColor(ofFloatColor(getValue(i), 0, 0)); break; 125 | case 1:ofSetColor(ofFloatColor(0, getValue(i), 0)); break; 126 | case 2:ofSetColor(ofFloatColor(0, 0, getValue(i))); break; 127 | case 3:ofSetColor(ofFloatColor(getValue(i), getValue(i), getValue(i))); break; 128 | } 129 | 130 | ofDrawRectangle(0, startY, barwidth[i], config->sliderHeight * 1.8); 131 | 132 | int iover = (getMouseY() - y) / config->sliderHeight/2; 133 | bool isOver = iover == i; 134 | if(isOver) { 135 | ofSetColor(ofFloatColor(1, 1, 1)); 136 | } else { 137 | ofSetColor(ofFloatColor(0.5, 0.5, 0.5)); 138 | } 139 | 140 | ofDrawBitmapString(ofToString(getValue(i), 4), 3, startY + 14); 141 | 142 | startY += config->sliderHeight * 2; 143 | } 144 | 145 | ofFill(); 146 | 147 | setTextBGColor(); 148 | ofDrawRectangle(0, startY, width, config->sliderTextHeight); 149 | 150 | ofSetColor(ofFloatColor(getValue(0), getValue(1), getValue(2))); 151 | // ofRect(0, startY+config->sliderTextHeight, width, config->sliderTextHeight * 1.5); 152 | ofDrawRectangle(150, startY + 3, width - 150 -3, config->sliderTextHeight - 8); 153 | 154 | setTextColor(); 155 | string s = name; 156 | ofDrawBitmapString(s, 3, startY + 14); 157 | ofDisableAlphaBlending(); 158 | ofPopMatrix(); 159 | } 160 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiColorPicker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../ofxSimpleGuiControl.h" 4 | 5 | 6 | class ofxSimpleGuiColorPicker : public ofxSimpleGuiControl { 7 | public: 8 | 9 | ofFloatColor *value; 10 | float min, max; 11 | 12 | float barwidth[4]; 13 | float pct[4]; 14 | 15 | ofxSimpleGuiColorPicker(string name, ofFloatColor& color, float max = 1); 16 | void setup(); 17 | #ifndef OFXMSAGUI_DONT_USE_XML 18 | void loadFromXML(ofxXmlSettings &XML); 19 | void saveToXML(ofxXmlSettings &XML); 20 | #endif 21 | float getValue(int i); 22 | void setValue(float f, int i); 23 | void updateSlider(); 24 | void onPress(int x, int y, int button); 25 | void onDragOver(int x, int y, int button); 26 | void onDragOutside(int x, int y, int button); 27 | void update(); 28 | void draw(float x, float y); 29 | }; 30 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiComboBox.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ofxSimpleGuiComboBox.cpp 3 | * AlgorhythmicSorting 4 | * 5 | * Created by Administrator on 7/2/10. 6 | * Copyright 2010 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "ofxSimpleGuiComboBox.h" 11 | #include "../ofxSimpleGuiPage.h" 12 | 13 | #define kMaxChoiceStringLen 150 14 | #define kMaxNameStringLen 100 15 | 16 | ofxSimpleGuiComboBox::ofxSimpleGuiComboBox(string name, int &choice_out, int numChoices, ofxSimpleGuiPage *owner, string* choiceTitles ) : 17 | ofxSimpleGuiControl(name), 18 | m_selectedChoice(choice_out), 19 | m_page(owner) 20 | { 21 | m_mouseChoice = 0; 22 | if(numChoices <=1) 23 | numChoices = 1; 24 | m_hasFocus=false; 25 | m_title = name; 26 | 27 | for(int i=0; i= m_choices.size()) return; 42 | m_choices[index] = title; 43 | } 44 | 45 | string ofxSimpleGuiComboBox::getTitleForIndex(int index) { 46 | if(index < 0 || index >= m_choices.size())return m_choices.size() ? m_choices[m_selectedChoice] : "No Choices Available"; 47 | return m_choices[index]; 48 | } 49 | 50 | 51 | void ofxSimpleGuiComboBox::addChoice(string title, int index) { 52 | int insertIndex = m_choices.size(); 53 | 54 | if(index >= 0 && index < m_choices.size()) insertIndex = index; 55 | 56 | m_choices.insert(m_choices.begin() + insertIndex, title); 57 | } 58 | 59 | 60 | int ofxSimpleGuiComboBox::getIndexForTitle(string title) { 61 | for(int i=0; i= 0) removeChoice(index); 70 | } 71 | 72 | void ofxSimpleGuiComboBox::removeChoice(int index) { 73 | int removeIndex = m_choices.size() - 1; 74 | if(index >= 0 && index < m_choices.size()) 75 | removeIndex = index; 76 | 77 | m_choices.erase(m_choices.begin() + removeIndex); 78 | //also update the selected indexes. 79 | if(m_selectedChoice >= removeIndex) 80 | m_selectedChoice--; 81 | if(m_mouseChoice >= removeIndex) 82 | m_mouseChoice--; 83 | } 84 | 85 | void ofxSimpleGuiComboBox::setup() { 86 | setSize(config->gridSize.x - config->padding.x, config->comboBoxHeight); 87 | } 88 | 89 | #ifndef OFXMSAGUI_DONT_USE_XML 90 | void ofxSimpleGuiComboBox::loadFromXML(ofxXmlSettings &XML) { 91 | setValue(XML.getValue(controlType + "_" + key + ":value", getValue())); 92 | } 93 | 94 | void ofxSimpleGuiComboBox::saveToXML(ofxXmlSettings &XML) { 95 | XML.addTag(controlType + "_" + key); 96 | XML.pushTag(controlType + "_" + key); 97 | XML.addValue("name", name); 98 | XML.addValue("value", getValue()); 99 | XML.popTag(); 100 | } 101 | #endif 102 | 103 | void ofxSimpleGuiComboBox::keyPressed( int key ) { 104 | } 105 | 106 | int ofxSimpleGuiComboBox::getValue() { 107 | return m_selectedChoice; 108 | } 109 | 110 | void ofxSimpleGuiComboBox::setValue(int index) { 111 | m_selectedChoice = ofClamp(index, 0, m_choices.size()); 112 | } 113 | 114 | void ofxSimpleGuiComboBox::setValue(string title) { 115 | setValue(getIndexForTitle(title)); 116 | } 117 | 118 | 119 | //press was outside - handle. 120 | void onPressOutside(int x, int y, int button) { 121 | 122 | } 123 | 124 | void ofxSimpleGuiComboBox::onPress(int x, int y, int button) { 125 | // beenPressed = true; 126 | m_mouseMovedSinceClick=false; 127 | //a click toggles focus state if we are off 128 | if(!m_hasFocus) { 129 | //expand the height for all choices 130 | // setSize(config->gridSize.x - config->padding.x, config->comboBoxHeight * m_choices.size()); 131 | m_hasFocus = true; 132 | //notify that we want to steal all events from the page 133 | m_page->SetEventStealingControl(*this); 134 | } else { 135 | //if we have focus, a click signals that we should lose it 136 | releaseEventStealingFocus(); 137 | } 138 | } 139 | 140 | void ofxSimpleGuiComboBox::onPressOutside(int x, int y, int button){ 141 | if(m_hasFocus) 142 | releaseEventStealingFocus(); 143 | } 144 | 145 | 146 | void ofxSimpleGuiComboBox::onDragOver(int x, int y, int button){ 147 | //same behavior as mouse move 148 | onMouseMove(x,y); 149 | } 150 | 151 | void ofxSimpleGuiComboBox::onDragOutside(int x, int y, int button){ 152 | //same behavior as mouse move 153 | onMouseMove(x,y); 154 | } 155 | 156 | bool ofxSimpleGuiComboBox::hitTest(int tx, int ty) const { 157 | if(!m_hasFocus) 158 | return ofxMSAInteractiveObject::hitTest(tx,ty); 159 | 160 | int fullheight = height + config->comboBoxTextHeight * m_choices.size(); 161 | 162 | return ((tx > x) && (tx < x + width) && (ty > y) && (ty < y + fullheight)); 163 | } 164 | 165 | void ofxSimpleGuiComboBox::onMouseMove(int x, int y) { 166 | m_mouseMovedSinceClick=true; 167 | if(m_hasFocus) { 168 | //see which index was selected. 169 | float fChoice = (y - (height - config->comboBoxTextHeight) - (this->y + config->comboBoxTextHeight))/config->comboBoxTextHeight; 170 | //TODO:replace with OF constrain macro. 171 | m_mouseChoice = fChoice < 0?-1:(fChoice>= m_choices.size()? -1:fChoice); 172 | } 173 | } 174 | 175 | void ofxSimpleGuiComboBox::onReleaseOutside(int x, int y, int button) { 176 | onRelease(x, y, button); 177 | } 178 | 179 | void ofxSimpleGuiComboBox::onRelease(int x, int y, int button) { 180 | if(m_hasFocus && m_mouseMovedSinceClick) { 181 | releaseEventStealingFocus(); 182 | } 183 | } 184 | 185 | void ofxSimpleGuiComboBox::releaseEventStealingFocus(){ 186 | //see which index was selected, but only if the user actually moved around. 187 | m_selectedChoice = m_mouseChoice >= 0? m_mouseChoice : m_selectedChoice; 188 | 189 | //a release toggles focus state if we are on - TODO: unless x and y don't change 190 | m_hasFocus = false; 191 | // setSize(config->gridSize.x - config->padding.x, config->comboBoxHeight); 192 | //also let the page know we don't need to steal all the events and draw over anymore 193 | m_page->ReleaseEventStealingControl(); 194 | } 195 | 196 | //special overloads - this is a hack - later think about making ofxSimpleGuiControl's methods virtual. 197 | void ofxSimpleGuiComboBox::setCBTextColor() { 198 | if(m_hasFocus) ofSetHexColor(config->textOverColor); 199 | else ofSetHexColor(config->textColor); 200 | } 201 | 202 | void ofxSimpleGuiComboBox::setCBTextBGColor() { 203 | if(m_hasFocus) ofSetHexColor(config->textBGOverColor); 204 | else ofSetHexColor(config->textBGColor); 205 | } 206 | 207 | 208 | #define kSGCBTriangleWidth 10 209 | #define KSGCBTrianglePadding 5 210 | #define kSGCBTextPaddingX 3 211 | #define kSGCBTextPaddingY 15 212 | void ofxSimpleGuiComboBox::draw(float x, float y) { 213 | //we assume a max of 256 characters. 214 | char choiceBuf[256]; 215 | 216 | setPosition(x, y); 217 | 218 | ofPushMatrix(); 219 | ofTranslate(x, y, 0); 220 | 221 | ofEnableAlphaBlending(); 222 | ofFill(); 223 | setTextBGColor(); 224 | ofDrawRectangle(0, 0, width, height); 225 | 226 | setTextColor(); 227 | // sprintf(choiceBuf, "%s: %s", m_title, m_choices.size() ? m_choices[m_selectedChoice] : "(No Choices Available)"); 228 | 229 | ofDrawBitmapString(m_title + "\n" + (m_choices.size() ? m_choices[m_selectedChoice] : "N/A"), kSGCBTextPaddingX, kSGCBTextPaddingY); 230 | //draw a combobox down triangle icon so the users know to click 231 | ofDrawTriangle(width - (kSGCBTriangleWidth + KSGCBTrianglePadding), kSGCBTextPaddingY/2, 232 | width - (KSGCBTrianglePadding), kSGCBTextPaddingY/2, 233 | width - (kSGCBTriangleWidth/2 + KSGCBTrianglePadding), kSGCBTextPaddingY); 234 | 235 | if(m_hasFocus) { 236 | setCBTextBGColor(); 237 | ofDrawRectangle(0, height, width, config->comboBoxTextHeight * m_choices.size()); 238 | setTextColor(); 239 | ofDrawLine(0, config->comboBoxHeight-1, width, config->comboBoxHeight-1); 240 | 241 | for(int i=0; i < m_choices.size(); i++) { 242 | setCBTextColor(); 243 | //invert for selected choice 244 | float curY = height + i*config->comboBoxTextHeight; 245 | if(i==m_mouseChoice){ 246 | //draw a text colored rect so we can see the inverse 247 | ofDrawRectangle(0, curY, width, config->comboBoxTextHeight); 248 | setCBTextBGColor(); 249 | } 250 | 251 | ofDrawBitmapString(m_choices[i], kSGCBTextPaddingX, curY + kSGCBTextPaddingY); 252 | } 253 | } 254 | ofDisableAlphaBlending(); 255 | 256 | ofPopMatrix(); 257 | } 258 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiComboBox.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ofxSimpleGuiComboBox.h 3 | * open frameworks simpleguitoo 4 | * 5 | * Created by Michael Chinen on 7/2/10. 6 | * 7 | */ 8 | 9 | #pragma once 10 | 11 | #include "../ofxSimpleGuiControl.h" 12 | 13 | 14 | class ofxSimpleGuiPage; 15 | 16 | class ofxSimpleGuiComboBox : public ofxSimpleGuiControl { 17 | public: 18 | //create a combo box which displays "Name : selection" 19 | //choiceTitles is an array of strings that can be NULL in which case numbers will be used to display the choices 20 | //the titles can be movified later with the below documented add/set/removeChoice methods 21 | ofxSimpleGuiComboBox(string name, int &choice_out, int numChoices, ofxSimpleGuiPage *owner, string* choiceTitles = NULL ) ; 22 | virtual ~ofxSimpleGuiComboBox(); 23 | 24 | void setup(); 25 | #ifndef OFXMSAGUI_DONT_USE_XML 26 | void loadFromXML(ofxXmlSettings &XML); 27 | void saveToXML(ofxXmlSettings &XML); 28 | #endif 29 | void keyPressed( int key ); 30 | void onPress(int x, int y, int button); 31 | void onRelease(int x, int y, int button); 32 | void onReleaseOutside(int x, int y, int button); 33 | void draw(float x, float y); 34 | 35 | //returns the selected index number of the current choice 36 | int getValue(); 37 | 38 | // set the current selected choice to number 39 | void setValue(int index); 40 | 41 | // set the current selected to text 42 | void setValue(string title); 43 | 44 | 45 | // get index for title 46 | int getIndexForTitle(string title); 47 | 48 | //Changes the title of a choice index. index must be valid. 49 | void setTitleForIndex(int index, string title); 50 | 51 | //Get the current choice title an invalid index (default is -1), 52 | //Otherwise get the title of the index asked for. 53 | string getTitleForIndex(int index = -1); 54 | 55 | //Add a new choice with a specified title. 56 | //If an invalid index (default = -1) is used then append to the end. 57 | //If an invalid title is supplied, then the title is set to the index number of the new choice. 58 | void addChoice(string title = NULL, int index = -1); 59 | 60 | //convenience function to remove by a string match. removes the first index that matches 61 | void removeChoice(string title); 62 | 63 | //remove a choice at specified index 64 | //invalid index (default = -1) will remove the last choice in the combo box 65 | void removeChoice(int index = -1); 66 | 67 | virtual void onPressOutside(int x, int y, int button) override; 68 | virtual void onMouseMove(int x, int y) override; 69 | virtual void onDragOver(int x, int y, int button) override; 70 | virtual void onDragOutside(int x, int y, int button) override; 71 | 72 | virtual bool hitTest(int tx, int ty) const override; 73 | 74 | protected: 75 | void setCBTextColor(); 76 | void setCBTextBGColor(); 77 | void releaseEventStealingFocus(); 78 | 79 | int m_mouseChoice; 80 | int &m_selectedChoice; 81 | bool m_hasFocus; 82 | bool m_mouseMovedSinceClick; 83 | string m_title; 84 | vector m_choices; 85 | ofxSimpleGuiPage* m_page; 86 | }; 87 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiContent.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ofxSimpleGuiContent.h" 3 | 4 | 5 | ofxSimpleGuiContent::ofxSimpleGuiContent(string name, ofBaseDraws& content, float fixwidth) : ofxSimpleGuiControl(name) { 6 | this->content = &content; 7 | this->fixwidth = fixwidth; 8 | controlType = "Content"; 9 | setup(); 10 | } 11 | 12 | void ofxSimpleGuiContent::setup() { 13 | fixheight = fixwidth * content->getHeight()/content->getWidth(); 14 | setSize(fixwidth, fixheight + config->sliderTextHeight); 15 | } 16 | 17 | void ofxSimpleGuiContent::draw(float x, float y) { 18 | if(content == NULL) return; 19 | 20 | if(content->getWidth() == 0 && content->getHeight() ==0) return; 21 | 22 | setPosition(x, y); 23 | setup(); 24 | 25 | ofPushMatrix(); 26 | ofTranslate(x, y, 0); 27 | ofEnableAlphaBlending(); 28 | ofFill(); 29 | glColor4f(0, 0, 0, 0.8f); 30 | ofDrawRectangle(0, 0, width, fixheight); 31 | 32 | ofSetHexColor(0xffffff); 33 | content->draw(0, 0, width, fixheight); 34 | 35 | ofFill(); 36 | setTextBGColor(); 37 | ofDrawRectangle(0, fixheight, width, config->sliderTextHeight); 38 | 39 | setTextColor(); 40 | ofDrawBitmapString(name, 3, fixheight + 15); 41 | ofDisableAlphaBlending(); 42 | ofPopMatrix(); 43 | } 44 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiContent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../ofxSimpleGuiControl.h" 4 | 5 | 6 | class ofxSimpleGuiContent : public ofxSimpleGuiControl { 7 | public: 8 | float fixwidth; 9 | float fixheight; 10 | ofBaseDraws *content; 11 | 12 | ofxSimpleGuiContent(string name, ofBaseDraws& content, float fixwidth=250.0); 13 | void setup(); 14 | void draw(float x, float y); 15 | }; 16 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiFPSCounter.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ofxSimpleGuiFPSCounter.h" 3 | 4 | ofxSimpleGuiFPSCounter::ofxSimpleGuiFPSCounter() : ofxSimpleGuiControl("FPS Counter") { 5 | controlType = "FPSCounter"; 6 | setup(); 7 | } 8 | 9 | void ofxSimpleGuiFPSCounter::setup() { 10 | setSize(config->gridSize.x - config->padding.x, config->titleHeight); 11 | } 12 | 13 | 14 | void ofxSimpleGuiFPSCounter::draw(float x, float y) { 15 | setPosition(x, y); 16 | 17 | ofPushMatrix(); 18 | ofTranslate(x, y, 0); 19 | 20 | ofEnableAlphaBlending(); 21 | ofFill(); 22 | setTextBGColor(false); 23 | ofDrawRectangle(0, 0, width, height); 24 | 25 | setTextColor(false); 26 | ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate()), 3, 15); 27 | 28 | ofPopMatrix(); 29 | } 30 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiFPSCounter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../ofxSimpleGuiControl.h" 4 | 5 | class ofxSimpleGuiFPSCounter : public ofxSimpleGuiControl { 6 | public: 7 | ofxSimpleGuiFPSCounter(); 8 | void setup(); 9 | void draw(float x, float y); 10 | }; 11 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiMovieSlider.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/memo/ofxSimpleGuiToo/fd652980aa8fe471c756077192f10f2408121934/src/Controls/ofxSimpleGuiMovieSlider.cpp -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiMovieSlider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | #include "ofxSimpleGuiControl.h" 4 | 5 | #include "ofxSimpleGuiButton.h" 6 | 7 | //------------------------------------------------------------------------------ Movie slider 8 | class ofxSimpleGuiMovieSlider : public ofxSimpleGuiControl { 9 | public: 10 | float pct; 11 | float sliderPos; 12 | float* value; 13 | float barwidth; 14 | ofVideoPlayer* input; 15 | float videoLength; 16 | 17 | ofxSimpleGuiButton* pauseBtn; 18 | ofxSimpleGuiButton* cue1Btn; 19 | ofxSimpleGuiButton* cue2Btn; 20 | ofxSimpleGuiButton* resetBtn; 21 | 22 | bool doPause; 23 | bool cue_1, cue_2, resetCue; 24 | float cuePoint1, cuePoint2; 25 | 26 | //--------------------------------------------------------------------- movie slider 27 | ofxSimpleGuiMovieSlider(string name, ofVideoPlayer* input) : ofxSimpleGuiControl(name) { 28 | setSize(config->gridSize.x - config->padding.x, config->sliderHeight); 29 | 30 | barwidth = 0; 31 | this->input = input; 32 | 33 | //init 34 | if(input) { 35 | videoLength = input->getDuration(); 36 | } 37 | 38 | //Buttons 39 | doPause = false; 40 | pauseBtn = new ofxSimpleGuiButton("Pause", doPause); 41 | cue1Btn = new ofxSimpleGuiButton("Cue 1", cue_1); 42 | cue2Btn = new ofxSimpleGuiButton("Cue 2", cue_2); 43 | resetBtn = new ofxSimpleGuiButton("Reset", resetCue); 44 | 45 | pauseBtn->setToggleMode(true); 46 | resetCue = false; 47 | cue_1 = false; 48 | cue_2 = false; 49 | cuePoint1 = 0.0; 50 | cuePoint2 = 1.0; 51 | controlType = "MovieSlider"; 52 | setup(); 53 | } 54 | 55 | //--------------------------------------------------------------------- update 56 | void update() { 57 | 58 | if(!enabled) return; 59 | 60 | if(!input) return; 61 | if(!lock) barwidth = ofMap(input->getPosition(), 0.0, 1.0, 0.0, (float)width); 62 | 63 | if(resetCue) { 64 | cuePoint1 = 0.0; 65 | cuePoint2 = 1.0; 66 | input->setPosition(0.0); 67 | resetCue = false; 68 | } 69 | if(cue_1) { 70 | cuePoint1 = input->getPosition(); 71 | cue_1 = false; 72 | } 73 | if(cue_2) { 74 | cuePoint2 = input->getPosition(); 75 | cue_2 = false; 76 | } 77 | if(!lock) { 78 | if(input->getPosition() >= cuePoint2) { 79 | input->setPosition(cuePoint1); 80 | } 81 | else if(input->getPosition() <= cuePoint1) { 82 | input->setPosition(cuePoint1); 83 | } 84 | } 85 | enabled = false; 86 | } 87 | 88 | //--------------------------------------------------------------------- mouse dragged 89 | void onDragOver(int x, int y, int buton) { 90 | if(lock) { 91 | //cuePoint1 = 0.0; 92 | //cuePoint2 = 1.0; 93 | 94 | barwidth = x - this->x; 95 | if(barwidth <= 0) barwidth = 0; 96 | if(barwidth >= width) barwidth = width; 97 | 98 | input->setPaused(true); 99 | input->setPosition(ofMap(barwidth, 0.0, (float)width, 0.0, 1.0)); 100 | } 101 | } 102 | 103 | //--------------------------------------------------------------------- mouse pressed 104 | void onPress(int x, int y, int button) { 105 | //cuePoint1 = 0.0; 106 | //cuePoint2 = 1.0; 107 | lock = true; 108 | input->setPaused(true); 109 | barwidth = x - this->x; 110 | input->setPaused(true); 111 | input->setPosition(ofMap(barwidth, 0.0, (float)width, 0.0, 1.0)); 112 | } 113 | 114 | //--------------------------------------------------------------------- mouse released 115 | void onRelease() { 116 | lock = false; 117 | input->play(); 118 | input->setPaused(doPause); 119 | } 120 | 121 | 122 | void draw(float x, float y) { 123 | 124 | enabled = true; 125 | //update postion of gui object 126 | setPosition(x, y); 127 | 128 | glPushMatrix(); 129 | glTranslatef(x, y, 0); 130 | ofEnableAlphaBlending(); 131 | ofFill(); 132 | ofSetColor(255, 255, 255, 200); 133 | // if(isMouseOver()) ofSetHexColor(config->overColor.r, config->overColor.g, config->overColor.b); 134 | // if(focused && !isMouseOver()) ofSetHexColor(config->focusColor.r, config->focusColor.g, config->focusColor.b); 135 | ofRect(0, 0, width, height); 136 | 137 | setFullColor(); 138 | ofRect(0, 0, barwidth, height); 139 | 140 | ofSetHexColor(config->textBGColor); 141 | ofRect(0, height, width, 20); 142 | ofSetHexColor(config->textColor); 143 | float inputpos = ofMap(input->getPosition(), 0.0, 1.0, 0.0, videoLength); 144 | ostringstream info; 145 | info << name << ":" << ofToString(inputpos, 3) << "/" << ofToString(videoLength, 3) << endl; 146 | ofDrawBitmapString(info.str(), 3, height+15); 147 | 148 | // cues 149 | // if(cuePoint1 > 0.0) { 150 | // ofSetHexColor(config->overColor.r, config->overColor.g, config->overColor.b, 200); 151 | // ofRect(ofMap(cuePoint1, 0.0, 1.0, 0.0, width), 0, 1, height); 152 | // } 153 | // if(cuePoint2 < 1.0) { 154 | // ofSetHexColor(config->overColor.r, config->overColor.g, config->overColor.b, 200); 155 | // ofRect(ofMap(cuePoint2, 0.0, 1.0, 0.0, width), 0, 1, height); 156 | // } 157 | 158 | ofDisableAlphaBlending(); 159 | glPopMatrix(); 160 | 161 | 162 | 163 | // a bit of a hack but for simple no images to load :) 164 | pauseBtn->draw(x, y+35); 165 | cue1Btn->draw(x+23, y+35); 166 | cue2Btn->draw(x+46, y+35); 167 | resetBtn->draw(x+69, y+35); 168 | 169 | ofSetHexColor(0xffffff); 170 | ofDrawBitmapString("1", x+30, y+49); 171 | ofDrawBitmapString("2", x+53, y+49); 172 | ofDrawBitmapString("R", x+76, y+49); 173 | 174 | ofSetHexColor(0xffffff); 175 | ofFill(); 176 | 177 | if(!doPause) { 178 | ofRect(x+6, y+38, 2, 14); 179 | ofRect(x+13, y+38, 2, 14); 180 | } 181 | else if(doPause){ 182 | glPushMatrix(); 183 | glTranslatef(x+6, y+37, 0); 184 | ofTriangle(0, 0, 0, 16, 8, 8); 185 | glPopMatrix(); 186 | } 187 | 188 | } 189 | 190 | }; 191 | */ 192 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiQuadWarp.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ofxSimpleGuiQuadWarp.h" 3 | 4 | #define MOUSE_DISTANCE 10.0f 5 | 6 | //--------------------------------------------------------------------- 7 | ofxSimpleGuiQuadWarp::ofxSimpleGuiQuadWarp(string name, ofBaseDraws &baseDraw, ofPoint *pts) : ofxSimpleGuiControl(name) { 8 | this->baseDraw = &baseDraw; 9 | 10 | setPosition(0, 0); 11 | // setSize(baseDraw.getWidth(), baseDraw.getHeight()); 12 | 13 | curPoint = NULL; 14 | this->pts = pts; 15 | 16 | for(int i=0; i<4; i++) pts[i].z = i; // z axis stores the index 17 | 18 | controlType = "QuadWarp"; 19 | setup(); 20 | } 21 | 22 | void ofxSimpleGuiQuadWarp::setup() { 23 | 24 | } 25 | 26 | 27 | #ifndef OFXMSAGUI_DONT_USE_XML 28 | void ofxSimpleGuiQuadWarp::loadFromXML(ofxXmlSettings &XML) { 29 | for(int i=0; i<4; i++) { 30 | pts[i].x = XML.getValue(controlType + "_" + key + ":values_" + ofToString(i) + "_x", pts[i].x); 31 | pts[i].y = XML.getValue(controlType + "_" + key + ":values_" + ofToString(i) + "_y", pts[i].y); 32 | } 33 | } 34 | 35 | void ofxSimpleGuiQuadWarp::saveToXML(ofxXmlSettings &XML) { 36 | XML.addTag(controlType + "_" + key); 37 | XML.pushTag(controlType + "_" + key); 38 | XML.addValue("name", name); 39 | for(int i=0; i<4; i++) { 40 | XML.addValue("values_" + ofToString(i) + "_x", pts[i].x); 41 | XML.addValue("values_" + ofToString(i) + "_y", pts[i].y); 42 | } 43 | XML.popTag(); 44 | } 45 | #endif 46 | 47 | 48 | //--------------------------------------------------------------------- 49 | void ofxSimpleGuiQuadWarp::onPress(int x, int y, int button) { 50 | curPoint = NULL; 51 | for(int i=0; i<4; i++) { 52 | if(ofDistSquared(x - this->x, y - this->y, pts[i].x, pts[i].y) < MOUSE_DISTANCE * MOUSE_DISTANCE) { 53 | curPoint = pts + i; 54 | } 55 | } 56 | 57 | // if doubleclick, reset 58 | if(ofDistSquared(x, y, lastPressPlace.x, lastPressPlace.y) < MOUSE_DISTANCE * MOUSE_DISTANCE && ofGetElapsedTimef() - lastPressTime < 0.25f) { 59 | // pts[0].set(0, 0); 60 | // pts[1].set(width, 0); 61 | // pts[2].set(width, height); 62 | // pts[3].set(0, height); 63 | if(curPoint) { 64 | switch((int)curPoint->z) { // stores index of point 65 | case 0: pts[0].set(0, 0); break; 66 | case 1: pts[1].set(width, 0); break; 67 | case 2: pts[2].set(width, height); break; 68 | case 3: pts[3].set(0, height); break; 69 | } 70 | } 71 | } 72 | 73 | lastPressPlace.set(x, y); 74 | lastPressTime = ofGetElapsedTimef(); 75 | } 76 | 77 | void ofxSimpleGuiQuadWarp::onPressOutside(int x, int y, int button) { 78 | onPress(x, y, button); 79 | } 80 | 81 | 82 | void ofxSimpleGuiQuadWarp::onDragOver(int x, int y, int button) { 83 | if(curPoint) { 84 | curPoint->set(x - this->x, y - this->y); 85 | } 86 | 87 | } 88 | 89 | //--------------------------------------------------------------------- 90 | void ofxSimpleGuiQuadWarp::onDragOutside(int x, int y, int button) { 91 | onDragOver(x, y, button); 92 | } 93 | 94 | 95 | 96 | //--------------------------------------------------------------------- 97 | void ofxSimpleGuiQuadWarp::draw(float x, float y) { 98 | setPosition(x, y); 99 | ofPushMatrix(); 100 | ofTranslate(x, y, 0); 101 | ofSetColor(ofFloatColor(1, 1, 1)); 102 | baseDraw->draw(0, 0); 103 | 104 | ofEnableAlphaBlending(); 105 | ofFill(); 106 | 107 | for(int i=0; i<4; i++) { 108 | if(curPoint == &pts[i]) { 109 | ofSetColor(255, 0, 0); 110 | ofDrawCircle(pts[i].x, pts[i].y, 4); 111 | } else { 112 | ofSetColor(0, 255, 0); 113 | ofDrawCircle(pts[i].x, pts[i].y, 2); 114 | } 115 | 116 | } 117 | 118 | 119 | ofBeginShape(); 120 | ofNoFill(); 121 | ofSetColor(255, 255, 255); 122 | for(int i=0; i<4; i++) { 123 | ofVertex(pts[i].x, pts[i].y); 124 | } 125 | ofEndShape(TRUE); 126 | ofDisableAlphaBlending(); 127 | 128 | ofPopMatrix(); 129 | } 130 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiQuadWarp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../ofxSimpleGuiControl.h" 4 | 5 | 6 | //------------------------------------------------------------------------------ quad warp 7 | class ofxSimpleGuiQuadWarp : public ofxSimpleGuiControl { 8 | public: 9 | ofPoint *pts; 10 | ofPoint *curPoint; 11 | ofBaseDraws *baseDraw; 12 | 13 | // for doubleclick 14 | ofPoint lastPressPlace; 15 | float lastPressTime; 16 | 17 | ofxSimpleGuiQuadWarp(string name, ofBaseDraws &baseDraw, ofPoint *pts); 18 | void setup(); 19 | #ifndef OFXMSAGUI_DONT_USE_XML 20 | void loadFromXML(ofxXmlSettings &XML); 21 | void saveToXML(ofxXmlSettings &XML); 22 | #endif 23 | void onPress(int x, int y, int button); 24 | void onPressOutside(int x, int y, int button); 25 | void onDragOver(int x, int y, int button); 26 | void onDragOutside(int x, int y, int button); 27 | void draw(float x, float y); 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiSlider2d.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ofxSimpleGuiSlider2d.h" 3 | 4 | 5 | ofxSimpleGuiSlider2d::ofxSimpleGuiSlider2d(string name, ofPoint& value, float xmin, float xmax, float ymin, float ymax) : ofxSimpleGuiControl(name) { 6 | min.set(xmin, ymin); 7 | max.set(xmax, ymax); 8 | this->value = &value; 9 | controlType = "Slider2D"; 10 | setup(); 11 | } 12 | 13 | void ofxSimpleGuiSlider2d::setup() { 14 | setSize(config->slider2DSize.x, config->slider2DSize.y + config->slider2DTextHeight); 15 | point.x = ofMap((*value).x, min.x, max.x, x, x+width); 16 | point.y = ofMap((*value).y, min.y, max.y, y, y+height-config->slider2DTextHeight); 17 | } 18 | 19 | #ifndef OFXMSAGUI_DONT_USE_XML 20 | void ofxSimpleGuiSlider2d::loadFromXML(ofxXmlSettings &XML) { 21 | value->set(XML.getValue(controlType + "_" + key + ":valueX", value->x), XML.getValue(controlType + "_" + key + ":valueY", value->y)); 22 | } 23 | 24 | 25 | void ofxSimpleGuiSlider2d::saveToXML(ofxXmlSettings &XML) { 26 | XML.addTag(controlType + "_" + key); 27 | XML.pushTag(controlType + "_" + key); 28 | XML.addValue("name", name); 29 | XML.addValue("valueX", value->x); 30 | XML.addValue("valueY", value->y); 31 | XML.popTag(); 32 | } 33 | #endif 34 | 35 | void ofxSimpleGuiSlider2d::setValue(float x, float y) { 36 | (*value).x = x; 37 | (*value).y = y; 38 | } 39 | 40 | void ofxSimpleGuiSlider2d::setMin(float x, float y) { 41 | min.x = x; 42 | min.y = y; 43 | } 44 | 45 | void ofxSimpleGuiSlider2d::setMax(float x, float y) { 46 | max.x = x; 47 | max.y = y; 48 | } 49 | 50 | void ofxSimpleGuiSlider2d::onPress(int x, int y, int button) { 51 | lock = true; 52 | point.set(x, y); 53 | } 54 | 55 | void ofxSimpleGuiSlider2d::onDragOver(int x, int y, int button) { 56 | if(lock) { 57 | point.set(x, y); 58 | } 59 | } 60 | 61 | void ofxSimpleGuiSlider2d::onDragOutside(int x, int y, int button) { 62 | if(lock) { 63 | point.set(x, y); 64 | } 65 | } 66 | 67 | void ofxSimpleGuiSlider2d::onRelease() { 68 | lock = false; 69 | } 70 | 71 | void ofxSimpleGuiSlider2d::update() { 72 | if(point.x > x + width) point.x = x + width; 73 | else if(point.x < x) point.x = x; 74 | 75 | if(point.y > y+height - config->slider2DTextHeight) point.y = y + height - config->slider2DTextHeight; 76 | else if(point.y < y) point.y = y; 77 | 78 | if(lock){ 79 | (*value).x = ofMap(point.x, x, x+width, min.x, max.x); 80 | (*value).y = ofMap(point.y, y, y+height-config->slider2DTextHeight, min.y, max.y); 81 | } 82 | } 83 | 84 | void ofxSimpleGuiSlider2d::draw(float x, float y) { 85 | setPosition(x, y); 86 | ofPoint pointv; 87 | pointv.x = ofMap((*value).x, min.x, max.x, x, x+width); 88 | pointv.y = ofMap((*value).y, min.y, max.y, y, y+height-config->slider2DTextHeight); 89 | 90 | ofEnableAlphaBlending(); 91 | ofPushMatrix(); 92 | ofTranslate(x, y, 0); 93 | 94 | ofFill(); 95 | setFullColor(); 96 | ofDrawRectangle(0, 0, width, height - config->slider2DTextHeight); 97 | 98 | ofFill(); 99 | setTextBGColor(); 100 | ofDrawRectangle(0, height-config->slider2DTextHeight, width, config->slider2DTextHeight); 101 | 102 | setTextColor(); 103 | ofDrawBitmapString(name+"\nx:"+ofToString(value->x, 2)+"\ny:"+ofToString(value->y, 2), 3, height+15-config->slider2DTextHeight); 104 | 105 | setTextColor(); 106 | ofDrawCircle(pointv.x-x, pointv.y-y, 2); 107 | 108 | setTextColor(); 109 | ofDrawLine(pointv.x-x, 0, pointv.x-x, height-config->slider2DTextHeight); 110 | ofDrawLine(0, pointv.y-y,width, pointv.y-y); 111 | 112 | ofPopMatrix(); 113 | ofDisableAlphaBlending(); 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiSlider2d.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../ofxSimpleGuiControl.h" 4 | 5 | 6 | class ofxSimpleGuiSlider2d : public ofxSimpleGuiControl { 7 | public: 8 | ofPoint *value; 9 | ofPoint point, min, max; 10 | 11 | ofxSimpleGuiSlider2d(string name, ofPoint& value, float xmin, float xmax, float ymin, float ymax); 12 | void setup(); 13 | #ifndef OFXMSAGUI_DONT_USE_XML 14 | void loadFromXML(ofxXmlSettings &XML); 15 | void saveToXML(ofxXmlSettings &XML); 16 | #endif 17 | void setValue(float x, float y); 18 | void setMin(float x, float y); 19 | void setMax(float x, float y); 20 | void onPress(int x, int y, int button); 21 | void onDragOver(int x, int y, int button); 22 | void onDragOutside(int x, int y, int button); 23 | void onRelease(); 24 | void update(); 25 | void draw(float x, float y); 26 | }; 27 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiSliderBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofxSimpleGuiControl.h" 4 | 5 | 6 | 7 | template class ofxSimpleGuiSliderBase : public ofxSimpleGuiControl { 8 | public: 9 | 10 | Type *value; 11 | Type min, max; 12 | 13 | float barwidth; 14 | float pct; 15 | 16 | float lerpSpeed; 17 | Type targetValue; 18 | Type oldValue; 19 | Type increment; 20 | 21 | //--------------------------------------------------------------------- construct 22 | ofxSimpleGuiSliderBase(string name, Type &value, Type min, Type max) : ofxSimpleGuiControl(name) { 23 | this->value = &value; 24 | setMin(min); 25 | setMax(max); 26 | 27 | targetValue = value; 28 | oldValue = targetValue; 29 | controlType = "SliderBase"; 30 | 31 | setIncrement(0); 32 | setSmoothing(0); 33 | 34 | setup(); 35 | } 36 | 37 | void setMin(Type m) { 38 | min = m; 39 | } 40 | 41 | void setMax(Type m) { 42 | max = m; 43 | } 44 | 45 | void setup() { 46 | setSize(config->gridSize.x - config->padding.x, config->sliderHeight + config->sliderTextHeight); 47 | pct = ofMap((*value), min, max, 0.0, width); 48 | barwidth = pct; 49 | } 50 | 51 | #ifndef OFXMSAGUI_DONT_USE_XML 52 | void loadFromXML(ofxXmlSettings &XML) { 53 | setValue((Type)XML.getValue(controlType + "_" + key + ":value", getValue())); 54 | } 55 | 56 | void saveToXML(ofxXmlSettings &XML) { 57 | XML.addTag(controlType + "_" + key); 58 | XML.pushTag(controlType + "_" + key); 59 | XML.addValue("name", name); 60 | XML.addValue("value", getValue()); 61 | XML.popTag(); 62 | } 63 | #endif 64 | 65 | void setSmoothing(float smoothing) { 66 | lerpSpeed = 1.0f - smoothing * 0.9; // so smoothing :1 still results in some motion! 67 | } 68 | 69 | void setIncrement(Type increment) { 70 | this->increment = increment; 71 | } 72 | 73 | 74 | 75 | Type getValue() { 76 | return (*value); 77 | } 78 | 79 | 80 | void setValue(Type f) { 81 | setTargetValue(f); 82 | oldValue = *value = targetValue; 83 | } 84 | 85 | void setTargetValue(Type f) { 86 | targetValue = ofClamp(f, min, max); 87 | } 88 | 89 | 90 | void increase() { 91 | if(increment == 0) setIncrement((max - min) * 0.001); 92 | // oldValue = *value; // save oldValue (so the draw doesn't update target but uses it) 93 | setTargetValue(*value + increment); 94 | } 95 | 96 | void decrease() { 97 | if(increment == 0) setIncrement((max - min) * 0.001); 98 | // oldValue = *value; // save oldValue (so the draw doesn't update target but uses it) 99 | setTargetValue(*value - increment); 100 | } 101 | 102 | 103 | void updateSlider() { 104 | if(!enabled) return; 105 | 106 | if(pct > width) { 107 | pct = width; 108 | } 109 | else { 110 | pct = getMouseX() - x; 111 | float temp = ofMap(pct, 0.0, width, min, max, true); 112 | 113 | targetValue = (Type)temp; 114 | oldValue = *value; // save oldValue (so the draw doesn't update target but uses it) 115 | } 116 | } 117 | 118 | void onPress(int x, int y, int button) { 119 | updateSlider(); 120 | } 121 | 122 | void onDragOver(int x, int y, int button) { 123 | updateSlider(); 124 | } 125 | 126 | void onDragOutside(int x, int y, int button) { 127 | updateSlider(); 128 | } 129 | 130 | 131 | 132 | void onKeyRight() { 133 | increase(); 134 | } 135 | 136 | void onKeyLeft() { 137 | decrease(); 138 | } 139 | 140 | void onKeyUp() { 141 | increase(); 142 | } 143 | 144 | void onKeyDown() { 145 | decrease(); 146 | } 147 | 148 | 149 | //--------------------------------------------------------------------- update 150 | void update() { 151 | if(!enabled) return; 152 | 153 | if(oldValue != *value) { // if value has changed programmatically by something else 154 | oldValue = targetValue = *value; // save the value in target and oldvalue 155 | } else { // otherwise lerp 156 | *value += (Type)((targetValue - *value) * lerpSpeed); 157 | oldValue = *value; // and save oldvalue 158 | } 159 | 160 | if(lock) { 161 | updateSlider(); 162 | } 163 | 164 | // enabled = false; 165 | 166 | } 167 | 168 | //--------------------------------------------------------------------- draw 169 | void draw(float x, float y) { 170 | 171 | // enabled = true; 172 | 173 | //update postion of gui object 174 | setPosition(x, y); 175 | 176 | //VALUE CLAMP 177 | barwidth = ofMap((*value), min, max, 0.0, (float)width); 178 | if(barwidth > width) barwidth = width; 179 | else if(barwidth < 0) barwidth = 0; 180 | 181 | ofEnableAlphaBlending(); 182 | ofPushMatrix(); 183 | ofTranslate(x, y, 0); 184 | ofFill(); 185 | 186 | setEmptyColor(); 187 | ofDrawRectangle(0, 0, width, config->sliderHeight); 188 | 189 | 190 | setFullColor(); 191 | ofDrawRectangle(0, 0, barwidth, config->sliderHeight); 192 | 193 | setTextBGColor(); 194 | ofDrawRectangle(0, config->sliderHeight, width, config->sliderTextHeight); 195 | 196 | setTextColor(); 197 | string s = name + ": " + ofToString((*value)); 198 | ofDrawBitmapString(s, 3, config->sliderHeight + 14); 199 | ofDisableAlphaBlending(); 200 | ofPopMatrix(); 201 | } 202 | 203 | 204 | 205 | }; 206 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiSliderFloat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofxSimpleGuiControl.h" 4 | 5 | #include "ofxSimpleGuiSliderBase.h" 6 | 7 | 8 | class ofxSimpleGuiSliderFloat : public ofxSimpleGuiSliderBase { 9 | 10 | public: 11 | ofxSimpleGuiSliderFloat(string name, float &value, float min, float max) : ofxSimpleGuiSliderBase(name, value, min, max) { 12 | controlType = "SliderFloat"; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiSliderInt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofxSimpleGuiControl.h" 4 | 5 | #include "ofxSimpleGuiSliderBase.h" 6 | 7 | 8 | class ofxSimpleGuiSliderInt : public ofxSimpleGuiSliderBase { 9 | 10 | public: 11 | ofxSimpleGuiSliderInt(string name, int &value, int min, int max) : ofxSimpleGuiSliderBase(name, value, min, max) { 12 | controlType = "SliderInt"; 13 | setIncrement(1); 14 | } 15 | 16 | }; 17 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiTitle.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ofxSimpleGuiTitle.h" 3 | 4 | ofxSimpleGuiTitle::ofxSimpleGuiTitle(string name, float height) : ofxSimpleGuiControl(name) { 5 | beToggle = false; 6 | beenPressed = false; 7 | // this->value = &value; 8 | value = NULL; 9 | controlType = "Title"; 10 | // newColumn = true; 11 | 12 | if(height == 0) height = config->titleHeight; 13 | if(hasTitle == false) height/=2; 14 | setSize(config->gridSize.x - config->padding.x, height); 15 | setup(); 16 | } 17 | 18 | void ofxSimpleGuiTitle::setup() { 19 | } 20 | 21 | #ifndef OFXMSAGUI_DONT_USE_XML 22 | void ofxSimpleGuiTitle::loadFromXML(ofxXmlSettings &XML) { 23 | if(!value) return; 24 | setValue(XML.getValue(controlType + "_" + key + ":value", getValue())); 25 | } 26 | 27 | void ofxSimpleGuiTitle::saveToXML(ofxXmlSettings &XML) { 28 | if(!value) return; 29 | XML.addTag(controlType + "_" + key); 30 | XML.pushTag(controlType + "_" + key); 31 | XML.addValue("name", name); 32 | XML.addValue("value", getValue()); 33 | XML.popTag(); 34 | } 35 | #endif 36 | 37 | bool ofxSimpleGuiTitle::getValue() { 38 | if(!value) return false; 39 | return (*value); 40 | } 41 | void ofxSimpleGuiTitle::setValue(bool b) { 42 | if(!value) return; 43 | (*value) = b; 44 | } 45 | void ofxSimpleGuiTitle::toggle() { 46 | if(!value) return; 47 | (*value) = !(*value); 48 | } 49 | 50 | void ofxSimpleGuiTitle::setToggleMode(bool b) { 51 | if(!value) return; 52 | beToggle = b; 53 | } 54 | 55 | void ofxSimpleGuiTitle::onPress(int x, int y, int button) { 56 | if(!value) return; 57 | beenPressed = true; 58 | if(beToggle) (*value) = !(*value); 59 | else (*value) = true; 60 | } 61 | 62 | void ofxSimpleGuiTitle::onRelease(int x, int y, int button) { 63 | if(!value) return; 64 | if(!beToggle) (*value) = false; 65 | } 66 | 67 | void ofxSimpleGuiTitle::draw(float x, float y) { 68 | setPosition(x, y); 69 | 70 | if(hasTitle == false) return; 71 | 72 | ofPushMatrix(); 73 | ofTranslate(x, y, 0); 74 | 75 | ofEnableAlphaBlending(); 76 | ofFill(); 77 | // setTextBGColor(value != NULL); 78 | // ofSetColor(0, 0, 0); 79 | ofSetHexColor(config->fullActiveColor); 80 | ofDrawRectangle(0, 0, width, height); 81 | 82 | // if a toggle 83 | if(value && (*value) && beToggle) { 84 | setTextColor(); 85 | //ofLine(0, 0, box.width, box.height); 86 | //ofLine(box.width, 0, 0, box.height); 87 | } 88 | 89 | setTextColor(value != NULL); 90 | ofDrawBitmapString(name, 3, 15); 91 | 92 | ofDisableAlphaBlending(); 93 | 94 | ofPopMatrix(); 95 | } 96 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiTitle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../ofxSimpleGuiControl.h" 4 | 5 | class ofxSimpleGuiTitle : public ofxSimpleGuiControl { 6 | 7 | public: 8 | 9 | bool* value; 10 | bool beToggle; 11 | bool beenPressed; 12 | 13 | ofxSimpleGuiTitle(string name, float height); 14 | void setup(); 15 | 16 | #ifndef OFXMSAGUI_DONT_USE_XML 17 | void loadFromXML(ofxXmlSettings &XML); 18 | void saveToXML(ofxXmlSettings &XML); 19 | #endif 20 | 21 | bool getValue(); 22 | void setValue(bool b); 23 | void toggle(); 24 | void setToggleMode(bool b); 25 | void onPress(int x, int y, int button); 26 | void onRelease(int x, int y, int button); 27 | void draw(float x, float y); 28 | }; 29 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiToggle.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ofxSimpleGuiToggle.h" 3 | 4 | 5 | ofxSimpleGuiToggle::ofxSimpleGuiToggle(string name, bool &value) : ofxSimpleGuiControl(name) { 6 | this->value = &value; 7 | setMomentary(false); 8 | controlType = "Toggle"; 9 | setup(); 10 | } 11 | 12 | ofxSimpleGuiToggle& ofxSimpleGuiToggle::setMomentary(bool m) { 13 | momentary = m; 14 | return *this; 15 | } 16 | 17 | 18 | void ofxSimpleGuiToggle::setup() { 19 | setSize(config->gridSize.x - config->padding.x, config->toggleHeight); 20 | } 21 | 22 | #ifndef OFXMSAGUI_DONT_USE_XML 23 | void ofxSimpleGuiToggle::loadFromXML(ofxXmlSettings &XML) { 24 | setValue(XML.getValue(controlType + "_" + key + ":value", getValue())); 25 | } 26 | 27 | void ofxSimpleGuiToggle::saveToXML(ofxXmlSettings &XML) { 28 | XML.addTag(controlType + "_" + key); 29 | XML.pushTag(controlType + "_" + key); 30 | XML.addValue("name", name); 31 | XML.addValue("value", getValue()); 32 | XML.popTag(); 33 | } 34 | #endif 35 | 36 | bool ofxSimpleGuiToggle::getValue() { 37 | return (*value); 38 | } 39 | 40 | void ofxSimpleGuiToggle::setValue(bool b) { 41 | (*value) = b; 42 | } 43 | 44 | void ofxSimpleGuiToggle::toggle() { 45 | (*value) = !(*value); 46 | } 47 | 48 | void ofxSimpleGuiToggle::onPress(int x, int y, int button) { 49 | if(momentary) setValue(true); 50 | else toggle(); 51 | } 52 | 53 | void ofxSimpleGuiToggle::onRelease(int x, int y, int button) { 54 | if(momentary) setValue(false); 55 | } 56 | 57 | void ofxSimpleGuiToggle::keyPressed( int key ) { 58 | if(key==keyboardShortcut) onPress(0, 0, 0); 59 | } 60 | 61 | void ofxSimpleGuiToggle::keyReleased( int key ) { 62 | if(key==keyboardShortcut) onRelease(0, 0, 0); 63 | } 64 | 65 | void ofxSimpleGuiToggle::onKeyEnter() { 66 | toggle(); 67 | } 68 | 69 | void ofxSimpleGuiToggle::update() { 70 | // if(!enabled) return; 71 | // enabled = false; 72 | } 73 | 74 | void ofxSimpleGuiToggle::draw(float x, float y) { 75 | // enabled = true; 76 | setPosition(x, y); 77 | 78 | ofPushMatrix(); 79 | ofTranslate(x, y, 0); 80 | 81 | ofEnableAlphaBlending(); 82 | ofFill(); 83 | setFullColor(*value); 84 | ofDrawRectangle(0, 0, height, height); 85 | 86 | if((*value)) { 87 | setTextColor(); 88 | ofDrawLine(0, 0, height, height); 89 | ofDrawLine(height, 0, 0, height); 90 | } 91 | 92 | setTextBGColor(); 93 | ofDrawRectangle(height, 0, width - height, height); 94 | 95 | setTextColor(); 96 | ofDrawBitmapString(name, height + 15, 15); 97 | ofDisableAlphaBlending(); 98 | 99 | ofPopMatrix(); 100 | } 101 | 102 | -------------------------------------------------------------------------------- /src/Controls/ofxSimpleGuiToggle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../ofxSimpleGuiControl.h" 4 | 5 | 6 | class ofxSimpleGuiToggle : public ofxSimpleGuiControl { 7 | 8 | public: 9 | bool *value; 10 | bool momentary; 11 | 12 | ofxSimpleGuiToggle(string name, bool &value); 13 | ofxSimpleGuiToggle& setMomentary(bool m); 14 | void setup(); 15 | 16 | #ifndef OFXMSAGUI_DONT_USE_XML 17 | void loadFromXML(ofxXmlSettings &XML); 18 | void saveToXML(ofxXmlSettings &XML); 19 | #endif 20 | 21 | bool getValue(); 22 | void setValue(bool b); 23 | void toggle(); 24 | void onPress(int x, int y, int button); 25 | void onRelease(int x, int y, int button); 26 | void keyPressed( int key ); 27 | void keyReleased( int key ); 28 | void onKeyEnter(); 29 | void update(); 30 | void draw(float x, float y); 31 | }; 32 | -------------------------------------------------------------------------------- /src/ofxSimpleGuiConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "ofxSimpleGuiConfig.h" 2 | 3 | ofxSimpleGuiConfig defaultSimpleGuiConfig; 4 | 5 | 6 | ofxSimpleGuiConfig::ofxSimpleGuiConfig() { 7 | 8 | sliderHeight = 10; 9 | sliderTextHeight = 22; 10 | titleHeight = sliderHeight + sliderTextHeight; 11 | toggleHeight = titleHeight; 12 | buttonHeight = titleHeight; 13 | slider2DTextHeight = titleHeight * 1.5; 14 | comboBoxHeight = titleHeight; //15 15 | comboBoxTextHeight = 15; 16 | 17 | 18 | padding.set (titleHeight/2, 5); 19 | offset.set (titleHeight/2, titleHeight/2); 20 | slider2DSize.set (titleHeight * 4, titleHeight * 4); 21 | 22 | gridSize.x = 200 + padding.x; 23 | gridSize.y = toggleHeight + padding.y; 24 | 25 | textColor = 0x888888; 26 | textOverColor = 0xFFFFFF; 27 | textBGColor = 0x000000; 28 | textBGOverColor = 0x222222; 29 | 30 | fullColor = 0xaaaaaa; 31 | fullOverColor = 0xffffff; 32 | fullActiveColor = 0x881818; 33 | emptyColor = 0x333333; 34 | 35 | borderColor = 0x333333; 36 | } -------------------------------------------------------------------------------- /src/ofxSimpleGuiConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofTypes.h" 4 | #include "ofPoint.h" 5 | 6 | class ofxSimpleGuiConfig { 7 | public: 8 | ofPoint gridSize; 9 | 10 | float buttonHeight; 11 | float toggleHeight; 12 | float sliderHeight; 13 | float sliderTextHeight; 14 | float slider2DTextHeight; 15 | float titleHeight; 16 | float comboBoxHeight; 17 | float comboBoxTextHeight; 18 | 19 | ofPoint padding; 20 | ofPoint offset; 21 | ofPoint slider2DSize; 22 | 23 | int textColor; 24 | int textOverColor; 25 | int textBGColor; 26 | int textBGOverColor; 27 | 28 | int fullColor; 29 | int fullOverColor; 30 | int fullActiveColor; 31 | int emptyColor; 32 | int borderColor; 33 | 34 | ofxSimpleGuiConfig(); 35 | }; 36 | 37 | 38 | extern ofxSimpleGuiConfig defaultSimpleGuiConfig; 39 | 40 | -------------------------------------------------------------------------------- /src/ofxSimpleGuiControl.cpp: -------------------------------------------------------------------------------- 1 | #include "ofxSimpleGuiControl.h" 2 | 3 | 4 | ofxSimpleGuiControl::ofxSimpleGuiControl(string name) { 5 | controlType = ""; 6 | this->config = &defaultSimpleGuiConfig; 7 | setName(name); 8 | setKey(key); 9 | setPosition(0, 0); 10 | lock = false; 11 | focused = false; 12 | newColumn = false; 13 | setKeyboardShortcut(0); 14 | 15 | setup(); 16 | 17 | disableAllEvents(); // just for safety to make sure nothing is registered twice 18 | // enableAppEvents(); 19 | // enableMouseEvents(); 20 | // disableKeyEvents(); 21 | } 22 | 23 | ofxSimpleGuiControl &ofxSimpleGuiControl::setConfig(ofxSimpleGuiConfig *config) { 24 | this->config = config; 25 | setup(); 26 | return *this; 27 | } 28 | 29 | ofxSimpleGuiControl &ofxSimpleGuiControl::setNewColumn(bool b) { 30 | newColumn = b; 31 | return *this; 32 | } 33 | 34 | 35 | 36 | ofxSimpleGuiControl &ofxSimpleGuiControl::setName(string newName) { 37 | name = newName; 38 | origName = name; 39 | if(key.compare("") == 0) setKey(""); // if key has not been set yet, set name as key too 40 | 41 | hasTitle = (name.compare("") != 0); 42 | return *this; 43 | } 44 | 45 | 46 | ofxSimpleGuiControl &ofxSimpleGuiControl::setKey(string newKey) { 47 | if(newKey.compare("") == 0) key = name; 48 | else key = newKey; 49 | for(int i=0; itextOverColor); 57 | else ofSetHexColor(config->textColor); 58 | return *this; 59 | } 60 | 61 | ofxSimpleGuiControl &ofxSimpleGuiControl::setTextBGColor(bool clickable) { 62 | if(isMouseOver() && clickable) ofSetHexColor(config->textBGOverColor); 63 | else ofSetHexColor(config->textBGColor); 64 | return *this; 65 | } 66 | 67 | ofxSimpleGuiControl &ofxSimpleGuiControl::setFullColor(bool forceActive) { 68 | if(isMousePressed() || forceActive) ofSetHexColor(config->fullActiveColor); 69 | else if(isMouseOver()) ofSetHexColor(config->fullOverColor); 70 | else ofSetHexColor(config->fullColor); 71 | return *this; 72 | } 73 | 74 | ofxSimpleGuiControl &ofxSimpleGuiControl::setEmptyColor() { 75 | ofSetHexColor(config->emptyColor); 76 | // if(isMouseOver()) ofSetHexColor(config->overColor.r, config->overColor.g, config->overColor.b); 77 | // if(focused && !isMouseOver()) ofSetHexColor(config->focusColor.r, config->focusColor.g, config->focusColor.b); 78 | return *this; 79 | } 80 | 81 | ofxSimpleGuiControl &ofxSimpleGuiControl::setKeyboardShortcut(char c) { 82 | keyboardShortcut = c; 83 | if(c) { 84 | // printf("ofxSimpleGuiControl::setKeyboardShortcut %s %c\n", name.c_str(), c); 85 | name = origName + " (" + c + ")"; 86 | } else { 87 | name = origName; 88 | } 89 | return *this; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /src/ofxSimpleGuiControl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofxMSAInteractiveObject.h" 4 | #include "ofxSimpleGuiConfig.h" 5 | 6 | #ifndef OFXMSAGUI_DONT_USE_XML 7 | #include "ofxXmlSettings.h" 8 | #endif 9 | 10 | class ofxSimpleGuiControl : public ofxMSAInteractiveObject { 11 | public: 12 | string name; // Human readable name this is what is displayed on screen (includes keyboard shortcut) 13 | string origName; // the original name (excluding keyboard shortcut) 14 | string key; // Machine readable name (don't change this after creating control, used for saving/loading) 15 | string controlType; 16 | bool lock; 17 | bool focused; 18 | bool newColumn; 19 | bool hasTitle; 20 | char keyboardShortcut; 21 | 22 | ofxSimpleGuiControl(string name); 23 | ofxSimpleGuiControl& setName(string newName); 24 | ofxSimpleGuiControl& setKey(string newKey); 25 | ofxSimpleGuiControl& setConfig(ofxSimpleGuiConfig *config); 26 | ofxSimpleGuiControl& setNewColumn(bool b=true); 27 | 28 | ofxSimpleGuiControl& setTextColor(bool clickable = true); 29 | ofxSimpleGuiControl& setTextBGColor(bool clickable = true); 30 | ofxSimpleGuiControl& setFullColor(bool forceActive = false); 31 | ofxSimpleGuiControl& setEmptyColor(); 32 | ofxSimpleGuiControl& setKeyboardShortcut(char c); 33 | 34 | #ifndef OFXMSAGUI_DONT_USE_XML 35 | virtual void loadFromXML(ofxXmlSettings &XML) {} 36 | virtual void saveToXML(ofxXmlSettings &XML) {} 37 | #endif 38 | 39 | virtual void setup() {} 40 | 41 | virtual void draw(float x, float y) {} 42 | virtual void draw() { draw(x, y); } 43 | 44 | virtual void onKeyUp() {} // up key is pressed 45 | virtual void onKeyDown() {} // down key is pressed 46 | virtual void onKeyLeft() {} // left key is pressed 47 | virtual void onKeyRight() {} // right key is pressed 48 | virtual void onKeyEnter() {} // enter key is pressed 49 | 50 | 51 | // from ofxMSAInteractiveObject 52 | virtual void onRollOver(int x, int y) {} // called when mouse enters object x, y, width, height 53 | virtual void onRollOut() {} // called when mouse leaves object x, y, width, height 54 | virtual void onMouseMove(int x, int y) {} // called when mouse moves while over object x, y, width, height 55 | virtual void onDragOver(int x, int y, int button) {} // called when mouse moves while over object and button is down 56 | virtual void onDragOutside(int x, int y, int button) {} // called when mouse moves while outside the object after being clicked on it 57 | virtual void onPress(int x, int y, int button) {} // called when mouse presses while over object 58 | virtual void onPressOutside(int x, int y, int button) {} // called when mouse presses while outside object 59 | virtual void onRelease(int x, int y, int button) {} // called when mouse releases while over object 60 | virtual void onReleaseOutside(int x, int y, int button) {} // called when mouse releases outside of object after being pressed on object 61 | 62 | virtual void keyPressed( int key ){} 63 | virtual void keyReleased( int key ){} 64 | 65 | 66 | protected: 67 | ofxSimpleGuiConfig *config; 68 | }; 69 | 70 | -------------------------------------------------------------------------------- /src/ofxSimpleGuiIncludes.h: -------------------------------------------------------------------------------- 1 | #include "ofxSimpleGuiPage.h" 2 | #include "ofxSimpleGuiConfig.h" 3 | #include "ofxSimpleGuiButton.h" 4 | #include "ofxSimpleGuiContent.h" 5 | #include "ofxSimpleGuiFPSCounter.h" 6 | #include "ofxSimpleGuiQuadWarp.h" 7 | #include "ofxSimpleGuiSliderFloat.h" 8 | #include "ofxSimpleGuiSliderInt.h" 9 | #include "ofxSimpleGuiSlider2d.h" 10 | #include "ofxSimpleGuiMovieSlider.h" 11 | #include "ofxSimpleGuiToggle.h" 12 | #include "ofxSimpleGuiTitle.h" 13 | #include "ofxSimpleGuiColorPicker.h" 14 | #include "ofxSimpleGuiComboBox.h" 15 | //#include "ofxSimpleGuiOption.h" 16 | //#include "ofxSimpleGuiOptionGroup.h" 17 | -------------------------------------------------------------------------------- /src/ofxSimpleGuiPage.cpp: -------------------------------------------------------------------------------- 1 | #include "ofxSimpleGuiPage.h" 2 | 3 | ofxSimpleGuiPage::ofxSimpleGuiPage(string name) : ofxSimpleGuiControl(name) { 4 | disableAllEvents(); 5 | width = 0; 6 | height = ofGetHeight(); 7 | eventStealingControl = NULL; 8 | setXMLName(name + "_settings.xml"); 9 | } 10 | 11 | ofxSimpleGuiPage::~ofxSimpleGuiPage() { 12 | // delete all controls 13 | } 14 | 15 | 16 | ofxSimpleGuiPage &ofxSimpleGuiPage::setXMLName(string s) { 17 | xmlFilename = s; 18 | return *this; 19 | } 20 | 21 | 22 | void ofxSimpleGuiPage::loadFromXML(string xmlFilepath) { 23 | string fullPath = xmlFilepath + xmlFilename; 24 | ofLog(OF_LOG_VERBOSE, "ofxSimpleGuiPage::loadFromXML: " + fullPath); 25 | #ifndef OFXMSAGUI_DONT_USE_XML 26 | 27 | if(xmlFilename.compare("") == 0) return; 28 | 29 | if(XML.loadFile(fullPath) == false) { 30 | ofLog(OF_LOG_ERROR, "Error loading xmlFilename: " + fullPath); 31 | return; 32 | } 33 | 34 | XML.pushTag("controls"); 35 | for(int i=0; i < controls.size(); i++) { 36 | controls[i]->loadFromXML(XML); 37 | } 38 | XML.popTag(); 39 | #endif 40 | } 41 | 42 | void ofxSimpleGuiPage::saveToXML(string xmlFilepath) { 43 | if(controls.size() <= 1 || xmlFilename.compare("") == 0) return; // if it has no controls (title counts as one control) 44 | 45 | #ifndef OFXMSAGUI_DONT_USE_XML 46 | XML.clear(); // clear cause we are building a new xml file 47 | 48 | XML.addTag("controls"); 49 | XML.pushTag("controls"); 50 | for(int i=0; i < controls.size(); i++) { 51 | controls[i]->saveToXML(XML); 52 | } 53 | XML.popTag(); 54 | 55 | string fullPath = xmlFilepath + xmlFilename; 56 | XML.saveFile(fullPath); 57 | // if(doSaveBackup) 58 | ofLog(OF_LOG_VERBOSE, "ofxSimpleGuiPage::saveToXML: " + fullPath + " " + ofToString(controls.size(), 0) + " items"); 59 | #endif 60 | } 61 | 62 | 63 | float ofxSimpleGuiPage::getNextY(float y) { 64 | return y; 65 | int iy = (int)ceil(y/config->gridSize.y); 66 | return (iy) * config->gridSize.y; 67 | } 68 | 69 | 70 | void ofxSimpleGuiPage::draw(float x, float y, bool alignRight) { 71 | setPosition(x += config->offset.x, y += config->offset.y); 72 | if(alignRight) x = ofGetWidth() - x - config->gridSize.x; 73 | 74 | float posX = 0; 75 | float posY = 0; 76 | float stealingX = 0; 77 | float stealingY = 0; 78 | 79 | ofSetRectMode(OF_RECTMODE_CORNER); 80 | 81 | for(int i=0; igridSize.x; 86 | else posX += config->gridSize.x; 87 | posY = 0; 88 | } 89 | 90 | float controlX = posX + x; 91 | float controlY = posY + y; 92 | 93 | //we don't draw the event stealing controls until the end because they can expand and overlap with other controls (e.g. combo box) 94 | if(eventStealingControl == &control) { 95 | stealingX = controlX; 96 | stealingY = controlY; 97 | } else { 98 | // printf("drawing control: %s %s\n", control.controlType.c_str(), control.name.c_str()); 99 | control.draw(controlX, controlY); 100 | } 101 | 102 | if(control.hasTitle) { 103 | ofNoFill(); 104 | ofSetHexColor(config->borderColor); 105 | glLineWidth(0.5f); 106 | ofDrawRectangle(controlX, controlY, control.width, control.height); 107 | } 108 | posY = getNextY(posY + control.height + config->padding.y); 109 | 110 | if(posY + y >= height - control.height - config->padding.y) { 111 | if(alignRight) posX -= config->gridSize.x; 112 | else posX += config->gridSize.x; 113 | posY = 0; 114 | } 115 | 116 | // if(guiFocus == controls[i]->guiID) controls[i]->focused = true; // MEMO 117 | // else controls[i]->focused = false; 118 | } 119 | //event stealing controls get drawn on top 120 | if(eventStealingControl) { 121 | eventStealingControl->draw(stealingX, stealingY); 122 | if(eventStealingControl->hasTitle) { 123 | ofNoFill(); 124 | ofSetHexColor(config->borderColor); 125 | glLineWidth(0.5f); 126 | ofDrawRectangle(stealingX, stealingY, eventStealingControl->width, eventStealingControl->height); 127 | } 128 | } 129 | } 130 | 131 | 132 | ofxSimpleGuiControl &ofxSimpleGuiPage::addControl(ofxSimpleGuiControl& control) { 133 | controls.push_back(&control); 134 | width += control.width + config->padding.x; 135 | return control; 136 | } 137 | 138 | ofxSimpleGuiButton &ofxSimpleGuiPage::addButton(string name, bool &value) { 139 | return (ofxSimpleGuiButton &)addControl(* new ofxSimpleGuiButton(name, value)); 140 | } 141 | 142 | ofxSimpleGuiContent &ofxSimpleGuiPage::addContent(string name, ofBaseDraws &content, float fixwidth) { 143 | if(fixwidth == -1) fixwidth = config->gridSize.x - config->padding.x; 144 | return (ofxSimpleGuiContent &)addControl(* new ofxSimpleGuiContent(name, content, fixwidth)); 145 | } 146 | 147 | ofxSimpleGuiFPSCounter &ofxSimpleGuiPage::addFPSCounter() { 148 | return (ofxSimpleGuiFPSCounter &)addControl(* new ofxSimpleGuiFPSCounter()); 149 | } 150 | 151 | ofxSimpleGuiQuadWarp &ofxSimpleGuiPage::addQuadWarper(string name, ofBaseDraws &baseDraw, ofPoint *pts) { 152 | return (ofxSimpleGuiQuadWarp &)addControl(* new ofxSimpleGuiQuadWarp(name, baseDraw, pts)); 153 | } 154 | // 155 | //ofxSimpleGuiMovieSlider &ofxSimpleGuiPage::addMovieSlider(string name, ofVideoPlayer& input) { 156 | // return (ofxSimpleGuiMovieSlider &)addControl(* new ofxSimpleGuiMovieSlider(name, input)); 157 | //} 158 | 159 | ofxSimpleGuiSliderInt &ofxSimpleGuiPage::addSlider(string name, int &value, int min, int max) { 160 | return (ofxSimpleGuiSliderInt &)addControl(* new ofxSimpleGuiSliderInt(name, value, min, max)); 161 | } 162 | 163 | ofxSimpleGuiSliderFloat &ofxSimpleGuiPage::addSlider(string name, float &value, float min, float max) { 164 | return (ofxSimpleGuiSliderFloat &)addControl(* new ofxSimpleGuiSliderFloat(name, value, min, max)); 165 | } 166 | 167 | ofxSimpleGuiSlider2d &ofxSimpleGuiPage::addSlider2d(string name, ofPoint& value, float xmin, float xmax, float ymin, float ymax) { 168 | return (ofxSimpleGuiSlider2d &)addControl(* new ofxSimpleGuiSlider2d(name, value, xmin, xmax, ymin, ymax)); 169 | } 170 | 171 | ofxSimpleGuiTitle &ofxSimpleGuiPage::addTitle(string name, float height) { 172 | return (ofxSimpleGuiTitle &)addControl(* new ofxSimpleGuiTitle(name, height)); 173 | } 174 | 175 | ofxSimpleGuiToggle &ofxSimpleGuiPage::addToggle(string name, bool &value) { 176 | return (ofxSimpleGuiToggle &)addControl(* new ofxSimpleGuiToggle(name, value)); 177 | } 178 | 179 | ofxSimpleGuiColorPicker &ofxSimpleGuiPage::addColorPicker(string name, ofFloatColor& color) { 180 | return (ofxSimpleGuiColorPicker &)addControl(* new ofxSimpleGuiColorPicker(name, color)); 181 | } 182 | 183 | 184 | ofxSimpleGuiComboBox &ofxSimpleGuiPage::addComboBox(string name, int &choice_out, int numChoices, string* choiceTitles) { 185 | return (ofxSimpleGuiComboBox &)addControl(* new ofxSimpleGuiComboBox(name, choice_out, numChoices, this, choiceTitles)); 186 | } 187 | 188 | 189 | 190 | 191 | void ofxSimpleGuiPage::update(ofEventArgs &e) { 192 | for(int i=0; iupdate(); 193 | } 194 | 195 | void ofxSimpleGuiPage::SetEventStealingControl(ofxSimpleGuiControl &control) { 196 | eventStealingControl = &control; 197 | } 198 | void ofxSimpleGuiPage::ReleaseEventStealingControl() { 199 | eventStealingControl = NULL; 200 | } 201 | 202 | void ofxSimpleGuiPage::mouseMoved(ofMouseEventArgs &e) { 203 | if(eventStealingControl) 204 | eventStealingControl->_mouseMoved(e); 205 | else 206 | for(int i=0; i_mouseMoved(e); 207 | } 208 | 209 | void ofxSimpleGuiPage::mousePressed(ofMouseEventArgs &e) { 210 | if(eventStealingControl) 211 | eventStealingControl->_mousePressed(e); 212 | else 213 | for(int i=0; i_mousePressed(e); 214 | } 215 | 216 | void ofxSimpleGuiPage::mouseDragged(ofMouseEventArgs &e) { 217 | if(eventStealingControl) 218 | eventStealingControl->_mouseDragged(e); 219 | else 220 | for(int i=0; i_mouseDragged(e); 221 | } 222 | 223 | void ofxSimpleGuiPage::mouseReleased(ofMouseEventArgs &e) { 224 | if(eventStealingControl) 225 | eventStealingControl->_mouseReleased(e); 226 | else 227 | for(int i=0; i_mouseReleased(e); 228 | } 229 | 230 | void ofxSimpleGuiPage::keyPressed(ofKeyEventArgs &e) { 231 | bool keyUp = e.key == OF_KEY_UP; 232 | bool keyDown = e.key == OF_KEY_DOWN; 233 | bool keyLeft = e.key == OF_KEY_LEFT; 234 | bool keyRight = e.key == OF_KEY_RIGHT; 235 | bool keyEnter = e.key == OF_KEY_RETURN; 236 | 237 | for(int i=0; iisMouseOver()) { 240 | if(keyUp) c->onKeyUp(); 241 | if(keyDown) c->onKeyDown(); 242 | if(keyLeft) c->onKeyLeft(); 243 | if(keyRight) c->onKeyRight(); 244 | if(keyEnter) c->onKeyEnter(); 245 | c->_keyPressed(e); 246 | } 247 | } 248 | } 249 | 250 | void ofxSimpleGuiPage::keyReleased(ofKeyEventArgs &e) { 251 | for(int i=0; iisMouseOver()) controls[i]->_keyReleased(e); 252 | } 253 | 254 | 255 | vector & ofxSimpleGuiPage::getControls() { 256 | return controls; 257 | } 258 | 259 | -------------------------------------------------------------------------------- /src/ofxSimpleGuiPage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofxSimpleGuiIncludes.h" 4 | 5 | class ofxSimpleGuiPage : public ofxSimpleGuiControl { 6 | public: 7 | ofxSimpleGuiPage(string name); 8 | ~ofxSimpleGuiPage(); 9 | 10 | void draw(float x, float y, bool alignRight); 11 | 12 | ofxSimpleGuiPage& setXMLName(string xmlFilename); 13 | void loadFromXML(string xmlFilepath = ""); 14 | void saveToXML(string xmlFilepath = ""); 15 | 16 | 17 | ofxSimpleGuiControl &addControl(ofxSimpleGuiControl& control); 18 | ofxSimpleGuiButton &addButton(string name, bool &value); 19 | ofxSimpleGuiContent &addContent(string name, ofBaseDraws &content, float fixwidth = -1); 20 | ofxSimpleGuiFPSCounter &addFPSCounter(); 21 | ofxSimpleGuiQuadWarp &addQuadWarper(string name, ofBaseDraws &baseDraw, ofPoint *pts); 22 | // ofxSimpleGuiMovieSlider &addMovieSlider(string name, ofVideoPlayer& input); 23 | ofxSimpleGuiSliderInt &addSlider(string name, int &value, int min, int max); 24 | ofxSimpleGuiSliderFloat &addSlider(string name, float &value, float min = 0.f, float max = 1.f); 25 | ofxSimpleGuiSlider2d &addSlider2d(string name, ofPoint& value, float xmin, float xmax, float ymin, float ymax); 26 | ofxSimpleGuiTitle &addTitle(string name="", float height = 0); 27 | ofxSimpleGuiToggle &addToggle(string name, bool &value); 28 | ofxSimpleGuiColorPicker &addColorPicker(string name, ofFloatColor& color); 29 | ofxSimpleGuiComboBox &addComboBox(string name, int &choice_out, int numChoices, string* choiceTitles=NULL); 30 | 31 | void SetEventStealingControl(ofxSimpleGuiControl &control); 32 | void ReleaseEventStealingControl(); 33 | 34 | // void setup(ofEventArgs &e); 35 | void update(ofEventArgs &e); 36 | // void draw(ofEventArgs &e); 37 | // void exit(ofEventArgs &e); 38 | 39 | void mouseMoved(ofMouseEventArgs &e); 40 | void mousePressed(ofMouseEventArgs &e); 41 | void mouseDragged(ofMouseEventArgs &e); 42 | void mouseReleased(ofMouseEventArgs &e); 43 | 44 | void keyPressed(ofKeyEventArgs &e); 45 | void keyReleased(ofKeyEventArgs &e); 46 | 47 | 48 | vector & getControls(); 49 | 50 | void clear() { controls.clear(); } 51 | 52 | protected: 53 | vector controls; 54 | 55 | //some controls can take over focus (e.g. combo box,) which means events should only be passed to them 56 | ofxSimpleGuiControl* eventStealingControl; 57 | float getNextY(float y); 58 | #ifndef OFXMSAGUI_DONT_USE_XML 59 | ofxXmlSettings XML; 60 | #endif 61 | string xmlFilename; 62 | }; 63 | -------------------------------------------------------------------------------- /src/ofxSimpleGuiToo.cpp: -------------------------------------------------------------------------------- 1 | #include "ofxSimpleGuiToo.h" 2 | 3 | ofxSimpleGuiToo gui; 4 | 5 | 6 | //------------------------------------------------------------------------------ constrcutor 7 | ofxSimpleGuiToo::ofxSimpleGuiToo() { 8 | config = NULL; 9 | doDefaultKeys = false; 10 | } 11 | 12 | void ofxSimpleGuiToo::setup() { 13 | config = &defaultSimpleGuiConfig; 14 | 15 | titleButton = NULL; 16 | 17 | headerPage = &addPage("Header"); 18 | headerPage->height = config->buttonHeight * 2; 19 | headerPage->width = 0; 20 | titleButton = &headerPage->addButton("title", doNextPage); 21 | headerPage->addButton("<", doPrevPage); 22 | //headerPage->addButton(">", doNextPage); 23 | headerPage->addToggle("Auto Save", doAutoSave); 24 | headerPage->addButton("Save Settings", doSave); 25 | headerPage->addButton("Save Preset", savePreset); 26 | headerPage->addButton("Load Preset", loadPreset); 27 | headerPage->addFPSCounter(); 28 | 29 | addPage(); 30 | setAutoSave(true); 31 | setAlignRight(false); 32 | setDraw(false); 33 | setPage(1); 34 | autoHeight(); 35 | 36 | ofAddListener(ofEvents().keyPressed, this, &ofxSimpleGuiToo::keyPressed); 37 | } 38 | 39 | void ofxSimpleGuiToo::setForceHeight(int h) { 40 | forceHeight = h; 41 | } 42 | 43 | void ofxSimpleGuiToo::autoHeight() { 44 | forceHeight = 0; 45 | } 46 | 47 | 48 | void ofxSimpleGuiToo::addListeners() { 49 | // ofAddListener(ofEvents().setup, this, &ofxSimpleGuiToo::setup); 50 | ofAddListener(ofEvents().update, this, &ofxSimpleGuiToo::update); 51 | // ofAddListener(ofEvents().draw, this, &ofxSimpleGuiToo::draw); 52 | // ofAddListener(ofEvents().exit, this, &ofxSimpleGuiToo::exit); 53 | 54 | ofAddListener(ofEvents().mousePressed, this, &ofxSimpleGuiToo::mousePressed); 55 | ofAddListener(ofEvents().mouseMoved, this, &ofxSimpleGuiToo::mouseMoved); 56 | ofAddListener(ofEvents().mouseDragged, this, &ofxSimpleGuiToo::mouseDragged); 57 | ofAddListener(ofEvents().mouseReleased, this, &ofxSimpleGuiToo::mouseReleased); 58 | 59 | // ofAddListener(ofEvents().keyPressed, this, &ofxSimpleGuiToo::keyPressed); 60 | ofAddListener(ofEvents().keyReleased, this, &ofxSimpleGuiToo::keyReleased); 61 | } 62 | 63 | 64 | void ofxSimpleGuiToo::removeListeners() { 65 | // ofRemoveListener(ofEvents().setup, this, &ofxSimpleGuiToo::setup); 66 | ofRemoveListener(ofEvents().update, this, &ofxSimpleGuiToo::update); 67 | // ofRemoveListener(ofEvents().draw, this, &ofxSimpleGuiToo::draw); 68 | // ofRemoveListener(ofEvents().exit, this, &ofxSimpleGuiToo::exit); 69 | 70 | ofRemoveListener(ofEvents().mousePressed, this, &ofxSimpleGuiToo::mousePressed); 71 | ofRemoveListener(ofEvents().mouseMoved, this, &ofxSimpleGuiToo::mouseMoved); 72 | ofRemoveListener(ofEvents().mouseDragged, this, &ofxSimpleGuiToo::mouseDragged); 73 | ofRemoveListener(ofEvents().mouseReleased, this, &ofxSimpleGuiToo::mouseReleased); 74 | 75 | // ofRemoveListener(ofEvents().keyPressed, this, &ofxSimpleGuiToo::keyPressed); 76 | ofRemoveListener(ofEvents().keyReleased, this, &ofxSimpleGuiToo::keyReleased); 77 | } 78 | 79 | void ofxSimpleGuiToo::setDraw(bool b) { 80 | if(doDraw != b) { 81 | doDraw = b; 82 | if(doDraw) addListeners(); 83 | else removeListeners(); 84 | if(doAutoSave) saveToXML(); 85 | } 86 | } 87 | 88 | void ofxSimpleGuiToo::show() { 89 | setDraw(true); 90 | } 91 | 92 | void ofxSimpleGuiToo::hide() { 93 | setDraw(false); 94 | } 95 | 96 | void ofxSimpleGuiToo::toggleDraw() { 97 | setDraw(!doDraw); 98 | } 99 | 100 | bool ofxSimpleGuiToo::isOn() { 101 | return doDraw; 102 | } 103 | 104 | 105 | void ofxSimpleGuiToo::setAutoSave(bool b) { 106 | doAutoSave = b; 107 | } 108 | 109 | 110 | void ofxSimpleGuiToo::loadFromXML(string path) { 111 | ofLog(OF_LOG_VERBOSE, "ofxSimpleGuiToo::loadFromXML");// + file); 112 | 113 | for(int i=1; i < pages.size(); i++) { 114 | pages[i]->loadFromXML(path); 115 | } 116 | 117 | setPage(1); 118 | } 119 | 120 | 121 | void ofxSimpleGuiToo::saveToXML(string path) { 122 | doSave = false; 123 | 124 | for(int i=1; i < pages.size(); i++) { 125 | pages[i]->saveToXML(path); 126 | } 127 | 128 | ofLog(OF_LOG_VERBOSE, "ofxSimpleGuiToo::saveToXML"); 129 | } 130 | 131 | 132 | void ofxSimpleGuiToo::setAlignRight(bool b) { 133 | alignRight = b; 134 | } 135 | 136 | void ofxSimpleGuiToo::setDefaultKeys(bool b) { 137 | doDefaultKeys = b; 138 | } 139 | 140 | 141 | void ofxSimpleGuiToo::drawFocus(float x, float y) { 142 | ofPushMatrix(); 143 | ofTranslate(x, y, 0); 144 | ofFill(); 145 | // ofSetHexColor(config->focusColor.r, config->focusColor.g, config->focusColor.b, 200); 146 | ofDrawRectangle(0, 0, 10, 10); 147 | ofPopMatrix(); 148 | } 149 | 150 | 151 | void ofxSimpleGuiToo::draw() { 152 | if(!doDraw) return; 153 | 154 | ofPushStyle(); 155 | 156 | glDisable(GL_DEPTH_TEST); 157 | 158 | ofSetLineWidth(3); 159 | 160 | glDisableClientState(GL_COLOR_ARRAY); 161 | 162 | headerPage->draw(0, 0, alignRight); // this is the header 163 | ofSetHexColor(config->borderColor); 164 | if(alignRight) ofDrawLine(ofGetWidth() - headerPage->width, headerPage->height, headerPage->width, headerPage->height); 165 | else ofDrawLine(0, headerPage->height, headerPage->width, headerPage->height); 166 | pages[currentPageIndex]->draw(0.0f, headerPage->height, alignRight); 167 | 168 | ofPopStyle(); 169 | } 170 | 171 | 172 | void ofxSimpleGuiToo::nextPage() { 173 | setPage(currentPageIndex + 1); 174 | } 175 | void ofxSimpleGuiToo::prevPage() { 176 | setPage(currentPageIndex - 1); 177 | } 178 | 179 | void ofxSimpleGuiToo::nextPageWithBlank() { 180 | if(doDraw) { 181 | setPage(currentPageIndex + 1); 182 | if(currentPageIndex == 1) setDraw(false); 183 | } else { 184 | setDraw(true); 185 | setPage(1); 186 | } 187 | } 188 | 189 | 190 | 191 | void ofxSimpleGuiToo::setPage(int i) { 192 | currentPageIndex = i; 193 | if(currentPageIndex >= pages.size()) currentPageIndex = 1; 194 | else if(currentPageIndex < 1) currentPageIndex = pages.size()-1; 195 | 196 | if(titleButton) titleButton->setName(ofToString(currentPageIndex) + ": " + pages[currentPageIndex]->name); 197 | } 198 | 199 | 200 | void ofxSimpleGuiToo::setPage(string name) { 201 | // ofxSimpleGuiPage *page; 202 | for(int i=1; i < pages.size(); i++) { 203 | if(name.compare(pages[i]->name) == 0) { 204 | setPage(i); 205 | break; 206 | } 207 | } 208 | } 209 | 210 | 211 | ofxSimpleGuiPage& ofxSimpleGuiToo::page(int i) { 212 | return *pages.at(i); 213 | } 214 | 215 | ofxSimpleGuiPage& ofxSimpleGuiToo::page(string name) { 216 | if(!config) setup(); 217 | for(int i=1; iname) == 0) return *pages[i]; 218 | // return *pages[0]; // return first page by default 219 | static ofxSimpleGuiPage errorpage("ERROR"); // TODO what a shit hack 220 | return errorpage; 221 | } 222 | 223 | 224 | ofxSimpleGuiPage& ofxSimpleGuiToo::currentPage() { 225 | return page(currentPageIndex); 226 | } 227 | 228 | vector & ofxSimpleGuiToo::getPages() { 229 | return pages; 230 | } 231 | 232 | 233 | 234 | ofxSimpleGuiPage &ofxSimpleGuiToo::addPage(string name) { 235 | if(!config) setup(); 236 | 237 | ofxSimpleGuiPage *newPage = new ofxSimpleGuiPage(name);//ofToString(pages.size(), 0) + ": " + name); 238 | pages.push_back(newPage); 239 | if(name == "") newPage->setName("SETTINGS"); 240 | static bool b; 241 | // if(pages.size() > 1) headerPage->addTitle(newPage->name); // if this isn't the first page, add to header 242 | // if(pages.size() > 1) newPage->addTitle(newPage->name); // if this isn't the first page, add to header 243 | setPage(pages.size() - 1); 244 | return *newPage; 245 | } 246 | 247 | ofxSimpleGuiControl &ofxSimpleGuiToo::control(string name) { 248 | for(int i = 0; i < pages.size(); i++) { 249 | for(int j = 0; j < pages[i]->getControls().size(); j++) { 250 | if(name==pages[i]->getControls()[j]->name) { 251 | return *pages[i]->getControls()[j]; 252 | } 253 | } 254 | } 255 | return *pages[0]->getControls()[0]; // return first page first control by default 256 | } 257 | 258 | 259 | ofxSimpleGuiControl &ofxSimpleGuiToo::addControl(ofxSimpleGuiControl& control) { 260 | if(!config) setup(); 261 | return pages[currentPageIndex]->addControl(control); 262 | } 263 | 264 | ofxSimpleGuiButton &ofxSimpleGuiToo::addButton(string name, bool &value) { 265 | if(!config) setup(); 266 | return pages[currentPageIndex]->addButton(name, value); 267 | } 268 | 269 | ofxSimpleGuiContent &ofxSimpleGuiToo::addContent(string name, ofBaseDraws &content, float fixwidth) { 270 | if(!config) setup(); 271 | return pages[currentPageIndex]->addContent(name, content, fixwidth); 272 | } 273 | 274 | ofxSimpleGuiFPSCounter &ofxSimpleGuiToo::addFPSCounter() { 275 | if(!config) setup(); 276 | return pages[currentPageIndex]->addFPSCounter(); 277 | } 278 | 279 | ofxSimpleGuiQuadWarp &ofxSimpleGuiToo::addQuadWarper(string name, ofBaseDraws &baseDraw, ofPoint *pts) { 280 | return pages[currentPageIndex]->addQuadWarper(name, baseDraw, pts); 281 | } 282 | // 283 | //ofxSimpleGuiMovieSlider &ofxSimpleGuiToo::addMovieSlider(string name, ofVideoPlayer& input) { 284 | // return pages[currentPageIndex]->addMovieSlider(name, input); 285 | //} 286 | 287 | ofxSimpleGuiSliderInt &ofxSimpleGuiToo::addSlider(string name, int &value, int min, int max) { 288 | if(!config) setup(); 289 | return pages[currentPageIndex]->addSlider(name, value, min, max); 290 | } 291 | 292 | ofxSimpleGuiSliderFloat &ofxSimpleGuiToo::addSlider(string name, float &value, float min, float max) { 293 | if(!config) setup(); 294 | return pages[currentPageIndex]->addSlider(name, value, min, max); 295 | } 296 | 297 | ofxSimpleGuiSlider2d &ofxSimpleGuiToo::addSlider2d(string name, ofPoint& value, float xmin, float xmax, float ymin, float ymax) { 298 | if(!config) setup(); 299 | return pages[currentPageIndex]->addSlider2d(name, value, xmin, xmax, ymin, ymax); 300 | } 301 | 302 | ofxSimpleGuiTitle &ofxSimpleGuiToo::addTitle(string name, float height) { 303 | if(!config) setup(); 304 | return pages[currentPageIndex]->addTitle(name, height); 305 | } 306 | 307 | ofxSimpleGuiToggle &ofxSimpleGuiToo::addToggle(string name, bool &value) { 308 | if(!config) setup(); 309 | return pages[currentPageIndex]->addToggle(name, value); 310 | } 311 | 312 | 313 | ofxSimpleGuiColorPicker &ofxSimpleGuiToo::addColorPicker(string name, ofFloatColor& color) { 314 | if(!config) setup(); 315 | return pages[currentPageIndex]->addColorPicker(name, color); 316 | } 317 | 318 | 319 | ofxSimpleGuiComboBox &ofxSimpleGuiToo::addComboBox(string name, int &value, int numChoices, string* choiceTitles) { 320 | if(!config) setup(); 321 | return pages[currentPageIndex]->addComboBox(name, value, numChoices, choiceTitles); 322 | } 323 | 324 | ofxSimpleGuiComboBox &ofxSimpleGuiToo::addComboBox(string name, int &value, vector& choiceTitles) { 325 | return addComboBox(name, value, choiceTitles.size(), &choiceTitles[0]); 326 | } 327 | 328 | 329 | //void ofxSimpleGuiToo::setup(ofEventArgs &e) { 330 | void ofxSimpleGuiToo::update(ofEventArgs &e) { 331 | if (doPrevPage) { 332 | doPrevPage = false; 333 | prevPage(); 334 | } 335 | 336 | if(doNextPage) { 337 | doNextPage = false; 338 | nextPage(); 339 | } 340 | 341 | headerPage->update(e); 342 | if(forceHeight) { 343 | pages[currentPageIndex]->height = forceHeight; 344 | } else { 345 | pages[currentPageIndex]->height = ofGetHeight(); 346 | } 347 | pages[currentPageIndex]->update(e); 348 | 349 | 350 | // if(doSaveBackup) doSave = true; 351 | 352 | if(doSave) saveToXML(); 353 | 354 | if(savePreset) { 355 | savePreset = false; 356 | ofFileDialogResult saveResult = ofSystemSaveDialog("my-preset", "Save preset"); 357 | if (saveResult.bSuccess) { 358 | ofDisableDataPath(); 359 | ofDirectory::createDirectory(saveResult.getPath(), false); 360 | saveToXML(saveResult.getPath() + "/"); 361 | ofEnableDataPath(); 362 | } 363 | } 364 | 365 | if(loadPreset) { 366 | loadPreset = false; 367 | ofFileDialogResult loadResult = ofSystemLoadDialog("Load preset", true); 368 | if (loadResult.bSuccess) { 369 | ofDisableDataPath(); 370 | loadFromXML(loadResult.getPath() + "/"); 371 | ofEnableDataPath(); 372 | } 373 | } 374 | } 375 | //void ofxSimpleGuiToo::draw(ofEventArgs &e) { 376 | //void ofxSimpleGuiToo::exit(ofEventArgs &e) { 377 | 378 | void ofxSimpleGuiToo::mouseMoved(ofMouseEventArgs &e) { 379 | headerPage->mouseMoved(e); 380 | pages[currentPageIndex]->mouseMoved(e); 381 | } 382 | 383 | void ofxSimpleGuiToo::mousePressed(ofMouseEventArgs &e) { 384 | headerPage->mousePressed(e); 385 | pages[currentPageIndex]->mousePressed(e); 386 | } 387 | 388 | void ofxSimpleGuiToo::mouseDragged(ofMouseEventArgs &e) { 389 | headerPage->mouseDragged(e); 390 | pages[currentPageIndex]->mouseDragged(e); 391 | } 392 | 393 | void ofxSimpleGuiToo::mouseReleased(ofMouseEventArgs &e) { 394 | headerPage->mouseReleased(e); 395 | pages[currentPageIndex]->mouseReleased(e); 396 | // if(doAutoSave) doSave = true; 397 | if(doAutoSave) saveToXML(); 398 | } 399 | 400 | void ofxSimpleGuiToo::keyPressed(ofKeyEventArgs &e) { 401 | // if(doDefaultKeys && e.hasModifier(OF_KEY_CONTROL) && e.hasModifier(OF_KEY_ALT)) { 402 | if(doDefaultKeys && e.hasModifier(OF_KEY_CONTROL)) { 403 | int key = e.keycode; 404 | if(key == ' ') { 405 | toggleDraw(); 406 | } else if(key>='0' && key<='9') { 407 | setPage((int)(key - '0')); 408 | setDraw(true); 409 | } else if(doDraw) { 410 | switch(key) { 411 | case '[': prevPage(); break; 412 | case ']': nextPage(); break; 413 | } 414 | } 415 | } 416 | 417 | if(doDraw) { 418 | headerPage->keyPressed(e); 419 | pages[currentPageIndex]->keyPressed(e); 420 | } 421 | 422 | } 423 | 424 | void ofxSimpleGuiToo::keyReleased(ofKeyEventArgs &e) { 425 | headerPage->keyReleased(e); 426 | pages[currentPageIndex]->keyReleased(e); 427 | } 428 | 429 | /* 430 | //------------------------------------------------------------------------ mouse moved 431 | void ofxSimpleGuiToo::mouseMoved(int x, int y) { 432 | mx = x; my = y; 433 | } 434 | 435 | //------------------------------------------------------------------------ mouse released 436 | void ofxSimpleGuiToo::mouseReleased() { 437 | if(doAutoSave) { 438 | saveToXML(); 439 | } 440 | } 441 | 442 | //------------------------------------------------------------------------ key released 443 | void ofxSimpleGuiToo::keyReleased(int key) { 444 | if(doAutoSave) { 445 | saveToXML(); 446 | } 447 | } 448 | 449 | //------------------------------------------------------------------------ key press 450 | void ofxSimpleGuiToo::keyPressed(int key) { 451 | 452 | } 453 | */ 454 | 455 | -------------------------------------------------------------------------------- /src/ofxSimpleGuiToo.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | 3 | Copyright (c) 2008, 2009, 2010, Memo Akten, www.memo.tv 4 | *** The Mega Super Awesome Visuals Company *** 5 | * All rights reserved. 6 | 7 | based on Todd Vanderlin's ofxSimpleGui API 8 | http://toddvanderlin.com/ 9 | 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions are met: 13 | * 14 | * * Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * * Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * * Neither the name of MSA Visuals nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 29 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 30 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 32 | * OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ***********************************************************************/ 35 | 36 | #pragma once 37 | 38 | #include "ofMain.h" 39 | 40 | #ifndef OFXMSAGUI_DONT_USE_XML 41 | #include "ofxXmlSettings.h" 42 | #endif 43 | 44 | #include "ofxSimpleGuiIncludes.h" 45 | 46 | class ofxSimpleGuiToo { 47 | 48 | public: 49 | int guiFocus; 50 | 51 | ofxSimpleGuiConfig *config; 52 | 53 | ofxSimpleGuiToo(); 54 | void setup(); 55 | 56 | 57 | void loadFromXML(string path = ""); 58 | void saveToXML(string path = ""); 59 | void setAutoSave(bool b); 60 | void setAlignRight(bool b=true); 61 | void setDefaultKeys(bool b=true); 62 | 63 | // int getValueI(string nameID); 64 | // float getValueF(string nameID); 65 | // bool getValueB(string nameID); 66 | 67 | void drawFocus(float x, float y); 68 | 69 | 70 | void setDraw(bool b); 71 | void toggleDraw(); 72 | void show(); // simply calls setDraw(true); 73 | void hide(); // simply calls setDraw(false); 74 | bool isOn(); 75 | 76 | void nextPage(); 77 | void prevPage(); 78 | void setPage(int i); // 1 based index of page 79 | void setPage(string name); 80 | void setForceHeight(int h); 81 | void autoHeight(); 82 | 83 | void nextPageWithBlank(); // cycles through pages, and closes after last page 84 | 85 | ofxSimpleGuiPage& page(int i); // 1 based index of page 86 | ofxSimpleGuiPage& page(string name); // returns page by name 87 | ofxSimpleGuiPage& currentPage(); // returns current page 88 | vector & getPages(); 89 | 90 | ofxSimpleGuiControl &control(string name); // returns control by name 91 | 92 | 93 | ofxSimpleGuiPage &addPage(string name = ""); 94 | ofxSimpleGuiControl &addControl(ofxSimpleGuiControl& control); 95 | ofxSimpleGuiContent &addContent(string name, ofBaseDraws &content, float fixwidth = -1); 96 | ofxSimpleGuiButton &addButton(string name, bool &value); 97 | ofxSimpleGuiFPSCounter &addFPSCounter(); 98 | // ofxSimpleGuiMovieSlider &addMovieSlider(string name, ofVideoPlayer& input); 99 | ofxSimpleGuiQuadWarp &addQuadWarper(string name, ofBaseDraws &baseDraw, ofPoint *pts); 100 | ofxSimpleGuiSliderInt &addSlider(string name, int &value, int min, int max); 101 | ofxSimpleGuiSliderFloat &addSlider(string name, float &value, float min = 0.f, float max = 1.f); 102 | ofxSimpleGuiSlider2d &addSlider2d(string name, ofPoint& value, float xmin, float xmax, float ymin, float ymax); 103 | ofxSimpleGuiTitle &addTitle(string name="", float height = 0); 104 | ofxSimpleGuiToggle &addToggle(string name, bool &value); 105 | ofxSimpleGuiColorPicker &addColorPicker(string name, ofFloatColor& color); 106 | ofxSimpleGuiComboBox &addComboBox(string name, int &value, int numChoices, string* choiceTitles=NULL); 107 | ofxSimpleGuiComboBox &addComboBox(string name, int &value, vector& choiceTitles); 108 | 109 | 110 | void draw(); 111 | 112 | protected: 113 | bool doAutoSave = true; 114 | bool alignRight = false; 115 | bool doDefaultKeys = false; 116 | bool doSave = false;//, doSaveBackup; 117 | bool savePreset = false; 118 | bool loadPreset = false; 119 | bool doNextPage = false; 120 | bool doPrevPage = false; 121 | int forceHeight = false; 122 | int currentPageIndex = 0; // 1 based index of page (0 is for global controls) 123 | 124 | bool doDraw = true; 125 | float border; 126 | 127 | ofxSimpleGuiPage *headerPage; 128 | ofxSimpleGuiButton *titleButton; 129 | vector pages; // 0 is for headerPage 130 | 131 | void addListeners(); 132 | void removeListeners(); 133 | 134 | // void setup(ofEventArgs &e); 135 | void update(ofEventArgs &e); 136 | // void draw(ofEventArgs &e); 137 | // void exit(ofEventArgs &e); 138 | 139 | void mouseMoved(ofMouseEventArgs &e); 140 | void mousePressed(ofMouseEventArgs &e); 141 | void mouseDragged(ofMouseEventArgs &e); 142 | void mouseReleased(ofMouseEventArgs &e); 143 | 144 | void keyPressed(ofKeyEventArgs &e); 145 | void keyReleased(ofKeyEventArgs &e); 146 | }; 147 | 148 | 149 | extern ofxSimpleGuiToo gui; 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /src/ofxSimpleGuiValueControl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ofxSimpleGuiControlWithValue.cpp 3 | * MSA demo 4 | * 5 | * Created by Mehmet Akten on 18/08/2010. 6 | * Copyright 2010 MSA Visuals Ltd. All rights reserved. 7 | * 8 | */ 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/ofxSimpleGuiValueControl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofxSimpleGuiControl.h" 4 | 5 | template 6 | class ofxSimpleGuiValueControl : public ofxSimpleGuiControl { 7 | public: 8 | T *value; 9 | T oldValue; 10 | 11 | ofxSimpleGuiValueControl(string name, T &value) : ofxSimpleGuiControl(name), value(&value) {} 12 | 13 | virtual bool changed() { 14 | if(*value != oldValue) { 15 | oldValue = *value; 16 | return true; 17 | } 18 | return false; 19 | } 20 | 21 | // void update() { 22 | // } 23 | }; --------------------------------------------------------------------------------