Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复弹幕模糊的问题 #725

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/Libs/Danmaku.Core/DanmakuRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ internal class DanmakuRender
private volatile float _rollingAreaRatio = 0.8f;
private volatile float _rollingSpeed = DefaultRollingSpeed; // 1 to 10
private volatile bool _isPaused;
private float _scale = 1.0f;
private double _textOpacity = 1.0;
private Color _borderColor = Colors.Blue;
private string _defaultFontFamilyName = DefaultFontFamilyName;
Expand All @@ -69,9 +70,10 @@ public DanmakuRender(CanvasAnimatedControl canvas, FrameworkElement container)
_canvas = canvas ?? throw new ArgumentNullException("canvas");
_container = container;
_dpi = _canvas.Dpi;
CanvasWidth = (float)container.ActualWidth;
CanvasHeight = (float)_container.ActualHeight;
_rollingSpeed = DefaultRollingSpeed;
_scale = (float)(_canvas?.XamlRoot?.RasterizationScale ?? 1.0);
CanvasWidth = (float)(container.ActualWidth * _scale);
CanvasHeight = (float)(_container.ActualHeight * _scale);
_rollingSpeed = (float)(DefaultRollingSpeed * _scale);

_container.SizeChanged += OnContainerSizeChanged;
_canvas.CreateResources += OnCanvasCreateResources;
Expand Down Expand Up @@ -116,7 +118,7 @@ public void SetRollingAreaRatio(int value)

public void SetRollingSpeed(double value)
{
_rollingSpeed = (float)(value * 0.02f);
_rollingSpeed = (float)(value * 0.02f * _scale);
}

public void SetOpacity(double value)
Expand Down Expand Up @@ -224,6 +226,7 @@ public void RenderDanmakuItem(uint layerId, DanmakuItem danmakuItem)
}
}
textFormat.FontSize = (int)Math.Max(textFormat.FontSize, 2f);
textFormat.FontSize = textFormat.FontSize * _scale;

if (!string.IsNullOrWhiteSpace(renderItem.FontFamilyName))
{
Expand Down Expand Up @@ -584,11 +587,11 @@ private void OnContainerSizeChanged(object sender, SizeChangedEventArgs e)
return;
}

CanvasWidth = (float)e.NewSize.Width;
CanvasHeight = (float)e.NewSize.Height;
CanvasWidth = (float)(e.NewSize.Width * _scale);
CanvasHeight = (float)(e.NewSize.Height * _scale);
for (int i = 0; i < _renderLayerList.Length; i++)
{
_renderLayerList[i].UpdateYSlotManagerLength((uint)e.NewSize.Height, _rollingAreaRatio);
_renderLayerList[i].UpdateYSlotManagerLength((uint)(e.NewSize.Height * _scale), _rollingAreaRatio);
}
Logger.Log($"Update canvas size: {CanvasWidth}x{CanvasHeight}");
}
Expand Down Expand Up @@ -725,6 +728,7 @@ private void OnCanvasDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEvent
}

int totalCount = 0;
args.DrawingSession.Transform = new Matrix3x2 { M11 = 1f / _scale, M22 = 1f / _scale };
for (uint layerId = 0; layerId < _renderLayerList.Length; layerId++)
{
if (!_renderLayerList[layerId].IsEnabled)
Expand Down
Loading