Skip to content

Commit

Permalink
GDExt example: add ImPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Jul 12, 2024
1 parent 79b0a84 commit 2e98523
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
30 changes: 23 additions & 7 deletions doc/examples/GDExt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,30 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(imgui)

FetchContent_Declare(
implot
GIT_REPOSITORY https://github.com/epezent/implot
GIT_TAG master
)
FetchContent_MakeAvailable(implot)

add_library(gdexample SHARED)
target_compile_features(gdexample PRIVATE cxx_std_20)
target_compile_definitions(gdexample PUBLIC
IMGUI_USER_CONFIG="imconfig-godot.h"
)

target_sources(gdexample PRIVATE
imgui/imgui.cpp
imgui/imgui_demo.cpp
imgui/imgui_draw.cpp
imgui/imgui_tables.cpp
imgui/imgui_widgets.cpp
imgui/imgui.h
${FETCHCONTENT_BASE_DIR}/imgui-src/imgui.cpp
${FETCHCONTENT_BASE_DIR}/imgui-src/imgui_demo.cpp
${FETCHCONTENT_BASE_DIR}/imgui-src/imgui_draw.cpp
${FETCHCONTENT_BASE_DIR}/imgui-src/imgui_tables.cpp
${FETCHCONTENT_BASE_DIR}/imgui-src/imgui_widgets.cpp
${FETCHCONTENT_BASE_DIR}/imgui-src/imgui.h
${FETCHCONTENT_BASE_DIR}/implot-src/implot.cpp
${FETCHCONTENT_BASE_DIR}/implot-src/implot_demo.cpp
${FETCHCONTENT_BASE_DIR}/implot-src/implot_items.cpp
${FETCHCONTENT_BASE_DIR}/implot-src/implot.h
src/example.cpp
src/example.h
src/register_types.cpp
Expand All @@ -42,7 +53,12 @@ target_sources(gdexample PRIVATE

target_link_libraries(gdexample PUBLIC godot-cpp)

target_include_directories(gdexample PRIVATE src ${IMGUI_GODOT_INCLUDE} imgui)
target_include_directories(gdexample PRIVATE
src
${IMGUI_GODOT_INCLUDE}
${FETCHCONTENT_BASE_DIR}/imgui-src
${FETCHCONTENT_BASE_DIR}/implot-src
)

set_property(TARGET gdexample
PROPERTY OUTPUT_NAME "libgdexample.windows.template_$<IF:$<CONFIG:Debug>,debug,release>.x86_64")
Expand Down
7 changes: 7 additions & 0 deletions doc/examples/GDExt/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ if not os.path.exists("imgui"):
subprocess.call("git clone -b docking https://github.com/ocornut/imgui", shell=True)
subprocess.call(f"git -C imgui checkout {IMGUI_TAG}", shell=True)

if not os.path.exists("implot"):
subprocess.call("git clone https://github.com/epezent/implot", shell=True)

env = SConscript("godot-cpp/SConstruct")
env = env.Clone()

Expand All @@ -26,6 +29,10 @@ sources += Glob(f"imgui/*.cpp")
env.Append(CPPDEFINES=['IMGUI_USER_CONFIG="\\"imconfig-godot.h\\""'])
env.Append(CPPPATH=["imgui", IMGUI_GODOT_INCLUDE])

# ImPlot
sources += Glob(f"implot/*.cpp")
env.Append(CPPPATH=["implot", IMGUI_GODOT_INCLUDE])

if env["platform"] == "macos":
library = env.SharedLibrary(
"project/bin/libgdexample.{}.{}.framework/libgdexample.{}.{}".format(
Expand Down
5 changes: 4 additions & 1 deletion doc/examples/GDExt/src/example.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "example.h"
#include <godot_cpp/classes/resource_loader.hpp>
#include <imgui-godot.h>
#include <implot.h>

using godot::ResourceLoader;
using godot::Engine;
using godot::ResourceLoader;

void Example::_bind_methods()
{
Expand Down Expand Up @@ -38,4 +39,6 @@ void Example::_process(double delta)
ImGui::Separator();
ImGui::Image(_img, {64, 64});
ImGui::End();

ImPlot::ShowDemoWindow();
}
4 changes: 4 additions & 0 deletions doc/examples/GDExt/src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>
#include <imgui-godot.h>
#include <implot.h>

using godot::MODULE_INITIALIZATION_LEVEL_SCENE;

Expand All @@ -15,6 +16,7 @@ void initialize_example_module(ModuleInitializationLevel p_level)
return;

ImGui::Godot::SyncImGuiPtrs();
ImPlot::CreateContext();

godot::ClassDB::register_class<Example>();
}
Expand All @@ -23,6 +25,8 @@ void uninitialize_example_module(ModuleInitializationLevel p_level)
{
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE)
return;

ImPlot::DestroyContext();
}

extern "C" {
Expand Down

0 comments on commit 2e98523

Please sign in to comment.