├── C-DS ├── Resources │ ├── DSU.png │ ├── mob.png │ ├── C-DS.png │ ├── deque.png │ ├── graphs.png │ ├── grids.png │ ├── icon.png │ ├── queue.png │ ├── stack.png │ ├── trie.png │ ├── vector.png │ ├── LogoDark.png │ ├── hash_map.png │ ├── logoFont.ttf │ ├── mainFont.ttf │ ├── LogoLight.png │ ├── hash_table.png │ ├── linked_list.png │ ├── mainFont-bold.ttf │ ├── sparce_table.png │ └── mainFont-italic.ttf ├── C-DS.vcxproj.user ├── Image.h ├── TextArea.h ├── DockingArea.h ├── Settings.h ├── CodeVisualizer.h ├── Markdown.h ├── DockingArea.cpp ├── main.cpp ├── TextArea.cpp ├── GrandWindow.h ├── imgui.ini ├── GrandWindow.cpp ├── Image.cpp ├── QueueVisualization.h ├── App.h ├── Vector.h ├── Stack.h ├── SparseTable.h ├── Segment_Tree.h ├── Tree.h ├── Segment_Tree.cpp ├── LinkedList.h ├── MainMenu.h ├── Deque.h ├── Trie.h ├── CodeVisualizer.cpp ├── DSU.h ├── HashTable.h ├── HashMap.h ├── Grid.h ├── GraphTools.h ├── SparseTable.cpp ├── Markdown.cpp ├── C-DS.vcxproj.filters ├── MainMenu.cpp ├── Tree.cpp ├── Stack.cpp ├── QueueVisualization.cpp ├── C-DS.vcxproj ├── App.cpp ├── Vector.cpp └── Settings.cpp ├── glfw ├── lib-vc2010-32 │ └── glfw3.lib └── lib-vc2010-64 │ └── glfw3.lib ├── imgui ├── LICENSE.txt ├── imgui_impl_opengl3.h ├── imgui_impl_glfw.h └── imconfig.h ├── C-DS.sln ├── .gitattributes ├── README.md └── .gitignore /C-DS/Resources/DSU.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/DSU.png -------------------------------------------------------------------------------- /C-DS/Resources/mob.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/mob.png -------------------------------------------------------------------------------- /C-DS/Resources/C-DS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/C-DS.png -------------------------------------------------------------------------------- /C-DS/Resources/deque.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/deque.png -------------------------------------------------------------------------------- /C-DS/Resources/graphs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/graphs.png -------------------------------------------------------------------------------- /C-DS/Resources/grids.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/grids.png -------------------------------------------------------------------------------- /C-DS/Resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/icon.png -------------------------------------------------------------------------------- /C-DS/Resources/queue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/queue.png -------------------------------------------------------------------------------- /C-DS/Resources/stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/stack.png -------------------------------------------------------------------------------- /C-DS/Resources/trie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/trie.png -------------------------------------------------------------------------------- /C-DS/Resources/vector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/vector.png -------------------------------------------------------------------------------- /C-DS/Resources/LogoDark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/LogoDark.png -------------------------------------------------------------------------------- /C-DS/Resources/hash_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/hash_map.png -------------------------------------------------------------------------------- /C-DS/Resources/logoFont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/logoFont.ttf -------------------------------------------------------------------------------- /C-DS/Resources/mainFont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/mainFont.ttf -------------------------------------------------------------------------------- /C-DS/Resources/LogoLight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/LogoLight.png -------------------------------------------------------------------------------- /C-DS/Resources/hash_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/hash_table.png -------------------------------------------------------------------------------- /C-DS/Resources/linked_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/linked_list.png -------------------------------------------------------------------------------- /glfw/lib-vc2010-32/glfw3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/glfw/lib-vc2010-32/glfw3.lib -------------------------------------------------------------------------------- /glfw/lib-vc2010-64/glfw3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/glfw/lib-vc2010-64/glfw3.lib -------------------------------------------------------------------------------- /C-DS/Resources/mainFont-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/mainFont-bold.ttf -------------------------------------------------------------------------------- /C-DS/Resources/sparce_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/sparce_table.png -------------------------------------------------------------------------------- /C-DS/Resources/mainFont-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WisdomCasual/C-DS/HEAD/C-DS/Resources/mainFont-italic.ttf -------------------------------------------------------------------------------- /C-DS/C-DS.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | 6 | -------------------------------------------------------------------------------- /C-DS/Image.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define GL_SILENCE_DEPRECATION 3 | #if defined(IMGUI_IMPL_OPENGL_ES2) 4 | #include 5 | #endif 6 | #include 7 | 8 | 9 | namespace image_imp { 10 | 11 | bool loadImage(const char*, GLuint*, int*, int*); 12 | void SetWindowIcon(GLFWwindow*, const char*); 13 | 14 | } 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /C-DS/TextArea.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imgui.h" 3 | #include 4 | #include 5 | 6 | class TextArea 7 | { 8 | // private fields: 9 | ImGuiWindowClass window_class; 10 | const std::string name; 11 | 12 | public: 13 | 14 | TextArea(std::string); 15 | ~TextArea(); 16 | 17 | // public methods: 18 | void update(); 19 | const std::string getName(); 20 | 21 | }; -------------------------------------------------------------------------------- /C-DS/DockingArea.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imgui.h" 3 | #include 4 | #include 5 | 6 | class DockingArea 7 | { 8 | private: 9 | // private fields: 10 | ImGuiWindowClass window_class; 11 | const std::string name; 12 | 13 | public: 14 | 15 | DockingArea(std::string); 16 | ~DockingArea(); 17 | 18 | // public methods: 19 | void update(); 20 | const std::string getName(); 21 | 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /C-DS/Settings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | 5 | class Settings : 6 | public GrandWindow 7 | { 8 | // private fields: 9 | ImGuiStyle* style; 10 | bool initialized = false, debuggingSettings = false; 11 | 12 | public: 13 | 14 | Settings(std::string, int&, float&, bool&, int&); 15 | ~Settings(); 16 | 17 | // public methods: 18 | void update(); 19 | 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /C-DS/CodeVisualizer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | 6 | #include "DockingArea.h" 7 | #include "TextArea.h" 8 | 9 | class CodeVisualizer : 10 | public GrandWindow 11 | { 12 | private: 13 | // private fields: 14 | DockingArea* docking_area; 15 | TextArea* text_area; 16 | 17 | // private methods: 18 | void updateMenuBar(); 19 | 20 | public: 21 | 22 | CodeVisualizer(std::string, int&, float&, bool&, int&); 23 | ~CodeVisualizer(); 24 | 25 | // public methods: 26 | void update(); 27 | 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /C-DS/Markdown.h: -------------------------------------------------------------------------------- 1 | #include "ImGui.h" // https://github.com/ocornut/imgui 2 | #include "imgui_markdown.h" // https://github.com/juliettef/imgui_markdown 3 | //#include "IconsFontAwesome5.h" // https://github.com/juliettef/IconFontCppHeaders 4 | 5 | #include 6 | 7 | void LinkCallback(ImGui::MarkdownLinkCallbackData data_); 8 | 9 | ImGui::MarkdownImageData ImageCallback(ImGui::MarkdownLinkCallbackData data_); 10 | 11 | void LinkCallback(ImGui::MarkdownLinkCallbackData data_); 12 | 13 | void LoadFonts(float fontSize_); 14 | 15 | void MarkdownFormatCallback(const ImGui::MarkdownFormatInfo& markdownFormatInfo_, bool start_); 16 | 17 | void Markdown(const std::string& markdown_); 18 | 19 | void clearCachedImages(); -------------------------------------------------------------------------------- /C-DS/DockingArea.cpp: -------------------------------------------------------------------------------- 1 | #include "DockingArea.h" 2 | 3 | DockingArea::DockingArea(std::string name) 4 | : name(name) 5 | { 6 | window_class.DockNodeFlagsOverrideSet = ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_NoDockingOverMe | ImGuiDockNodeFlags_NoDockingOverOther | ImGuiDockNodeFlags_NoDockingSplitOther; 7 | } 8 | 9 | DockingArea::~DockingArea() 10 | { 11 | 12 | } 13 | 14 | void DockingArea::update() 15 | { 16 | ImGui::SetNextWindowClass(&window_class); 17 | ImGui::Begin(name.c_str(), NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar); 18 | ImGuiID dockSpace = ImGui::GetID("dockSpace"); 19 | ImGui::DockSpace(dockSpace); 20 | ImGui::End(); 21 | } 22 | 23 | const std::string DockingArea::getName() 24 | { 25 | return name; 26 | } 27 | -------------------------------------------------------------------------------- /C-DS/main.cpp: -------------------------------------------------------------------------------- 1 | #include "App.h" 2 | 3 | App *app; 4 | 5 | static void glfw_error_callback(int error, const char* description) 6 | { 7 | fprintf(stderr, "GLFW Error %d: %s\n", error, description); 8 | } 9 | 10 | void framebuffer_size_callback(GLFWwindow* window, int width, int height) 11 | { 12 | glViewport(0, 0, width, height); 13 | } 14 | 15 | void window_refresh_callback(GLFWwindow* window) 16 | { 17 | app->update(); 18 | app->render(); 19 | glFinish(); 20 | } 21 | 22 | int main() { 23 | glfwSetErrorCallback(glfw_error_callback); 24 | if (!glfwInit()) 25 | exit(1); 26 | app = new App("C-DS"); 27 | 28 | glfwSetWindowRefreshCallback(app->getWindow(), window_refresh_callback); 29 | glfwSetFramebufferSizeCallback(app->getWindow(), framebuffer_size_callback); 30 | 31 | app->run(); 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C-DS/TextArea.cpp: -------------------------------------------------------------------------------- 1 | #include "TextArea.h" 2 | 3 | TextArea::TextArea(std::string name) 4 | : name(name) 5 | { 6 | window_class.DockNodeFlagsOverrideSet = ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_NoDocking; 7 | } 8 | 9 | TextArea::~TextArea() 10 | { 11 | 12 | } 13 | 14 | void TextArea::update() 15 | { 16 | ImGui::SetNextWindowClass(&window_class); 17 | ImGui::Begin(name.c_str(), NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar); 18 | 19 | if (ImGui::Button("Run")) { 20 | 21 | } 22 | 23 | ImGui::SameLine(); 24 | ImGui::Text("Text 2"); 25 | static char text[int(1e4)]; 26 | ImGui::InputTextMultiline("IDE", text, IM_ARRAYSIZE(text), ImVec2(-FLT_MIN, -FLT_MIN)); 27 | 28 | ImGui::End(); 29 | } 30 | 31 | const std::string TextArea::getName() 32 | { 33 | return name; 34 | } 35 | -------------------------------------------------------------------------------- /imgui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2024 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /C-DS/GrandWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | 6 | class GrandWindow 7 | { 8 | private: 9 | 10 | std::string name; 11 | bool autoZooming = false; 12 | float targetZoom = 1.0f; 13 | 14 | protected: 15 | 16 | int& state; 17 | float& GuiScale; 18 | float zoomScale = 1.0f; 19 | bool& settingsEnabled; 20 | int& colorMode; 21 | float center_x_percent = 0.5f, center_y_percent = 0.5f; 22 | ImVec2 camPos = { 0.0f, 1000.f * GuiScale }, camTarget = { 0.0f, 0.0f }; 23 | ImVec2 center = { 0, 0 }; 24 | 25 | const ImGuiViewport* viewport = ImGui::GetMainViewport(); 26 | const ImGuiIO* io = &ImGui::GetIO(); 27 | 28 | GrandWindow(std::string name, int& state, float& GuiScale, bool& settingsEnabled, int& colorMode) : name(name), state(state), GuiScale(GuiScale), settingsEnabled(settingsEnabled), colorMode(colorMode){}; 29 | 30 | void drawWatermark(float opacity = 0.7f) const; 31 | void updateCam(float minZoomScale = 0.5f, float maxZoomScale = 3.0f); 32 | void autoZoom(float newZoom); 33 | void inline updateCenter() { 34 | // updates the center to the center of the current window 35 | center = ImVec2(ImGui::GetWindowPos().x + ImGui::GetWindowSize().x * center_x_percent, ImGui::GetWindowPos().y + ImGui::GetWindowSize().y * center_y_percent); 36 | }; 37 | 38 | public: 39 | 40 | virtual void update() = 0; 41 | 42 | const inline std::string getName() { return name; }; 43 | 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /C-DS.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34601.278 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "C-DS", "C-DS\C-DS.vcxproj", "{1A4DFB39-2234-48A4-B2E6-475E5D52D2A9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1A4DFB39-2234-48A4-B2E6-475E5D52D2A9}.Debug|x64.ActiveCfg = Debug|x64 17 | {1A4DFB39-2234-48A4-B2E6-475E5D52D2A9}.Debug|x64.Build.0 = Debug|x64 18 | {1A4DFB39-2234-48A4-B2E6-475E5D52D2A9}.Debug|x86.ActiveCfg = Debug|Win32 19 | {1A4DFB39-2234-48A4-B2E6-475E5D52D2A9}.Debug|x86.Build.0 = Debug|Win32 20 | {1A4DFB39-2234-48A4-B2E6-475E5D52D2A9}.Release|x64.ActiveCfg = Release|x64 21 | {1A4DFB39-2234-48A4-B2E6-475E5D52D2A9}.Release|x64.Build.0 = Release|x64 22 | {1A4DFB39-2234-48A4-B2E6-475E5D52D2A9}.Release|x86.ActiveCfg = Release|Win32 23 | {1A4DFB39-2234-48A4-B2E6-475E5D52D2A9}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {B4B9F2B5-0072-42FE-AA7F-F666DAC73291} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /C-DS/imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][Window_1] 2 | Pos=0,26 3 | Size=894,694 4 | Collapsed=0 5 | 6 | [Window][Window_2] 7 | Pos=896,26 8 | Size=384,694 9 | Collapsed=0 10 | 11 | [Window][DockSpaceViewport_11111111] 12 | Pos=0,36 13 | Size=1920,938 14 | Collapsed=0 15 | 16 | [Window][Debug##Default] 17 | Pos=213,150 18 | Size=400,400 19 | Collapsed=1 20 | 21 | [Window][Hello, world!] 22 | Pos=212,119 23 | Size=734,624 24 | Collapsed=0 25 | 26 | [Window][Dock_Area] 27 | Pos=0,26 28 | Size=630,544 29 | Collapsed=0 30 | 31 | [Window][IDE_Area] 32 | Pos=632,26 33 | Size=270,544 34 | Collapsed=0 35 | 36 | [Window][JOONYOU] 37 | Pos=8,375 38 | Size=514,337 39 | Collapsed=0 40 | DockId=0x00000003,0 41 | 42 | [Window][Docking_Area] 43 | Pos=0,36 44 | Size=1342,938 45 | Collapsed=0 46 | DockId=0x00000001 47 | 48 | [Window][Text_Area] 49 | Pos=1344,36 50 | Size=576,938 51 | Collapsed=0 52 | DockId=0x00000002 53 | 54 | [Window][Settings] 55 | Pos=96,111 56 | Size=758,1099 57 | Collapsed=0 58 | 59 | [Window][Graph_Tools] 60 | Pos=290,136 61 | Size=1432,885 62 | Collapsed=0 63 | 64 | [Window][Hash_Map] 65 | Size=1334,979 66 | Collapsed=0 67 | 68 | [Docking][Data] 69 | DockSpace ID=0x8B93E3BD Pos=0,36 Size=1920,938 Split=X 70 | DockNode ID=0x00000001 Parent=0x8B93E3BD SizeRef=1342,974 Selected=0xFA64D971 71 | DockNode ID=0x00000002 Parent=0x8B93E3BD SizeRef=576,974 Selected=0xAA3703AF 72 | DockSpace ID=0xD7F179FF Pos=8,34 Size=614,528 Split=X 73 | DockNode ID=0x00000003 Parent=0xD7F179FF SizeRef=514,678 Selected=0xD00C9CD4 74 | DockNode ID=0x00000004 Parent=0xD7F179FF SizeRef=139,678 CentralNode=1 Selected=0xD00C9CD4 75 | 76 | -------------------------------------------------------------------------------- /C-DS/GrandWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "GrandWindow.h" 2 | 3 | 4 | void GrandWindow::drawWatermark(float opacity) const { 5 | ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[5]); 6 | 7 | float shade = abs(colorMode - 0.8f); 8 | ImGui::TextColored(ImVec4(shade, shade, shade, opacity), "C-"); 9 | ImGui::SameLine(); 10 | ImGui::TextColored(ImVec4(0.3f, 0.6f, 1.0f, opacity), "DS"); 11 | ImGui::PopFont(); 12 | }; 13 | 14 | void GrandWindow::updateCam(float minZoomScale, float maxZoomScale) { 15 | 16 | updateCenter(); 17 | 18 | camPos.x += (camTarget.x - camPos.x) * 10.f * io->DeltaTime; 19 | camPos.y += (camTarget.y - camPos.y) * 10.f * io->DeltaTime; 20 | 21 | if (ImGui::IsWindowHovered() && io->MouseWheel != 0.0f) { 22 | targetZoom += io->MouseWheel * 0.15f; 23 | targetZoom = std::min(std::max(targetZoom, minZoomScale), maxZoomScale); 24 | autoZooming = false; 25 | } 26 | 27 | if (abs(zoomScale - targetZoom) <= 0.005f) return; 28 | 29 | if (!autoZooming) { 30 | camTarget.x -= (io->MousePos.x - center.x) / zoomScale; 31 | camTarget.y -= (io->MousePos.y - center.y) / zoomScale; 32 | camPos.x -= (io->MousePos.x - center.x) / zoomScale; 33 | camPos.y -= (io->MousePos.y - center.y) / zoomScale; 34 | } 35 | 36 | zoomScale += (targetZoom - zoomScale) * 10.f * io->DeltaTime; 37 | zoomScale = std::min(std::max(zoomScale, minZoomScale), maxZoomScale); 38 | 39 | if (!autoZooming) { 40 | camTarget.x += (io->MousePos.x - center.x) / zoomScale; 41 | camTarget.y += (io->MousePos.y - center.y) / zoomScale; 42 | camPos.x += (io->MousePos.x - center.x) / zoomScale; 43 | camPos.y += (io->MousePos.y - center.y) / zoomScale; 44 | } 45 | 46 | } 47 | 48 | void GrandWindow::autoZoom(float newZoom) { 49 | targetZoom = newZoom; 50 | autoZooming = true; 51 | camTarget = { 0, 0 }; 52 | }; -------------------------------------------------------------------------------- /C-DS/Image.cpp: -------------------------------------------------------------------------------- 1 | #include "Image.h" 2 | 3 | #define STB_IMAGE_IMPLEMENTATION 4 | #include "stb_image.h" 5 | #include 6 | 7 | bool image_imp::loadImage(const char* filename, GLuint* out_texture, int* out_width, int* out_height) { 8 | int width, height, channels; 9 | unsigned char* imageData = stbi_load(filename, &width, &height, &channels, 0); 10 | 11 | if (!imageData) { 12 | std::cout << "Failed to load image file: " << filename << '\n'; 13 | return false; 14 | } 15 | 16 | GLuint textureID; 17 | glGenTextures(1, &textureID); 18 | glBindTexture(GL_TEXTURE_2D, textureID); 19 | 20 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 21 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 22 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 23 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 24 | 25 | GLenum format = (channels == 3) ? GL_RGB : GL_RGBA; 26 | glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, imageData); 27 | 28 | stbi_image_free(imageData); 29 | 30 | *out_texture = textureID; 31 | if (out_width != NULL) 32 | *out_width = width; 33 | if (out_height != NULL) 34 | *out_height = height; 35 | return true; 36 | } 37 | 38 | void image_imp::SetWindowIcon(GLFWwindow* window, const char* iconPath) { 39 | int width, height, channels; 40 | unsigned char* data = stbi_load(iconPath, &width, &height, &channels, 0); 41 | if (data) { 42 | GLFWimage icon; 43 | icon.width = width; 44 | icon.height = height; 45 | icon.pixels = data; 46 | glfwSetWindowIcon(window, 1, &icon); 47 | stbi_image_free(data); 48 | } 49 | else { 50 | printf("Failed to load icon: %s\n", iconPath); 51 | } 52 | } -------------------------------------------------------------------------------- /C-DS/QueueVisualization.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | class QueueVisualization : public GrandWindow 7 | { 8 | private: 9 | 10 | const int MAX_SIZE = 1024; 11 | 12 | // speed constraints: 13 | const float MAX_SPEED = 10.0f; 14 | const float MIN_SPEED = 0.1f; 15 | const float DELAY_TIME = 0.2f; 16 | const float BASE_DELAY = 0.6f; 17 | 18 | const float QUEUE_ROUNDNESS = 10.f; 19 | const float CELL_SIZE = 70.f; 20 | const float SEPARATOR_SIZE = 5.f; 21 | 22 | enum { 23 | DEFAULT_CELL_COL, 24 | CELL_BORDER_COL, 25 | ARROW1_COL, 26 | ARROW2_COL, 27 | TEXT_COLOR, 28 | TEXT_OUTLINE_COL 29 | }; 30 | 31 | // private fields: 32 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 33 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 34 | 35 | 36 | 37 | 38 | int cur_tool = 0, sz = 0, tailpointer = 0, headpointer = 0, currentMaxSize = 1, expansion = -1, tempSize = 0; 39 | bool camfollow = false, movingCam = false; 40 | 41 | char add_element_content[200] = {}; 42 | float speed = 1.f, passedTime = 0.f; 43 | 44 | std::string* content = new std::string[currentMaxSize], *tempContent = nullptr; 45 | std::queue pending; 46 | 47 | void controlsUpdate(); 48 | void getInput(); 49 | ImU32 getColor(int); 50 | void drawText(ImVec2, const char*); 51 | void queueUpdate(); 52 | void drawQueue(int, std::string[], int, int, int); 53 | void drawArrow(int, int, int, bool); 54 | bool Enqueue(std::string); 55 | void Dequeue(); 56 | void expand(); 57 | 58 | public: 59 | QueueVisualization(std::string, int&, float&, bool&, int&); 60 | ~QueueVisualization(); 61 | void update(); 62 | 63 | }; -------------------------------------------------------------------------------- /C-DS/App.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imgui.h" 3 | #include "imgui_impl_glfw.h" 4 | #include "imgui_impl_opengl3.h" 5 | #define GL_SILENCE_DEPRECATION 6 | #if defined(IMGUI_IMPL_OPENGL_ES2) 7 | #include 8 | #endif 9 | #include 10 | 11 | #define IMGUI_ENABLE_FREETYPE 12 | 13 | #if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) 14 | #pragma comment(lib, "legacy_stdio_definitions") 15 | #endif 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "Settings.h" 22 | #include "MainMenu.h" 23 | #include "Grid.h" 24 | #include "GraphTools.h" 25 | #include "DSU.h" 26 | #include "CodeVisualizer.h" 27 | #include "Tree.h" 28 | #include "Trie.h" 29 | #include "QueueVisualization.h" 30 | #include "SparseTable.h" 31 | #include "LinkedList.h" 32 | #include "Deque.h" 33 | #include "HashTable.h" 34 | #include "HashMap.h" 35 | #include "Stack.h" 36 | #include "Vector.h" 37 | 38 | class App 39 | { 40 | private: 41 | 42 | // private fields: 43 | GLFWwindow* window; 44 | ImGuiStyle* style; 45 | const ImVec4 clear_color = ImVec4(0.f, 0.f, 0.f, 1.00f); 46 | 47 | GrandWindow* curWindow = nullptr; 48 | Settings* settings = nullptr; 49 | ImGuiIO* io; 50 | 51 | bool vSyncEnabled = true; 52 | int windowPosX = 100, windowPosY = 100; 53 | int windowWidth = 1280, windowHeight = 720; 54 | bool settingsEnabled = false, overlayEndabled = false, f3Pressed = false; 55 | bool isFullscreen = false, f11Pressed = false; 56 | int colorMode = 1; 57 | int state = 0; 58 | float GuiScale = 1.f; 59 | bool zoomIn = false, zoomOut = false; 60 | 61 | // private methods: 62 | void initWindow(std::string); 63 | void initStyle(); 64 | void toggleFullscreen(); 65 | void updateWindow(); 66 | void overlay(); 67 | 68 | public: 69 | 70 | App(std::string); 71 | ~App(); 72 | 73 | 74 | // public methods: 75 | void run(); 76 | void update(); 77 | void render(); 78 | GLFWwindow* getWindow(); 79 | 80 | }; 81 | 82 | -------------------------------------------------------------------------------- /C-DS/Vector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | class Vector : public GrandWindow 7 | { 8 | public: 9 | void update(); 10 | Vector(std::string, int&, float&, bool&, int&); 11 | ~Vector(); 12 | private: 13 | 14 | const int MAX_SIZE = 1024; 15 | 16 | // speed constraints: 17 | const float MAX_SPEED = 10.0f; 18 | const float MIN_SPEED = 0.1f; 19 | const float DELAY_TIME = 0.2f; 20 | const float BASE_DELAY = 0.6f; 21 | 22 | const float VEC_ROUNDNESS = 10.f; 23 | const float VEC_CELL_SIZE = 70.f; 24 | const float VEC_SEPARATOR_SIZE = 5.f; 25 | 26 | enum { 27 | DEFAULT_CELL_COL, 28 | MARKED_CELL_COL, 29 | CELL_BORDER_COL, 30 | END_CELL_COL, 31 | ARROW1_COL, 32 | ARROW2_COL, 33 | TEXT_COLOR, 34 | TEXT_OUTLINE_COL 35 | }; 36 | 37 | // private fields: 38 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 39 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 40 | 41 | 42 | 43 | 44 | 45 | int cur_tool = 0, sz = 0, tailpointer = 0, currentMaxSize = 1, expansion = -1, tempSize = 0, insertIdx = -1, eraseIdx = -1, selected_index = 0; 46 | bool camfollow = false, movingCam = false, inserting = 0; 47 | 48 | char add_element_content[200] = {}; 49 | float speed = 1.f, passedTime = 0.f; 50 | 51 | std::string* content = new std::string[currentMaxSize], * tempContent = nullptr; 52 | std::queue pending; 53 | 54 | 55 | void updateMenuBar(); 56 | void controlsUpdate(); 57 | 58 | 59 | 60 | ImU32 getColor(int); 61 | void drawText(ImVec2, const char*); 62 | void vectorUpdate(); 63 | void drawVector(int, std::string[], int, int, bool); 64 | void getInput(); 65 | void drawArrow(int, int, int, bool); 66 | bool pushBack(std::string); 67 | void popBack(); 68 | void expand(); 69 | void erase(); 70 | void insert(); 71 | }; -------------------------------------------------------------------------------- /C-DS/Stack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | class Stack : public GrandWindow 7 | { 8 | private: 9 | 10 | const int STACK_MAX_SIZE = 1024; 11 | 12 | // speed constraints: 13 | const float STACK_MAX_SPEED = 10.0f; 14 | const float STACK_MIN_SPEED = 0.1f; 15 | const float STACK_DELAY_TIME = 0.2f; 16 | const float STACK_BASE_DELAY = 0.6f; 17 | 18 | const float STACK_ROUNDNESS = 10.f; 19 | const float STACK_CELL_SIZE = 70.f; 20 | const float STACK_SEPARATOR_SIZE = 5.f; 21 | 22 | enum { 23 | DEFAULT_CELL_COL, 24 | CELL_BORDER_COL, 25 | END_CELL_COL, 26 | ARROW1_COL, 27 | ARROW2_COL, 28 | TEXT_COLOR, 29 | TEXT_OUTLINE_COL 30 | }; 31 | 32 | // private fields: 33 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 34 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 35 | 36 | 37 | 38 | 39 | // tools for stack: 40 | // 1: enqueue 41 | // 2: dequeue 42 | // 3: expand (behind the scenes) (for later visualize the the expansion process : ~visualize the 2 contentays~) 43 | int cur_tool = 0, sz = 0, headpointer = 0, currentMaxSize = 1, expansion = -1, tempSize = 0; 44 | bool camfollow = false, movingCam = false; 45 | 46 | char add_element_content[200] = {}; 47 | float speed = 1.f, passedTime = 0.f; 48 | 49 | std::string* content = new std::string[currentMaxSize], * tempContent = nullptr; 50 | std::queue pending; 51 | 52 | 53 | void controlsUpdate(); 54 | 55 | ImU32 getColor(int); 56 | void drawText(ImVec2, const char*); 57 | void getInput(); 58 | void stackUpdate(); 59 | void drawStack(int, std::string[], int, int, float, bool); 60 | void drawArrow(int, int, int, bool, float); 61 | bool Push(std::string); 62 | void Pop(); 63 | void expand(); 64 | 65 | public: 66 | 67 | Stack(std::string, int&, float&, bool&, int&); 68 | ~Stack(); 69 | void update(); 70 | 71 | }; -------------------------------------------------------------------------------- /C-DS/SparseTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | class SparseTable : public GrandWindow 7 | { 8 | private: 9 | // grid size constraints: 10 | #define X_MAX 50 11 | #define X_MIN 2 12 | #define Y_MAX 50 13 | #define Y_MIN 2 14 | 15 | // speed constraints: 16 | #define GRID_MAX_SPEED 100.0f 17 | #define GRID_MIN_SPEED 0.1f 18 | #define GRID_DELAY_TIME 0.2f 19 | 20 | #define CELL_SIZE 70.f 21 | #define SEPARATOR_SIZE 5.f 22 | 23 | // private fields: 24 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 25 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 26 | 27 | 28 | 29 | int cur_tool = 0, LOG = 18, x_size, y_size,sz=0; 30 | float speed = 1.f, curTime = 0; 31 | bool cleared = true, paused = false, camFollow = false, movingCam = false, building = false, built=false; 32 | ImVec2 camPos = { 0, 0 }, camTarget = { 0, 0 }, cur_pos{ 0,0 }, s_pos{ 0,0 }, cur_cell{ 0,0 }; 33 | char buffer[256]; 34 | std::vectorElements; 35 | std::vector>selected; 36 | std::vector>table; 37 | std::vectorlogs; 38 | /* 39 | Sparse_Table[LOG][arr_size] 40 | first row will hold the full array 41 | for every row will hold the answer for the query that starts at indx i and ends at j + 2^i 42 | first the user will enter the array and 43 | and the grid will adjust to fit the number 44 | then he will press the build button 45 | when building every cell will be highlighted and the cells it will take it's answer from 46 | 47 | */ 48 | 49 | void controlsUpdate(); 50 | ImU32 getColor(int, int); 51 | void build(); 52 | void init(); 53 | void drawtable(); 54 | void drawarray(float); 55 | public: 56 | void update(); 57 | SparseTable(std::string, int&, float&, bool&, int&); 58 | ~SparseTable(); 59 | }; 60 | 61 | -------------------------------------------------------------------------------- /C-DS/Segment_Tree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | class Segment_Tree : 14 | 15 | public GrandWindow 16 | { 17 | private: 18 | #define VERTEX_RADIUS 30.f * zoomScale 19 | #define UPDATED_NODE_COLOR ImGui::GetColorU32(IM_COL32(50, 150, 50, 255)) 20 | #define FIXED_NODE_COLOR ImGui::GetColorU32(IM_COL32(40, 40, 40, 255)) 21 | #define VIS_VERT_COL ImGui::GetColorU32(IM_COL32(50, 150, 50, 255)) 22 | #define INCORRECT ImGui::GetColorU32(IM_COL32(150, 50, 50, 255)) 23 | 24 | #define DEFAULT_VERT_COL ImGui::GetColorU32(IM_COL32(150, 150, 150, 255)) 25 | #define COMP_VERT_COL ImGui::GetColorU32(IM_COL32(50, 150, 150, 255)) 26 | 27 | // speed constraints: 28 | #define SEGTREE_MAX_SPEED 10.0f 29 | #define SEGTREE_MIN_SPEED 0.1f 30 | #define SEGTREE_DELAY 1.f 31 | struct Vertex { 32 | int minimum = INT_MAX, maximum = INT_MIN, sum = 0, gcd = 0, xr = 0; 33 | float x, y; 34 | float fx = 0, fy = 0; 35 | bool fixed = true; 36 | ImU32 color; 37 | Vertex() { 38 | x = (rand() % 10000) / 100.f; 39 | y = (rand() % 10000) / 100.f; 40 | color = DEFAULT_VERT_COL; 41 | } 42 | }; 43 | 44 | 45 | float speed = 1.f, curTime = 0; 46 | bool movingCam = false, leftClickPressed = false, camFollow = false; 47 | 48 | std::string word; 49 | 50 | int cur_tool = 0; 51 | char add_node_text[4][20] = {}; 52 | 53 | int sz = 0, level = 0; 54 | 55 | 56 | Vertex Neutral; 57 | std::vectorTree; 58 | 59 | ImU32 ContrastingColor(ImU32); 60 | void graphUpdate(); 61 | float calcDist(float, float, float, float); 62 | void controlsUpdate(); 63 | void drawEdge(ImDrawList*, int, int); 64 | 65 | 66 | 67 | Vertex Query(int, int, int, int, int); 68 | Vertex Query(int, int); 69 | Vertex Query(int); 70 | Vertex Merge(Vertex, Vertex); 71 | Vertex Single(int); 72 | 73 | 74 | void update(int, int, int, int, int); 75 | void update(int, int); 76 | 77 | // node , s , e 78 | void build(int, int, int); 79 | 80 | void clear(); 81 | 82 | Segment_Tree(std::string, int&, float&, bool&, int&); 83 | ~Segment_Tree(); 84 | 85 | // public methods: 86 | void update(); 87 | 88 | }; -------------------------------------------------------------------------------- /C-DS/Tree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | class Tree : 9 | public GrandWindow 10 | { 11 | private: 12 | // graph settings: 13 | #define EDGE_LENGTH 200.f 14 | 15 | #define VERTEX_RADIUS 30.f * zoomScale 16 | #define ROOT_NODE_COLOR ImGui::GetColorU32(IM_COL32(50, 150, 50, 255)) 17 | #define FIXED_NODE_COLOR ImGui::GetColorU32(IM_COL32(40, 40, 40, 255)) 18 | #define VIS_VERT_COL ImGui::GetColorU32(IM_COL32(50, 150, 50, 255)) 19 | 20 | #define DEFAULT_VERT_COL ImGui::GetColorU32(IM_COL32(150, 150, 150, 255)) 21 | #define COMP_VERT_COL ImGui::GetColorU32(IM_COL32(50, 150, 150, 255)) 22 | 23 | // speed constraints: 24 | #define DSU_MAX_SPEED 10.0f 25 | #define DSU_MIN_SPEED 0.1f 26 | #define DSU_DELAY 1.f 27 | 28 | struct Vertex { 29 | float x, y; 30 | float fx = 0, fy = 0; 31 | bool fixed = false, searching = false; 32 | ImU32 color; 33 | Vertex() { 34 | x = (rand() % 10000) / 100.f; 35 | y = (rand() % 10000) / 100.f; 36 | color = DEFAULT_VERT_COL; 37 | } 38 | }; 39 | 40 | // private fields: 41 | 42 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 43 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 44 | 45 | 46 | 47 | 48 | 49 | float speed = 1.f, curTime = 0; 50 | bool movingCam = false, leftClickPressed = false, disabled=false; 51 | std::string node_u, node_v, cur_node_u, cur_node_v, viewComponent; 52 | 53 | std::unordered_map parent; 54 | std::unordered_map nodes; 55 | 56 | std::string dragging; 57 | 58 | int n,cur_tool = 0; 59 | std::unordered_map node_level; 60 | char add_node_text[20] = {}; 61 | std::string root = "\0"; 62 | 63 | // private methods: 64 | ImU32 ContrastingColor(ImU32); 65 | void graphUpdate(); 66 | float calcDist(float, float, float, float); 67 | void controlsUpdate(); 68 | void drawEdge(ImDrawList*, const std::string, const std::string); 69 | void addNode(std::string, std::string); 70 | 71 | public: 72 | 73 | Tree(std::string, int&, float&, bool&, int&); 74 | ~Tree(); 75 | 76 | // public methods: 77 | void update(); 78 | 79 | }; 80 | 81 | -------------------------------------------------------------------------------- /C-DS/Segment_Tree.cpp: -------------------------------------------------------------------------------- 1 | #include "Segment_Tree.h" 2 | #include 3 | 4 | 5 | ImU32 Segment_Tree::ContrastingColor(ImU32) 6 | { 7 | return ImU32(); 8 | } 9 | 10 | void Segment_Tree::graphUpdate() 11 | { 12 | } 13 | 14 | float Segment_Tree::calcDist(float, float, float, float) 15 | { 16 | return 0.0f; 17 | } 18 | 19 | void Segment_Tree::controlsUpdate() 20 | { 21 | } 22 | 23 | void Segment_Tree::drawEdge(ImDrawList*, int, int) 24 | { 25 | } 26 | Segment_Tree::Vertex Segment_Tree::Merge(Vertex a, Vertex b) 27 | { 28 | Vertex res; 29 | res.minimum = std::min(a.minimum, b.minimum); 30 | res.maximum = std::max(a.maximum, b.maximum); 31 | //res.gcd = __gcd(a.gcd, b.gcd); 32 | res.sum = a.sum + b.sum; 33 | res.xr = (a.xr ^ b.xr); 34 | return res; 35 | } 36 | Segment_Tree::Vertex Segment_Tree::Query(int node, int s, int e, int l, int r) 37 | { 38 | if (l > e || s > r) 39 | return Neutral; 40 | if (s >= l && e <= r) 41 | return Tree[node]; 42 | int md = (s + e) >> 1; 43 | Vertex shmal = Query(node * 2, s, md, l, r); 44 | Vertex Yemen = Query(node * 2 + 1, md + 1, e, l, r); 45 | return Merge(shmal, Yemen); 46 | } 47 | 48 | Segment_Tree::Vertex Segment_Tree::Query(int l, int r) 49 | { 50 | return Query(l - 1, r - 1); 51 | } 52 | 53 | Segment_Tree::Vertex Segment_Tree::Query(int index) 54 | { 55 | return Query(index - 1, index - 1); 56 | } 57 | 58 | Segment_Tree::Vertex Segment_Tree::Single(int value) 59 | { 60 | Vertex ret; 61 | ret.xr = value; 62 | ret.gcd = value; 63 | ret.sum = value; 64 | ret.minimum = value; 65 | ret.maximum = value; 66 | return ret; 67 | } 68 | 69 | void Segment_Tree::update(int node, int s, int e, int indx, int val) 70 | { 71 | if (s == e) 72 | return Tree[node] = Single(val), void(); 73 | int md = (s + e) / 2; 74 | if (indx > md) 75 | update(node * 2 + 1, md + 1, e, indx, val); 76 | else 77 | update(node * 2, s, md, indx, val); 78 | Tree[node] = Merge(Tree[node * 2], Tree[node * 2 + 1]); 79 | } 80 | 81 | void Segment_Tree::build(int, int, int) 82 | { 83 | } 84 | 85 | void Segment_Tree::clear() 86 | { 87 | } 88 | 89 | Segment_Tree::Segment_Tree(std::string name, int& state, float& GuiScale, bool& settingsEnabled, int& colorMode) 90 | : GrandWindow(name, state, GuiScale, settingsEnabled, colorMode) 91 | { 92 | 93 | } 94 | 95 | Segment_Tree::~Segment_Tree() 96 | { 97 | } 98 | 99 | void Segment_Tree::update() 100 | { 101 | } -------------------------------------------------------------------------------- /C-DS/LinkedList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | class LinkedList : 9 | public GrandWindow 10 | { 11 | const float LL_VERTEX_RADIUS = 30.f; 12 | const float NODES_DIST = 150.f; 13 | 14 | // speed constraints: 15 | const float LL_MAX_SPEED = 5.0f; 16 | const float LL_MIN_SPEED = 0.5f; 17 | const float LL_DELAY = 1.f; 18 | 19 | enum { 20 | DEF_VERT_COL, 21 | ITER_VERT_COL, 22 | VERT_BORDER_COL, 23 | DEFAULT_EDGE_COL, 24 | TEXT_COL, 25 | TEXT_OUTLINE_COL, 26 | 27 | PUSH_BACK, 28 | PUSH_FRONT, 29 | INSERT, 30 | IDLE 31 | }; 32 | 33 | // private fields: 34 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 35 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 36 | 37 | 38 | 39 | 40 | int cur_tool = 0, highlighted_idx = -1, selected_index = 0, iterationMode = 0;; 41 | std::string insert_val; 42 | float speed = 1.f, curTime = 0; 43 | bool paused = false, camFollow = false, movingCam = false; 44 | 45 | std::queue pending; 46 | 47 | struct Node { 48 | std::string value; 49 | Node* next; 50 | ImVec2 curPos; 51 | Node(std::string value, ImVec2 curPos) { 52 | this->value = value; 53 | this->curPos = curPos; 54 | next = nullptr; 55 | } 56 | }; 57 | 58 | int listSize = 0, mode = IDLE; 59 | Node* head = nullptr, * tail = nullptr, * curNode = nullptr, * tempNode = nullptr; 60 | 61 | char add_element_content[200] = {}; 62 | 63 | // private methods: 64 | ImU32 getColor(int color_code); 65 | void drawText(ImVec2, const char*); 66 | void pushFront(std::string); 67 | void pushBack(std::string); 68 | void popFront(); 69 | void getInput(); 70 | Node* reverse(Node*); 71 | void controlsUpdate(); 72 | float calcDist(float, float, float, float); 73 | void drawEdge(ImVec2&, ImVec2&); 74 | void listUpdate(); 75 | void followNode(ImVec2); 76 | 77 | public: 78 | 79 | LinkedList(std::string, int&, float&, bool&, int&); 80 | ~LinkedList(); 81 | 82 | // public methods: 83 | void update(); 84 | 85 | 86 | }; 87 | 88 | -------------------------------------------------------------------------------- /C-DS/MainMenu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "imgui.h" 3 | #define GL_SILENCE_DEPRECATION 4 | #if defined(IMGUI_IMPL_OPENGL_ES2) 5 | #include 6 | #endif 7 | #include 8 | 9 | #include "GrandWindow.h" 10 | #include 11 | 12 | class MainMenu : 13 | public GrandWindow 14 | { 15 | private: 16 | 17 | #define BUTTON_WIDTH 500 18 | #define BUTTON_HEIGHT 375 19 | 20 | struct ButtonData { 21 | const std::string label, imagePath; 22 | GLuint textureID; 23 | int imageWidth = 0, imageHeight = 0, stateID = 0; 24 | ButtonData(std::string label, std::string imagePath, int stateID) 25 | : label(label), imagePath(imagePath), stateID(stateID) { textureID = NULL; } 26 | }; 27 | 28 | 29 | // private fields: 30 | ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 31 | 32 | 33 | 34 | static int* comp; 35 | static unsigned char* frame_data; 36 | GLuint logoTextureID[2]; 37 | int logo_width[2], logo_height[2]; 38 | 39 | int buttons_cnt; 40 | ButtonData buttons[11] = { ButtonData("Grid", "Resources\\grids.png", 1), 41 | ButtonData("Graph", "Resources\\graphs.png", 2), 42 | ButtonData("Stack", "Resources\\stack.png", 10), 43 | ButtonData("Queue", "Resources\\queue.png", 5), 44 | ButtonData("Linked-List", "Resources\\linked_list.png", 7), 45 | ButtonData("Deque", "Resources\\deque.png", 6), 46 | ButtonData("Vector", "Resources\\vector.png", 11), 47 | ButtonData("Hash Table", "Resources\\hash_table.png", 8), 48 | ButtonData("Hash Map", "Resources\\hash_map.png", 9), 49 | ButtonData("DSU", "Resources\\DSU.png", 3), 50 | ButtonData("Trie", "Resources\\trie.png", 12), 51 | /*ButtonData("Sparse Table", "Resources\\sparce_table.png",30)*/ }; 52 | 53 | // private methods: 54 | bool ImageButtonWithText(const char*, ImTextureID, const ImVec2&); 55 | void updateButtons(); 56 | void drawLogo(); 57 | 58 | public: 59 | 60 | MainMenu(std::string, int&, float&, bool&, int&); 61 | ~MainMenu(); 62 | 63 | // public methods: 64 | void update(); 65 | 66 | }; 67 | 68 | -------------------------------------------------------------------------------- /C-DS/Deque.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | 7 | class Deque : 8 | public GrandWindow 9 | { 10 | const float DQ_VERTEX_RADIUS = 30.f; 11 | const float DQ_NODES_SPACING = 150.f; 12 | 13 | 14 | // speed constraints: 15 | const float DQ_MAX_SPEED = 5.0f; 16 | const float DQ_MIN_SPEED = 0.5f; 17 | const float DQ_DELAY = 1.f; 18 | 19 | enum { 20 | DEF_VERT_COL, 21 | ITER_VERT_COL, 22 | VERT_BORDER_COL, 23 | DEFAULT_EDGE_COL, 24 | TEXT_COL, 25 | TEXT_OUTLINE_COL, 26 | 27 | PUSH_BACK, 28 | PUSH_FRONT, 29 | INSERT, 30 | IDLE 31 | }; 32 | 33 | // private fields: 34 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 35 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 36 | 37 | 38 | int cur_tool = 0, highlighted_idx = -1, selected_index = 0, iterationMode = 0, mode = IDLE; 39 | std::string insert_val; 40 | float speed = 1.f, curTime = 0; 41 | bool paused = false, camFollow = false, movingCam = false; 42 | 43 | struct Node { 44 | std::string value; 45 | Node* next; 46 | Node* prev; 47 | ImVec2 curPos; 48 | Node(std::string value, ImVec2 curPos) { 49 | this->value = value; 50 | this->curPos = curPos; 51 | next = nullptr; 52 | prev = nullptr; 53 | } 54 | }; 55 | 56 | int dequeSize = 0; 57 | Node* head = nullptr, * tail = nullptr, * curNode = nullptr, * tempNode = nullptr; 58 | std::queue pending; 59 | 60 | char add_element_content[200] = {}; 61 | 62 | // private methods: 63 | void pushFront(std::string); 64 | void pushBack(std::string); 65 | void popFront(); 66 | void popBack(); 67 | ImU32 getColor(int color_code); 68 | void drawText(ImVec2, const char*); 69 | void getInput(); 70 | void controlsUpdate(); 71 | float calcDist(float, float, float, float); 72 | void drawEdge(ImVec2&, ImVec2&); 73 | void dequeUpdate(); 74 | void followNode(ImVec2); 75 | 76 | public: 77 | 78 | Deque(std::string, int&, float&, bool&, int&); 79 | ~Deque(); 80 | 81 | // public methods: 82 | void update(); 83 | 84 | 85 | }; 86 | 87 | -------------------------------------------------------------------------------- /C-DS/Trie.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | class Trie : 11 | public GrandWindow 12 | { 13 | private: 14 | // trie settings: 15 | const float TRIE_EDGE_LENGTH = 100.f; 16 | const float TRIE_VERTEX_RADIUS = 30.f; 17 | 18 | // speed constraints: 19 | const float TRIE_MAX_SPEED = 10.0f; 20 | const float TRIE_MIN_SPEED = 0.1f; 21 | const float TRIE_DELAY = 1.f; 22 | 23 | enum { 24 | UPDATED_NODE_COLOR, 25 | FIXED_VERT_COLOR, 26 | VISITED_VERT_COL, 27 | INCORRECT, 28 | DEF_VERT_COL, 29 | VERT_BORDER_COL, 30 | MARKED_VERT_COL, 31 | DEFAULT_EDGE_COL, 32 | 33 | TEXT_COL, 34 | TEXT_OUTLINE_COL 35 | }; 36 | 37 | struct Vertex { 38 | std::mapchildren; 39 | int cnt = 0; 40 | std::string val = "\0"; 41 | int endofword = 0; 42 | float x, y; 43 | float fx = 0, fy = 0; 44 | bool fixed = false, searching = false; 45 | int color; 46 | Vertex() { 47 | x = (rand() % 10000) / 100.f; 48 | y = (rand() % 10000) / 100.f; 49 | color = DEF_VERT_COL; 50 | } 51 | }; 52 | 53 | // private fields: 54 | 55 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 56 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 57 | 58 | 59 | ImGuiIO* io = &ImGui::GetIO(); 60 | 61 | 62 | float speed = 1.f, curTime = 0; 63 | bool movingCam = false, leftClickPressed = false; 64 | bool disableButtons = false, trueUpdate = false, camFollow = false; 65 | bool deleting = false; 66 | int curNode = -1, curIdx = -1 , endw = 0; 67 | 68 | //-_- 69 | int dragging = -1; 70 | std::vectorparent; 71 | std::vectornodes; 72 | std::queueupdatedNodes; 73 | std::stackdeletedNodes; 74 | 75 | std::string word; 76 | 77 | int cur_tool = 0; 78 | char add_node_text[4][20] = {}; 79 | 80 | // private methods: 81 | ImU32 getColor(int); 82 | void drawText(ImVec2, const char*); 83 | void graphUpdate(); 84 | float calcDist(float, float, float, float); 85 | void controlsUpdate(); 86 | void drawEdge(ImDrawList*, int, int); 87 | void insertWord(); 88 | bool search(std::string word, bool); 89 | void clear(); 90 | 91 | public: 92 | 93 | Trie(std::string, int&, float&, bool&, int&); 94 | ~Trie(); 95 | 96 | // public methods: 97 | void update(); 98 | 99 | }; 100 | 101 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /C-DS/CodeVisualizer.cpp: -------------------------------------------------------------------------------- 1 | #include "CodeVisualizer.h" 2 | 3 | void CodeVisualizer::updateMenuBar() 4 | { 5 | if (ImGui::BeginMainMenuBar()) 6 | { 7 | if (ImGui::BeginMenu("File")) 8 | { 9 | if (ImGui::MenuItem("New", "Ctrl+N")) {} 10 | if (ImGui::MenuItem("Open", "Ctrl+O")) {} 11 | if (ImGui::MenuItem("Save", "Ctrl+S")) {} 12 | ImGui::EndMenu(); 13 | } 14 | 15 | if (ImGui::BeginMenu("Edit")) 16 | { 17 | if (ImGui::MenuItem("Cut", "Ctrl+X")) {} 18 | if (ImGui::MenuItem("Copy", "Ctrl+C")) {} 19 | if (ImGui::MenuItem("Paste", "Ctrl+V")) {} 20 | ImGui::EndMenu(); 21 | } 22 | 23 | if (ImGui::BeginMenu("View")) 24 | { 25 | if (ImGui::MenuItem("Zoom in", "Ctrl+=")) { 26 | //GuiScale = GuiScale * 1.2f; 27 | //ImGui::GetIO().FontGlobalScale = GuiScale; 28 | } 29 | if (ImGui::MenuItem("Zoom out", "Ctrl+-")) { 30 | //GuiScale = GuiScale * 0.8f; 31 | //ImGui::GetIO().FontGlobalScale = GuiScale; 32 | } 33 | if (ImGui::MenuItem("Settings")) { 34 | settingsEnabled = true; 35 | } 36 | ImGui::EndMenu(); 37 | } 38 | 39 | ImGui::EndMainMenuBar(); 40 | } 41 | } 42 | 43 | CodeVisualizer::CodeVisualizer(std::string name, int& state, float& GuiScale, bool& settingsEnabled, int& colorMode) 44 | : GrandWindow(name, state, GuiScale, settingsEnabled, colorMode) 45 | { 46 | docking_area = new DockingArea("Docking_Area"); 47 | text_area = new TextArea("Text_Area"); 48 | 49 | ImGuiID dockspace_id = ImGui::DockSpaceOverViewport(ImGui::GetMainViewport(), ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDocking); 50 | 51 | ImGuiID dock_id_left, dock_id_right; 52 | 53 | ImGui::DockBuilderRemoveNode(dockspace_id); 54 | ImGui::DockBuilderAddNode(dockspace_id); 55 | ImGui::DockBuilderSetNodeSize(dockspace_id, ImGui::GetMainViewport()->Size); 56 | 57 | ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Left, 0.7f, &dock_id_left, &dock_id_right); 58 | ImGui::DockBuilderDockWindow(docking_area->getName().c_str(), dock_id_left); 59 | ImGui::DockBuilderDockWindow(text_area->getName().c_str(), dock_id_right); 60 | 61 | ImGui::DockBuilderFinish(dockspace_id); 62 | } 63 | 64 | CodeVisualizer::~CodeVisualizer() 65 | { 66 | delete docking_area; 67 | delete text_area; 68 | } 69 | 70 | void CodeVisualizer::update() 71 | { 72 | updateMenuBar(); 73 | 74 | ImGui::DockSpaceOverViewport(ImGui::GetMainViewport(), ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDocking); 75 | docking_area->update(); 76 | text_area->update(); 77 | } 78 | -------------------------------------------------------------------------------- /C-DS/DSU.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class DSU : 10 | public GrandWindow 11 | { 12 | 13 | private: 14 | // graph settings: 15 | const float EDGE_LENGTH = 200.f; 16 | const float VERTEX_RADIUS = 30.f; 17 | 18 | const int BY_SIZE = 1; 19 | const int BY_HEIGHT = 2; 20 | 21 | // speed constraints: 22 | const float MAX_SPEED = 10.0f; 23 | const float MIN_SPEED = 0.1f; 24 | const float DELAY = 1.f; 25 | 26 | const char NO_DRAGGING = char(2); 27 | 28 | enum { 29 | FIXED_NODE_COL, 30 | VIS_VERT_COL, 31 | DEFAULT_VERT_COL, 32 | COMP_VERT_COL, 33 | VERT_BORDER_COL, 34 | DEFAULT_EDGE_COL, 35 | TEXT_COL, 36 | TEXT_OUTLINE_COL 37 | }; 38 | 39 | struct Vertex { 40 | float x, y; 41 | float fx = 0, fy = 0; 42 | bool fixed = false, searching = false, beingDragged = false; 43 | int color; 44 | Vertex() { 45 | x = (rand() % 10000) / 100.f; 46 | y = (rand() % 10000) / 100.f; 47 | color = DEFAULT_VERT_COL; 48 | } 49 | }; 50 | 51 | // private fields: 52 | 53 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 54 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 55 | 56 | 57 | 58 | 59 | 60 | int cur_tool = 0, rank_type = 0; 61 | float speed = 1.f, curTime = 0; 62 | bool movingCam = false, leftClickPressed = false, pathCompression = false, isMerging = false; 63 | std::string node_u, node_v, cur_node_u, cur_node_v, viewComponent; 64 | 65 | std::unordered_map st_height, st_size; 66 | std::unordered_map parent; 67 | std::unordered_map nodes; 68 | char add_node_text[50] = {}; 69 | 70 | std::string dragging; 71 | 72 | // private methods: 73 | 74 | void updateDraggedComponent(); 75 | void graphUpdate(); 76 | float calcDist(float, float, float, float); 77 | ImU32 getColor(int color_code); 78 | void drawText(ImVec2, const char*); 79 | void controlsUpdate(); 80 | void drawEdge(ImDrawList*, const std::string, const std::string); 81 | void mergeGroup(const std::string, const std::string); 82 | const std::string find(const std::string); 83 | void addNode(std::string); 84 | bool sameGroup(const std::string, const std::string); 85 | 86 | public: 87 | 88 | DSU(std::string, int&, float&, bool&, int&); 89 | ~DSU(); 90 | 91 | // public methods: 92 | void update(); 93 | 94 | }; 95 | 96 | -------------------------------------------------------------------------------- /C-DS/HashTable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | class HashTable : 9 | public GrandWindow 10 | { 11 | // grid size constraints: 12 | const int MAX_TABLE_SIZE = 50; 13 | const int MIN_TABLE_SIZE = 2; 14 | 15 | const float HT_SEPARATOR_SIZE = 70.f; 16 | const float CELL_SIZE_X = 180.f; 17 | const float CELL_SIZE_Y = 60.f; 18 | 19 | const float BUCKET_ROUNDNESS = 10.f; 20 | const float HT_VERTEX_RADIUS = 30.f; 21 | const float HT_NODES_DIST = 200.f; 22 | 23 | // speed constraints: 24 | const float HT_MAX_SPEED = 5.0f; 25 | const float HT_MIN_SPEED = 0.5f; 26 | const float HT_DELAY = 1.f; 27 | 28 | enum { 29 | DEFAULT_BUCKET_COL, 30 | BUCKET_BORDER_COL, 31 | CUR_BUCKET_COL, 32 | FAIL_BUCKET_COL, 33 | 34 | DEFAULT_NODE_COL, 35 | NODE_BORDER_COL, 36 | ITER_NODE_COL, 37 | FAIL_NODE_COL, 38 | FOUND_NODE_COL, 39 | DEFAULT_EDGE_COL, 40 | TEXT_COL, 41 | TEXT_OUTLINE_COL, 42 | 43 | INSERT, 44 | FIND, 45 | ERASE, 46 | IDLE 47 | }; 48 | 49 | private: 50 | // private fields: 51 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 52 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 53 | 54 | 55 | 56 | 57 | int cur_tool = 0, table_size_slider = 10, table_size = 10, cur_bucket = -1, mode = IDLE; 58 | float speed = 1.0f, curTime = 0.0f, window_height = 100.0f; 59 | bool paused = false, camFollow = false, movingCam = false, found = false;; 60 | 61 | std::string searchVal, toDelete; 62 | 63 | struct Node { 64 | std::string value; 65 | Node* next; 66 | ImVec2 curPos; 67 | ImU32 color; 68 | Node(std::string value, ImVec2 curPos) { 69 | this->value = value; 70 | this->curPos = curPos; 71 | next = nullptr; 72 | color = DEFAULT_NODE_COL; 73 | } 74 | }; 75 | 76 | std::vector buckets; 77 | Node* iteratingNode = nullptr, *tempNode = nullptr; 78 | std::queue pending; 79 | 80 | char add_element_content[200] = ""; 81 | 82 | // private methods: 83 | ImU32 getColor(int color_code); 84 | void drawText(ImVec2, const char*); 85 | void getInput(); 86 | void selectBucket(int); 87 | void controlsUpdate(); 88 | void tableUpdate(); 89 | float calcDist(float, float, float, float); 90 | void drawEdge(ImVec2, ImVec2); 91 | void followNode(ImVec2); 92 | void insertUpdate(); 93 | void findUpdate(); 94 | void eraseUpdate(); 95 | int hashValue(std::string); 96 | 97 | public: 98 | 99 | HashTable(std::string, int&, float&, bool&, int&); 100 | ~HashTable(); 101 | 102 | // public methods: 103 | void update(); 104 | 105 | 106 | }; 107 | 108 | -------------------------------------------------------------------------------- /C-DS/HashMap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | 6 | 7 | class HashMap : 8 | public GrandWindow 9 | { 10 | // grid size constraints: 11 | const int MAX_TABLE_SIZE = 50; 12 | const int MIN_TABLE_SIZE = 2; 13 | 14 | const float HM_SEPARATOR_SIZE = 100.f; 15 | const float CELL_SIZE_X = 180.f; 16 | const float CELL_SIZE_Y = 60.f; 17 | 18 | const float BUCKET_ROUNDNESS = 10.f; 19 | const float HM_VERTEX_RADIUS = 30.f; 20 | const float NODES_DIST = 200.f; 21 | const float LINK_DIST = 120.f;; 22 | 23 | // speed constraints: 24 | const float HM_MAX_SPEED = 5.0f; 25 | const float HM_MIN_SPEED = 0.5f; 26 | const float HM_DELAY = 1.f; 27 | 28 | enum { 29 | DEFAULT_BUCKET_COL, 30 | BUCKET_BORDER_COL, 31 | CUR_BUCKET_COL, 32 | FAIL_BUCKET_COL, 33 | 34 | DEFAULT_NODE_COL, 35 | NODE_BORDER_COL, 36 | ITER_NODE_COL, 37 | FAIL_NODE_COL, 38 | FOUND_NODE_COL, 39 | DEFAULT_EDGE_COL, 40 | TEXT_COL, 41 | TEXT_OUTLINE_COL, 42 | 43 | INSERT, 44 | FIND, 45 | ERASE, 46 | IDLE 47 | }; 48 | 49 | 50 | private: 51 | // private fields: 52 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 53 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 54 | 55 | 56 | 57 | 58 | int cur_tool = 0, table_size_slider = 10, table_size = 10, cur_bucket = -1, mode = IDLE; 59 | float speed = 1.0f, curTime = 0.0f, window_height = 100.0f; 60 | bool paused = false, camFollow = false, movingCam = false, found = false;; 61 | 62 | std::string searchKey, newVal, toDelete; 63 | 64 | struct Node { 65 | std::string key, value; 66 | Node* next; 67 | ImVec2 curPos; 68 | ImU32 keyColor; 69 | ImU32 valColor; 70 | Node(std::string key, std::string value, ImVec2 curPos) { 71 | this->key = key; 72 | this->value = value; 73 | this->curPos = curPos; 74 | next = nullptr; 75 | keyColor = valColor = DEFAULT_NODE_COL; 76 | } 77 | }; 78 | 79 | std::vector buckets; 80 | Node* iteratingNode = nullptr, * tempNode = nullptr; 81 | 82 | char key_text[10] = "", value_text[10] = ""; 83 | 84 | // private methods: 85 | ImU32 getColor(int color_code); 86 | void drawText(ImVec2, const char*); 87 | void controlsUpdate(); 88 | void tableUpdate(); 89 | float calcDist(float, float, float, float); 90 | void drawEdge(ImVec2, ImVec2); 91 | void followNode(ImVec2); 92 | void insertUpdate(); 93 | void findUpdate(); 94 | void eraseUpdate(); 95 | int hashValue(std::string); 96 | 97 | public: 98 | 99 | HashMap(std::string, int&, float&, bool&, int&); 100 | ~HashMap(); 101 | 102 | // public methods: 103 | void update(); 104 | 105 | 106 | }; 107 | 108 | -------------------------------------------------------------------------------- /imgui/imgui_impl_opengl3.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline 2 | // - Desktop GL: 2.x 3.x 4.x 3 | // - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0) 4 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) 5 | 6 | // Implemented features: 7 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! 8 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). 9 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 10 | 11 | // About WebGL/ES: 12 | // - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES. 13 | // - This is done automatically on iOS, Android and Emscripten targets. 14 | // - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h. 15 | 16 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 17 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 18 | // Learn about Dear ImGui: 19 | // - FAQ https://dearimgui.com/faq 20 | // - Getting Started https://dearimgui.com/getting-started 21 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 22 | // - Introduction, links and more at the top of imgui.cpp 23 | 24 | // About GLSL version: 25 | // The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string. 26 | // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" 27 | // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. 28 | 29 | #pragma once 30 | #include "imgui.h" // IMGUI_IMPL_API 31 | #ifndef IMGUI_DISABLE 32 | 33 | // Backend API 34 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr); 35 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); 36 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); 37 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); 38 | 39 | // (Optional) Called by Init/NewFrame/Shutdown 40 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); 41 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); 42 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); 43 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); 44 | 45 | // Specific OpenGL ES versions 46 | //#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten 47 | //#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android 48 | 49 | // You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line. 50 | #if !defined(IMGUI_IMPL_OPENGL_ES2) \ 51 | && !defined(IMGUI_IMPL_OPENGL_ES3) 52 | 53 | // Try to detect GLES on matching platforms 54 | #if defined(__APPLE__) 55 | #include 56 | #endif 57 | #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) 58 | #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" 59 | #elif defined(__EMSCRIPTEN__) || defined(__amigaos4__) 60 | #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" 61 | #else 62 | // Otherwise imgui_impl_opengl3_loader.h will be used. 63 | #endif 64 | 65 | #endif 66 | 67 | #endif // #ifndef IMGUI_DISABLE 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C-DS 2 | 3 |
4 | 5 |
6 | 14 | 15 | # Table Of Contents 16 | - [About](#about) 17 | - [Features](#features) 18 | - [Demo](#demo) 19 | - [Installation & Running](#installation--running) 20 | 21 | ## About 22 | **C-DS** is a data structure visualization app designed to help users understand and interact with various data structures. Whether you're a student learning about algorithms and data structures or a professional looking to analyze and optimize your code, **C-DS** provides a comprehensive set of tools and features to make your data structure exploration seamless and insightful. 23 | 24 | It was originally an academic project for the **2024 Data Structures course** in [Faculty of Computer Science - Ain Shams University](https://cis.asu.edu.eg/). 25 | 26 | ## Features 27 | ### User Interface Settings 28 | * GUI scale adjuster to resize the visualization interface. 29 | 30 | * Light and dark mode themes for comfortable viewing. 31 | 32 | [![settings-menu.png](https://i.postimg.cc/xCQtN8b2/settings-menu.png)](https://postimg.cc/TykrZR97) 33 | 34 | ### Grid Visualization Tools 35 | * Customize grid width and height. 36 | 37 | * Set start and end positions on the grid. 38 | 39 | * Add or remove obstacles to create different pathfinding scenarios. 40 | 41 | * Visualize traversal algorithms such as DFS, BFS, Dijkstra’s, and A*. 42 | 43 | * Enable or disable diagonal movement in traversals. 44 | 45 | * Camera follow mode to track the current exploration point. 46 | 47 | * Adjustable camera speed for better control of the visualization flow. 48 | 49 | https://github.com/user-attachments/assets/e43b16c3-a839-4390-8e96-4c76619e7319 50 | 51 | ### Graph Visualization Tools 52 | * Move nodes freely to customize the graph layout. 53 | 54 | * Move camera to navigate the graph smoothly. 55 | 56 | * View adjacent nodes to understand connectivity. 57 | 58 | * Set starting and ending nodes for algorithm visualization. 59 | 60 | * Generate random graphs, weighted or unweighted, directed or undirected. 61 | 62 | * Import and visualize pre-existing graphs by input. 63 | 64 | * Visualize algorithms including DFS, BFS, Dijkstra’s, and Minimum Spanning Tree (Kruskal’s Algorithm). 65 | 66 | https://github.com/user-attachments/assets/deb37e6b-4743-4ef4-92b5-724418c69c4d 67 | 68 | ### Basic Data Structure Visualizations 69 | Understand foundational data structures through interactive visualizations of: 70 | 71 | * Stack: Visualize LIFO operations like push and pop. 72 | 73 | * Queue: Explore FIFO operations with enqueue and dequeue. 74 | 75 | * Linked List: See how nodes are connected and manipulated. 76 | 77 | * Deque: Double-ended queue operations from both ends. 78 | 79 | * Vector (Dynamic Array): Dynamic resizing and element access. 80 | 81 | https://github.com/user-attachments/assets/3922ad8f-f9f3-4eb0-8741-94a29fd0d962 82 | 83 | ### Advanced Data Structure Visualizations 84 | 85 | * Hashtable: Understand key-value storage with hash functions. 86 | 87 | * Hashmap: Explore an implementation of associative arrays. 88 | 89 | * Disjoint Set Union (DSU): Visualize union and find operations used in connectivity problems. 90 | 91 | * Trie (Prefix Tree): See how tries handle fast prefix searches and autocomplete. 92 | 93 | 94 | 95 | 96 | https://github.com/user-attachments/assets/00cea46c-b184-49c1-8aee-31e4a9aa0036 97 | 98 | 99 | ## Demo 100 | [![Demo](https://i.postimg.cc/j535D88Y/logo.png)](https://drive.google.com/file/d/10Go1OUR9pBcbghCPX_nkEdVTEnjNahNi/view?usp=sharing) 101 | 102 | **▶️ [Watch Demo](https://drive.google.com/file/d/10Go1OUR9pBcbghCPX_nkEdVTEnjNahNi/view?usp=sharing)** 103 | 104 | ## Installation & Running 105 | 106 | To run the program locally, follow these steps: 107 | 108 | 1. **Clone the repository** 109 | 110 | 2. This project uses **imGUI** for its interface, so ensure you have the appropriate dependencies or build environment set up (e.g., C++ compiler with imGUI integration). 111 | 112 | 3. **Compile and run `App.cpp`** 113 | 114 | -------------------------------------------------------------------------------- /imgui/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | // (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.) 5 | 6 | // Implemented features: 7 | // [X] Platform: Clipboard support. 8 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only). 9 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 10 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 11 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). 12 | // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 13 | // Issues: 14 | // [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor). 15 | 16 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 17 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 18 | // Learn about Dear ImGui: 19 | // - FAQ https://dearimgui.com/faq 20 | // - Getting Started https://dearimgui.com/getting-started 21 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 22 | // - Introduction, links and more at the top of imgui.cpp 23 | 24 | #pragma once 25 | #include "imgui.h" // IMGUI_IMPL_API 26 | #ifndef IMGUI_DISABLE 27 | 28 | struct GLFWwindow; 29 | struct GLFWmonitor; 30 | 31 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 32 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 33 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks); 34 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 35 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 36 | 37 | // Emscripten related initialization phase methods 38 | #ifdef __EMSCRIPTEN__ 39 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback(const char* canvas_selector); 40 | #endif 41 | 42 | // GLFW callbacks install 43 | // - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any. 44 | // - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks. 45 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); 46 | IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); 47 | 48 | // GFLW callbacks options: 49 | // - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user) 50 | IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows); 51 | 52 | // GLFW callbacks (individual callbacks to call yourself if you didn't install callbacks) 53 | IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 54 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 55 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 56 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 57 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 58 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 59 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 60 | IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event); 61 | 62 | #endif // #ifndef IMGUI_DISABLE 63 | -------------------------------------------------------------------------------- /C-DS/Grid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | class Grid : 9 | public GrandWindow 10 | { 11 | private: 12 | // grid size constraints: 13 | const int X_MAX = 50; 14 | const int X_MIN = 2; 15 | const int Y_MAX = 50; 16 | const int Y_MIN = 2; 17 | const float GRID_ROUNDNESS = 7.f; 18 | 19 | // speed constraints: 20 | const float GRID_MAX_SPEED = 100.0f; 21 | const float GRID_MIN_SPEED = 0.1f; 22 | const float GRID_DELAY_TIME = 0.2f; 23 | 24 | const float CELL_SIZE = 70.f; 25 | const float SEPARATOR_SIZE = 5.f; 26 | 27 | enum { 28 | PATH_CELL, 29 | VISITED_CELL, 30 | START_POS_CELL, 31 | END_POS_CELL, 32 | OBSTACLE_CELL, 33 | EMPTY_CELL, 34 | INQUE_CELL, 35 | 36 | OUTLINE_COL, 37 | }; 38 | 39 | // private fields: 40 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 41 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 42 | 43 | int cur_tool = 0, x_size = 5, y_size = 5, activeAlgo = 0, obstaclesCnt = 0; 44 | float speed = 1.f, curTime = 0; 45 | bool diagonal_movement = false, found = false, cleared = false, paused = false, camFollow = false, movingCam = false; 46 | 47 | int prev_x = -1, prev_y = -1; 48 | 49 | std::pair start_pos = { 0, 0 }, end_pos = { x_size - 1, y_size - 1 }; 50 | std::pair cur_node; 51 | 52 | const int dx[4] = { 1, 0, -1, 0 }; 53 | const int dy[4] = { 0, 1, 0, -1 }; 54 | const int dir[3] = { 0, 1, -1 }; 55 | const double diagonal_cost = sqrt(2); 56 | 57 | struct Node { 58 | int x = -1, y = -1; 59 | Node() {}; 60 | Node(int x, int y){ 61 | this->x = x; 62 | this->y = y; 63 | } 64 | Node(std::pair node) { 65 | x = node.first; 66 | y = node.second; 67 | } 68 | }; 69 | struct djskNode { 70 | Node coordinates = {}; 71 | double cost = 0; 72 | djskNode() {}; 73 | djskNode(Node coordinates, double cost) { 74 | this->coordinates = coordinates; 75 | this->cost = cost; 76 | } 77 | friend bool operator<(const djskNode& l, const djskNode &r){ 78 | return l.cost > r.cost; 79 | } 80 | }; 81 | struct aStarNode { 82 | djskNode curNode = {}; 83 | 84 | aStarNode() {}; 85 | aStarNode(Node coordinates, double cost, double gVal){ 86 | this->curNode = djskNode(coordinates, cost+gVal); 87 | } 88 | friend bool operator<(const aStarNode& l, const aStarNode& r) { 89 | return l.curNode < r.curNode; 90 | } 91 | }; 92 | 93 | std::stack> dfs_stack; 94 | std::queue> bfs_queue; 95 | std::priority_queue>> dijkstra_queue; 96 | std::priority_queue astar_queue; 97 | 98 | 99 | std::vector> vis = std::vector>(X_MAX, std::vector(Y_MAX)); 100 | std::vector> cost = std::vector>(X_MAX, std::vector(Y_MAX, FLT_MAX)); 101 | std::vector> is_obstacle = std::vector>(X_MAX, std::vector(Y_MAX)); 102 | std::vector>> par = std::vector>>(X_MAX, std::vector>(Y_MAX)); 103 | 104 | // private methods: 105 | void controlsUpdate(); 106 | void gridUpdate(); 107 | void useTool(int, int); 108 | ImU32 getCellColor(int, int); 109 | ImU32 getColor(int); 110 | void clearVisited(); 111 | bool inbounds(int, int); 112 | double getCost(int x, int y); 113 | void followCell(int, int); 114 | void dfs(); 115 | void bfs(); 116 | void dijkstra(); 117 | double g_val(Node a); 118 | void a_star(); 119 | void st_line_eq(ImVec2, float); 120 | 121 | public: 122 | 123 | Grid(std::string, int&, float&, bool&, int&); 124 | ~Grid(); 125 | 126 | // public methods: 127 | void update(); 128 | 129 | 130 | }; 131 | 132 | -------------------------------------------------------------------------------- /C-DS/GraphTools.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GrandWindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class GraphTools : 13 | public GrandWindow 14 | { 15 | private: 16 | // graph settings: 17 | const float EDGE_LENGTH = 200.f; 18 | const float VERTEX_RADIUS = 30.f; 19 | 20 | const char NO_DRAGGING = char(2); 21 | 22 | enum { 23 | 24 | FIXED_NODE_COLOR, 25 | 26 | DEFAULT_VERT_COL, 27 | ADJ_ROOT_COL, 28 | ADJ_CHILD_COL, 29 | VIS_VERT_COL, 30 | PATH_VERT_COL, 31 | INQUE_VERT_COL, 32 | ADJ_EDGE_COL, 33 | VERT_BORDER_COL, 34 | 35 | START_POINT_COL, 36 | END_POINT_COL, 37 | 38 | DEFAULT_EDGE_COL, 39 | VIS_EDGE_COL, 40 | PATH_EDGE_COL, 41 | INQUE_EDGE_COL, 42 | CANCELED_EDGE_COL, 43 | 44 | TEXT_COL, 45 | TEXT_OUTLINE_COL 46 | }; 47 | 48 | 49 | // speed constraints: 50 | #define GRAPH_MAX_SPEED 20.0f 51 | #define GRAPH_MIN_SPEED 0.1f 52 | #define GRAPH_DELAY 1.f 53 | 54 | class Random { 55 | private: 56 | std::mt19937 eng{ std::random_device{}() }; 57 | 58 | public: 59 | Random() = default; 60 | Random(std::mt19937::result_type seed) : eng(seed) {} 61 | 62 | int DrawNumber(int min, int max) { 63 | if (max < min) return 0; 64 | return std::uniform_int_distribution{min, max}(eng); 65 | } 66 | }; 67 | 68 | static Random randomizer; 69 | 70 | struct Vertex { 71 | float x, y; 72 | float fx = 0, fy = 0; 73 | bool fixed = false, beingDragged = false; 74 | int color = DEFAULT_VERT_COL; 75 | 76 | Vertex() { 77 | x = randomizer.DrawNumber(0, 10000) / 100.f; 78 | y = randomizer.DrawNumber(0, 10000) / 100.f; 79 | } 80 | }; 81 | 82 | struct Edge { 83 | int w = 0; 84 | bool weighted = false; 85 | bool directed = true; 86 | ImVec2 pos = {0, 0}; 87 | int color = DEFAULT_EDGE_COL; 88 | }; 89 | 90 | class DSU { 91 | private: 92 | std::unordered_map parent; 93 | std::unordered_map st_size; 94 | public: 95 | DSU(std::unordered_map& nodes) { 96 | 97 | for (auto node : nodes){ 98 | parent[node.first] = node.first; 99 | st_size[node.first] = 1; 100 | } 101 | 102 | } 103 | std::string find(const std::string& x) { 104 | return (parent[x] == x ? x : parent[x] = find(parent[x])); 105 | } 106 | bool isConnected(const std::string& u, const std::string& v) { 107 | return (find(u) == find(v)); 108 | } 109 | void Union(const std::string& u, const std::string& v) { 110 | std::string set_u = find(u); 111 | std::string set_v = find(v); 112 | if (set_u == set_v) 113 | return; 114 | if (st_size[set_u] < st_size[set_v]) 115 | parent[set_u] = set_v, st_size[set_v] += st_size[set_u]; 116 | else 117 | parent[set_v] = set_u, st_size[set_u] += st_size[set_v]; 118 | } 119 | }; 120 | 121 | // private fields: 122 | 123 | std::unordered_map nodes; 124 | std::map, Edge> edges; 125 | std::unordered_map>>> adj; 126 | DSU* mst_dsu = nullptr; 127 | 128 | char graphText[100000]; 129 | 130 | ImGuiWindowFlags main_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus; 131 | ImGuiWindowFlags controls_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; 132 | 133 | 134 | int cur_tool = 0, activeAlgo = 0, directed = 0, found = 0; 135 | float speed = 1.f, curTime = 0, edgesLastTransition = 0.0f;; 136 | bool cleared = true, paused = false, leftClickPressed = false, camFollow = false, movingCam = false, weighted_rand = false; 137 | bool showNodeText = true, showWeightText = true; 138 | std::string dragging, cur_node; 139 | std::string viewAdjacent, startNode = "", endNode = ""; 140 | 141 | 142 | std::stack> dfs_stack; 143 | std::queue bfs_queue; 144 | std::priority_queue> dijkstra_queue; 145 | std::priority_queue>> kruskal_queue; 146 | std::unordered_map vis; 147 | std::map, long long> edge_vis; 148 | std::unordered_map par; 149 | std::unordered_map>path; 150 | 151 | // private methods: 152 | void controlsUpdate(); 153 | void generateGraph(); 154 | void clearStates(); 155 | void pointToNode(const std::string, ImU32); 156 | void drawEdge(ImDrawList*, const std::string, const std::string, Edge&); 157 | void drawEdgeWeight(ImDrawList*, const std::string, const std::string, Edge&); 158 | void drawText(ImVec2, const char*); 159 | float calcDist(float, float, float, float); 160 | void updateDraggedComponent(); 161 | void graphUpdate(); 162 | void followNode(const std::string); 163 | void dfs(); 164 | void bfs(); 165 | void dijkstra(); 166 | void kruskal(); 167 | void bellmanFord(); 168 | ImU32 getColor(int); 169 | 170 | public: 171 | 172 | GraphTools(std::string, int&, float&, bool&, int&); 173 | ~GraphTools(); 174 | 175 | // public methods: 176 | void update(); 177 | 178 | }; 179 | 180 | -------------------------------------------------------------------------------- /C-DS/SparseTable.cpp: -------------------------------------------------------------------------------- 1 | #include "SparseTable.h" 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | void SparseTable::update() 8 | { 9 | ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f); 10 | ImGui::SetNextWindowPos(viewport->WorkPos); 11 | ImGui::SetNextWindowSize(viewport->WorkSize); 12 | updateCenter(); 13 | ImGui::Begin(getName().c_str(), NULL, main_flags); 14 | 15 | ImGui::PopStyleVar(); 16 | 17 | drawWatermark(); 18 | 19 | //drawtable(); 20 | if(!built) 21 | drawarray(center.y); 22 | 23 | if ((ImGui::IsWindowHovered() || movingCam) && ((ImGui::IsMouseDown(0) && cur_tool == 0) || ImGui::IsMouseDown(2))) { 24 | movingCam = true; 25 | camPos.x += io->MouseDelta.x / zoomScale; 26 | camPos.y += io->MouseDelta.y / zoomScale; 27 | camTarget.x += io->MouseDelta.x / zoomScale; 28 | camTarget.y += io->MouseDelta.y / zoomScale; 29 | } 30 | else if (!(ImGui::IsMouseDown(0) && cur_tool == 0) && !ImGui::IsMouseDown(2)) { 31 | movingCam = false; 32 | } 33 | 34 | updateCam(); 35 | 36 | ImGui::End(); 37 | 38 | controlsUpdate(); 39 | } 40 | 41 | SparseTable::SparseTable(std::string name, int& state, float& GuiScale, bool& settingsEnabled, int& colorMode) 42 | : GrandWindow(name, state, GuiScale, settingsEnabled, colorMode) 43 | { 44 | 45 | } 46 | 47 | SparseTable::~SparseTable() 48 | { 49 | 50 | } 51 | 52 | void SparseTable::controlsUpdate() 53 | { 54 | ImVec2 controlsWinSize(std::min(450.f * GuiScale, viewport->WorkSize.x - ImGui::GetStyle().WindowPadding.x), std::min(855.f * GuiScale, viewport->WorkSize.y - 2 * ImGui::GetStyle().WindowPadding.y)); 55 | ImVec2 controlsWinPos(viewport->Size.x - controlsWinSize.x - ImGui::GetStyle().WindowPadding.x, viewport->Size.y - controlsWinSize.y - ImGui::GetStyle().WindowPadding.y); 56 | bool disabled = false; 57 | 58 | ImGui::SetNextWindowSize(controlsWinSize); 59 | ImGui::SetNextWindowPos(controlsWinPos); 60 | 61 | ImGui::Begin("Controls", NULL, controls_flags); 62 | 63 | if (ImGui::Button("Back")) 64 | state = 0; 65 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 66 | if (ImGui::Button("Reset Camera")) 67 | camTarget = { 0,0 }; 68 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 69 | ImGui::Text("Insert Element"); 70 | ImGui::InputText(" ", buffer, IM_ARRAYSIZE(buffer), ImGuiInputTextFlags_CharsDecimal); 71 | if (ImGui::Button("Insert")) { 72 | std::string curElement; 73 | char* ptr = buffer; 74 | while (*ptr != '\0') { 75 | if (*ptr == ',') { 76 | if (curElement.size() > 0) { 77 | Elements.push_back(stoi(curElement)); 78 | curElement.clear(); 79 | } 80 | } 81 | else 82 | curElement.push_back(*ptr); 83 | 84 | ptr++; 85 | } 86 | if (curElement.size() > 0) { 87 | Elements.push_back(stoi(curElement)); 88 | curElement.clear(); 89 | } 90 | 91 | memset(buffer, 0, sizeof buffer); 92 | } 93 | 94 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 95 | 96 | if (Elements.size() < 4) { 97 | disabled = true; 98 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 99 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 100 | } 101 | 102 | ImGui::Dummy(ImVec2(100.0f * GuiScale, 0.0f)); 103 | ImGui::SameLine(); 104 | if (ImGui::Button("Build", ImVec2(200 * GuiScale, ImGui::GetFrameHeight()))) 105 | { 106 | build(); 107 | } 108 | 109 | 110 | if (disabled) { 111 | ImGui::PopItemFlag(); 112 | ImGui::PopStyleVar(); 113 | } 114 | ImGui::End(); 115 | 116 | } 117 | 118 | ImU32 SparseTable::getColor(int x, int y) 119 | { 120 | ImU32 col; 121 | 122 | col = ImGui::GetColorU32(IM_COL32(150, 150, 150, 255)); // default 123 | 124 | if (selected[x][y]) { 125 | col = ImGui::GetColorU32(IM_COL32(255, 87, 51, 255)); 126 | } 127 | else if (x == cur_cell.x && y == cur_cell.y) { 128 | col = ImGui::GetColorU32(IM_COL32(100, 100, 100, 255)); 129 | } 130 | return col; 131 | } 132 | 133 | void SparseTable::build() 134 | { 135 | 136 | drawtable(); 137 | } 138 | 139 | void SparseTable::init() 140 | { 141 | sz = (int)Elements.size(); 142 | logs.resize(sz + 1); 143 | table = std::vector>(LOG + 1, std::vector(sz)); 144 | for (int i = 2; i <= sz; i++) { 145 | logs[i] = logs[i >> 1] + 1; 146 | } 147 | for(int i=0;iAddRectFilled(cur_pos, ImVec2(cur_pos.x + cell_size, cur_pos.y + cell_size), getColor(y, x)); 176 | cur_pos.x += cell_size + separator_size; 177 | } 178 | cur_pos.y += cell_size + separator_size; 179 | } 180 | } 181 | 182 | void SparseTable::drawarray(float yPos) 183 | { 184 | ImVec2 center(viewport->WorkPos.x + viewport->WorkSize.x * 0.5f, yPos); 185 | 186 | float separator_size = std::max(SEPARATOR_SIZE * zoomScale, 1.f); 187 | float cell_size = CELL_SIZE * zoomScale; 188 | 189 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 190 | sz = (int)Elements.size(); 191 | ImVec2 s_pos(center.x + camPos.x * zoomScale - sz* cell_size * 0.5f , 192 | center.y + camPos.y * zoomScale - cell_size * 0.5f); 193 | ImVec2 cur_pos(s_pos); 194 | for (int i = 0; i < sz; i++) 195 | { 196 | std::string CurNum; 197 | int temp = Elements[i]; 198 | while (temp) { 199 | CurNum.push_back(char((temp % 10) + '0')); 200 | temp /= 10; 201 | } 202 | ImVec2 textSize = ImGui::CalcTextSize(CurNum.c_str()); 203 | ImVec2 pos((cur_pos.x + (std::max(cell_size, textSize.x) - textSize.x) * 0.5f), (cur_pos.y + (cell_size - textSize.y) * 0.5f)); 204 | ImU32 col = IM_COL32(255, 255, 255, 255); 205 | draw_list->AddRectFilled(cur_pos, ImVec2(cur_pos.x + std::max(cell_size, textSize.x), 206 | cur_pos.y + cell_size), IM_COL32(100, 100, 100, 255)); 207 | draw_list->AddText(pos, col, CurNum.c_str()); 208 | cur_pos.x += std::max(cell_size, textSize.x) + separator_size; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /C-DS/Markdown.cpp: -------------------------------------------------------------------------------- 1 | #include "Markdown.h" 2 | 3 | // Following includes for Windows LinkCallback 4 | #define WIN32_LEAN_AND_MEAN 5 | #include 6 | #include "Shellapi.h" 7 | #include "Image.h" 8 | 9 | #include 10 | 11 | 12 | static ImGui::MarkdownConfig mdConfig; 13 | 14 | static ImFont* H1 = NULL; 15 | static ImFont* H2 = NULL; 16 | static ImFont* H3 = NULL; 17 | static ImFont* bold = NULL; 18 | static ImFont* italic = NULL; 19 | 20 | std::unordered_map cached_images; 21 | 22 | void LinkCallback(ImGui::MarkdownLinkCallbackData data_) 23 | { 24 | std::string url(data_.link, data_.linkLength); 25 | if (!data_.isImage) 26 | { 27 | ShellExecuteA(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL); 28 | } 29 | } 30 | 31 | ImGui::MarkdownImageData ImageCallback(ImGui::MarkdownLinkCallbackData data_) 32 | { 33 | GLuint textureID;; 34 | int width, height; 35 | std::string path; 36 | 37 | for (int i = 0; i < data_.linkLength; i++) 38 | path.push_back(data_.link[i]); 39 | 40 | if (!cached_images.count(path)) { 41 | image_imp::loadImage(path.c_str(), &textureID, &width, &height); 42 | 43 | ImGui::MarkdownImageData imageDataResult; 44 | 45 | imageDataResult.isValid = true; 46 | imageDataResult.useLinkCallback = false; 47 | imageDataResult.user_texture_id = reinterpret_cast(static_cast(textureID));; 48 | imageDataResult.original_size = ImVec2((float)width, (float)height); 49 | 50 | cached_images[path] = imageDataResult; 51 | } 52 | 53 | ImGui::MarkdownImageData& imageDataResult = cached_images[path]; 54 | 55 | // For image resize when available size.x > image width, add 56 | ImVec2 const availableSize = ImGui::GetContentRegionAvail(); 57 | if (imageDataResult.original_size.x > availableSize.x) 58 | { 59 | float const ratio = imageDataResult.original_size.y / imageDataResult.original_size.x; 60 | imageDataResult.size.x = availableSize.x; 61 | imageDataResult.size.y = availableSize.x * ratio; 62 | } 63 | else 64 | { 65 | imageDataResult.size = imageDataResult.original_size; 66 | } 67 | 68 | return imageDataResult; 69 | } 70 | 71 | void LoadFonts(float fontSize_) 72 | { 73 | ImGuiIO& io = ImGui::GetIO(); 74 | io.Fonts->Clear(); 75 | // Base font 76 | ImFont* customFont = io.Fonts->AddFontFromFileTTF("Resources\\mainFont.ttf", fontSize_); 77 | 78 | // Set custom font as default 79 | io.FontDefault = customFont; 80 | 81 | // Bold headings H2 and H3 82 | H2 = H3 = io.Fonts->AddFontFromFileTTF("Resources\\mainFont-bold.ttf", fontSize_ * 1.1f); 83 | 84 | // bold heading H1 85 | H1 = io.Fonts->AddFontFromFileTTF("Resources\\mainFont-bold.ttf", fontSize_ * 1.2f); 86 | 87 | 88 | italic = io.Fonts->AddFontFromFileTTF("Resources\\mainFont-italic.ttf", fontSize_); 89 | bold = io.Fonts->AddFontFromFileTTF("Resources\\mainFont-bold.ttf", fontSize_); 90 | } 91 | 92 | void MarkdownFormatCallback(const ImGui::MarkdownFormatInfo& markdownFormatInfo_, bool start_) 93 | { 94 | // Call the default first so any settings can be overwritten by our implementation. 95 | // Alternatively could be called or not called in a switch statement on a case by case basis. 96 | // See defaultMarkdownFormatCallback definition for furhter examples of how to use it. 97 | //ImGui::defaultMarkdownFormatCallback(markdownFormatInfo_, start_); 98 | 99 | switch (markdownFormatInfo_.type) 100 | { 101 | case ImGui::MarkdownFormatType::NORMAL_TEXT: 102 | break; 103 | case ImGui::MarkdownFormatType::EMPHASIS: 104 | { 105 | if (markdownFormatInfo_.level == 1) 106 | { 107 | // normal emphasis 108 | if (start_) 109 | { 110 | ImGui::PushFont(italic); 111 | } 112 | else 113 | { 114 | ImGui::PopFont(); 115 | } 116 | } 117 | else 118 | { 119 | // strong emphasis 120 | if (start_) 121 | { 122 | ImGui::PushFont(bold); 123 | } 124 | else 125 | { 126 | ImGui::PopFont(); 127 | } 128 | } 129 | break; 130 | } 131 | case ImGui::MarkdownFormatType::HEADING: 132 | { 133 | ImGui::MarkdownHeadingFormat fmt; 134 | if (markdownFormatInfo_.level > ImGui::MarkdownConfig::NUMHEADINGS) 135 | { 136 | fmt = markdownFormatInfo_.config->headingFormats[ImGui::MarkdownConfig::NUMHEADINGS - 1]; 137 | } 138 | else 139 | { 140 | fmt = markdownFormatInfo_.config->headingFormats[markdownFormatInfo_.level - 1]; 141 | } 142 | if (start_) 143 | { 144 | if (fmt.font) 145 | { 146 | ImGui::PushFont(fmt.font); 147 | } 148 | ImGui::NewLine(); 149 | } 150 | else 151 | { 152 | if (fmt.separator) 153 | { 154 | ImGui::Separator(); 155 | ImGui::NewLine(); 156 | } 157 | else 158 | { 159 | ImGui::NewLine(); 160 | } 161 | if (fmt.font) 162 | { 163 | ImGui::PopFont(); 164 | } 165 | } 166 | break; 167 | } 168 | case ImGui::MarkdownFormatType::UNORDERED_LIST: 169 | break; 170 | case ImGui::MarkdownFormatType::LINK: 171 | if (start_) 172 | { 173 | ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_ButtonHovered]); 174 | } 175 | else 176 | { 177 | ImGui::PopStyleColor(); 178 | if (markdownFormatInfo_.itemHovered) 179 | { 180 | SetCursor(::LoadCursor(NULL, IDC_HAND)); 181 | ImGui::UnderLine(ImGui::GetStyle().Colors[ImGuiCol_ButtonHovered]); 182 | } 183 | else 184 | { 185 | ImGui::UnderLine(ImGui::GetStyle().Colors[ImGuiCol_Button]); 186 | } 187 | } 188 | break; 189 | 190 | default: 191 | break; 192 | } 193 | } 194 | 195 | void Markdown(const std::string& markdown_) 196 | { 197 | // You can make your own Markdown function with your prefered string container and markdown config. 198 | // > C++14 can use ImGui::MarkdownConfig mdConfig{ LinkCallback, NULL, ImageCallback, ICON_FA_LINK, { { H1, true }, { H2, true }, { H3, false } }, NULL }; 199 | mdConfig.linkCallback = LinkCallback; 200 | mdConfig.tooltipCallback = NULL; 201 | mdConfig.imageCallback = ImageCallback; 202 | //mdConfig.linkIcon = ICON_FA_LINK; 203 | mdConfig.headingFormats[0] = { H1, true }; 204 | mdConfig.headingFormats[1] = { H2, true }; 205 | mdConfig.headingFormats[2] = { H3, false }; 206 | mdConfig.userData = NULL; 207 | mdConfig.formatCallback = MarkdownFormatCallback; 208 | ImGui::Markdown(markdown_.c_str(), markdown_.length(), mdConfig); 209 | } 210 | 211 | void clearCachedImages() 212 | { 213 | cached_images.clear(); 214 | } 215 | -------------------------------------------------------------------------------- /C-DS/C-DS.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {1b95ce2c-eb31-48e8-8e3f-31ca49fabc81} 18 | 19 | 20 | {460248d6-7ab6-43db-8780-260187c3bf78} 21 | 22 | 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files\imgui 32 | 33 | 34 | Source Files\imgui 35 | 36 | 37 | Source Files\imgui 38 | 39 | 40 | Source Files\imgui 41 | 42 | 43 | Source Files\imgui 44 | 45 | 46 | Source Files\imgui 47 | 48 | 49 | Source Files\imgui 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | Source Files 68 | 69 | 70 | Source Files 71 | 72 | 73 | Source Files 74 | 75 | 76 | Source Files 77 | 78 | 79 | Source Files 80 | 81 | 82 | Source Files 83 | 84 | 85 | Source Files 86 | 87 | 88 | Source Files 89 | 90 | 91 | Source Files 92 | 93 | 94 | Source Files 95 | 96 | 97 | Source Files 98 | 99 | 100 | Source Files 101 | 102 | 103 | Source Files 104 | 105 | 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files\imgui 112 | 113 | 114 | Header Files\imgui 115 | 116 | 117 | Header Files\imgui 118 | 119 | 120 | Header Files\imgui 121 | 122 | 123 | Header Files\imgui 124 | 125 | 126 | Header Files\imgui 127 | 128 | 129 | Header Files\imgui 130 | 131 | 132 | Header Files\imgui 133 | 134 | 135 | Header Files\imgui 136 | 137 | 138 | Header Files 139 | 140 | 141 | Header Files 142 | 143 | 144 | Header Files 145 | 146 | 147 | Header Files 148 | 149 | 150 | Header Files 151 | 152 | 153 | Header Files 154 | 155 | 156 | Header Files 157 | 158 | 159 | Header Files 160 | 161 | 162 | Header Files 163 | 164 | 165 | Header Files 166 | 167 | 168 | Header Files 169 | 170 | 171 | Header Files 172 | 173 | 174 | Header Files 175 | 176 | 177 | Header Files 178 | 179 | 180 | Header Files 181 | 182 | 183 | Header Files 184 | 185 | 186 | Header Files 187 | 188 | 189 | Header Files 190 | 191 | 192 | Header Files 193 | 194 | 195 | -------------------------------------------------------------------------------- /C-DS/MainMenu.cpp: -------------------------------------------------------------------------------- 1 | #include "MainMenu.h" 2 | #include 3 | #include "Image.h" 4 | 5 | #include 6 | 7 | bool MainMenu::ImageButtonWithText(const char* label, ImTextureID texId, const ImVec2& imageSize) { 8 | 9 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 10 | ImGuiIO* io = &ImGui::GetIO(); 11 | ImGuiContext& g = *GImGui; 12 | const ImGuiStyle& style = g.Style; 13 | 14 | if (window->SkipItems) 15 | return false; 16 | 17 | ImVec2 size = imageSize; 18 | size.x -= 2.f * style.FramePadding.x; 19 | size.y -= 2.f * style.FramePadding.y; 20 | 21 | if (size.x <= 0 && size.y <= 0) { size.x = size.y = ImGui::GetTextLineHeightWithSpacing(); } 22 | else { 23 | if (size.x <= 0) size.x = size.y; 24 | else if (size.y <= 0) size.y = size.x; 25 | 26 | size.x *= window->FontWindowScale * ImGui::GetIO().FontGlobalScale; 27 | size.y *= window->FontWindowScale * ImGui::GetIO().FontGlobalScale; 28 | } 29 | 30 | 31 | const ImGuiID id = window->GetID(label); 32 | const ImVec2 textSize = ImGui::CalcTextSize(label, NULL, true); 33 | const bool hasText = textSize.x > 0; 34 | 35 | const float innerSpacing = hasText ? style.ItemInnerSpacing.x : 0.f; 36 | const ImVec2 padding = style.FramePadding; 37 | const ImVec2 totalSizeWithoutPadding(size.x > textSize.x ? size.x : textSize.x, size.y + innerSpacing + textSize.y); 38 | 39 | const ImRect bb(window->DC.CursorPos, ImVec2(window->DC.CursorPos.x + totalSizeWithoutPadding.x + padding.x * 2, window->DC.CursorPos.y + totalSizeWithoutPadding.y + padding.y * 2)); 40 | 41 | 42 | ImVec2 start(0, 0); 43 | start = ImVec2(window->DC.CursorPos.x + padding.x, window->DC.CursorPos.y + padding.y); if (size.x < textSize.x) start.x += (textSize.x - size.x) * .5f; 44 | const ImRect image_bb(start, ImVec2(start.x + size.x, start.y + size.y)); 45 | 46 | start = ImVec2(window->DC.CursorPos.x + padding.x, window->DC.CursorPos.y + padding.y); if (size.x > textSize.x) start.x += (size.x - textSize.x) * .5f; start.y += size.y + innerSpacing; 47 | 48 | ImGui::ItemSize(bb); 49 | if (!ImGui::ItemAdd(bb, id)) 50 | return false; 51 | 52 | bool hovered = false, held = false; 53 | bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held); 54 | 55 | // Render 56 | const ImU32 col = ImGui::GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); 57 | ImGui::RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); 58 | 59 | window->DrawList->AddImageRounded(texId, image_bb.Min, image_bb.Max, ImVec2(0, 0), ImVec2(1, 1), ImGui::GetColorU32(ImVec4(1, 1, 1, 1)), style.FrameRounding); 60 | 61 | if (textSize.x > 0) ImGui::RenderText(start, label); 62 | 63 | return pressed; 64 | } 65 | 66 | MainMenu::MainMenu(std::string name, int& state, float& GuiScale, bool& settingsEnabled, int& colorMode) 67 | : GrandWindow(name, state, GuiScale, settingsEnabled, colorMode) 68 | { 69 | 70 | buttons_cnt = (sizeof buttons) / (sizeof(buttons[0])); 71 | 72 | for (auto& cur_button : buttons) { 73 | if (!image_imp::loadImage(cur_button.imagePath.c_str(), &cur_button.textureID, &cur_button.imageWidth, &cur_button.imageHeight)) { 74 | std::cout << "failed to load image\n"; 75 | } 76 | } 77 | 78 | image_imp::loadImage("Resources\\LogoDark.png", &logoTextureID[0], &logo_width[0], &logo_height[0]); 79 | image_imp::loadImage("Resources\\LogoLight.png", &logoTextureID[1], &logo_width[1], &logo_height[1]); 80 | 81 | } 82 | 83 | MainMenu::~MainMenu() 84 | { 85 | 86 | } 87 | 88 | void MainMenu::updateButtons() 89 | { 90 | ImVec2 item_spacing = ImGui::GetStyle().ItemSpacing; 91 | float usabe_area = viewport->WorkSize.x * 0.8f; 92 | int button_idx = 0, per_row = std::max((int)floor(viewport->WorkSize.x / (BUTTON_WIDTH * GuiScale + item_spacing.x)), 1); 93 | 94 | 95 | float button_width = (usabe_area / (float)per_row - item_spacing.x) / GuiScale, text_height = 45.f * GuiScale; 96 | 97 | if (per_row > buttons_cnt) { 98 | button_width = BUTTON_WIDTH; 99 | } 100 | 101 | float button_height = button_width * 3.f / 4.f; 102 | 103 | int row_idx = 1; 104 | 105 | ImVec2 pos(viewport->WorkPos.x + (viewport->WorkSize.x - usabe_area) * 0.5f, ImGui::GetCursorPosY()); 106 | 107 | if (per_row > buttons_cnt) 108 | ImGui::SetCursorPosX(viewport->WorkPos.x + (viewport->WorkSize.x - ((button_width * GuiScale + item_spacing.x) * buttons_cnt)) * 0.5f); 109 | else 110 | ImGui::SetCursorPosX(pos.x); 111 | 112 | 113 | if (((buttons_cnt + per_row - 1) / per_row) * (button_height * GuiScale + text_height + item_spacing.y) + 50.f * GuiScale < viewport->WorkSize.y - pos.y) { 114 | pos.y += (viewport->WorkSize.y - pos.y - ((buttons_cnt + per_row - 1) / per_row) * (button_height * GuiScale + text_height + item_spacing.y)) * 0.5f; 115 | } 116 | 117 | ImGui::SetCursorPosY(pos.y); 118 | 119 | 120 | while (button_idx < buttons_cnt) { 121 | if (ImageButtonWithText(buttons[button_idx].label.c_str(), (void*)(intptr_t)buttons[button_idx].textureID, ImVec2(button_width * 1.5f, button_height * 1.5f))) { 122 | state = buttons[button_idx].stateID; 123 | } 124 | if (row_idx == per_row) { 125 | row_idx = 1; 126 | pos.y += button_height * GuiScale + text_height + item_spacing.y; 127 | 128 | int rem = buttons_cnt - button_idx - 1; 129 | if (rem < per_row) 130 | ImGui::SetCursorPosX(viewport->WorkPos.x + (viewport->WorkSize.x - ((button_width * GuiScale + item_spacing.x) * rem)) * 0.5f); 131 | else 132 | ImGui::SetCursorPosX(pos.x); 133 | 134 | ImGui::SetCursorPosY(pos.y); 135 | } 136 | else { 137 | ImGui::SameLine(); 138 | row_idx++; 139 | } 140 | button_idx++; 141 | } 142 | } 143 | 144 | void MainMenu::drawLogo() 145 | { 146 | float logoScale = GuiScale; 147 | 148 | float logo_space = 300.f * GuiScale; 149 | 150 | if (logo_space > viewport->WorkSize.y * 2.f / 5.f) { 151 | logoScale = std::max(viewport->WorkSize.y * 2.f / 5.f, 100.f) / logo_space; 152 | logo_space = std::max(viewport->WorkSize.y * 2.f / 5.f, 100.f); 153 | } 154 | 155 | ImVec2 logo_size(logo_space * logo_width[colorMode] / logo_height[colorMode], logo_space); 156 | 157 | if (logo_size.x > (viewport->WorkSize.x - ImGui::GetStyle().ScrollbarSize)) { 158 | logoScale = ((viewport->WorkSize.x - ImGui::GetStyle().ScrollbarSize) * logo_height[colorMode] / logo_width[colorMode]) / (300.f * GuiScale); 159 | logo_size = ImVec2((viewport->WorkSize.x - ImGui::GetStyle().ScrollbarSize), (viewport->WorkSize.x - ImGui::GetStyle().ScrollbarSize) * logo_height[colorMode] / logo_width[colorMode]); 160 | } 161 | 162 | ImGui::SetCursorPosX(viewport->WorkPos.x + viewport->WorkSize.x - 130.f * GuiScale); 163 | 164 | if (ImGui::Button("Settings")) { 165 | settingsEnabled = true; 166 | } 167 | 168 | ImGui::SetCursorPosX(viewport->WorkPos.x + (viewport->WorkSize.x - logo_size.x) * 0.5f); 169 | ImGui::Image((void*)(intptr_t)logoTextureID[colorMode], logo_size); 170 | } 171 | 172 | void MainMenu::update() 173 | { 174 | 175 | ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f); 176 | ImGui::SetNextWindowPos(viewport->WorkPos); 177 | ImGui::SetNextWindowSize(viewport->WorkSize); 178 | 179 | ImGui::Begin(getName().c_str(), NULL, flags); 180 | 181 | drawLogo(); 182 | updateButtons(); 183 | 184 | ImGui::End(); 185 | ImGui::PopStyleVar(); 186 | 187 | } 188 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // DEAR IMGUI COMPILE-TIME OPTIONS 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. 19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 21 | 22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 26 | //#define IMGUI_API __declspec( dllexport ) 27 | //#define IMGUI_API __declspec( dllimport ) 28 | 29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names. 30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87+ disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This is automatically done by IMGUI_DISABLE_OBSOLETE_FUNCTIONS. 32 | 33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools. 34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. 35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. 37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() will be empty. 38 | 39 | //---- Don't implement some functions to reduce linkage requirements. 40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) 42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) 43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME). 44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 51 | 52 | //---- Include imgui_user.h at the end of imgui.h as a convenience 53 | // May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included. 54 | //#define IMGUI_INCLUDE_IMGUI_USER_H 55 | //#define IMGUI_USER_H_FILENAME "my_folder/my_imgui_user.h" 56 | 57 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 58 | //#define IMGUI_USE_BGRA_PACKED_COLOR 59 | 60 | //---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 61 | //#define IMGUI_USE_WCHAR32 62 | 63 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 64 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 65 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 66 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 67 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined. 68 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 69 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 70 | //#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined. 71 | 72 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 73 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. 74 | //#define IMGUI_USE_STB_SPRINTF 75 | 76 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 77 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 78 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 79 | //#define IMGUI_ENABLE_FREETYPE 80 | 81 | //---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT) 82 | // Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided). 83 | // Only works in combination with IMGUI_ENABLE_FREETYPE. 84 | // (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement) 85 | //#define IMGUI_ENABLE_FREETYPE_LUNASVG 86 | 87 | //---- Use stb_truetype to build and rasterize the font atlas (default) 88 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 89 | //#define IMGUI_ENABLE_STB_TRUETYPE 90 | 91 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 92 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 93 | /* 94 | #define IM_VEC2_CLASS_EXTRA \ 95 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 96 | operator MyVec2() const { return MyVec2(x,y); } 97 | 98 | #define IM_VEC4_CLASS_EXTRA \ 99 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 100 | operator MyVec4() const { return MyVec4(x,y,z,w); } 101 | */ 102 | //---- ...Or use Dear ImGui's own very basic math operators. 103 | //#define IMGUI_DEFINE_MATH_OPERATORS 104 | 105 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 106 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 107 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 108 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 109 | //#define ImDrawIdx unsigned int 110 | 111 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 112 | //struct ImDrawList; 113 | //struct ImDrawCmd; 114 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 115 | //#define ImDrawCallback MyImDrawCallback 116 | 117 | //---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase) 118 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 119 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 120 | //#define IM_DEBUG_BREAK __debugbreak() 121 | 122 | //---- Debug Tools: Enable slower asserts 123 | //#define IMGUI_DEBUG_PARANOID 124 | 125 | //---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files) 126 | /* 127 | namespace ImGui 128 | { 129 | void MyFunction(const char* name, MyMatrix44* mtx); 130 | } 131 | */ 132 | -------------------------------------------------------------------------------- /C-DS/Tree.cpp: -------------------------------------------------------------------------------- 1 | #include "Tree.h" 2 | #include 3 | 4 | ImU32 Tree::ContrastingColor(ImU32 col) 5 | { 6 | ImVec4 ret = ImGui::ColorConvertU32ToFloat4(col); 7 | 8 | ret.x = std::min(ret.x + 50.f, 255.f); 9 | ret.y = std::min(ret.y + 50.f, 255.f); 10 | ret.z = std::min(ret.z + 50.f, 255.f); 11 | 12 | return ImGui::ColorConvertFloat4ToU32(ret); 13 | } 14 | 15 | void Tree::controlsUpdate() 16 | { 17 | ImVec2 controlsWinSize(std::min(450.f * GuiScale, viewport->WorkSize.x - ImGui::GetStyle().WindowPadding.x), std::min(750.f * GuiScale, viewport->WorkSize.y - 2 * ImGui::GetStyle().WindowPadding.y)); 18 | ImVec2 controlsWinPos(viewport->Size.x - controlsWinSize.x - ImGui::GetStyle().WindowPadding.x, viewport->Size.y - controlsWinSize.y - ImGui::GetStyle().WindowPadding.y); 19 | 20 | ImGui::SetNextWindowSize(controlsWinSize); 21 | ImGui::SetNextWindowPos(controlsWinPos); 22 | 23 | ImGui::Begin("Controls", NULL, controls_flags); 24 | 25 | if (ImGui::Button("Back")) 26 | state = 0; 27 | 28 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 29 | 30 | ImGui::Text("Tools:"); 31 | 32 | ImGui::RadioButton("Move Nodes", &cur_tool, 0); 33 | 34 | ImGui::RadioButton("Move Camera", &cur_tool, 1); 35 | if (camTarget.x != 0 || camTarget.y != 0) { 36 | ImGui::SameLine(); 37 | if (ImGui::Button("Reset##Move_Cam")) 38 | camTarget = { 0, 0 }; 39 | } 40 | 41 | ImGui::RadioButton("View Component", &cur_tool, 2); 42 | 43 | if (viewComponent.size()) { 44 | ImGui::SameLine(); 45 | if (ImGui::Button("Reset##View_Component")) 46 | viewComponent.clear(); 47 | } 48 | 49 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 50 | 51 | 52 | 53 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 54 | 55 | 56 | 57 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 58 | 59 | ImGui::InputText("##Enter_Node", add_node_text, IM_ARRAYSIZE(add_node_text)); 60 | 61 | //ImGui::SameLine(); 62 | 63 | int itemCnt = 0; 64 | static int cur_p = 0; 65 | const char** items = new const char* [nodes.size() + 1]; 66 | 67 | items[itemCnt++] = ""; 68 | 69 | for (auto node : nodes) { 70 | char* temparr = new char[node.first.size() + 1]; 71 | for (int i = 0; i < node.first.size(); i++) 72 | temparr[i] = node.first[i]; 73 | temparr[node.first.size()] = '\0'; 74 | 75 | items[itemCnt++] = temparr; 76 | } 77 | 78 | if (root == "\0") { 79 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 80 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 81 | } 82 | 83 | ImGui::Combo("##u", &cur_p, items, itemCnt); 84 | 85 | if (root == "\0") { 86 | ImGui::PopItemFlag(); 87 | ImGui::PopStyleVar(); 88 | } 89 | 90 | std::string cur_p_str = items[cur_p]; 91 | 92 | for (int i = 1; i < itemCnt; i++) 93 | delete[] items[i]; 94 | 95 | if ((root != "\0" && cur_p == 0) || add_node_text[0] == '\0') { 96 | disabled = true; 97 | } 98 | if (disabled) { 99 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 100 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 101 | } 102 | 103 | if (ImGui::Button("Insert")) { 104 | std::string curNode; 105 | char* ptr = add_node_text; 106 | while (*ptr != '\0') { 107 | curNode.push_back(*ptr); 108 | ptr++; 109 | } 110 | 111 | if (curNode.size() > 0) { 112 | 113 | if (root == "\0") { 114 | root = cur_p_str = curNode; 115 | nodes[root].color = ROOT_NODE_COLOR; 116 | nodes[root].fixed = true; 117 | } 118 | addNode(curNode, cur_p_str); 119 | curNode.clear(); 120 | } 121 | cur_p = 0; 122 | memset(add_node_text, 0, sizeof add_node_text); 123 | } 124 | 125 | if (disabled) { 126 | ImGui::PopItemFlag(); 127 | ImGui::PopStyleVar(); 128 | } 129 | 130 | disabled = false; 131 | 132 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 133 | 134 | ImGui::SliderFloat("Speed", &speed, DSU_MIN_SPEED, DSU_MAX_SPEED, "%.1fx", ImGuiSliderFlags_AlwaysClamp); 135 | 136 | ImGui::End(); 137 | } 138 | 139 | float Tree::calcDist(float x1, float y1, float x2, float y2) 140 | { 141 | return sqrtf((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); 142 | } 143 | 144 | void Tree::graphUpdate() 145 | { 146 | 147 | updateCenter(); 148 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 149 | 150 | const float cf = 0.55f; // center attraction 151 | const float k = 3.f; // Spring constant 152 | const float c = 8000.f; // Repulsion constant 153 | const float dampening = 0.85f; // Dampening factor 154 | 155 | for (auto& node : nodes) { 156 | 157 | auto& u = node.second; 158 | u.fx -= cf * u.x; 159 | u.fy -= cf * u.y; 160 | 161 | for (auto& otherNode : nodes) { 162 | if (node.first != otherNode.first) { 163 | auto& v = otherNode.second; 164 | 165 | float d = calcDist(u.x, u.y, v.x, v.y); 166 | float dx = v.x - u.x; 167 | float dy = v.y - u.y; 168 | float force = c / (d * d); 169 | 170 | u.fx -= force * dx; 171 | u.fy -= force * dy; 172 | } 173 | } 174 | } 175 | 176 | for (auto& node : nodes) { 177 | if (node.first != parent[node.first]) { 178 | auto& u = nodes[node.first]; 179 | auto& v = nodes[parent[node.first]]; 180 | 181 | float dx = v.x - u.x; 182 | float dy = v.y - u.y; 183 | float d = calcDist(u.x, u.y, v.x, v.y); 184 | 185 | float force = k * (d - EDGE_LENGTH); 186 | 187 | u.fx += force * dx / d; 188 | u.fy += force * dy / d; 189 | v.fx -= force * dx / d; 190 | v.fy -= force * dy / d; 191 | } 192 | } 193 | 194 | for (auto& node : nodes) { 195 | ImVec2 pos; 196 | pos.x = center.x + (camPos.x + node.second.x) * zoomScale; 197 | pos.y = center.y + (camPos.y + node.second.y) * zoomScale; 198 | 199 | float dist = calcDist(pos.x, pos.y, io->MousePos.x, io->MousePos.y); 200 | 201 | if (ImGui::IsMouseDown(0) && dragging.empty() && dist <= VERTEX_RADIUS && ImGui::IsWindowHovered() && cur_tool == 0) { 202 | dragging = node.first; 203 | } 204 | else if ((!ImGui::IsWindowFocused() || !ImGui::IsMouseDown(0 || cur_tool != 0)) && !dragging.empty()) { 205 | dragging.clear(); 206 | } 207 | /* 208 | if (ImGui::IsMouseDoubleClicked(0) && dist <= VERTEX_RADIUS && ImGui::IsWindowHovered() && cur_tool == 0) { 209 | node.second.fixed = !node.second.fixed; 210 | } 211 | */ 212 | if (ImGui::IsMouseDown(0) && dist <= VERTEX_RADIUS && ImGui::IsWindowHovered() && cur_tool == 2) { 213 | if (!leftClickPressed) { 214 | viewComponent = node.first; 215 | } 216 | } 217 | /* 218 | if (node.second.searching) { 219 | node.second.color = VIS_VERT_COL; 220 | } 221 | else if (sameGroup(node.first, viewComponent)) { 222 | node.second.color = COMP_VERT_COL; 223 | } 224 | else 225 | node.second.color = DEFAULT_VERT_COL; 226 | */ 227 | 228 | if (dragging == node.first) { 229 | node.second.fx = node.second.fy = 0; 230 | node.second.x += io->MouseDelta.x / zoomScale; 231 | node.second.y += io->MouseDelta.y / zoomScale; 232 | continue; 233 | } 234 | if (node.second.fixed) { 235 | node.second.fx = node.second.fy = 0; 236 | continue; 237 | } 238 | node.second.x += node.second.fx * io->DeltaTime; 239 | node.second.y += node.second.fy * io->DeltaTime; 240 | node.second.fx *= dampening; 241 | node.second.fy *= dampening; 242 | } 243 | 244 | if (ImGui::IsMouseDown(0) && dragging.empty() && ImGui::IsWindowFocused() && cur_tool == 0) { 245 | dragging = char(2); 246 | } 247 | 248 | for (auto& node : nodes) 249 | if (parent.count(node.first)) 250 | drawEdge(draw_list, node.first, parent[node.first]); 251 | 252 | for (auto& node : nodes) { 253 | ImVec2 textCenter = ImGui::CalcTextSize(node.first.c_str()); 254 | textCenter.x /= 2.f; 255 | textCenter.y /= 2.f; 256 | 257 | draw_list->AddCircleFilled(ImVec2(center.x + (camPos.x + node.second.x) * zoomScale, center.y + (camPos.y + node.second.y) * zoomScale), VERTEX_RADIUS, node.second.color); 258 | if (node.second.fixed) 259 | draw_list->AddCircle(ImVec2(center.x + (camPos.x + node.second.x) * zoomScale, center.y + (camPos.y + node.second.y) * zoomScale), VERTEX_RADIUS, FIXED_NODE_COLOR, 100, 5.f * zoomScale); 260 | draw_list->AddText(ImVec2(center.x + (camPos.x + node.second.x) * zoomScale - textCenter.x, center.y + (camPos.y + node.second.y) * zoomScale - textCenter.y), ContrastingColor(node.second.color), node.first.c_str()); 261 | } 262 | 263 | if (ImGui::IsMouseDown(0)) 264 | leftClickPressed = true; 265 | else 266 | leftClickPressed = false; 267 | 268 | } 269 | 270 | void Tree::drawEdge(ImDrawList* draw_list, const std::string u, const std::string v) 271 | { 272 | updateCenter(); 273 | 274 | ImVec2 from = ImVec2(center.x + (camPos.x + nodes[v].x) * zoomScale, center.y + (camPos.y + nodes[v].y) * zoomScale); 275 | ImVec2 to = ImVec2(center.x + (camPos.x + nodes[u].x) * zoomScale, center.y + (camPos.y + nodes[u].y) * zoomScale); 276 | 277 | //const ImU32 color = edge.color; 278 | const ImU32 color = ImGui::GetColorU32(IM_COL32(200, 200, 200, 255)); 279 | const float thickness = 5.f * zoomScale; 280 | 281 | ImVec2 dir = ImVec2(to.x - from.x, to.y - from.y); 282 | float length = calcDist(from.x, from.y, to.x, to.y); 283 | dir.x /= length; 284 | dir.y /= length; 285 | 286 | const float headSize = 15.f * zoomScale; 287 | to.x -= dir.x * VERTEX_RADIUS; 288 | to.y -= dir.y * VERTEX_RADIUS; 289 | from.x += dir.x * VERTEX_RADIUS; 290 | from.y += dir.y * VERTEX_RADIUS; 291 | 292 | ImVec2 p1 = ImVec2(to.x - dir.x * headSize - dir.y * headSize, to.y - dir.y * headSize + dir.x * headSize); 293 | ImVec2 p2 = ImVec2(to.x - dir.x * headSize + dir.y * headSize, to.y - dir.y * headSize - dir.x * headSize); 294 | draw_list->AddTriangleFilled(p1, p2, to, color); 295 | 296 | to.x -= dir.x * headSize / 2; 297 | to.y -= dir.y * headSize / 2; 298 | from.x += dir.x * headSize / 2; 299 | from.y += dir.y * headSize / 2; 300 | 301 | draw_list->AddLine(from, to, color, thickness); 302 | 303 | } 304 | 305 | void Tree::addNode(std::string u, std::string p) 306 | { 307 | nodes[u]; 308 | parent[u] = p; 309 | } 310 | Tree::Tree(std::string name, int& state, float& GuiScale, bool& settingsEnabled, int& colorMode) 311 | : GrandWindow(name, state, GuiScale, settingsEnabled, colorMode) 312 | { 313 | 314 | } 315 | 316 | Tree::~Tree() 317 | { 318 | 319 | } 320 | 321 | void Tree::update() 322 | { 323 | ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f); 324 | ImGui::SetNextWindowPos(viewport->WorkPos); 325 | ImGui::SetNextWindowSize(viewport->WorkSize); 326 | 327 | ImGui::Begin(getName().c_str(), NULL, main_flags); 328 | 329 | ImGui::PopStyleVar(); 330 | 331 | graphUpdate(); 332 | 333 | if ((ImGui::IsWindowHovered() || movingCam) && ((ImGui::IsMouseDown(0) && cur_tool == 1) || ImGui::IsMouseDown(2))) { 334 | movingCam = true; 335 | camPos.x += io->MouseDelta.x / zoomScale; 336 | camPos.y += io->MouseDelta.y / zoomScale; 337 | camTarget.x += io->MouseDelta.x / zoomScale; 338 | camTarget.y += io->MouseDelta.y / zoomScale; 339 | } 340 | else if (!(ImGui::IsMouseDown(0) && cur_tool == 1) && !ImGui::IsMouseDown(2)) { 341 | movingCam = false; 342 | } 343 | 344 | updateCam(); 345 | 346 | ImGui::End(); 347 | 348 | controlsUpdate(); 349 | 350 | } 351 | -------------------------------------------------------------------------------- /C-DS/Stack.cpp: -------------------------------------------------------------------------------- 1 | #include "Stack.h" 2 | #include 3 | #include 4 | 5 | void Stack::update() 6 | { 7 | 8 | ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f); 9 | ImGui::SetNextWindowPos(viewport->WorkPos); 10 | ImGui::SetNextWindowSize(viewport->WorkSize); 11 | 12 | ImGui::Begin(getName().c_str(), NULL, main_flags); 13 | 14 | ImGui::PopStyleVar(); 15 | 16 | drawWatermark(); 17 | 18 | stackUpdate(); 19 | 20 | if ((ImGui::IsWindowHovered() || movingCam) && ((ImGui::IsMouseDown(0) && cur_tool == 0) || ImGui::IsMouseDown(2))) { 21 | movingCam = true; 22 | camPos.x += io->MouseDelta.x / zoomScale; 23 | camPos.y += io->MouseDelta.y / zoomScale; 24 | camTarget.x += io->MouseDelta.x / zoomScale; 25 | camTarget.y += io->MouseDelta.y / zoomScale; 26 | } 27 | else if (!(ImGui::IsMouseDown(0) && cur_tool == 0) && !ImGui::IsMouseDown(2)) { 28 | movingCam = false; 29 | } 30 | 31 | updateCam(); 32 | 33 | ImGui::End(); 34 | 35 | controlsUpdate(); 36 | } 37 | 38 | Stack::Stack(std::string name, int& state, float& GuiScale, bool& settingsEnabled, int& colorMode) 39 | : GrandWindow(name, state, GuiScale, settingsEnabled, colorMode) 40 | { 41 | 42 | } 43 | 44 | Stack::~Stack() 45 | { 46 | 47 | } 48 | 49 | void Stack::getInput() 50 | { 51 | std::string curElement; 52 | char* ptr = add_element_content; 53 | while (*ptr != '\0') { 54 | if (*ptr == ',') { 55 | if (curElement.size() > 0) { 56 | pending.push(curElement); 57 | curElement.clear(); 58 | } 59 | } 60 | else 61 | curElement.push_back(*ptr); 62 | 63 | ptr++; 64 | } 65 | if (curElement.size() > 0) { 66 | pending.push(curElement); 67 | curElement.clear(); 68 | } 69 | 70 | memset(add_element_content, 0, sizeof add_element_content); 71 | } 72 | 73 | ImU32 Stack::getColor(int color_code) 74 | { 75 | switch (color_code) { 76 | case DEFAULT_CELL_COL: 77 | return colorMode ? ImGui::GetColorU32(IM_COL32(200, 200, 200, 255)) : ImGui::GetColorU32(IM_COL32(150, 150, 150, 255)); 78 | case CELL_BORDER_COL: 79 | return ImGui::GetColorU32(IM_COL32(40, 40, 40, 255)); 80 | case ARROW1_COL: 81 | return colorMode ? ImGui::GetColorU32(IM_COL32(200, 50, 50, 255)) : ImGui::GetColorU32(IM_COL32(150, 50, 50, 255)); 82 | case ARROW2_COL: 83 | return colorMode ? ImGui::GetColorU32(IM_COL32(50, 50, 200, 255)) : ImGui::GetColorU32(IM_COL32(50, 50, 150, 255)); 84 | case END_CELL_COL: 85 | return colorMode ? ImGui::GetColorU32(IM_COL32(200, 80, 80, 255)) : ImGui::GetColorU32(IM_COL32(150, 50, 50, 255)); 86 | case TEXT_COLOR: 87 | return colorMode ? ImGui::GetColorU32(IM_COL32(0, 0, 0, 255)) : ImGui::GetColorU32(IM_COL32(255, 255, 255, 255)); 88 | case TEXT_OUTLINE_COL: 89 | return colorMode ? ImGui::GetColorU32(IM_COL32(255, 255, 255, 255)) : ImGui::GetColorU32(IM_COL32(0, 0, 0, 255)); 90 | 91 | default: 92 | return ImGui::GetColorU32(IM_COL32(255, 0, 255, 255)); 93 | } 94 | } 95 | 96 | void Stack::drawText(ImVec2 pos, const char* text) 97 | { 98 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 99 | 100 | for (float x = -1; x <= 1; x++) { 101 | for (float y = -1; y <= 1; y++) { 102 | if (x == 0 && y == 0) continue; 103 | draw_list->AddText(ImVec2(pos.x + x, pos.y + y), getColor(TEXT_OUTLINE_COL), text); 104 | } 105 | } 106 | 107 | draw_list->AddText(pos, getColor(TEXT_COLOR), text); 108 | } 109 | 110 | void Stack::stackUpdate() 111 | { 112 | 113 | updateCenter(); 114 | 115 | 116 | float mxCellWidth = STACK_CELL_SIZE * zoomScale; 117 | for (int i = 0; i < currentMaxSize; i++) 118 | mxCellWidth = std::max(mxCellWidth, ImGui::CalcTextSize(content[i].c_str()).x + 15.f * zoomScale); 119 | 120 | if (~expansion) 121 | { 122 | passedTime += io->DeltaTime * speed; 123 | if (passedTime >= STACK_BASE_DELAY) { 124 | expand(); 125 | passedTime = 0.f; 126 | } 127 | 128 | drawStack(int(center.x - (mxCellWidth+ STACK_CELL_SIZE*zoomScale)/2.f), content, currentMaxSize, headpointer, mxCellWidth, 0); 129 | 130 | if (~expansion) 131 | drawStack(int(center.x + (mxCellWidth+ STACK_CELL_SIZE*zoomScale)/2.f), tempContent, currentMaxSize * 2, expansion, mxCellWidth, 1); 132 | } 133 | else 134 | { 135 | 136 | if (pending.size()) { 137 | passedTime += io->DeltaTime * speed; 138 | if (passedTime >= STACK_BASE_DELAY) { 139 | if (Push(pending.front())) 140 | pending.pop(); 141 | passedTime = 0.f; 142 | } 143 | } 144 | 145 | drawStack((int)center.x, content, currentMaxSize, headpointer, mxCellWidth, 0); 146 | } 147 | 148 | } 149 | 150 | void Stack::drawStack(int xpos, std::string temp[], int mxSz, int head, float mxCellWidth, bool inverted) 151 | { 152 | 153 | ImVec2 center((float)xpos, viewport->WorkPos.y + viewport->WorkSize.y * 0.5f); 154 | 155 | float separator_size = std::max(STACK_SEPARATOR_SIZE * zoomScale, 1.f); 156 | float cell_size = STACK_CELL_SIZE * zoomScale; 157 | 158 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 159 | 160 | float ySize = ((cell_size + separator_size) * (mxSz-2)); 161 | float headPointerY = ((cell_size + separator_size) * head) - cell_size * 0.5f; 162 | 163 | ImVec2 s_pos(center.x + camPos.x * zoomScale - mxCellWidth * 0.5f, center.y + camPos.y * zoomScale + ySize * 0.5f); 164 | 165 | if (!inverted) 166 | s_pos.y += cell_size * 0.5f; 167 | 168 | ImVec2 cur_pos(s_pos); 169 | 170 | for (int i = 0; i < mxSz; i++) 171 | { 172 | i %= mxSz; 173 | ImVec2 textSize = ImGui::CalcTextSize(temp[i].c_str()); 174 | ImVec2 pos((cur_pos.x + (mxCellWidth - textSize.x) * 0.5f), (cur_pos.y + (cell_size - textSize.y) * 0.5f)); 175 | 176 | draw_list->AddRectFilled(cur_pos, ImVec2(cur_pos.x + mxCellWidth, cur_pos.y + cell_size), getColor(DEFAULT_CELL_COL), STACK_ROUNDNESS * zoomScale); 177 | draw_list->AddRect(cur_pos, ImVec2(cur_pos.x + mxCellWidth, cur_pos.y + cell_size), getColor(CELL_BORDER_COL), STACK_ROUNDNESS * zoomScale, 0, 4.f * zoomScale); 178 | 179 | drawText(pos, temp[i].c_str()); 180 | cur_pos.y -= cell_size + separator_size; 181 | } 182 | if (!inverted) { 183 | draw_list->AddRectFilled(cur_pos, ImVec2(cur_pos.x + mxCellWidth, cur_pos.y + cell_size), getColor(END_CELL_COL), STACK_ROUNDNESS * zoomScale); 184 | draw_list->AddRect(cur_pos, ImVec2(cur_pos.x + mxCellWidth, cur_pos.y + cell_size), getColor(CELL_BORDER_COL), STACK_ROUNDNESS * zoomScale, 0, 4.f * zoomScale); 185 | } 186 | 187 | drawArrow(int(cur_pos.x), int(s_pos.y - headPointerY), (inverted ? ARROW2_COL : ARROW1_COL), inverted, mxCellWidth); 188 | } 189 | 190 | void Stack::drawArrow(int x, int y, int col, bool inverted, float mxCellWidth) 191 | { 192 | // This will be given the x and y where the head of the arrow should be 193 | updateCenter(); 194 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 195 | const float headSize = 20.f * zoomScale; 196 | const float length = 50.f * zoomScale; 197 | 198 | int sign = 1; 199 | if (inverted) { 200 | sign = -1; 201 | x += int(mxCellWidth); 202 | } 203 | 204 | ImVec2 from = ImVec2(x - sign * length, (float)y); 205 | ImVec2 to = ImVec2(x - sign * headSize, (float)y); 206 | 207 | draw_list->AddLine(from, to, getColor(col), 20.f * zoomScale); 208 | to.x += sign * headSize * 0.5f; 209 | 210 | ImVec2 p1 = ImVec2(to.x - sign * headSize, to.y + headSize); 211 | ImVec2 p2 = ImVec2(to.x - sign * headSize, to.y - headSize); 212 | 213 | draw_list->AddTriangleFilled(p1, p2, to, getColor(col)); 214 | } 215 | 216 | bool Stack::Push(std::string value) 217 | { 218 | if (sz == currentMaxSize) 219 | { 220 | if (sz == STACK_MAX_SIZE) 221 | return 1; 222 | 223 | expand(); 224 | return 0; 225 | } 226 | 227 | content[headpointer] = value; 228 | 229 | headpointer++; 230 | sz++; 231 | 232 | return 1; 233 | } 234 | 235 | void Stack::expand() 236 | { 237 | 238 | if (currentMaxSize * 2 > STACK_MAX_SIZE) 239 | return; 240 | 241 | 242 | if (tempContent == nullptr) { 243 | tempContent = new std::string[currentMaxSize * 2]; 244 | expansion = 0; 245 | headpointer = 0; 246 | return; 247 | } 248 | 249 | if (expansion < sz) { 250 | tempContent[expansion] = content[headpointer]; 251 | headpointer++; 252 | expansion++; 253 | return; 254 | } 255 | 256 | headpointer = sz; 257 | // head for popping , tail for pushing 258 | delete[] content; 259 | content = tempContent; 260 | tempContent = nullptr; 261 | expansion = -1; 262 | currentMaxSize *= 2; 263 | } 264 | 265 | void Stack::Pop() 266 | { 267 | if (sz == 0) 268 | return; 269 | sz--; 270 | content[--headpointer] = ""; 271 | } 272 | 273 | void Stack::controlsUpdate() 274 | { 275 | 276 | ImVec2 controlsWinSize(std::min(450.f * GuiScale, viewport->WorkSize.x - ImGui::GetStyle().WindowPadding.x), std::min(340.f * GuiScale, viewport->WorkSize.y - 2 * ImGui::GetStyle().WindowPadding.y)); 277 | ImVec2 controlsWinPos(viewport->Size.x - controlsWinSize.x - ImGui::GetStyle().WindowPadding.x, viewport->Size.y - controlsWinSize.y - ImGui::GetStyle().WindowPadding.y); 278 | 279 | ImGui::SetNextWindowSize(controlsWinSize); 280 | ImGui::SetNextWindowPos(controlsWinPos); 281 | 282 | ImGui::Begin("Controls", NULL, controls_flags); 283 | 284 | if (ImGui::Button("Back")) 285 | state = 0; 286 | 287 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 288 | 289 | if (ImGui::Button("Reset Camera")) 290 | camTarget = { 0, 0 }; 291 | 292 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 293 | 294 | bool disabled = false; 295 | if (~expansion || pending.size()) { 296 | disabled = true; 297 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 298 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 299 | } 300 | 301 | ImGui::InputText("##Enter_node", add_element_content, IM_ARRAYSIZE(add_element_content)); 302 | 303 | ImGui::SameLine(); 304 | 305 | bool noPush = false; 306 | if (sz == STACK_MAX_SIZE && currentMaxSize >= STACK_MAX_SIZE && !disabled) { 307 | noPush = true; 308 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 309 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 310 | } 311 | 312 | if (ImGui::Button("Push")) { 313 | getInput(); 314 | } 315 | 316 | if (noPush) { 317 | ImGui::PopItemFlag(); 318 | ImGui::PopStyleVar(); 319 | } 320 | 321 | bool noPop = false; 322 | if (sz == 0 && !disabled) { 323 | noPop = true; 324 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 325 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 326 | } 327 | 328 | if (ImGui::Button("Pop")) { 329 | Pop(); 330 | } 331 | 332 | if (noPop) { 333 | ImGui::PopItemFlag(); 334 | ImGui::PopStyleVar(); 335 | } 336 | 337 | if (currentMaxSize >= STACK_MAX_SIZE && !disabled) { 338 | disabled = true; 339 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 340 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 341 | } 342 | 343 | if (ImGui::Button("Expand")) { 344 | expand(); 345 | } 346 | 347 | if (disabled) { 348 | ImGui::PopItemFlag(); 349 | ImGui::PopStyleVar(); 350 | } 351 | 352 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 353 | 354 | ImGui::SliderFloat("Speed", &speed, STACK_MIN_SPEED, STACK_MAX_SPEED, "%.1fx", ImGuiSliderFlags_AlwaysClamp); 355 | 356 | ImGui::End(); 357 | } -------------------------------------------------------------------------------- /C-DS/QueueVisualization.cpp: -------------------------------------------------------------------------------- 1 | #include "QueueVisualization.h" 2 | #include 3 | #include 4 | 5 | void QueueVisualization::update() 6 | { 7 | 8 | ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f); 9 | ImGui::SetNextWindowPos(viewport->WorkPos); 10 | ImGui::SetNextWindowSize(viewport->WorkSize); 11 | 12 | ImGui::Begin(getName().c_str(), NULL, main_flags); 13 | 14 | ImGui::PopStyleVar(); 15 | 16 | drawWatermark(); 17 | 18 | queueUpdate(); 19 | 20 | if ((ImGui::IsWindowHovered() || movingCam) && ((ImGui::IsMouseDown(0) && cur_tool == 0) || ImGui::IsMouseDown(2))) { 21 | movingCam = true; 22 | camPos.x += io->MouseDelta.x / zoomScale; 23 | camPos.y += io->MouseDelta.y / zoomScale; 24 | camTarget.x += io->MouseDelta.x / zoomScale; 25 | camTarget.y += io->MouseDelta.y / zoomScale; 26 | } 27 | else if (!(ImGui::IsMouseDown(0) && cur_tool == 0) && !ImGui::IsMouseDown(2)) { 28 | movingCam = false; 29 | } 30 | 31 | updateCam(); 32 | 33 | ImGui::End(); 34 | 35 | controlsUpdate(); 36 | } 37 | 38 | QueueVisualization::QueueVisualization(std::string name, int& state, float& GuiScale, bool& settingsEnabled, int& colorMode) 39 | : GrandWindow(name, state, GuiScale, settingsEnabled, colorMode) 40 | { 41 | 42 | } 43 | 44 | QueueVisualization::~QueueVisualization() 45 | { 46 | 47 | } 48 | 49 | void QueueVisualization::getInput() 50 | { 51 | std::string curElement; 52 | char* ptr = add_element_content; 53 | while (*ptr != '\0') { 54 | if (*ptr == ',') { 55 | if (curElement.size() > 0) { 56 | pending.push(curElement); 57 | curElement.clear(); 58 | } 59 | } 60 | else 61 | curElement.push_back(*ptr); 62 | 63 | ptr++; 64 | } 65 | if (curElement.size() > 0) { 66 | pending.push(curElement); 67 | curElement.clear(); 68 | } 69 | 70 | memset(add_element_content, 0, sizeof add_element_content); 71 | } 72 | 73 | ImU32 QueueVisualization::getColor(int color_code) 74 | { 75 | switch (color_code) { 76 | case DEFAULT_CELL_COL: 77 | return colorMode ? ImGui::GetColorU32(IM_COL32(200, 200, 200, 255)) : ImGui::GetColorU32(IM_COL32(150, 150, 150, 255)); 78 | case CELL_BORDER_COL: 79 | return ImGui::GetColorU32(IM_COL32(40, 40, 40, 255)); 80 | case ARROW1_COL: 81 | return colorMode ? ImGui::GetColorU32(IM_COL32(200, 50, 50, 255)) : ImGui::GetColorU32(IM_COL32(150, 50, 50, 255)); 82 | case ARROW2_COL: 83 | return colorMode ? ImGui::GetColorU32(IM_COL32(50, 50, 200, 255)) : ImGui::GetColorU32(IM_COL32(50, 50, 150, 255)); 84 | case TEXT_COLOR: 85 | return colorMode ? ImGui::GetColorU32(IM_COL32(0, 0, 0, 255)) : ImGui::GetColorU32(IM_COL32(255, 255, 255, 255)); 86 | case TEXT_OUTLINE_COL: 87 | return colorMode ? ImGui::GetColorU32(IM_COL32(255, 255, 255, 255)) : ImGui::GetColorU32(IM_COL32(0, 0, 0, 255)); 88 | 89 | default: 90 | return ImGui::GetColorU32(IM_COL32(255, 0, 255, 255)); 91 | } 92 | } 93 | 94 | void QueueVisualization::drawText(ImVec2 pos, const char* text) 95 | { 96 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 97 | 98 | for (float x = -1; x <= 1; x++) { 99 | for (float y = -1; y <= 1; y++) { 100 | if (x == 0 && y == 0) continue; 101 | draw_list->AddText(ImVec2(pos.x + x, pos.y + y), getColor(TEXT_OUTLINE_COL), text); 102 | } 103 | } 104 | 105 | draw_list->AddText(pos, getColor(TEXT_COLOR), text); 106 | } 107 | 108 | void QueueVisualization::queueUpdate() 109 | { 110 | 111 | updateCenter(); 112 | 113 | if (~expansion) 114 | { 115 | passedTime += io->DeltaTime*speed; 116 | if (passedTime >= BASE_DELAY) { 117 | expand(); 118 | passedTime = 0.f; 119 | } 120 | 121 | drawQueue(int(center.y - 2.f * CELL_SIZE * zoomScale), content, currentMaxSize, tailpointer, headpointer); 122 | if(~expansion) 123 | drawQueue(int(center.y + 2.f * CELL_SIZE * zoomScale), tempContent, currentMaxSize*2, expansion, 0); 124 | } 125 | else 126 | { 127 | 128 | if(pending.size()) { 129 | passedTime += io->DeltaTime * speed; 130 | if (passedTime >= BASE_DELAY) { 131 | if(Enqueue(pending.front())) 132 | pending.pop(); 133 | passedTime = 0.f; 134 | } 135 | } 136 | 137 | drawQueue((int)center.y, content, currentMaxSize, tailpointer, headpointer); 138 | } 139 | 140 | } 141 | 142 | void QueueVisualization::drawQueue(int ypos, std::string temp[], int mxSz, int tail, int head) 143 | { 144 | 145 | ImVec2 center(viewport->WorkPos.x + viewport->WorkSize.x * 0.5f, (float)ypos); 146 | 147 | float separator_size = std::max(SEPARATOR_SIZE * zoomScale, 1.f); 148 | float cell_size = CELL_SIZE * zoomScale; 149 | 150 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 151 | 152 | float xSize = 0.f, headPointerX = 0.f, tailPointerX = 0.f; 153 | 154 | for (int i = 0; i < mxSz; i++) 155 | { 156 | float textWidth = ImGui::CalcTextSize(temp[i].c_str()).x + 15.f * zoomScale; 157 | xSize += std::max(cell_size, textWidth) + separator_size; 158 | if (i <= head) { 159 | if (i == head) 160 | headPointerX += std::max(cell_size, textWidth) * 0.5f; 161 | else 162 | headPointerX += std::max(cell_size, textWidth) + separator_size; 163 | } 164 | if (i <= tail) { 165 | if (i == tail) 166 | tailPointerX += std::max(cell_size, textWidth) * 0.5f; 167 | else 168 | tailPointerX += std::max(cell_size, textWidth) + separator_size; 169 | } 170 | } 171 | 172 | ImVec2 s_pos(center.x + camPos.x * zoomScale - xSize * 0.5f, 173 | center.y + camPos.y * zoomScale - cell_size * 0.5f); 174 | ImVec2 cur_pos(s_pos); 175 | 176 | for (int i = 0; i < mxSz; i++) 177 | { 178 | i %= mxSz; 179 | ImVec2 textSize = ImGui::CalcTextSize(temp[i].c_str()); 180 | ImVec2 pos((cur_pos.x + (std::max(cell_size, textSize.x + 15.f * zoomScale) - textSize.x) * 0.5f), (cur_pos.y + (cell_size - textSize.y) * 0.5f)); 181 | 182 | draw_list->AddRectFilled(cur_pos, ImVec2(cur_pos.x + std::max(cell_size, textSize.x + 15.f * zoomScale), cur_pos.y + cell_size), getColor(DEFAULT_CELL_COL), QUEUE_ROUNDNESS * zoomScale); 183 | draw_list->AddRect(cur_pos, ImVec2(cur_pos.x + std::max(cell_size, textSize.x + 15.f * zoomScale), cur_pos.y + cell_size), getColor(CELL_BORDER_COL), QUEUE_ROUNDNESS * zoomScale, 0, 4.f * zoomScale); 184 | drawText(pos, temp[i].c_str()); 185 | cur_pos.x += std::max(cell_size, textSize.x + 15.f * zoomScale) + separator_size; 186 | } 187 | 188 | drawArrow(int(s_pos.x + headPointerX), int(cur_pos.y), ARROW1_COL, 1); 189 | drawArrow(int(s_pos.x + tailPointerX), int(cur_pos.y), ARROW2_COL, 0); 190 | 191 | } 192 | 193 | void QueueVisualization::drawArrow(int x, int y, int col, bool DownToUp) 194 | { 195 | // This will be given the x and y where the head of the arrow should be 196 | updateCenter(); 197 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 198 | const float headSize = 20.f * zoomScale; 199 | const float length = 50.f * zoomScale; 200 | 201 | int sign = -1; 202 | if(DownToUp) { 203 | sign = 1; 204 | y += int(CELL_SIZE*zoomScale); 205 | } 206 | ImVec2 from = ImVec2((float)x , y + sign*length); 207 | ImVec2 to = ImVec2((float)x, y + sign*headSize); 208 | 209 | draw_list->AddLine(from, to, getColor(col), 20.f * zoomScale); 210 | to.y += -sign*headSize * 0.5f; 211 | 212 | ImVec2 p1 = ImVec2(to.x + headSize, to.y + sign*headSize); 213 | ImVec2 p2 = ImVec2(to.x - headSize, to.y + sign*headSize); 214 | 215 | draw_list->AddTriangleFilled(p1, p2, to, getColor(col)); 216 | } 217 | 218 | bool QueueVisualization::Enqueue(std::string value) 219 | { 220 | if (sz == currentMaxSize) 221 | { 222 | if (sz == MAX_SIZE) 223 | return 1; 224 | 225 | expand(); 226 | return 0; 227 | } 228 | 229 | content[tailpointer] = value; 230 | 231 | tailpointer++; 232 | tailpointer %= currentMaxSize; 233 | sz++; 234 | 235 | return 1; 236 | } 237 | 238 | void QueueVisualization::expand() 239 | { 240 | 241 | if (currentMaxSize * 2 > MAX_SIZE) 242 | return; 243 | 244 | 245 | if (tempContent == nullptr) { 246 | tempContent = new std::string[currentMaxSize*2]; 247 | expansion = 0; 248 | return; 249 | } 250 | 251 | if(expansion < sz) { 252 | tempContent[expansion] = content[headpointer]; 253 | headpointer++; 254 | headpointer %= currentMaxSize; 255 | expansion++; 256 | return; 257 | } 258 | 259 | headpointer = 0, tailpointer = expansion; 260 | // head for popping , tail for pushing 261 | delete[] content; 262 | content = tempContent; 263 | tempContent = nullptr; 264 | expansion = -1; 265 | currentMaxSize *= 2; 266 | } 267 | 268 | void QueueVisualization::Dequeue() 269 | { 270 | if (sz == 0) 271 | return; 272 | sz--; 273 | content[headpointer++] = ""; 274 | headpointer %= currentMaxSize; 275 | } 276 | 277 | void QueueVisualization::controlsUpdate() 278 | { 279 | 280 | ImVec2 controlsWinSize(std::min(450.f * GuiScale, viewport->WorkSize.x - ImGui::GetStyle().WindowPadding.x), std::min(340.f * GuiScale, viewport->WorkSize.y - 2 * ImGui::GetStyle().WindowPadding.y)); 281 | ImVec2 controlsWinPos(viewport->Size.x - controlsWinSize.x - ImGui::GetStyle().WindowPadding.x, viewport->Size.y - controlsWinSize.y - ImGui::GetStyle().WindowPadding.y); 282 | 283 | ImGui::SetNextWindowSize(controlsWinSize); 284 | ImGui::SetNextWindowPos(controlsWinPos); 285 | 286 | ImGui::Begin("Controls", NULL, controls_flags); 287 | 288 | if (ImGui::Button("Back")) 289 | state = 0; 290 | 291 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 292 | 293 | if (ImGui::Button("Reset Camera")) 294 | camTarget = { 0, 0 }; 295 | 296 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 297 | 298 | bool disabled = false; 299 | if (~expansion || pending.size()) { 300 | disabled = true; 301 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 302 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 303 | } 304 | 305 | ImGui::InputText("##Enter_node", add_element_content, IM_ARRAYSIZE(add_element_content)); 306 | 307 | ImGui::SameLine(); 308 | 309 | bool noPush = false; 310 | if (sz == MAX_SIZE && currentMaxSize >= MAX_SIZE && !disabled) { 311 | noPush = true; 312 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 313 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 314 | } 315 | 316 | if (ImGui::Button("Enqueue")) { 317 | getInput(); 318 | } 319 | 320 | if (noPush) { 321 | ImGui::PopItemFlag(); 322 | ImGui::PopStyleVar(); 323 | } 324 | 325 | bool noPop = false; 326 | if (sz == 0 && !disabled) { 327 | noPop = true; 328 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 329 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 330 | } 331 | 332 | if (ImGui::Button("Dequeue")) { 333 | Dequeue(); 334 | } 335 | 336 | if (noPop) { 337 | ImGui::PopItemFlag(); 338 | ImGui::PopStyleVar(); 339 | } 340 | 341 | if (currentMaxSize >= MAX_SIZE && !disabled) { 342 | disabled = true; 343 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 344 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 345 | } 346 | 347 | if (ImGui::Button("Expand")) { 348 | expand(); 349 | } 350 | 351 | if (disabled) { 352 | ImGui::PopItemFlag(); 353 | ImGui::PopStyleVar(); 354 | } 355 | 356 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 357 | 358 | ImGui::SliderFloat("Speed", &speed, MIN_SPEED, MAX_SPEED, "%.1fx", ImGuiSliderFlags_AlwaysClamp); 359 | 360 | ImGui::End(); 361 | } -------------------------------------------------------------------------------- /C-DS/C-DS.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 17.0 23 | Win32Proj 24 | {1a4dfb39-2234-48a4-b2e6-475e5d52d2a9} 25 | CDS 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | $(ProjectDir)$(Configuration)\ 75 | $(ProjectDir)$(Configuration)\ 76 | $(IncludePath) 77 | 78 | 79 | $(ProjectDir)$(Configuration)\ 80 | $(ProjectDir)$(Configuration)\ 81 | $(IncludePath) 82 | 83 | 84 | $(ProjectDir)$(Configuration)\ 85 | $(ProjectDir)$(Configuration)\ 86 | $(IncludePath) 87 | 88 | 89 | $(ProjectDir)$(Configuration)\ 90 | $(ProjectDir)$(Configuration)\ 91 | $(IncludePath) 92 | 93 | 94 | 95 | Level3 96 | true 97 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 98 | true 99 | $(SolutionDir)\imgui;$(SolutionDir)\glfw\include;%(AdditionalIncludeDirectories) 100 | 101 | 102 | Console 103 | true 104 | $(SolutionDir)\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories) 105 | opengl32.lib;glfw3.lib;%(AdditionalDependencies) 106 | msvcrt.lib 107 | 108 | 109 | 110 | 111 | Level3 112 | true 113 | true 114 | true 115 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 116 | true 117 | $(SolutionDir)\imgui;$(SolutionDir)\glfw\include;%(AdditionalIncludeDirectories) 118 | 119 | 120 | Console 121 | true 122 | true 123 | true 124 | $(SolutionDir)\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories) 125 | opengl32.lib;glfw3.lib;%(AdditionalDependencies) 126 | 127 | 128 | 129 | 130 | Level3 131 | true 132 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 133 | true 134 | $(SolutionDir)\imgui;$(SolutionDir)\glfw\include;%(AdditionalIncludeDirectories) 135 | 136 | 137 | Console 138 | true 139 | $(SolutionDir)\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories) 140 | opengl32.lib;glfw3.lib;%(AdditionalDependencies) 141 | msvcrt.lib 142 | 143 | 144 | 145 | 146 | Level3 147 | true 148 | true 149 | true 150 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 151 | true 152 | $(SolutionDir)\imgui;$(SolutionDir)\glfw\include;%(AdditionalIncludeDirectories) 153 | 154 | 155 | Console 156 | true 157 | true 158 | true 159 | $(SolutionDir)\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories) 160 | opengl32.lib;glfw3.lib;%(AdditionalDependencies) 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | -------------------------------------------------------------------------------- /C-DS/App.cpp: -------------------------------------------------------------------------------- 1 | #include "App.h" 2 | #include "Image.h" 3 | #include "Markdown.h" 4 | #include 5 | 6 | 7 | void App::initWindow(std::string title) 8 | { 9 | 10 | // Decide GL+GLSL versions 11 | #if defined(IMGUI_IMPL_OPENGL_ES2) 12 | // GL ES 2.0 + GLSL 100 13 | const char* glsl_version = "#version 100"; 14 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 15 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 16 | glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); 17 | #elif defined(__APPLE__) 18 | // GL 3.2 + GLSL 150 19 | const char* glsl_version = "#version 150"; 20 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 22 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 23 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac 24 | #else 25 | // GL 3.0 + GLSL 130 26 | const char* glsl_version = "#version 130"; 27 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 28 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 29 | //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 30 | //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only 31 | #endif 32 | 33 | // Create window with graphics context 34 | window = glfwCreateWindow(windowWidth, windowHeight, title.c_str(), nullptr, nullptr); 35 | if (window == nullptr) 36 | exit(1); 37 | glfwMakeContextCurrent(window); 38 | glfwSwapInterval(vSyncEnabled); // Enable vsync 39 | 40 | // Setup Dear ImGui context 41 | IMGUI_CHECKVERSION(); 42 | ImGui::CreateContext(); 43 | io = &ImGui::GetIO(); (void)io; 44 | 45 | initStyle(); 46 | 47 | // Setup Platform/Renderer backends 48 | ImGui_ImplGlfw_InitForOpenGL(window, true); 49 | 50 | ImGui_ImplOpenGL3_Init(glsl_version); 51 | 52 | //initialize window icon 53 | 54 | image_imp::SetWindowIcon(window, "Resources\\icon.png"); 55 | 56 | } 57 | 58 | void App::initStyle() 59 | { 60 | io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls 61 | io->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls 62 | io->ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking 63 | io->ConfigWindowsMoveFromTitleBarOnly = true; // Move Windows from the title bar only 64 | 65 | //io->ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows 66 | //io->ConfigViewportsNoAutoMerge = true; 67 | //io->ConfigViewportsNoTaskBarIcon = true; 68 | 69 | 70 | // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones. 71 | style = &ImGui::GetStyle(); 72 | 73 | if (io->ConfigFlags & ImGuiConfigFlags_ViewportsEnable) 74 | { 75 | style->WindowRounding = 0.0f; 76 | style->Colors[ImGuiCol_WindowBg].w = 1.0f; 77 | } 78 | 79 | //Setup Dear ImGui style 80 | if(colorMode == 0) 81 | ImGui::StyleColorsDark(); 82 | else 83 | ImGui::StyleColorsLight(); 84 | 85 | // load custom fonts 86 | LoadFonts(45.0f); 87 | io->Fonts->AddFontFromFileTTF("Resources/logoFont.ttf", 150.0f); 88 | 89 | ImGui::GetIO().FontGlobalScale = GuiScale / 1.5f; 90 | 91 | // Set window rounding radius 92 | style->WindowRounding = 10.0f; 93 | 94 | 95 | style->WindowPadding = ImVec2(14, 14); 96 | style->ItemSpacing = ImVec2(10, 8); 97 | 98 | style->GrabRounding = style->FrameRounding = 8.f; 99 | 100 | } 101 | 102 | void App::toggleFullscreen() 103 | { 104 | GLFWmonitor* monitor = glfwGetPrimaryMonitor(); 105 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 106 | 107 | if (isFullscreen) 108 | glfwSetWindowMonitor(window, nullptr, windowPosX, windowPosY, windowWidth, windowHeight, GLFW_DONT_CARE); 109 | else { 110 | glfwGetWindowPos(window, &windowPosX, &windowPosY); 111 | glfwGetWindowSize(window, &windowWidth, &windowHeight); 112 | glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE); 113 | } 114 | glfwSwapInterval(vSyncEnabled); 115 | 116 | isFullscreen = !isFullscreen; 117 | } 118 | 119 | void App::updateWindow() 120 | { 121 | if (curWindow != nullptr) { 122 | delete curWindow; 123 | curWindow = nullptr; 124 | } 125 | 126 | switch (state) { 127 | 128 | case 0: 129 | curWindow = new MainMenu("Main_Menu", state, GuiScale, settingsEnabled, colorMode); 130 | break; 131 | case 1: 132 | curWindow = new Grid("Grid", state, GuiScale, settingsEnabled, colorMode); 133 | break; 134 | case 2: 135 | curWindow = new GraphTools("Graph_Tools", state, GuiScale, settingsEnabled, colorMode); 136 | break; 137 | case 3: 138 | curWindow = new DSU("DESU?", state, GuiScale, settingsEnabled, colorMode); 139 | break; 140 | case 4: 141 | curWindow = new Tree("Tree", state, GuiScale, settingsEnabled, colorMode); 142 | break; 143 | case 5: 144 | curWindow = new QueueVisualization("Queue", state, GuiScale, settingsEnabled, colorMode); 145 | break; 146 | case 6: 147 | curWindow = new Deque("Deque", state, GuiScale, settingsEnabled, colorMode); 148 | break; 149 | case 7: 150 | curWindow = new LinkedList("Linked_List", state, GuiScale, settingsEnabled, colorMode); 151 | break; 152 | case 8: 153 | curWindow = new HashTable("Hash_Table", state, GuiScale, settingsEnabled, colorMode); 154 | break; 155 | case 9: 156 | curWindow = new HashMap("Hash_Map", state, GuiScale, settingsEnabled, colorMode); 157 | break; 158 | case 10: 159 | curWindow = new Stack("Stack", state, GuiScale, settingsEnabled, colorMode); 160 | break; 161 | case 11: 162 | curWindow = new Vector("Vector", state, GuiScale, settingsEnabled, colorMode); 163 | break; 164 | case 12: 165 | curWindow = new Trie("Trie", state, GuiScale, settingsEnabled, colorMode); 166 | break; 167 | case 30: 168 | curWindow = new SparseTable("Sparsy", state, GuiScale, settingsEnabled, colorMode); 169 | break; 170 | } 171 | state = -1; 172 | 173 | } 174 | 175 | void App::overlay() 176 | { 177 | static int location = 1; 178 | ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; 179 | const ImGuiViewport* viewport = ImGui::GetMainViewport(); 180 | const ImGuiIO* io = &ImGui::GetIO(); 181 | 182 | if (location >= 0) 183 | { 184 | const float PAD = 10.0f; 185 | 186 | ImVec2 work_pos = viewport->WorkPos; 187 | ImVec2 work_size = viewport->WorkSize; 188 | ImVec2 window_pos, window_pos_pivot; 189 | window_pos.x = (location & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD); 190 | window_pos.y = (location & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD); 191 | window_pos_pivot.x = (location & 1) ? 1.0f : 0.0f; 192 | window_pos_pivot.y = (location & 2) ? 1.0f : 0.0f; 193 | ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); 194 | ImGui::SetNextWindowViewport(viewport->ID); 195 | window_flags |= ImGuiWindowFlags_NoMove; 196 | } 197 | else if (location == -2) 198 | { 199 | ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); 200 | window_flags |= ImGuiWindowFlags_NoMove; 201 | } 202 | 203 | ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background 204 | 205 | if (ImGui::Begin("Debugging overlay", &overlayEndabled, window_flags)) 206 | { 207 | ImGui::Text("Debugging overlay\n" "(right-click to change position)"); 208 | ImGui::Separator(); 209 | 210 | ImGui::Text("Frames/Second: %.f", io->Framerate); 211 | 212 | if (ImGui::IsMousePosValid()) 213 | ImGui::Text("Mouse Position: (%.f,%.f)", io->MousePos.x, io->MousePos.y); 214 | else 215 | ImGui::Text("Mouse Position: "); 216 | 217 | ImGui::Text(isFullscreen ? "Window Mode: Fullscreen" : "Window Mode: Windowed"); 218 | 219 | if (ImGui::BeginPopupContextWindow()) 220 | { 221 | if (ImGui::MenuItem("Custom", NULL, location == -1)) location = -1; 222 | if (ImGui::MenuItem("Center", NULL, location == -2)) location = -2; 223 | if (ImGui::MenuItem("Top-left", NULL, location == 0)) location = 0; 224 | if (ImGui::MenuItem("Top-right", NULL, location == 1)) location = 1; 225 | if (ImGui::MenuItem("Bottom-left", NULL, location == 2)) location = 2; 226 | if (ImGui::MenuItem("Bottom-right", NULL, location == 3)) location = 3; 227 | if (overlayEndabled && ImGui::MenuItem("Close")) overlayEndabled = false; 228 | ImGui::EndPopup(); 229 | } 230 | } 231 | ImGui::End(); 232 | } 233 | 234 | App::App(std::string title) 235 | { 236 | initWindow(title); 237 | settings = new Settings("settings", state, GuiScale, settingsEnabled, colorMode); 238 | } 239 | 240 | App::~App() 241 | { 242 | // Cleanup 243 | ImGui_ImplOpenGL3_Shutdown(); 244 | ImGui_ImplGlfw_Shutdown(); 245 | ImGui::DestroyContext(); 246 | 247 | glfwDestroyWindow(window); 248 | glfwTerminate(); 249 | 250 | if (curWindow != nullptr) 251 | delete curWindow; 252 | 253 | if (settings != nullptr) 254 | delete settings; 255 | } 256 | 257 | void App::run() 258 | { 259 | 260 | while (!glfwWindowShouldClose(window)) 261 | { 262 | glfwPollEvents(); 263 | update(); 264 | render(); 265 | } 266 | 267 | } 268 | 269 | void App::update() 270 | { 271 | 272 | // Start the Dear ImGui frame 273 | ImGui_ImplOpenGL3_NewFrame(); 274 | ImGui_ImplGlfw_NewFrame(); 275 | ImGui::NewFrame(); 276 | 277 | if (state != -1) 278 | updateWindow(); 279 | 280 | curWindow->update(); 281 | 282 | if (settingsEnabled) 283 | settings->update(); 284 | 285 | if(overlayEndabled) 286 | overlay(); 287 | 288 | if (io->KeysDown[ImGuiKey_F3]) { 289 | if(!f3Pressed) 290 | overlayEndabled = !overlayEndabled; 291 | f3Pressed = true; 292 | } 293 | else { 294 | f3Pressed = false; 295 | } 296 | 297 | if (io->KeysDown[ImGuiKey_F11] || (isFullscreen && io->KeysDown[ImGuiKey_Escape])) { 298 | if (!f11Pressed) 299 | toggleFullscreen(); 300 | f11Pressed = true; 301 | } 302 | else { 303 | f11Pressed = false; 304 | } 305 | 306 | if (io->KeyCtrl && io->KeysDown[ImGuiKey_Minus]) { 307 | if (!zoomOut) { 308 | zoomOut = true; 309 | GuiScale -= 0.2f; 310 | GuiScale = std::max(GuiScale, 0.6f); 311 | ImGui::GetIO().FontGlobalScale = GuiScale / 1.5f; 312 | } 313 | } 314 | else 315 | zoomOut = false; 316 | 317 | if (io->KeyCtrl && io->KeysDown[ImGuiKey_Equal]) { 318 | if (!zoomIn) { 319 | zoomIn = true; 320 | GuiScale += 0.2f; 321 | GuiScale = std::min(GuiScale, 2.f); 322 | ImGui::GetIO().FontGlobalScale = GuiScale / 1.5f; 323 | } 324 | } 325 | else 326 | zoomIn = false; 327 | } 328 | 329 | void App::render() 330 | { 331 | // Rendering 332 | ImGui::Render(); 333 | int display_w, display_h; 334 | glfwGetFramebufferSize(window, &display_w, &display_h); 335 | glViewport(0, 0, display_w, display_h); 336 | glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); 337 | glClear(GL_COLOR_BUFFER_BIT); 338 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); 339 | 340 | // Update and Render additional Platform Windows 341 | // (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere. 342 | // For this specific demo app we could also call glfwMakeContextCurrent(window) directly) 343 | if (io->ConfigFlags & ImGuiConfigFlags_ViewportsEnable) 344 | { 345 | GLFWwindow* backup_current_context = glfwGetCurrentContext(); 346 | ImGui::UpdatePlatformWindows(); 347 | ImGui::RenderPlatformWindowsDefault(); 348 | glfwMakeContextCurrent(backup_current_context); 349 | } 350 | 351 | glfwSwapBuffers(window); 352 | } 353 | 354 | GLFWwindow* App::getWindow() 355 | { 356 | return window; 357 | } 358 | -------------------------------------------------------------------------------- /C-DS/Vector.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector.h" 2 | #include 3 | #include 4 | 5 | void Vector::update() 6 | { 7 | 8 | ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f); 9 | ImGui::SetNextWindowPos(viewport->WorkPos); 10 | ImGui::SetNextWindowSize(viewport->WorkSize); 11 | 12 | ImGui::Begin(getName().c_str(), NULL, main_flags); 13 | 14 | ImGui::PopStyleVar(); 15 | 16 | drawWatermark(); 17 | 18 | vectorUpdate(); 19 | 20 | if ((ImGui::IsWindowHovered() || movingCam) && ((ImGui::IsMouseDown(0) && cur_tool == 0) || ImGui::IsMouseDown(2))) { 21 | movingCam = true; 22 | camPos.x += io->MouseDelta.x / zoomScale; 23 | camPos.y += io->MouseDelta.y / zoomScale; 24 | camTarget.x += io->MouseDelta.x / zoomScale; 25 | camTarget.y += io->MouseDelta.y / zoomScale; 26 | } 27 | else if (!(ImGui::IsMouseDown(0) && cur_tool == 0) && !ImGui::IsMouseDown(2)) { 28 | movingCam = false; 29 | } 30 | 31 | updateCam(); 32 | 33 | ImGui::End(); 34 | 35 | controlsUpdate(); 36 | } 37 | 38 | Vector::Vector(std::string name, int& state, float& GuiScale, bool& settingsEnabled, int& colorMode) 39 | : GrandWindow(name, state, GuiScale, settingsEnabled, colorMode) 40 | { 41 | 42 | } 43 | 44 | Vector::~Vector() 45 | { 46 | 47 | } 48 | 49 | ImU32 Vector::getColor(int color_code) 50 | { 51 | switch (color_code) { 52 | case DEFAULT_CELL_COL: 53 | return colorMode ? ImGui::GetColorU32(IM_COL32(200, 200, 200, 255)) : ImGui::GetColorU32(IM_COL32(150, 150, 150, 255)); 54 | case CELL_BORDER_COL: 55 | return ImGui::GetColorU32(IM_COL32(40, 40, 40, 255)); 56 | case ARROW1_COL: 57 | return colorMode ? ImGui::GetColorU32(IM_COL32(200, 50, 50, 255)) : ImGui::GetColorU32(IM_COL32(150, 50, 50, 255)); 58 | case ARROW2_COL: 59 | return colorMode ? ImGui::GetColorU32(IM_COL32(50, 50, 200, 255)) : ImGui::GetColorU32(IM_COL32(50, 50, 150, 255)); 60 | case END_CELL_COL: 61 | return colorMode ? ImGui::GetColorU32(IM_COL32(200, 80, 80, 255)) : ImGui::GetColorU32(IM_COL32(150, 50, 50, 255)); 62 | case MARKED_CELL_COL: 63 | return colorMode ? ImGui::GetColorU32(IM_COL32(80, 200, 200, 255)) : ImGui::GetColorU32(IM_COL32(50, 150, 150, 255)); 64 | case TEXT_COLOR: 65 | return colorMode ? ImGui::GetColorU32(IM_COL32(0, 0, 0, 255)) : ImGui::GetColorU32(IM_COL32(255, 255, 255, 255)); 66 | case TEXT_OUTLINE_COL: 67 | return colorMode ? ImGui::GetColorU32(IM_COL32(255, 255, 255, 255)) : ImGui::GetColorU32(IM_COL32(0, 0, 0, 255)); 68 | 69 | default: 70 | return ImGui::GetColorU32(IM_COL32(255, 0, 255, 255)); 71 | } 72 | } 73 | 74 | void Vector::drawText(ImVec2 pos, const char* text) 75 | { 76 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 77 | 78 | for (float x = -1; x <= 1; x++) { 79 | for (float y = -1; y <= 1; y++) { 80 | if (x == 0 && y == 0) continue; 81 | draw_list->AddText(ImVec2(pos.x + x, pos.y + y), getColor(TEXT_OUTLINE_COL), text); 82 | } 83 | } 84 | 85 | draw_list->AddText(pos, getColor(TEXT_COLOR), text); 86 | } 87 | 88 | void Vector::vectorUpdate() 89 | { 90 | 91 | updateCenter(); 92 | 93 | 94 | if (~insertIdx) { 95 | passedTime += io->DeltaTime * speed; 96 | if (passedTime >= BASE_DELAY) { 97 | insert(); 98 | passedTime = 0.f; 99 | } 100 | drawVector((int)center.y, content, currentMaxSize, tailpointer, 0); 101 | return; 102 | } 103 | 104 | if (~eraseIdx) { 105 | passedTime += io->DeltaTime * speed; 106 | if (passedTime >= BASE_DELAY) { 107 | erase(); 108 | passedTime = 0.f; 109 | } 110 | 111 | } 112 | 113 | if (~expansion) 114 | { 115 | passedTime += io->DeltaTime * speed; 116 | if (passedTime >= BASE_DELAY) { 117 | expand(); 118 | passedTime = 0.f; 119 | } 120 | 121 | drawVector(int(center.y - VEC_CELL_SIZE * zoomScale), content, currentMaxSize, tailpointer, 0); 122 | if (~expansion) 123 | drawVector(int(center.y + VEC_CELL_SIZE * zoomScale), tempContent, currentMaxSize * 2, expansion, 1); 124 | } 125 | else 126 | { 127 | if (pending.size()) { 128 | passedTime += io->DeltaTime * speed; 129 | if (passedTime >= BASE_DELAY) { 130 | if (pushBack(pending.front())) { 131 | if (inserting) { 132 | insert(); 133 | selected_index++; 134 | } 135 | pending.pop(); 136 | } 137 | passedTime = 0.f; 138 | } 139 | } 140 | else 141 | inserting = 0; 142 | 143 | drawVector((int)center.y, content, currentMaxSize, tailpointer, 0); 144 | } 145 | 146 | } 147 | 148 | void Vector::drawVector(int ypos, std::string temp[], int mxSz, int tail, bool inverted) 149 | { 150 | 151 | ImVec2 center(viewport->WorkPos.x + viewport->WorkSize.x * 0.5f, (float)ypos); 152 | 153 | float separator_size = std::max(VEC_SEPARATOR_SIZE * zoomScale, 1.f); 154 | float cell_size = VEC_CELL_SIZE * zoomScale; 155 | 156 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 157 | 158 | float xSize = 0.f, tailPointerX = 0.f; 159 | 160 | for (int i = 0; i < mxSz; i++) 161 | { 162 | float textWidth = ImGui::CalcTextSize(temp[i].c_str()).x + 15.f * zoomScale; 163 | xSize += std::max(cell_size, textWidth) + separator_size; 164 | 165 | if (i <= tail) { 166 | if (i == tail) 167 | tailPointerX += std::max(cell_size, textWidth) * 0.5f; 168 | else 169 | tailPointerX += std::max(cell_size, textWidth) + separator_size; 170 | } 171 | } 172 | 173 | if (mxSz == tail) 174 | tailPointerX += cell_size * 0.5f; 175 | 176 | ImVec2 s_pos(center.x + camPos.x * zoomScale - xSize * 0.5f, 177 | center.y + camPos.y * zoomScale - cell_size * 0.5f); 178 | if (!inverted) 179 | s_pos.x -= cell_size * 0.5f; 180 | 181 | ImVec2 cur_pos(s_pos); 182 | 183 | for (int i = 0; i < mxSz; i++) 184 | { 185 | ImVec2 textSize = ImGui::CalcTextSize(temp[i].c_str()); 186 | 187 | ImVec2 pos((cur_pos.x + (std::max(cell_size, textSize.x + 15.f * zoomScale) - textSize.x) * 0.5f), (cur_pos.y + (cell_size - textSize.y) * 0.5f)); 188 | 189 | draw_list->AddRectFilled(cur_pos, ImVec2(cur_pos.x + std::max(cell_size, textSize.x + 15.f * zoomScale), cur_pos.y + cell_size), getColor((i == eraseIdx || i == insertIdx ? MARKED_CELL_COL : DEFAULT_CELL_COL)), VEC_ROUNDNESS * zoomScale); 190 | draw_list->AddRect(cur_pos, ImVec2(cur_pos.x + std::max(cell_size, textSize.x + 15.f * zoomScale), cur_pos.y + cell_size), getColor(CELL_BORDER_COL), VEC_ROUNDNESS * zoomScale, 0, 4.f * zoomScale); 191 | 192 | drawText(pos, temp[i].c_str()); 193 | cur_pos.x += std::max(cell_size, textSize.x + 15.f * zoomScale) + separator_size; 194 | } 195 | 196 | if (!inverted) { 197 | draw_list->AddRectFilled(cur_pos, ImVec2(cur_pos.x + cell_size, cur_pos.y + cell_size), getColor(END_CELL_COL), VEC_ROUNDNESS * zoomScale); 198 | draw_list->AddRect(cur_pos, ImVec2(cur_pos.x + cell_size, cur_pos.y + cell_size), getColor(CELL_BORDER_COL), VEC_ROUNDNESS * zoomScale, 0, 4.f * zoomScale); 199 | } 200 | 201 | drawArrow(int(s_pos.x + tailPointerX), int(cur_pos.y), (inverted ? ARROW2_COL : ARROW1_COL), inverted); 202 | 203 | } 204 | 205 | void Vector::getInput() 206 | { 207 | std::string curElement; 208 | char* ptr = add_element_content; 209 | while (*ptr != '\0') { 210 | if (*ptr == ',') { 211 | if (curElement.size() > 0) { 212 | pending.push(curElement); 213 | curElement.clear(); 214 | } 215 | } 216 | else 217 | curElement.push_back(*ptr); 218 | 219 | ptr++; 220 | } 221 | if (curElement.size() > 0) { 222 | pending.push(curElement); 223 | curElement.clear(); 224 | } 225 | 226 | memset(add_element_content, 0, sizeof add_element_content); 227 | } 228 | 229 | void Vector::drawArrow(int x, int y, int col, bool DownToUp) 230 | { 231 | // This will be given the x and y where the head of the arrow should be 232 | updateCenter(); 233 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 234 | const float headSize = 20.f * zoomScale; 235 | const float length = 50.f * zoomScale; 236 | 237 | int sign = -1; 238 | if (DownToUp) { 239 | sign = 1; 240 | y += int(VEC_CELL_SIZE * zoomScale); 241 | } 242 | ImVec2 from = ImVec2((float)x, y + sign * length); 243 | ImVec2 to = ImVec2((float)x, y + sign * headSize); 244 | 245 | draw_list->AddLine(from, to, getColor(col), 20.f * zoomScale); 246 | to.y += -sign * headSize * 0.5f; 247 | 248 | ImVec2 p1 = ImVec2(to.x + headSize, to.y + sign * headSize); 249 | ImVec2 p2 = ImVec2(to.x - headSize, to.y + sign * headSize); 250 | 251 | draw_list->AddTriangleFilled(p1, p2, to, getColor(col)); 252 | } 253 | 254 | bool Vector::pushBack(std::string value) 255 | { 256 | if (sz == currentMaxSize) 257 | { 258 | if (sz == MAX_SIZE) 259 | return true; 260 | 261 | expand(); 262 | return false; 263 | } 264 | 265 | content[tailpointer] = value; 266 | 267 | tailpointer++; 268 | sz++; 269 | 270 | return true; 271 | } 272 | 273 | void Vector::expand() 274 | { 275 | 276 | if (currentMaxSize * 2 > MAX_SIZE) 277 | return; 278 | 279 | 280 | if (tempContent == nullptr) { 281 | tempContent = new std::string[currentMaxSize * 2]; 282 | expansion = 0; 283 | tailpointer = 0; 284 | return; 285 | } 286 | 287 | if (expansion < sz) { 288 | tempContent[expansion] = content[tailpointer]; 289 | tailpointer++; 290 | expansion++; 291 | return; 292 | } 293 | 294 | tailpointer = expansion; 295 | // head for popping , tail for pushing 296 | delete[] content; 297 | content = tempContent; 298 | tempContent = nullptr; 299 | expansion = -1; 300 | currentMaxSize *= 2; 301 | } 302 | 303 | void Vector::erase() 304 | { 305 | if (eraseIdx == -1) { 306 | eraseIdx = selected_index; 307 | return; 308 | } 309 | 310 | if (eraseIdx < sz-1) { 311 | std::swap(content[eraseIdx], content[eraseIdx+1]); 312 | eraseIdx++; 313 | return; 314 | } 315 | popBack(); 316 | eraseIdx = -1; 317 | } 318 | 319 | void Vector::insert() 320 | { 321 | if (insertIdx == -1) { 322 | insertIdx = sz - 1; 323 | return; 324 | } 325 | 326 | if (insertIdx > selected_index) { 327 | swap(content[insertIdx], content[insertIdx - 1]); 328 | insertIdx--; 329 | return; 330 | } 331 | 332 | insertIdx = -1; 333 | } 334 | 335 | void Vector::popBack() 336 | { 337 | if (sz == 0) 338 | return; 339 | sz--; 340 | content[--tailpointer] = ""; 341 | } 342 | 343 | void Vector::updateMenuBar() 344 | { 345 | } 346 | 347 | void Vector::controlsUpdate() 348 | { 349 | 350 | ImVec2 controlsWinSize(std::min(450.f * GuiScale, viewport->WorkSize.x - ImGui::GetStyle().WindowPadding.x), std::min(540.f * GuiScale, viewport->WorkSize.y - 2 * ImGui::GetStyle().WindowPadding.y)); 351 | ImVec2 controlsWinPos(viewport->Size.x - controlsWinSize.x - ImGui::GetStyle().WindowPadding.x, viewport->Size.y - controlsWinSize.y - ImGui::GetStyle().WindowPadding.y); 352 | 353 | ImGui::SetNextWindowSize(controlsWinSize); 354 | ImGui::SetNextWindowPos(controlsWinPos); 355 | 356 | ImGui::Begin("Controls", NULL, controls_flags); 357 | 358 | if (ImGui::Button("Back")) 359 | state = 0; 360 | 361 | ImGui::Dummy(ImVec2(0.0f, 15.0f * GuiScale)); 362 | 363 | if (ImGui::Button("Reset Camera")) 364 | camTarget = { 0, 0 }; 365 | 366 | ImGui::Dummy(ImVec2(0.0f, 15.0f * GuiScale)); 367 | 368 | bool disabled = false; 369 | if (~expansion || pending.size() || ~eraseIdx) { 370 | disabled = true; 371 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 372 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 373 | } 374 | 375 | ImGui::InputText("Input", add_element_content, IM_ARRAYSIZE(add_element_content)); 376 | 377 | ImGui::DragInt("Index", &selected_index, 0.015f, 0, sz, "%d", ImGuiSliderFlags_AlwaysClamp | ((sz == 0) ? ImGuiSliderFlags_ReadOnly : 0)); 378 | selected_index = std::max(0, std::min(selected_index, sz)); 379 | 380 | 381 | if (ImGui::Button("Push Back")) { 382 | getInput(); 383 | } 384 | 385 | bool noPush = false; 386 | if (sz == MAX_SIZE && currentMaxSize >= MAX_SIZE && !disabled) { 387 | noPush = true; 388 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 389 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 390 | } 391 | 392 | if (ImGui::Button("Insert at Index")) 393 | { 394 | getInput(); 395 | inserting = 1; 396 | } 397 | 398 | if (noPush) { 399 | ImGui::PopItemFlag(); 400 | ImGui::PopStyleVar(); 401 | } 402 | 403 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 404 | 405 | bool noPop = false; 406 | if (sz == 0 && !disabled) { 407 | noPop = true; 408 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 409 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 410 | } 411 | 412 | if (ImGui::Button("Pop Back")) { 413 | popBack(); 414 | } 415 | 416 | if (selected_index == sz && !disabled && !noPop) { 417 | noPop = true; 418 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 419 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 420 | } 421 | 422 | if (ImGui::Button("Erase at Index")) { 423 | erase(); 424 | } 425 | 426 | if (noPop) { 427 | ImGui::PopItemFlag(); 428 | ImGui::PopStyleVar(); 429 | } 430 | 431 | if (currentMaxSize >= MAX_SIZE && !disabled) { 432 | disabled = true; 433 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 434 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 435 | } 436 | 437 | if (ImGui::Button("Expand")) { 438 | expand(); 439 | } 440 | 441 | if (disabled) { 442 | ImGui::PopItemFlag(); 443 | ImGui::PopStyleVar(); 444 | } 445 | 446 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 447 | 448 | ImGui::SliderFloat("Speed", &speed, MIN_SPEED, MAX_SPEED, "%.1fx", ImGuiSliderFlags_AlwaysClamp); 449 | 450 | ImGui::End(); 451 | } -------------------------------------------------------------------------------- /C-DS/Settings.cpp: -------------------------------------------------------------------------------- 1 | #include "Settings.h" 2 | 3 | Settings::Settings(std::string name, int& state, float& GuiScale, bool& settingsEnabled, int& colorMode) 4 | : GrandWindow(name, state, GuiScale, settingsEnabled, colorMode) 5 | { 6 | style = &ImGui::GetStyle(); 7 | } 8 | 9 | Settings::~Settings() 10 | { 11 | 12 | } 13 | 14 | void Settings::update() 15 | { 16 | if (!initialized) { 17 | initialized= true; 18 | ImGui::SetNextWindowSize(ImVec2(500.f, 600.f)); 19 | } 20 | 21 | ImGui::Begin("Settings", &settingsEnabled, ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings); 22 | 23 | 24 | ImGui::Text("Scaling:"); 25 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 26 | 27 | if (ImGui::SliderFloat("##GUI Scale", &GuiScale, 0.6f, 2.0f, "GUI Scale = %.3f")) { 28 | ImGui::GetIO().FontGlobalScale = GuiScale / 1.5f; 29 | } 30 | 31 | if (GuiScale != 1.0f) { 32 | ImGui::SameLine(); 33 | if (ImGui::Button("Reset##GUI_SCALE")) { 34 | GuiScale = 1.0f; 35 | ImGui::GetIO().FontGlobalScale = GuiScale / 1.5f; 36 | } 37 | } 38 | 39 | ImGui::Dummy(ImVec2(0.0f, 20.0f * GuiScale)); 40 | 41 | ImGui::Text("Color Mode:"); 42 | ImGui::Dummy(ImVec2(0.0f, 10.0f * GuiScale)); 43 | 44 | if(ImGui::RadioButton("Light Mode", &colorMode, 1)) 45 | ImGui::StyleColorsLight(); 46 | 47 | ImGui::SameLine(); 48 | 49 | if(ImGui::RadioButton("Dark Mode", &colorMode, 0)) 50 | ImGui::StyleColorsDark(); 51 | 52 | 53 | 54 | if(debuggingSettings){ 55 | 56 | ImGuiStyle* ref = nullptr; 57 | 58 | // You can pass in a reference ImGuiStyle structure to compare to, revert to and save to 59 | // (without a reference style pointer, we will use one compared locally as a reference) 60 | ImGuiStyle& style = ImGui::GetStyle(); 61 | static ImGuiStyle ref_saved_style; 62 | 63 | // Default to using internal storage as reference 64 | static bool init = true; 65 | if (init && ref == NULL) 66 | ref_saved_style = style; 67 | init = false; 68 | if (ref == NULL) 69 | ref = &ref_saved_style; 70 | 71 | ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f); 72 | 73 | if (ImGui::ShowStyleSelector("Colors##Selector")) 74 | ref_saved_style = style; 75 | ImGui::ShowFontSelector("Fonts##Selector"); 76 | 77 | // Simplified Settings (expose floating-pointer border sizes as boolean representing 0.0f or 1.0f) 78 | if (ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f, "%.0f")) 79 | style.GrabRounding = style.FrameRounding; // Make GrabRounding always the same value as FrameRounding 80 | { bool border = (style.WindowBorderSize > 0.0f); if (ImGui::Checkbox("WindowBorder", &border)) { style.WindowBorderSize = border ? 1.0f : 0.0f; } } 81 | ImGui::SameLine(); 82 | { bool border = (style.FrameBorderSize > 0.0f); if (ImGui::Checkbox("FrameBorder", &border)) { style.FrameBorderSize = border ? 1.0f : 0.0f; } } 83 | ImGui::SameLine(); 84 | { bool border = (style.PopupBorderSize > 0.0f); if (ImGui::Checkbox("PopupBorder", &border)) { style.PopupBorderSize = border ? 1.0f : 0.0f; } } 85 | 86 | // Save/Revert button 87 | if (ImGui::Button("Save Ref")) 88 | *ref = ref_saved_style = style; 89 | ImGui::SameLine(); 90 | if (ImGui::Button("Revert Ref")) 91 | style = *ref; 92 | ImGui::SameLine(); 93 | 94 | ImGui::Separator(); 95 | 96 | if (ImGui::BeginTabBar("##tabs", ImGuiTabBarFlags_None)) 97 | { 98 | if (ImGui::BeginTabItem("Sizes")) 99 | { 100 | ImGui::SeparatorText("Main"); 101 | ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f"); 102 | ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f"); 103 | ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f"); 104 | ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f"); 105 | ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f"); 106 | ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 30.0f, "%.0f"); 107 | ImGui::SliderFloat("ScrollbarSize", &style.ScrollbarSize, 1.0f, 20.0f, "%.0f"); 108 | ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f, "%.0f"); 109 | 110 | ImGui::SeparatorText("Borders"); 111 | ImGui::SliderFloat("WindowBorderSize", &style.WindowBorderSize, 0.0f, 1.0f, "%.0f"); 112 | ImGui::SliderFloat("ChildBorderSize", &style.ChildBorderSize, 0.0f, 1.0f, "%.0f"); 113 | ImGui::SliderFloat("PopupBorderSize", &style.PopupBorderSize, 0.0f, 1.0f, "%.0f"); 114 | ImGui::SliderFloat("FrameBorderSize", &style.FrameBorderSize, 0.0f, 1.0f, "%.0f"); 115 | ImGui::SliderFloat("TabBorderSize", &style.TabBorderSize, 0.0f, 1.0f, "%.0f"); 116 | ImGui::SliderFloat("TabBarBorderSize", &style.TabBarBorderSize, 0.0f, 2.0f, "%.0f"); 117 | 118 | ImGui::SeparatorText("Rounding"); 119 | ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 12.0f, "%.0f"); 120 | ImGui::SliderFloat("ChildRounding", &style.ChildRounding, 0.0f, 12.0f, "%.0f"); 121 | ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f, "%.0f"); 122 | ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 12.0f, "%.0f"); 123 | ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 12.0f, "%.0f"); 124 | ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f, "%.0f"); 125 | ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f, "%.0f"); 126 | 127 | ImGui::SeparatorText("Tables"); 128 | ImGui::SliderFloat2("CellPadding", (float*)&style.CellPadding, 0.0f, 20.0f, "%.0f"); 129 | ImGui::SliderAngle("TableAngledHeadersAngle", &style.TableAngledHeadersAngle, -50.0f, +50.0f); 130 | 131 | ImGui::SeparatorText("Widgets"); 132 | ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f"); 133 | int window_menu_button_position = style.WindowMenuButtonPosition + 1; 134 | if (ImGui::Combo("WindowMenuButtonPosition", (int*)&window_menu_button_position, "None\0Left\0Right\0")) 135 | style.WindowMenuButtonPosition = window_menu_button_position - 1; 136 | ImGui::Combo("ColorButtonPosition", (int*)&style.ColorButtonPosition, "Left\0Right\0"); 137 | ImGui::SliderFloat2("ButtonTextAlign", (float*)&style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); 138 | ImGui::SliderFloat2("SelectableTextAlign", (float*)&style.SelectableTextAlign, 0.0f, 1.0f, "%.2f"); 139 | ImGui::SliderFloat("SeparatorTextBorderSize", &style.SeparatorTextBorderSize, 0.0f, 10.0f, "%.0f"); 140 | ImGui::SliderFloat2("SeparatorTextAlign", (float*)&style.SeparatorTextAlign, 0.0f, 1.0f, "%.2f"); 141 | ImGui::SliderFloat2("SeparatorTextPadding", (float*)&style.SeparatorTextPadding, 0.0f, 40.0f, "%.0f"); 142 | ImGui::SliderFloat("LogSliderDeadzone", &style.LogSliderDeadzone, 0.0f, 12.0f, "%.0f"); 143 | 144 | ImGui::SeparatorText("Docking"); 145 | ImGui::SliderFloat("DockingSplitterSize", &style.DockingSeparatorSize, 0.0f, 12.0f, "%.0f"); 146 | 147 | ImGui::SeparatorText("Tooltips"); 148 | for (int n = 0; n < 2; n++) 149 | if (ImGui::TreeNodeEx(n == 0 ? "HoverFlagsForTooltipMouse" : "HoverFlagsForTooltipNav")) 150 | { 151 | ImGuiHoveredFlags* p = (n == 0) ? &style.HoverFlagsForTooltipMouse : &style.HoverFlagsForTooltipNav; 152 | ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayNone", p, ImGuiHoveredFlags_DelayNone); 153 | ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayShort", p, ImGuiHoveredFlags_DelayShort); 154 | ImGui::CheckboxFlags("ImGuiHoveredFlags_DelayNormal", p, ImGuiHoveredFlags_DelayNormal); 155 | ImGui::CheckboxFlags("ImGuiHoveredFlags_Stationary", p, ImGuiHoveredFlags_Stationary); 156 | ImGui::CheckboxFlags("ImGuiHoveredFlags_NoSharedDelay", p, ImGuiHoveredFlags_NoSharedDelay); 157 | ImGui::TreePop(); 158 | } 159 | 160 | ImGui::SeparatorText("Misc"); 161 | ImGui::SliderFloat2("DisplaySafeAreaPadding", (float*)&style.DisplaySafeAreaPadding, 0.0f, 30.0f, "%.0f"); ImGui::SameLine(); 162 | 163 | ImGui::EndTabItem(); 164 | } 165 | 166 | if (ImGui::BeginTabItem("Colors")) 167 | { 168 | 169 | static ImGuiColorEditFlags alpha_flags = 0; 170 | alpha_flags = ImGuiColorEditFlags_AlphaPreviewHalf; 171 | ImGui::SetNextWindowSizeConstraints(ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * 10), ImVec2(FLT_MAX, FLT_MAX)); 172 | ImGui::BeginChild("##colors", ImVec2(0, 0), ImGuiChildFlags_Border, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar | ImGuiWindowFlags_NavFlattened); 173 | ImGui::PushItemWidth(ImGui::GetFontSize() * -12); 174 | for (int i = 0; i < ImGuiCol_COUNT; i++) 175 | { 176 | const char* name = ImGui::GetStyleColorName(i); 177 | ImGui::PushID(i); 178 | #ifndef IMGUI_DISABLE_DEBUG_TOOLS 179 | if (ImGui::Button("?")) 180 | ImGui::DebugFlashStyleColor((ImGuiCol)i); 181 | ImGui::SetItemTooltip("Flash given color to identify places where it is used."); 182 | ImGui::SameLine(); 183 | #endif 184 | ImGui::ColorEdit4("##color", (float*)&style.Colors[i], ImGuiColorEditFlags_AlphaBar | alpha_flags); 185 | 186 | ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); 187 | ImGui::TextUnformatted(name); 188 | ImGui::PopID(); 189 | } 190 | ImGui::PopItemWidth(); 191 | ImGui::EndChild(); 192 | 193 | ImGui::EndTabItem(); 194 | } 195 | 196 | if (ImGui::BeginTabItem("Fonts")) 197 | { 198 | ImGuiIO& io = ImGui::GetIO(); 199 | ImFontAtlas* atlas = io.Fonts; 200 | 201 | // Post-baking font scaling. Note that this is NOT the nice way of scaling fonts, read below. 202 | // (we enforce hard clamping manually as by default DragFloat/SliderFloat allows CTRL+Click text to get out of bounds). 203 | const float MIN_SCALE = 0.3f; 204 | const float MAX_SCALE = 2.0f; 205 | static float window_scale = 1.0f; 206 | ImGui::PushItemWidth(ImGui::GetFontSize() * 8); 207 | if (ImGui::DragFloat("window GuiScale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE, "%.2f", ImGuiSliderFlags_AlwaysClamp)) // GuiScale only this window 208 | ImGui::SetWindowFontScale(window_scale); 209 | ImGui::DragFloat("global GuiScale", &io.FontGlobalScale, 0.005f, MIN_SCALE, MAX_SCALE, "%.2f", ImGuiSliderFlags_AlwaysClamp); // GuiScale everything 210 | ImGui::PopItemWidth(); 211 | 212 | ImGui::EndTabItem(); 213 | } 214 | 215 | if (ImGui::BeginTabItem("Rendering")) 216 | { 217 | ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines); 218 | ImGui::SameLine(); 219 | 220 | ImGui::Checkbox("Anti-aliased lines use texture", &style.AntiAliasedLinesUseTex); 221 | ImGui::SameLine(); 222 | 223 | ImGui::Checkbox("Anti-aliased fill", &style.AntiAliasedFill); 224 | ImGui::PushItemWidth(ImGui::GetFontSize() * 8); 225 | ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, 10.0f, "%.2f"); 226 | if (style.CurveTessellationTol < 0.10f) style.CurveTessellationTol = 0.10f; 227 | 228 | // When editing the "Circle Segment Max Error" value, draw a preview of its effect on auto-tessellated circles. 229 | ImGui::DragFloat("Circle Tessellation Max Error", &style.CircleTessellationMaxError, 0.005f, 0.10f, 5.0f, "%.2f", ImGuiSliderFlags_AlwaysClamp); 230 | const bool show_samples = ImGui::IsItemActive(); 231 | if (show_samples) 232 | ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos()); 233 | if (show_samples && ImGui::BeginTooltip()) 234 | { 235 | ImGui::TextUnformatted("(R = radius, N = number of segments)"); 236 | ImGui::Spacing(); 237 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 238 | const float min_widget_width = ImGui::CalcTextSize("N: MMM\nR: MMM").x; 239 | for (int n = 0; n < 8; n++) 240 | { 241 | const float RAD_MIN = 5.0f; 242 | const float RAD_MAX = 70.0f; 243 | const float rad = RAD_MIN + (RAD_MAX - RAD_MIN) * (float)n / (8.0f - 1.0f); 244 | 245 | ImGui::BeginGroup(); 246 | 247 | ImGui::Text("R: %.f\nN: %d", rad, draw_list->_CalcCircleAutoSegmentCount(rad)); 248 | 249 | const float offset_y = floorf(RAD_MAX); 250 | 251 | const ImVec2 p1 = ImGui::GetCursorScreenPos(); 252 | 253 | /* 254 | const ImVec2 p2 = ImGui::GetCursorScreenPos(); 255 | draw_list->AddCircleFilled(ImVec2(p2.x + offset_x, p2.y + offset_y), rad, ImGui::GetColorU32(ImGuiCol_Text)); 256 | ImGui::Dummy(ImVec2(canvas_width, RAD_MAX * 2)); 257 | */ 258 | 259 | ImGui::EndGroup(); 260 | ImGui::SameLine(); 261 | } 262 | ImGui::EndTooltip(); 263 | } 264 | ImGui::SameLine(); 265 | 266 | ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI (zero alpha clips all widgets). But application code could have a toggle to switch between zero and non-zero. 267 | ImGui::DragFloat("Disabled Alpha", &style.DisabledAlpha, 0.005f, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); 268 | ImGui::PopItemWidth(); 269 | 270 | ImGui::EndTabItem(); 271 | } 272 | 273 | ImGui::EndTabBar(); 274 | } 275 | 276 | ImGui::PopItemWidth(); 277 | } 278 | 279 | ImGui::End(); 280 | } 281 | --------------------------------------------------------------------------------