Skip to content

Commit

Permalink
支持设置弹幕字体
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmoyue committed May 2, 2024
1 parent a31b9fa commit 36428f7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/BiliLite.UWP/Controls/PlayerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,11 @@
<Slider x:Name="DanmuTopMargin" Value="0" Minimum="0" Maximum="200" StepFrequency="4"></Slider>
<TextBlock Margin="0 4 0 0">弹幕同屏密度(0为不限制) <Run Text="{x:Bind Path=DanmuSettingMaxNum.Value,Mode=OneWay,Converter={StaticResource numberToStringConvert}}"/></TextBlock>
<Slider x:Name="DanmuSettingMaxNum" Value="0" Minimum="0" Maximum="50" StepFrequency="1"></Slider>

<TextBlock Margin="0 4 0 0">
弹幕字体
</TextBlock>
<AutoSuggestBox QueryIcon="Accept" x:Name="DanmuSettingFont"></AutoSuggestBox>

<Grid Margin="0 4 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
Expand Down
11 changes: 11 additions & 0 deletions src/BiliLite.UWP/Controls/PlayerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,17 @@ private void LoadDanmuSetting()
SettingService.SetValue<int>(SettingConstants.VideoDanmaku.BORDER_STYLE, DanmuSettingStyle.SelectedIndex);
}
});

//弹幕字体
var fontFamily =
SettingService.GetValue<string>(SettingConstants.VideoDanmaku.DANMAKU_FONT_FAMILY, string.Empty);
m_danmakuController.SetFont(fontFamily);
DanmuSettingFont.Text = fontFamily;
DanmuSettingFont.QuerySubmitted += (e, args) =>
{
m_danmakuController.SetFont(DanmuSettingFont.Text);
SettingService.SetValue(SettingConstants.VideoDanmaku.DANMAKU_FONT_FAMILY, DanmuSettingFont.Text);
};
//合并弹幕
DanmuSettingMerge.IsOn = SettingService.GetValue<bool>(SettingConstants.VideoDanmaku.MERGE, false);
DanmuSettingMerge.Toggled += async (e, args) =>
Expand Down
6 changes: 6 additions & 0 deletions src/BiliLite.UWP/Models/Common/SettingConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ public class VideoDanmaku
/// </summary>
[SettingKey(typeof(int))]
public const string SHIELD_LEVEL = "VideoDanmuShieldLevel";

/// <summary>
/// 弹幕字体
/// </summary>
[SettingKey(typeof(string))]
public const string DANMAKU_FONT_FAMILY = "VideoDanmuFontFamily";
}

public class Live
Expand Down
5 changes: 5 additions & 0 deletions src/BiliLite.UWP/Services/FrostMasterDanmakuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public override void ShowScroll()
m_danmakuMaster.SetLayerRenderState(DanmakuDefaultLayerDef.RollingLayerId, true);
}

public override void SetFont(string fontName)
{
m_danmakuMaster.SetFontFamilyName(fontName);
}

public override void SetFontZoom(double fontZoom)
{
base.SetFontZoom(fontZoom);
Expand Down
6 changes: 6 additions & 0 deletions src/BiliLite.UWP/Services/Interfaces/IDanmakuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public virtual void Show()
/// </summary>
public abstract void ShowScroll();

/// <summary>
/// 设置字体
/// </summary>
/// <param name="fontName"></param>
public abstract void SetFont(string fontName);

/// <summary>
/// 设置弹幕字体缩放
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/BiliLite.UWP/Services/NsDanmakuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public override void ShowScroll()
m_danmakuControl.ShowDanmaku(DanmakuLocation.Scroll);
}

public override void SetFont(string fontName)
{
if (string.IsNullOrEmpty(fontName)) return;
m_danmakuControl.FontFamily = new FontFamily(fontName);
}

public override void SetFontZoom(double fontZoom)
{
base.SetFontZoom(fontZoom);
Expand Down

0 comments on commit 36428f7

Please sign in to comment.