Archived
forked from RDTKEditor/RDTKEditor
Merge pull request '封装预览区域绘制函数' (#4) from obsmain into master
Reviewed-on: obugs/RDTKEditor#4
This commit is contained in:
+13
-26
@@ -2,6 +2,7 @@
|
|||||||
using RDTKEditor.Models;
|
using RDTKEditor.Models;
|
||||||
using RhythmBase.Events;
|
using RhythmBase.Events;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
using SkiaSharp.Views.Desktop;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -16,6 +17,7 @@ namespace RDTKEditor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
|
private SKSizeI _vsScale = new(1600,900);
|
||||||
private readonly RDTKView viewModel = new();
|
private readonly RDTKView viewModel = new();
|
||||||
public MainWindow()
|
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 sfc = e.Surface;
|
||||||
var cvs = sfc.Canvas;
|
var cvs = sfc.Canvas;
|
||||||
var info = e.Info;
|
var info = e.Info;
|
||||||
|
|
||||||
// 清除画布
|
|
||||||
cvs.Clear(SKColors.Black);
|
cvs.Clear(SKColors.Black);
|
||||||
|
SKPoint scale = new(info.Width / _vsScale.Width, info.Height / _vsScale.Height);
|
||||||
// 获取绘图表面的宽度和高度
|
|
||||||
float width = info.Width;
|
|
||||||
float height = info.Height;
|
|
||||||
|
|
||||||
// 设置缩放比例
|
|
||||||
float scaleX = width / 1600f;
|
|
||||||
float scaleY = height / 900f;
|
|
||||||
|
|
||||||
// 保存画布状态
|
|
||||||
cvs.Save();
|
cvs.Save();
|
||||||
|
cvs.Scale(scale);
|
||||||
|
Draw(cvs);
|
||||||
|
cvs.Restore();
|
||||||
|
}
|
||||||
|
private void Draw(SKCanvas canvas)
|
||||||
|
{
|
||||||
|
// 以 1600x900 为基准绘制
|
||||||
|
|
||||||
// 应用缩放
|
canvas.DrawLine(0, 0, _vsScale.Width, _vsScale.Height, new SKPaint
|
||||||
cvs.Scale(scaleX, scaleY);
|
|
||||||
|
|
||||||
// 绘制内容
|
|
||||||
cvs.DrawLine(0, 0, 1600, 900, new SKPaint
|
|
||||||
{
|
{
|
||||||
Color = SKColors.Red,
|
Color = SKColors.Red,
|
||||||
StrokeWidth = 3,
|
StrokeWidth = 3,
|
||||||
IsStroke = true,
|
IsStroke = true,
|
||||||
});
|
});
|
||||||
cvs.DrawLine(0, 900, 1600, 0, new SKPaint
|
canvas.DrawLine(0, _vsScale.Height, _vsScale.Width, 0, new SKPaint
|
||||||
{
|
{
|
||||||
Color = SKColors.White,
|
Color = SKColors.White,
|
||||||
StrokeWidth = 3,
|
StrokeWidth = 3,
|
||||||
IsStroke = true,
|
IsStroke = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 恢复画布状态
|
|
||||||
cvs.Restore();
|
|
||||||
|
|
||||||
// 打印绘图表面的尺寸
|
|
||||||
Debug.Print(info.Size.ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public class MainViewModel : INotifyPropertyChanged
|
public class MainViewModel : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user