RaUI/Source/ryControls/Gdu.WinFormUI/GMControls/RollingBar/GMRollingBar.cs

309 lines
7.2 KiB
C#
Raw Normal View History

/*
*
* 使
* 使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
}
}