-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalMethods.cs
More file actions
257 lines (219 loc) · 10.1 KB
/
LocalMethods.cs
File metadata and controls
257 lines (219 loc) · 10.1 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static RayGui_cs.RayGui;
namespace RayGui_cs
{
public static unsafe partial class RayGui
{
// GuiTextSplit function (custom implementation might be needed)
public static string[] GuiTextSplit(string text, char delimiter, ref int count)
{
string[] result = text.Split(delimiter);
count = result.Length;
return result;
}
// ConvertHSVtoRGB function
public static Vector3 ConvertHSVtoRGB(Vector3 hsv)
{
Vector3 rgb = new Vector3();
float hh, p, q, t, ff;
long i;
if (hsv.Y <= 0.0f)
{
rgb.X = hsv.Z;
rgb.Y = hsv.Z;
rgb.Z = hsv.Z;
return rgb;
}
hh = hsv.X;
if (hh >= 360.0f) hh = 0.0f;
hh /= 60.0f;
i = (long)hh;
ff = hh - i;
p = hsv.Z * (1.0f - hsv.Y);
q = hsv.Z * (1.0f - (hsv.Y * ff));
t = hsv.Z * (1.0f - (hsv.Y * (1.0f - ff)));
switch (i)
{
case 0:
rgb.X = hsv.Z;
rgb.Y = t;
rgb.Z = p;
break;
case 1:
rgb.X = q;
rgb.Y = hsv.Z;
rgb.Z = p;
break;
case 2:
rgb.X = p;
rgb.Y = hsv.Z;
rgb.Z = t;
break;
case 3:
rgb.X = p;
rgb.Y = q;
rgb.Z = hsv.Z;
break;
case 4:
rgb.X = t;
rgb.Y = p;
rgb.Z = hsv.Z;
break;
default:
rgb.X = hsv.Z;
rgb.Y = p;
rgb.Z = q;
break;
}
return rgb;
}
// ConvertRGBtoHSV function
public static Vector3 ConvertRGBtoHSV(Vector3 rgb)
{
Vector3 hsv = new Vector3();
float min, max, delta;
min = rgb.X < rgb.Y ? rgb.X : rgb.Y;
min = min < rgb.Z ? min : rgb.Z;
max = rgb.X > rgb.Y ? rgb.X : rgb.Y;
max = max > rgb.Z ? max : rgb.Z;
hsv.Z = max;
delta = max - min;
if (delta < 0.00001f)
{
hsv.Y = 0;
hsv.X = 0;
return hsv;
}
if (max > 0.0f)
{
hsv.Y = (delta / max);
}
else
{
hsv.Y = 0.0f;
hsv.X = 0.0f;
return hsv;
}
if (rgb.X >= max)
hsv.X = (rgb.Y - rgb.Z) / delta;
else if (rgb.Y >= max)
hsv.X = 2.0f + (rgb.Z - rgb.X) / delta;
else
hsv.X = 4.0f + (rgb.X - rgb.Y) / delta;
hsv.X *= 60.0f;
if (hsv.X < 0.0f) hsv.X += 360.0f;
return hsv;
}
public static Color GuiFade(Color color, float alpha)
{
if (alpha < 0.0f) alpha = 0.0f;
else if (alpha > 1.0f) alpha = 1.0f;
return new Color(color.R, color.G, color.B, (byte)(color.A * alpha));
}
//public static int GuiSliderPro(Rectangle bounds, string textLeft, string textRight, ref float value, float minValue, float maxValue, int sliderWidth)
//{
// int result = 0;
// GuiState state = (GuiState)GuiGetState();
// float temp = (maxValue - minValue) / 2.0f;
// float* tempValue = &temp;
// int sliderValue = (int)(((value - minValue) / (maxValue - minValue)) * (bounds.Width - 2 * GuiGetStyle((int)GuiControl.SLIDER, (int)GuiControlProperty.BORDER_WIDTH)));
// Rectangle slider = new Rectangle
// {
// X = bounds.X,
// Y = bounds.Y + GuiGetStyle((int)GuiControl.SLIDER, (int)GuiControlProperty.BORDER_WIDTH) + GuiGetStyle((int)GuiControl.SLIDER, (int)GuiSliderProperty.SLIDER_PADDING),
// Width = 0,
// Height = bounds.Height - 2 * GuiGetStyle((int)GuiControl.SLIDER, (int)GuiControlProperty.BORDER_WIDTH) - 2 * GuiGetStyle((int)GuiControl.SLIDER, (int)GuiSliderProperty.SLIDER_PADDING)
// };
// if (sliderWidth > 0)
// {
// slider.X += (sliderValue - sliderWidth / 2);
// slider.Width = sliderWidth;
// }
// else if (sliderWidth == 0)
// {
// slider.X += GuiGetStyle((int)GuiControl.SLIDER, (int)GuiControlProperty.BORDER_WIDTH);
// slider.Width = sliderValue;
// }
// // Update control
// if ((state != GuiState.STATE_DISABLED) && !guiLocked)
// {
// Vector2 mousePoint = GetMousePosition();
// if (guiSliderDragging)
// {
// if (IsMouseButtonDown(MouseButton.Left))
// {
// if (CHECK_BOUNDS_ID(bounds, guiSliderActive))
// {
// state = GuiState.STATE_PRESSED;
// // Get equivalent value and slider position from mousePoint.X
// value = ((maxValue - minValue) * (mousePoint.X - (bounds.X + sliderWidth / 2))) / (bounds.Width - sliderWidth) + minValue;
// }
// }
// else
// {
// guiSliderDragging = false;
// guiSliderActive = new Rectangle();
// }
// }
// else if (CheckCollisionPointRec(mousePoint, bounds))
// {
// if (IsMouseButtonDown(MouseButton.Left))
// {
// state = GuiState.STATE_PRESSED;
// guiSliderDragging = true;
// guiSliderActive = bounds;
// if (!CheckCollisionPointRec(mousePoint, slider))
// {
// value = ((maxValue - minValue) * (mousePoint.X - (bounds.X + sliderWidth / 2))) / (bounds.Width - sliderWidth) + minValue;
// if (sliderWidth > 0) slider.X = mousePoint.X - slider.Width / 2;
// else if (sliderWidth == 0) slider.Width = sliderValue;
// }
// }
// else state = GuiState.STATE_FOCUSED;
// }
// if (value > maxValue) value = maxValue;
// else if (value < minValue) value = minValue;
// }
// // Bar limits check
// if (sliderWidth > 0)
// {
// if (slider.X <= (bounds.X + GuiGetStyle(GuiControl.SLIDER, GuiControlProperty.BORDER_WIDTH))) slider.X = bounds.X + GuiGetStyle(GuiControl.SLIDER, GuiControlProperty.BORDER_WIDTH);
// else if ((slider.X + slider.Width) >= (bounds.X + bounds.Width)) slider.X = bounds.X + bounds.Width - slider.Width - GuiGetStyle(GuiControl.SLIDER, GuiControlProperty.BORDER_WIDTH);
// }
// else if (sliderWidth == 0)
// {
// if (slider.Width > bounds.Width) slider.Width = bounds.Width - 2 * GuiGetStyle(GuiControl.SLIDER, GuiControlProperty.BORDER_WIDTH);
// }
// // Draw control
// GuiDrawRectangle(bounds, GuiGetStyle(GuiControl.SLIDER, GuiControlProperty.BORDER_WIDTH), GetColor(GuiGetStyle(GuiControl.SLIDER, (int)state * 3 + (int)GuiControlProperty.BORDER_COLOR_NORMAL)), GetColor(GuiGetStyle(GuiControl.SLIDER, (int)GuiControlProperty.BASE_COLOR_NORMAL)));
// // Draw slider internal bar
// if (state == GuiState.STATE_NORMAL) GuiDrawRectangle(slider, 0, Color.BLANK, GetColor(GuiGetStyle(GuiControl.SLIDER, (int)GuiControlProperty.BASE_COLOR_PRESSED)));
// else if (state == GuiState.STATE_FOCUSED) GuiDrawRectangle(slider, 0, Color.BLANK, GetColor(GuiGetStyle(GuiControl.SLIDER, (int)GuiControlProperty.TEXT_COLOR_FOCUSED)));
// else if (state == GuiState.STATE_PRESSED) GuiDrawRectangle(slider, 0, Color.BLANK, GetColor(GuiGetStyle(GuiControl.SLIDER, (int)GuiControlProperty.TEXT_COLOR_PRESSED)));
// // Draw left/right text if provided
// if (textLeft != null)
// {
// Rectangle textBounds = new Rectangle();
// textBounds.Width = (float)GetTextWidth(textLeft);
// textBounds.Height = (float)GuiGetStyle(GuiControl.DEFAULT, (int)GuiControlProperty.TEXT_SIZE);
// textBounds.X = bounds.X - textBounds.Width - GuiGetStyle(GuiControl.SLIDER, (int)GuiControlProperty.TEXT_PADDING);
// textBounds.Y = bounds.Y + bounds.Height / 2 - GuiGetStyle(GuiControl.DEFAULT, (int)GuiControlProperty.TEXT_SIZE) / 2;
// GuiDrawText(textLeft, textBounds, GuiTextAlignment.TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(GuiControl.SLIDER, (int)state * 3 + (int)GuiControlProperty.TEXT_COLOR_NORMAL)));
// }
// if (textRight != null)
// {
// Rectangle textBounds = new Rectangle();
// textBounds.Width = (float)GetTextWidth(textRight);
// textBounds.Height = (float)GuiGetStyle(GuiControl.DEFAULT, (int)GuiControlProperty.TEXT_SIZE);
// textBounds.X = bounds.X + bounds.Width + GuiGetStyle((int)GuiControl.SLIDER, (int)GuiControlProperty.TEXT_PADDING);
// textBounds.Y = bounds.Y + bounds.Height / 2 - GuiGetStyle(GuiControl.DEFAULT, (int)GuiControlProperty.TEXT_SIZE) / 2;
// GuiDrawText(textRight, textBounds, GuiTextAlignment.TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(GuiControl.SLIDER, (int)state * 3 + (int)GuiControlProperty.TEXT_COLOR_NORMAL)));
// }
// return result;
//}
}
}