Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
5.3 kB
3
Indexable
Never
#include "gui.h"
#include "iostream"
#include "fstream"

#include "../imgui/imgui.h"
#include "../imgui/imgui_impl_dx9.h"
#include "../imgui/imgui_impl_win32.h"
#include "../imgui/imgui_internal.h"

ImVec2 operator+(const ImVec2& a, const ImVec2& b) { return { a.x + b.x, a.y + b.y }; }
ImVec2 CenterTextInRectangle(ImDrawList* drawList, ImFont* font, const ImVec2& rectPos, const ImVec2& rectSize, const char* text);

using namespace std;

class Window {
public:
	Window() {}

	void createTab(const char* tabName) {
		bool isNewTab = true;
		ImVec2 pos = ImGui::GetWindowPos();

		int index = 0;
		for (auto& tab : tabs) { if (tab.name == tabName) { isNewTab = false; break; }; index++; }
		if (isNewTab) {
			tabs.push_back({ tabName, false });
			if (index == 0) tabs[0].open = true;
		}

		ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));
		ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(0, 0, 0, 0));
		ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32(0, 0, 0, 20));

		pos = ImVec2(pos.x + (240.0f * index), pos.y);
		ImGui::SetCursorPos(ImVec2(240.0f * index, 0));
		ImGui::Button("", ImVec2(240.0f, 75.0f));

		if (ImGui::IsItemClicked(0)) {
			for (auto& tab : tabs) {
				if (tab.name == tabName) tab.open = true;
				else tab.open = false;
			}
		}

		ImGui::PopStyleColor(3);

		for (auto& tab : tabs) {
			if (tab.name == tabName) {
				int depth = 13;
				ImVec2 size = ImVec2(240.0f, 75.0f);
				ImU32 shadowColor = IM_COL32(255, 255, 255, 2);

				ImDrawList* drawList = ImGui::GetWindowDrawList();
				ImDrawList* backDrawList = ImGui::GetBackgroundDrawList();

				ImVec2 textPos = CenterTextInRectangle(drawList, ImGui::GetIO().Fonts->Fonts[2], ImVec2(pos.x, pos.y), ImVec2(size.x, size.y), tabName);

				ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[2]);
				if (tab.open) {
					drawList->AddRectFilled(ImVec2(pos.x, pos.y), ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(50, 50, 50, 255), 0.0f);
					for (int i = 0; i < depth; ++i) {
						ImVec2 offset(i, i);

						float alpha = ((float)(depth - i) / (float)depth) * ((shadowColor >> 24) & 0xFF) / 255.0f;
						ImU32 color = IM_COL32((shadowColor >> 0) & 0xFF, (shadowColor >> 8) & 0xFF, (shadowColor >> 16) & 0xFF, (int)(alpha * 255));

						drawList->AddRectFilled(ImVec2(pos.x - offset.x + 8.0f, pos.y - offset.y + 8.0f), ImVec2(pos.x + size.x + offset.x - 8.0f, pos.y + size.y + offset.y - 8.0f), color, 0.0f, ImDrawFlags_RoundCornersAll);
					}
					drawList->AddText(textPos, IM_COL32(191, 191, 191, 255), tabName);
				}
				else drawList->AddText(textPos, IM_COL32(171, 171, 171, 255), tabName);

				ImGui::PopFont();
				ImGui::PopStyleColor(1);
			}
		}
	}

	void addContainer(int index, const char* tabName, float width = 100.0f, bool hotkey = false) {
		int depth = 13;
		float radius = 25.0f;
		ImVec2 size = ImVec2(width, 425.0f);
		ImU32 shadowColor = IM_COL32(0, 0, 0, 10);

		ImVec2 pos = ImGui::GetWindowPos();
		pos = pos + ImVec2(40.0f, 115.0f);
		ImDrawList* drawList = ImGui::GetWindowDrawList();

		int tabIndex = 0;
		for (auto& tab : tabs) {
			if (tab.name == tabName) break;
			tabIndex++;
		}

		bool isNewTab = true;
		for (auto& tab : tabs)
			for (auto& container : tab.tabContainers)
				if (container.index == index && container.name == tabName) { isNewTab = false; break; }
		if (isNewTab) tabs[tabIndex].tabContainers.push_back({ index, tabName, width });

		float addSize = 0.0f;
		for (auto& container : tabs[tabIndex].tabContainers) {
			if (container.index == index) break;
			addSize += container.size + 40.0f;
		}

		for (auto& tab : tabs) {
			if (tab.name == tabName && tab.open) {
				ImGui::BeginChild("containerTab", { 0, 0 }, true, ImGuiWindowFlags_NoScrollbar);
				for (int i = 0; i < depth; ++i) {
					ImVec2 offset(i, i);

					float alpha = ((float)(depth - i) / (float)depth) * ((shadowColor >> 24) & 0xFF) / 255.0f;
					ImU32 color = IM_COL32((shadowColor >> 0) & 0xFF, (shadowColor >> 8) & 0xFF, (shadowColor >> 16) & 0xFF, (int)(alpha * 255));

					drawList->AddRectFilled(ImVec2(pos.x - offset.x + addSize, pos.y - offset.y), ImVec2(pos.x + size.x + offset.x + addSize, pos.y + size.y + offset.y), color, radius, ImDrawFlags_RoundCornersAll);
				}
				drawList->AddRectFilled(ImVec2(pos.x + addSize, pos.y), ImVec2(pos.x + size.x + addSize, pos.y + size.y), IM_COL32(64, 64, 64, 255), radius);

				for (int i = 0; i < depth; ++i) {
					ImVec2 offset(i, i);

					float alpha = ((float)(depth - i) / (float)depth) * ((shadowColor >> 24) & 0xFF) / 255.0f;
					ImU32 color = IM_COL32((shadowColor >> 0) & 0xFF, (shadowColor >> 8) & 0xFF, (shadowColor >> 16) & 0xFF, (int)(alpha * 255));

					drawList->AddRectFilled(ImVec2(pos.x + addSize, pos.y + 40.0f), ImVec2(pos.x + size.x + addSize, pos.y + 45.0f + offset.y), color);
				}
				drawList->AddRectFilled(ImVec2(pos.x + addSize, pos.y), ImVec2(pos.x + size.x + addSize, pos.y + 45.0f), IM_COL32(84, 84, 84, 255), radius, ImDrawFlags_RoundCornersTop);

				ImGui::EndChild();
			}
		}
	}

private:
	struct Container {
		int index;
		string name;
		float size;
	};

	struct Tab {
		string name;
		bool open;
		vector<Container> tabContainers;
	};

	vector<Tab> tabs;
};