private void DrawIndicatorV(Rect rect, float value, float minV, float maxV) { GUI.BeginGroup(rect); bool clamped = false; if (value < minV) { value = minV; clamped = true; } if (value > maxV) { value = maxV; clamped = true; } var sx = rect.width; var sy = rect.height; GUI.Box(new Rect(0, 0, sx, sy), ""); Color color = XKCDColors.NeonGreen; float spacing = (float)Math.Floor(sy * 0.11f + 0.5f); float middle = (float)Math.Floor(sy * 0.5f + 0.5f); var lineRect = new Rect(3, 0, sx - 6, 1); for (float y = middle + spacing; y < sy; y += spacing) { lineRect.y = y; Drawing.DrawRect(lineRect, color); } for (float y = middle - spacing; y > 0; y -= spacing) { lineRect.y = y; Drawing.DrawRect(lineRect, color); } lineRect.y = middle - 1; lineRect.x = 1; lineRect.width = sx - 3; lineRect.height = 3; color = XKCDColors.NeonBlue; Drawing.DrawRect(lineRect, color); // our box runs for 0 to sy-1 // we do not want diamond to get clipped // so lowest y should be 0 and highest should be (sy-1)-9 // center should draw at middle - 4 var frac = -0.5f + (value - minV) / (maxV - minV); // range -0.5 to 0.5 var range = (sy - 1) - 9; float yy = middle + range * frac - 4; var dcolor = clamped ? XKCDColors.NeonRed : XKCDColors.NeonBlue; Drawing.DrawDiamond(new Rect(3, yy, 15, 9), dcolor); GUI.EndGroup(); }
private void DrawIndicatorH(Rect rect, float value, float minV, float maxV) { GUI.BeginGroup(rect); bool clamped = false; if (value < minV) { value = minV; clamped = true; } if (value > maxV) { value = maxV; clamped = true; } float sx = rect.width; float sy = rect.height; GUI.Box(new Rect(0, 0, sx, sy), ""); Color color = XKCDColors.NeonGreen; float spacing = (float)Math.Floor(sx * 0.11f + 0.5f); float middle = (float)Math.Floor(sx * 0.5f + 0.5f); Rect lineRect = new Rect(0, 3, 1, sy - 6); for (float x = middle + spacing; x < sx; x += spacing) { lineRect.x = x; Drawing.DrawRect(lineRect, color); } for (float x = middle - spacing; x > 0; x -= spacing) { lineRect.x = x; Drawing.DrawRect(lineRect, color); } lineRect.x = middle - 1; lineRect.y = 1; lineRect.height = sy - 3; lineRect.width = 3; color = XKCDColors.NeonBlue; Drawing.DrawRect(lineRect, color); // our box runs for 0 to sx-1 // we do not want diamond to get clipped // so lowest y should be 0 and highest should be (sx-1)-9 // center should draw at middle - 4 float frac = -0.5f + (value - minV) / (maxV - minV); // range -0.5 to 0.5 float range = (sx - 1) - 9; float xx = middle + range * frac - 4; Color dcolor = clamped ? XKCDColors.NeonRed : XKCDColors.NeonBlue; Drawing.DrawDiamond(new Rect(xx, 3, 9, 15), dcolor); GUI.EndGroup(); }