-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathImGuiExtension.cs
312 lines (274 loc) · 11.5 KB
/
ImGuiExtension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ExileCore;
using ExileCore.Shared.Nodes;
using ImGuiNET;
using SharpDX;
using ImGuiVector2 = System.Numerics.Vector2;
using ImGuiVector4 = System.Numerics.Vector4;
namespace Random_Features.Libs
{
public class ImGuiExtension
{
// Int Sliders
public static int IntSlider(string labelString, int value, int minValue, int maxValue)
{
var refValue = value;
ImGui.SliderInt(labelString, ref refValue, minValue, maxValue);
return refValue;
}
public static int IntSlider(string labelString, string sliderString, int value, int minValue, int maxValue)
{
var refValue = value;
ImGui.SliderInt(labelString, ref refValue, minValue, maxValue);
return refValue;
}
public static int IntSlider(string labelString, RangeNode<int> setting)
{
var refValue = setting.Value;
ImGui.SliderInt(labelString, ref refValue, setting.Min, setting.Max);
return refValue;
}
public static int IntSlider(string labelString, string sliderString, RangeNode<int> setting)
{
var refValue = setting.Value;
ImGui.SliderInt(labelString, ref refValue, setting.Min, setting.Max);
return refValue;
}
// float Sliders
public static float FloatSlider(string labelString, float value, float minValue, float maxValue)
{
var refValue = value;
ImGui.SliderFloat(labelString, ref refValue, minValue, maxValue, "%.00f", 1f);
return refValue;
}
public static float FloatSlider(string labelString, float value, float minValue, float maxValue, float power)
{
var refValue = value;
ImGui.SliderFloat(labelString, ref refValue, minValue, maxValue, "%.00f", power);
return refValue;
}
public static float FloatSlider(string labelString, string sliderString, float value, float minValue, float maxValue)
{
var refValue = value;
ImGui.SliderFloat(labelString, ref refValue, minValue, maxValue, $"{sliderString}: {value}", 1f);
return refValue;
}
public static float FloatSlider(string labelString, string sliderString, float value, float minValue, float maxValue, float power)
{
var refValue = value;
ImGui.SliderFloat(labelString, ref refValue, minValue, maxValue, $"{sliderString}: {value}", power);
return refValue;
}
public static float FloatSlider(string labelString, RangeNode<float> setting)
{
var refValue = setting.Value;
ImGui.SliderFloat(labelString, ref refValue, setting.Min, setting.Max, "%.00f", 1f);
return refValue;
}
public static float FloatSlider(string labelString, RangeNode<float> setting, float power)
{
var refValue = setting.Value;
ImGui.SliderFloat(labelString, ref refValue, setting.Min, setting.Max, "%.00f", power);
return refValue;
}
public static float FloatSlider(string labelString, string sliderString, RangeNode<float> setting)
{
var refValue = setting.Value;
ImGui.SliderFloat(labelString, ref refValue, setting.Min, setting.Max, $"{sliderString}: {setting.Value}", 1f);
return refValue;
}
public static float FloatSlider(string labelString, string sliderString, RangeNode<float> setting, float power)
{
var refValue = setting.Value;
ImGui.SliderFloat(labelString, ref refValue, setting.Min, setting.Max, $"{sliderString}: {setting.Value}", power);
return refValue;
}
// Color Pickers
public static Color ColorPicker(string labelName, Color inputColor)
{
var color = inputColor.ToVector4();
var colorToVect4 = new ImGuiVector4(color.X, color.Y, color.Z, color.W);
if (ImGui.ColorEdit4(labelName, ref colorToVect4, ImGuiColorEditFlags.AlphaBar)) return new Color(colorToVect4.X, colorToVect4.Y, colorToVect4.Z, colorToVect4.W);
return inputColor;
}
// Checkboxes
public static bool Checkbox(string labelString, bool boolValue)
{
ImGui.Checkbox(labelString, ref boolValue);
return boolValue;
}
public static bool Checkbox(string labelString, bool boolValue, out bool outBool)
{
ImGui.Checkbox(labelString, ref boolValue);
outBool = boolValue;
return boolValue;
}
// Hotkey Selector
public static IEnumerable<Keys> KeyCodes() => Enum.GetValues(typeof(Keys)).Cast<Keys>();
// Tooltip Hover
public static void ToolTipWithText(string text, string desc)
{
ImGui.SameLine();
ImGui.TextDisabled(text);
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AnyWindow))
{
ImGui.SetTooltip(desc);
}
}
public static int ComboBox(string sideLabel, int currentSelectedItem, List<string> objectList)
{
ImGui.Combo(sideLabel, ref currentSelectedItem, objectList.ToArray(), objectList.Count);
return currentSelectedItem;
}
public static string ComboBox(string sideLabel, string currentSelectedItem, List<string> objectList, ImGuiComboFlags comboFlags = ImGuiComboFlags.HeightRegular)
{
if (ImGui.BeginCombo(sideLabel, currentSelectedItem, comboFlags))
{
var refObject = currentSelectedItem;
for (var n = 0; n < objectList.Count; n++)
{
var isSelected = refObject == objectList[n];
if (ImGui.Selectable(objectList[n], isSelected)) return objectList[n];
if (isSelected) ImGui.SetItemDefaultFocus();
}
ImGui.EndCombo();
}
return currentSelectedItem;
}
public static string ComboBox(string sideLabel, string currentSelectedItem, List<string> objectList, out bool didChange, ImGuiComboFlags comboFlags = ImGuiComboFlags.HeightRegular)
{
if (ImGui.BeginCombo(sideLabel, currentSelectedItem, comboFlags))
{
var refObject = currentSelectedItem;
for (var n = 0; n < objectList.Count; n++)
{
var isSelected = refObject == objectList[n];
if (ImGui.Selectable(objectList[n], isSelected))
{
didChange = true;
return objectList[n];
}
if (isSelected) ImGui.SetItemDefaultFocus();
}
ImGui.EndCombo();
}
didChange = false;
return currentSelectedItem;
}
public static string InputText(string label, string currentValue, uint maxLength, ImGuiInputTextFlags flags)
{
byte[] buff = new byte[maxLength];
if (!String.IsNullOrEmpty(currentValue))
{
byte[] currentValueBytes = Encoding.UTF8.GetBytes(currentValue);
Array.Copy(currentValueBytes, buff, currentValueBytes.Length);
}
ImGui.InputText(label, buff, maxLength, flags);
return Encoding.Default.GetString(buff).TrimEnd('\0');
}
public static Keys HotkeySelector(string buttonName, Keys currentKey)
{
var open = true;
if (ImGui.Button(buttonName))
{
ImGui.OpenPopup(buttonName);
open = true;
}
if (ImGui.BeginPopupModal(buttonName, ref open, (ImGuiWindowFlags)35))
{
if (Input.GetKeyState(Keys.Escape))
{
ImGui.CloseCurrentPopup();
ImGui.EndPopup();
}
else
{
foreach (var key in Enum.GetValues(typeof(Keys)))
{
var keyState = Input.GetKeyState((Keys)key);
if (keyState)
{
currentKey = (Keys)key;
ImGui.CloseCurrentPopup();
break;
}
}
}
ImGui.Text($" Press new key to change '{currentKey}' or Esc for exit.");
ImGui.EndPopup();
}
return currentKey;
}
// ImColor_HSV Maker
public static ImGuiVector4 ImColor_HSV(float h, float s, float v)
{
ImGui.ColorConvertHSVtoRGB(h, s, v, out var r, out var g, out var b);
return new ImGuiVector4(r, g, b, 255);
}
public static ImGuiVector4 ImColor_HSV(float h, float s, float v, float a)
{
ImGui.ColorConvertHSVtoRGB(h, s, v, out var r, out var g, out var b);
return new ImGuiVector4(r, g, b, a);
}
// Color menu tabs
public static void ImGuiExtension_ColorTabs(string idString, int height, IReadOnlyList<string> settingList, ref int selectedItem, ref int uniqueIdPop)
{
var newcontentRegionArea = new System.Numerics.Vector2();
newcontentRegionArea = ImGuiNative.igGetContentRegionAvail();
var boxRegion = new ImGuiVector2(newcontentRegionArea.X, height);
if (ImGui.BeginChild(idString, boxRegion, true, ImGuiWindowFlags.HorizontalScrollbar))
{
for (var i = 0; i < settingList.Count; i++)
{
ImGui.PushID(uniqueIdPop);
var hue = 1f / settingList.Count * i;
ImGui.PushStyleColor(ImGuiCol.Button, ImColor_HSV(hue, 0.6f, 0.6f, 0.8f));
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ImColor_HSV(hue, 0.7f, 0.7f, 0.9f));
ImGui.PushStyleColor(ImGuiCol.ButtonActive, ImColor_HSV(hue, 0.8f, 0.8f, 1.0f));
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 3.0f);
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, 2.0f);
if (i > 0) ImGui.SameLine();
if (ImGui.Button(settingList[i])) selectedItem = i;
uniqueIdPop++;
ImGui.PopStyleVar();
ImGui.PopStyleColor(3);
ImGui.PopID();
}
}
ImGui.EndChild();
}
public static void SpacedTextHeader(string text)
{
ImGui.Spacing();
ImGui.Separator();
ImGui.Spacing();
ImGui.Text(text);
ImGui.Separator();
ImGui.Spacing();
}
//Spacing
public static void Spacing(int amount)
{
for (var i = 0; i < amount; i++)
ImGui.Spacing();
}
//End Columns
public static void EndColumn()
{
ImGui.Columns(1, null, false);
}
public static void ToolTip(string desc)
{
ImGui.SameLine();
ImGui.TextDisabled("(?)");
if (ImGui.IsItemHovered(ImGuiHoveredFlags.None))
{
ImGui.SetTooltip(desc);
}
}
}
}