/// <summary> /// Gets grayscale brush from color. /// </summary> /// <param name="originalColor">Input color.</param> /// <returns>Brush with converted grayscale color.</returns> private static SolidColorBrush _GetGrayscaleBrush(System.Drawing.Color originalColor) { Color grayscaleColor = new Color(); double R = Convert.ToDouble(originalColor.R); double G = Convert.ToDouble(originalColor.G); double B = Convert.ToDouble(originalColor.B); grayscaleColor.A = originalColor.A; // Convert original color to grayscale. grayscaleColor.R = Convert.ToByte((R + G + B) / GRAYSCALE_CONVERTER_PARAMETER); grayscaleColor.G = Convert.ToByte((R + G + B) / GRAYSCALE_CONVERTER_PARAMETER); grayscaleColor.B = Convert.ToByte((R + G + B) / GRAYSCALE_CONVERTER_PARAMETER); SolidColorBrush resultBrush = new SolidColorBrush(grayscaleColor); // Freeze brush. resultBrush = (SolidColorBrush)resultBrush.GetCurrentValueAsFrozen(); Debug.Assert(resultBrush != null); return resultBrush; }
/// <summary> /// Creates canvas with invalidated route and its stops. /// </summary> /// <param name="route">Route to draw.</param> /// <param name="sortedRouteStops">Sorted stops from route.</param> /// <param name="mapImage">Map image.</param> /// <returns>Canvas with invalidated route and its stops.</returns> private SysControls.Canvas _CreateRouteCanvas(Route route, IList<Stop> sortedRouteStops, MapImage mapImage) { Debug.Assert(null != route); Debug.Assert(null != mapImage); Debug.Assert(null != sortedRouteStops); // create canvas var canvas = new SysControls.Canvas(); canvas.InvalidateVisual(); canvas.Height = mapImage.ImageHeight; canvas.Width = mapImage.ImageWidth; // init route brush from route color System.Drawing.Color color = route.Color; var mediaColor = SysWindows.Media.Color.FromArgb(color.A, color.R, color.G, color.B); var fillingBrush = new SolidColorBrush(mediaColor); // create and init route image SymbolControl routeBox = new SymbolControl(_routeSymbolTemplate); routeBox.Geometry = _CreatePath(route, sortedRouteStops, mapImage.Extent, mapImage.ImageWidth, mapImage.ImageHeight); routeBox.Fill = (SolidColorBrush)fillingBrush.GetCurrentValueAsFrozen(); routeBox.HorizontalAlignment = HorizontalAlignment.Stretch; routeBox.VerticalAlignment = VerticalAlignment.Stretch; // draw route canvas.Children.Add(routeBox); // draw stops - from last to first (visual elements) int stopLastIndex = sortedRouteStops.Count - 1; for (int index = stopLastIndex; index >= 0; --index) { Stop stop = sortedRouteStops[index]; if (!stop.MapLocation.HasValue) continue; // skip empty bool isVisible = true; if (stop.AssociatedObject is Location) { if (index == 0) { isVisible = _showLeadingStemTime; } else if (index == stopLastIndex) { isVisible = _showTrailingStemTime; } // else do nothing } if (isVisible) { UIElement element = _CreateStopUIElement(stop, mapImage, fillingBrush); if (element != null) canvas.Children.Add(element); } } return canvas; }
/// <summary> /// Defines fill brush. /// </summary> /// <param name="parentColor">Parent color.</param> /// <returns>Normal fill brush</returns> private static SolidColorBrush _GetFillBrush(System.Drawing.Color parentColor) { Color color = new Color(); color.A = parentColor.A; color.R = parentColor.R; color.G = parentColor.G; color.B = parentColor.B; SolidColorBrush resultBrush = new SolidColorBrush(color); // Freeze brush. resultBrush = (SolidColorBrush)resultBrush.GetCurrentValueAsFrozen(); Debug.Assert(resultBrush != null); return resultBrush; }
/// <summary> /// Returns selected brush. /// </summary> /// <returns>Selected brush.</returns> public static Brush GetSelectedBrush() { if (_selectionBrush == null) { _selectionBrush = (SolidColorBrush)Application.Current.FindResource(SELECTION_COLOR_NAME); _selectionBrush = (SolidColorBrush)_selectionBrush.GetCurrentValueAsFrozen(); } return _selectionBrush; }
/// <summary> /// Returns location brush. /// </summary> /// <returns>Location brush.</returns> public static Brush GetLocationBrush() { if (_locationBrush == null) { _locationBrush = (SolidColorBrush)Application.Current.FindResource(LOCATION_COLOR_SOURCE_NAME); _locationBrush = (SolidColorBrush)_locationBrush.GetCurrentValueAsFrozen(); } return _locationBrush; }
/// <summary> /// Returns drag over brush. /// </summary> /// <returns>Drag over brush.</returns> public static Brush GetDragOverBrush() { if (_dragOverBrush == null) { _dragOverBrush = (SolidColorBrush)Application.Current.FindResource(DRAG_OVER_COLOR_NAME); _dragOverBrush = (SolidColorBrush)_dragOverBrush.GetCurrentValueAsFrozen(); } return _dragOverBrush; }
/// <summary> /// Returns break brush. /// </summary> /// <returns>Break brush.</returns> public static Brush GetBreakBrush() { if (_breakBrush == null) { _breakBrush = (SolidColorBrush)Application.Current.FindResource(BREAK_COLOR_SOURCE_NAME); _breakBrush = (SolidColorBrush)_breakBrush.GetCurrentValueAsFrozen(); } return _breakBrush; }