Skip to content

Commit 592347e

Browse files
Introduction of ImGuiProvider Gem (#115)
* ImGuiProvider Gem for managing displaying of ImGui GUI * Added readme with new Gem Description * Added missing notifications after enabling/disabling debug ImGui --------- Signed-off-by: Norbert Prokopiuk <[email protected]>
1 parent 402e524 commit 592347e

File tree

59 files changed

+1942
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1942
-0
lines changed

Gems/ImGuiProvider/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
o3de_gem_setup("ImGuiProvider")
3+
4+
ly_add_external_target_path(${CMAKE_CURRENT_SOURCE_DIR}/3rdParty)
5+
6+
add_subdirectory(Code)
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
2+
# Currently we are in the Code folder: ${CMAKE_CURRENT_LIST_DIR}
3+
# Get the platform specific folder ${pal_dir} for the current folder: ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME}
4+
# Note: o3de_pal_dir will take care of the details for us, as this may be a restricted platform
5+
# in which case it will see if that platform is present here or in the restricted folder.
6+
# i.e. It could here in our gem : Gems/ImGuiProvider/Code/Platform/<platorm_name> or
7+
# <restricted_folder>/<platform_name>/Gems/ImGuiProvider/Code
8+
o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")
9+
10+
# Now that we have the platform abstraction layer (PAL) folder for this folder, thats where we will find the
11+
# traits for this platform. Traits for a platform are defines for things like whether or not something in this gem
12+
# is supported by this platform.
13+
include(${pal_dir}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
14+
15+
# Check to see if building the Gem Modules are supported for the current platform
16+
if(NOT PAL_TRAIT_IMGUIPROVIDER_SUPPORTED)
17+
return()
18+
endif()
19+
20+
# The ${gem_name}.API target declares the common interface that users of this gem should depend on in their targets
21+
ly_add_target(
22+
NAME ${gem_name}.API INTERFACE
23+
NAMESPACE Gem
24+
FILES_CMAKE
25+
imguiprovider_api_files.cmake
26+
${pal_dir}/imguiprovider_api_files.cmake
27+
INCLUDE_DIRECTORIES
28+
INTERFACE
29+
Include
30+
BUILD_DEPENDENCIES
31+
INTERFACE
32+
AZ::AzCore
33+
Gem::Atom_Feature_Common.Static
34+
)
35+
36+
# The ${gem_name}.Private.Object target is an internal target
37+
# It should not be used outside of this Gems CMakeLists.txt
38+
ly_add_target(
39+
NAME ${gem_name}.Private.Object STATIC
40+
NAMESPACE Gem
41+
FILES_CMAKE
42+
imguiprovider_private_files.cmake
43+
${pal_dir}/imguiprovider_private_files.cmake
44+
TARGET_PROPERTIES
45+
O3DE_PRIVATE_TARGET TRUE
46+
INCLUDE_DIRECTORIES
47+
PRIVATE
48+
Include
49+
Source
50+
BUILD_DEPENDENCIES
51+
PUBLIC
52+
AZ::AzCore
53+
AZ::AzFramework
54+
Gem::Atom_Feature_Common.Static
55+
)
56+
57+
58+
# Here add ${gem_name} target, it depends on the Private Object library and Public API interface
59+
ly_add_target(
60+
NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
61+
NAMESPACE Gem
62+
FILES_CMAKE
63+
imguiprovider_shared_files.cmake
64+
${pal_dir}/imguiprovider_shared_files.cmake
65+
INCLUDE_DIRECTORIES
66+
PUBLIC
67+
Include
68+
PRIVATE
69+
Source
70+
BUILD_DEPENDENCIES
71+
PUBLIC
72+
Gem::${gem_name}.API
73+
PRIVATE
74+
Gem::${gem_name}.Private.Object
75+
)
76+
77+
# Include the gem name into the Client Module source file
78+
# for use with the AZ_DECLARE_MODULE_CLASS macro
79+
# This is to allow renaming of the gem to also cause
80+
# the CreateModuleClass_Gem_<gem-name> function which
81+
# is used to bootstrap the gem in monolithic builds to link to the new gem name
82+
ly_add_source_properties(
83+
SOURCES
84+
Source/Clients/ImGuiProviderModule.cpp
85+
PROPERTY COMPILE_DEFINITIONS
86+
VALUES
87+
O3DE_GEM_NAME=${gem_name}
88+
O3DE_GEM_VERSION=${gem_version})
89+
90+
# By default, we will specify that the above target ${gem_name} would be used by
91+
# Client and Server type targets when this gem is enabled. If you don't want it
92+
# active in Clients or Servers by default, delete one of both of the following lines:
93+
ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
94+
ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name})
95+
ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})
96+
97+
# For the Client and Server variants of ${gem_name} Gem, an alias to the ${gem_name}.API target will be made
98+
ly_create_alias(NAME ${gem_name}.Clients.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
99+
ly_create_alias(NAME ${gem_name}.Servers.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
100+
ly_create_alias(NAME ${gem_name}.Unified.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
101+
102+
# Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
103+
# for the Clients, Servers, Unified gem variants
104+
o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Clients Servers Unified)
105+
106+
# If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Editor MODULE target
107+
if(PAL_TRAIT_BUILD_HOST_TOOLS)
108+
# The ${gem_name}.Editor.API target can be used by other gems that want to interact with the ${gem_name}.Editor module
109+
ly_add_target(
110+
NAME ${gem_name}.Editor.API INTERFACE
111+
NAMESPACE Gem
112+
FILES_CMAKE
113+
imguiprovider_editor_api_files.cmake
114+
${pal_dir}/imguiprovider_editor_api_files.cmake
115+
INCLUDE_DIRECTORIES
116+
INTERFACE
117+
Include
118+
BUILD_DEPENDENCIES
119+
INTERFACE
120+
AZ::AzToolsFramework
121+
)
122+
123+
# The ${gem_name}.Editor.Private.Object target is an internal target
124+
# which is only to be used by this gems CMakeLists.txt and any subdirectories
125+
# Other gems should not use this target
126+
ly_add_target(
127+
NAME ${gem_name}.Editor.Private.Object STATIC
128+
NAMESPACE Gem
129+
FILES_CMAKE
130+
imguiprovider_editor_private_files.cmake
131+
TARGET_PROPERTIES
132+
O3DE_PRIVATE_TARGET TRUE
133+
INCLUDE_DIRECTORIES
134+
PRIVATE
135+
Include
136+
Source
137+
BUILD_DEPENDENCIES
138+
PUBLIC
139+
AZ::AzToolsFramework
140+
${gem_name}.Private.Object
141+
Gem::Atom_Feature_Common.Static
142+
)
143+
144+
ly_add_target(
145+
NAME ${gem_name}.Editor GEM_MODULE
146+
NAMESPACE Gem
147+
AUTOMOC
148+
FILES_CMAKE
149+
imguiprovider_editor_shared_files.cmake
150+
INCLUDE_DIRECTORIES
151+
PRIVATE
152+
Source
153+
PUBLIC
154+
Include
155+
BUILD_DEPENDENCIES
156+
PUBLIC
157+
Gem::${gem_name}.Editor.API
158+
PRIVATE
159+
Gem::${gem_name}.Editor.Private.Object
160+
)
161+
162+
# Include the gem name into the Editor Module source file
163+
# for use with the AZ_DECLARE_MODULE_CLASS macro
164+
# This is to allow renaming of the gem to also cause
165+
# the CreateModuleClass_Gem_<gem-name> function which
166+
# is used to bootstrap the gem in monolithic builds to link to the new gem name
167+
ly_add_source_properties(
168+
SOURCES
169+
Source/Tools/ImGuiProviderEditorModule.cpp
170+
PROPERTY COMPILE_DEFINITIONS
171+
VALUES
172+
O3DE_GEM_NAME=${gem_name}
173+
O3DE_GEM_VERSION=${gem_version})
174+
175+
# By default, we will specify that the above target ${gem_name} would be used by
176+
# Tool and Builder type targets when this gem is enabled. If you don't want it
177+
# active in Tools or Builders by default, delete one of both of the following lines:
178+
ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
179+
ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
180+
181+
# For the Tools and Builders variants of ${gem_name} Gem, an alias to the ${gem_name}.Editor API target will be made
182+
ly_create_alias(NAME ${gem_name}.Tools.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
183+
ly_create_alias(NAME ${gem_name}.Builders.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
184+
185+
# Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
186+
# for the Tools and Builders gem variants
187+
o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Tools Builders)
188+
endif()
189+
190+
################################################################################
191+
# Tests
192+
################################################################################
193+
# See if globally, tests are supported
194+
if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
195+
# We globally support tests, see if we support tests on this platform for ${gem_name}.Tests
196+
# We support ${gem_name}.Tests on this platform, add dependency on the Private Object target
197+
ly_add_target(
198+
NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
199+
NAMESPACE Gem
200+
FILES_CMAKE
201+
imguiprovider_tests_files.cmake
202+
INCLUDE_DIRECTORIES
203+
PRIVATE
204+
Tests
205+
Source
206+
Include
207+
BUILD_DEPENDENCIES
208+
PRIVATE
209+
AZ::AzTest
210+
AZ::AzFramework
211+
Gem::${gem_name}.Private.Object
212+
)
213+
214+
# Add ${gem_name}.Tests to googletest
215+
ly_add_googletest(
216+
NAME Gem::${gem_name}.Tests
217+
)
218+
219+
# unit test for Menu tree utils
220+
ly_add_target(
221+
NAME ImGuiProvider.MenuTree.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
222+
NAMESPACE Gem
223+
FILES_CMAKE
224+
imguiprovder_menu_tree_tests_files.cmake
225+
INCLUDE_DIRECTORIES
226+
PRIVATE
227+
Source
228+
Tests
229+
BUILD_DEPENDENCIES
230+
PRIVATE
231+
AZ::AzTestShared
232+
AZ::AzToolsFramework
233+
AZ::AzManipulatorTestFramework.Static
234+
Gem::${gem_name}.API
235+
Gem::${gem_name}.Private.Object
236+
)
237+
target_compile_options(ImGuiProvider.MenuTree.Tests PUBLIC -fexceptions)
238+
set_target_properties(ImGuiProvider.MenuTree.Tests PROPERTIES UNITY_BUILD OFF)
239+
ly_add_googletest(
240+
NAME Gem::ImGuiProvider.MenuTree.Tests
241+
)
242+
243+
244+
245+
# If we are a host platform we want to add tools test like editor tests here
246+
if(PAL_TRAIT_BUILD_HOST_TOOLS)
247+
# We are a host platform, see if Editor tests are supported on this platform
248+
# We support ${gem_name}.Editor.Tests on this platform, add ${gem_name}.Editor.Tests target which depends on
249+
# private ${gem_name}.Editor.Private.Object target
250+
ly_add_target(
251+
NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
252+
NAMESPACE Gem
253+
FILES_CMAKE
254+
imguiprovider_editor_tests_files.cmake
255+
INCLUDE_DIRECTORIES
256+
PRIVATE
257+
Tests
258+
Source
259+
Include
260+
BUILD_DEPENDENCIES
261+
PRIVATE
262+
AZ::AzTest
263+
Gem::${gem_name}.Editor.Private.Object
264+
)
265+
266+
# Add ${gem_name}.Editor.Tests to googletest
267+
ly_add_googletest(
268+
NAME Gem::${gem_name}.Editor.Tests
269+
)
270+
endif()
271+
endif()
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
#pragma once
3+
4+
#include <AzCore/Component/ComponentBus.h>
5+
#include <AzCore/Component/EntityId.h>
6+
#include <AzCore/RTTI/TypeInfo.h>
7+
#include <AzCore/base.h>
8+
#include <AzCore/std/containers/vector.h>
9+
#include <AzCore/std/optional.h>
10+
#include <AzCore/std/string/string.h>
11+
#include <ImGuiProvider/ImGuiProviderTypeIds.h>
12+
13+
#include <Atom/Feature/ImGui/SystemBus.h>
14+
#include <AzCore/EBus/EBus.h>
15+
#include <AzCore/IO/Path/Path.h>
16+
#include <AzCore/Interface/Interface.h>
17+
18+
namespace ImGuiProvider
19+
{
20+
// path to feature on the toolbar e.g. "Tools1/Tools2/ActualFeature"
21+
using ImGuiFeaturePath = AZ::IO::Path;
22+
23+
class ImGuiProviderRequests
24+
{
25+
public:
26+
AZ_RTTI(ImGuiProviderRequests, ImGuiProviderRequestsTypeId);
27+
virtual ~ImGuiProviderRequests() = default;
28+
29+
//! @brief Retruns id of currently selected GUI if any is active, nullopt is no gu is active
30+
virtual AZStd::optional<ImGuiFeaturePath> GetActiveGuiId() = 0;
31+
32+
//! @brief Activates GUI with given ID
33+
//! @param guiIdToActivate id of gui to activate. Id is set during registration;
34+
virtual void SetActiveGUI(const ImGuiFeaturePath& guiIdToActivate) = 0;
35+
};
36+
37+
class ImGuiProviderBusTraits : public AZ::EBusTraits
38+
{
39+
public:
40+
//////////////////////////////////////////////////////////////////////////
41+
// EBusTraits overrides
42+
static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
43+
static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
44+
//////////////////////////////////////////////////////////////////////////
45+
};
46+
47+
using ImGuiProviderRequestBus = AZ::EBus<ImGuiProviderRequests, ImGuiProviderBusTraits>;
48+
using ImGuiProviderInterface = AZ::Interface<ImGuiProviderRequests>;
49+
50+
class ImGuiProviderNotifications : public AZ::ComponentBus
51+
{
52+
public:
53+
AZ_RTTI(ImGuiProviderNotifications, ImGuiProviderNotificationsTypeId);
54+
virtual ~ImGuiProviderNotifications() = default;
55+
56+
//! @brief Called to trigger ImGui update
57+
virtual void OnImGuiUpdate()
58+
{
59+
}
60+
61+
//! @brief Called when ImGui registered by the handler was selected and is currently displayed.
62+
//! Called once per state change (hidden -> visible)
63+
virtual void OnImGuiSelected()
64+
{
65+
}
66+
67+
//! @brief Called when ImGui registered by the handler was unselected and is currently hidden.
68+
//! Called once per state change (visible -> hidden)
69+
virtual void OnImGuiUnselected()
70+
{
71+
}
72+
};
73+
74+
class ImGuiProviderNotificationBusTraits : public AZ::EBusTraits
75+
{
76+
public:
77+
//////////////////////////////////////////////////////////////////////////
78+
// EBusTraits overrides
79+
using BusIdType = ImGuiFeaturePath;
80+
static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
81+
static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
82+
//////////////////////////////////////////////////////////////////////////
83+
};
84+
85+
using ImGuiProviderNotificationBus = AZ::EBus<ImGuiProviderNotifications, ImGuiProviderNotificationBusTraits>;
86+
87+
} // namespace ImGuiProvider
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
#pragma once
3+
4+
namespace ImGuiProvider
5+
{
6+
// System Component TypeIds
7+
inline constexpr const char* ImGuiProviderSystemComponentTypeId = "{EC45C197-1A3E-44DB-BC61-4CB46BE33EB9}";
8+
inline constexpr const char* ImGuiProviderEditorSystemComponentTypeId = "{F587B9A3-7CC4-480A-BC7A-3065317F1B7A}";
9+
10+
// Module derived classes TypeIds
11+
inline constexpr const char* ImGuiProviderModuleInterfaceTypeId = "{45D939AA-9177-47B7-9765-105EEEDABD84}";
12+
inline constexpr const char* ImGuiProviderModuleTypeId = "{2819D2AA-B3E6-4653-B108-502168902968}";
13+
// The Editor Module by default is mutually exclusive with the Client Module
14+
// so they use the Same TypeId
15+
inline constexpr const char* ImGuiProviderEditorModuleTypeId = ImGuiProviderModuleTypeId;
16+
17+
// Interface TypeIds
18+
inline constexpr const char* ImGuiProviderRequestsTypeId = "{C13938F9-A14D-4DE5-8833-6690DD1CA778}";
19+
inline constexpr const char* ImGuiProviderNotificationsTypeId = "{a382fe14-af02-4eb9-a1ad-31cee42b9d46}";
20+
} // namespace ImGuiProvider
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
set(PAL_TRAIT_IMGUIPROVIDER_SUPPORTED TRUE)
3+
set(PAL_TRAIT_IMGUIPROVIDER_TEST_SUPPORTED FALSE)
4+
set(PAL_TRAIT_IMGUIPROVIDER_EDITOR_TEST_SUPPORTED FALSE)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
set(FILES
3+
)

0 commit comments

Comments
 (0)