Skip to content

Commit

Permalink
expand module demo
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Apr 25, 2024
1 parent 3f1a5fa commit 0ca734b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
20 changes: 15 additions & 5 deletions doc/examples/Module/modules/mymod/mynode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "mynode.h"
#include "core/config/engine.h"
#include <cstdio>
#include "core/io/resource_loader.h"
#include <imgui-godot.h>

MyNode::MyNode()
Expand All @@ -22,13 +22,23 @@ void MyNode::_bind_methods()

void MyNode::_notification(int what)
{
#ifdef DEBUG_ENABLED
if (Engine::get_singleton()->is_editor_hint())
return;
#endif

switch (what)
{
case NOTIFICATION_PROCESS: {
ImGui::Begin("C++ module");
case NOTIFICATION_PROCESS:
ImGui::Begin("C++ module", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("hello");
ImGui::Image(_img, {_iconSize, _iconSize});
ImGui::DragFloat("size", &_iconSize, 1.f, 32.f, 512.f);
ImGui::End();
}
break;
break;

case NOTIFICATION_READY:
_img = ResourceLoader::load("res://icon.svg");
break;
}
}
6 changes: 5 additions & 1 deletion doc/examples/Module/modules/mymod/mynode.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "scene/main/node.h"
#include "scene/resources/texture.h"

class MyNode : public Node
{
Expand All @@ -14,4 +14,8 @@ class MyNode : public Node
public:
MyNode();
~MyNode();

private:
Ref<Texture2D> _img;
float _iconSize = 64.f;
};
4 changes: 2 additions & 2 deletions doc/examples/Module/project/icon.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
Expand All @@ -32,6 +32,6 @@ process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
svg/scale=4.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
16 changes: 8 additions & 8 deletions gdext/include/imgui-godot.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ using godot::Window;
#else
// module
#include "core/config/engine.h"
#include "core/input/input_enums.h"
#include "core/os/keyboard.h"
#include "core/variant/callable.h"
#include "scene/main/viewport.h"
#include "scene/main/window.h"
#include "scene/resources/texture.h"
#include "core/os/keyboard.h"
#include "core/input/input_enums.h"
#endif

static_assert(sizeof(RID) == 8);
Expand Down Expand Up @@ -647,36 +647,36 @@ inline ImGuiKey ToImGuiKey(JoyButton btn)
namespace ImGui {
inline bool SubViewport(SubViewport* svp)
{
ERR_FAIL_COND_V(!Godot::detail::GET_IMGUIGD(), false);
ERR_FAIL_COND_V(!ImGui::Godot::detail::GET_IMGUIGD(), false);
static const StringName sn("SubViewport");
return Godot::detail::ImGuiGD->call(sn, svp);
return ImGui::Godot::detail::ImGuiGD->call(sn, svp);
}

inline void Image(Texture2D* tex, const Vector2& size, const Vector2& uv0 = {0, 0}, const Vector2& uv1 = {1, 1},
const Color& tint_col = {1, 1, 1, 1}, const Color& border_col = {0, 0, 0, 0})
{
ImGui::Image(Godot::BindTexture(tex), size, uv0, uv1, tint_col, border_col);
ImGui::Image(ImGui::Godot::BindTexture(tex), size, uv0, uv1, tint_col, border_col);
}

inline void Image(const Ref<Texture2D>& tex, const Vector2& size, const Vector2& uv0 = {0, 0},
const Vector2& uv1 = {1, 1}, const Color& tint_col = {1, 1, 1, 1},
const Color& border_col = {0, 0, 0, 0})
{
ImGui::Image(Godot::BindTexture(tex.ptr()), size, uv0, uv1, tint_col, border_col);
ImGui::Image(ImGui::Godot::BindTexture(tex.ptr()), size, uv0, uv1, tint_col, border_col);
}

inline bool ImageButton(const char* str_id, Texture2D* tex, const Vector2& size, const Vector2& uv0 = {0, 0},
const Vector2& uv1 = {1, 1}, const Color& bg_col = {0, 0, 0, 0},
const Color& tint_col = {1, 1, 1, 1})
{
return ImGui::ImageButton(str_id, Godot::BindTexture(tex), size, uv0, uv1, bg_col, tint_col);
return ImGui::ImageButton(str_id, ImGui::Godot::BindTexture(tex), size, uv0, uv1, bg_col, tint_col);
}

inline bool ImageButton(const char* str_id, const Ref<Texture2D>& tex, const Vector2& size, const Vector2& uv0 = {0, 0},
const Vector2& uv1 = {1, 1}, const Color& bg_col = {0, 0, 0, 0},
const Color& tint_col = {1, 1, 1, 1})
{
return ImGui::ImageButton(str_id, Godot::BindTexture(tex.ptr()), size, uv0, uv1, bg_col, tint_col);
return ImGui::ImageButton(str_id, ImGui::Godot::BindTexture(tex.ptr()), size, uv0, uv1, bg_col, tint_col);
}
} // namespace ImGui
#endif
Expand Down

0 comments on commit 0ca734b

Please sign in to comment.