From a7016c546fee333bccc163c4a8edb87c178a64dc Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sun, 31 May 2020 23:51:40 -0300 Subject: [PATCH 01/16] adds SerialHelper and AgsImVec2 objects. Long work to support styles. --- CMakeLists.txt | 4 ++ agsimgui/AgsImVec2.cpp | 113 ++++++++++++++++++++++++++++++++++++++ agsimgui/AgsImVec2.h | 73 ++++++++++++++++++++++++ agsimgui/SerialHelper.cpp | 64 +++++++++++++++++++++ agsimgui/SerialHelper.h | 36 ++++++++++++ agsimgui/agsimgui.cpp | 4 ++ 6 files changed, 294 insertions(+) create mode 100644 agsimgui/AgsImVec2.cpp create mode 100644 agsimgui/AgsImVec2.h create mode 100644 agsimgui/SerialHelper.cpp create mode 100644 agsimgui/SerialHelper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9922e5e..69cc24c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,10 @@ add_library(agsimgui SHARED agsimgui/imgui/examples/imgui_impl_dx9.cpp agsimgui/imgui/examples/imgui_impl_dx9.h agsimgui/agsimgui.h + agsimgui/AgsImVec2.cpp + agsimgui/AgsImVec2.h + agsimgui/SerialHelper.cpp + agsimgui/SerialHelper.h agsimgui/agsimgui.cpp agsimgui/Screen.cpp agsimgui/Screen.h) diff --git a/agsimgui/AgsImVec2.cpp b/agsimgui/AgsImVec2.cpp new file mode 100644 index 0000000..2dfa4e1 --- /dev/null +++ b/agsimgui/AgsImVec2.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2020 Érico Vieira Porto + * + * This program is free software. You can use and redistribute it + * under the terms and conditions of the MIT License (see LICENCE). + */ + +#include +#include "AgsImVec2.h" + +AgsImVec2::AgsImVec2(float x, float y) { + _x = x; + _y = y; +} + +AgsImVec2::~AgsImVec2(void) +{ +} + +void AgsImVec2::SetX(float x){ + _x = x; +} + +float AgsImVec2::GetX(){ + return _x; +} + +void AgsImVec2::SetY(float y){ + _y = y; +} + +float AgsImVec2::GetY(){ + return _y; +} + +AgsImVec2* AgsImVec2::Scale(float scale){ + return new AgsImVec2(_x * scale, _y * scale); +} + +float AgsImVec2::Length(){ + return sqrtf(_x * _x + _y * _y); +} + +float AgsImVec2::SquaredLength(){ + return (_x * _x + _y * _y); +} + +AgsImVec2* AgsImVec2::Add(AgsImVec2* agsImVec2) { + if(agsImVec2 == nullptr) return new AgsImVec2(_x , _y ); + + return new AgsImVec2(_x + agsImVec2->GetX(), _y + agsImVec2->GetY()); +} + +AgsImVec2* AgsImVec2::Sub(AgsImVec2* agsImVec2) { + if(agsImVec2 == nullptr) return new AgsImVec2(_x , _y ); + + return new AgsImVec2(_x - agsImVec2->GetX(), _y - agsImVec2->GetY()); +} + +//------------------------------------------------------------------------------ + + +extern IAGSEngine* engine; + +AgsImVec2Interface AgsImVec2_Interface; +AgsImVec2Reader AgsImVec2_Reader; + +const char* AgsImVec2Interface::name = "AgsImVec2"; + +//------------------------------------------------------------------------------ +#include "SerialHelper.h" +using namespace SerialHelper; + +int AgsImVec2Interface::Dispose(const char* address, bool force) +{ + delete ((AgsImVec2*)address); + return (1); +} + +//------------------------------------------------------------------------------ + +int AgsImVec2Interface::Serialize(const char* address, char* buffer, int bufsize) +{ + AgsImVec2* agsimgui_imvec2 = (AgsImVec2*)address; + char* ptr = buffer; + char* end = buffer + bufsize; + + ptr = FloatToChar(agsimgui_imvec2->GetX(), ptr, end); + ptr = FloatToChar(agsimgui_imvec2->GetY(), ptr, end); + + return (ptr - buffer); +} + +//------------------------------------------------------------------------------ + +void AgsImVec2Reader::Unserialize(int key, const char* serializedData, int dataSize) +{ + char* ptr = (char*) serializedData; + int agsimgui_imvec2_id = key; + + + float val_x; + float val_y; + + ptr = CharToFloat( val_x, ptr); + ptr = CharToFloat( val_y, ptr); + + AgsImVec2* agsimgui_imvec2 = new AgsImVec2(val_x, val_y); + + engine->RegisterUnserializedObject(key, agsimgui_imvec2, &AgsImVec2_Interface); +} + +//.............................................................................. diff --git a/agsimgui/AgsImVec2.h b/agsimgui/AgsImVec2.h new file mode 100644 index 0000000..fa188bc --- /dev/null +++ b/agsimgui/AgsImVec2.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2020 Érico Vieira Porto + * + * This program is free software. You can use and redistribute it + * under the terms and conditions of the MIT License (see LICENCE). + */ + +#pragma once + +#ifndef _AGSIMVEC2_H +#define _AGSIMVEC2_H + +#include "plugin/agsplugin.h" + +class AgsImVec2 +{ + float _x = 0.0; + float _y = 0.0; +public: + AgsImVec2(float x, float y); + ~AgsImVec2(void); + void SetX(float x); + float GetX(); + void SetY(float y); + float GetY(); + + AgsImVec2* Scale(float scale); + float Length(); + float SquaredLength(); + AgsImVec2* Add(AgsImVec2* AgsImVec2); + AgsImVec2* Sub(AgsImVec2* AgsImVec2); +}; + + + +//------------------------------------------------------------------------------ +// AGS interface instances + +class AgsImVec2Interface : public IAGSScriptManagedObject +{ +public: + static const char* name; + + AgsImVec2Interface() {}; + + virtual int Dispose(const char* address, bool force); + virtual const char* GetType() { return (name); } + virtual int Serialize(const char* address, char* buffer, int bufsize); + +}; + +//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +class AgsImVec2Reader : public IAGSManagedObjectReader +{ +public: + + AgsImVec2Reader() {} + + virtual void Unserialize(int key, const char* serializedData, int dataSize); + +}; + +//------------------------------------------------------------------------------ + +extern AgsImVec2Interface AgsImVec2_Interface; +extern AgsImVec2Reader AgsImVec2_Reader; + +//------------------------------------------------------------------------------ + +#endif /* _AGSIMVEC2_H */ + +//............ diff --git a/agsimgui/SerialHelper.cpp b/agsimgui/SerialHelper.cpp new file mode 100644 index 0000000..9006cea --- /dev/null +++ b/agsimgui/SerialHelper.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2020 Érico Vieira Porto + * + * This program is free software. You can use and redistribute it + * under the terms and conditions of the MIT License (see LICENCE). + */ + +#include "SerialHelper.h" +#include + +namespace SerialHelper { + + char* IntToChar(int i, char * buf, char* end) { + assert(buf + sizeof(int) < end); + + *((int*)buf) = i; + + return buf + sizeof(int); + } + + char* CharToInt(int &i, char * buf) { + i = *((int*)buf); + return buf + sizeof(int); + } + + char* FloatToChar(float f, char * buf, char* end) { + assert(buf + sizeof(float) < end); + + *((float*)buf) = f; + + return buf + sizeof(float); + } + + char* CharToFloat(float &f, char * buf) { + f = *((float*)buf); + return buf + sizeof(float); + } + + char* BoolToChar(bool b, char* buf, char* end) { + assert(buf + sizeof(char) < end); + + if (b) { + *buf = 1; + } + else { + *buf = 0; + } + return buf + sizeof(char); + } + + char* CharToBool(bool &b, char* buf) { + if (*buf == 0) { + b = false; + } + else { + b = true; + } + return buf + sizeof(char); + } + + + + +} diff --git a/agsimgui/SerialHelper.h b/agsimgui/SerialHelper.h new file mode 100644 index 0000000..32f257e --- /dev/null +++ b/agsimgui/SerialHelper.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2020 Érico Vieira Porto + * + * This program is free software. You can use and redistribute it + * under the terms and conditions of the MIT License (see LICENCE). + */ + +#pragma once + +#ifndef AGSBOX2D_SERIALHELPER_H +#define AGSBOX2D_SERIALHELPER_H + +namespace SerialHelper { + + union u_cf + { + float f; + char s[sizeof(float)]; + }; + + union u_ci + { + int i; + char s[sizeof(int)]; + }; + + char* IntToChar(int i, char * buf, char* end); + char* FloatToChar(float f, char * buf, char* end); + char* BoolToChar(bool b, char* buf, char* end); + + char* CharToInt(int &i, char * buf); + char* CharToFloat(float &f, char * buf); + char* CharToBool(bool &b, char* buf); +} + +#endif /* AGSBOX2D_SERIALHELPER_H */ \ No newline at end of file diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index 5abb37b..5e76b60 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -39,6 +39,8 @@ struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax error #include "Screen.h" #include "libs/clip/clip.h" +#include "AgsImVec2.h" + #include #if defined(BUILTIN_PLUGINS) @@ -1578,6 +1580,8 @@ int AgsImGuiHelper_GetClipboarImage() { if (engine->version < MIN_ENGINE_VERSION) engine->AbortGame("Plugin needs engine version " STRINGIFY(MIN_ENGINE_VERSION) " or newer."); + engine->AddManagedObjectReader(AgsImVec2Interface::name, &AgsImVec2_Reader); + //register functions if(screen.driver == Screen::Driver::eOpenGL) { From e6db270288785a98ad4f08df1e6db6fe62844147 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 16:20:33 -0300 Subject: [PATCH 02/16] adds ImVec2 --- agsimgui/AgsImVec2.cpp | 61 +++++++----------------- agsimgui/AgsImVec2.h | 37 ++++++++------- agsimgui/agsimgui.cpp | 103 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 61 deletions(-) diff --git a/agsimgui/AgsImVec2.cpp b/agsimgui/AgsImVec2.cpp index 2dfa4e1..ca4bb1c 100644 --- a/agsimgui/AgsImVec2.cpp +++ b/agsimgui/AgsImVec2.cpp @@ -8,64 +8,40 @@ #include #include "AgsImVec2.h" -AgsImVec2::AgsImVec2(float x, float y) { - _x = x; - _y = y; +float AgsImVec2::Length() { + return sqrt(x * x + y * y); } -AgsImVec2::~AgsImVec2(void) -{ -} - -void AgsImVec2::SetX(float x){ - _x = x; -} - -float AgsImVec2::GetX(){ - return _x; -} - -void AgsImVec2::SetY(float y){ - _y = y; -} - -float AgsImVec2::GetY(){ - return _y; -} - -AgsImVec2* AgsImVec2::Scale(float scale){ - return new AgsImVec2(_x * scale, _y * scale); -} - -float AgsImVec2::Length(){ - return sqrtf(_x * _x + _y * _y); +AgsImVec2* AgsImVec2::Scale(float scale) { + return new AgsImVec2(x * scale, y * scale); } float AgsImVec2::SquaredLength(){ - return (_x * _x + _y * _y); + return (x * x + y * y); } AgsImVec2* AgsImVec2::Add(AgsImVec2* agsImVec2) { - if(agsImVec2 == nullptr) return new AgsImVec2(_x , _y ); + if(agsImVec2 == nullptr) return new AgsImVec2(x , y ); - return new AgsImVec2(_x + agsImVec2->GetX(), _y + agsImVec2->GetY()); + return new AgsImVec2(x + agsImVec2->x, y + agsImVec2->y); } AgsImVec2* AgsImVec2::Sub(AgsImVec2* agsImVec2) { - if(agsImVec2 == nullptr) return new AgsImVec2(_x , _y ); + if(agsImVec2 == nullptr) return new AgsImVec2(x , y ); - return new AgsImVec2(_x - agsImVec2->GetX(), _y - agsImVec2->GetY()); + return new AgsImVec2(x - agsImVec2->x, y - agsImVec2->y); } -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + extern IAGSEngine* engine; AgsImVec2Interface AgsImVec2_Interface; AgsImVec2Reader AgsImVec2_Reader; -const char* AgsImVec2Interface::name = "AgsImVec2"; +const char* AgsImVec2Interface::name = "ImVec2"; //------------------------------------------------------------------------------ #include "SerialHelper.h" @@ -81,12 +57,12 @@ int AgsImVec2Interface::Dispose(const char* address, bool force) int AgsImVec2Interface::Serialize(const char* address, char* buffer, int bufsize) { - AgsImVec2* agsimgui_imvec2 = (AgsImVec2*)address; + AgsImVec2* imvec2 = (AgsImVec2*)address; char* ptr = buffer; char* end = buffer + bufsize; - ptr = FloatToChar(agsimgui_imvec2->GetX(), ptr, end); - ptr = FloatToChar(agsimgui_imvec2->GetY(), ptr, end); + ptr = FloatToChar(imvec2->x, ptr, end); + ptr = FloatToChar(imvec2->y, ptr, end); return (ptr - buffer); } @@ -96,8 +72,6 @@ int AgsImVec2Interface::Serialize(const char* address, char* buffer, int bufsize void AgsImVec2Reader::Unserialize(int key, const char* serializedData, int dataSize) { char* ptr = (char*) serializedData; - int agsimgui_imvec2_id = key; - float val_x; float val_y; @@ -105,9 +79,10 @@ void AgsImVec2Reader::Unserialize(int key, const char* serializedData, int dataS ptr = CharToFloat( val_x, ptr); ptr = CharToFloat( val_y, ptr); - AgsImVec2* agsimgui_imvec2 = new AgsImVec2(val_x, val_y); + AgsImVec2* imvec2 = new AgsImVec2(val_x, val_y, key); - engine->RegisterUnserializedObject(key, agsimgui_imvec2, &AgsImVec2_Interface); + engine->RegisterUnserializedObject(key, imvec2, &AgsImVec2_Interface); } //.............................................................................. + diff --git a/agsimgui/AgsImVec2.h b/agsimgui/AgsImVec2.h index fa188bc..569c082 100644 --- a/agsimgui/AgsImVec2.h +++ b/agsimgui/AgsImVec2.h @@ -11,27 +11,28 @@ #define _AGSIMVEC2_H #include "plugin/agsplugin.h" - -class AgsImVec2 -{ - float _x = 0.0; - float _y = 0.0; -public: - AgsImVec2(float x, float y); - ~AgsImVec2(void); - void SetX(float x); - float GetX(); - void SetY(float y); - float GetY(); - - AgsImVec2* Scale(float scale); - float Length(); +#include "imgui/imgui.h" + +struct AgsImVec2 : ImVec2 { + public : + int id; + AgsImVec2(float x, float y) + : ImVec2(x,y){ + id = -1; + } + + AgsImVec2(float x, float y, int _id) + : ImVec2(x,y){ + id = _id; + } + float Length() ; float SquaredLength(); - AgsImVec2* Add(AgsImVec2* AgsImVec2); - AgsImVec2* Sub(AgsImVec2* AgsImVec2); -}; + AgsImVec2* Scale(float scale) ; + AgsImVec2 *Add(AgsImVec2 *agsImVec2); + AgsImVec2 *Sub(AgsImVec2 *agsImVec2); +}; //------------------------------------------------------------------------------ // AGS interface instances diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index 5e76b60..b5833a6 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -353,6 +353,34 @@ namespace agsimgui { " ImGuiTreeNodeFlags_NavLeftJumpsBackHere = 8192, // (WIP) Nav: left direction may move to this TreeNode() from any of its child (items submitted between TreeNode and TreePop) \r\n" " ImGuiTreeNodeFlags_CollapsingHeader = 26, \r\n" " }; \r\n" +" \r\n" +"builtin managed struct ImVec2 { \r\n" +" \r\n" +" /// Creates a ImVec2 with float X and Y coordinates. \r\n" +" import static ImVec2* Create(float x, float y); // $AUTOCOMPLETESTATICONLY$ \r\n" +" \r\n" +" /// Float X coordinate of the ImVec2. \r\n" +" import attribute float X; \r\n" +" \r\n" +" /// Float Y coordinate of the ImVec2. \r\n" +" import attribute float Y; \r\n" +" \r\n" +" /// Multiplies x and y coordinates by a scalar and returns a new ImVec2 with the result. \r\n" +" import ImVec2* Scale(float scale); \r\n" +" \r\n" +" /// Returns length from ImVec2 (distance from 0,0 origin). \r\n" +" import float Length(); \r\n" +" \r\n" +" /// Returns squared length from ImVec2 (distance from 0,0 origin). Faster than length. \r\n" +" import float SquaredLength(); \r\n" +" \r\n" +" /// Returns a new ImVec2 with the sum of this with imVec2. \r\n" +" import ImVec2* Add(ImVec2* imVec2); \r\n" +" \r\n" +" /// Returns a new ImVec2 with the subtraction of imVec2 from this. \r\n" +" import ImVec2* Sub(ImVec2* imVec2); \r\n" +" \r\n" +"}; \r\n" " \r\n" " struct AgsImGui{ \r\n" " // Main \r\n" @@ -895,6 +923,68 @@ typedef int (*SCAPI_MOUSE_ISBUTTONDOWN) (int button); SCAPI_MOUSE_ISBUTTONDOWN Mouse_IsButtonDown = NULL; bool has_new_render = false; bool has_new_frame = false; + + +// -- begin AgsImVec2 + +AgsImVec2* AgsImVec2_Create(uint32_t x, uint32_t y){ + float fx = ToNormalFloat(x); + float fy = ToNormalFloat(y); + AgsImVec2* agsImVec2 = new AgsImVec2(fx, fy); + agsImVec2->id = engine->RegisterManagedObject(agsImVec2, &AgsImVec2_Interface); + return agsImVec2; +} + +int32 AgsImVec2_GetY(AgsImVec2* self) { + return ToAgsFloat(self->y); +} + +void AgsImVec2_SetX(AgsImVec2* self, uint32_t x) { + float fx = ToNormalFloat(x); + + self->x = fx; +} + +uint32_t AgsImVec2_GetX(AgsImVec2* self) { + return ToAgsFloat(self->x); +} + +void AgsImVec2_SetY(AgsImVec2* self, uint32_t y) { + float fy = ToNormalFloat(y); + + self->y = fy; +} + +uint32_t AgsImVec2_Length(AgsImVec2* self) { + return ToAgsFloat(self->Length()); +} + +uint32_t AgsImVec2_SquaredLength(AgsImVec2* self) { + return ToAgsFloat(self->SquaredLength()); +} + +AgsImVec2* AgsImVec2_Add(AgsImVec2* self, AgsImVec2* other){ + AgsImVec2* agsImVec2 = self->Add(other); + agsImVec2->id = engine->RegisterManagedObject(agsImVec2, &AgsImVec2_Interface); + return agsImVec2; +} + +AgsImVec2* AgsImVec2_Sub(AgsImVec2* self, AgsImVec2* other){ + AgsImVec2* agsImVec2 = self->Sub(other); + agsImVec2->id = engine->RegisterManagedObject(agsImVec2, &AgsImVec2_Interface); + return agsImVec2; +} + + +AgsImVec2* AgsImVec2_Scale(AgsImVec2* self, uint32_t scale){ + float f_scale = ToNormalFloat(scale); + AgsImVec2* agsImVec2 = self->Scale(f_scale); + agsImVec2->id = engine->RegisterManagedObject(agsImVec2, &AgsImVec2_Interface); + return agsImVec2; +} + +// -- end AgsImVec2 + void AgsImGui_NewFrame(){ if (!screen.initialized) return; @@ -1657,6 +1747,19 @@ int AgsImGuiHelper_GetClipboarImage() { Mouse_IsButtonDown = (SCAPI_MOUSE_ISBUTTONDOWN) engine->GetScriptFunctionAddress("Mouse::IsButtonDown^1"); + + engine->RegisterScriptFunction("ImVec2::Create^2", (void*)AgsImVec2_Create); + engine->RegisterScriptFunction("ImVec2::set_X", (void*)AgsImVec2_SetX); + engine->RegisterScriptFunction("ImVec2::get_X", (void*)AgsImVec2_GetX); + engine->RegisterScriptFunction("ImVec2::set_Y", (void*)AgsImVec2_SetY); + engine->RegisterScriptFunction("ImVec2::get_Y", (void*)AgsImVec2_GetY); + engine->RegisterScriptFunction("ImVec2::Length^0", (void*)AgsImVec2_Length); + engine->RegisterScriptFunction("ImVec2::SquaredLength^0", (void*)AgsImVec2_SquaredLength); + engine->RegisterScriptFunction("ImVec2::Add^1", (void*)AgsImVec2_Add); + engine->RegisterScriptFunction("ImVec2::Sub^1", (void*)AgsImVec2_Sub); + engine->RegisterScriptFunction("ImVec2::Scale^1", (void*)AgsImVec2_Scale); + + engine->RegisterScriptFunction("AgsImGui::NewFrame^0", (void*)AgsImGui_NewFrame); engine->RegisterScriptFunction("AgsImGui::EndFrame^0", (void*)AgsImGui_EndFrame); engine->RegisterScriptFunction("AgsImGui::Render^0", (void*)AgsImGui_Render); From 1feeea681e5a73dd3c99bd8150da706e18a34821 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 16:35:51 -0300 Subject: [PATCH 03/16] adds ImVec4 --- CMakeLists.txt | 2 + agsimgui/AgsImVec2.cpp | 10 +-- agsimgui/AgsImVec2.h | 8 +-- agsimgui/AgsImVec4.cpp | 94 ++++++++++++++++++++++++++++ agsimgui/AgsImVec4.h | 74 ++++++++++++++++++++++ agsimgui/agsimgui.cpp | 135 ++++++++++++++++++++++++++++++++++++++++- 6 files changed, 313 insertions(+), 10 deletions(-) create mode 100644 agsimgui/AgsImVec4.cpp create mode 100644 agsimgui/AgsImVec4.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 69cc24c..2da3c8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,8 @@ add_library(agsimgui SHARED agsimgui/agsimgui.h agsimgui/AgsImVec2.cpp agsimgui/AgsImVec2.h + agsimgui/AgsImVec4.cpp + agsimgui/AgsImVec4.h agsimgui/SerialHelper.cpp agsimgui/SerialHelper.h agsimgui/agsimgui.cpp diff --git a/agsimgui/AgsImVec2.cpp b/agsimgui/AgsImVec2.cpp index ca4bb1c..7e9d059 100644 --- a/agsimgui/AgsImVec2.cpp +++ b/agsimgui/AgsImVec2.cpp @@ -57,12 +57,12 @@ int AgsImVec2Interface::Dispose(const char* address, bool force) int AgsImVec2Interface::Serialize(const char* address, char* buffer, int bufsize) { - AgsImVec2* imvec2 = (AgsImVec2*)address; + AgsImVec2* agsImVec2 = (AgsImVec2*)address; char* ptr = buffer; char* end = buffer + bufsize; - ptr = FloatToChar(imvec2->x, ptr, end); - ptr = FloatToChar(imvec2->y, ptr, end); + ptr = FloatToChar(agsImVec2->x, ptr, end); + ptr = FloatToChar(agsImVec2->y, ptr, end); return (ptr - buffer); } @@ -79,9 +79,9 @@ void AgsImVec2Reader::Unserialize(int key, const char* serializedData, int dataS ptr = CharToFloat( val_x, ptr); ptr = CharToFloat( val_y, ptr); - AgsImVec2* imvec2 = new AgsImVec2(val_x, val_y, key); + AgsImVec2* agsImVec2 = new AgsImVec2(val_x, val_y, key); - engine->RegisterUnserializedObject(key, imvec2, &AgsImVec2_Interface); + engine->RegisterUnserializedObject(key, agsImVec2, &AgsImVec2_Interface); } //.............................................................................. diff --git a/agsimgui/AgsImVec2.h b/agsimgui/AgsImVec2.h index 569c082..85f9b65 100644 --- a/agsimgui/AgsImVec2.h +++ b/agsimgui/AgsImVec2.h @@ -16,13 +16,13 @@ struct AgsImVec2 : ImVec2 { public : int id; - AgsImVec2(float x, float y) - : ImVec2(x,y){ + AgsImVec2(float _x, float _y) + : ImVec2(_x,_y){ id = -1; } - AgsImVec2(float x, float y, int _id) - : ImVec2(x,y){ + AgsImVec2(float _x, float _y, int _id) + : ImVec2(_x,_y){ id = _id; } float Length() ; diff --git a/agsimgui/AgsImVec4.cpp b/agsimgui/AgsImVec4.cpp new file mode 100644 index 0000000..0dfac7a --- /dev/null +++ b/agsimgui/AgsImVec4.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 4040 Érico Vieira Porto + * + * This program is free software. You can use and redistribute it + * under the terms and conditions of the MIT License (see LICENCE). + */ + +#include +#include "AgsImVec4.h" + +float AgsImVec4::Length() { + return sqrt(x * x + y * y + z * z + w * w); +} + +AgsImVec4* AgsImVec4::Scale(float scale) { + return new AgsImVec4(x * scale, y * scale, z*scale, w*scale); +} + +float AgsImVec4::SquaredLength(){ + return (x * x + y * y + z * z + w * w); +} + +AgsImVec4* AgsImVec4::Add(AgsImVec4* agsImVec4) { + if(agsImVec4 == nullptr) return new AgsImVec4(x , y , z, w); + + return new AgsImVec4(x + agsImVec4->x, y + agsImVec4->y, z + agsImVec4->z, w + agsImVec4->w); +} + +AgsImVec4* AgsImVec4::Sub(AgsImVec4* agsImVec4) { + if(agsImVec4 == nullptr) return new AgsImVec4(x , y, z, w); + + return new AgsImVec4(x - agsImVec4->x, y - agsImVec4->y, z - agsImVec4->z, w - agsImVec4->w); +} + + + +//------------------------------------------------------------------------------ + +extern IAGSEngine* engine; + +AgsImVec4Interface AgsImVec4_Interface; +AgsImVec4Reader AgsImVec4_Reader; + +const char* AgsImVec4Interface::name = "ImVec4"; + +//------------------------------------------------------------------------------ +#include "SerialHelper.h" +using namespace SerialHelper; + +int AgsImVec4Interface::Dispose(const char* address, bool force) +{ + delete ((AgsImVec4*)address); + return (1); +} + +//------------------------------------------------------------------------------ + +int AgsImVec4Interface::Serialize(const char* address, char* buffer, int bufsize) +{ + AgsImVec4* agsImVec4 = (AgsImVec4*)address; + char* ptr = buffer; + char* end = buffer + bufsize; + + ptr = FloatToChar(agsImVec4->x, ptr, end); + ptr = FloatToChar(agsImVec4->y, ptr, end); + ptr = FloatToChar(agsImVec4->z, ptr, end); + ptr = FloatToChar(agsImVec4->w, ptr, end); + + return (ptr - buffer); +} + +//------------------------------------------------------------------------------ + +void AgsImVec4Reader::Unserialize(int key, const char* serializedData, int dataSize) +{ + char* ptr = (char*) serializedData; + + float val_x; + float val_y; + float val_z; + float val_w; + + ptr = CharToFloat( val_x, ptr); + ptr = CharToFloat( val_y, ptr); + ptr = CharToFloat( val_z, ptr); + ptr = CharToFloat( val_w, ptr); + + AgsImVec4* agsImVec4 = new AgsImVec4(val_x, val_y, val_z, val_w, key); + + engine->RegisterUnserializedObject(key, agsImVec4, &AgsImVec4_Interface); +} + +//.............................................................................. + diff --git a/agsimgui/AgsImVec4.h b/agsimgui/AgsImVec4.h new file mode 100644 index 0000000..312b1f0 --- /dev/null +++ b/agsimgui/AgsImVec4.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 4040 Érico Vieira Porto + * + * This program is free software. You can use and redistribute it + * under the terms and conditions of the MIT License (see LICENCE). + */ + +#pragma once + +#ifndef _AGSIMVEC4_H +#define _AGSIMVEC4_H + +#include "plugin/agsplugin.h" +#include "imgui/imgui.h" + +struct AgsImVec4 : ImVec4 { + public : + int id; + AgsImVec4(float _x, float _y, float _z, float _w) + : ImVec4(_x,_y,_z,_w){ + id = -1; + } + + AgsImVec4(float _x, float _y, float _z, float _w, int _id) + : ImVec4(_x,_y,_z,_w){ + id = _id; + } + float Length() ; + float SquaredLength(); + AgsImVec4* Scale(float scale) ; + + AgsImVec4 *Add(AgsImVec4 *agsImVec4); + + AgsImVec4 *Sub(AgsImVec4 *agsImVec4); +}; + +//------------------------------------------------------------------------------ +// AGS interface instances + +class AgsImVec4Interface : public IAGSScriptManagedObject +{ +public: + static const char* name; + + AgsImVec4Interface() {}; + + virtual int Dispose(const char* address, bool force); + virtual const char* GetType() { return (name); } + virtual int Serialize(const char* address, char* buffer, int bufsize); + +}; + +//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +class AgsImVec4Reader : public IAGSManagedObjectReader +{ +public: + + AgsImVec4Reader() {} + + virtual void Unserialize(int key, const char* serializedData, int dataSize); + +}; + +//------------------------------------------------------------------------------ + +extern AgsImVec4Interface AgsImVec4_Interface; +extern AgsImVec4Reader AgsImVec4_Reader; + +//------------------------------------------------------------------------------ + +#endif /* _AGSIMVEC4_H */ + +//............ diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index b5833a6..bb23ce6 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -40,6 +40,7 @@ struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax error #include "libs/clip/clip.h" #include "AgsImVec2.h" +#include "AgsImVec4.h" #include @@ -354,6 +355,40 @@ namespace agsimgui { " ImGuiTreeNodeFlags_CollapsingHeader = 26, \r\n" " }; \r\n" " \r\n" +"builtin managed struct ImVec4 { \r\n" +" \r\n" +" /// Creates a ImVec4 with float X and Y coordinates. \r\n" +" import static ImVec4* Create(float x, float y); // $AUTOCOMPLETESTATICONLY$ \r\n" +" \r\n" +" /// Float X coordinate of the ImVec4. \r\n" +" import attribute float X; \r\n" +" \r\n" +" /// Float Y coordinate of the ImVec4. \r\n" +" import attribute float Y; \r\n" +" \r\n" +" /// Float X coordinate of the ImVec4. \r\n" +" import attribute float Z; \r\n" +" \r\n" +" /// Float Y coordinate of the ImVec4. \r\n" +" import attribute float W; \r\n" +" \r\n" +" /// Multiplies x and y coordinates by a scalar and returns a new ImVec4 with the result. \r\n" +" import ImVec4* Scale(float scale); \r\n" +" \r\n" +" /// Returns length from ImVec4 (distance from 0,0 origin). \r\n" +" import float Length(); \r\n" +" \r\n" +" /// Returns squared length from ImVec4 (distance from 0,0 origin). Faster than length. \r\n" +" import float SquaredLength(); \r\n" +" \r\n" +" /// Returns a new ImVec4 with the sum of this with imVec4. \r\n" +" import ImVec4* Add(ImVec4* imVec4); \r\n" +" \r\n" +" /// Returns a new ImVec4 with the subtraction of imVec4 from this. \r\n" +" import ImVec4* Sub(ImVec4* imVec4); \r\n" +" \r\n" +"}; \r\n" +" \r\n" "builtin managed struct ImVec2 { \r\n" " \r\n" " /// Creates a ImVec2 with float X and Y coordinates. \r\n" @@ -985,6 +1020,90 @@ AgsImVec2* AgsImVec2_Scale(AgsImVec2* self, uint32_t scale){ // -- end AgsImVec2 + +// -- begin AgsImVec4 + +AgsImVec4* AgsImVec4_Create(uint32_t x, uint32_t y, uint32_t z, uint32_t w){ + float fx = ToNormalFloat(x); + float fy = ToNormalFloat(y); + float fz = ToNormalFloat(z); + float fw = ToNormalFloat(w); + AgsImVec4* agsImVec4 = new AgsImVec4(fx, fy, fz, fw); + agsImVec4->id = engine->RegisterManagedObject(agsImVec4, &AgsImVec4_Interface); + return agsImVec4; +} + +int32 AgsImVec4_GetY(AgsImVec4* self) { + return ToAgsFloat(self->y); +} + +void AgsImVec4_SetX(AgsImVec4* self, uint32_t x) { + float fx = ToNormalFloat(x); + + self->x = fx; +} + +uint32_t AgsImVec4_GetX(AgsImVec4* self) { + return ToAgsFloat(self->x); +} + +void AgsImVec4_SetY(AgsImVec4* self, uint32_t y) { + float fy = ToNormalFloat(y); + + self->y = fy; +} + +int32 AgsImVec4_GetZ(AgsImVec4* self) { + return ToAgsFloat(self->z); +} + +void AgsImVec4_SetZ(AgsImVec4* self, uint32_t z) { + float fz = ToNormalFloat(z); + + self->z = fz; +} + +uint32_t AgsImVec4_GetW(AgsImVec4* self) { + return ToAgsFloat(self->w); +} + +void AgsImVec4_SetW(AgsImVec4* self, uint32_t w) { + float fw = ToNormalFloat(w); + + self->w = fw; +} + +uint32_t AgsImVec4_Length(AgsImVec4* self) { + return ToAgsFloat(self->Length()); +} + +uint32_t AgsImVec4_SquaredLength(AgsImVec4* self) { + return ToAgsFloat(self->SquaredLength()); +} + +AgsImVec4* AgsImVec4_Add(AgsImVec4* self, AgsImVec4* other){ + AgsImVec4* agsImVec4 = self->Add(other); + agsImVec4->id = engine->RegisterManagedObject(agsImVec4, &AgsImVec4_Interface); + return agsImVec4; +} + +AgsImVec4* AgsImVec4_Sub(AgsImVec4* self, AgsImVec4* other){ + AgsImVec4* agsImVec4 = self->Sub(other); + agsImVec4->id = engine->RegisterManagedObject(agsImVec4, &AgsImVec4_Interface); + return agsImVec4; +} + + +AgsImVec4* AgsImVec4_Scale(AgsImVec4* self, uint32_t scale){ + float f_scale = ToNormalFloat(scale); + AgsImVec4* agsImVec4 = self->Scale(f_scale); + agsImVec4->id = engine->RegisterManagedObject(agsImVec4, &AgsImVec4_Interface); + return agsImVec4; +} + +// -- end AgsImVec4 + + void AgsImGui_NewFrame(){ if (!screen.initialized) return; @@ -1671,6 +1790,7 @@ int AgsImGuiHelper_GetClipboarImage() { engine->AbortGame("Plugin needs engine version " STRINGIFY(MIN_ENGINE_VERSION) " or newer."); engine->AddManagedObjectReader(AgsImVec2Interface::name, &AgsImVec2_Reader); + engine->AddManagedObjectReader(AgsImVec4Interface::name, &AgsImVec4_Reader); //register functions if(screen.driver == Screen::Driver::eOpenGL) { @@ -1747,6 +1867,20 @@ int AgsImGuiHelper_GetClipboarImage() { Mouse_IsButtonDown = (SCAPI_MOUSE_ISBUTTONDOWN) engine->GetScriptFunctionAddress("Mouse::IsButtonDown^1"); + engine->RegisterScriptFunction("ImVec4::Create^4", (void*)AgsImVec4_Create); + engine->RegisterScriptFunction("ImVec4::set_X", (void*)AgsImVec4_SetX); + engine->RegisterScriptFunction("ImVec4::get_X", (void*)AgsImVec4_GetX); + engine->RegisterScriptFunction("ImVec4::set_Y", (void*)AgsImVec4_SetY); + engine->RegisterScriptFunction("ImVec4::get_Y", (void*)AgsImVec4_GetY); + engine->RegisterScriptFunction("ImVec4::set_Z", (void*)AgsImVec4_SetZ); + engine->RegisterScriptFunction("ImVec4::get_Z", (void*)AgsImVec4_GetZ); + engine->RegisterScriptFunction("ImVec4::set_W", (void*)AgsImVec4_SetW); + engine->RegisterScriptFunction("ImVec4::get_W", (void*)AgsImVec4_GetW); + engine->RegisterScriptFunction("ImVec4::Length^0", (void*)AgsImVec4_Length); + engine->RegisterScriptFunction("ImVec4::SquaredLength^0", (void*)AgsImVec4_SquaredLength); + engine->RegisterScriptFunction("ImVec4::Add^1", (void*)AgsImVec4_Add); + engine->RegisterScriptFunction("ImVec4::Sub^1", (void*)AgsImVec4_Sub); + engine->RegisterScriptFunction("ImVec4::Scale^1", (void*)AgsImVec4_Scale); engine->RegisterScriptFunction("ImVec2::Create^2", (void*)AgsImVec2_Create); engine->RegisterScriptFunction("ImVec2::set_X", (void*)AgsImVec2_SetX); @@ -1759,7 +1893,6 @@ int AgsImGuiHelper_GetClipboarImage() { engine->RegisterScriptFunction("ImVec2::Sub^1", (void*)AgsImVec2_Sub); engine->RegisterScriptFunction("ImVec2::Scale^1", (void*)AgsImVec2_Scale); - engine->RegisterScriptFunction("AgsImGui::NewFrame^0", (void*)AgsImGui_NewFrame); engine->RegisterScriptFunction("AgsImGui::EndFrame^0", (void*)AgsImGui_EndFrame); engine->RegisterScriptFunction("AgsImGui::Render^0", (void*)AgsImGui_Render); From cfa92aacc34978ba439911a5fae1c6fa4c7f45c2 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 20:21:51 -0300 Subject: [PATCH 04/16] adds ImGuiStyle to AgsImGui api --- CMakeLists.txt | 2 + agsimgui/AgsImGuiStyle.cpp | 59 ++++ agsimgui/AgsImGuiStyle.h | 67 ++++ agsimgui/agsimgui.cpp | 639 +++++++++++++++++++++++++++++++++++++ 4 files changed, 767 insertions(+) create mode 100644 agsimgui/AgsImGuiStyle.cpp create mode 100644 agsimgui/AgsImGuiStyle.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2da3c8f..9ac7a19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,8 @@ add_library(agsimgui SHARED agsimgui/AgsImVec2.h agsimgui/AgsImVec4.cpp agsimgui/AgsImVec4.h + agsimgui/AgsImGuiStyle.cpp + agsimgui/AgsImGuiStyle.h agsimgui/SerialHelper.cpp agsimgui/SerialHelper.h agsimgui/agsimgui.cpp diff --git a/agsimgui/AgsImGuiStyle.cpp b/agsimgui/AgsImGuiStyle.cpp new file mode 100644 index 0000000..6de2242 --- /dev/null +++ b/agsimgui/AgsImGuiStyle.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2020 Érico Vieira Porto + * + * This program is free software. You can use and redistribute it + * under the terms and conditions of the MIT License (see LICENCE). + */ + +#include +#include "AgsImGuiStyle.h" + + +//------------------------------------------------------------------------------ + +extern IAGSEngine* engine; + +AgsImGuiStyleInterface AgsImGuiStyle_Interface; +AgsImGuiStyleReader AgsImGuiStyle_Reader; + +const char* AgsImGuiStyleInterface::name = "ImGuiStyle"; + +//------------------------------------------------------------------------------ +#include "SerialHelper.h" +using namespace SerialHelper; + +int AgsImGuiStyleInterface::Dispose(const char* address, bool force) +{ + delete ((AgsImGuiStyle*)address); + return (1); +} + +//------------------------------------------------------------------------------ + +int AgsImGuiStyleInterface::Serialize(const char* address, char* buffer, int bufsize) +{ + AgsImGuiStyle* agsImGuiStyle = (AgsImGuiStyle*)address; + char* ptr = buffer; + char* end = buffer + bufsize; + + + return (ptr - buffer); +} + +//------------------------------------------------------------------------------ + +void AgsImGuiStyleReader::Unserialize(int key, const char* serializedData, int dataSize) +{ + char* ptr = (char*) serializedData; + + float val_x; + float val_y; + + + AgsImGuiStyle* agsImGuiStyle = new AgsImGuiStyle(key); + + engine->RegisterUnserializedObject(key, agsImGuiStyle, &AgsImGuiStyle_Interface); +} + +//.............................................................................. + diff --git a/agsimgui/AgsImGuiStyle.h b/agsimgui/AgsImGuiStyle.h new file mode 100644 index 0000000..4d548eb --- /dev/null +++ b/agsimgui/AgsImGuiStyle.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2020 Érico Vieira Porto + * + * This program is free software. You can use and redistribute it + * under the terms and conditions of the MIT License (see LICENCE). + */ + +#pragma once + +#ifndef _AGSIMGUISTYLE_H +#define _AGSIMGUISTYLE_H + +#include "plugin/agsplugin.h" +#include "imgui/imgui.h" + +struct AgsImGuiStyle: ImGuiStyle { + public : + int id; + AgsImGuiStyle() + : ImGuiStyle(){ + id = -1; + } + + AgsImGuiStyle(int _id) + : ImGuiStyle(){ + id = _id; + } +}; + +//------------------------------------------------------------------------------ +// AGS interface instances + +class AgsImGuiStyleInterface : public IAGSScriptManagedObject +{ +public: + static const char* name; + + AgsImGuiStyleInterface() {}; + + virtual int Dispose(const char* address, bool force); + virtual const char* GetType() { return (name); } + virtual int Serialize(const char* address, char* buffer, int bufsize); + +}; + +//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +class AgsImGuiStyleReader : public IAGSManagedObjectReader +{ +public: + + AgsImGuiStyleReader() {} + + virtual void Unserialize(int key, const char* serializedData, int dataSize); + +}; + +//------------------------------------------------------------------------------ + +extern AgsImGuiStyleInterface AgsImGuiStyle_Interface; +extern AgsImGuiStyleReader AgsImGuiStyle_Reader; + +//------------------------------------------------------------------------------ + +#endif /* _AGSIMGUISTYLE_H */ + +//............ diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index bb23ce6..0015726 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -41,6 +41,7 @@ struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax error #include "AgsImVec2.h" #include "AgsImVec4.h" +#include "AgsImGuiStyle.h" #include @@ -187,6 +188,59 @@ namespace agsimgui { const char *ourScriptHeader = " // ags imgui module header \r\n" " \r\n" +" enum ImGuiCol_ \r\n" +" { \r\n" +" ImGuiCol_Text, \r\n" +" ImGuiCol_TextDisabled, \r\n" +" ImGuiCol_WindowBg, // Background of normal windows \r\n" +" ImGuiCol_ChildBg, // Background of child windows \r\n" +" ImGuiCol_PopupBg, // Background of popups, menus, tooltips windows \r\n" +" ImGuiCol_Border, \r\n" +" ImGuiCol_BorderShadow, \r\n" +" ImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input \r\n" +" ImGuiCol_FrameBgHovered, \r\n" +" ImGuiCol_FrameBgActive, \r\n" +" ImGuiCol_TitleBg, \r\n" +" ImGuiCol_TitleBgActive, \r\n" +" ImGuiCol_TitleBgCollapsed, \r\n" +" ImGuiCol_MenuBarBg, \r\n" +" ImGuiCol_ScrollbarBg, \r\n" +" ImGuiCol_ScrollbarGrab, \r\n" +" ImGuiCol_ScrollbarGrabHovered, \r\n" +" ImGuiCol_ScrollbarGrabActive, \r\n" +" ImGuiCol_CheckMark, \r\n" +" ImGuiCol_SliderGrab, \r\n" +" ImGuiCol_SliderGrabActive, \r\n" +" ImGuiCol_Button, \r\n" +" ImGuiCol_ButtonHovered, \r\n" +" ImGuiCol_ButtonActive, \r\n" +" ImGuiCol_Header, // Header* colors are used for CollapsingHeader, TreeNode, Selectable, MenuItem \r\n" +" ImGuiCol_HeaderHovered, \r\n" +" ImGuiCol_HeaderActive, \r\n" +" ImGuiCol_Separator, \r\n" +" ImGuiCol_SeparatorHovered, \r\n" +" ImGuiCol_SeparatorActive, \r\n" +" ImGuiCol_ResizeGrip, \r\n" +" ImGuiCol_ResizeGripHovered, \r\n" +" ImGuiCol_ResizeGripActive, \r\n" +" ImGuiCol_Tab, \r\n" +" ImGuiCol_TabHovered, \r\n" +" ImGuiCol_TabActive, \r\n" +" ImGuiCol_TabUnfocused, \r\n" +" ImGuiCol_TabUnfocusedActive, \r\n" +" ImGuiCol_PlotLines, \r\n" +" ImGuiCol_PlotLinesHovered, \r\n" +" ImGuiCol_PlotHistogram, \r\n" +" ImGuiCol_PlotHistogramHovered, \r\n" +" ImGuiCol_TextSelectedBg, \r\n" +" ImGuiCol_DragDropTarget, \r\n" +" ImGuiCol_NavHighlight, // Gamepad/keyboard: current highlighted item \r\n" +" ImGuiCol_NavWindowingHighlight, // Highlight window when using CTRL+TAB \r\n" +" ImGuiCol_NavWindowingDimBg, // Darken/colorize entire screen behind the CTRL+TAB window list, when active \r\n" +" ImGuiCol_ModalWindowDimBg, // Darken/colorize entire screen behind a modal window, when one is active \r\n" +" ImGuiCol_COUNT \r\n" +" }; \r\n" +" \r\n" " enum ImGuiFocusedFlags \r\n" " { \r\n" " ImGuiFocusedFlags_None = 0, \r\n" @@ -417,6 +471,123 @@ namespace agsimgui { " \r\n" "}; \r\n" " \r\n" +"builtin managed struct ImGuiStyle \r\n" +" { \r\n" +" /// Creates an empty ImGuiStyle. \r\n" +" import static ImGuiStyle* Create(); // $AUTOCOMPLETESTATICONLY$ \r\n" +" \r\n" +" /// Global alpha applies to everything in Dear ImGui. \r\n" +" import attribute float Alpha; \r\n" +" \r\n" +" /// Padding within a window. +" import attribute ImVec2 WindowPadding; +" \r\n" +" /// Radius of window corners rounding. Set to 0.0f to have rectangular windows. \r\n" +" import attribute float WindowRounding; \r\n" +" \r\n" +" /// Thickness of border around windows. Generally set to 0.0f or 1.0f. \r\n" +" import attribute float WindowBorderSize; \r\n" +" \r\n" +" /// Minimum window size. This is a global setting. For individual windows, use SetNextWindowSizeConstraints(). \r\n" +" import attribute ImVec2 WindowMinSize; \r\n" +" \r\n" +" /// Alignment for title bar text. Defaults to (0.0f,0.5f) for left-aligned,vertically centered. \r\n" +" import attribute ImVec2 WindowTitleAlign; \r\n" +" \r\n" +" /// Side of the collapsing/docking button in the title bar (None/Left/Right). Defaults to ImGuiDir_Left. \r\n" +" import attribute ImGuiDir WindowMenuButtonPosition; \r\n" +" \r\n" +" /// Radius of child window corners rounding. Set to 0.0f to have rectangular windows. \r\n" +" import attribute float ChildRounding; \r\n" +" \r\n" +" /// Thickness of border around child windows. Generally set to 0.0f or 1.0f. \r\n" +" import attribute float ChildBorderSize; \r\n" +" \r\n" +" /// Radius of popup window corners rounding. (Note that tooltip windows use WindowRounding) \r\n" +" import attribute float PopupRounding; \r\n" +" \r\n" +" /// Thickness of border around popup/tooltip windows. Generally set to 0.0f or 1.0f. \r\n" +" import attribute float PopupBorderSize; \r\n" +" \r\n" +" /// Padding within a framed rectangle (used by most widgets). \r\n" +" import attribute ImVec2 FramePadding; \r\n" +" \r\n" +" /// Radius of frame corners rounding. Set to 0.0f to have rectangular frame (used by most widgets). \r\n" +" import attribute float FrameRounding; \r\n" +" \r\n" +" /// Thickness of border around frames. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly). \r\n" +" import attribute float FrameBorderSize; \r\n" +" \r\n" +" /// Horizontal and vertical spacing between widgets/lines. \r\n" +" import attribute ImVec2 ItemSpacing; \r\n" +" \r\n" +" /// Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label). \r\n" +" import attribute ImVec2 ItemInnerSpacing; \r\n" +" \r\n" +" /// Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. Don't grow this too much! \r\n" +" import attribute ImVec2 TouchExtraPadding; \r\n" +" \r\n" +" /// Horizontal indentation when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2). \r\n" +" import attribute float IndentSpacing; \r\n" +" \r\n" +" /// Minimum horizontal spacing between two columns. Preferably > (FramePadding.x + 1). \r\n" +" import attribute float ColumnsMinSpacing; \r\n" +" \r\n" +" /// Width of the vertical scrollbar, Height of the horizontal scrollbar. \r\n" +" import attribute float ScrollbarSize; \r\n" +" \r\n" +" /// Radius of grab corners for scrollbar. \r\n" +" import attribute float ScrollbarRounding; \r\n" +" \r\n" +" /// Minimum width/height of a grab box for slider/scrollbar. \r\n" +" import attribute float GrabMinSize; \r\n" +" \r\n" +" /// Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs. \r\n" +" import attribute float GrabRounding; \r\n" +" \r\n" +" /// Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs. \r\n" +" import attribute float TabRounding; \r\n" +" \r\n" +" /// Thickness of border around tabs. \r\n" +" import attribute float TabBorderSize; \r\n" +" \r\n" +" /// Minimum width for close button to appears on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected. \r\n" +" import attribute float TabMinWidthForUnselectedCloseButton; \r\n" +" \r\n" +" /// Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right. \r\n" +" import attribute ImGuiDir ColorButtonPosition; \r\n" +" \r\n" +" /// Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f) (centered). \r\n" +" import attribute ImVec2 ButtonTextAlign; \r\n" +" \r\n" +" /// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line. \r\n" +" import attribute ImVec2 SelectableTextAlign; \r\n" +" \r\n" +" /// Window position are clamped to be visible within the display area by at least this amount. Only applies to regular windows. \r\n" +" import attribute ImVec2 DisplayWindowPadding; \r\n" +" \r\n" +" /// If you cannot see the edges of your screen (e.g. on a TV) increase the safe area padding. Apply to popups/tooltips as well regular windows. NB: Prefer configuring your TV sets correctly! \r\n" +" import attribute ImVec2 DisplaySafeAreaPadding; \r\n" +" \r\n" +" /// Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later. \r\n" +" import attribute float MouseCursorScale; \r\n" +" \r\n" +" /// Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU. \r\n" +" import attribute bool AntiAliasedLines; \r\n" +" \r\n" +" /// Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.) \r\n" +" import attribute bool AntiAliasedFill; \r\n" +" \r\n" +" /// Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. \r\n" +" import attribute float CurveTessellationTol; \r\n" +" \r\n" +" /// Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry. \r\n" +" import attribute float CircleSegmentMaxError; \r\n" +" \r\n" +" /// Colors \r\n" +" import attribute ImVec4 Colors[ImGuiCol_COUNT]; \r\n" +" }; \r\n" +" \r\n" " struct AgsImGui{ \r\n" " // Main \r\n" " \r\n" @@ -930,6 +1101,10 @@ int inline ToAgsBool(bool b){ return b ? 1 : 0; } +bool inline ToNormalBool(int bi){ + return bi!=0 ? true : false; +} + std::string g_ClipboardTextData = ""; static const char* ImGui_ImplClip_GetClipboardText(void*) @@ -1103,6 +1278,394 @@ AgsImVec4* AgsImVec4_Scale(AgsImVec4* self, uint32_t scale){ // -- end AgsImVec4 +// -- being AgsImGuiStyle + +AgsImVec2* NewAgsImVec2(ImVec2 &imVec2) { + AgsImVec2 *agsImVec2 = new AgsImVec2(imVec2.x,imVec2.y); + agsImVec2->id = engine->RegisterManagedObject(agsImVec2, &AgsImVec2_Interface); + return agsImVec2; +} + +AgsImVec4* NewAgsImVec4(ImVec4 &imVec4) { + AgsImVec4 *agsImVec4 = new AgsImVec4(imVec4.x,imVec4.y, imVec4.z, imVec4.w); + agsImVec4->id = engine->RegisterManagedObject(agsImVec4, &AgsImVec4_Interface); + return agsImVec4; +} + +void SetAgsImVec2(ImVec2 &imVec2, AgsImVec2* agsImVec2){ + imVec2.x = agsImVec2->x; + imVec2.y = agsImVec2->y; +} + +void SetAgsImVec4(ImVec4 &imVec4, AgsImVec4* agsImVec4){ + imVec4.x = agsImVec4->x; + imVec4.y = agsImVec4->y; + imVec4.z = agsImVec4->z; + imVec4.w = agsImVec4->w; +} + +void AgsImGuiStyle_SetAlpha(AgsImGuiStyle* self, uint32_t alpha){ + float f_alpha = ToNormalFloat(alpha); + self->Alpha = f_alpha; +} + +uint32_t AgsImGuiStyle_GetAlpha(AgsImGuiStyle* self){ + return ToAgsFloat(self->Alpha); +} + + +void AgsImGuiStyle_SetWindowPadding(AgsImGuiStyle* self, AgsImVec2* windowPadding){ + SetAgsImVec2(self->WindowPadding, windowPadding); +} + +AgsImVec2* AgsImGuiStyle_GetWindowPadding(AgsImGuiStyle* self){ + return NewAgsImVec2(self->WindowPadding); +} + + +void AgsImGuiStyle_SetWindowRounding(AgsImGuiStyle* self, uint32_t windowRounding){ + float f_windowRounding = ToNormalFloat(windowRounding); + self->WindowRounding = f_windowRounding; +} + +uint32_t AgsImGuiStyle_GetWindowRounding(AgsImGuiStyle* self){ + return ToAgsFloat(self->WindowRounding); +} + + +void AgsImGuiStyle_SetWindowBorderSize(AgsImGuiStyle* self, uint32_t windowBorderSize){ + float f_windowBorderSize = ToNormalFloat(windowBorderSize); + self->WindowBorderSize = f_windowBorderSize; +} + +uint32_t AgsImGuiStyle_GetWindowBorderSize(AgsImGuiStyle* self){ + return ToAgsFloat(self->WindowBorderSize); +} + + +void AgsImGuiStyle_SetWindowMinSize(AgsImGuiStyle* self, AgsImVec2* windowMinSize){ + SetAgsImVec2(self->WindowMinSize, windowMinSize); +} + +AgsImVec2* AgsImGuiStyle_GetWindowMinSize(AgsImGuiStyle* self){ + return NewAgsImVec2(self->WindowMinSize); +} + + +void AgsImGuiStyle_SetWindowTitleAlign(AgsImGuiStyle* self, AgsImVec2* windowTitleAlign){ + SetAgsImVec2(self->WindowTitleAlign, windowTitleAlign); +} + +AgsImVec2* AgsImGuiStyle_GetWindowTitleAlign(AgsImGuiStyle* self){ + return NewAgsImVec2(self->WindowTitleAlign); +} + + +void AgsImGuiStyle_SetWindowMenuButtonPosition(AgsImGuiStyle* self, int windowMenuButtonPosition){ + self->WindowMenuButtonPosition = windowMenuButtonPosition; +} + +int AgsImGuiStyle_GetWindowMenuButtonPosition(AgsImGuiStyle* self){ + return self->WindowMenuButtonPosition; +} + + +void AgsImGuiStyle_SetChildRounding(AgsImGuiStyle* self, uint32_t childRounding){ + float f_childRounding = ToNormalFloat(childRounding); + self->ChildRounding = f_childRounding; +} + +uint32_t AgsImGuiStyle_GetChildRounding(AgsImGuiStyle* self){ + return ToAgsFloat(self->ChildRounding); +} + + +void AgsImGuiStyle_SetChildBorderSize(AgsImGuiStyle* self, uint32_t childBorderSize){ + float f_childBorderSize = ToNormalFloat(childBorderSize); + self->ChildBorderSize = f_childBorderSize; +} + +uint32_t AgsImGuiStyle_GetChildBorderSize(AgsImGuiStyle* self){ + return ToAgsFloat(self->ChildBorderSize); +} + + +void AgsImGuiStyle_SetPopupRounding(AgsImGuiStyle* self, uint32_t popupRounding){ + float f_popupRounding = ToNormalFloat(popupRounding); + self->PopupRounding = f_popupRounding; +} + +uint32_t AgsImGuiStyle_GetPopupRounding(AgsImGuiStyle* self){ + return ToAgsFloat(self->PopupRounding); +} + + +void AgsImGuiStyle_SetPopupBorderSize(AgsImGuiStyle* self, uint32_t popupBorderSize){ + float f_popupBorderSize = ToNormalFloat(popupBorderSize); + self->PopupBorderSize = f_popupBorderSize; +} + +uint32_t AgsImGuiStyle_GetPopupBorderSize(AgsImGuiStyle* self){ + return ToAgsFloat(self->PopupBorderSize); +} + + +void AgsImGuiStyle_SetFramePadding(AgsImGuiStyle* self, AgsImVec2* framePadding){ + SetAgsImVec2(self->FramePadding, framePadding); +} + +AgsImVec2* AgsImGuiStyle_GetFramePadding(AgsImGuiStyle* self){ + return NewAgsImVec2(self->FramePadding); +} + + +void AgsImGuiStyle_SetFrameRounding(AgsImGuiStyle* self, uint32_t frameRounding){ + float f_frameRounding = ToNormalFloat(frameRounding); + self->FrameRounding = f_frameRounding; +} + +uint32_t AgsImGuiStyle_GetFrameRounding(AgsImGuiStyle* self){ + return ToAgsFloat(self->FrameRounding); +} + + +void AgsImGuiStyle_SetFrameBorderSize(AgsImGuiStyle* self, uint32_t frameBorderSize){ + float f_frameBorderSize = ToNormalFloat(frameBorderSize); + self->FrameBorderSize = f_frameBorderSize; +} + +uint32_t AgsImGuiStyle_GetFrameBorderSize(AgsImGuiStyle* self){ + return ToAgsFloat(self->FrameBorderSize); +} + + +void AgsImGuiStyle_SetItemSpacing(AgsImGuiStyle* self, AgsImVec2* itemSpacing){ + SetAgsImVec2(self->ItemSpacing, itemSpacing); +} + +AgsImVec2* AgsImGuiStyle_GetItemSpacing(AgsImGuiStyle* self){ + return NewAgsImVec2(self->ItemSpacing); +} + + +void AgsImGuiStyle_SetItemInnerSpacing(AgsImGuiStyle* self, AgsImVec2* itemInnerSpacing){ + SetAgsImVec2(self->ItemInnerSpacing, itemInnerSpacing); +} + +AgsImVec2* AgsImGuiStyle_GetItemInnerSpacing(AgsImGuiStyle* self){ + return NewAgsImVec2(self->ItemInnerSpacing); +} + + +void AgsImGuiStyle_SetTouchExtraPadding(AgsImGuiStyle* self, AgsImVec2* touchExtraPadding){ + SetAgsImVec2(self->TouchExtraPadding, touchExtraPadding); +} + +AgsImVec2* AgsImGuiStyle_GetTouchExtraPadding(AgsImGuiStyle* self){ + return NewAgsImVec2(self->TouchExtraPadding); +} + + +void AgsImGuiStyle_SetIndentSpacing(AgsImGuiStyle* self, uint32_t indentSpacing){ + float f_indentSpacing = ToNormalFloat(indentSpacing); + self->IndentSpacing = f_indentSpacing; +} + +uint32_t AgsImGuiStyle_GetIndentSpacing(AgsImGuiStyle* self){ + return ToAgsFloat(self->IndentSpacing); +} + + +void AgsImGuiStyle_SetColumnsMinSpacing(AgsImGuiStyle* self, uint32_t columnsMinSpacing){ + float f_columnsMinSpacing = ToNormalFloat(columnsMinSpacing); + self->ColumnsMinSpacing = f_columnsMinSpacing; +} + +uint32_t AgsImGuiStyle_GetColumnsMinSpacing(AgsImGuiStyle* self){ + return ToAgsFloat(self->ColumnsMinSpacing); +} + + +void AgsImGuiStyle_SetScrollbarSize(AgsImGuiStyle* self, uint32_t scrollbarSize){ + float f_scrollbarSize = ToNormalFloat(scrollbarSize); + self->ScrollbarSize = f_scrollbarSize; +} + +uint32_t AgsImGuiStyle_GetScrollbarSize(AgsImGuiStyle* self){ + return ToAgsFloat(self->ScrollbarSize); +} + + +void AgsImGuiStyle_SetScrollbarRounding(AgsImGuiStyle* self, uint32_t scrollbarRounding){ + float f_scrollbarRounding = ToNormalFloat(scrollbarRounding); + self->ScrollbarRounding = f_scrollbarRounding; +} + +uint32_t AgsImGuiStyle_GetScrollbarRounding(AgsImGuiStyle* self){ + return ToAgsFloat(self->ScrollbarRounding); +} + + +void AgsImGuiStyle_SetGrabMinSize(AgsImGuiStyle* self, uint32_t grabMinSize){ + float f_grabMinSize = ToNormalFloat(grabMinSize); + self->GrabMinSize = f_grabMinSize; +} + +uint32_t AgsImGuiStyle_GetGrabMinSize(AgsImGuiStyle* self){ + return ToAgsFloat(self->GrabMinSize); +} + + +void AgsImGuiStyle_SetGrabRounding(AgsImGuiStyle* self, uint32_t grabRounding){ + float f_grabRounding = ToNormalFloat(grabRounding); + self->GrabRounding = f_grabRounding; +} + +uint32_t AgsImGuiStyle_GetGrabRounding(AgsImGuiStyle* self){ + return ToAgsFloat(self->GrabRounding); +} + + +void AgsImGuiStyle_SetTabRounding(AgsImGuiStyle* self, uint32_t tabRounding){ + float f_tabRounding = ToNormalFloat(tabRounding); + self->TabRounding = f_tabRounding; +} + +uint32_t AgsImGuiStyle_GetTabRounding(AgsImGuiStyle* self){ + return ToAgsFloat(self->TabRounding); +} + + +void AgsImGuiStyle_SetTabBorderSize(AgsImGuiStyle* self, uint32_t tabBorderSize){ + float f_tabBorderSize = ToNormalFloat(tabBorderSize); + self->TabBorderSize = f_tabBorderSize; +} + +uint32_t AgsImGuiStyle_GetTabBorderSize(AgsImGuiStyle* self){ + return ToAgsFloat(self->TabBorderSize); +} + + +void AgsImGuiStyle_SetTabMinWidthForUnselectedCloseButton(AgsImGuiStyle* self, uint32_t tabMinWidthForUnselectedCloseButton){ + float f_tabMinWidthForUnselectedCloseButton = ToNormalFloat(tabMinWidthForUnselectedCloseButton); + self->TabMinWidthForUnselectedCloseButton = f_tabMinWidthForUnselectedCloseButton; +} + +uint32_t AgsImGuiStyle_GetTabMinWidthForUnselectedCloseButton(AgsImGuiStyle* self){ + return ToAgsFloat(self->TabMinWidthForUnselectedCloseButton); +} + + +void AgsImGuiStyle_SetColorButtonPosition(AgsImGuiStyle* self, int colorButtonPosition){ + self->ColorButtonPosition = colorButtonPosition; +} + +int AgsImGuiStyle_GetColorButtonPosition(AgsImGuiStyle* self){ + return self->ColorButtonPosition; +} + + +void AgsImGuiStyle_SetButtonTextAlign(AgsImGuiStyle* self, AgsImVec2* buttonTextAlign){ + SetAgsImVec2(self->ButtonTextAlign, buttonTextAlign); +} + +AgsImVec2* AgsImGuiStyle_GetButtonTextAlign(AgsImGuiStyle* self){ + return NewAgsImVec2(self->ButtonTextAlign); +} + + +void AgsImGuiStyle_SetSelectableTextAlign(AgsImGuiStyle* self, AgsImVec2* selectableTextAlign){ + SetAgsImVec2(self->SelectableTextAlign, selectableTextAlign); +} + +AgsImVec2* AgsImGuiStyle_GetSelectableTextAlign(AgsImGuiStyle* self){ + return NewAgsImVec2(self->SelectableTextAlign); +} + + +void AgsImGuiStyle_SetDisplayWindowPadding(AgsImGuiStyle* self, AgsImVec2* displayWindowPadding){ + SetAgsImVec2(self->DisplayWindowPadding, displayWindowPadding); +} + +AgsImVec2* AgsImGuiStyle_GetDisplayWindowPadding(AgsImGuiStyle* self){ + return NewAgsImVec2(self->DisplayWindowPadding); +} + + +void AgsImGuiStyle_SetDisplaySafeAreaPadding(AgsImGuiStyle* self, AgsImVec2* displaySafeAreaPadding){ + SetAgsImVec2(self->DisplaySafeAreaPadding, displaySafeAreaPadding); +} + +AgsImVec2* AgsImGuiStyle_GetDisplaySafeAreaPadding(AgsImGuiStyle* self){ + return NewAgsImVec2(self->DisplaySafeAreaPadding); +} + + +void AgsImGuiStyle_SetMouseCursorScale(AgsImGuiStyle* self, uint32_t mouseCursorScale){ + float f_mouseCursorScale = ToNormalFloat(mouseCursorScale); + self->MouseCursorScale = f_mouseCursorScale; +} + +uint32_t AgsImGuiStyle_GetMouseCursorScale(AgsImGuiStyle* self){ + return ToAgsFloat(self->MouseCursorScale); +} + + +void AgsImGuiStyle_SetAntiAliasedLines(AgsImGuiStyle* self, int antiAliasedLines){ + self->AntiAliasedLines = ToNormalBool(antiAliasedLines); +} + +int AgsImGuiStyle_GetAntiAliasedLines(AgsImGuiStyle* self){ + return ToAgsBool(self->AntiAliasedLines); +} + + +void AgsImGuiStyle_SetAntiAliasedFill(AgsImGuiStyle* self, int antiAliasedFill){ + self->AntiAliasedFill = ToNormalBool(antiAliasedFill); +} + +int AgsImGuiStyle_GetAntiAliasedFill(AgsImGuiStyle* self){ + return ToAgsBool(self->AntiAliasedFill); +} + + +void AgsImGuiStyle_SetCurveTessellationTol(AgsImGuiStyle* self, uint32_t curveTessellationTol){ + float f_curveTessellationTol = ToNormalFloat(curveTessellationTol); + self->CurveTessellationTol = f_curveTessellationTol; +} + +uint32_t AgsImGuiStyle_GetCurveTessellationTol(AgsImGuiStyle* self){ + return ToAgsFloat(self->CurveTessellationTol); +} + + +void AgsImGuiStyle_SetCircleSegmentMaxError(AgsImGuiStyle* self, uint32_t circleSegmentMaxError){ + float f_circleSegmentMaxError= ToNormalFloat(circleSegmentMaxError); + self->CircleSegmentMaxError = f_circleSegmentMaxError; +} + +uint32_t AgsImGuiStyle_GetCircleSegmentMaxError(AgsImGuiStyle* self){ + return ToAgsFloat(self->CircleSegmentMaxError); +} + + +void AgsImGuiStyle_SetColors(AgsImGuiStyle* self, int i, AgsImVec4* color){ + if ((i < 0) || (i > ImGuiCol_COUNT)) + return; + + SetAgsImVec4(self->Colors[i], color); +} + +AgsImVec4* AgsImGuiStyle_GetColors(AgsImGuiStyle* self, int i){ + if ((i < 0) || (i > ImGuiCol_COUNT)) + return nullptr; + + return NewAgsImVec4(self->Colors[i]); +} + + + +// -- end AgsImGuiStyle void AgsImGui_NewFrame(){ if (!screen.initialized) return; @@ -1791,6 +2354,7 @@ int AgsImGuiHelper_GetClipboarImage() { engine->AddManagedObjectReader(AgsImVec2Interface::name, &AgsImVec2_Reader); engine->AddManagedObjectReader(AgsImVec4Interface::name, &AgsImVec4_Reader); + engine->AddManagedObjectReader(AgsImGuiStyleInterface::name, &AgsImGuiStyle_Reader); //register functions if(screen.driver == Screen::Driver::eOpenGL) { @@ -1893,6 +2457,81 @@ int AgsImGuiHelper_GetClipboarImage() { engine->RegisterScriptFunction("ImVec2::Sub^1", (void*)AgsImVec2_Sub); engine->RegisterScriptFunction("ImVec2::Scale^1", (void*)AgsImVec2_Scale); + engine->RegisterScriptFunction("ImGuiStyle::set_Alpha", (void*)AgsImGuiStyle_SetAlpha); + engine->RegisterScriptFunction("ImGuiStyle::get_Alpha", (void*)AgsImGuiStyle_GetAlpha); + engine->RegisterScriptFunction("ImGuiStyle::set_WindowPadding", (void*)AgsImGuiStyle_SetWindowPadding); + engine->RegisterScriptFunction("ImGuiStyle::get_WindowPadding", (void*)AgsImGuiStyle_GetWindowPadding); + engine->RegisterScriptFunction("ImGuiStyle::set_WindowRounding", (void*)AgsImGuiStyle_SetWindowRounding); + engine->RegisterScriptFunction("ImGuiStyle::get_WindowRounding", (void*)AgsImGuiStyle_GetWindowRounding); + engine->RegisterScriptFunction("ImGuiStyle::set_WindowBorderSize", (void*)AgsImGuiStyle_SetWindowBorderSize); + engine->RegisterScriptFunction("ImGuiStyle::get_WindowBorderSize", (void*)AgsImGuiStyle_GetWindowBorderSize); + engine->RegisterScriptFunction("ImGuiStyle::set_WindowMinSize", (void*)AgsImGuiStyle_SetWindowMinSize); + engine->RegisterScriptFunction("ImGuiStyle::get_WindowMinSize", (void*)AgsImGuiStyle_GetWindowMinSize); + engine->RegisterScriptFunction("ImGuiStyle::set_WindowTitleAlign", (void*)AgsImGuiStyle_SetWindowTitleAlign); + engine->RegisterScriptFunction("ImGuiStyle::get_WindowTitleAlign", (void*)AgsImGuiStyle_GetWindowTitleAlign); + engine->RegisterScriptFunction("ImGuiStyle::set_WindowMenuButtonPosition", (void*)AgsImGuiStyle_SetWindowMenuButtonPosition); + engine->RegisterScriptFunction("ImGuiStyle::get_WindowMenuButtonPosition", (void*)AgsImGuiStyle_GetWindowMenuButtonPosition); + engine->RegisterScriptFunction("ImGuiStyle::set_ChildRounding", (void*)AgsImGuiStyle_SetChildRounding); + engine->RegisterScriptFunction("ImGuiStyle::get_ChildRounding", (void*)AgsImGuiStyle_GetChildRounding); + engine->RegisterScriptFunction("ImGuiStyle::set_ChildBorderSize", (void*)AgsImGuiStyle_SetChildBorderSize); + engine->RegisterScriptFunction("ImGuiStyle::get_ChildBorderSize", (void*)AgsImGuiStyle_GetChildBorderSize); + engine->RegisterScriptFunction("ImGuiStyle::set_PopupRounding", (void*)AgsImGuiStyle_SetPopupRounding); + engine->RegisterScriptFunction("ImGuiStyle::get_PopupRounding", (void*)AgsImGuiStyle_GetPopupRounding); + engine->RegisterScriptFunction("ImGuiStyle::set_PopupBorderSize", (void*)AgsImGuiStyle_SetPopupBorderSize); + engine->RegisterScriptFunction("ImGuiStyle::get_PopupBorderSize", (void*)AgsImGuiStyle_GetPopupBorderSize); + engine->RegisterScriptFunction("ImGuiStyle::set_FramePadding", (void*)AgsImGuiStyle_SetFramePadding); + engine->RegisterScriptFunction("ImGuiStyle::get_FramePadding", (void*)AgsImGuiStyle_GetFramePadding); + engine->RegisterScriptFunction("ImGuiStyle::set_FrameRounding", (void*)AgsImGuiStyle_SetFrameRounding); + engine->RegisterScriptFunction("ImGuiStyle::get_FrameRounding", (void*)AgsImGuiStyle_GetFrameRounding); + engine->RegisterScriptFunction("ImGuiStyle::set_FrameBorderSize", (void*)AgsImGuiStyle_SetFrameBorderSize); + engine->RegisterScriptFunction("ImGuiStyle::get_FrameBorderSize", (void*)AgsImGuiStyle_GetFrameBorderSize); + engine->RegisterScriptFunction("ImGuiStyle::set_ItemSpacing", (void*)AgsImGuiStyle_SetItemSpacing); + engine->RegisterScriptFunction("ImGuiStyle::get_ItemSpacing", (void*)AgsImGuiStyle_GetItemSpacing); + engine->RegisterScriptFunction("ImGuiStyle::set_ItemInnerSpacing", (void*)AgsImGuiStyle_SetItemInnerSpacing); + engine->RegisterScriptFunction("ImGuiStyle::get_ItemInnerSpacing", (void*)AgsImGuiStyle_GetItemInnerSpacing); + engine->RegisterScriptFunction("ImGuiStyle::set_TouchExtraPadding", (void*)AgsImGuiStyle_SetTouchExtraPadding); + engine->RegisterScriptFunction("ImGuiStyle::get_TouchExtraPadding", (void*)AgsImGuiStyle_GetTouchExtraPadding); + engine->RegisterScriptFunction("ImGuiStyle::set_IndentSpacing", (void*)AgsImGuiStyle_SetIndentSpacing); + engine->RegisterScriptFunction("ImGuiStyle::get_IndentSpacing", (void*)AgsImGuiStyle_GetIndentSpacing); + engine->RegisterScriptFunction("ImGuiStyle::set_ColumnsMinSpacing", (void*)AgsImGuiStyle_SetColumnsMinSpacing); + engine->RegisterScriptFunction("ImGuiStyle::get_ColumnsMinSpacing", (void*)AgsImGuiStyle_GetColumnsMinSpacing); + engine->RegisterScriptFunction("ImGuiStyle::set_ScrollbarSize", (void*)AgsImGuiStyle_SetScrollbarSize); + engine->RegisterScriptFunction("ImGuiStyle::get_ScrollbarSize", (void*)AgsImGuiStyle_GetScrollbarSize); + engine->RegisterScriptFunction("ImGuiStyle::set_ScrollbarRounding", (void*)AgsImGuiStyle_SetScrollbarRounding); + engine->RegisterScriptFunction("ImGuiStyle::get_ScrollbarRounding", (void*)AgsImGuiStyle_GetScrollbarRounding); + engine->RegisterScriptFunction("ImGuiStyle::set_GrabMinSize", (void*)AgsImGuiStyle_SetGrabMinSize); + engine->RegisterScriptFunction("ImGuiStyle::get_GrabMinSize", (void*)AgsImGuiStyle_GetGrabMinSize); + engine->RegisterScriptFunction("ImGuiStyle::set_GrabRounding", (void*)AgsImGuiStyle_SetGrabRounding); + engine->RegisterScriptFunction("ImGuiStyle::get_GrabRounding", (void*)AgsImGuiStyle_GetGrabRounding); + engine->RegisterScriptFunction("ImGuiStyle::set_TabRounding", (void*)AgsImGuiStyle_SetTabRounding); + engine->RegisterScriptFunction("ImGuiStyle::get_TabRounding", (void*)AgsImGuiStyle_GetTabRounding); + engine->RegisterScriptFunction("ImGuiStyle::set_TabBorderSize", (void*)AgsImGuiStyle_SetTabBorderSize); + engine->RegisterScriptFunction("ImGuiStyle::get_TabBorderSize", (void*)AgsImGuiStyle_GetTabBorderSize); + engine->RegisterScriptFunction("ImGuiStyle::set_TabMinWidthForUnselectedCloseButton", (void*)AgsImGuiStyle_SetTabMinWidthForUnselectedCloseButton); + engine->RegisterScriptFunction("ImGuiStyle::get_TabMinWidthForUnselectedCloseButton", (void*)AgsImGuiStyle_GetTabMinWidthForUnselectedCloseButton); + engine->RegisterScriptFunction("ImGuiStyle::set_ColorButtonPosition", (void*)AgsImGuiStyle_SetColorButtonPosition); + engine->RegisterScriptFunction("ImGuiStyle::get_ColorButtonPosition", (void*)AgsImGuiStyle_GetColorButtonPosition); + engine->RegisterScriptFunction("ImGuiStyle::set_ButtonTextAlign", (void*)AgsImGuiStyle_SetButtonTextAlign); + engine->RegisterScriptFunction("ImGuiStyle::get_ButtonTextAlign", (void*)AgsImGuiStyle_GetButtonTextAlign); + engine->RegisterScriptFunction("ImGuiStyle::set_SelectableTextAlign", (void*)AgsImGuiStyle_SetSelectableTextAlign); + engine->RegisterScriptFunction("ImGuiStyle::get_SelectableTextAlign", (void*)AgsImGuiStyle_GetSelectableTextAlign); + engine->RegisterScriptFunction("ImGuiStyle::set_DisplayWindowPadding", (void*)AgsImGuiStyle_SetDisplayWindowPadding); + engine->RegisterScriptFunction("ImGuiStyle::get_DisplayWindowPadding", (void*)AgsImGuiStyle_GetDisplayWindowPadding); + engine->RegisterScriptFunction("ImGuiStyle::set_DisplaySafeAreaPadding", (void*)AgsImGuiStyle_SetDisplaySafeAreaPadding); + engine->RegisterScriptFunction("ImGuiStyle::get_DisplaySafeAreaPadding", (void*)AgsImGuiStyle_GetDisplaySafeAreaPadding); + engine->RegisterScriptFunction("ImGuiStyle::set_MouseCursorScale", (void*)AgsImGuiStyle_SetMouseCursorScale); + engine->RegisterScriptFunction("ImGuiStyle::get_MouseCursorScale", (void*)AgsImGuiStyle_GetMouseCursorScale); + engine->RegisterScriptFunction("ImGuiStyle::set_AntiAliasedLines", (void*)AgsImGuiStyle_SetAntiAliasedLines); + engine->RegisterScriptFunction("ImGuiStyle::get_AntiAliasedLines", (void*)AgsImGuiStyle_GetAntiAliasedLines); + engine->RegisterScriptFunction("ImGuiStyle::set_AntiAliasedFill", (void*)AgsImGuiStyle_SetAntiAliasedFill); + engine->RegisterScriptFunction("ImGuiStyle::get_AntiAliasedFill", (void*)AgsImGuiStyle_GetAntiAliasedFill); + engine->RegisterScriptFunction("ImGuiStyle::set_CurveTessellationTol", (void*)AgsImGuiStyle_SetCurveTessellationTol); + engine->RegisterScriptFunction("ImGuiStyle::get_CurveTessellationTol", (void*)AgsImGuiStyle_GetCurveTessellationTol); + engine->RegisterScriptFunction("ImGuiStyle::set_CircleSegmentMaxError", (void*)AgsImGuiStyle_SetCircleSegmentMaxError); + engine->RegisterScriptFunction("ImGuiStyle::get_CircleSegmentMaxError", (void*)AgsImGuiStyle_GetCircleSegmentMaxError); + engine->RegisterScriptFunction("ImGuiStyle::seti_Colors", (void*)AgsImGuiStyle_SetColors); + engine->RegisterScriptFunction("ImGuiStyle::geti_Colors", (void*)AgsImGuiStyle_GetColors); + engine->RegisterScriptFunction("AgsImGui::NewFrame^0", (void*)AgsImGui_NewFrame); engine->RegisterScriptFunction("AgsImGui::EndFrame^0", (void*)AgsImGui_EndFrame); engine->RegisterScriptFunction("AgsImGui::Render^0", (void*)AgsImGui_Render); From 634d26cf53f1ea6d73b35713a6569cfe2a97f2ae Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 20:39:58 -0300 Subject: [PATCH 05/16] updates Makefile to build AgsImGui new objects ImVec2 ImVec4 and ImGuiStyle --- agsimgui/Makefile-objs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agsimgui/Makefile-objs b/agsimgui/Makefile-objs index 4ee23cf..657e50a 100644 --- a/agsimgui/Makefile-objs +++ b/agsimgui/Makefile-objs @@ -1 +1 @@ -OBJS += Screen.o imgui/imgui.o imgui/imgui_demo.o imgui/imgui_draw.o imgui/imgui_widgets.o imgui/examples/imgui_impl_softraster.o imgui/examples/imgui_impl_dx9.o imgui/misc/cpp/imgui_stdlib.o agsimgui.o +OBJS += Screen.o imgui/imgui.o imgui/imgui_demo.o imgui/imgui_draw.o imgui/imgui_widgets.o imgui/examples/imgui_impl_softraster.o imgui/examples/imgui_impl_dx9.o imgui/misc/cpp/imgui_stdlib.o agsimgui.o AgsImGuiStyle.o AgsImVec2.o AgsImVec4.o From 7400434915fc4e49cdfc8595607838dac122dd1f Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 20:43:45 -0300 Subject: [PATCH 06/16] updates vcxproj files --- agsimgui/agsimgui.vcxproj | 6 ++++++ agsimgui/agsimgui.vcxproj.filters | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/agsimgui/agsimgui.vcxproj b/agsimgui/agsimgui.vcxproj index 56ddeaa..ee7308b 100644 --- a/agsimgui/agsimgui.vcxproj +++ b/agsimgui/agsimgui.vcxproj @@ -168,6 +168,9 @@ + + + @@ -182,6 +185,9 @@ + + + diff --git a/agsimgui/agsimgui.vcxproj.filters b/agsimgui/agsimgui.vcxproj.filters index 795be51..cc06f39 100644 --- a/agsimgui/agsimgui.vcxproj.filters +++ b/agsimgui/agsimgui.vcxproj.filters @@ -30,6 +30,15 @@ Source Files + + Source Files + + + Source Files + + + Source Files + Source Files @@ -68,6 +77,15 @@ Header Files + + Header Files + + + Header Files + + + Header Files + Header Files From f28a2da8b43f16eebc832d47ac67990e50afab9d Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 20:54:46 -0300 Subject: [PATCH 07/16] fixes enum of styles --- agsimgui/agsimgui.cpp | 114 +++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index 0015726..663be99 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -190,64 +190,64 @@ namespace agsimgui { " \r\n" " enum ImGuiCol_ \r\n" " { \r\n" -" ImGuiCol_Text, \r\n" -" ImGuiCol_TextDisabled, \r\n" -" ImGuiCol_WindowBg, // Background of normal windows \r\n" -" ImGuiCol_ChildBg, // Background of child windows \r\n" -" ImGuiCol_PopupBg, // Background of popups, menus, tooltips windows \r\n" -" ImGuiCol_Border, \r\n" -" ImGuiCol_BorderShadow, \r\n" -" ImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input \r\n" -" ImGuiCol_FrameBgHovered, \r\n" -" ImGuiCol_FrameBgActive, \r\n" -" ImGuiCol_TitleBg, \r\n" -" ImGuiCol_TitleBgActive, \r\n" -" ImGuiCol_TitleBgCollapsed, \r\n" -" ImGuiCol_MenuBarBg, \r\n" -" ImGuiCol_ScrollbarBg, \r\n" -" ImGuiCol_ScrollbarGrab, \r\n" -" ImGuiCol_ScrollbarGrabHovered, \r\n" -" ImGuiCol_ScrollbarGrabActive, \r\n" -" ImGuiCol_CheckMark, \r\n" -" ImGuiCol_SliderGrab, \r\n" -" ImGuiCol_SliderGrabActive, \r\n" -" ImGuiCol_Button, \r\n" -" ImGuiCol_ButtonHovered, \r\n" -" ImGuiCol_ButtonActive, \r\n" -" ImGuiCol_Header, // Header* colors are used for CollapsingHeader, TreeNode, Selectable, MenuItem \r\n" -" ImGuiCol_HeaderHovered, \r\n" -" ImGuiCol_HeaderActive, \r\n" -" ImGuiCol_Separator, \r\n" -" ImGuiCol_SeparatorHovered, \r\n" -" ImGuiCol_SeparatorActive, \r\n" -" ImGuiCol_ResizeGrip, \r\n" -" ImGuiCol_ResizeGripHovered, \r\n" -" ImGuiCol_ResizeGripActive, \r\n" -" ImGuiCol_Tab, \r\n" -" ImGuiCol_TabHovered, \r\n" -" ImGuiCol_TabActive, \r\n" -" ImGuiCol_TabUnfocused, \r\n" -" ImGuiCol_TabUnfocusedActive, \r\n" -" ImGuiCol_PlotLines, \r\n" -" ImGuiCol_PlotLinesHovered, \r\n" -" ImGuiCol_PlotHistogram, \r\n" -" ImGuiCol_PlotHistogramHovered, \r\n" -" ImGuiCol_TextSelectedBg, \r\n" -" ImGuiCol_DragDropTarget, \r\n" -" ImGuiCol_NavHighlight, // Gamepad/keyboard: current highlighted item \r\n" -" ImGuiCol_NavWindowingHighlight, // Highlight window when using CTRL+TAB \r\n" -" ImGuiCol_NavWindowingDimBg, // Darken/colorize entire screen behind the CTRL+TAB window list, when active \r\n" -" ImGuiCol_ModalWindowDimBg, // Darken/colorize entire screen behind a modal window, when one is active \r\n" -" ImGuiCol_COUNT \r\n" +" eImGuiCol_Text, \r\n" +" eImGuiCol_TextDisabled, \r\n" +" eImGuiCol_WindowBg, // Background of normal windows \r\n" +" eImGuiCol_ChildBg, // Background of child windows \r\n" +" eImGuiCol_PopupBg, // Background of popups, menus, tooltips windows \r\n" +" eImGuiCol_Border, \r\n" +" eImGuiCol_BorderShadow, \r\n" +" eImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input \r\n" +" eImGuiCol_FrameBgHovered, \r\n" +" eImGuiCol_FrameBgActive, \r\n" +" eImGuiCol_TitleBg, \r\n" +" eImGuiCol_TitleBgActive, \r\n" +" eImGuiCol_TitleBgCollapsed, \r\n" +" eImGuiCol_MenuBarBg, \r\n" +" eImGuiCol_ScrollbarBg, \r\n" +" eImGuiCol_ScrollbarGrab, \r\n" +" eImGuiCol_ScrollbarGrabHovered, \r\n" +" eImGuiCol_ScrollbarGrabActive, \r\n" +" eImGuiCol_CheckMark, \r\n" +" eImGuiCol_SliderGrab, \r\n" +" eImGuiCol_SliderGrabActive, \r\n" +" eImGuiCol_Button, \r\n" +" eImGuiCol_ButtonHovered, \r\n" +" eImGuiCol_ButtonActive, \r\n" +" eImGuiCol_Header, // Header* colors are used for CollapsingHeader, TreeNode, Selectable, MenuItem \r\n" +" eImGuiCol_HeaderHovered, \r\n" +" eImGuiCol_HeaderActive, \r\n" +" eImGuiCol_Separator, \r\n" +" eImGuiCol_SeparatorHovered, \r\n" +" eImGuiCol_SeparatorActive, \r\n" +" eImGuiCol_ResizeGrip, \r\n" +" eImGuiCol_ResizeGripHovered, \r\n" +" eImGuiCol_ResizeGripActive, \r\n" +" eImGuiCol_Tab, \r\n" +" eImGuiCol_TabHovered, \r\n" +" eImGuiCol_TabActive, \r\n" +" eImGuiCol_TabUnfocused, \r\n" +" eImGuiCol_TabUnfocusedActive, \r\n" +" eImGuiCol_PlotLines, \r\n" +" eImGuiCol_PlotLinesHovered, \r\n" +" eImGuiCol_PlotHistogram, \r\n" +" eImGuiCol_PlotHistogramHovered, \r\n" +" eImGuiCol_TextSelectedBg, \r\n" +" eImGuiCol_DragDropTarget, \r\n" +" eImGuiCol_NavHighlight, // Gamepad/keyboard: current highlighted item \r\n" +" eImGuiCol_NavWindowingHighlight, // Highlight window when using CTRL+TAB \r\n" +" eImGuiCol_NavWindowingDimBg, // Darken/colorize entire screen behind the CTRL+TAB window list, when active \r\n" +" eImGuiCol_ModalWindowDimBg, // Darken/colorize entire screen behind a modal window, when one is active \r\n" +" eImGuiCol_COUNT \r\n" " }; \r\n" " \r\n" " enum ImGuiFocusedFlags \r\n" " { \r\n" -" ImGuiFocusedFlags_None = 0, \r\n" -" ImGuiFocusedFlags_ChildWindows = 1, // IsWindowFocused(): Return true if any children of the window is focused \r\n" -" ImGuiFocusedFlags_RootWindow = 2, // IsWindowFocused(): Test from root window (top most parent of the current hierarchy) \r\n" -" ImGuiFocusedFlags_AnyWindow = 4, // IsWindowFocused(): Return true if any window is focused. \r\n" -" ImGuiFocusedFlags_RootAndChildWindows = 3 \r\n" +" eImGuiFocusedFlags_None = 0, \r\n" +" eImGuiFocusedFlags_ChildWindows = 1, // IsWindowFocused(): Return true if any children of the window is focused \r\n" +" eImGuiFocusedFlags_RootWindow = 2, // IsWindowFocused(): Test from root window (top most parent of the current hierarchy) \r\n" +" eImGuiFocusedFlags_AnyWindow = 4, // IsWindowFocused(): Return true if any window is focused. \r\n" +" eImGuiFocusedFlags_RootAndChildWindows = 3 \r\n" " }; \r\n" " \r\n" " enum ImGuiHoveredFlags \r\n" @@ -585,7 +585,7 @@ namespace agsimgui { " import attribute float CircleSegmentMaxError; \r\n" " \r\n" " /// Colors \r\n" -" import attribute ImVec4 Colors[ImGuiCol_COUNT]; \r\n" +" import attribute ImVec4 Colors[]; \r\n" " }; \r\n" " \r\n" " struct AgsImGui{ \r\n" @@ -1650,14 +1650,14 @@ uint32_t AgsImGuiStyle_GetCircleSegmentMaxError(AgsImGuiStyle* self){ void AgsImGuiStyle_SetColors(AgsImGuiStyle* self, int i, AgsImVec4* color){ - if ((i < 0) || (i > ImGuiCol_COUNT)) + if ((i < 0) || (i >= ImGuiCol_COUNT)) return; SetAgsImVec4(self->Colors[i], color); } AgsImVec4* AgsImGuiStyle_GetColors(AgsImGuiStyle* self, int i){ - if ((i < 0) || (i > ImGuiCol_COUNT)) + if ((i < 0) || (i >= ImGuiCol_COUNT)) return nullptr; return NewAgsImVec4(self->Colors[i]); From 25b8f11cf5507384a58d5f249f3bb241937a88d7 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 20:56:58 -0300 Subject: [PATCH 08/16] adds managed builtin --- agsimgui/agsimgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index 663be99..a4e0092 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -588,7 +588,7 @@ namespace agsimgui { " import attribute ImVec4 Colors[]; \r\n" " }; \r\n" " \r\n" -" struct AgsImGui{ \r\n" +"builtin managed struct AgsImGui{ \r\n" " // Main \r\n" " \r\n" " /// start a new Dear ImGui frame, you can submit any command from this point until Render()/EndFrame(). \r\n" From 37fb3f5693b80476ca86172c504f8adc251ea1e9 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 21:00:05 -0300 Subject: [PATCH 09/16] fixes missing line end int the header --- agsimgui/agsimgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index a4e0092..1149843 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -479,8 +479,8 @@ namespace agsimgui { " /// Global alpha applies to everything in Dear ImGui. \r\n" " import attribute float Alpha; \r\n" " \r\n" -" /// Padding within a window. -" import attribute ImVec2 WindowPadding; +" /// Padding within a window. \r\n" +" import attribute ImVec2 WindowPadding; \r\n" " \r\n" " /// Radius of window corners rounding. Set to 0.0f to have rectangular windows. \r\n" " import attribute float WindowRounding; \r\n" From 044ad30859eb6fcac4f40b3a980c89d3d3c66eb0 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 21:04:12 -0300 Subject: [PATCH 10/16] updates makefile and vcxproj to include SerialHelper --- agsimgui/Makefile-objs | 2 +- agsimgui/agsimgui.vcxproj | 2 ++ agsimgui/agsimgui.vcxproj.filters | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/agsimgui/Makefile-objs b/agsimgui/Makefile-objs index 657e50a..e1273f7 100644 --- a/agsimgui/Makefile-objs +++ b/agsimgui/Makefile-objs @@ -1 +1 @@ -OBJS += Screen.o imgui/imgui.o imgui/imgui_demo.o imgui/imgui_draw.o imgui/imgui_widgets.o imgui/examples/imgui_impl_softraster.o imgui/examples/imgui_impl_dx9.o imgui/misc/cpp/imgui_stdlib.o agsimgui.o AgsImGuiStyle.o AgsImVec2.o AgsImVec4.o +OBJS += Screen.o imgui/imgui.o imgui/imgui_demo.o imgui/imgui_draw.o imgui/imgui_widgets.o imgui/examples/imgui_impl_softraster.o imgui/examples/imgui_impl_dx9.o imgui/misc/cpp/imgui_stdlib.o agsimgui.o AgsImGuiStyle.o AgsImVec2.o AgsImVec4.o SerialHelper.o diff --git a/agsimgui/agsimgui.vcxproj b/agsimgui/agsimgui.vcxproj index ee7308b..12a945e 100644 --- a/agsimgui/agsimgui.vcxproj +++ b/agsimgui/agsimgui.vcxproj @@ -171,6 +171,7 @@ + @@ -188,6 +189,7 @@ + diff --git a/agsimgui/agsimgui.vcxproj.filters b/agsimgui/agsimgui.vcxproj.filters index cc06f39..0ab890d 100644 --- a/agsimgui/agsimgui.vcxproj.filters +++ b/agsimgui/agsimgui.vcxproj.filters @@ -39,6 +39,9 @@ Source Files + + Source Files + Source Files @@ -86,6 +89,9 @@ Header Files + + Header Files + Header Files From ffb56608f1b44f333a23478bbdcd01ead3d886e6 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 21:10:08 -0300 Subject: [PATCH 11/16] Fixes Member variable cannot be struct --- agsimgui/agsimgui.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index 1149843..dc18ea0 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -480,7 +480,7 @@ namespace agsimgui { " import attribute float Alpha; \r\n" " \r\n" " /// Padding within a window. \r\n" -" import attribute ImVec2 WindowPadding; \r\n" +" import attribute ImVec2* WindowPadding; \r\n" " \r\n" " /// Radius of window corners rounding. Set to 0.0f to have rectangular windows. \r\n" " import attribute float WindowRounding; \r\n" @@ -489,10 +489,10 @@ namespace agsimgui { " import attribute float WindowBorderSize; \r\n" " \r\n" " /// Minimum window size. This is a global setting. For individual windows, use SetNextWindowSizeConstraints(). \r\n" -" import attribute ImVec2 WindowMinSize; \r\n" +" import attribute ImVec2* WindowMinSize; \r\n" " \r\n" " /// Alignment for title bar text. Defaults to (0.0f,0.5f) for left-aligned,vertically centered. \r\n" -" import attribute ImVec2 WindowTitleAlign; \r\n" +" import attribute ImVec2* WindowTitleAlign; \r\n" " \r\n" " /// Side of the collapsing/docking button in the title bar (None/Left/Right). Defaults to ImGuiDir_Left. \r\n" " import attribute ImGuiDir WindowMenuButtonPosition; \r\n" @@ -510,7 +510,7 @@ namespace agsimgui { " import attribute float PopupBorderSize; \r\n" " \r\n" " /// Padding within a framed rectangle (used by most widgets). \r\n" -" import attribute ImVec2 FramePadding; \r\n" +" import attribute ImVec2* FramePadding; \r\n" " \r\n" " /// Radius of frame corners rounding. Set to 0.0f to have rectangular frame (used by most widgets). \r\n" " import attribute float FrameRounding; \r\n" @@ -519,13 +519,13 @@ namespace agsimgui { " import attribute float FrameBorderSize; \r\n" " \r\n" " /// Horizontal and vertical spacing between widgets/lines. \r\n" -" import attribute ImVec2 ItemSpacing; \r\n" +" import attribute ImVec2* ItemSpacing; \r\n" " \r\n" " /// Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label). \r\n" -" import attribute ImVec2 ItemInnerSpacing; \r\n" +" import attribute ImVec2* ItemInnerSpacing; \r\n" " \r\n" " /// Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. Don't grow this too much! \r\n" -" import attribute ImVec2 TouchExtraPadding; \r\n" +" import attribute ImVec2* TouchExtraPadding; \r\n" " \r\n" " /// Horizontal indentation when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2). \r\n" " import attribute float IndentSpacing; \r\n" @@ -558,16 +558,16 @@ namespace agsimgui { " import attribute ImGuiDir ColorButtonPosition; \r\n" " \r\n" " /// Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f) (centered). \r\n" -" import attribute ImVec2 ButtonTextAlign; \r\n" +" import attribute ImVec2* ButtonTextAlign; \r\n" " \r\n" " /// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line. \r\n" -" import attribute ImVec2 SelectableTextAlign; \r\n" +" import attribute ImVec2* SelectableTextAlign; \r\n" " \r\n" " /// Window position are clamped to be visible within the display area by at least this amount. Only applies to regular windows. \r\n" -" import attribute ImVec2 DisplayWindowPadding; \r\n" +" import attribute ImVec2* DisplayWindowPadding; \r\n" " \r\n" " /// If you cannot see the edges of your screen (e.g. on a TV) increase the safe area padding. Apply to popups/tooltips as well regular windows. NB: Prefer configuring your TV sets correctly! \r\n" -" import attribute ImVec2 DisplaySafeAreaPadding; \r\n" +" import attribute ImVec2* DisplaySafeAreaPadding; \r\n" " \r\n" " /// Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later. \r\n" " import attribute float MouseCursorScale; \r\n" @@ -585,7 +585,7 @@ namespace agsimgui { " import attribute float CircleSegmentMaxError; \r\n" " \r\n" " /// Colors \r\n" -" import attribute ImVec4 Colors[]; \r\n" +" import attribute ImVec4* Colors[]; \r\n" " }; \r\n" " \r\n" "builtin managed struct AgsImGui{ \r\n" From 60820d84c02485ae3c047d9639e71fa2c6353409 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 22:00:59 -0300 Subject: [PATCH 12/16] adds a way to get or set Style --- agsimgui/AgsImGuiStyle.cpp | 41 +++++++++++++++++++++++++++++++++ agsimgui/AgsImGuiStyle.h | 47 ++++++++++++++++++++++++++++++++++++++ agsimgui/agsimgui.cpp | 27 ++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/agsimgui/AgsImGuiStyle.cpp b/agsimgui/AgsImGuiStyle.cpp index 6de2242..b18ac28 100644 --- a/agsimgui/AgsImGuiStyle.cpp +++ b/agsimgui/AgsImGuiStyle.cpp @@ -8,6 +8,47 @@ #include #include "AgsImGuiStyle.h" +void AgsImGuiStyle::SetAgsImGuiStyle(ImGuiStyle &imGuiStyle, AgsImGuiStyle* agsImGuiStyle){ + imGuiStyle.Alpha = agsImGuiStyle->Alpha; + imGuiStyle.WindowPadding = agsImGuiStyle->WindowPadding; + imGuiStyle.WindowRounding = agsImGuiStyle->WindowRounding; + imGuiStyle.WindowBorderSize = agsImGuiStyle->WindowBorderSize; + imGuiStyle.WindowMinSize = agsImGuiStyle->WindowMinSize; + imGuiStyle.WindowTitleAlign = agsImGuiStyle->WindowTitleAlign; + imGuiStyle.WindowMenuButtonPosition = agsImGuiStyle->WindowMenuButtonPosition; + imGuiStyle.ChildRounding = agsImGuiStyle->ChildRounding; + imGuiStyle.ChildBorderSize = agsImGuiStyle->ChildBorderSize; + imGuiStyle.PopupRounding = agsImGuiStyle->PopupRounding; + imGuiStyle.PopupBorderSize = agsImGuiStyle->PopupBorderSize; + imGuiStyle.FramePadding = agsImGuiStyle->FramePadding; + imGuiStyle.FrameRounding = agsImGuiStyle->FrameRounding; + imGuiStyle.FrameBorderSize = agsImGuiStyle->FrameBorderSize; + imGuiStyle.ItemSpacing = agsImGuiStyle->ItemSpacing; + imGuiStyle.ItemInnerSpacing = agsImGuiStyle->ItemInnerSpacing; + imGuiStyle.TouchExtraPadding = agsImGuiStyle->TouchExtraPadding; + imGuiStyle.IndentSpacing = agsImGuiStyle->IndentSpacing; + imGuiStyle.ColumnsMinSpacing = agsImGuiStyle->ColumnsMinSpacing; + imGuiStyle.ScrollbarSize = agsImGuiStyle->ScrollbarSize; + imGuiStyle.ScrollbarRounding = agsImGuiStyle->ScrollbarRounding; + imGuiStyle.GrabMinSize = agsImGuiStyle->GrabMinSize; + imGuiStyle.GrabRounding = agsImGuiStyle->GrabRounding; + imGuiStyle.TabRounding = agsImGuiStyle->TabRounding; + imGuiStyle.TabBorderSize = agsImGuiStyle->TabBorderSize; + imGuiStyle.TabMinWidthForUnselectedCloseButton = agsImGuiStyle->TabMinWidthForUnselectedCloseButton; + imGuiStyle.ColorButtonPosition = agsImGuiStyle->ColorButtonPosition; + imGuiStyle.ButtonTextAlign = agsImGuiStyle->ButtonTextAlign; + imGuiStyle.SelectableTextAlign = agsImGuiStyle->SelectableTextAlign; + imGuiStyle.DisplayWindowPadding = agsImGuiStyle->DisplayWindowPadding; + imGuiStyle.DisplaySafeAreaPadding = agsImGuiStyle->DisplaySafeAreaPadding; + imGuiStyle.MouseCursorScale = agsImGuiStyle->MouseCursorScale; + imGuiStyle.AntiAliasedLines = agsImGuiStyle->AntiAliasedLines; + imGuiStyle.AntiAliasedFill = agsImGuiStyle->AntiAliasedFill; + imGuiStyle.CurveTessellationTol = agsImGuiStyle->CurveTessellationTol; + imGuiStyle.CircleSegmentMaxError = agsImGuiStyle->CircleSegmentMaxError; + for(int i=0; iColors[i]; + } +} //------------------------------------------------------------------------------ diff --git a/agsimgui/AgsImGuiStyle.h b/agsimgui/AgsImGuiStyle.h index 4d548eb..7c5d847 100644 --- a/agsimgui/AgsImGuiStyle.h +++ b/agsimgui/AgsImGuiStyle.h @@ -25,6 +25,53 @@ struct AgsImGuiStyle: ImGuiStyle { : ImGuiStyle(){ id = _id; } + + AgsImGuiStyle(ImGuiStyle imGuiStyle) + : ImGuiStyle(){ + id = -1; + Alpha = imGuiStyle.Alpha; + WindowPadding = imGuiStyle.WindowPadding; + WindowRounding = imGuiStyle.WindowRounding; + WindowBorderSize = imGuiStyle.WindowBorderSize; + WindowMinSize = imGuiStyle.WindowMinSize; + WindowTitleAlign = imGuiStyle.WindowTitleAlign; + WindowMenuButtonPosition = imGuiStyle.WindowMenuButtonPosition; + ChildRounding = imGuiStyle.ChildRounding; + ChildBorderSize = imGuiStyle.ChildBorderSize; + PopupRounding = imGuiStyle.PopupRounding; + PopupBorderSize = imGuiStyle.PopupBorderSize; + FramePadding = imGuiStyle.FramePadding; + FrameRounding = imGuiStyle.FrameRounding; + FrameBorderSize = imGuiStyle.FrameBorderSize; + ItemSpacing = imGuiStyle.ItemSpacing; + ItemInnerSpacing = imGuiStyle.ItemInnerSpacing; + TouchExtraPadding = imGuiStyle.TouchExtraPadding; + IndentSpacing = imGuiStyle.IndentSpacing; + ColumnsMinSpacing = imGuiStyle.ColumnsMinSpacing; + ScrollbarSize = imGuiStyle.ScrollbarSize; + ScrollbarRounding = imGuiStyle.ScrollbarRounding; + GrabMinSize = imGuiStyle.GrabMinSize; + GrabRounding = imGuiStyle.GrabRounding; + TabRounding = imGuiStyle.TabRounding; + TabBorderSize = imGuiStyle.TabBorderSize; + TabMinWidthForUnselectedCloseButton = imGuiStyle.TabMinWidthForUnselectedCloseButton; + ColorButtonPosition = imGuiStyle.ColorButtonPosition; + ButtonTextAlign = imGuiStyle.ButtonTextAlign; + SelectableTextAlign = imGuiStyle.SelectableTextAlign; + DisplayWindowPadding = imGuiStyle.DisplayWindowPadding; + DisplaySafeAreaPadding = imGuiStyle.DisplaySafeAreaPadding; + MouseCursorScale = imGuiStyle.MouseCursorScale; + AntiAliasedLines = imGuiStyle.AntiAliasedLines; + AntiAliasedFill = imGuiStyle.AntiAliasedFill; + CurveTessellationTol = imGuiStyle.CurveTessellationTol; + CircleSegmentMaxError = imGuiStyle.CircleSegmentMaxError; + for(int i=0; iw; } +AgsImGuiStyle* NewAgsImGuiStyle(ImGuiStyle &imGuiStyle) { + AgsImGuiStyle *agsImGuiStyle = new AgsImGuiStyle(imGuiStyle); + agsImGuiStyle->id = engine->RegisterManagedObject(agsImGuiStyle, &AgsImGuiStyle_Interface); + return agsImGuiStyle; +} + +void SetAgsImGuiStyle(ImGuiStyle &imGuiStyle, AgsImGuiStyle* agsImGuiStyle){ + AgsImGuiStyle::SetAgsImGuiStyle(imGuiStyle, agsImGuiStyle); +} + void AgsImGuiStyle_SetAlpha(AgsImGuiStyle* self, uint32_t alpha){ float f_alpha = ToNormalFloat(alpha); self->Alpha = f_alpha; @@ -1667,6 +1681,16 @@ AgsImVec4* AgsImGuiStyle_GetColors(AgsImGuiStyle* self, int i){ // -- end AgsImGuiStyle +AgsImGuiStyle* AgsImGui_GetStyle(){ + ImGuiStyle &imGuiStyle = ImGui::GetStyle(); + return NewAgsImGuiStyle(imGuiStyle); +} + +void AgsImGui_SetStyle(AgsImGuiStyle* agsImGuiStyle){ + ImGuiStyle &imGuiStyle = ImGui::GetStyle(); + SetAgsImGuiStyle(imGuiStyle, agsImGuiStyle); +} + void AgsImGui_NewFrame(){ if (!screen.initialized) return; @@ -2532,6 +2556,9 @@ int AgsImGuiHelper_GetClipboarImage() { engine->RegisterScriptFunction("ImGuiStyle::seti_Colors", (void*)AgsImGuiStyle_SetColors); engine->RegisterScriptFunction("ImGuiStyle::geti_Colors", (void*)AgsImGuiStyle_GetColors); + engine->RegisterScriptFunction("AgsImGui::get_Style", (void*)AgsImGui_GetStyle); + engine->RegisterScriptFunction("AgsImGui::set_Style", (void*)AgsImGui_SetStyle); + engine->RegisterScriptFunction("AgsImGui::NewFrame^0", (void*)AgsImGui_NewFrame); engine->RegisterScriptFunction("AgsImGui::EndFrame^0", (void*)AgsImGui_EndFrame); engine->RegisterScriptFunction("AgsImGui::Render^0", (void*)AgsImGui_Render); From 78a57a0767a668e26913567bdcd7908815547450 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 22:13:07 -0300 Subject: [PATCH 13/16] fixes header to account 2 extra parameters in ImVec4 Create and adds optionals --- agsimgui/agsimgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index 9de2f3c..effbeef 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -412,7 +412,7 @@ namespace agsimgui { "builtin managed struct ImVec4 { \r\n" " \r\n" " /// Creates a ImVec4 with float X and Y coordinates. \r\n" -" import static ImVec4* Create(float x, float y); // $AUTOCOMPLETESTATICONLY$ \r\n" +" import static ImVec4* Create(float x=0, float y=0, float z=0, float w=0); // $AUTOCOMPLETESTATICONLY$ \r\n" " \r\n" " /// Float X coordinate of the ImVec4. \r\n" " import attribute float X; \r\n" @@ -446,7 +446,7 @@ namespace agsimgui { "builtin managed struct ImVec2 { \r\n" " \r\n" " /// Creates a ImVec2 with float X and Y coordinates. \r\n" -" import static ImVec2* Create(float x, float y); // $AUTOCOMPLETESTATICONLY$ \r\n" +" import static ImVec2* Create(float x=0, float y=0); // $AUTOCOMPLETESTATICONLY$ \r\n" " \r\n" " /// Float X coordinate of the ImVec2. \r\n" " import attribute float X; \r\n" From ccdcda12368a088648d42a3700acfb3379d46691 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sat, 6 Jun 2020 22:25:03 -0300 Subject: [PATCH 14/16] modifies for a seter and a getter function --- agsimgui/agsimgui.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index effbeef..5b53663 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -590,8 +590,11 @@ namespace agsimgui { " \r\n" "builtin managed struct AgsImGui{ \r\n" " \r\n" -" /// Gets or Sets the Style customization use in AgsImGui \r\n" -" import static attribute ImGuiStyle* Style; \r\n" +" /// Gets the Style customization use in AgsImGui \r\n" +" import static ImGuiStyle* GetStyle(); \r\n" +" \r\n" +" /// Sets the Style customization use in AgsImGui \r\n" +" import static void SetStyle(ImGuiStyle* imGuiStyle); \r\n" " \r\n" " // Main \r\n" " \r\n" @@ -2556,8 +2559,8 @@ int AgsImGuiHelper_GetClipboarImage() { engine->RegisterScriptFunction("ImGuiStyle::seti_Colors", (void*)AgsImGuiStyle_SetColors); engine->RegisterScriptFunction("ImGuiStyle::geti_Colors", (void*)AgsImGuiStyle_GetColors); - engine->RegisterScriptFunction("AgsImGui::get_Style", (void*)AgsImGui_GetStyle); - engine->RegisterScriptFunction("AgsImGui::set_Style", (void*)AgsImGui_SetStyle); + engine->RegisterScriptFunction("AgsImGui::GetStyle^0", (void*)AgsImGui_GetStyle); + engine->RegisterScriptFunction("AgsImGui::SetStyle^1", (void*)AgsImGui_SetStyle); engine->RegisterScriptFunction("AgsImGui::NewFrame^0", (void*)AgsImGui_NewFrame); engine->RegisterScriptFunction("AgsImGui::EndFrame^0", (void*)AgsImGui_EndFrame); From deb5cfa9ea316dc3a74e80feef1496b4097feb10 Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sun, 7 Jun 2020 00:28:01 -0300 Subject: [PATCH 15/16] adds serialization and deserialization of AgsImGuiStyle class --- agsimgui/AgsImGuiStyle.cpp | 159 ++++++++++++++++++++++++++++++++++++- agsimgui/SerialHelper.cpp | 43 ++++++++++ agsimgui/SerialHelper.h | 7 ++ 3 files changed, 207 insertions(+), 2 deletions(-) diff --git a/agsimgui/AgsImGuiStyle.cpp b/agsimgui/AgsImGuiStyle.cpp index b18ac28..810be72 100644 --- a/agsimgui/AgsImGuiStyle.cpp +++ b/agsimgui/AgsImGuiStyle.cpp @@ -77,6 +77,46 @@ int AgsImGuiStyleInterface::Serialize(const char* address, char* buffer, int buf char* ptr = buffer; char* end = buffer + bufsize; + ptr = FloatToChar(agsImGuiStyle->Alpha, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->WindowPadding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->WindowRounding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->WindowBorderSize, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->WindowMinSize, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->WindowTitleAlign, ptr, end); + ptr = IntToChar(agsImGuiStyle->WindowMenuButtonPosition, ptr, end); + ptr = FloatToChar(agsImGuiStyle->ChildRounding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->ChildBorderSize, ptr, end); + ptr = FloatToChar(agsImGuiStyle->PopupRounding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->PopupBorderSize, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->FramePadding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->FrameRounding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->FrameBorderSize, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->ItemSpacing, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->ItemInnerSpacing, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->TouchExtraPadding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->IndentSpacing, ptr, end); + ptr = FloatToChar(agsImGuiStyle->ColumnsMinSpacing, ptr, end); + ptr = FloatToChar(agsImGuiStyle->ScrollbarSize, ptr, end); + ptr = FloatToChar(agsImGuiStyle->ScrollbarRounding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->GrabMinSize, ptr, end); + ptr = FloatToChar(agsImGuiStyle->GrabRounding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->TabRounding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->TabBorderSize, ptr, end); + ptr = FloatToChar(agsImGuiStyle->TabMinWidthForUnselectedCloseButton, ptr, end); + ptr = IntToChar(agsImGuiStyle->ColorButtonPosition, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->ButtonTextAlign, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->SelectableTextAlign, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->DisplayWindowPadding, ptr, end); + ptr = ImVec2ToChar(agsImGuiStyle->DisplaySafeAreaPadding, ptr, end); + ptr = FloatToChar(agsImGuiStyle->MouseCursorScale, ptr, end); + ptr = BoolToChar(agsImGuiStyle->AntiAliasedLines, ptr, end); + ptr = BoolToChar(agsImGuiStyle->AntiAliasedFill, ptr, end); + ptr = FloatToChar(agsImGuiStyle->CurveTessellationTol, ptr, end); + ptr = FloatToChar(agsImGuiStyle->CircleSegmentMaxError, ptr, end); + + for(int i=0; iColors[i], ptr, end); + } return (ptr - buffer); } @@ -87,11 +127,126 @@ void AgsImGuiStyleReader::Unserialize(int key, const char* serializedData, int d { char* ptr = (char*) serializedData; - float val_x; - float val_y; + float _Alpha; + ImVec2 _WindowPadding; + float _WindowRounding; + float _WindowBorderSize; + ImVec2 _WindowMinSize; + ImVec2 _WindowTitleAlign; + int _WindowMenuButtonPosition; + float _ChildRounding; + float _ChildBorderSize; + float _PopupRounding; + float _PopupBorderSize; + ImVec2 _FramePadding; + float _FrameRounding; + float _FrameBorderSize; + ImVec2 _ItemSpacing; + ImVec2 _ItemInnerSpacing; + ImVec2 _TouchExtraPadding; + float _IndentSpacing; + float _ColumnsMinSpacing; + float _ScrollbarSize; + float _ScrollbarRounding; + float _GrabMinSize; + float _GrabRounding; + float _TabRounding; + float _TabBorderSize; + float _TabMinWidthForUnselectedCloseButton; + int _ColorButtonPosition; + ImVec2 _ButtonTextAlign; + ImVec2 _SelectableTextAlign; + ImVec2 _DisplayWindowPadding; + ImVec2 _DisplaySafeAreaPadding; + float _MouseCursorScale; + bool _AntiAliasedLines; + bool _AntiAliasedFill; + float _CurveTessellationTol; + float _CircleSegmentMaxError; + ImVec4 _Colors[ImGuiCol_COUNT]; + + ptr = CharToFloat( _Alpha, ptr); + ptr = CharToImVec2( _WindowPadding, ptr); + ptr = CharToFloat( _WindowRounding, ptr); + ptr = CharToFloat( _WindowBorderSize, ptr); + ptr = CharToImVec2( _WindowMinSize, ptr); + ptr = CharToImVec2( _WindowTitleAlign, ptr); + ptr = CharToInt( _WindowMenuButtonPosition, ptr); + ptr = CharToFloat( _ChildRounding, ptr); + ptr = CharToFloat( _ChildBorderSize, ptr); + ptr = CharToFloat( _PopupRounding, ptr); + ptr = CharToFloat( _PopupBorderSize, ptr); + ptr = CharToImVec2( _FramePadding, ptr); + ptr = CharToFloat( _FrameRounding, ptr); + ptr = CharToFloat( _FrameBorderSize, ptr); + ptr = CharToImVec2( _ItemSpacing, ptr); + ptr = CharToImVec2( _ItemInnerSpacing, ptr); + ptr = CharToImVec2( _TouchExtraPadding, ptr); + ptr = CharToFloat( _IndentSpacing, ptr); + ptr = CharToFloat( _ColumnsMinSpacing, ptr); + ptr = CharToFloat( _ScrollbarSize, ptr); + ptr = CharToFloat( _ScrollbarRounding, ptr); + ptr = CharToFloat( _GrabMinSize, ptr); + ptr = CharToFloat( _GrabRounding, ptr); + ptr = CharToFloat( _TabRounding, ptr); + ptr = CharToFloat( _TabBorderSize, ptr); + ptr = CharToFloat( _TabMinWidthForUnselectedCloseButton, ptr); + ptr = CharToInt( _ColorButtonPosition, ptr); + ptr = CharToImVec2( _ButtonTextAlign, ptr); + ptr = CharToImVec2( _SelectableTextAlign, ptr); + ptr = CharToImVec2( _DisplayWindowPadding, ptr); + ptr = CharToImVec2( _DisplaySafeAreaPadding, ptr); + ptr = CharToFloat( _MouseCursorScale, ptr); + ptr = CharToBool(_AntiAliasedLines, ptr); + ptr = CharToBool(_AntiAliasedFill, ptr); + ptr = CharToFloat( _CurveTessellationTol, ptr); + ptr = CharToFloat( _CircleSegmentMaxError, ptr); + for(int i=0; iAlpha = _Alpha; + agsImGuiStyle->WindowPadding = _WindowPadding; + agsImGuiStyle->WindowRounding = _WindowRounding; + agsImGuiStyle->WindowBorderSize = _WindowBorderSize; + agsImGuiStyle->WindowMinSize = _WindowMinSize; + agsImGuiStyle->WindowTitleAlign = _WindowTitleAlign; + agsImGuiStyle->WindowMenuButtonPosition = _WindowMenuButtonPosition; + agsImGuiStyle->ChildRounding = _ChildRounding; + agsImGuiStyle->ChildBorderSize = _ChildBorderSize; + agsImGuiStyle->PopupRounding = _PopupRounding; + agsImGuiStyle->PopupBorderSize = _PopupBorderSize; + agsImGuiStyle->FramePadding = _FramePadding; + agsImGuiStyle->FrameRounding = _FrameRounding; + agsImGuiStyle->FrameBorderSize = _FrameBorderSize; + agsImGuiStyle->ItemSpacing = _ItemSpacing; + agsImGuiStyle->ItemInnerSpacing = _ItemInnerSpacing; + agsImGuiStyle->TouchExtraPadding = _TouchExtraPadding; + agsImGuiStyle->IndentSpacing = _IndentSpacing; + agsImGuiStyle->ColumnsMinSpacing = _ColumnsMinSpacing; + agsImGuiStyle->ScrollbarSize = _ScrollbarSize; + agsImGuiStyle->ScrollbarRounding = _ScrollbarRounding; + agsImGuiStyle->GrabMinSize = _GrabMinSize; + agsImGuiStyle->GrabRounding = _GrabRounding; + agsImGuiStyle->TabRounding = _TabRounding; + agsImGuiStyle->TabBorderSize = _TabBorderSize; + agsImGuiStyle->TabMinWidthForUnselectedCloseButton = _TabMinWidthForUnselectedCloseButton; + agsImGuiStyle->ColorButtonPosition = _ColorButtonPosition; + agsImGuiStyle->ButtonTextAlign = _ButtonTextAlign; + agsImGuiStyle->SelectableTextAlign = _SelectableTextAlign; + agsImGuiStyle->DisplayWindowPadding = _DisplayWindowPadding; + agsImGuiStyle->DisplaySafeAreaPadding = _DisplaySafeAreaPadding; + agsImGuiStyle->MouseCursorScale = _MouseCursorScale; + agsImGuiStyle->AntiAliasedLines = _AntiAliasedLines; + agsImGuiStyle->AntiAliasedFill = _AntiAliasedFill; + agsImGuiStyle->CurveTessellationTol = _CurveTessellationTol; + agsImGuiStyle->CircleSegmentMaxError = _CircleSegmentMaxError; + + for(int i=0; iColors[i] = _Colors[i]; + } engine->RegisterUnserializedObject(key, agsImGuiStyle, &AgsImGuiStyle_Interface); } diff --git a/agsimgui/SerialHelper.cpp b/agsimgui/SerialHelper.cpp index 9006cea..432c453 100644 --- a/agsimgui/SerialHelper.cpp +++ b/agsimgui/SerialHelper.cpp @@ -7,6 +7,7 @@ #include "SerialHelper.h" #include +#include "imgui/imgui.h" namespace SerialHelper { @@ -31,11 +32,53 @@ namespace SerialHelper { return buf + sizeof(float); } + char* ImVec2ToChar(ImVec2 imVec2, char * buf, char* end) { + assert(buf + 2*sizeof(float) < end); + + buf = FloatToChar(imVec2.x, buf, end); + buf = FloatToChar(imVec2.y, buf, end); + + return buf; + } + + char* ImVec4ToChar(ImVec4 imVec4, char * buf, char* end) { + assert(buf + 4*sizeof(float) < end); + + buf = FloatToChar(imVec4.x, buf, end); + buf = FloatToChar(imVec4.y, buf, end); + buf = FloatToChar(imVec4.z, buf, end); + buf = FloatToChar(imVec4.w, buf, end); + + return buf; + } + char* CharToFloat(float &f, char * buf) { f = *((float*)buf); return buf + sizeof(float); } + char* CharToImVec2(ImVec2 &imVec2, char * buf) { + float _x, _y; + buf = CharToFloat(_x, buf); + buf = CharToFloat(_y, buf); + imVec2.x = _x; + imVec2.y = _y; + return buf; + } + + char* CharToImVec4(ImVec4 &imVec4, char * buf) { + float _x, _y, _z, _w; + buf = CharToFloat(_x, buf); + buf = CharToFloat(_y, buf); + buf = CharToFloat(_z, buf); + buf = CharToFloat(_w, buf); + imVec4.x = _x; + imVec4.y = _y; + imVec4.z = _z; + imVec4.w = _w; + return buf; + } + char* BoolToChar(bool b, char* buf, char* end) { assert(buf + sizeof(char) < end); diff --git a/agsimgui/SerialHelper.h b/agsimgui/SerialHelper.h index 32f257e..e6f741b 100644 --- a/agsimgui/SerialHelper.h +++ b/agsimgui/SerialHelper.h @@ -10,6 +10,8 @@ #ifndef AGSBOX2D_SERIALHELPER_H #define AGSBOX2D_SERIALHELPER_H +#include "imgui/imgui.h" + namespace SerialHelper { union u_cf @@ -31,6 +33,11 @@ namespace SerialHelper { char* CharToInt(int &i, char * buf); char* CharToFloat(float &f, char * buf); char* CharToBool(bool &b, char* buf); + + char* ImVec2ToChar(ImVec2 imVec2, char * buf, char* end); + char* ImVec4ToChar(ImVec4 imVec4, char * buf, char* end); + char* CharToImVec2(ImVec2 &imVec2, char * buf); + char* CharToImVec4(ImVec4 &imVec4, char * buf); } #endif /* AGSBOX2D_SERIALHELPER_H */ \ No newline at end of file From b59505ac07ec4dc84dcee942ec21e46981fbe1eb Mon Sep 17 00:00:00 2001 From: ericoporto Date: Sun, 7 Jun 2020 01:34:17 -0300 Subject: [PATCH 16/16] ImGui style is now serialized and deserialized in the save file --- agsimgui/AgsImGuiStyle.cpp | 1 + agsimgui/agsimgui.cpp | 268 ++++++++++++++++++++++++++++++++++++- 2 files changed, 262 insertions(+), 7 deletions(-) diff --git a/agsimgui/AgsImGuiStyle.cpp b/agsimgui/AgsImGuiStyle.cpp index 810be72..343584e 100644 --- a/agsimgui/AgsImGuiStyle.cpp +++ b/agsimgui/AgsImGuiStyle.cpp @@ -248,6 +248,7 @@ void AgsImGuiStyleReader::Unserialize(int key, const char* serializedData, int d agsImGuiStyle->Colors[i] = _Colors[i]; } + agsImGuiStyle->id = key; engine->RegisterUnserializedObject(key, agsImGuiStyle, &AgsImGuiStyle_Interface); } diff --git a/agsimgui/agsimgui.cpp b/agsimgui/agsimgui.cpp index 5b53663..0e3a407 100644 --- a/agsimgui/agsimgui.cpp +++ b/agsimgui/agsimgui.cpp @@ -83,6 +83,10 @@ namespace agsimgui { } #endif +const unsigned int Magic = 0xCAFE0000; +const unsigned int Version = 3; +const unsigned int SaveMagic = Magic + Version; + //define engine IAGSEngine *engine; @@ -2686,6 +2690,8 @@ int AgsImGuiHelper_GetClipboarImage() { engine->RequestEventHook(AGSE_KEYPRESS); engine->RequestEventHook(AGSE_POSTSCREENDRAW); engine->RequestEventHook(AGSE_MOUSECLICK); + engine->RequestEventHook(AGSE_SAVEGAME); + engine->RequestEventHook(AGSE_RESTOREGAME); } //------------------------------------------------------------------------------ @@ -2708,6 +2714,247 @@ int AgsImGuiHelper_GetClipboarImage() { //------------------------------------------------------------------------------ +static size_t engineFileRead(void * ptr, size_t size, size_t count, long fileHandle) { + auto totalBytes = engine->FRead(ptr, size*count, fileHandle); + return totalBytes/size; +} + +static size_t engineFileWrite(const void *ptr, size_t size, size_t count, long fileHandle) { + auto totalBytes = engine->FWrite(const_cast(ptr), size*count, fileHandle); + return totalBytes/size; +} + +void EngineReadFloat(float &f, long fileHandle){ + engine->FRead(&f, sizeof(float), fileHandle); +} + +void EngineWriteFloat(float &f, long fileHandle){ + engine->FWrite(&f, sizeof(float), fileHandle); +} + +void EngineReadInt(int &i, long fileHandle){ + engine->FRead(&i, sizeof(int), fileHandle); +} + +void EngineWriteInt(int &i, long fileHandle){ + engine->FWrite(&i, sizeof(int), fileHandle); +} + +void EngineReadBool(bool &b, long fileHandle){ + engine->FRead(&b, sizeof(bool), fileHandle); +} + +void EngineWriteBool(bool &b, long fileHandle){ + engine->FWrite(&b, sizeof(bool), fileHandle); +} + +void EngineReadImVec2(ImVec2 &imVec2, long fileHandle){ + EngineReadFloat(imVec2.x, fileHandle); + EngineReadFloat(imVec2.y, fileHandle); +} + +void EngineWriteImVec2(ImVec2 &imVec2, long fileHandle){ + EngineWriteFloat(imVec2.x, fileHandle); + EngineWriteFloat(imVec2.y, fileHandle); +} + +void EngineReadImVec4(ImVec4 &imVec4, long fileHandle){ + EngineReadFloat(imVec4.x, fileHandle); + EngineReadFloat(imVec4.y, fileHandle); + EngineReadFloat(imVec4.z, fileHandle); + EngineReadFloat(imVec4.w, fileHandle); +} + +void EngineWriteImVec4(ImVec4 &imVec4, long fileHandle){ + EngineWriteFloat(imVec4.x, fileHandle); + EngineWriteFloat(imVec4.y, fileHandle); + EngineWriteFloat(imVec4.z, fileHandle); + EngineWriteFloat(imVec4.w, fileHandle); +} + + +void RestoreGame(long fileHandle) +{ + unsigned int SaveVersion = 0; + engineFileRead(&SaveVersion, sizeof(SaveVersion), 1, fileHandle); + + if (SaveVersion != SaveMagic) { + engine->AbortGame("agsimgui: bad save."); + } + + ImGuiStyle &imGuiStyle = ImGui::GetStyle(); + + float _Alpha; + ImVec2 _WindowPadding; + float _WindowRounding; + float _WindowBorderSize; + ImVec2 _WindowMinSize; + ImVec2 _WindowTitleAlign; + int _WindowMenuButtonPosition; + float _ChildRounding; + float _ChildBorderSize; + float _PopupRounding; + float _PopupBorderSize; + ImVec2 _FramePadding; + float _FrameRounding; + float _FrameBorderSize; + ImVec2 _ItemSpacing; + ImVec2 _ItemInnerSpacing; + ImVec2 _TouchExtraPadding; + float _IndentSpacing; + float _ColumnsMinSpacing; + float _ScrollbarSize; + float _ScrollbarRounding; + float _GrabMinSize; + float _GrabRounding; + float _TabRounding; + float _TabBorderSize; + float _TabMinWidthForUnselectedCloseButton; + int _ColorButtonPosition; + ImVec2 _ButtonTextAlign; + ImVec2 _SelectableTextAlign; + ImVec2 _DisplayWindowPadding; + ImVec2 _DisplaySafeAreaPadding; + float _MouseCursorScale; + bool _AntiAliasedLines; + bool _AntiAliasedFill; + float _CurveTessellationTol; + float _CircleSegmentMaxError; + ImVec4 _Colors[ImGuiCol_COUNT]; + + EngineReadFloat( _Alpha, fileHandle); + EngineReadImVec2( _WindowPadding, fileHandle); + EngineReadFloat( _WindowRounding, fileHandle); + EngineReadFloat( _WindowBorderSize, fileHandle); + EngineReadImVec2( _WindowMinSize, fileHandle); + EngineReadImVec2( _WindowTitleAlign, fileHandle); + EngineReadInt( _WindowMenuButtonPosition, fileHandle); + EngineReadFloat( _ChildRounding, fileHandle); + EngineReadFloat( _ChildBorderSize, fileHandle); + EngineReadFloat( _PopupRounding, fileHandle); + EngineReadFloat( _PopupBorderSize, fileHandle); + EngineReadImVec2( _FramePadding, fileHandle); + EngineReadFloat( _FrameRounding, fileHandle); + EngineReadFloat( _FrameBorderSize, fileHandle); + EngineReadImVec2( _ItemSpacing, fileHandle); + EngineReadImVec2( _ItemInnerSpacing, fileHandle); + EngineReadImVec2( _TouchExtraPadding, fileHandle); + EngineReadFloat( _IndentSpacing, fileHandle); + EngineReadFloat( _ColumnsMinSpacing, fileHandle); + EngineReadFloat( _ScrollbarSize, fileHandle); + EngineReadFloat( _ScrollbarRounding, fileHandle); + EngineReadFloat( _GrabMinSize, fileHandle); + EngineReadFloat( _GrabRounding, fileHandle); + EngineReadFloat( _TabRounding, fileHandle); + EngineReadFloat( _TabBorderSize, fileHandle); + EngineReadFloat( _TabMinWidthForUnselectedCloseButton, fileHandle); + EngineReadInt( _ColorButtonPosition, fileHandle); + EngineReadImVec2( _ButtonTextAlign, fileHandle); + EngineReadImVec2( _SelectableTextAlign, fileHandle); + EngineReadImVec2( _DisplayWindowPadding, fileHandle); + EngineReadImVec2( _DisplaySafeAreaPadding, fileHandle); + EngineReadFloat( _MouseCursorScale, fileHandle); + EngineReadBool(_AntiAliasedLines, fileHandle); + EngineReadBool(_AntiAliasedFill, fileHandle); + EngineReadFloat( _CurveTessellationTol, fileHandle); + EngineReadFloat( _CircleSegmentMaxError, fileHandle); + + for(int i=0; i