Skip to content

Commit 46acce3

Browse files
committed
feat: add gui sample
1 parent 6f84b01 commit 46acce3

File tree

9 files changed

+303
-23
lines changed

9 files changed

+303
-23
lines changed

engine/samples/12_gui/CMakeLists.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#////////////////////////////////////////////////////////////////////////////////////////////////////
2+
#// Copyright (c) 2024 RacoonStudios
3+
#//
4+
#// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5+
#// software and associated documentation files (the "Software"), to deal in the Software
6+
#// without restriction, including without limitation the rights to use, copy, modify, merge,
7+
#// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8+
#// to whom the Software is furnished to do so, subject to the following conditions:
9+
#//
10+
#// The above copyright notice and this permission notice shall be included in all copies or
11+
#// substantial portions of the Software.
12+
#//
13+
#// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
#// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15+
#// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16+
#// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17+
#// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18+
#// DEALINGS IN THE SOFTWARE.
19+
#////////////////////////////////////////////////////////////////////////////////////////////////////
20+
21+
22+
##################################################
23+
## Project
24+
##################################################
25+
re_add_target(
26+
NAME 12_gui EXECUTABLE
27+
NAMESPACE RE
28+
FILES_CMAKE
29+
${CMAKE_CURRENT_SOURCE_DIR}/gui_files.cmake
30+
PLATFORM_INCLUDE_FILES
31+
${CMAKE_CURRENT_SOURCE_DIR}/gui_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
32+
INCLUDE_DIRECTORIES
33+
PUBLIC
34+
${ME_CONFIG_FILE_LOCATION}
35+
${CMAKE_CURRENT_SOURCE_DIR}/public
36+
${CMAKE_CURRENT_SOURCE_DIR}/private
37+
BUILD_DEPENDENCIES
38+
PUBLIC
39+
core
40+
gui
41+
RUNTIME_DEPENDENCIES
42+
PUBLIC
43+
core
44+
gui
45+
COMPILE_DEFINITIONS
46+
PUBLIC
47+
${${PAL_PLATFORM_NAME_UPPERCASE}_COMPILE_DEFS}
48+
${PAL_PLATFORM_NAME_UPPERCASE}
49+
TARGET_PROPERTIES
50+
-fPIC
51+
)

engine/foundation/gui/gui_linux_files.cmake renamed to engine/samples/12_gui/gui_files.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#////////////////////////////////////////////////////////////////////////////////////////////////////
2-
#// Copyright (c) 2025 RacoonStudios
2+
#// Copyright (c) 2024 RacoonStudios
33
#//
44
#// Permission is hereby granted, free of charge, to any person obtaining a copy of this
55
#// software and associated documentation files (the "Software"), to deal in the Software
@@ -20,7 +20,7 @@
2020

2121

2222
set(FILES
23-
private/linux/linux_clipboard.cpp
24-
private/linux/linux_graphics.cpp
25-
private/linux/linux_gui.cpp
23+
private/main.cpp
24+
private/application.cpp
25+
private/sample_window.cpp
2626
)

