-
Notifications
You must be signed in to change notification settings - Fork 96
/
SCANcolorUtil.cs
357 lines (319 loc) · 10.9 KB
/
SCANcolorUtil.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#region license
/*
* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* SCANpalette - manages colors and palettes of colors
*
* Copyright (c)2014 technogeeky <technogeeky@gmail.com>;
* Copyright (c)2014 (Your Name Here) <your email here>; see LICENSE.txt for licensing details.
*/
#endregion
using System;
using System.Collections.Generic;
using UnityEngine;
using SCANsat.SCAN_Data;
using SCANsat.SCAN_Palettes;
namespace SCANsat.SCAN_UI.UI_Framework
{
public class SCANcolorUtil
{
// Basic Colors
// (these are here just so that all references to some color are the same throughout
// SCANsat)
public static Color black = Color.black;
public static Color32 Black = (Color32)black;
public static Color white = Color.white;
public static Color32 White = (Color32)white;
public static Color red = Color.red;
public static Color32 Red = (Color32)red;
public static Color grey = Color.grey;
public static Color32 Grey = (Color32)grey;
public static Color clear = Color.clear;
public static Color32 Clear = new Color32(0, 0, 0, 0);
public static Color magenta = Color.magenta;
public static Color yellow = Color.yellow;
public static Color cyan = Color.cyan;
public static Color blue = Color.blue;
public static Color green = Color.green;
public static Color mechjebYellow = new Color(1.0f, 0.56f, 0.0f);
public static Color lerp (Color a, Color b, float t) {
return Color.Lerp (a,b,t);
}
public static Color32 lerp(Color32 a, Color32 b, float t)
{
return Color32.Lerp(a, b, t);
}
// XKCD Colors
// (these are collected here for the same reason)
public static Color xkcd_Amber = XKCDColors.Amber;
public static Color xkcd_ArmyGreen = XKCDColors.ArmyGreen;
public static Color xkcd_PukeGreen = XKCDColors.PukeGreen;
public static Color xkcd_Lemon = XKCDColors.Lemon;
public static Color xkcd_OrangeRed = XKCDColors.OrangeRed;
public static Color xkcd_CamoGreen = XKCDColors.CamoGreen;
public static Color xkcd_Marigold = XKCDColors.Marigold;
public static Color xkcd_Puce = XKCDColors.Puce;
public static Color xkcd_DarkTeal = XKCDColors.DarkTeal;
public static Color xkcd_DarkPurple = XKCDColors.DarkPurple;
public static Color xkcd_DarkGrey = XKCDColors.DarkGrey;
public static Color xkcd_LightGrey = XKCDColors.LightGrey;
public static Color xkcd_PurplyPink = XKCDColors.PurplyPink;
public static Color xkcd_Magenta = XKCDColors.Magenta;
public static Color xkcd_YellowGreen = XKCDColors.YellowGreen;
public static Color xkcd_LightRed = XKCDColors.LightRed;
public static Color xkcd_Cerulean = XKCDColors.Cerulean;
public static Color xkcd_Yellow = XKCDColors.Yellow;
public static Color xkcd_Red = XKCDColors.Red;
public static Color xkcd_White = XKCDColors.White;
public static Color xkcd_DarkGreenAlpha = XKCDColors.DarkGreen * new Vector4(1, 1, 1, 0.4f);
// colourblind barrier-free colours, according to Masataka Okabe and Kei Ito
// http://jfly.iam.u-tokyo.ac.jp/color/
public static Color cb_skyBlue = new Color(0.35f, 0.7f, 0.9f); // sky blue
public static Color cb_bluishGreen = new Color(0f, 0.6f, 0.5f); // bluish green
public static Color cb_yellow = new Color(0.95f, 0.9f, 0.25f); // yellow
public static Color cb_blue = new Color(0f, 0.45f, 0.7f); // blue
public static Color cb_vermillion = new Color(0.8f, 0.4f, 0f); // vermillion
public static Color cb_reddishPurple = new Color(0.8f, 0.6f, 0.7f); // reddish purple
public static Color cb_orange = new Color(0.9f, 0.6f, 0f); // orange
public static Color32 CB_skyBlue = (Color32)cb_skyBlue;
public static Color32 CB_bluishGreen = (Color32)cb_bluishGreen;
public static Color32 CB_yellow = (Color32)cb_yellow;
public static Color32 CB_blue = (Color32)cb_blue;
public static Color32 CB_vermillion = (Color32)cb_vermillion;
public static Color32 CB_reddishPurple = (Color32)cb_reddishPurple;
public static Color32 CB_orange = (Color32)cb_orange;
/* SOLARIZED colors: currently unused, so commented out */
/*
public static Color sol_base03 = new Color32(0,43,54,255);
public static Color sol_base02 = new Color32(7,54,66,255);
public static Color sol_base01 = new Color32(88,110,117,255);
public static Color sol_base00 = new Color32(101,123,131,255);
public static Color sol_base0 = new Color32(131,148,150,255);
public static Color sol_base1 = new Color32(147,161,161,255);
public static Color sol_base2 = new Color32(238,232,213,255);
public static Color sol_base3 = new Color32(253,246,227,255);
public static Color sol_yellow = new Color32(181,137,0,255);
public static Color sol_orange = new Color32(203,75,22,255);
public static Color sol_red = new Color32(45,220,50,255);
public static Color sol_magenta = new Color32(211,54,130,255);
public static Color sol_violet = new Color32(108,113,196,255);
public static Color sol_blue = new Color32(38,139,210,255);
public static Color sol_cyan = new Color32(42,161,152,255);
public static Color sol_green = new Color32(133,153,0,255);
*/
public static Color[] heightGradient = {
xkcd_ArmyGreen,
xkcd_Yellow,
xkcd_Red,
xkcd_Magenta,
xkcd_White,
xkcd_White
};
public static Color32[] redline;
public static Color32[] small_redline;
public static Color32 heightToColor(float val, bool color, SCANterrainConfig terrain, float min = 0, float max = 0, float range = 0, bool useCustomRange = false)
{
Color32[] c = terrain.ColorPal.ColorsArray;
if (terrain.PalRev)
c = terrain.ColorPal.ColorsReverse;
if (useCustomRange)
{
if (color)
return heightToColor(val, max, min, range, terrain.ClampTerrain, terrain.PalDis, c, true);
else
return heightToColor(val, max, min, range, terrain.PalDis);
}
else
{
if (color)
return heightToColor(val, terrain.MaxTerrain, terrain.MinTerrain, terrain.TerrainRange, terrain.ClampTerrain, terrain.PalDis, c);
else
return heightToColor(val, terrain.MaxTerrain, terrain.MinTerrain, terrain.TerrainRange, terrain.PalDis);
}
}
private static Color32 heightToColor(float val, float max, float min, float range, bool discrete)
{
Color32 c = Black;
val -= min;
if (SCAN_Settings_Config.Instance.TrueGreyScale)
{
val = Mathf.Clamp(val, 0, range) / range;
c = lerp(Black, White, val);
}
else
{
if (discrete)
{
val = (GreyScalePalette.ColorsReverse.Length) * Mathf.Clamp(val, 0, range) / range;
if (Math.Floor(val) > GreyScalePalette.ColorsReverse.Length - 1)
val = GreyScalePalette.ColorsReverse.Length - 0.01f;
c = GreyScalePalette.ColorsReverse[(int)Math.Floor(val)];
}
else
{
val = (GreyScalePalette.ColorsReverse.Length - 1) * Mathf.Clamp(val, 0, range) / range;
if (Math.Floor(val) > GreyScalePalette.ColorsReverse.Length - 2)
val = GreyScalePalette.ColorsReverse.Length - 1.01f;
c = lerp(GreyScalePalette.ColorsReverse[(int)Math.Floor(val)], GreyScalePalette.ColorsReverse[(int)Math.Floor(val) + 1], val - (int)Math.Floor(val));
}
}
return c;
}
internal static Color32 heightToColor(float val, float max, float min, float range, float? clamp, bool discrete, Color32[] p, bool useCustomRange = false)
{
Color32 c = Black;
if (clamp != null)
{
if (!useCustomRange)
{
if (clamp < min + 10f)
clamp = min + 10f;
if (clamp > max - 10f)
clamp = max - 10f;
}
if (val <= (float)clamp)
{
float newRange;
if (useCustomRange)
{
if (max < (float)clamp)
newRange = max - min;
else
newRange = (float)clamp - min;
}
else
newRange = (float)clamp - min;
val -= min;
val = Mathf.Clamp(val, 0, newRange) / newRange;
if (discrete)
c = p[(int)Math.Round(val)];
else
c = lerp(p[0], p[1], val);
}
else
{
float newRange;
if (useCustomRange)
{
if (min > (float)clamp)
{
newRange = max - min;
val -= min;
}
else
{
newRange = max - (float)clamp;
val -= (float)clamp;
}
}
else
{
newRange = max - (float)clamp;
val -= (float)clamp;
}
if (discrete)
{
val = (p.Length - 2) * Mathf.Clamp(val, 0, newRange) / newRange;
if (Math.Floor(val) > p.Length - 3)
val = p.Length - 2.01f;
c = p[(int)Math.Floor(val) + 2];
}
else
{
val = (p.Length - 3) * Mathf.Clamp(val, 0, newRange) / newRange;
if (Math.Floor(val) > p.Length - 4)
val = p.Length - 3.01f;
c = lerp(p[(int)Math.Floor(val) + 2], p[(int)Math.Floor(val) + 3], val - (int)Math.Floor(val));
}
}
}
else
{
val -= min;
if (discrete)
{
val = (p.Length) * Mathf.Clamp(val, 0, range) / range;
if (Math.Floor(val) > p.Length - 1)
val = p.Length - 0.01f;
c = p[(int)Math.Floor(val)];
}
else
{
val = (p.Length - 1) * Mathf.Clamp(val, 0, range) / range;
if (Math.Floor(val) > p.Length - 2)
val = p.Length - 1.01f;
c = lerp(p[(int)Math.Floor(val)], p[(int)Math.Floor(val) + 1], val - (int)Math.Floor(val));
}
}
return c;
}
public static string colorHex ( Color32 c ) {
return string.Format("#{0:X2}{1:X2}{2:X2}", c.r, c.g, c.b);
}
public static string coloredNoQuote(Color c, string text)
{
return string.Format("<color={0}>{1}</color>", colorHex(c), text);
}
internal static Color c_good
{
get
{
if (SCANcontroller.controller.mainMapColor)
return cb_bluishGreen;
else
return cb_skyBlue;
}
}
internal static Color c_bad
{
get
{
return cb_orange;
}
}
internal static Color c_ugly {
get
{
if (SCANcontroller.controller.mainMapColor)
return xkcd_LightRed;
else
return cb_yellow;
}
}
private static SCANPaletteType currentPaletteSet;
private static SCANPalette greyScalePalette;
public static SCANPaletteType SetCurrentPalettesType(SCANPaletteKind type)
{
return SCANconfigLoader.SCANPalettes.GetPaletteType(type);
}
public static SCANPalette GreyScalePalette
{
get
{
if (greyScalePalette == null)
{
Color32[] c = new Color32[9] { new Color32(255, 255, 255, 255), new Color32(240, 240, 240, 255), new Color32(217, 217, 217, 255), new Color32(189, 189, 189, 255), new Color32(150, 150, 150, 255), new Color32(115, 115, 115, 255), new Color32(082, 082, 082, 255), new Color32(037, 037, 037, 255), new Color32(000, 0, 000, 255) };
greyScalePalette = new SCANPalette(c, "GreyScalePalette", SCANPaletteKind.Fixed, c.Length);
}
return greyScalePalette;
}
}
public static SCANPaletteType CurrentPalettes
{
get { return currentPaletteSet; }
internal set
{
currentPaletteSet = value;
}
}
public static string[] GetPaletteKindNames()
{
SCANPaletteKind[] v = (SCANPaletteKind[])Enum.GetValues(typeof(SCANPaletteKind));
string[] r = new string[v.Length - 1];
for (int i = 0; i < v.Length - 1; ++i)
r[i] = v[i].ToString();
return r;
}
}
}