aboutsummaryrefslogtreecommitdiff
path: root/src/brussel.engine/EditorUtils.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2023-10-19 22:50:07 -0700
committerrtk0c <[email protected]>2023-10-19 22:50:07 -0700
commit2c92e07f337e42cf58970443f9de678f85a9b2a4 (patch)
tree075d5407e1e12a9d35cbee6e4c20ad34e0765c42 /src/brussel.engine/EditorUtils.hpp
parent615809c036f604bce4582cea8ad49c64693f4f45 (diff)
The great renaming: switch to "module style"
Diffstat (limited to 'src/brussel.engine/EditorUtils.hpp')
-rw-r--r--src/brussel.engine/EditorUtils.hpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/brussel.engine/EditorUtils.hpp b/src/brussel.engine/EditorUtils.hpp
new file mode 100644
index 0000000..96e92d3
--- /dev/null
+++ b/src/brussel.engine/EditorUtils.hpp
@@ -0,0 +1,84 @@
+#pragma once
+
+#include "EditorCore.hpp"
+#include "ImGuiGuizmo.hpp"
+#include "Ires.hpp"
+
+#include <Color.hpp>
+#include <Metadata.hpp>
+
+#include <imgui.h>
+#include <string>
+
+// To check whether a payload is of this type, use starts_with()
+#define BRUSSEL_TAG_PREFIX_GameObject "GameObject"
+#define BRUSSEL_TAG_PREFIX_Ires "Ires"
+
+#define BRUSSEL_TAG_Level "Level"
+
+namespace ImGui {
+
+const char* GetKeyNameGlfw(int key);
+
+void SetNextWindowSizeRelScreen(float xPercent, float yPercent, ImGuiCond cond = ImGuiCond_None);
+void SetNextWindowCentered(ImGuiCond cond = ImGuiCond_None);
+
+void PushDisabled();
+void PopDisabled();
+
+bool Button(const char* label, bool disabled);
+bool Button(const char* label, const ImVec2& sizeArg, bool disabled);
+
+bool ColorEdit3(const char* label, RgbaColor* color, ImGuiColorEditFlags flags = 0);
+bool ColorEdit4(const char* label, RgbaColor* color, ImGuiColorEditFlags flags = 0);
+bool ColorPicker3(const char* label, RgbaColor* color, ImGuiColorEditFlags flags = 0);
+bool ColorPicker4(const char* label, RgbaColor* color, ImGuiColorEditFlags flags = 0);
+
+bool Splitter(bool splitVertically, float thickness, float* size1, float* size2, float minSize1, float minSize2, float splitterLongAxisSize = -1.0f);
+
+void AddUnderLine(ImColor col);
+
+enum class IconType {
+ Flow,
+ Circle,
+ Square,
+ Grid,
+ RoundSquare,
+ Diamond,
+};
+
+void DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, IconType type, bool filled, ImU32 color, ImU32 innerColor);
+void Icon(const ImVec2& size, IconType type, bool filled, const ImVec4& color = ImVec4(1, 1, 1, 1), const ImVec4& innerColor = ImVec4(0, 0, 0, 0));
+
+void DrawArrow(ImDrawList* drawList, ImVec2 from, ImVec2 to, ImU32 color, float lineThickness = 1.0f);
+
+// NOTE: string is copied into an internal storage
+void DialogConfirmation(std::string message, std::function<void(bool)> callback);
+void ShowDialogs();
+
+} // namespace ImGui
+
+namespace Utils {
+
+float CalcImageHeight(glm::vec2 original, int targetWidth);
+float CalcImageWidth(glm::vec2 original, float targetHeight);
+ImVec2 FitImage(glm::vec2 original);
+
+// TODO get kind from T
+template <typename T>
+T* SimpleIresReceptor(T* existing, IEditor& editor, IresObject::Kind kind) {
+ if (existing) {
+ existing->ShowReference(editor);
+ } else {
+ IresObject::ShowReferenceNull(editor);
+ }
+ if (ImGui::BeginDragDropTarget()) {
+ if (auto payload = ImGui::AcceptDragDropPayload(Metadata::EnumToString(kind).data())) {
+ return *static_cast<T* const*>(payload->Data);
+ }
+ ImGui::EndDragDropTarget();
+ }
+ return nullptr;
+}
+
+} // namespace Utils