Commit a93a2bfe by liulongfei

添加跟踪框样式,其他累积更新

parent fe3c3e43
...@@ -24,9 +24,7 @@ ...@@ -24,9 +24,7 @@
</Border> </Border>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True"> <Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="bd" Property="Background" Value="#22ffffff"></Setter> <Setter TargetName="bd" Property="Background" Value="#66ff0000"></Setter>
<Setter TargetName="rect1" Property="Fill" Value="#ffff0000"></Setter>
<Setter TargetName="rect2" Property="Fill" Value="#ffff0000"></Setter>
</Trigger> </Trigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
......
...@@ -165,6 +165,10 @@ ...@@ -165,6 +165,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Widgets\IconButton\IconButton.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Widgets\LabelValue\LabelValue.xaml"> <Page Include="Widgets\LabelValue\LabelValue.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
...@@ -217,6 +221,7 @@ ...@@ -217,6 +221,7 @@
<Compile Include="VideoControl\Control\Plugin\ManualCorrection\ManualCorrectionExpand.cs" /> <Compile Include="VideoControl\Control\Plugin\ManualCorrection\ManualCorrectionExpand.cs" />
<Compile Include="VideoControl\Control\Plugin\ManualCorrection\Info\ManualCorrectionInfo.cs" /> <Compile Include="VideoControl\Control\Plugin\ManualCorrection\Info\ManualCorrectionInfo.cs" />
<Compile Include="VideoControl\Control\Plugin\ManualCorrection\ManualCorrectionPlugin.cs" /> <Compile Include="VideoControl\Control\Plugin\ManualCorrection\ManualCorrectionPlugin.cs" />
<Compile Include="VideoControl\Control\Plugin\TrackingBox\Enum\TrackingBoxStyle.cs" />
<Compile Include="VideoControl\Recording\VideoControlRecordingFrame.cs" /> <Compile Include="VideoControl\Recording\VideoControlRecordingFrame.cs" />
<Compile Include="VideoControl\Recording\VideoControlRecording.cs" /> <Compile Include="VideoControl\Recording\VideoControlRecording.cs" />
<Compile Include="VideoControl\Stream\BMDStream\BMDStream.cs" /> <Compile Include="VideoControl\Stream\BMDStream\BMDStream.cs" />
...@@ -299,6 +304,7 @@ ...@@ -299,6 +304,7 @@
<Compile Include="Widgets\HotkeyBox\HotkeyBox.cs" /> <Compile Include="Widgets\HotkeyBox\HotkeyBox.cs" />
<Compile Include="Widgets\HotkeyBox\HotkeyHelper.cs" /> <Compile Include="Widgets\HotkeyBox\HotkeyHelper.cs" />
<Compile Include="Widgets\HotkeyBox\HotkeyPropertyAttribute.cs" /> <Compile Include="Widgets\HotkeyBox\HotkeyPropertyAttribute.cs" />
<Compile Include="Widgets\IconButton\IconButton.cs" />
<Compile Include="Widgets\LabelValue\LabelValue2.cs" /> <Compile Include="Widgets\LabelValue\LabelValue2.cs" />
<Compile Include="Widgets\LabelValue\LabelValue.cs" /> <Compile Include="Widgets\LabelValue\LabelValue.cs" />
<Compile Include="Widgets\NavigationControl\NavigationConfig.cs" /> <Compile Include="Widgets\NavigationControl\NavigationConfig.cs" />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Common
{
/// <summary>
/// 跟踪目标框样式
/// </summary>
public enum TrackingBoxStyle
{
/// <summary>
/// 矩形
/// </summary>
Rectangle,
/// <summary>
/// 矩形_角落框
/// </summary>
Rectangle_Corner
}
}
...@@ -5,7 +5,6 @@ using System.Linq; ...@@ -5,7 +5,6 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace VIZ.Framework.Common namespace VIZ.Framework.Common
{ {
/// <summary> /// <summary>
...@@ -19,6 +18,11 @@ namespace VIZ.Framework.Common ...@@ -19,6 +18,11 @@ namespace VIZ.Framework.Common
public string ID { get; set; } public string ID { get; set; }
/// <summary> /// <summary>
/// 样式
/// </summary>
public TrackingBoxStyle Type { get; set; } = TrackingBoxStyle.Rectangle;
/// <summary>
/// 源区域 /// 源区域
/// </summary> /// </summary>
public RawRectangleF SrcRect { get; set; } public RawRectangleF SrcRect { get; set; }
......
using SharpDX.Direct2D1; using OpenCvSharp;
using SharpDX.Direct2D1;
using SharpDX.DirectWrite; using SharpDX.DirectWrite;
using SharpDX.Mathematics.Interop; using SharpDX.Mathematics.Interop;
using System; using System;
...@@ -79,10 +80,10 @@ namespace VIZ.Framework.Common ...@@ -79,10 +80,10 @@ namespace VIZ.Framework.Common
foreach (TrackingBoxInfo info in infos) foreach (TrackingBoxInfo info in infos)
{ {
// 跟踪框绘制区域转化为UI绘制区域 // 跟踪框绘制区域转化为UI绘制区域
SharpDX.Mathematics.Interop.RawRectangleF rect; RawRectangleF rect;
if (context.Mode == VideoRenderMode.UI) if (context.Mode == VideoRenderMode.UI)
{ {
Rect drawRect = ImageHelper.ConvertImageRectToUiRect(context.VideoRenderInfo.Frame.Width, context.VideoRenderInfo.Frame.Height, context.VideoRenderInfo.DrawingRect, info.SrcRect.ToRect()); System.Windows.Rect drawRect = ImageHelper.ConvertImageRectToUiRect(context.VideoRenderInfo.Frame.Width, context.VideoRenderInfo.Frame.Height, context.VideoRenderInfo.DrawingRect, info.SrcRect.ToRect());
rect = drawRect.ToRawRectangleF(); rect = drawRect.ToRawRectangleF();
} }
else else
...@@ -92,7 +93,12 @@ namespace VIZ.Framework.Common ...@@ -92,7 +93,12 @@ namespace VIZ.Framework.Common
// 绘制跟踪框 // 绘制跟踪框
SolidColorBrush brush = new SolidColorBrush(context.Target, info.DrawingBorderColor); SolidColorBrush brush = new SolidColorBrush(context.Target, info.DrawingBorderColor);
context.Target.DrawRectangle(rect, brush, info.DrawingBorderWidth);
switch (info.Type)
{
case TrackingBoxStyle.Rectangle: this.Render_Rectangle(context, info, rect, brush); break;
case TrackingBoxStyle.Rectangle_Corner: this.Render_Rectangle_Corner(context, info, rect, brush); break;
}
// 在调试模式下绘制目标框面积占比 // 在调试模式下绘制目标框面积占比
if (!ApplicationDomain.IS_DEBUG) if (!ApplicationDomain.IS_DEBUG)
...@@ -130,6 +136,50 @@ namespace VIZ.Framework.Common ...@@ -130,6 +136,50 @@ namespace VIZ.Framework.Common
} }
/// <summary> /// <summary>
/// 渲染矩形
/// </summary>
/// <param name="context">渲染上下文</param>
/// <param name="info">跟踪框信息</param>
/// <param name="rect">绘制矩形</param>
/// <param name="brush">画刷</param>
private void Render_Rectangle(VideoRenderContext context, TrackingBoxInfo info, RawRectangleF rect, SolidColorBrush brush)
{
context.Target.DrawRectangle(rect, brush, info.DrawingBorderWidth);
}
/// <summary>
/// 渲染矩形_角落框
/// </summary>
/// <param name="context">渲染上下文</param>
/// <param name="info">跟踪框信息</param>
/// <param name="rect">绘制矩形</param>
/// <param name="brush">画刷</param>
private void Render_Rectangle_Corner(VideoRenderContext context, TrackingBoxInfo info, RawRectangleF rect, SolidColorBrush brush)
{
// 角落框占比 1/5
float width = rect.Right - rect.Left;
float height = rect.Bottom - rect.Top;
float corner_width = width * 0.2f;
float corner_height = height * 0.2f;
// left top
context.Target.DrawLine(new RawVector2(rect.Left, rect.Top), new RawVector2(rect.Left + corner_width, rect.Top), brush);
context.Target.DrawLine(new RawVector2(rect.Left, rect.Top), new RawVector2(rect.Left, rect.Top + corner_height), brush);
// right top
context.Target.DrawLine(new RawVector2(rect.Right, rect.Top), new RawVector2(rect.Right - corner_width, rect.Top), brush);
context.Target.DrawLine(new RawVector2(rect.Right, rect.Top), new RawVector2(rect.Right, rect.Top + corner_height), brush);
// right bottom
context.Target.DrawLine(new RawVector2(rect.Right, rect.Bottom), new RawVector2(rect.Right, rect.Bottom - corner_height), brush);
context.Target.DrawLine(new RawVector2(rect.Right, rect.Bottom), new RawVector2(rect.Right - corner_width, rect.Bottom), brush);
// left bottom
context.Target.DrawLine(new RawVector2(rect.Left, rect.Bottom), new RawVector2(rect.Left, rect.Bottom - corner_height), brush);
context.Target.DrawLine(new RawVector2(rect.Left, rect.Bottom), new RawVector2(rect.Left + corner_width, rect.Bottom), brush);
}
/// <summary>
/// 鼠标左键点击 /// 鼠标左键点击
/// </summary> /// </summary>
private void VideoRender_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) private void VideoRender_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
...@@ -141,8 +191,8 @@ namespace VIZ.Framework.Common ...@@ -141,8 +191,8 @@ namespace VIZ.Framework.Common
if (renderInfo == null) if (renderInfo == null)
return; return;
Point uiPoint = e.GetPosition(this.VideoRender); System.Windows.Point uiPoint = e.GetPosition(this.VideoRender);
Point bmpPoint = ImageHelper.ConvertUiPointToImagePoint(renderInfo.Frame.Width, renderInfo.Frame.Height, renderInfo.DrawingRect, uiPoint); System.Windows.Point bmpPoint = ImageHelper.ConvertUiPointToImagePoint(renderInfo.Frame.Width, renderInfo.Frame.Height, renderInfo.DrawingRect, uiPoint);
TrackingBoxClickEventArgs args = new TrackingBoxClickEventArgs(); TrackingBoxClickEventArgs args = new TrackingBoxClickEventArgs();
args.MousePoint = uiPoint; args.MousePoint = uiPoint;
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace VIZ.Framework.Common
{
/// <summary>
/// 图标按钮
/// </summary>
public class IconButton : Button
{
static IconButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(IconButton), new FrameworkPropertyMetadata(typeof(IconButton)));
}
#region Icon -- 图标
/// <summary>
/// 图标
/// </summary>
public ImageSource Icon
{
get { return (ImageSource)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for Icon. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register("Icon", typeof(ImageSource), typeof(IconButton), new PropertyMetadata(null));
#endregion
#region IconWidth -- 图标宽度
/// <summary>
/// 图标宽度
/// </summary>
public double IconWidth
{
get { return (double)GetValue(IconWidthProperty); }
set { SetValue(IconWidthProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for IconWidth. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty IconWidthProperty =
DependencyProperty.Register("IconWidth", typeof(double), typeof(IconButton), new PropertyMetadata(20d));
#endregion
#region IconHeight -- 图标高度
/// <summary>
/// 图标高度
/// </summary>
public double IconHeight
{
get { return (double)GetValue(IconHeightProperty); }
set { SetValue(IconHeightProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for IconHeight. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty IconHeightProperty =
DependencyProperty.Register("IconHeight", typeof(double), typeof(IconButton), new PropertyMetadata(20d));
#endregion
}
}
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VIZ.Framework.Common">
<Style TargetType="local:IconButton">
<Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:IconButton">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Width="{TemplateBinding IconWidth}" Height="{TemplateBinding IconHeight}"
Source="{TemplateBinding Icon}"></Image>
<ContentPresenter Grid.Column="1"></ContentPresenter>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace VIZ.Framework.Core
{
/// <summary>
/// 枚举2枚举描述转化器
/// </summary>
public class Enum2EnumDescriptionConverter : IValueConverter
{
#region EnumType -- 枚举类型
private Type enumType;
/// <summary>
/// 枚举类型
/// </summary>
public Type EnumType
{
get { return enumType; }
set { enumType = value; this.models = EnumHelper.GetEnumModels(value); }
}
#endregion
/// <summary>
/// 枚举模型集合
/// </summary>
private List<EnumModel> models;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || this.models == null)
return null;
EnumModel model = this.models.FirstOrDefault(p => p.Key.Equals(value));
return model?.Description;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || this.models == null)
return default;
EnumModel model = this.models.FirstOrDefault(p => string.Equals(p.Description, value.ToString()));
return model?.Key;
}
}
}
...@@ -44,6 +44,16 @@ namespace VIZ.Framework.Core ...@@ -44,6 +44,16 @@ namespace VIZ.Framework.Core
public static List<EnumModel> GetEnumModels<TEnum>() public static List<EnumModel> GetEnumModels<TEnum>()
{ {
Type type = typeof(TEnum); Type type = typeof(TEnum);
return GetEnumModels(type);
}
/// <summary>
/// 获取枚举的枚举模型
/// </summary>
/// <typeparam name="TEnum">枚举类型</typeparam>
/// <returns>枚举模型列表</returns>
public static List<EnumModel> GetEnumModels(Type type)
{
if (!type.IsEnum) if (!type.IsEnum)
throw new Exception($"type: {type.Name} is not enum."); throw new Exception($"type: {type.Name} is not enum.");
......
using SharpDX.Mathematics.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// 值辅助类
/// </summary>
public static class ValueHelper
{
/// <summary>
/// 转化类型
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static TValue ConvertValue<TValue>(string value)
{
if (string.IsNullOrEmpty(value))
return default;
Type type = typeof(TValue);
// String
if (type == typeof(string))
return (TValue)(object)value;
// Int32
if (type == typeof(Int32))
return (TValue)(object)Convert.ToInt32(value);
// Int64
if (type == typeof(Int64))
return (TValue)(object)Convert.ToInt64(value);
// Float
if (type == typeof(float))
return (TValue)(object)(float)Convert.ToDouble(value);
// Double
if (type == typeof(double))
return (TValue)(object)Convert.ToDouble(value);
// Bool
if (type == typeof(bool))
return (TValue)(object)Convert.ToBoolean(value);
// RawColor4
if (type == typeof(RawColor4))
return (TValue)(object)SharpDxColorHelper.FromString(value);
// DateTime
if (type == typeof(DateTime))
return (TValue)(object)DateTime.Parse(value);
// TimeSpan
if (type == typeof(TimeSpan))
return (TValue)(object)TimeSpan.Parse(value);
return default;
}
}
}
using SharpDX.Mathematics.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace VIZ.Framework.Core
{
/// <summary>
/// XML 辅助类
/// </summary>
public static class XmlHelper
{
/// <summary>
/// 获取属性值
/// </summary>
/// <param name="element">XML节点</param>
/// <param name="attrubteName">属性名</param>
/// <returns>属性值</returns>
public static string GetAttributeValue(this XElement element, XName attrubteName)
{
return GetAttributeValue(element, attrubteName, string.Empty);
}
/// <summary>
/// 获取属性值
/// </summary>
/// <param name="element">XML节点</param>
/// <param name="attrubteName">属性名</param>
/// <param name="defaultValue">默认值</param>
/// <returns>属性值</returns>
public static string GetAttributeValue(this XElement element, XName attrubteName, string defaultValue)
{
XAttribute attribute = element.Attribute(attrubteName);
if (attribute == null)
return defaultValue;
return attribute.Value;
}
/// <summary>
/// 获取属性值
/// </summary>
/// <typeparam name="T">值类型</typeparam>
/// <param name="element">XML节点</param>
/// <param name="attrubteName">属性名</param>
/// <returns>属性值</returns>
public static T GetAttributeValue<T>(this XElement element, XName attrubteName)
{
string value = GetAttributeValue(element, attrubteName, string.Empty);
if (string.IsNullOrWhiteSpace(value))
return default;
return ValueHelper.ConvertValue<T>(value);
}
/// <summary>
/// 获取属性值
/// </summary>
/// <typeparam name="T">值类型</typeparam>
/// <param name="element">XML节点</param>
/// <param name="attrubteName">属性名</param>
/// <param name="defaultValue">默认值</param>
/// <returns>属性值</returns>
public static T GetAttributeValue<T>(this XElement element, XName attrubteName, T defaultValue)
{
string value = GetAttributeValue(element, attrubteName, string.Empty);
if (string.IsNullOrWhiteSpace(value))
return defaultValue;
return ValueHelper.ConvertValue<T>(value);
}
}
}
...@@ -92,6 +92,9 @@ namespace VIZ.Framework.Core ...@@ -92,6 +92,9 @@ namespace VIZ.Framework.Core
{ {
try try
{ {
if (wparam == IntPtr.Zero || lparam == IntPtr.Zero)
return new IntPtr(1);
IntPtr data_ptr = Navigation3DHelper.on_message_3D_Mouse(wparam, lparam); IntPtr data_ptr = Navigation3DHelper.on_message_3D_Mouse(wparam, lparam);
Navigation3DData data = Marshal.PtrToStructure<Navigation3DData>(data_ptr); Navigation3DData data = Marshal.PtrToStructure<Navigation3DData>(data_ptr);
Navigation3DHelper.dispose_3D_Mouse_data(data_ptr); Navigation3DHelper.dispose_3D_Mouse_data(data_ptr);
......
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
<Compile Include="Core\Converter\ByteSizeConverter.cs" /> <Compile Include="Core\Converter\ByteSizeConverter.cs" />
<Compile Include="Core\Converter\Bool2SolidColorBrushConverter.cs" /> <Compile Include="Core\Converter\Bool2SolidColorBrushConverter.cs" />
<Compile Include="Core\Converter\Color2SolidColorBrushConverter.cs" /> <Compile Include="Core\Converter\Color2SolidColorBrushConverter.cs" />
<Compile Include="Core\Converter\Enum2EnumDescriptionConverter.cs" />
<Compile Include="Core\Converter\StringAppendConverter.cs" /> <Compile Include="Core\Converter\StringAppendConverter.cs" />
<Compile Include="Core\Enum\EnumHelper.cs" /> <Compile Include="Core\Enum\EnumHelper.cs" />
<Compile Include="Core\Enum\EnumModel.cs" /> <Compile Include="Core\Enum\EnumModel.cs" />
...@@ -103,6 +104,8 @@ ...@@ -103,6 +104,8 @@
<Compile Include="Core\Helper\KeepSymbolHelper.cs" /> <Compile Include="Core\Helper\KeepSymbolHelper.cs" />
<Compile Include="Core\Helper\ProcessHelper.cs" /> <Compile Include="Core\Helper\ProcessHelper.cs" />
<Compile Include="Core\Helper\FPSHelper.cs" /> <Compile Include="Core\Helper\FPSHelper.cs" />
<Compile Include="Core\Helper\ValueHelper.cs" />
<Compile Include="Core\Helper\XmlHelper.cs" />
<Compile Include="Core\Net\NetHelperMacInfo.cs" /> <Compile Include="Core\Net\NetHelperMacInfo.cs" />
<Compile Include="Core\Object\IObjectPoolManager.cs" /> <Compile Include="Core\Object\IObjectPoolManager.cs" />
<Compile Include="Core\Object\ObjectPoolManager.cs" /> <Compile Include="Core\Object\ObjectPoolManager.cs" />
......
...@@ -111,7 +111,7 @@ namespace VIZ.Framework.Storage ...@@ -111,7 +111,7 @@ namespace VIZ.Framework.Storage
// section=配置节,key=键名,temp=上面,path=路径 // section=配置节,key=键名,temp=上面,path=路径
GetPrivateProfileString(attribute.Section, propertyName, attribute.DefaultValue, temp, MAX_READ_SIZE, sPath); GetPrivateProfileString(attribute.Section, propertyName, attribute.DefaultValue, temp, MAX_READ_SIZE, sPath);
TValue result = this.ConvertValue<TValue>(temp?.ToString()); TValue result = ValueHelper.ConvertValue<TValue>(temp?.ToString());
return result; return result;
} }
...@@ -139,49 +139,5 @@ namespace VIZ.Framework.Storage ...@@ -139,49 +139,5 @@ namespace VIZ.Framework.Storage
// section=配置节,key=键名,value=键值,path=路径 // section=配置节,key=键名,value=键值,path=路径
WritePrivateProfileString(attribute.Section, propertyName, (value == null ? string.Empty : value.ToString()), sPath); WritePrivateProfileString(attribute.Section, propertyName, (value == null ? string.Empty : value.ToString()), sPath);
} }
/// <summary>
/// 转化类型
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
private TValue ConvertValue<TValue>(string value)
{
if (string.IsNullOrEmpty(value))
return default;
Type type = typeof(TValue);
// String
if (type == typeof(string))
return (TValue)(object)value;
// Int32
if (type == typeof(Int32))
return (TValue)(object)Convert.ToInt32(value);
// Int64
if (type == typeof(Int64))
return (TValue)(object)Convert.ToInt64(value);
// Float
if (type == typeof(float))
return (TValue)(object)(float)Convert.ToDouble(value);
// Double
if (type == typeof(double))
return (TValue)(object)Convert.ToDouble(value);
// Bool
if (type == typeof(bool))
return (TValue)(object)Convert.ToBoolean(value);
// RawColor4
if (type == typeof(RawColor4))
return (TValue)(object)SharpDxColorHelper.FromString(value);
return default;
}
} }
} }
...@@ -79,6 +79,9 @@ ...@@ -79,6 +79,9 @@
<Compile Include="Ini\IniConfigBase.cs" /> <Compile Include="Ini\IniConfigBase.cs" />
<Compile Include="Ini\IniStorage.cs" /> <Compile Include="Ini\IniStorage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XML\IXmlNode.cs" />
<Compile Include="XML\XmlNodeAttribute.cs" />
<Compile Include="XML\XmlAttributeAttribute.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\VIZ.Framework.Core\VIZ.Framework.Core.csproj"> <ProjectReference Include="..\VIZ.Framework.Core\VIZ.Framework.Core.csproj">
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace VIZ.Framework.Storage
{
/// <summary>
/// XML 节点
/// </summary>
public interface IXmlNode
{
/// <summary>
/// 将当前节点转化为XElement节点
/// </summary>
/// <returns>XElement节点</returns>
XElement ToXElement();
/// <summary>
/// 从XElement节点中加载数据
/// </summary>
/// <param name="element">XElement节点</param>
void FromXElement(XElement element);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Storage
{
/// <summary>
/// XML属性
/// </summary>
public class XmlAttributeAttribute : Attribute
{
/// <summary>
/// XML属性
/// </summary>
/// <param name="name">名称</param>
public XmlAttributeAttribute(string name)
{
this.Name = name;
}
/// <summary>
/// 属性名
/// </summary>
public string Name { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Storage
{
/// <summary>
/// XML 节点
/// </summary>
public class XmlNodeAttribute : Attribute
{
/// <summary>
/// XML 节点
/// </summary>
/// <param name="name">名称</param>
public XmlNodeAttribute(string name)
{
this.Name = name;
}
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment