Merge pull request '封装预览区域绘制函数' (#4) from obsmain into master

Reviewed-on: obugs/RDTKEditor#4
This commit is contained in:
2025-04-02 10:42:11 +08:00
+13 -26
View File
@@ -2,6 +2,7 @@
using RDTKEditor.Models;
using RhythmBase.Events;
using SkiaSharp;
using SkiaSharp.Views.Desktop;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
@@ -16,6 +17,7 @@ namespace RDTKEditor
/// </summary>
public partial class MainWindow : Window
{
private SKSizeI _vsScale = new(1600,900);
private readonly RDTKView viewModel = new();
public MainWindow()
{
@@ -251,50 +253,35 @@ namespace RDTKEditor
});
}*/
private void mainUI_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintSurfaceEventArgs e)
private void mainUI_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
var sfc = e.Surface;
var cvs = sfc.Canvas;
var info = e.Info;
// 清除画布
cvs.Clear(SKColors.Black);
// 获取绘图表面的宽度和高度
float width = info.Width;
float height = info.Height;
// 设置缩放比例
float scaleX = width / 1600f;
float scaleY = height / 900f;
// 保存画布状态
SKPoint scale = new(info.Width / _vsScale.Width, info.Height / _vsScale.Height);
cvs.Save();
cvs.Scale(scale);
Draw(cvs);
cvs.Restore();
}
private void Draw(SKCanvas canvas)
{
// 以 1600x900 为基准绘制
// 应用缩放
cvs.Scale(scaleX, scaleY);
// 绘制内容
cvs.DrawLine(0, 0, 1600, 900, new SKPaint
canvas.DrawLine(0, 0, _vsScale.Width, _vsScale.Height, new SKPaint
{
Color = SKColors.Red,
StrokeWidth = 3,
IsStroke = true,
});
cvs.DrawLine(0, 900, 1600, 0, new SKPaint
canvas.DrawLine(0, _vsScale.Height, _vsScale.Width, 0, new SKPaint
{
Color = SKColors.White,
StrokeWidth = 3,
IsStroke = true,
});
// 恢复画布状态
cvs.Restore();
// 打印绘图表面的尺寸
Debug.Print(info.Size.ToString());
}
}
public class MainViewModel : INotifyPropertyChanged
{