修改插件系统接口,增加 SDK 开发函数方便开发

This commit is contained in:
寂静的羽夏 2022-03-25 18:20:05 +08:00
parent b44bd6d9ac
commit 27e9decabd
4 changed files with 138 additions and 9 deletions

View File

@ -496,8 +496,9 @@ namespace IWingRecorder
/// <summary> /// <summary>
/// 开始录制 /// 开始录制
/// </summary> /// </summary>
/// <param name="filename">录制文件</param>
/// <returns></returns> /// <returns></returns>
bool StartRecording(); bool StartRecording(string filename);
/// <summary> /// <summary>
/// 结束录制 /// 结束录制

View File

@ -1,9 +1,14 @@
using System.Text; using System.ComponentModel;
using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
namespace IWingRecorder namespace IWingRecorder
{ {
/// <summary>
/// 羽云录屏插件系统 SDK ,提供宿主与插件通信的编码基础,
/// 并提供简单的函数封装方便插件开发
/// </summary>
public partial class Utilities public partial class Utilities
{ {
/// <summary> /// <summary>
@ -12,20 +17,38 @@ namespace IWingRecorder
/// </summary> /// </summary>
public const string PluginVersion = "V1B"; public const string PluginVersion = "V1B";
/// <summary>
/// 对于 WPF 字体样式枚举
/// </summary>
public enum TextDecorationType public enum TextDecorationType
{ {
/// <summary>
/// 无效果
/// </summary>
None, None,
/// <summary>
/// 下划线
/// </summary>
Underline, Underline,
/// <summary>
/// 基线
/// </summary>
Baseline, Baseline,
/// <summary>
/// 删除线
/// </summary>
Strikethrough, Strikethrough,
/// <summary>
/// 上划线
/// </summary>
OverLine OverLine
} }
/// <summary> /// <summary>
/// 获取文本效果类型 /// 通过 WPF 文字样式获取 TextDecorationType 文本效果类型枚举
/// </summary> /// </summary>
/// <param name="decoration"></param> /// <param name="decoration">TextDecoration 对象</param>
/// <returns></returns> /// <returns>返回 TextDecorationType 枚举</returns>
public static TextDecorationType TypeOfTextDecorationItem(TextDecoration decoration) public static TextDecorationType TypeOfTextDecorationItem(TextDecoration decoration)
{ {
if (decoration == TextDecorations.Underline[0]) if (decoration == TextDecorations.Underline[0])
@ -47,6 +70,73 @@ namespace IWingRecorder
return TextDecorationType.None; return TextDecorationType.None;
} }
/// <summary>
/// 判断 TextDecorationCollection 对象是否包含 TextDecorationType 字体样式枚举
/// </summary>
/// <param name="decorations">TextDecorationCollection 对象</param>
/// <param name="type">TextDecorationType 字体样式枚举</param>
/// <returns>如果包含返回 true</returns>
public static bool TextDecorationTypeContains(TextDecorationCollection decorations, TextDecorationType type)
{
switch (type)
{
case TextDecorationType.None:
return true;
case TextDecorationType.Underline:
return decorations.Contains(TextDecorations.Underline[0]);
case TextDecorationType.Baseline:
return decorations.Contains(TextDecorations.Baseline[0]);
case TextDecorationType.Strikethrough:
return decorations.Contains(TextDecorations.Strikethrough[0]);
case TextDecorationType.OverLine:
return decorations.Contains(TextDecorations.OverLine[0]);
default:
return false;
}
}
/// <summary>
/// 获取包含最大路径的 StringBuilder 对象
/// </summary>
/// <returns></returns>
public static StringBuilder Get_MAX_PATH_BufferStringBuilder()
=> new StringBuilder(260);
/// <summary>
/// 将 WPF 的 Color 对象转化为 ARGB 十六进制数字
/// </summary>
/// <param name="color">WPF 的 Color 对象</param>
/// <returns>ARGB 十六进制数字</returns>
public static uint ColorToRGBHex(Color color)
{
return (uint)(color.A << 24 | color.R << 16 | color.G << 8 | color.B);
}
/// <summary>
/// 忽略大小写比较字符串
/// </summary>
/// <param name="str1">字符串 1</param>
/// <param name="str2">字符串 2</param>
/// <returns>如果忽略大小写字符串相等返回 true</returns>
public static bool StringCompareIgnoreCase(string str1, string str2)
{
return string.Compare(str1, str2, true) == 0;
}
/// <summary>
/// 调用 PropertyChanged 事件函数,通知数据更改
/// </summary>
/// <param name="propertyChanged">数据更改事件处理事件</param>
/// <param name="sender">触发者</param>
/// <param name="propertyName">属性名</param>
public static void OnPropertyChanged(PropertyChangedEventHandler propertyChanged, object sender, string propertyName)
{
propertyChanged?.Invoke(sender, new PropertyChangedEventArgs(propertyName));
}
/// <summary>
/// 羽云录屏封装的 WPF 字体对象
/// </summary>
public class WingFont public class WingFont
{ {
public FontFamily FontFamily { get; set; } public FontFamily FontFamily { get; set; }
@ -69,6 +159,43 @@ namespace IWingRecorder
} }
return $"{FontFamily} | {FontWeight} | {FontStyle} | {sb}"; return $"{FontFamily} | {FontWeight} | {FontStyle} | {sb}";
} }
/// <summary>
/// 将 WingFont 字体转为 C++ 使用的 LOGFONT
/// 注意此转换将会损失一些 WPF 字体特性
/// </summary>
/// <returns>LOGFONT结构体</returns>
public object ToLogFont()
{
var fontstyle = FontStyle;
System.Drawing.FontStyle fontStyle = System.Drawing.FontStyle.Regular;
if (fontstyle == FontStyles.Oblique || fontstyle== FontStyles.Italic)
fontStyle |= System.Drawing.FontStyle.Italic;
var textd = TextDecorations;
if (textd != null)
{
if(TextDecorationTypeContains(textd, TextDecorationType.Underline)||
TextDecorationTypeContains(textd, TextDecorationType.Baseline))
fontStyle|= System.Drawing.FontStyle.Underline;
if(TextDecorationTypeContains(textd, TextDecorationType.Strikethrough))
fontStyle |= System.Drawing.FontStyle.Strikeout;
}
var fontweight = FontWeight;
if (fontweight != null)
{
if (fontweight == FontWeights.Bold || fontweight == FontWeights.SemiBold ||
fontweight == FontWeights.DemiBold || fontweight == FontWeights.UltraBold ||
fontweight == FontWeights.ExtraBold)
fontStyle |= System.Drawing.FontStyle.Bold;
}
System.Drawing.Font font = new System.Drawing.Font(FontFamily.Source, (float)FontSize,fontStyle);
object logFont = new object();
font.ToLogFont(logFont);
return logFont;
}
} }
} }
} }

View File

@ -226,8 +226,9 @@ namespace TestAddin
return true; return true;
} }
public bool StartRecording() public bool StartRecording(string filename)
{ {
FormTest.WriteLine($"+ StartRecording : {filename}");
timer.Start(); timer.Start();
recordingState = RecordingState.Recording; recordingState = RecordingState.Recording;
return true; return true;
@ -305,7 +306,7 @@ namespace TestAddin
if (format == null) return false; if (format == null) return false;
foreach (var item in SupportRecordingFormats) foreach (var item in SupportRecordingFormats)
{ {
if (string.Compare(item.Name, format, true) == 0) if (Utilities.StringCompareIgnoreCase(item.Name, format))
{ {
currentRecordingFormat = format; currentRecordingFormat = format;
OnPropertyChanged(nameof(CurrentRecordingFormat)); OnPropertyChanged(nameof(CurrentRecordingFormat));
@ -336,7 +337,7 @@ namespace TestAddin
if (format == null) return false; if (format == null) return false;
foreach (var item in SupportScreenShotFormat) foreach (var item in SupportScreenShotFormat)
{ {
if (string.Compare(item, format, true) == 0) if (Utilities.StringCompareIgnoreCase(item, format))
{ {
currentScreenShotFormat = format; currentScreenShotFormat = format;
OnPropertyChanged(nameof(CurrentScreenShotFormat)); OnPropertyChanged(nameof(CurrentScreenShotFormat));

View File

@ -166,7 +166,7 @@ namespace WingRecorder
{ {
new CountDownWindow().ShowDialog(); new CountDownWindow().ShowDialog();
} }
if (engine.StartRecording()) if (engine.StartRecording(Utilities.GetRandomFileName(Utilities.RandomFileType.Video, engine.CurrentRecordingFormat)))
{ {
config.Locked = true; config.Locked = true;
lblStartRecord.Text = PauseTitle; lblStartRecord.Text = PauseTitle;