From 1a551cc2fbd73f882a0c27be6bad87e52b38f845 Mon Sep 17 00:00:00 2001 From: praydog Date: Wed, 13 Mar 2024 06:54:22 -0700 Subject: [PATCH] Lua: Add more imgui functions --- src/mods/bindings/ImGui.cpp | 62 ++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/src/mods/bindings/ImGui.cpp b/src/mods/bindings/ImGui.cpp index e86c42620..85d83a96a 100644 --- a/src/mods/bindings/ImGui.cpp +++ b/src/mods/bindings/ImGui.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "../ScriptRunner.hpp" @@ -1104,6 +1105,28 @@ float calc_item_width() { return ImGui::CalcItemWidth(); } +void item_size(sol::object pos, sol::object size, sol::object text_baseline_y) { + if (text_baseline_y.is()) { + ImGui::ItemSize(ImRect{create_imvec2(pos), create_imvec2(size)}, text_baseline_y.as()); + } else { + ImGui::ItemSize(ImRect{create_imvec2(pos), create_imvec2(size)}); + } +} + +bool item_add(const char* label, sol::object pos, sol::object size) { + if (label == nullptr) { + label = ""; + } + + const auto window = ImGui::GetCurrentWindow(); + + if (window == nullptr) { + return false; + } + + return ImGui::ItemAdd(ImRect{create_imvec2(pos), create_imvec2(size)}, window->GetID(label)); +} + void push_style_color(int style_color, sol::object color_obj) { if (color_obj.is()) { ImGui::PushStyleColor((ImGuiCol)style_color, (ImU32)color_obj.as()); @@ -1187,6 +1210,14 @@ const char* get_clipboard() { return ImGui::GetClipboardText(); } +void progress_bar(float progress, sol::object size, const char* overlay ){ + if (overlay == nullptr) { + overlay = ""; + } + + ImGui::ProgressBar(progress, create_imvec2(size), overlay); +} + bool begin_table(const char* str_id, int column, sol::object flags_obj, sol::object outer_size_obj, sol::object inner_width_obj) { if (str_id == nullptr) { str_id = ""; @@ -1283,12 +1314,24 @@ ImGuiTableSortSpecs* table_get_sort_specs() { return ImGui::TableGetSortSpecs(); } -void progress_bar(float progress, sol::object size, const char* overlay ){ - if (overlay == nullptr) { - overlay = ""; +// Window Drawlist +void draw_list_path_clear() { + if (auto dl = ImGui::GetWindowDrawList(); dl != nullptr) { + dl->PathClear(); } +} - ImGui::ProgressBar(progress, create_imvec2(size), overlay); +void draw_list_path_line_to(sol::object pos_obj) { + auto pos = create_imvec2(pos_obj); + if (auto dl = ImGui::GetWindowDrawList(); dl != nullptr) { + dl->PathLineTo(pos); + } +} + +void draw_list_path_stroke(ImU32 color, bool closed, float thickness) { + if (auto dl = ImGui::GetWindowDrawList(); dl != nullptr) { + dl->PathStroke(color, closed, thickness); + } } } // namespace api::imgui @@ -1972,10 +2015,15 @@ void bindings::open_imgui(ScriptState* s) { imgui["end_menu"] = api::imgui::end_menu; imgui["menu_item"] = api::imgui::menu_item; imgui["get_display_size"] = api::imgui::get_display_size; + + // Item imgui["push_item_width"] = api::imgui::push_item_width; imgui["pop_item_width"] = api::imgui::pop_item_width; imgui["set_next_item_width"] = api::imgui::set_next_item_width; imgui["calc_item_width"] = api::imgui::calc_item_width; + imgui["item_add"] = api::imgui::item_add; + imgui["item_size"] = api::imgui::item_size; + imgui["push_style_color"] = api::imgui::push_style_color; imgui["pop_style_color"] = api::imgui::pop_style_color; imgui["push_style_var"] = api::imgui::push_style_var; @@ -1990,6 +2038,12 @@ void bindings::open_imgui(ScriptState* s) { imgui["get_clipboard"] = api::imgui::get_clipboard; imgui["progress_bar"] = api::imgui::progress_bar; + // Draw list + imgui["draw_list_path_clear"] = api::imgui::draw_list_path_clear; + imgui["draw_list_path_line_to"] = api::imgui::draw_list_path_line_to; + imgui["draw_list_path_stroke"] = api::imgui::draw_list_path_stroke; + + // TABLE APIS imgui["begin_table"] = api::imgui::begin_table; imgui["end_table"] = api::imgui::end_table;