Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1/*
2Copyright (c) 2021 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_EDITOR_UTILS_H_
34#define DVD_EDITOR_UTILS_H_
35
36#include "UndoManager.h"
38
39enum class PushConstantType;
40
41namespace ImGui {
42 bool InputDoubleN(const char* label, double* v, int components, const char* display_format, ImGuiInputTextFlags extra_flags);
43 bool InputDouble2(const char* label, double v[2], const char* display_format, ImGuiInputTextFlags extra_flags);
44 bool InputDouble3(const char* label, double v[3], const char* display_format, ImGuiInputTextFlags extra_flags);
45 bool InputDouble4(const char* label, double v[4], const char* display_format, ImGuiInputTextFlags extra_flags);
46 typedef int ImGuiPopupFlags;
47
48} // namespace ImGui
49
50namespace Divide {
51
52 [[nodiscard]] ImGuiKey DivideKeyToImGuiKey(const Input::KeyCode key) noexcept;
53
54namespace Util {
55 constexpr F32 LabelColumnWidth = 200.f;
56 constexpr F32 LabelColumnWidthNarrow = 110.f;
57
58 static const ImVec4 Colours[] = {
59 {0.8f, 0.1f, 0.15f, 1.f},
60 {0.2f, 0.7f, 0.2f, 1.f},
61 {0.1f, 0.25f, 0.8f, 1.f}
62 };
63 static const ImVec4 ColoursHovered[] = {
64 {0.9f, 0.2f, 0.2f, 1.f},
65 {0.3f, 0.8f, 0.3f, 1.f},
66 {0.2f, 0.35f, 0.8f, 1.f}
67 };
68
69 constexpr const char* FieldLabels[] = {
70 "X", "Y", "Z", "W", "U", "V", "T"
71 };
72 // Separate activate is used for stuff that do continuous value changes, e.g. colour selectors, but you only want to register the old val once
73 template<typename T, bool SeparateActivate, typename Pred>
74 void RegisterUndo(Editor& editor, PushConstantType type, const T& oldVal, const T& newVal, const char* name, Pred&& dataSetter);
75
77 bool wasChanged = false;
78 bool wasDeactivated = false;
79 };
80
81 template<typename T, size_t N, bool isSlider>
82 DrawReturnValue DrawVec(ImGuiDataType data_type,
83 const char* label,
84 T* values,
85 ImGuiInputTextFlags flags,
86 T resetValue = 0,
87 const char* format = "%.2f");
88
89 template<typename T, size_t N, bool isSlider>
90 DrawReturnValue DrawVec(ImGuiDataType data_type,
91 const char* label,
92 const char* const compLabels[],
93 T* values,
94 ImGuiInputTextFlags flags,
95 T resetValue = 0,
96 T minValue = 0,
97 T maxValue = 0,
98 T step = 0,
99 T stepFast = 0,
100 const char* format = "%.2f");
101
102 template<typename T, bool isSlider>
103 DrawReturnValue DrawVecComponent(ImGuiDataType data_type,
104 const char* label,
105 T& value,
106 T resetValue,
107 T minValue,
108 T maxValue,
109 T step,
110 T stepFast,
111 ImVec4 buttonColour,
112 ImVec4 buttonColourHovered,
113 ImVec4 buttonColourActive,
114 ImGuiInputTextFlags flags,
115 const char* format = "%.2f");
116
117 const char* GetFormat(ImGuiDataType dataType, const char* input, bool hex);
120
121 template<typename Pred>
122 bool colourInput4(Editor& parent, const char* name, FColour4& col, const bool readOnly, Pred&& dataSetter);
123 template<typename Pred>
124 bool colourInput3(Editor& parent, const char* name, FColour3& col, const bool readOnly, Pred&& dataSetter);
125
126 template<typename FieldDataType, typename ComponentType, size_t num_comp>
127 bool inputOrSlider(Editor& parent, const bool isSlider, const char* label, const F32 stepIn, ImGuiDataType data_type, EditorComponentField& field, ImGuiInputTextFlags flags, const char* format);
128
129 template<typename FieldDataType, typename ComponentType, size_t num_comp, bool IsSlider>
130 bool inputOrSlider(Editor& parent, const char* label, const F32 stepIn, const ImGuiDataType data_type, EditorComponentField& field, const ImGuiInputTextFlags flags, const char* format);
131
132 template<typename T, size_t num_rows>
133 bool inputMatrix(Editor& parent, const char* label, const F32 stepIn, const ImGuiDataType data_type, EditorComponentField& field, const ImGuiInputTextFlags flags, const char* format);
134
135 [[nodiscard]] F32 GetLineHeight() noexcept;
136 void AddUnderLine();
137
138 void BeginPropertyTable(I32 numComponents, const char* label);
139 void EndPropertyTable();
140
141 void PushButtonStyle(bool bold,
142 ImVec4 buttonColour,
143 ImVec4 buttonColourHovered,
144 ImVec4 buttonColourActive);
145 void PopButtonStyle();
146 void PushBoldFont();
147 void PopBoldFont();
149 void PopNarrowLabelWidth();
150 void PushTooltip(const char* tooltip);
151 void PopTooltip();
152 [[nodiscard]] bool IsPushedTooltip();
153 const char* PushedToolTip();
154
155 void CenterNextWindow();
156 void OpenCenteredPopup(const char* name, ImGui::ImGuiPopupFlags popup_flags = 0);
157 void PrintColouredText(const std::string_view text, const ImVec4& colour);
158
159 [[nodiscard]] ImGuiInputTextFlags GetDefaultFlagsForSettings(bool readOnly, bool hex);
160 [[nodiscard]] ImGuiInputTextFlags GetDefaultFlagsForField(const EditorComponentField& field);
161
162} //namespace Util
163} //namespace Divide
164
165#ifdef _MSC_VER
166#pragma warning(push)
167#pragma warning(disable: 4127) // conditional expression is constant
168#endif
169
170#include "Utils.inl"
171
172#ifdef _MSC_VER
173#pragma warning(pop)
174#endif
175
176#endif // DVD_EDITOR_UTILS_H_
DrawReturnValue DrawVec(ImGuiDataType data_type, const char *label, T *values, ImGuiInputTextFlags flags, T resetValue=0, const char *format="%.2f")
Definition: Utils.inl:168
void CenterNextWindow()
Definition: Utils.cpp:406
const char * PushedToolTip()
Definition: Utils.cpp:331
void PushTooltip(const char *tooltip)
Definition: Utils.cpp:316
void PushNarrowLabelWidth()
Definition: Utils.cpp:300
void RegisterUndo(Editor &editor, PushConstantType type, const T &oldVal, const T &newVal, const char *name, Pred &&dataSetter)
Definition: Utils.inl:50
void PopBoldFont()
Definition: Utils.cpp:291
void PopButtonStyle()
Definition: Utils.cpp:350
F32 GetLineHeight() noexcept
Definition: Utils.cpp:224
void PopNarrowLabelWidth()
Definition: Utils.cpp:308
void OpenCenteredPopup(const char *name, ImGui::ImGuiPopupFlags popup_flags=0)
static const ImVec4 Colours[]
Definition: Utils.h:58
void PushBoldFont()
Definition: Utils.cpp:282
bool colourInput4(Editor &parent, EditorComponentField &field)
Definition: Utils.cpp:374
void PopTooltip()
Definition: Utils.cpp:321
static const ImVec4 ColoursHovered[]
Definition: Utils.h:63
void EndPropertyTable()
Definition: Utils.cpp:271
constexpr F32 LabelColumnWidth
Definition: Utils.h:55
void PushButtonStyle(bool bold, ImVec4 buttonColour, ImVec4 buttonColourHovered, ImVec4 buttonColourActive)
Definition: Utils.cpp:336
void AddUnderLine()
Definition: Utils.cpp:229
ImGuiInputTextFlags GetDefaultFlagsForField(const EditorComponentField &field)
Definition: Utils.cpp:437
bool colourInput3(Editor &parent, EditorComponentField &field)
Definition: Utils.cpp:390
bool inputOrSlider(Editor &parent, const bool isSlider, const char *label, const F32 stepIn, ImGuiDataType data_type, EditorComponentField &field, ImGuiInputTextFlags flags, const char *format)
Definition: Utils.inl:236
void PrintColouredText(const std::string_view text, const ImVec4 &colour)
Definition: Utils.cpp:422
bool inputMatrix(Editor &parent, const char *label, const F32 stepIn, const ImGuiDataType data_type, EditorComponentField &field, const ImGuiInputTextFlags flags, const char *format)
Definition: Utils.inl:325
bool IsPushedTooltip()
Definition: Utils.cpp:326
const char * GetFormat(ImGuiDataType dataType, const char *input, bool hex)
Definition: Utils.cpp:357
constexpr F32 LabelColumnWidthNarrow
Definition: Utils.h:56
ImGuiInputTextFlags GetDefaultFlagsForSettings(bool readOnly, bool hex)
Definition: Utils.cpp:429
DrawReturnValue DrawVecComponent(ImGuiDataType data_type, const char *label, T &value, T resetValue, T minValue, T maxValue, T step, T stepFast, ImVec4 buttonColour, ImVec4 buttonColourHovered, ImVec4 buttonColourActive, ImGuiInputTextFlags flags, const char *format="%.2f")
Definition: Utils.inl:71
constexpr const char * FieldLabels[]
Definition: Utils.h:69
void BeginPropertyTable(I32 numComponents, const char *label)
Definition: Utils.cpp:237
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
ImGuiKey DivideKeyToImGuiKey(const Input::KeyCode key) noexcept
Definition: Utils.cpp:66
Project & parent
Definition: DefaultScene.h:41
bool InputDouble4(const char *label, double v[4], const char *display_format, ImGuiInputTextFlags extra_flags)
Definition: Utils.cpp:57
bool InputDouble3(const char *label, double v[3], const char *display_format, ImGuiInputTextFlags extra_flags)
Definition: Utils.cpp:52
int ImGuiPopupFlags
Definition: Utils.h:46
bool InputDouble2(const char *label, double v[2], const char *display_format, ImGuiInputTextFlags extra_flags)
Definition: Utils.cpp:47
bool InputDoubleN(const char *label, double *v, int components, const char *display_format, ImGuiInputTextFlags extra_flags)
Definition: Utils.cpp:20