DotNet 4.8.1 build of DotNetBar
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace DevComponents.DotNetBar.Charts
|
||||
{
|
||||
internal static class MathHelper
|
||||
{
|
||||
#region ToDegrees
|
||||
|
||||
public static double ToDegrees(double radians)
|
||||
{
|
||||
return (radians * 180 / Math.PI);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ToRadians
|
||||
|
||||
public static double ToRadians(double degrees)
|
||||
{
|
||||
return (degrees * Math.PI / 180);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetPointAngle
|
||||
|
||||
public static int GetPointAngle(Point pt)
|
||||
{
|
||||
double theta = Math.Atan2(pt.X, -pt.Y);
|
||||
int angle = (int)(MathHelper.ToDegrees(theta) + 270) % 360;
|
||||
|
||||
return (angle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetPointRadius
|
||||
|
||||
public static int GetPointRadius(ref Point pt, Point cpt)
|
||||
{
|
||||
pt.X -= cpt.X;
|
||||
pt.Y -= cpt.Y;
|
||||
|
||||
return ((int)Math.Sqrt(pt.X * pt.X + pt.Y * pt.Y));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetOffsetPoint
|
||||
|
||||
public static Point GetOffsetPoint(
|
||||
Point pt, Point cpt, out int radius, out int angle)
|
||||
{
|
||||
radius = MathHelper.GetPointRadius(ref pt, cpt);
|
||||
angle = MathHelper.GetPointAngle(pt);
|
||||
|
||||
return (pt);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Clamp
|
||||
|
||||
public static T Clamp<T>(T value, T min, T max)
|
||||
where T : IComparable<T>
|
||||
{
|
||||
T result = value;
|
||||
|
||||
if (result.CompareTo(max) > 0)
|
||||
result = max;
|
||||
|
||||
if (result.CompareTo(min) < 0)
|
||||
result = min;
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ToScalar
|
||||
|
||||
public static double ToScalar(double x)
|
||||
{
|
||||
return (MathHelper.Sqrt((float)(x / Math.PI)) * 2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sqrt
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
private struct FloatIntUnion
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public float f;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public int tmp;
|
||||
}
|
||||
|
||||
public static float Sqrt(float x)
|
||||
{
|
||||
if (x != 0)
|
||||
{
|
||||
FloatIntUnion u;
|
||||
|
||||
u.tmp = 0;
|
||||
u.f = x;
|
||||
|
||||
u.tmp -= 1 << 23; // Subtract 2^m
|
||||
u.tmp >>= 1; // Divide by 2
|
||||
u.tmp += 1 << 29; // Add ((b + 1) / 2) * 2^m
|
||||
|
||||
return (u.f);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DevComponents.DotNetBar.Charts
|
||||
{
|
||||
public class PieSeriesConverter : ExpandableObjectConverter
|
||||
{
|
||||
public override PropertyDescriptorCollection
|
||||
GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
|
||||
{
|
||||
PropertyDescriptorCollection pdc = base.GetProperties(context, value, attributes);
|
||||
|
||||
PropertyDescriptor[] newProps = new PropertyDescriptor[pdc.Count - 1];
|
||||
|
||||
int n = 0;
|
||||
|
||||
for (int i = 0; i < pdc.Count; i++)
|
||||
{
|
||||
if (pdc[i].Name.Equals("SeriesType") == false)
|
||||
newProps[n++] = pdc[i];
|
||||
}
|
||||
|
||||
return new PropertyDescriptorCollection(newProps);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DevComponents.DotNetBar.Charts
|
||||
{
|
||||
public class PointFConverter : ExpandableObjectConverter
|
||||
{
|
||||
#region CanConvertTo
|
||||
|
||||
public override bool CanConvertTo(
|
||||
ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
return (true);
|
||||
|
||||
return (base.CanConvertTo(context, destinationType));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ConvertTo
|
||||
|
||||
public override object ConvertTo(
|
||||
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
{
|
||||
PointF pf = (PointF)value;
|
||||
|
||||
return (String.Format("{0:f}, {1:f}", pf.X, pf.Y));
|
||||
}
|
||||
|
||||
return (base.ConvertTo(context, culture, value, destinationType));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CanConvertFrom
|
||||
|
||||
public override bool CanConvertFrom(
|
||||
ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof(string))
|
||||
return (true);
|
||||
|
||||
return (base.CanConvertFrom(context, sourceType));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ConvertFrom
|
||||
|
||||
public override object ConvertFrom(
|
||||
ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value is string)
|
||||
{
|
||||
string[] values = ((string)value).Split(',');
|
||||
|
||||
if (values.Length != 2)
|
||||
throw new ArgumentException("Invalid value to convert.");
|
||||
|
||||
try
|
||||
{
|
||||
float x = float.Parse(values[0]);
|
||||
float y = float.Parse(values[1]);
|
||||
|
||||
PointF pf = new PointF(x, y);
|
||||
|
||||
return (pf);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new ArgumentException("Invalid value to convert.");
|
||||
}
|
||||
}
|
||||
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetCreateInstanceSupported
|
||||
|
||||
public override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
|
||||
{
|
||||
return (true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateInstance
|
||||
|
||||
public override object CreateInstance(
|
||||
ITypeDescriptorContext context, IDictionary propertyValues)
|
||||
{
|
||||
if (propertyValues != null)
|
||||
return (new PointF((float)propertyValues["X"], (float)propertyValues["Y"]));
|
||||
|
||||
return (null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace DevComponents.DotNetBar.Charts
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides helpers when working with text.
|
||||
/// </summary>
|
||||
internal static class TextHelper
|
||||
{
|
||||
private static int _textMarkupCultureSpecific = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Get or sets the text-markup padding for text
|
||||
/// measurement when running on Japanese version of Windows.
|
||||
/// </summary>
|
||||
public static int TextMarkupCultureSpecificPadding
|
||||
{
|
||||
get { return _textMarkupCultureSpecific; }
|
||||
set { _textMarkupCultureSpecific = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MeasureText always adds about 1/2 em width of white space on the right,
|
||||
/// even when NoPadding is specified. It returns zero for an empty string.
|
||||
/// To get the precise string width, measure the width of a string containing a
|
||||
/// single period and subtract that from the width of our original string plus a period.
|
||||
/// </summary>
|
||||
public static Size MeasureText(Graphics g,
|
||||
string s, Font font, Size csize, eTextFormat tf)
|
||||
{
|
||||
return (TextDrawing.MeasureString(g, s, font, csize, tf));
|
||||
|
||||
if (font.Italic == true)
|
||||
return (TextDrawing.MeasureString(g, s, font, csize, tf));
|
||||
|
||||
Size sz1 = TextDrawing.MeasureString(g, ".", font, csize, tf);
|
||||
Size sz2 = TextDrawing.MeasureString(g, s + ".", font, csize, tf);
|
||||
|
||||
return (new Size(sz2.Width - sz1.Width, sz2.Height));
|
||||
}
|
||||
|
||||
public static Size MeasureText(Graphics g, string s, Font font)
|
||||
{
|
||||
return (TextDrawing.MeasureString(g, s, font));
|
||||
|
||||
if (font.Italic == true)
|
||||
return (TextDrawing.MeasureString(g, s, font));
|
||||
|
||||
Size sz1 = TextDrawing.MeasureString(g, ".", font);
|
||||
Size sz2 = TextDrawing.MeasureString(g, s + ".", font);
|
||||
|
||||
return (new Size(sz2.Width - sz1.Width, sz2.Height));
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user