RaUI/Source/ryControls/Gdu.WinFormUI/GMControls/RollingBar/GMRollingBar.cs
如果当时 34a3ef3ed9 ### 2021-02-22更新
------
#### ryControls    V2.1.2102.2201
*.[新增]新加入Gdu.WinformUI控件。
2021-02-22 21:42:59 +08:00

309 lines
7.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 本代码受中华人民共和国著作权法保护,作者仅授权下载代码之人在学习和交流范围内
* 自由使用与修改代码;欲将代码用于商业用途的,请与作者联系。
* 使用本代码请保留此处信息。作者联系方式ping3108@163.com, 欢迎进行技术交流
*/
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Windows.Forms;
using MGdu.WinFormUI.MyGraphics;
//忽略没有注释警告
#pragma warning disable 1591
namespace MGdu.WinFormUI
{
[ToolboxItem(true)]
public class GMRollingBar : GMBarControlBase, IGMControl
{
#region
public GMRollingBar()
{
rollingTimer = new Timer();
rollingTimer.Tick += new EventHandler(rollingTimer_Tick);
rollingTimer.Interval = _refleshFrequency;
rollingTimer.Enabled = false;
}
#endregion
#region private var
float currentAngle = 0f;
Timer rollingTimer;
#endregion
#region IGMControl实现
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public GMControlType ControlType
{
get { return GMControlType.RollingBar; }
}
#endregion
#region
GMRollingBarThemeBase _xtheme;
RollingBarStyle _style;
int _refleshFrequency = 150;
[DefaultValue(150)]
public int RefleshFrequency
{
get
{
return _refleshFrequency;
}
set
{
if (_refleshFrequency != value)
{
if (value < 1)
value = 150;
_refleshFrequency = value;
rollingTimer.Interval = _refleshFrequency;
}
}
}
[DefaultValue(typeof(RollingBarStyle),"0")]
public RollingBarStyle Style
{
get
{
return _style;
}
set
{
if (_style != value)
{
_style = value;
Invalidate();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public GMRollingBarThemeBase XTheme
{
get
{
return _xtheme;
}
set
{
_xtheme = value;
Invalidate();
}
}
#endregion
#region
public void StartRolling()
{
if (rollingTimer.Enabled)
return;
rollingTimer.Enabled = true;
}
public void StopRolling()
{
rollingTimer.Enabled = false;
}
#endregion
#region XTheme配置的属性
protected virtual int Radius1
{
get
{
if (_xtheme == null)
return 10;
else
return _xtheme.Radius1;
}
}
protected virtual int Radius2
{
get
{
if (_xtheme == null)
return 24;
else
return _xtheme.Radius2;
}
}
protected virtual int SpokeNum
{
get
{
if (_xtheme == null)
return 12;
else
return _xtheme.SpokeNum;
}
}
protected virtual float PenWidth
{
get
{
if (_xtheme == null)
return 2;
else
return _xtheme.PenWidth;
}
}
protected virtual Color BaseColor
{
get
{
if (_xtheme == null)
return Color.Red;
else
return _xtheme.BaseColor;
}
}
protected virtual Color GMBackColor
{
get
{
if (_xtheme == null)
return Color.Transparent;
else
return _xtheme.BackColor;
}
}
#endregion
#region
private void rollingTimer_Tick(object sender, EventArgs e)
{
base.Invalidate();
}
#endregion
#region
protected virtual void PaintThisRollingBar(Graphics g)
{
switch (Style)
{
case RollingBarStyle.Default:
PaintDefault(g);
break;
case RollingBarStyle.ChromeOneQuarter:
PaintChromeOneQuarter(g);
break;
case RollingBarStyle.DiamondRing:
PaintDiamondRing(g);
break;
case RollingBarStyle.BigGuyLeadsLittleGuys:
PaintTheseGuys(g);
break;
}
}
private void IncreaseCurrentAngle(int spokeNum)
{
if (rollingTimer.Enabled)
{
currentAngle += 360f / spokeNum;
if (currentAngle > 360f)
currentAngle -= 360f;
}
}
private void PaintDefault(Graphics g)
{
IncreaseCurrentAngle(SpokeNum);
RollingBarPainter.RenderDefault(
g,
ClientRectangle,
GMBackColor,
currentAngle,
Radius1,
Radius2,
SpokeNum,
PenWidth,
ColorHelper.GetLighterArrayColors(BaseColor, SpokeNum));
}
private void PaintChromeOneQuarter(Graphics g)
{
IncreaseCurrentAngle(10);
RollingBarPainter.RenderChromeOneQuarter(
g,
ClientRectangle,
GMBackColor,
currentAngle,
Radius1,
BaseColor);
}
private void PaintDiamondRing(Graphics g)
{
IncreaseCurrentAngle(12);
RollingBarPainter.RenderDiamondRing(
g,
ClientRectangle,
GMBackColor,
currentAngle,
Radius1,
BaseColor,
_xtheme == null ? Color.White : _xtheme.DiamondColor);
}
private void PaintTheseGuys(Graphics g)
{
IncreaseCurrentAngle(10);
RollingBarPainter.RenderTheseGuys(
g,
ClientRectangle,
GMBackColor,
currentAngle,
Radius1,
BaseColor);
}
#endregion
#region
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
PaintThisRollingBar(e.Graphics);
}
#endregion
}
}