public DominoRenderer(ProjectCanvas pc) { _noSkia = new FormattedText() { Text = "Current rendering API is not Skia" }; Bounds = new Rect(0, 0, pc.Bounds.Width, pc.Bounds.Height); TightBounds = pc.TransformedBounds; shift_x = (float)pc.ShiftX; shift_y = (float)pc.ShiftY; zoom = (float)pc.Zoom; unselectedBorderColor = pc.UnselectedBorderColor.ToSKColor(); selectedBorderColor = pc.SelectedBorderColor.ToSKColor(); pasteHightlightColor = Colors.Violet.ToSKColor(); deletionHighlightColor = SKColors.Red; selectionColor = pc.SelectionDomainColor.ToSKColor(); selectionPath = pc.SelectionDomain.Clone(); this.project = pc.Project; // Transform the selection path into screen coordinates var transform = SKMatrix.CreateScaleTranslation(zoom, zoom, -shift_x * zoom, -shift_y * zoom); this.ProjectHeight = (float)pc.ProjectHeight; this.ProjectWidth = (float)pc.ProjectWidth; this.above = pc.SourceImageAbove; this.background = pc.BackgroundColor.ToSKColor(); this.AdditionalDrawables = pc.AdditionalDrawables; selectionPath?.Transform(transform); selectionVisible = pc.SelectionDomainVisible; bitmap = pc.SourceImage; bitmapopacity = (byte)(pc.SourceImageOpacity * 255); dominoopacity = (byte)(pc.DominoOpacity * 255); BorderSize = pc.BorderSize; }
private void AdditionalDrawablesChanged(ProjectCanvas o, AvaloniaPropertyChangedEventArgs e) { if (e.OldValue != null && e.OldValue is AvaloniaList <CanvasDrawable> list) { list.CollectionChanged -= ForceRedrawMethod; } if (e.NewValue != null && e.NewValue is AvaloniaList <CanvasDrawable> list2) { list2.CollectionChanged += ForceRedrawMethod; } }
private void UpdateHorizontalSlider(ProjectCanvas o, AvaloniaPropertyChangedEventArgs e) { if (e == null || e.Property == ShiftXProperty || e.Property == ZoomProperty) { double newval = e == null || e.Property == ZoomProperty ? ShiftX : (double)e.NewValue; // Binding to maximum or minimum doesn't work for some reason, so it's fixed VirtualHorizontalSliderMax = Math.Max(ShiftX, ProjectWidth - Bounds.Width / Zoom); VirtualHorizontalSliderMin = Math.Min(ShiftX, 0); var scaling_factor = 100.0 / (VirtualHorizontalSliderMax - VirtualHorizontalSliderMin); var candidate = newval * scaling_factor - VirtualHorizontalSliderMin * scaling_factor; if (Math.Abs(candidate - HorizontalSliderPos) > 0.01) { HorizontalSliderPos = candidate; } HorizontalSliderSize = scaling_factor * Bounds.Width; } else if (e.Property == HorizontalSliderPosProperty && !double.IsNaN((double)e.NewValue)) { var scaling_factor = 100.0 / (VirtualHorizontalSliderMax - VirtualHorizontalSliderMin); ShiftX = (double)e.NewValue / scaling_factor + VirtualHorizontalSliderMin; } }