diff --git a/SCANmap.cs b/SCANmap.cs index e2883c9..78ee3eb 100644 --- a/SCANmap.cs +++ b/SCANmap.cs @@ -10,34 +10,50 @@ public class SCANmap XKCDColors.Yellow, XKCDColors.Red, XKCDColors.Magenta, - XKCDColors.White, XKCDColors.White }; + public static float startGradientHeight = -1500;// default range is from -1500 to 9000 + public static float heightGradientRange = 10500;// default of 10500 + private const float gradientSealevelPercent = 1500f/10500f;//indetifys the point to start using heightGradient for lerps public static Color heightToColor(float val, int scheme) { if(scheme == 1 || SCANcontroller.controller.colours == 1) { - return Color.Lerp(Color.black, Color.white, Mathf.Clamp((val + 1500f) / 9000f, 0, 1)); + return Color.Lerp(Color.black, Color.white, Mathf.Clamp((val - startGradientHeight) / heightGradientRange, 0, 1)); } Color c = Color.black; - if(val <= 0) { - val = (Mathf.Clamp(val, -1500, 0) + 1500) / 1000f; - c = Color.Lerp(XKCDColors.DarkPurple, XKCDColors.Cerulean, val); - } else { - val = (heightGradient.Length - 2) * Mathf.Clamp(val, 0, 7500) / 7500.0f; - c = Color.Lerp(heightGradient[(int)val], heightGradient[(int)val + 1], val - (int)val); + val -= startGradientHeight; + val /= heightGradientRange; + if (val<0f) {//below gradient range + c=XKCDColors.DarkPurple; } + else if (val>=1f) {//above gradient range + c=heightGradient[heightGradient.Length-1]; + } + else {//in gradient range + if (val<=gradientSealevelPercent) { + c = Color.Lerp(XKCDColors.DarkPurple, XKCDColors.Cerulean, val/gradientSealevelPercent ); + } else { + val -= gradientSealevelPercent;//remove sealevel chunk + val /= (1f-gradientSealevelPercent);//realign the range from 0 to 1 + val *= (heightGradient.Length-1); + c = Color.Lerp(heightGradient[(int)val], heightGradient[(int)val + 1], val - (int)val); + } + } return c; } public static Texture2D legend; - private static float legendMin, legendMax; + private static float legendMin, legendMax, legendstartGradientHeight, legendheightGradientRange; private static int legendScheme; public static Texture2D getLegend(float min, float max, int scheme) { - if(legend != null && legendMin == min && legendMax == max && legendScheme == scheme) return legend; + if( legend != null && legendMin == min && legendMax == max && legendScheme == scheme && + legendstartGradientHeight == startGradientHeight && legendheightGradientRange == heightGradientRange ) return legend; legend = new Texture2D(256, 1, TextureFormat.RGB24, false); legendMin = min; legendMax = max; legendScheme = scheme; + legendstartGradientHeight = startGradientHeight; + legendheightGradientRange = heightGradientRange; Color[] pix = legend.GetPixels(); for(int x=0; x<256; ++x) { float val = (x * (max - min)) / 256f + min; @@ -412,4 +428,4 @@ public void resetMap(int mode) { resetMap(); } } -} \ No newline at end of file +} diff --git a/SCANui.cs b/SCANui.cs index d6b3964..5c27f66 100644 --- a/SCANui.cs +++ b/SCANui.cs @@ -975,7 +975,7 @@ private static void drawLegendLabel(Rect r, float val, float min, float max) { drawLabel(lr, Color.white, txt, false, true); } - private static void drawLegend() { + private static Rect drawLegend() { if(bigmap.mapmode == 0 && SCANcontroller.controller.legend) { GUILayout.Label("", GUILayout.ExpandWidth(true)); Rect r = GUILayoutUtility.GetLastRect(); @@ -984,7 +984,8 @@ private static void drawLegend() { for(float val=-1000f; val < 9000f; val += 1000f) { drawLegendLabel(r, val, -1500f, 9000f); } - } + return r; + }return new Rect(0,0,0,0); } private static void gui_bigmap_build(int wid) { @@ -1209,17 +1210,27 @@ private static void gui_bigmap_build(int wid) { info += " " + mlat.ToString("F") + " " + mlon.ToString("F"); // uncomment for debugging projections } } + + Rect legend_rect; if(maprect.width < 720) { GUILayout.EndHorizontal(); readableLabel(info, Color.white); - drawLegend(); + legend_rect = drawLegend(); } else { GUILayout.BeginVertical(); readableLabel(info, Color.white); - drawLegend(); + legend_rect = drawLegend(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } + bool in_gradient_legend = false; + float gradient_height = -1; + if(legend_rect.width>0f) { + float mgx = (Event.current.mousePosition.x - legend_rect.x) / legend_rect.width; + float mgy = (Event.current.mousePosition.y - legend_rect.y) / legend_rect.height; + in_gradient_legend = (mgx>=0f) && (mgx<=1f) && (mgy>=0f) && (mgy<=1f); + gradient_height = -1500f+(mgx*10500f); + } if(!notMappingToday) drawMapLabels(maprect, vessel, bigmap, data); @@ -1270,6 +1281,12 @@ private static void gui_bigmap_build(int wid) { pos_spotmap.y = Math.Max(maprect.y, Math.Min(maprect.y + maprect.height - pos_spotmap.height, pos_spotmap.y)); } } + if (in_gradient_legend) + { + SCANmap.heightGradientRange = gradient_height-SCANmap.startGradientHeight; + bigmap.resetMap(); + if(spotmap != null) spotmap.resetMap(); + } } else if(Event.current.button == 0) { if(spotmap != null && in_spotmap) { spotmap.mapscale = spotmap.mapscale / 1.25f; @@ -1277,6 +1294,14 @@ private static void gui_bigmap_build(int wid) { spotmap.resetMap(spotmap.mapmode); Event.current.Use(); } + if (in_gradient_legend) + { + float end_pos = SCANmap.startGradientHeight+SCANmap.heightGradientRange; + SCANmap.startGradientHeight = gradient_height; + SCANmap.heightGradientRange = end_pos-SCANmap.startGradientHeight; + bigmap.resetMap(); + if(spotmap != null) spotmap.resetMap(); + } } Event.current.Use(); } else if(Event.current.type == EventType.MouseDown) {