Archived
forked from RDTKEditor/RDTKEditor
Merge pull request '封装预览区域绘制函数' (#4) from obsmain into master
Reviewed-on: obugs/RDTKEditor#4
This commit is contained in:
+31
-44
@@ -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,51 +253,36 @@ namespace RDTKEditor
|
||||
});
|
||||
}*/
|
||||
|
||||
private void mainUI_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintSurfaceEventArgs e)
|
||||
{
|
||||
var sfc = e.Surface;
|
||||
var cvs = sfc.Canvas;
|
||||
var info = e.Info;
|
||||
private void mainUI_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
|
||||
{
|
||||
var sfc = e.Surface;
|
||||
var cvs = sfc.Canvas;
|
||||
var info = e.Info;
|
||||
cvs.Clear(SKColors.Black);
|
||||
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.Clear(SKColors.Black);
|
||||
|
||||
// 获取绘图表面的宽度和高度
|
||||
float width = info.Width;
|
||||
float height = info.Height;
|
||||
|
||||
// 设置缩放比例
|
||||
float scaleX = width / 1600f;
|
||||
float scaleY = height / 900f;
|
||||
|
||||
// 保存画布状态
|
||||
cvs.Save();
|
||||
|
||||
// 应用缩放
|
||||
cvs.Scale(scaleX, scaleY);
|
||||
|
||||
// 绘制内容
|
||||
cvs.DrawLine(0, 0, 1600, 900, new SKPaint
|
||||
{
|
||||
Color = SKColors.Red,
|
||||
StrokeWidth = 3,
|
||||
IsStroke = true,
|
||||
});
|
||||
cvs.DrawLine(0, 900, 1600, 0, new SKPaint
|
||||
{
|
||||
Color = SKColors.White,
|
||||
StrokeWidth = 3,
|
||||
IsStroke = true,
|
||||
});
|
||||
|
||||
// 恢复画布状态
|
||||
cvs.Restore();
|
||||
|
||||
// 打印绘图表面的尺寸
|
||||
Debug.Print(info.Size.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
canvas.DrawLine(0, 0, _vsScale.Width, _vsScale.Height, new SKPaint
|
||||
{
|
||||
Color = SKColors.Red,
|
||||
StrokeWidth = 3,
|
||||
IsStroke = true,
|
||||
});
|
||||
canvas.DrawLine(0, _vsScale.Height, _vsScale.Width, 0, new SKPaint
|
||||
{
|
||||
Color = SKColors.White,
|
||||
StrokeWidth = 3,
|
||||
IsStroke = true,
|
||||
});
|
||||
}
|
||||
}
|
||||
public class MainViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
Reference in New Issue
Block a user