init: 导入项目到 meswork Gitea
This commit is contained in:
216
DataMirrorTools_Simulator/GanttChartExample/Chart/PlaySlider.cs
Normal file
216
DataMirrorTools_Simulator/GanttChartExample/Chart/PlaySlider.cs
Normal file
@@ -0,0 +1,216 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Braincase.GanttChart
|
||||
{
|
||||
/// <summary>
|
||||
/// 绘制播放滑动条
|
||||
/// </summary>
|
||||
public partial class Chart
|
||||
{
|
||||
public enum ControlState//按钮状态
|
||||
{
|
||||
Normal,
|
||||
Hover,
|
||||
Pressed,
|
||||
Focused,
|
||||
}
|
||||
|
||||
private ControlState _controlState = ControlState.Normal;
|
||||
|
||||
private ControlState MouseState
|
||||
{
|
||||
get { return _controlState; }
|
||||
set
|
||||
{
|
||||
if (_controlState != value)
|
||||
{
|
||||
_controlState = value;
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool isMouseDown = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 确定拖拽范围
|
||||
/// </summary>
|
||||
RectangleF PlayMaskRectDragDrop;
|
||||
|
||||
private int _minValue = 0;
|
||||
private int _maxValue = 100;
|
||||
private int _currValue = 0;
|
||||
|
||||
private int offset = 0;//轨道距离两头的余量.
|
||||
private Size _sliderSize = new Size(1, 20);//滑块大小
|
||||
|
||||
public int Value
|
||||
{
|
||||
get { return this._currValue; }
|
||||
set
|
||||
{
|
||||
this._currValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a Task is being dragged by the mouse
|
||||
/// </summary>
|
||||
public event EventHandler<MouseEventArgs> PlaySliderMouseDrag = null;
|
||||
|
||||
|
||||
private void OnMouseMove_PlaySlider(MouseEventArgs e)
|
||||
{
|
||||
if (!this.isMouseDown)
|
||||
{
|
||||
this.MouseState = this.IsInSliderArea(e.Location) ? ControlState.Hover : this.MouseState = ControlState.Normal;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
this.MouseState = ControlState.Pressed;
|
||||
this.ChangeValue(e.Location);
|
||||
PlaySliderMouseDrag(this, e);
|
||||
//OnPlaySliderMouseDrop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMouseDown_PlaySlider(MouseEventArgs e)
|
||||
{
|
||||
base.Focus();
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
if (this.IsInSliderArea(e.Location))//滑块内.
|
||||
{
|
||||
this.isMouseDown = true;
|
||||
this.MouseState = ControlState.Pressed;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnMouseUp_PlaySlider(MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left )
|
||||
{
|
||||
this.isMouseDown = false;
|
||||
this.MouseState = this.IsInSliderArea(e.Location) ? ControlState.Hover : ControlState.Normal;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
if (!this.isMouseDown)
|
||||
{
|
||||
this.MouseState = ControlState.Normal;
|
||||
}
|
||||
base.OnMouseLeave(e);
|
||||
}
|
||||
|
||||
|
||||
protected override void OnMouseCaptureChanged(EventArgs e)
|
||||
{
|
||||
if (!base.Capture)//未捕获鼠标
|
||||
{
|
||||
isMouseDown = false;
|
||||
}
|
||||
base.OnMouseCaptureChanged(e);
|
||||
}
|
||||
//单击或滑动改变值
|
||||
private void ChangeValue(Point mouse )
|
||||
{
|
||||
//_mProject.NowIndex
|
||||
// int NowIndex;
|
||||
var point = _mViewport.DeviceToWorldCoord(mouse);
|
||||
_maxValue = (int)_mProject.MaxPlayLenth;;
|
||||
|
||||
//if (point.X <= this.ClientRectangle.X + offset + this._sliderSize.Width / 2f)
|
||||
if (point.X <= _minValue + offset + this._sliderSize.Width / 2f)
|
||||
{
|
||||
this.Value = this._minValue;
|
||||
return;
|
||||
}
|
||||
//if (point.X >= this.ClientRectangle.Right - offset - this._sliderSize.Width / 2f)
|
||||
if (point.X >= _maxValue - offset - this._sliderSize.Width / 2f)
|
||||
{
|
||||
this.Value = this._maxValue;
|
||||
return;
|
||||
}
|
||||
float len = point.X - this._sliderSize.Width / 2f - offset;
|
||||
var percent = len / (_maxValue - this._sliderSize.Width - 2 * offset);
|
||||
//var percent = len / (this.ClientRectangle.Width - this._sliderSize.Width - 2 * offset);
|
||||
var v = this._minValue + (int)((this._maxValue - this._minValue) * percent);
|
||||
if (v > this._maxValue) { v = this._maxValue; }
|
||||
if (v < this._minValue) { v = this._minValue; }
|
||||
this.Value = v;
|
||||
_mProject.NowIndexXf = v;
|
||||
_mProject.NowIndex = (int)(_mProject.AllCountFrame* percent);
|
||||
}
|
||||
|
||||
protected virtual void OnPlaySliderMouseDrop(TaskDragDropEventArgs e)
|
||||
{
|
||||
|
||||
|
||||
this.Invalidate();
|
||||
}
|
||||
//鼠标落点是否在滑块内
|
||||
private bool IsInSliderArea(Point point)
|
||||
{
|
||||
var chartcoord = _mViewport.DeviceToWorldCoord(point);
|
||||
return PlayMaskRectDragDrop.Contains(chartcoord);
|
||||
}
|
||||
/// <summary>
|
||||
/// 绘制播放线
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
private void OnPaint_PlaySlider(Graphics graphics)
|
||||
{
|
||||
//正常播放
|
||||
DrawPlayLine(graphics);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 绘制播放线
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
private void DrawPlayLine(Graphics graphics)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (float.NaN == _mProject.NowIndexXf) return;
|
||||
float xf1 = _mProject.NowIndexXf;
|
||||
Pen pen = new Pen(Color.Red);
|
||||
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
|
||||
pen.Width = 1;
|
||||
graphics.DrawLine(pen, new PointF(xf1, _mViewport.Y), new PointF(xf1, _mViewport.Rectangle.Bottom));
|
||||
|
||||
Color color = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(54)))), ((int)(((byte)(82)))));
|
||||
Brush brushes = new SolidBrush(color);
|
||||
PointF[] point = new PointF[3];
|
||||
float h0 = 6f;
|
||||
|
||||
PlayMaskRectDragDrop = new Rectangle((int)(xf1 - h0), (int)_mViewport.Y, (int)(2 * h0), (int)(_mViewport.Y + 2 * h0));
|
||||
point[0] = new PointF(xf1 - h0, _mViewport.Y);
|
||||
point[1] = new PointF(xf1 + h0, _mViewport.Y);
|
||||
point[2] = new PointF(xf1, _mViewport.Y + 2.0f * h0);
|
||||
graphics.FillPolygon(brushes, point);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//graphics.DrawRectangle(new Pen(Color.Red), PlayMaskRectDragDrop);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user