Skip to content

Commit

Permalink
test C++ widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Jul 31, 2023
1 parent df0d24f commit cdcd43c
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 76 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ gdext/proj/platform/

addons/imgui-godot-native/
gdext/proj/addons/imgui-godot/
gdext/samples/project/addons/
2 changes: 1 addition & 1 deletion addons/imgui-godot/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="imgui-godot"
description="Dear ImGui for Godot"
author="Patrick Dawson"
version="5.0.0-dev"
version="5.0.0-beta1"
script="scripts/ImGuiPlugin.gd"
10 changes: 8 additions & 2 deletions gdext/include/imgui-godot.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,24 @@ inline void Image(Texture2D* tex, const Vector2& size, const Vector2& uv0 = {0,
ImGui::Image(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(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, BindTexture(tex), size, uv0, uv1, bg_col, tint_col);
}

inline bool ImageButton(const String& str_id, Texture2D* tex, const Vector2& size, const Vector2& uv0 = {0, 0},
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.utf8().get_data(), BindTexture(tex), size, uv0, uv1, bg_col, tint_col);
return ImGui::ImageButton(str_id, BindTexture(tex.ptr()), size, uv0, uv1, bg_col, tint_col);
}

#ifdef IGN_GDEXT
Expand Down
2 changes: 1 addition & 1 deletion gdext/proj/addons/imgui-godot-native/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ name="imgui-godot-native"
description="Dear ImGui for Godot native extensions
Requires imgui-godot"
author="Patrick Dawson"
version="5.0.0-dev"
version="5.0.0-beta1"
script="plugin.gd"
Binary file removed gdext/samples/project/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions gdext/samples/project/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

importer="texture"
type="CompressedTexture2D"
uid="uid://cswr8vy4lt7dt"
path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"
uid="uid://c5ubx0utpymse"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.png"
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]

[params]

Expand All @@ -32,3 +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
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
20 changes: 0 additions & 20 deletions gdext/samples/project/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,3 @@
[node name="Node" type="Node"]

[node name="ExtNode" type="ExtNode" parent="."]

[node name="SampleNode" type="SampleNode" parent="."]
_import_path = NodePath("")
unique_name_in_owner = false
process_mode = 0
process_priority = 0
process_physics_priority = 0
process_thread_group = 0
editor_description = ""
script = null

[node name="AnotherNode" type="AnotherNode" parent="."]
_import_path = NodePath("")
unique_name_in_owner = false
process_mode = 0
process_priority = 0
process_physics_priority = 0
process_thread_group = 0
editor_description = ""
script = null
2 changes: 1 addition & 1 deletion gdext/samples/project/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ config_version=5
config/name="GDExtension Test Project"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.1")
config/icon="res://icon.png"
config/icon="res://icon.svg"

[autoload]

Expand Down
18 changes: 18 additions & 0 deletions gdext/samples/sample_gdext/src/ext_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@

// #include <godot_cpp/classes/global_constants.hpp>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/classes/texture2d.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
// #include <godot_cpp/variant/utility_functions.hpp>

using namespace godot;

struct ExtNode::Impl
{
Ref<Texture2D> tex;
};

ExtNode::ExtNode() : impl(std::make_unique<Impl>())
{
}

ExtNode::~ExtNode()
{
}

void ExtNode::_bind_methods()
{
ClassDB::bind_method(D_METHOD("imgui_layout"), &ExtNode::imgui_layout);
Expand All @@ -20,6 +35,8 @@ void ExtNode::_ready()
#endif
ImGui::Godot::SyncImGuiPtrs();
ImGui::Godot::Connect(Callable(this, "imgui_layout"));

impl->tex = ResourceLoader::get_singleton()->load("res://icon.svg");
}

void ExtNode::_process(double delta)
Expand All @@ -30,6 +47,7 @@ void ExtNode::_process(double delta)
#endif
ImGui::Begin("ExtNode process");
ImGui::Text("text 1");
ImGui::Godot::Image(impl->tex, {128, 128});
ImGui::End();
}

Expand Down
7 changes: 7 additions & 0 deletions gdext/samples/sample_gdext/src/ext_node.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <memory>
#include <godot_cpp/classes/node.hpp>

