Files
mirror-processhacker/1.x/trunk/ProcessHacker/Components/Indicator.cs
T
dmex e43aec1c5e PH1.x: Code Cleanup/Fixes
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4778 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2011-10-29 08:32:37 +00:00

199 lines
6.3 KiB
C#

/*
* Process Hacker -
* indicator component
*
* Copyright (C) 2009 Dean
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace ProcessHacker.Components
{
public partial class Indicator : UserControl
{
private Color _lineColor1 = Color.FromArgb(255, 0, 0);
public Color Color1
{
get { return _lineColor1; }
set { _lineColor1 = value; }
}
private Color _lineColor2 = Color.FromArgb(0, 255, 0);
public Color Color2
{
get { return _lineColor2; }
set { _lineColor2 = value; }
}
public long Data1 { get; set; }
public long Data2 { get; set; }
public Indicator()
{
InitializeComponent();
this.SetStyle(
ControlStyles.ResizeRedraw |
ControlStyles.UserPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
//SolidBrush brush = new SolidBrush(this.ForeColor);
SolidBrush brush1 = new SolidBrush(this.Color1);
SolidBrush brush2 = new SolidBrush(this.Color2);
int width = this.ClientSize.Width;
int height = this.ClientSize.Height;
int num1 = height;
num1 -= this.Font.Height + 4;
RectangleF layoutRectangle = new RectangleF(0f, num1, width, height);
StringFormat format = new StringFormat(StringFormatFlags.NoWrap)
{
Alignment = StringAlignment.Center
};
e.Graphics.DrawString(this.Text, this.Font, brush1, layoutRectangle, format);
int num2 = (((height - 6) - 4) - this.Font.Height) - 4;
num2++;
int num3 = num2 / 3;
byte red = (byte)(this.ForeColor.R / 2);
byte green = (byte)(this.ForeColor.G / 2);
byte blue = (byte)(this.ForeColor.B / 2);
Pen pen = new Pen(Color.FromArgb(red, green, blue))
{
DashStyle = DashStyle.Dot
};
int num4 = (width - this.GraphWidth) / 2;
int num5 = ((height - 4) - this.Font.Height) - 7;
int num6 = this.GraphWidth / 2;
int num9 = (int)Math.Ceiling(((this.Data1 - this.Minimum) * 1.0) / ((this.Maximum - (this.Minimum * 1.0)) / num3));
int num10 = (int)Math.Ceiling(((this.Data1 + this.Data2 - this.Minimum) * 1.0) / ((this.Maximum - (this.Minimum * 1.0)) / num3));
for (int i = 0; i < num3; i++)
{
int x = num4;
int y = (num5 - (i * 3)) - 1;
int num7 = x + num6;
int num8 = y;
if (i < num9)
{
e.Graphics.FillRectangle(brush1, x, y, num6, 2);
e.Graphics.FillRectangle(brush1, num7 + 1, y, num6, 2);
}
else if (i < num10)
{
e.Graphics.FillRectangle(brush2, x, y, num6, 2);
e.Graphics.FillRectangle(brush2, num7 + 1, y, num6, 2);
}
else
{
e.Graphics.DrawLine(pen, x, y, num7, num8);
e.Graphics.DrawLine(pen, x + 1, y + 1, num7, num8 + 1);
x = num7 + 1;
num7 = x + num6;
e.Graphics.DrawLine(pen, x, y, num7, num8);
e.Graphics.DrawLine(pen, x + 1, y + 1, num7, num8 + 1);
}
}
pen.Dispose();
//brush.Dispose();
brush1.Dispose();
brush2.Dispose();
}
protected override CreateParams CreateParams
{
get
{
CreateParams createParams = base.CreateParams;
createParams.ExStyle |= 0x200;
return createParams;
}
}
private int _GraphWidth = 0x21;
private long _Maximum = long.MaxValue;
private long _Minimum;
public int GraphWidth
{
get
{
return this._GraphWidth;
}
set
{
this._GraphWidth = value;
this.Invalidate();
}
}
public long Maximum
{
get
{
return this._Maximum;
}
set
{
if (value < this.Minimum)
{
//throw new ArgumentException();
return;
}
this._Maximum = value;
this.Invalidate();
}
}
public long Minimum
{
get
{
return this._Minimum;
}
set
{
if (value < 0)
{
throw new ArgumentException();
}
this._Minimum = value;
this.Invalidate();
}
}
public string TextValue
{
get
{
return base.Text;
}
set
{
base.Text = value;
this.Invalidate();
}
}
}
}