public PixelCanvas() { InitializeComponent(); TransformGroup group = new TransformGroup(); group.Children.Add(scale); group.Children.Add(translate); MainCanvas.RenderTransform = group; textShadow.Color = System.Windows.Media.Color.FromRgb(255, 255, 255); textShadow.Direction = 320; textShadow.ShadowDepth = 0.5; textShadow.Opacity = 0.5; textShadow.BlurRadius = 0; textShadow.Freeze(); //memory leak possible fix OnToolClick(moveTool, null); SetNameLabelDisplay(false); ChangeBrushSize(0); }
public void Run() { Debug.Assert(DataExchange != null && Helper != null && Launcher != null); //chatLocal.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 0xDD, 0xDD, 0xDD)); //chatGlobal.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 0xDD, 0xDD, 0xDD)); globalChatMode.IsChecked = true; //speedPanelGrid.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 0xDD, 0xDD, 0xDD)); textShadow.Color = System.Windows.Media.Color.FromRgb(255, 255, 255); textShadow.Direction = 320; textShadow.ShadowDepth = 0.5; textShadow.Opacity = 1.0; textShadow.BlurRadius = 2.0; textShadow.Freeze(); //possibly fix memory leak var updateTimer = new Timer(500); updateTimer.Elapsed += (a, b) => { try { Dispatcher.Invoke(() => DataExchange.CreateUpdate()); } catch (TaskCanceledException) { } }; updateTimer.Start(); speedLabelTimer = new System.Timers.Timer(1000); speedLabelTimer.AutoReset = true; speedLabelTimer.Elapsed += (a, b) => { try { Dispatcher.Invoke(RecalculateSpeedLabels); } catch (TaskCanceledException) { } }; speedLabelTimer.Start(); ignoreEvents = true; if (canvasId.Text.Length == 0) { canvasId.Text = "7"; } ignoreEvents = false; DataExchange.UpdateGeneralSettingsFromGUI(); }
/// <summary> /// Updates the line <paramref name="guide"/> with a new format. /// </summary> /// <param name="guide">The <see cref="Line"/> to update.</param> /// <param name="formatIndex">The new format index.</param> void UpdateGuide(LineSpan lineSpan, Line adornment) { if (lineSpan == null || adornment == null) { return; } LineFormat format; if (lineSpan.Type == LineSpanType.PageWidthMarker) { if (!Theme.PageWidthMarkers.TryGetValue(lineSpan.Indent, out format)) { format = Theme.DefaultLineFormat; } } else if (!Theme.LineFormats.TryGetValue(lineSpan.FormatIndex, out format)) { format = Theme.DefaultLineFormat; } if (!format.Visible) { adornment.Visibility = Visibility.Hidden; return; } bool highlight = lineSpan.Highlight || lineSpan.LinkedLines.Any(ls => ls.Highlight); var lineStyle = highlight ? format.HighlightStyle : format.LineStyle; var lineColor = (highlight && !lineStyle.HasFlag(LineStyle.Glow)) ? format.HighlightColor : format.LineColor; Brush brush; if (!GuideBrushCache.TryGetValue(lineColor, out brush)) { brush = new SolidColorBrush(lineColor.ToSWMC()); if (brush.CanFreeze) { brush.Freeze(); } GuideBrushCache[lineColor] = brush; } adornment.Stroke = brush; adornment.StrokeThickness = lineStyle.GetStrokeThickness(); adornment.StrokeDashArray = lineStyle.GetStrokeDashArray(); if (lineStyle.HasFlag(LineStyle.Dotted) || lineStyle.HasFlag(LineStyle.Dashed)) { adornment.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Unspecified); } else { adornment.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased); } if (lineStyle.HasFlag(LineStyle.Glow)) { Effect effect; var glowColor = highlight ? format.HighlightColor : format.LineColor; if (!GlowEffectCache.TryGetValue(glowColor, out effect)) { effect = new DropShadowEffect { Color = glowColor.ToSWMC(), BlurRadius = LineStyle.Thick.GetStrokeThickness(), Opacity = 1.0, ShadowDepth = 0.0, RenderingBias = RenderingBias.Performance }; if (effect.CanFreeze) { effect.Freeze(); } GlowEffectCache[glowColor] = effect; } try { adornment.Effect = effect; } catch (COMException) { // No sensible way to deal with this exception, so we'll // fall back on changing the color. adornment.Effect = null; if (!GuideBrushCache.TryGetValue(glowColor, out brush)) { brush = new SolidColorBrush(glowColor.ToSWMC()); if (brush.CanFreeze) { brush.Freeze(); } GuideBrushCache[glowColor] = brush; } adornment.Stroke = brush; } } else { adornment.Effect = null; } }