using namespace godot;
Expand All @@ -12,7 +13,13 @@ class ExtNode : public Node
static void _bind_methods();

public:
ExtNode();
~ExtNode();
void _ready() override;
void _process(double delta) override;
void imgui_layout();

private:
struct Impl;
std::unique_ptr<Impl> impl;
};
32 changes: 1 addition & 31 deletions gdext/src/ImGuiGD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,6 @@ void ImGuiGD::_bind_methods()

ClassDB::bind_static_method("ImGuiGD", D_METHOD("SetVisible", "visible"), &ImGuiGD::SetVisible);

ClassDB::bind_static_method("ImGuiGD",
D_METHOD("Image", "tex", "size", "uv0", "uv1", "tint_col", "border_col"),
&ImGuiGD::Image,
DEFVAL(Vector2(0, 0)),
DEFVAL(Vector2(1, 1)),
DEFVAL(Color(1, 1, 1, 1)),
DEFVAL(Color(0, 0, 0, 0)));

ClassDB::bind_static_method(
"ImGuiGD",
D_METHOD("ImageButton", "str_id", "tex", "size", "uv0", "uv1", "tint_col", "border_col"),
&ImGuiGD::ImageButton,
DEFVAL(Vector2(0, 0)),
DEFVAL(Vector2(1, 1)),
DEFVAL(Color(0, 0, 0, 0)),
DEFVAL(Color(1, 1, 1, 1)));

ClassDB::bind_static_method("ImGuiGD", D_METHOD("SubViewport", "svp"), &ImGuiGD::SubViewport);

ClassDB::bind_static_method("ImGuiGD", D_METHOD("GetFontPtrs"), &ImGuiGD::GetFontPtrs);
Expand Down Expand Up @@ -133,7 +116,7 @@ PackedInt64Array ImGuiGD::GetImGuiPtrs(String version, int ioSize, int vertSize,
if (version != String(ImGui::GetVersion()) || ioSize != sizeof(ImGuiIO) || vertSize != sizeof(ImDrawVert) ||
idxSize != sizeof(ImDrawIdx) || charSize != sizeof(ImWchar))
{
UtilityFunctions::printerr("ImGui version mismatch, use ", ImGui::GetVersion(), "-docking");
UtilityFunctions::push_error("ImGui version mismatch, use ", ImGui::GetVersion(), "-docking");
return {};
}

Expand All @@ -151,19 +134,6 @@ PackedInt64Array ImGuiGD::GetImGuiPtrs(String version, int ioSize, int vertSize,
return rv;
}

void ImGuiGD::Image(Texture2D* tex, const Vector2& size, const Vector2& uv0, const Vector2& uv1, const Color& tint_col,
const Color& border_col)
{
ImGui::Godot::Image(tex, size, uv0, uv1, tint_col, border_col);
}

bool ImGuiGD::ImageButton(const String& str_id, Texture2D* tex, const Vector2& size, const Vector2& uv0,
const Vector2& uv1, const Color& bg_col, const Color& tint_col)

{
return ImGui::Godot::ImageButton(str_id, tex, size, uv0, uv1, bg_col, tint_col);
}

bool ImGuiGD::SubViewport(godot::SubViewport* svp)
{
return ImGui::Godot::SubViewport(svp);
Expand Down
7 changes: 0 additions & 7 deletions gdext/src/ImGuiGD.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ class ImGuiGD : public Object
static PackedInt64Array GetFontPtrs();
static PackedInt64Array GetImGuiPtrs(String version, int ioSize, int vertSize, int idxSize, int charSize);

static 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});

static bool ImageButton(const String& 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});

static bool SubViewport(godot::SubViewport* svp);
};

Expand Down
18 changes: 9 additions & 9 deletions src/MyTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public override void _Process(double delta)
}
}

private void ImGuiLayout()
{
if (_window2Open)
{
ImGui.Begin("tool signal window", ref _window2Open);
ImGui.Text("always visible");
ImGui.End();
}
}
//private void ImGuiLayout()
//{
// if (_window2Open)
// {
// ImGui.Begin("tool signal window", ref _window2Open);
// ImGui.Text("always visible");
// ImGui.End();
// }
//}
}

0 comments on commit cdcd43c

Please sign in to comment.