engine/foundation/gui/gui_linux.cmake renamed to engine/samples/12_gui/gui_linux.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#////////////////////////////////////////////////////////////////////////////////////////////////////
2-
#// Copyright (c) 2025 RacoonStudios
2+
#// Copyright (c) 2024 RacoonStudios
33
#//
44
#// Permission is hereby granted, free of charge, to any person obtaining a copy of this
55
#// software and associated documentation files (the "Software"), to deal in the Software
@@ -25,7 +25,7 @@ set(RE_BUILD_DEPENDENCIES
2525
dl
2626
atomic
2727
ncurses
28-
uuid
29-
${LINUX_XCB_LIBS}
30-
${LINUX_CAIRO_LIBS}
31-
)
28+
${LINUX_X11_LIBS}
29+
${DBUS_LIBRARIES}
30+
stdc++fs
31+
)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2024 RacoonStudios
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5+
// software and associated documentation files (the "Software"), to deal in the Software
6+
// without restriction, including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8+
// to whom the Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all copies or
11+
// substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18+
// DEALINGS IN THE SOFTWARE.
19+
////////////////////////////////////////////////////////////////////////////////////////////////////
20+
21+
22+
//[-------------------------------------------------------]
23+
//[ Includes ]
24+
//[-------------------------------------------------------]
25+
#include "application.h"
26+
#include "sample_window.h"
27+
#include <core/frontend/cursor_device.h>
28+
#include <core/frontend/window_device.h>
29+
#include <gui/gui/gui_server.h>
30+
#include <gui/gui/gui_window_callback.h>
31+
32+
33+
Application::Application()
34+
: gui::GuiApplication() {
35+
36+
}
37+
38+
Application::~Application() {
39+
40+
}
41+
42+
43+
44+
core::Ptr<gui::GuiWindow> Application::create_window(const core::WindowCreateDesc& windowCreateDesc) {
45+
core::uint32 colorId = get_window_device()->get_num_windows();
46+
auto window = get_window_device()->create_window(windowCreateDesc);
47+
48+
// Append gui_window_callbacks
49+
window->add_window_callback(new gui::GuiWindowCallbacks());
50+
51+
SampleWindow* guiWindow = new SampleWindow(mGuiServer, colorId);
52+
gui::GuiWindow* mainWindow = get_gui_server()->create_window(guiWindow, window);
53+
54+
return core::Ptr<gui::GuiWindow>(guiWindow);
55+
}
56+
57+
58+
void Application::main() {
59+
auto window = create_window({"Some window", core::Recti(100, 100, 800, 600), core::EWindowStyle::WindowStyle_NoBorder});
60+
//auto window2 = create_window("Some window", core::Recti(200, 200, 800, 600), core::EWindowStyle::WindowStyle_NoBorder);
61+
62+
while (true && get_window_device()->get_num_windows() > 0) {
63+
gui::GuiApplication::on_update();
64+
gui::GuiApplication::on_draw();
65+
}
66+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2024 RacoonStudios
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5+
// software and associated documentation files (the "Software"), to deal in the Software
6+
// without restriction, including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8+
// to whom the Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all copies or
11+
// substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18+
// DEALINGS IN THE SOFTWARE.
19+
////////////////////////////////////////////////////////////////////////////////////////////////////
20+
21+
22+
//[-------------------------------------------------------]
23+
//[ Includes ]
24+
//[-------------------------------------------------------]
25+
#include <core/main.h>
26+
#include "application.h"
27+
28+
29+
//[-------------------------------------------------------]
30+
//[ Program entry point ]
31+
//[-------------------------------------------------------]
32+
// This is the real entry point for any RacoonEngine executable. You must define this function if you
33+
// include <PLCore/Main.h> in your project. The parameters passed by the engine into this function
34+
// are self-explanatory.
35+
int be_main(const core::String &sExecutableFilename, const core::Vector<core::String> &lstArguments) {
36+
// We just create an instance of our very basic application class and run it. This will result
37+
// in the engine being initialized into usable state and the above Application::Main method
38+
// being called. Note that only the very essential engine systems are initialized, such as log
39+
// and plugin system. We will explore the initialization of more advanced systems (such as renderer)
40+
// in future exercise.
41+
Application app;
42+
return app.run(sExecutableFilename, lstArguments);
43+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2024 RacoonStudios
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5+
// software and associated documentation files (the "Software"), to deal in the Software
6+
// without restriction, including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8+
// to whom the Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all copies or
11+
// substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18+
// DEALINGS IN THE SOFTWARE.
19+
////////////////////////////////////////////////////////////////////////////////////////////////////
20+
21+
22+
//[-------------------------------------------------------]
23+
//[ Includes ]
24+
//[-------------------------------------------------------]
25+
#include "sample_window.h"
26+
#include <core/color/color4.h>
27+
#include <imgui.h>
28+
29+
30+
//[-------------------------------------------------------]
31+
//[ Classes ]
32+
//[-------------------------------------------------------]
33+
SampleWindow::SampleWindow(core::Ptr<gui::GuiServer>& gui, core::uint32 colorId)
34+
: gui::GuiWindow(gui)
35+
, mColorId(colorId) {
36+
37+
}
38+
39+
SampleWindow::~SampleWindow() {
40+
41+
}
42+
43+
void SampleWindow::draw() {
44+
ImGui::ShowDemoWindow();
45+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2024 RacoonStudios
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5+
// software and associated documentation files (the "Software"), to deal in the Software
6+
// without restriction, including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8+
// to whom the Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all copies or
11+
// substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18+
// DEALINGS IN THE SOFTWARE.
19+
////////////////////////////////////////////////////////////////////////////////////////////////////
20+
21+
22+
//[-------------------------------------------------------]
23+
//[ Header guard ]
24+
//[-------------------------------------------------------]
25+
#pragma once
26+
27+
28+
//[-------------------------------------------------------]
29+
//[ Includes ]
30+
//[-------------------------------------------------------]
31+
#include <gui/application/gui_application.h>
32+
33+
34+
//[-------------------------------------------------------]
35+
//[ Classes ]
36+
//[-------------------------------------------------------]
37+
/**
38+
* @class
39+
* Application
40+
*
41+
* @brief
42+
* Example gui application.
43+
*/
44+
class Application : public gui::GuiApplication {
45+
46+
public:
47+
48+
/**
49+
* @brief
50+
* Constructor.
51+
*
52+
* @param[in] frontend
53+
* Reference to the frontend instance.
54+
*/
55+
Application();
56+
57+
/**
58+
* @brief
59+
* Destructor.
60+
*/
61+
~Application() override;
62+
63+
64+
public:
65+
66+
void main() override;
67+
68+
69+
public:
70+
71+
core::Ptr<gui::GuiWindow> create_window(const core::WindowCreateDesc& windowCreateDesc) override;
72+
};
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
////////////////////////////////////////////////////////////////////////////////////////////////////
2-
// Copyright (c) 2025 RacoonStudios
2+
// Copyright (c) 2024 RacoonStudios
33
//
44
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
55
// software and associated documentation files (the "Software"), to deal in the Software
@@ -20,29 +20,31 @@
2020

2121

2222
//[-------------------------------------------------------]
23-
//[ Includes ]
23+
//[ Header guard ]
2424
//[-------------------------------------------------------]
25-
#include "gui/gui/gui_impl.h"
25+
#pragma once
2626

2727

2828
//[-------------------------------------------------------]
29-
//[ Namespace ]
29+
//[ Includes ]
3030
//[-------------------------------------------------------]
31-
namespace gui {
31+
#include <gui/gui/gui_window.h>
3232

3333

3434
//[-------------------------------------------------------]
3535
//[ Classes ]
3636
//[-------------------------------------------------------]
37-
GuiImpl::GuiImpl(Gui* gui)
38-
: mGui(gui) {
39-
}
37+
class SampleWindow : public gui::GuiWindow {
38+
public:
39+
SampleWindow(core::Ptr<gui::GuiServer>& gui, core::uint32 colorId);
4040

41-
GuiImpl::~GuiImpl() {
42-
}
41+
~SampleWindow() override;
4342

43+
public:
4444

45-
//[-------------------------------------------------------]
46-
//[ Namespace ]
47-
//[-------------------------------------------------------]
48-
}
45+
void draw() override;
46+
47+
private:
48+
49+
core::uint32 mColorId;
50+
};

engine/samples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ re_add_subdirectory(05_sample_plugin)
2828
re_add_subdirectory(06_sample_plugin_app)
2929
re_add_subdirectory(10_frontend)
3030
re_add_subdirectory(11_frontend_multiwindow)
31+
re_add_subdirectory(12_gui)
3132
re_add_subdirectory(20_low_level_rendering)

0 commit comments

Comments
 (0)