DotNet 4.8.1 build of DotNetBar
This commit is contained in:
427
PROMS/DotNetBar Source Code/ColorPickers/ColorCombControl.cs
Normal file
427
PROMS/DotNetBar Source Code/ColorPickers/ColorCombControl.cs
Normal file
@@ -0,0 +1,427 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DevComponents.DotNetBar.ColorPickers
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the color comb control that allows color choice from pre-defined color comb palette.
|
||||
/// </summary>
|
||||
[ToolboxItem(true), DefaultEvent("SelectedColorChanged"), DefaultProperty("SelectedColor"), ToolboxBitmap(typeof(ColorCombControl), "ColorPickerItem.ColorCombControl.ico")]
|
||||
public class ColorCombControl : System.Windows.Forms.Control
|
||||
{
|
||||
#region Events
|
||||
/// <summary>
|
||||
/// Occurs when SelectedColor has changed.
|
||||
/// </summary>
|
||||
public event EventHandler SelectedColorChanged;
|
||||
/// <summary>
|
||||
/// Raises SelectedColorChanged event.
|
||||
/// </summary>
|
||||
/// <param name="e">Provides event arguments.</param>
|
||||
protected virtual void OnSelectedColorChanged(EventArgs e)
|
||||
{
|
||||
EventHandler handler = SelectedColorChanged;
|
||||
if (handler != null)
|
||||
handler(this, e);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
private CombCell[] m_ColorCombs = new CombCell[144];
|
||||
private const float YOffset = .824f;
|
||||
private float[] arrXOffset = new float[] { -0.5f, -1.0f, -0.5f, 0.5f, 1.0f, 0.5f };
|
||||
private float[] arrYOffset = new float[] { YOffset, 0.0f, -YOffset, -YOffset, 0.0f, YOffset };
|
||||
private int CombDepth = 7;
|
||||
private int m_MouseOverIndex = -1;
|
||||
private int m_SelectedIndex = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.Container components = null;
|
||||
#endregion
|
||||
|
||||
#region Constructor, Dispose
|
||||
/// <summary>
|
||||
/// Creates new instance of the control.
|
||||
/// </summary>
|
||||
public ColorCombControl()
|
||||
{
|
||||
for (int i = 0; i < m_ColorCombs.Length; i++)
|
||||
m_ColorCombs[i] = new CombCell();
|
||||
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.SetStyle(ControlStyles.Opaque, true);
|
||||
this.SetStyle(DisplayHelp.DoubleBufferFlag, true);
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (components != null)
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Component Designer generated code
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
private bool m_AntiAlias = true;
|
||||
/// <summary>
|
||||
/// Gets or sets whether anti-alias smoothing is used while painting. Default value is true.
|
||||
/// </summary>
|
||||
[DefaultValue(true), Browsable(true), Category("Appearance"), Description("Gets or sets whether anti-aliasing is used while painting.")]
|
||||
public bool AntiAlias
|
||||
{
|
||||
get { return m_AntiAlias; }
|
||||
set
|
||||
{
|
||||
if (m_AntiAlias != value)
|
||||
{
|
||||
m_AntiAlias = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int GetCellSize(int height)
|
||||
{
|
||||
int cellSize = height / (2 * CombDepth - 1) + 1;
|
||||
if ((int)(Math.Floor((double)cellSize / 2)) * 2 < cellSize)
|
||||
cellSize--;
|
||||
return cellSize;
|
||||
}
|
||||
|
||||
private void InitializeColorComb()
|
||||
{
|
||||
Rectangle clientRect = this.ClientRectangle;
|
||||
clientRect.Inflate(-8, -8);
|
||||
clientRect.Height -= GetCellSize(Math.Min(clientRect.Height, clientRect.Width));
|
||||
|
||||
// Normalize...
|
||||
if (clientRect.Height < clientRect.Width)
|
||||
clientRect.Inflate(-(clientRect.Width - clientRect.Height) / 2, 0);
|
||||
else
|
||||
clientRect.Inflate(0, -(clientRect.Height - clientRect.Width) / 2);
|
||||
|
||||
int cellSize = GetCellSize(clientRect.Height);
|
||||
clientRect.Height -= cellSize * 2;
|
||||
//clientRect.Inflate(-cellSize, 0);
|
||||
int x = (clientRect.Left + clientRect.Right) / 2;
|
||||
int y = (clientRect.Top + clientRect.Bottom) / 2;
|
||||
|
||||
// Center White Comb
|
||||
m_ColorCombs[0].Color = Color.White;
|
||||
m_ColorCombs[0].SetPosition(x, y, cellSize);
|
||||
|
||||
int index = 1;
|
||||
for (int nLevel = 1; nLevel < CombDepth; nLevel++)
|
||||
{
|
||||
float posX = x + (cellSize * nLevel);
|
||||
float posY = y;
|
||||
|
||||
for (int nSide = 0; nSide < CombDepth - 1; nSide++)
|
||||
{
|
||||
int xIncrease = (int)((cellSize) * arrXOffset[nSide]);
|
||||
int yIncrease = (int)((cellSize) * arrYOffset[nSide]);
|
||||
|
||||
for (int nCell = 0; nCell < nLevel; nCell++)
|
||||
{
|
||||
float nAngle = GetAngleFromPoint(posX - x, posY - y);
|
||||
double L = .936 * (CombDepth - nLevel) / CombDepth + .12;
|
||||
|
||||
m_ColorCombs[index].Color = GetRGBFromHLSExtend((float)nAngle, L, 1.0F);
|
||||
m_ColorCombs[index].SetPosition(posX, posY, cellSize);
|
||||
index++;
|
||||
|
||||
posX += xIncrease;
|
||||
posY += yIncrease;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_ColorCombs[index].Color = Color.Black;
|
||||
index++;
|
||||
m_ColorCombs[index].Color = Color.White;
|
||||
|
||||
int RGBOffset = 255 / (15 + 2);
|
||||
|
||||
int rgb = 255 - RGBOffset;
|
||||
|
||||
x = clientRect.X + cellSize * 3;
|
||||
y = clientRect.Bottom + cellSize;
|
||||
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
Color color = Color.FromArgb(rgb, rgb, rgb);
|
||||
m_ColorCombs[index].Color = color;
|
||||
m_ColorCombs[index].SetPosition(x, y, cellSize);
|
||||
x += cellSize;
|
||||
index++;
|
||||
if (i == 7)
|
||||
{
|
||||
x = clientRect.X + (int)(cellSize * 3.5);
|
||||
y += (int)(cellSize * YOffset);
|
||||
}
|
||||
rgb -= RGBOffset;
|
||||
}
|
||||
m_ColorCombs[index].Color = Color.Black;
|
||||
}
|
||||
|
||||
|
||||
private Color GetRGBFromHLSExtend(double H, double L, double S)
|
||||
{
|
||||
int R, G, B;
|
||||
|
||||
if (S == 0.0)
|
||||
{
|
||||
R = G = B = (int)(L * 255.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
float rm1, rm2;
|
||||
|
||||
if (L <= 0.5f)
|
||||
rm2 = (float)(L + L * S);
|
||||
else
|
||||
rm2 = (float)(L + S - L * S);
|
||||
|
||||
rm1 = (float)(2.0f * L - rm2);
|
||||
|
||||
R = GetRGBFromHue(rm1, rm2, (float)(H + 120.0f));
|
||||
G = GetRGBFromHue(rm1, rm2, (float)(H));
|
||||
B = GetRGBFromHue(rm1, rm2, (float)(H - 120.0f));
|
||||
}
|
||||
|
||||
return Color.FromArgb(R, G, B);
|
||||
}
|
||||
|
||||
private float GetAngleFromPoint(float nX, float nY)
|
||||
{
|
||||
double dAngle = Math.Atan2(nY, nX);
|
||||
return (float)(dAngle * 180.0 / Math.PI);
|
||||
}
|
||||
|
||||
private int GetRGBFromHue(float rm1, float rm2, float rh)
|
||||
{
|
||||
if (rh > 360.0f)
|
||||
rh -= 360.0f;
|
||||
else if (rh < 0.0f)
|
||||
rh += 360.0f;
|
||||
|
||||
if (rh < 60.0f)
|
||||
rm1 = rm1 + (rm2 - rm1) * rh / 60.0f;
|
||||
else if (rh < 180.0f)
|
||||
rm1 = rm2;
|
||||
else if (rh < 240.0f)
|
||||
rm1 = rm1 + (rm2 - rm1) * (240.0f - rh) / 60.0f;
|
||||
|
||||
return (int)(rm1 * 255);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
if (m_AntiAlias)
|
||||
{
|
||||
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
e.Graphics.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
|
||||
}
|
||||
|
||||
using (SolidBrush brush = new SolidBrush(this.BackColor))
|
||||
g.FillRectangle(brush, -1, -1, this.Width + 1, this.Height + 1);
|
||||
|
||||
if (this.BackColor == Color.Transparent || this.BackgroundImage != null)
|
||||
{
|
||||
base.OnPaintBackground(e);
|
||||
}
|
||||
|
||||
|
||||
foreach (CombCell c in m_ColorCombs)
|
||||
c.Draw(g);
|
||||
|
||||
if (m_MouseOverIndex >= 0)
|
||||
m_ColorCombs[m_MouseOverIndex].Draw(g);
|
||||
if (m_SelectedIndex >= 0)
|
||||
m_ColorCombs[m_SelectedIndex].Draw(g);
|
||||
|
||||
base.OnPaint(e);
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
InitializeColorComb();
|
||||
base.OnResize(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
|
||||
int newMouseOver = GetCellAt(e.X, e.Y);
|
||||
SetMouseOver(newMouseOver);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
if (m_SelectedIndex >= 0)
|
||||
{
|
||||
m_ColorCombs[m_SelectedIndex].Selected = false;
|
||||
this.Invalidate(m_ColorCombs[m_SelectedIndex].Bounds);
|
||||
}
|
||||
m_SelectedIndex = -1;
|
||||
|
||||
if (m_MouseOverIndex >= 0)
|
||||
{
|
||||
m_SelectedIndex = m_MouseOverIndex;
|
||||
m_ColorCombs[m_SelectedIndex].Selected = true;
|
||||
this.Invalidate(m_ColorCombs[m_SelectedIndex].Bounds);
|
||||
OnSelectedColorChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
base.OnMouseDown(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color mouse is currently over. If mouse is not over any color in comb Color.Empty is returned.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
public Color MouseOverColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_MouseOverIndex < 0)
|
||||
return Color.Empty;
|
||||
return m_ColorCombs[m_MouseOverIndex].Color;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the selected color. When setting the color note that color must be already present in the color comb otherwise the selected color will be reset to Color.Empty.
|
||||
/// </summary>
|
||||
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public Color SelectedColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_SelectedIndex < 0)
|
||||
return Color.Empty;
|
||||
return m_ColorCombs[m_SelectedIndex].Color;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == Color.Empty && m_SelectedIndex >= 0)
|
||||
{
|
||||
m_ColorCombs[m_SelectedIndex].Selected = false;
|
||||
m_SelectedIndex = -1;
|
||||
this.Invalidate();
|
||||
OnSelectedColorChanged(EventArgs.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
int colorIndex = GetCombColorIndex(value);
|
||||
if (colorIndex != m_SelectedIndex)
|
||||
{
|
||||
if (m_SelectedIndex >= 0)
|
||||
m_ColorCombs[m_SelectedIndex].Selected = false;
|
||||
m_SelectedIndex = colorIndex;
|
||||
if (m_SelectedIndex >= 0)
|
||||
m_ColorCombs[m_SelectedIndex].Selected = true;
|
||||
this.Invalidate();
|
||||
OnSelectedColorChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private int GetCombColorIndex(Color value)
|
||||
{
|
||||
for (int i = 0; i < m_ColorCombs.Length; i++)
|
||||
{
|
||||
if (m_ColorCombs[i].Color.Equals(value))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when MouseOverColor property has changed.
|
||||
/// </summary>
|
||||
public event EventHandler MouseOverColorChanged;
|
||||
/// <summary>
|
||||
/// Raises MouseOverColorChanged event.
|
||||
/// </summary>
|
||||
/// <param name="e">Provides event arguments.</param>
|
||||
protected virtual void OnMouseOverColorChanged(EventArgs e)
|
||||
{
|
||||
EventHandler handler = MouseOverColorChanged;
|
||||
if (handler != null)
|
||||
handler(this, e);
|
||||
}
|
||||
private void SetMouseOver(int newMouseOver)
|
||||
{
|
||||
if (newMouseOver != m_MouseOverIndex)
|
||||
{
|
||||
if (m_MouseOverIndex >= 0)
|
||||
{
|
||||
m_ColorCombs[m_MouseOverIndex].MouseOver = false;
|
||||
this.Invalidate(m_ColorCombs[m_MouseOverIndex].Bounds);
|
||||
}
|
||||
m_MouseOverIndex = newMouseOver;
|
||||
if (m_MouseOverIndex >= 0)
|
||||
{
|
||||
m_ColorCombs[m_MouseOverIndex].MouseOver = true;
|
||||
this.Invalidate(m_ColorCombs[m_MouseOverIndex].Bounds);
|
||||
}
|
||||
OnMouseOverColorChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
SetMouseOver(-1);
|
||||
}
|
||||
|
||||
private int GetCellAt(int x, int y)
|
||||
{
|
||||
for (int i = 0; i < m_ColorCombs.Length; i++)
|
||||
{
|
||||
if (m_ColorCombs[i].Bounds.Contains(x, y))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
BIN
PROMS/DotNetBar Source Code/ColorPickers/ColorCombControl.ico
Normal file
BIN
PROMS/DotNetBar Source Code/ColorPickers/ColorCombControl.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
290
PROMS/DotNetBar Source Code/ColorPickers/ColorContrastControl.cs
Normal file
290
PROMS/DotNetBar Source Code/ColorPickers/ColorContrastControl.cs
Normal file
@@ -0,0 +1,290 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DevComponents.DotNetBar.ColorPickerItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the color selection control.
|
||||
/// </summary>
|
||||
[ToolboxItem(false)]
|
||||
internal class ColorContrastControl : System.Windows.Forms.Control
|
||||
{
|
||||
#region Events
|
||||
/// <summary>
|
||||
/// Occurs when SelectedColor has changed.
|
||||
/// </summary>
|
||||
public event EventHandler SelectedColorChanged;
|
||||
/// <summary>
|
||||
/// Raises SelectedColorChanged event.
|
||||
/// </summary>
|
||||
/// <param name="e">Provides event arguments.</param>
|
||||
protected virtual void OnSelectedColorChanged(EventArgs e)
|
||||
{
|
||||
EventHandler handler = SelectedColorChanged;
|
||||
if (handler != null)
|
||||
handler(this, e);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.Container components = null;
|
||||
private Color m_SelectedColor = Color.White;
|
||||
private Bitmap m_BlendBitmap=null;
|
||||
private double m_SelectedLuminance = -1;
|
||||
#endregion
|
||||
|
||||
#region Constructor, Dispose
|
||||
public ColorContrastControl()
|
||||
{
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.SetStyle(ControlStyles.Opaque, true);
|
||||
this.SetStyle(DisplayHelp.DoubleBufferFlag, true);
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
||||
|
||||
// This call is required by the Windows.Forms Form Designer.
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose( bool disposing )
|
||||
{
|
||||
if( disposing )
|
||||
{
|
||||
if(components != null)
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
}
|
||||
base.Dispose( disposing );
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
if(this.BackColor == Color.Transparent)
|
||||
{
|
||||
base.OnPaintBackground(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
using(SolidBrush brush=new SolidBrush(this.BackColor))
|
||||
g.FillRectangle(brush, this.ClientRectangle);
|
||||
}
|
||||
|
||||
if(m_BlendBitmap!=null)
|
||||
g.DrawImageUnscaled(m_BlendBitmap, 0, 0);
|
||||
|
||||
if(m_SelectedLuminance>=0)
|
||||
{
|
||||
int y = (int)(this.ClientRectangle.Height * (1 - m_SelectedLuminance));
|
||||
int x = m_BlendBitmap.Width + 4;
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
path.AddLine(x, y, x + 7, y - 4);
|
||||
path.AddLine(x+ 7 , y - 4, x + 7, y + 4);
|
||||
path.CloseAllFigures();
|
||||
using(SolidBrush brush=new SolidBrush(Color.Black))
|
||||
g.FillPath(brush, path);
|
||||
path.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
CreateBlendBitmap();
|
||||
base.OnResize (e);
|
||||
}
|
||||
|
||||
|
||||
private void CreateBlendBitmap()
|
||||
{
|
||||
Rectangle clientRect = this.ClientRectangle;
|
||||
|
||||
Bitmap bmp = new Bitmap(12, clientRect.Height, PixelFormat.Format24bppRgb);
|
||||
using (Graphics graph = Graphics.FromImage(bmp))
|
||||
{
|
||||
graph.FillRectangle(SystemBrushes.Control, clientRect);
|
||||
|
||||
Color color = m_SelectedColor;
|
||||
int ry = color.R, gy = color.G, by = color.B;
|
||||
|
||||
int pointHeight = 4;
|
||||
int pointWidth = 12;
|
||||
|
||||
int x = clientRect.X;
|
||||
int y = clientRect.Y;
|
||||
double h = 0, s = 0, l = 0;
|
||||
GetHSLFromRGB(m_SelectedColor, ref h, ref s, ref l);
|
||||
|
||||
for (int j = clientRect.Y; j < clientRect.Height; j += pointHeight)
|
||||
{
|
||||
double lumCurrent = 1 - (double) j / (double) clientRect.Height;
|
||||
Color c = GetColorFromHSL(h, s, lumCurrent);
|
||||
using (SolidBrush brush = new SolidBrush(c))
|
||||
graph.FillRectangle(brush, new Rectangle(x, y, pointWidth, pointHeight));
|
||||
y += pointHeight;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_BlendBitmap!=null)
|
||||
m_BlendBitmap.Dispose();
|
||||
m_BlendBitmap = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the selected color.
|
||||
/// </summary>
|
||||
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public Color SelectedColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if(m_SelectedLuminance>=0)
|
||||
{
|
||||
double h = 0, s = 0, l = 0;
|
||||
GetHSLFromRGB(m_SelectedColor, ref h, ref s, ref l);
|
||||
return GetColorFromHSL(h, s, m_SelectedLuminance);
|
||||
}
|
||||
return m_SelectedColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_SelectedColor = value;
|
||||
double h = 0, s = 0, l = 0;
|
||||
GetHSLFromRGB(m_SelectedColor, ref h, ref s, ref l);
|
||||
//if(m_SelectedLuminance<0)
|
||||
m_SelectedLuminance = l;
|
||||
CreateBlendBitmap();
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private int GetRGBFromHue(float rm1, float rm2, float rh)
|
||||
{
|
||||
if (rh > 360.0f)
|
||||
rh -= 360.0f;
|
||||
else if (rh < 0.0f)
|
||||
rh += 360.0f;
|
||||
|
||||
if (rh < 60.0f)
|
||||
rm1 = rm1 + (rm2 - rm1) * rh / 60.0f;
|
||||
else if (rh < 180.0f)
|
||||
rm1 = rm2;
|
||||
else if (rh < 240.0f)
|
||||
rm1 = rm1 + (rm2 - rm1) * (240.0f - rh) / 60.0f;
|
||||
|
||||
return (int)(rm1 * 255);
|
||||
}
|
||||
|
||||
private Color GetColorFromHSL( double H, double S, double L)
|
||||
{
|
||||
double r=0,g=0,b=0;
|
||||
double temp1,temp2;
|
||||
if(L==0)
|
||||
{
|
||||
r=g=b=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(S==0)
|
||||
{
|
||||
r=g=b=L;
|
||||
}
|
||||
else
|
||||
{
|
||||
temp2 = ((L<=0.5) ? L*(1.0+S) : L+S-(L*S));
|
||||
temp1 = 2.0*L-temp2;
|
||||
double[] t3=new double[]{H+1.0/3.0,H,H-1.0/3.0};
|
||||
double[] clr=new double[]{0,0,0};
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
if(t3[i]<0)
|
||||
t3[i]+=1.0;
|
||||
|
||||
if(t3[i]>1)
|
||||
t3[i]-=1.0;
|
||||
|
||||
if(6.0*t3[i] < 1.0)
|
||||
clr[i]=temp1+(temp2-temp1)*t3[i]*6.0;
|
||||
else if(2.0*t3[i] < 1.0)
|
||||
clr[i]=temp2;
|
||||
else if(3.0*t3[i] < 2.0)
|
||||
clr[i]=(temp1+(temp2-temp1)*((2.0/3.0)-t3[i])*6.0);
|
||||
else
|
||||
clr[i]=temp1;
|
||||
}
|
||||
|
||||
r=clr[0];
|
||||
g=clr[1];
|
||||
b=clr[2];
|
||||
}
|
||||
}
|
||||
|
||||
return Color.FromArgb((int)(255*r),(int)(255*g),(int)(255*b));
|
||||
}
|
||||
|
||||
private void GetHSLFromRGB(Color color, ref double H, ref double S, ref double L )
|
||||
{
|
||||
H=color.GetHue()/360.0; // we store hue as 0-1 as opposed to 0-360
|
||||
L=color.GetBrightness();
|
||||
S=color.GetSaturation();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
double d = 1 - (double) e.Y / (double) ClientRectangle.Height;
|
||||
SetLuminance(d);
|
||||
base.OnMouseDown (e);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
if(e.Button==MouseButtons.Left && e.Y>=0 && e.Y<ClientRectangle.Bottom)
|
||||
{
|
||||
double d = 1 - (double) e.Y / (double) ClientRectangle.Height;
|
||||
SetLuminance(d);
|
||||
}
|
||||
base.OnMouseMove (e);
|
||||
}
|
||||
|
||||
private void SetLuminance(double d)
|
||||
{
|
||||
m_SelectedLuminance = d;
|
||||
this.Invalidate();
|
||||
if(SelectedColorChanged!=null)
|
||||
SelectedColorChanged(this, new EventArgs());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Component Designer generated code
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
//
|
||||
// ColorContrastControl
|
||||
//
|
||||
this.Name = "ColorContrastControl";
|
||||
this.Size = new System.Drawing.Size(24, 248);
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
198
PROMS/DotNetBar Source Code/ColorPickers/ColorItem.cs
Normal file
198
PROMS/DotNetBar Source Code/ColorPickers/ColorItem.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DevComponents.DotNetBar
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents color item used for color picker control. Color item can only be used as part of the color picker DotNetBar feature.
|
||||
/// </summary>
|
||||
public class ColorItem : BaseItem
|
||||
{
|
||||
#region Private Variables
|
||||
private Color m_Color = Color.Black;
|
||||
private Size m_DesiredSize = new Size(13, 13);
|
||||
private bool m_MouseOver = false;
|
||||
private eColorItemBorder m_Border = eColorItemBorder.All;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public ColorItem():this("","") {}
|
||||
public ColorItem(string sName):this(sName,""){}
|
||||
public ColorItem(string sName, string ItemText)
|
||||
: base(sName, ItemText)
|
||||
{
|
||||
this.IsAccessible=false;
|
||||
this.CanCustomize = false;
|
||||
}
|
||||
|
||||
public ColorItem(string sName, string ItemText, Color color)
|
||||
: base(sName, ItemText)
|
||||
{
|
||||
this.IsAccessible = false;
|
||||
this.CanCustomize = false;
|
||||
m_Color = color;
|
||||
}
|
||||
|
||||
public override BaseItem Copy()
|
||||
{
|
||||
ColorItem copy = new ColorItem(m_Name);
|
||||
this.CopyToItem(copy);
|
||||
|
||||
return copy;
|
||||
}
|
||||
protected override void CopyToItem(BaseItem copy)
|
||||
{
|
||||
ColorItem ci = copy as ColorItem;
|
||||
base.CopyToItem(ci);
|
||||
ci.DesiredSize = this.DesiredSize;
|
||||
ci.Color = this.Color;
|
||||
ci.Border = this.Border;
|
||||
if (this.ShouldSerializeDesiredSize())
|
||||
ci.DesiredSize = this.DesiredSize;
|
||||
}
|
||||
|
||||
public override void Paint(ItemPaintArgs p)
|
||||
{
|
||||
Rendering.BaseRenderer renderer = p.Renderer;
|
||||
if (renderer != null)
|
||||
{
|
||||
ColorItemRendererEventArgs e = new ColorItemRendererEventArgs(p.Graphics, this);
|
||||
renderer.DrawColorItem(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rendering.ColorItemPainter painter = PainterFactory.CreateColorItemPainter(this);
|
||||
if (painter != null)
|
||||
{
|
||||
ColorItemRendererEventArgs e = new ColorItemRendererEventArgs(p.Graphics, this);
|
||||
painter.PaintColorItem(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void RecalcSize()
|
||||
{
|
||||
m_Rect.Size = Dpi.Size(m_DesiredSize);
|
||||
base.RecalcSize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color represented by this item. Default value is Color.Black.
|
||||
/// </summary>
|
||||
[Browsable(true), DevCoBrowsable(true), DevCoSerialize(), Category("Appearance"), Description("Indicates the color represented by this item.")]
|
||||
public System.Drawing.Color Color
|
||||
{
|
||||
get { return m_Color; }
|
||||
set
|
||||
{
|
||||
m_Color = value;
|
||||
OnAppearanceChanged();
|
||||
}
|
||||
}
|
||||
private bool ShouldSerializeColor()
|
||||
{
|
||||
return (m_Color != Color.Black);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the size of the item when displayed. Default value is 13x13 pixels.
|
||||
/// </summary>
|
||||
[Browsable(true), DevCoBrowsable(true), DevCoSerialize(), Category("Appearance"), Description("Indicates the size of the item when displayed.")]
|
||||
public System.Drawing.Size DesiredSize
|
||||
{
|
||||
get { return m_DesiredSize; }
|
||||
set
|
||||
{
|
||||
if (value.Width > 0 && value.Height > 0)
|
||||
{
|
||||
m_DesiredSize = value;
|
||||
NeedRecalcSize = true;
|
||||
OnAppearanceChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
private bool ShouldSerializeDesiredSize()
|
||||
{
|
||||
return (m_DesiredSize.Width!=13 || m_DesiredSize.Height!=13);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets border drawn around the item. Default value is eColorItemBorder.All which indicates that border is drawn
|
||||
/// on all four sides.
|
||||
/// </summary>
|
||||
[Browsable(true), DevCoBrowsable(true), DefaultValue(eColorItemBorder.All), Description("Indicate border drawn around the item"), DevCoSerialize()]
|
||||
public eColorItemBorder Border
|
||||
{
|
||||
get { return m_Border; }
|
||||
set
|
||||
{
|
||||
m_Border = value;
|
||||
OnAppearanceChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether mouse is over the item.
|
||||
/// </summary>
|
||||
public bool IsMouseOver
|
||||
{
|
||||
get { return m_MouseOver; }
|
||||
}
|
||||
|
||||
[System.ComponentModel.Browsable(false), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public override void InternalMouseEnter()
|
||||
{
|
||||
base.InternalMouseEnter();
|
||||
SetMouseOver(true);
|
||||
BaseItem parent = this.Parent;
|
||||
while (parent != null && !(parent is ColorPickerDropDown))
|
||||
parent = parent.Parent;
|
||||
if (parent != null && parent is ColorPickerDropDown)
|
||||
((ColorPickerDropDown)parent).InvokeColorPreview(new ColorPreviewEventArgs(this.Color, this));
|
||||
}
|
||||
|
||||
|
||||
[System.ComponentModel.Browsable(false), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public override void InternalMouseLeave()
|
||||
{
|
||||
base.InternalMouseLeave();
|
||||
SetMouseOver(false);
|
||||
}
|
||||
|
||||
private void SetMouseOver(bool value)
|
||||
{
|
||||
if (value != m_MouseOver)
|
||||
{
|
||||
m_MouseOver = value;
|
||||
this.Refresh();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Serialization
|
||||
/// <summary>
|
||||
/// Overloaded. Serializes the item and all sub-items into the XmlElement.
|
||||
/// </summary>
|
||||
/// <param name="ThisItem">XmlElement to serialize the item to.</param>
|
||||
protected internal override void Serialize(ItemSerializationContext context)
|
||||
{
|
||||
base.Serialize(context);
|
||||
System.Xml.XmlElement xml = context.ItemXmlElement;
|
||||
ElementSerializer.Serialize(this, xml);
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// Overloaded. Deserializes the Item from the XmlElement.
|
||||
/// </summary>
|
||||
/// <param name="ItemXmlSource">Source XmlElement.</param>
|
||||
public override void Deserialize(ItemSerializationContext context)
|
||||
{
|
||||
base.Deserialize(context);
|
||||
System.Xml.XmlElement xml = context.ItemXmlElement;
|
||||
ElementSerializer.Deserialize(this, xml);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
978
PROMS/DotNetBar Source Code/ColorPickers/ColorPickerDropDown.cs
Normal file
978
PROMS/DotNetBar Source Code/ColorPickers/ColorPickerDropDown.cs
Normal file
@@ -0,0 +1,978 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Drawing;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using DevComponents.DotNetBar.Rendering;
|
||||
|
||||
namespace DevComponents.DotNetBar
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the color picker drop down button.
|
||||
/// </summary>
|
||||
[DefaultEvent("SelectedColorChanged")]
|
||||
public class ColorPickerDropDown : ButtonItem
|
||||
{
|
||||
#region Events
|
||||
/// <summary>
|
||||
/// Occurs when color is chosen from drop-down color picker or from Custom Colors dialog box. Selected color can be accessed through SelectedColor property.
|
||||
/// </summary>
|
||||
[Description("Occurs when color is chosen from drop-down color picker or from Custom Colors dialog box.")]
|
||||
public event EventHandler SelectedColorChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when mouse is moving over the colors presented by the color picker. You can use it to preview the color before it is selected.
|
||||
/// </summary>
|
||||
[Description("Occurs when mouse is moving over the colors presented by the color picker")]
|
||||
public event ColorPreviewEventHandler ColorPreview;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before color picker dialog is shown. Data property of the event arguments will hold the reference to the Form about to be shown.
|
||||
/// </summary>
|
||||
public event CancelObjectValueEventHandler BeforeColorDialog;
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
private bool m_ColorsInitialized = false;
|
||||
private bool m_DisplayThemeColors = true;
|
||||
private bool m_DisplayStandardColors = true;
|
||||
private bool m_DisplayMoreColors = true;
|
||||
|
||||
private bool m_Localized = false;
|
||||
private string m_ThemeColorsLabel = "Theme Colors";
|
||||
private string m_StandardColorsLabel = "Standard Colors";
|
||||
private string m_MoreColorsLabel = "&More Colors...";
|
||||
private Color m_SelectedColor = System.Drawing.Color.Empty;
|
||||
private Rectangle m_SelectedColorRectangle = Rectangle.Empty;
|
||||
private bool m_SelectedImageCreated = false;
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
/// <summary>
|
||||
/// Creates new instance of ButtonItem.
|
||||
/// </summary>
|
||||
public ColorPickerDropDown() : this("", "") { }
|
||||
/// <summary>
|
||||
/// Creates new instance of ButtonItem and assigns the name to it.
|
||||
/// </summary>
|
||||
/// <param name="sItemName">Item name.</param>
|
||||
public ColorPickerDropDown(string sItemName) : this(sItemName, "") { }
|
||||
/// <summary>
|
||||
/// Creates new instance of ButtonItem and assigns the name and text to it.
|
||||
/// </summary>
|
||||
/// <param name="sItemName">Item name.</param>
|
||||
/// <param name="ItemText">item text.</param>
|
||||
public ColorPickerDropDown(string sItemName, string ItemText)
|
||||
: base(sItemName, ItemText)
|
||||
{
|
||||
//this.AutoExpandOnClick = true;
|
||||
this.SubItems.Add(new ButtonItem("tempColorPickerItem"));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
/// <summary>
|
||||
/// Returns copy of the item.
|
||||
/// </summary>
|
||||
public override BaseItem Copy()
|
||||
{
|
||||
ColorPickerDropDown objCopy = new ColorPickerDropDown();
|
||||
this.CopyToItem(objCopy);
|
||||
return objCopy;
|
||||
}
|
||||
/// <summary>
|
||||
/// Copies the ButtonItem specific properties to new instance of the item.
|
||||
/// </summary>
|
||||
/// <param name="c">New ButtonItem instance.</param>
|
||||
protected override void CopyToItem(BaseItem c)
|
||||
{
|
||||
ColorPickerDropDown copy = c as ColorPickerDropDown;
|
||||
copy.DisplayMoreColors = this.DisplayMoreColors;
|
||||
copy.DisplayStandardColors = this.DisplayStandardColors;
|
||||
copy.DisplayThemeColors = this.DisplayThemeColors;
|
||||
copy.SelectedColorChanged = this.SelectedColorChanged;
|
||||
copy.CustomStandardColors = GetCopy(this.CustomStandardColors);
|
||||
copy.CustomThemeColors = GetCopy(this.CustomThemeColors);
|
||||
copy.SelectedColorImageRectangle = this.SelectedColorImageRectangle;
|
||||
copy.SelectedColor = this.SelectedColor;
|
||||
|
||||
base.CopyToItem(copy);
|
||||
}
|
||||
|
||||
private ColorItem[][] GetCopy(ColorItem[][] colorItems)
|
||||
{
|
||||
if (colorItems == null || colorItems.Length == 0)
|
||||
return null;
|
||||
ColorItem[][] copies=new ColorItem[colorItems.Length][];
|
||||
for (int i = 0; i < colorItems.Length; i++)
|
||||
{
|
||||
ColorItem[] items = colorItems[i];
|
||||
copies[i]=new ColorItem[items.Length];
|
||||
for (int j = 0; j < items.Length; j++)
|
||||
{
|
||||
copies[i][j] = (ColorItem) items[j].Copy();
|
||||
}
|
||||
}
|
||||
|
||||
return copies;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Raises the ColorPreview event.
|
||||
/// </summary>
|
||||
/// <param name="e">Provides the data for the event.</param>
|
||||
protected virtual void OnColorPreview(ColorPreviewEventArgs e)
|
||||
{
|
||||
if (ColorPreview != null)
|
||||
ColorPreview(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the ColorPreview event.
|
||||
/// </summary>
|
||||
/// <param name="e">Provides data for the event.</param>
|
||||
public void InvokeColorPreview(ColorPreviewEventArgs e)
|
||||
{
|
||||
OnColorPreview(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the last selected color from either the drop-down or Custom Color dialog box. Default value is
|
||||
/// Color.Empty. You can use SelectedColorChanged event to be notified when this property changes.
|
||||
/// </summary>
|
||||
[Browsable(false), DevCoBrowsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public Color SelectedColor
|
||||
{
|
||||
get { return m_SelectedColor; }
|
||||
set { SetSelectedColor(value, false); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether theme colors are displayed on drop-down. Default value is true.
|
||||
/// </summary>
|
||||
[Browsable(true), DefaultValue(true), DevCoBrowsable(true), DevCoSerialize(), Category("Appearance"), Description("Indicates whether theme colors are displayed on drop-down.")]
|
||||
public bool DisplayThemeColors
|
||||
{
|
||||
get { return m_DisplayThemeColors; }
|
||||
set { m_DisplayThemeColors = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether standard colors are displayed on drop-down. Default value is true.
|
||||
/// </summary>
|
||||
[Browsable(true), DefaultValue(true), DevCoBrowsable(true), DevCoSerialize(), Category("Appearance"), Description("Indicates whether standard colors are displayed on drop-down.")]
|
||||
public bool DisplayStandardColors
|
||||
{
|
||||
get { return m_DisplayStandardColors; }
|
||||
set { m_DisplayStandardColors = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets more colors menu item is visible which allows user to open Custom Colors dialog box. Default value is true.
|
||||
/// </summary>
|
||||
[Browsable(true), DefaultValue(true), DevCoBrowsable(true), DevCoSerialize(), Category("Appearance"), Description("Indicates more colors menu item is visible which allows user to open Custom Colors dialog box.")]
|
||||
public bool DisplayMoreColors
|
||||
{
|
||||
get { return m_DisplayMoreColors; }
|
||||
set { m_DisplayMoreColors = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether SubItems collection is serialized. ColorPickerDropDown does not serialize the sub items.
|
||||
/// </summary>
|
||||
protected override bool ShouldSerializeSubItems()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the rectangle in Image coordinates where selected color will be painted. Setting this property will
|
||||
/// have an effect only if Image property is used to set the image. Default value is an empty rectangle which indicates
|
||||
/// that selected color will not be painted on the image.
|
||||
/// </summary>
|
||||
[Browsable(true), Description("Indicates rectangle in Image coordinates where selected color will be painted. Property will have effect only if Image property is used to set the image."), Category("Behaviour")]
|
||||
public Rectangle SelectedColorImageRectangle
|
||||
{
|
||||
get { return m_SelectedColorRectangle; }
|
||||
set
|
||||
{
|
||||
m_SelectedColorRectangle = value;
|
||||
UpdateSelectedColorImage();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether property should be serialized.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public bool ShouldSerializeSelectedColorImageRectangle()
|
||||
{
|
||||
return !m_SelectedColorRectangle.IsEmpty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the property to its default value.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public void ResetSelectedColorImageRectangle()
|
||||
{
|
||||
SelectedColorImageRectangle = Rectangle.Empty;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Indicates whether the item will auto-expand when clicked.
|
||||
///// When item is on top level bar and not on menu and contains sub-items, sub-items will be shown only if user
|
||||
///// click the expand part of the button. Setting this property to true will expand the button and show sub-items when user
|
||||
///// clicks anywhere inside of the button. Default value is true which indicates that button is expanded only
|
||||
///// if its expand part is clicked.
|
||||
///// </summary>
|
||||
//[DefaultValue(true), Browsable(true), DevCoBrowsable(true), Category("Behavior"), Description("Indicates whether the item will auto-expand (display pop-up menu or toolbar) when clicked.")]
|
||||
//public override bool AutoExpandOnClick
|
||||
//{
|
||||
// get { return base.AutoExpandOnClick; }
|
||||
// set { base.AutoExpandOnClick = value; }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether internal representation of color items on popup has been initialized.
|
||||
/// </summary>
|
||||
[Browsable(false)]
|
||||
public bool ColorsInitialized
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ColorsInitialized;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnStyleChanged()
|
||||
{
|
||||
m_ColorsInitialized = false;
|
||||
base.OnStyleChanged();
|
||||
}
|
||||
|
||||
protected override void OnPopupOpen(PopupOpenEventArgs e)
|
||||
{
|
||||
base.OnPopupOpen(e); // Fire events first then initialize
|
||||
if (!m_ColorsInitialized)
|
||||
InitializeColorDropDown();
|
||||
}
|
||||
|
||||
private void InitializeColorDropDown()
|
||||
{
|
||||
this.SubItems.Clear();
|
||||
|
||||
LoadResources();
|
||||
if (m_DisplayThemeColors)
|
||||
{
|
||||
LabelItem label = new LabelItem();
|
||||
label.CanCustomize = false;
|
||||
label.Text = m_ThemeColorsLabel;
|
||||
if (GlobalManager.Renderer is Office2007Renderer)
|
||||
{
|
||||
label.BackColor = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.Gallery.GroupLabelBackground;
|
||||
label.ForeColor = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.Gallery.GroupLabelText;
|
||||
label.SingleLineColor = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.Gallery.GroupLabelBorder;
|
||||
}
|
||||
else
|
||||
{
|
||||
label.BackColor = ColorScheme.GetColor("DDE7EE");
|
||||
label.ForeColor = ColorScheme.GetColor("00156E");
|
||||
label.SingleLineColor = ColorScheme.GetColor("C5C5C5");
|
||||
}
|
||||
label.PaddingBottom = 1;
|
||||
label.PaddingLeft = 0;
|
||||
label.PaddingRight = 0;
|
||||
label.PaddingTop = 1;
|
||||
label.BorderSide = eBorderSide.Bottom;
|
||||
label.BorderType = eBorderType.SingleLine;
|
||||
this.SubItems.Add(label);
|
||||
ArrayList colors = this.GetThemeColors();
|
||||
AddColors(colors);
|
||||
}
|
||||
|
||||
if (m_DisplayStandardColors)
|
||||
{
|
||||
LabelItem label = new LabelItem();
|
||||
label.CanCustomize = false;
|
||||
label.Text = m_StandardColorsLabel;
|
||||
if (GlobalManager.Renderer is Office2007Renderer)
|
||||
{
|
||||
label.BackColor = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.QuickAccessToolbar.QatCustomizeMenuLabelBackground;
|
||||
label.ForeColor = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.QuickAccessToolbar.QatCustomizeMenuLabelText;
|
||||
label.SingleLineColor = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.Gallery.GroupLabelBorder;
|
||||
}
|
||||
else
|
||||
{
|
||||
label.BackColor = ColorScheme.GetColor("DDE7EE");
|
||||
label.ForeColor = ColorScheme.GetColor("00156E");
|
||||
label.SingleLineColor = ColorScheme.GetColor("C5C5C5");
|
||||
}
|
||||
label.PaddingBottom = 1;
|
||||
label.PaddingLeft = 0;
|
||||
label.PaddingRight = 0;
|
||||
label.PaddingTop = 1;
|
||||
label.BorderSide = eBorderSide.Bottom;
|
||||
label.BorderType = eBorderType.SingleLine;
|
||||
this.SubItems.Add(label);
|
||||
ArrayList colors = this.GetStandardColors();
|
||||
AddColors(colors);
|
||||
}
|
||||
|
||||
if (m_DisplayMoreColors)
|
||||
{
|
||||
ButtonItem button = new ButtonItem("sys_CPMoreColors", m_MoreColorsLabel);
|
||||
button.CanCustomize = false;
|
||||
button.Image = BarFunctions.LoadBitmap("SystemImages.ColorPickerCustomColors.png");
|
||||
button.Click += new EventHandler(MoreColorsButtonClick);
|
||||
button.BeginGroup = true;
|
||||
this.SubItems.Add(button);
|
||||
}
|
||||
|
||||
m_ColorsInitialized = true;
|
||||
|
||||
OnColorItemsInitialized(EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "Occurs after popup colors have been added to the SubItems collection. This event can be used to effectively add custom items to the popup.
|
||||
/// </summary>
|
||||
[Description("Occurs after popup colors have been added to the SubItems collection. This event can be used to effectively add custom items to the popup.")]
|
||||
public event EventHandler ColorItemsInitialized;
|
||||
|
||||
/// <summary>
|
||||
/// Raises RemovingToken event.
|
||||
/// </summary>
|
||||
/// <param name="e">Provides event arguments.</param>
|
||||
protected virtual void OnColorItemsInitialized(EventArgs e)
|
||||
{
|
||||
EventHandler handler = ColorItemsInitialized;
|
||||
if (handler != null)
|
||||
handler(this, e);
|
||||
}
|
||||
|
||||
private void MoreColorsButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
DisplayMoreColorsDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the Colors dialog that allows user to choose the color or create a custom color. If new color is chosen the
|
||||
/// SelectedColorChanged event is raised.
|
||||
/// </summary>
|
||||
public DialogResult DisplayMoreColorsDialog()
|
||||
{
|
||||
DialogResult result = DialogResult.Cancel;
|
||||
|
||||
if (StyleManager.IsMetro(this.EffectiveStyle))
|
||||
{
|
||||
ColorPickerItem.CustomColorDialogMetro d = new ColorPickerItem.CustomColorDialogMetro();
|
||||
d.SetStyle(this.EffectiveStyle);
|
||||
d.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
if (!this.SelectedColor.IsEmpty)
|
||||
d.CurrentColor = this.SelectedColor;
|
||||
LocalizeDialog(d);
|
||||
CancelObjectValueEventArgs e = new CancelObjectValueEventArgs(d);
|
||||
OnBeforeColorDialog(e);
|
||||
if (e.Cancel)
|
||||
{
|
||||
d.Dispose();
|
||||
return DialogResult.None;
|
||||
}
|
||||
if (_OwnerWindow != null)
|
||||
{
|
||||
if (_OwnerWindow is Form && ((Form)_OwnerWindow).TopMost)
|
||||
d.TopMost = true;
|
||||
d.ShowDialog(_OwnerWindow);
|
||||
}
|
||||
else
|
||||
d.ShowDialog();
|
||||
|
||||
result = d.DialogResult;
|
||||
if (result == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
if (!d.NewColor.IsEmpty)
|
||||
{
|
||||
this.SetSelectedColor(d.NewColor);
|
||||
}
|
||||
}
|
||||
|
||||
d.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
ColorPickerItem.CustomColorDialog d = new ColorPickerItem.CustomColorDialog();
|
||||
d.SetStyle(this.EffectiveStyle);
|
||||
d.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
if (!this.SelectedColor.IsEmpty)
|
||||
d.CurrentColor = this.SelectedColor;
|
||||
LocalizeDialog(d);
|
||||
CancelObjectValueEventArgs e = new CancelObjectValueEventArgs(d);
|
||||
OnBeforeColorDialog(e);
|
||||
if (e.Cancel)
|
||||
{
|
||||
d.Dispose();
|
||||
return DialogResult.None;
|
||||
}
|
||||
if (_OwnerWindow != null)
|
||||
{
|
||||
if (_OwnerWindow is Form && ((Form)_OwnerWindow).TopMost)
|
||||
d.TopMost = true;
|
||||
d.ShowDialog(_OwnerWindow);
|
||||
}
|
||||
else
|
||||
d.ShowDialog();
|
||||
|
||||
result = d.DialogResult;
|
||||
if (result == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
if (!d.NewColor.IsEmpty)
|
||||
{
|
||||
this.SetSelectedColor(d.NewColor);
|
||||
}
|
||||
}
|
||||
|
||||
d.Dispose();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the BeforeColorDialog event.
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected virtual void OnBeforeColorDialog(CancelObjectValueEventArgs e)
|
||||
{
|
||||
CancelObjectValueEventHandler h = this.BeforeColorDialog;
|
||||
if (h != null)
|
||||
h(this, e);
|
||||
}
|
||||
|
||||
private IWin32Window _OwnerWindow = null;
|
||||
/// <summary>
|
||||
/// Gets or sets the Owner Window that will be used as owner for the colors modal dialog when displayed.
|
||||
/// </summary>
|
||||
[Browsable(false), DefaultValue(null)]
|
||||
public IWin32Window OwnerWindow
|
||||
{
|
||||
get { return _OwnerWindow; }
|
||||
set { _OwnerWindow = value; }
|
||||
}
|
||||
|
||||
private void LocalizeDialog(ColorPickerItem.CustomColorDialog d)
|
||||
{
|
||||
if (this.GetOwner() != null)
|
||||
m_Localized = true;
|
||||
using (LocalizationManager lm = new LocalizationManager(this.GetOwner() as IOwnerLocalize))
|
||||
{
|
||||
string s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogOKButton);
|
||||
if (s != "") d.buttonOK.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogCancelButton);
|
||||
if (s != "") d.buttonCancel.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogNewColorLabel);
|
||||
if (s != "") d.labelNewColor.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogCurrentColorLabel);
|
||||
if (s != "") d.labelCurrentColor.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogStandardColorsLabel);
|
||||
if (s != "") d.labelStandardColors.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogCustomColorsLabel);
|
||||
if (s != "") d.labelCustomColors.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogGreenLabel);
|
||||
if (s != "") d.labelGreen.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogBlueLabel);
|
||||
if (s != "") d.labelBlue.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogRedLabel);
|
||||
if (s != "") d.labelRed.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerTabStandard);
|
||||
if (s != "") d.tabItemStandard.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerTabCustom);
|
||||
if (s != "") d.tabItemCustom.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerCaption);
|
||||
if (s != "") d.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogColorModelLabel);
|
||||
if (s != "") d.labelColorModel.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogRgbLabel);
|
||||
if (s != "") d.comboColorModel.Items[0] = s;
|
||||
}
|
||||
}
|
||||
private void LocalizeDialog(ColorPickerItem.CustomColorDialogMetro d)
|
||||
{
|
||||
if (this.GetOwner() != null)
|
||||
m_Localized = true;
|
||||
using (LocalizationManager lm = new LocalizationManager(this.GetOwner() as IOwnerLocalize))
|
||||
{
|
||||
string s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogOKButton);
|
||||
if (s != "") d.buttonOK.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogCancelButton);
|
||||
if (s != "") d.buttonCancel.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogNewColorLabel);
|
||||
if (s != "") d.labelNewColor.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogCurrentColorLabel);
|
||||
if (s != "") d.labelCurrentColor.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogStandardColorsLabel);
|
||||
if (s != "") d.labelStandardColors.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogCustomColorsLabel);
|
||||
if (s != "") d.labelCustomColors.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogGreenLabel);
|
||||
if (s != "") d.labelGreen.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogBlueLabel);
|
||||
if (s != "") d.labelBlue.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogRedLabel);
|
||||
if (s != "") d.labelRed.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerTabStandard);
|
||||
if (s != "") d.tabItemStandard.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerTabCustom);
|
||||
if (s != "") d.tabItemCustom.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerCaption);
|
||||
if (s != "") d.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogColorModelLabel);
|
||||
if (s != "") d.labelColorModel.Text = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerDialogRgbLabel);
|
||||
if (s != "") d.comboColorModel.Items[0] = s;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddColors(ArrayList colors)
|
||||
{
|
||||
int colorItemSpacing = 3;
|
||||
for (int i = 0; i < colors.Count; i++)
|
||||
{
|
||||
ItemContainer cont = new ItemContainer();
|
||||
cont.Orientation = eOrientation.Horizontal;
|
||||
cont.ItemSpacing = colorItemSpacing;
|
||||
if (i == 0)
|
||||
{
|
||||
cont.BackgroundStyle.MarginBottom = 5;
|
||||
cont.BackgroundStyle.MarginTop = 3;
|
||||
}
|
||||
if (i == colors.Count - 1)
|
||||
cont.BackgroundStyle.MarginBottom = 3;
|
||||
|
||||
ColorItem[] colorLine = (ColorItem[])colors[i];
|
||||
foreach (ColorItem ci in colorLine)
|
||||
{
|
||||
cont.SubItems.Add(ci);
|
||||
ci.Click += new EventHandler(ColorItemClick);
|
||||
ci.AutoCollapseOnClick = false;
|
||||
}
|
||||
this.SubItems.Add(cont);
|
||||
}
|
||||
}
|
||||
|
||||
private void ColorItemClick(object sender, EventArgs e)
|
||||
{
|
||||
ColorItem ci = sender as ColorItem;
|
||||
if (ci == null)
|
||||
return;
|
||||
|
||||
SetSelectedColor(ci.Color);
|
||||
if (AutoCollapseOnClick)
|
||||
BaseItem.CollapseAll(this);
|
||||
else if (this.PopupControl != null)
|
||||
this.PopupControl.Invalidate();
|
||||
}
|
||||
|
||||
private void SetSelectedColor(Color c)
|
||||
{
|
||||
SetSelectedColor(c, true);
|
||||
}
|
||||
|
||||
private void SetSelectedColor(Color c, bool raiseClick)
|
||||
{
|
||||
bool valueChanged = (m_SelectedColor != c);
|
||||
m_SelectedColor = c;
|
||||
|
||||
OnSelectedColorChanged(new EventArgs());
|
||||
if (raiseClick)
|
||||
RaiseClick();
|
||||
|
||||
if (valueChanged && ShouldSyncProperties)
|
||||
BarFunctions.SyncProperty(this, "SelectedColor");
|
||||
|
||||
UpdateSelectedColorImage();
|
||||
}
|
||||
|
||||
protected override void ScaleItem(SizeF factor)
|
||||
{
|
||||
base.ScaleItem(factor);
|
||||
UpdateSelectedColorImage();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the selected color image if the SelectedColorImageRectangle has been set and button is using Image property to display the image.
|
||||
/// </summary>
|
||||
public void UpdateSelectedColorImage()
|
||||
{
|
||||
if (m_SelectedColorRectangle.IsEmpty || m_SelectedColorRectangle.Width <= 0 || m_SelectedColorRectangle.Height <= 0 ||
|
||||
this.Image == null || this.DesignMode) return;
|
||||
|
||||
Bitmap bmp = new Bitmap(this.Image.Width, this.Image.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
{
|
||||
Rectangle r = m_SelectedColorRectangle;
|
||||
g.DrawImage(this.Image, 0, 0, this.Image.Width, this.Image.Height);
|
||||
Color selColor = this.SelectedColor;
|
||||
bool noColor = false;
|
||||
if (selColor.IsEmpty || selColor == Color.Transparent)
|
||||
{
|
||||
selColor = Color.White;
|
||||
noColor = true;
|
||||
}
|
||||
using (SolidBrush b = new SolidBrush(selColor))
|
||||
{
|
||||
g.FillRectangle(b, r);
|
||||
}
|
||||
if (noColor && r.Height > 5)
|
||||
{
|
||||
r.Width--;
|
||||
r.Height--;
|
||||
using (Pen p = new Pen(Color.Black))
|
||||
{
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||
g.DrawLine(p, r.X, r.Y, r.Right, r.Bottom);
|
||||
g.DrawLine(p, r.Right, r.Y, r.X, r.Bottom);
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_SelectedImageCreated)
|
||||
{
|
||||
Image img = this.Image;
|
||||
this.Image = bmp;
|
||||
img.Dispose();
|
||||
}
|
||||
else
|
||||
this.Image = bmp;
|
||||
m_SelectedImageCreated = true;
|
||||
}
|
||||
|
||||
#if FRAMEWORK20
|
||||
private ColorItem[][] _CustomThemeColors = null;
|
||||
/// <summary>
|
||||
/// Gets or sets the array of ColorItem objects that will be used as theme colors instead of built-in color palette.
|
||||
/// See: http://www.devcomponents.com/kb2/?p=79 for instructions.
|
||||
/// </summary>
|
||||
[DefaultValue(null), Category("Colors"), Description("Array of ColorItem objects that will be used as theme colors instead of built-in color palette.")]
|
||||
public ColorItem[][] CustomThemeColors
|
||||
{
|
||||
get { return _CustomThemeColors; }
|
||||
set
|
||||
{
|
||||
_CustomThemeColors = value;
|
||||
m_ColorsInitialized = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets collection of ColorItem[] arrays that represent themed colors. Each ColorItem[] array is used to represent single line of theme colors.
|
||||
/// </summary>
|
||||
/// <returns>Collection of ColorItem[] arrays.</returns>
|
||||
protected virtual ArrayList GetThemeColors()
|
||||
{
|
||||
ArrayList colors = new ArrayList();
|
||||
#if FRAMEWORK20
|
||||
if (_CustomThemeColors == null || _CustomThemeColors.Length == 0)
|
||||
#endif
|
||||
{
|
||||
eDotNetBarStyle effectiveStyle = EffectiveStyle;
|
||||
if (effectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(effectiveStyle))
|
||||
{
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItem("FFFFFF"),
|
||||
GetColorItem("000000"),
|
||||
GetColorItem("EEECE1"),
|
||||
GetColorItem("1F497D"),
|
||||
GetColorItem("4F81BD"),
|
||||
GetColorItem("C0504D"),
|
||||
GetColorItem("9BBB59"),
|
||||
GetColorItem("8064A2"),
|
||||
GetColorItem("4BACC6"),
|
||||
GetColorItem("F79646")});
|
||||
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItemTop("F2F2F2"),
|
||||
GetColorItemTop("7F7F7F"),
|
||||
GetColorItemTop("DDD9C3"),
|
||||
GetColorItemTop("C6D9F0"),
|
||||
GetColorItemTop("DBE5F1"),
|
||||
GetColorItemTop("F2DCDB"),
|
||||
GetColorItemTop("EBF1DD"),
|
||||
GetColorItemTop("E5E0EC"),
|
||||
GetColorItemTop("DBEEF3"),
|
||||
GetColorItemTop("FDEADA")});
|
||||
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItemMiddle("D8D8D8"),
|
||||
GetColorItemMiddle("595959"),
|
||||
GetColorItemMiddle("C4BD97"),
|
||||
GetColorItemMiddle("8DB3E2"),
|
||||
GetColorItemMiddle("B8CCE4"),
|
||||
GetColorItemMiddle("E5B9B7"),
|
||||
GetColorItemMiddle("D7E3BC"),
|
||||
GetColorItemMiddle("CCC1D9"),
|
||||
GetColorItemMiddle("B7DDE8"),
|
||||
GetColorItemMiddle("FBD5B5")});
|
||||
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItemMiddle("BFBFBF"),
|
||||
GetColorItemMiddle("3F3F3F"),
|
||||
GetColorItemMiddle("938953"),
|
||||
GetColorItemMiddle("548DD4"),
|
||||
GetColorItemMiddle("95B3D7"),
|
||||
GetColorItemMiddle("D99694"),
|
||||
GetColorItemMiddle("C3D69B"),
|
||||
GetColorItemMiddle("B2A1C7"),
|
||||
GetColorItemMiddle("92CDDC"),
|
||||
GetColorItemMiddle("FAC08F")});
|
||||
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItemMiddle("A5A5A5"),
|
||||
GetColorItemMiddle("262626"),
|
||||
GetColorItemMiddle("494429"),
|
||||
GetColorItemMiddle("17365D"),
|
||||
GetColorItemMiddle("366092"),
|
||||
GetColorItemMiddle("953734"),
|
||||
GetColorItemMiddle("76923C"),
|
||||
GetColorItemMiddle("5F497A"),
|
||||
GetColorItemMiddle("31859B"),
|
||||
GetColorItemMiddle("E36C09")});
|
||||
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItemBottom("7F7F7F"),
|
||||
GetColorItemBottom("0C0C0C"),
|
||||
GetColorItemBottom("1D1B10"),
|
||||
GetColorItemBottom("0F243E"),
|
||||
GetColorItemBottom("244061"),
|
||||
GetColorItemBottom("632423"),
|
||||
GetColorItemBottom("4F6128"),
|
||||
GetColorItemBottom("3F3151"),
|
||||
GetColorItemBottom("205867"),
|
||||
GetColorItemBottom("974806")});
|
||||
}
|
||||
else
|
||||
{
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItem("FFFFFF"),
|
||||
GetColorItem("000000"),
|
||||
GetColorItem("FAF3E8"),
|
||||
GetColorItem("1F497D"),
|
||||
GetColorItem("5C83B4"),
|
||||
GetColorItem("C0504D"),
|
||||
GetColorItem("9DBB61"),
|
||||
GetColorItem("8066A0"),
|
||||
GetColorItem("4BACC6"),
|
||||
GetColorItem("F59D56")});
|
||||
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItemTop("D8D8D8"),
|
||||
GetColorItemTop("7F7F7F"),
|
||||
GetColorItemTop("BBB6AE"),
|
||||
GetColorItemTop("C7D1DE"),
|
||||
GetColorItemTop("D6E0EC"),
|
||||
GetColorItemTop("EFD3D2"),
|
||||
GetColorItemTop("E6EED7"),
|
||||
GetColorItemTop("DFD8E7"),
|
||||
GetColorItemTop("D2EAF0"),
|
||||
GetColorItemTop("FCE6D4")});
|
||||
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItemMiddle("BFBFBF"),
|
||||
GetColorItemMiddle("727272"),
|
||||
GetColorItemMiddle("A29D96"),
|
||||
GetColorItemMiddle("8FA4BE"),
|
||||
GetColorItemMiddle("ADC1D9"),
|
||||
GetColorItemMiddle("DFA7A6"),
|
||||
GetColorItemMiddle("CEDDB0"),
|
||||
GetColorItemMiddle("BFB2CF"),
|
||||
GetColorItemMiddle("A5D5E2"),
|
||||
GetColorItemMiddle("FACEAA")});
|
||||
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItemMiddle("A5A5A5"),
|
||||
GetColorItemMiddle("595959"),
|
||||
GetColorItemMiddle("7D7974"),
|
||||
GetColorItemMiddle("57769D"),
|
||||
GetColorItemMiddle("84A2C6"),
|
||||
GetColorItemMiddle("CF7B79"),
|
||||
GetColorItemMiddle("B5CC88"),
|
||||
GetColorItemMiddle("9F8CB7"),
|
||||
GetColorItemMiddle("78C0D4"),
|
||||
GetColorItemMiddle("F7B580")});
|
||||
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItemMiddle("8C8C8C"),
|
||||
GetColorItemMiddle("3F3F3F"),
|
||||
GetColorItemMiddle("575551"),
|
||||
GetColorItemMiddle("17365D"),
|
||||
GetColorItemMiddle("456287"),
|
||||
GetColorItemMiddle("903C39"),
|
||||
GetColorItemMiddle("758C48"),
|
||||
GetColorItemMiddle("604C78"),
|
||||
GetColorItemMiddle("388194"),
|
||||
GetColorItemMiddle("B77540")});
|
||||
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItemBottom("7F7F7F"),
|
||||
GetColorItemBottom("262626"),
|
||||
GetColorItemBottom("3E3C3A"),
|
||||
GetColorItemBottom("0F243E"),
|
||||
GetColorItemBottom("2E415A"),
|
||||
GetColorItemBottom("602826"),
|
||||
GetColorItemBottom("4E5D30"),
|
||||
GetColorItemBottom("403350"),
|
||||
GetColorItemBottom("255663"),
|
||||
GetColorItemBottom("7A4E2B")});
|
||||
}
|
||||
}
|
||||
#if FRAMEWORK20
|
||||
else
|
||||
colors.AddRange(_CustomThemeColors);
|
||||
#endif
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array that represents the standard colors. Usually instances of ColorItem are included.
|
||||
/// </summary>
|
||||
/// <returns>ArrayList containing objects that describe standard colors.</returns>
|
||||
protected virtual ArrayList GetStandardColors()
|
||||
{
|
||||
ArrayList colors = new ArrayList();
|
||||
#if FRAMEWORK20
|
||||
if (_CustomStandardColors == null || _CustomStandardColors.Length == 0)
|
||||
#endif
|
||||
{
|
||||
eDotNetBarStyle effectiveStyle = EffectiveStyle;
|
||||
if (effectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(effectiveStyle))
|
||||
{
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItem("C00000"),
|
||||
GetColorItem("FF0000"),
|
||||
GetColorItem("FFC000"),
|
||||
GetColorItem("FFFF00"),
|
||||
GetColorItem("92D050"),
|
||||
GetColorItem("00B050"),
|
||||
GetColorItem("00B0F0"),
|
||||
GetColorItem("0070C0"),
|
||||
GetColorItem("002060"),
|
||||
GetColorItem("7030A0")});
|
||||
}
|
||||
else
|
||||
{
|
||||
colors.Add(new ColorItem[] {
|
||||
GetColorItem("BA1419"),
|
||||
GetColorItem("ED1C24"),
|
||||
GetColorItem("FFC20E"),
|
||||
GetColorItem("FFF200"),
|
||||
GetColorItem("9DDA4E"),
|
||||
GetColorItem("22B14C"),
|
||||
GetColorItem("00B7EF"),
|
||||
GetColorItem("0072BC"),
|
||||
GetColorItem("2F3699"),
|
||||
GetColorItem("6F3198")});
|
||||
}
|
||||
}
|
||||
#if FRAMEWORK20
|
||||
else
|
||||
colors.AddRange(_CustomStandardColors);
|
||||
#endif
|
||||
|
||||
return colors;
|
||||
}
|
||||
#if FRAMEWORK20
|
||||
private ColorItem[][] _CustomStandardColors = null;
|
||||
/// <summary>
|
||||
/// Gets or sets the array of ColorItem objects that will be used as standard colors instead of built-in color palette.
|
||||
/// See: http://www.devcomponents.com/kb2/?p=79 for instructions.
|
||||
/// </summary>
|
||||
[DefaultValue(null), Category("Colors"), Description("Array of ColorItem objects that will be used as standard colors instead of built-in color palette.")]
|
||||
public ColorItem[][] CustomStandardColors
|
||||
{
|
||||
get { return _CustomStandardColors; }
|
||||
set
|
||||
{
|
||||
_CustomStandardColors = value;
|
||||
m_ColorsInitialized = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private ColorItem GetColorItem(string color)
|
||||
{
|
||||
ColorItem c = new ColorItem("", "", ColorScheme.GetColor(color));
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
private ColorItem GetColorItemTop(string color)
|
||||
{
|
||||
ColorItem c = new ColorItem("", "", ColorScheme.GetColor(color));
|
||||
eColorItemBorder border = eColorItemBorder.Top | eColorItemBorder.Left | eColorItemBorder.Right;
|
||||
c.Border = border;
|
||||
return c;
|
||||
}
|
||||
|
||||
private ColorItem GetColorItemMiddle(string color)
|
||||
{
|
||||
ColorItem c = new ColorItem("", "", ColorScheme.GetColor(color));
|
||||
eColorItemBorder border = eColorItemBorder.Left | eColorItemBorder.Right;
|
||||
c.Border = border;
|
||||
return c;
|
||||
}
|
||||
|
||||
private ColorItem GetColorItemBottom(string color)
|
||||
{
|
||||
ColorItem c = new ColorItem("", "", ColorScheme.GetColor(color));
|
||||
eColorItemBorder border = eColorItemBorder.Bottom | eColorItemBorder.Left | eColorItemBorder.Right;
|
||||
c.Border = border;
|
||||
return c;
|
||||
}
|
||||
|
||||
private void LoadResources()
|
||||
{
|
||||
if (!m_Localized)
|
||||
{
|
||||
if (this.GetOwner() != null)
|
||||
m_Localized = true;
|
||||
using (LocalizationManager lm = new LocalizationManager(this.GetOwner() as IOwnerLocalize))
|
||||
{
|
||||
string s = lm.GetLocalizedString(LocalizationKeys.ColorPickerThemeColorsLabel);
|
||||
if (s != "") m_ThemeColorsLabel = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerStandardColorsLabel);
|
||||
if (s != "") m_StandardColorsLabel = s;
|
||||
s = lm.GetLocalizedString(LocalizationKeys.ColorPickerMoreColorsMenuItem);
|
||||
if (s != "") m_MoreColorsLabel = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes SelectedColorChanged event.
|
||||
/// </summary>
|
||||
protected virtual void OnSelectedColorChanged(EventArgs e)
|
||||
{
|
||||
if (SelectedColorChanged != null)
|
||||
SelectedColorChanged(this, e);
|
||||
DotNetBarManager manager = this.GetOwner() as DotNetBarManager;
|
||||
if (manager != null)
|
||||
manager.InvokeColorPickerSelectedColorChanged(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether button should popup when clicked automatically.
|
||||
/// </summary>
|
||||
protected override bool ShouldAutoExpandOnClick
|
||||
{
|
||||
get { return base.ShouldAutoExpandOnClick || m_SelectedColor.IsEmpty; }
|
||||
}
|
||||
|
||||
protected override void OnCommandChanged()
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DevComponents.DotNetBar.ColorPickerItem
|
||||
{
|
||||
[ToolboxItem(false)]
|
||||
internal class ColorSelectionPreviewControl : System.Windows.Forms.UserControl
|
||||
{
|
||||
#region Private Variables
|
||||
private Color m_CurrentColor = Color.Black;
|
||||
private Color m_NewColor = Color.Empty;
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public ColorSelectionPreviewControl()
|
||||
{
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.SetStyle(ControlStyles.Opaque, true);
|
||||
this.SetStyle(DisplayHelp.DoubleBufferFlag, true);
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if(this.BackColor == Color.Transparent)
|
||||
{
|
||||
base.OnPaintBackground(e);
|
||||
}
|
||||
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
Rectangle r = this.ClientRectangle;
|
||||
|
||||
g.FillRectangle(SystemBrushes.Control, r);
|
||||
|
||||
if(!m_NewColor.IsEmpty)
|
||||
{
|
||||
using(SolidBrush brush = new SolidBrush(m_NewColor))
|
||||
g.FillRectangle(brush, r.X, r.Y, r.Width, r.Height / 2);
|
||||
}
|
||||
|
||||
if(!m_CurrentColor.IsEmpty)
|
||||
{
|
||||
using(SolidBrush brush = new SolidBrush(m_CurrentColor))
|
||||
g.FillRectangle(brush, r.X, r.Y + r.Height / 2, r.Width, r.Height / 2);
|
||||
}
|
||||
|
||||
using(Pen pen=new Pen(Color.Black))
|
||||
{
|
||||
r.Width--;
|
||||
r.Height--;
|
||||
g.DrawRectangle(pen, r);
|
||||
|
||||
g.DrawLine(pen, r.X, r.Y + r.Height / 2, r.Right, r.Y + r.Height / 2);
|
||||
}
|
||||
}
|
||||
|
||||
public Color NewColor
|
||||
{
|
||||
get { return m_NewColor;}
|
||||
set
|
||||
{
|
||||
m_NewColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public Color CurrentColor
|
||||
{
|
||||
get { return m_CurrentColor;}
|
||||
set
|
||||
{
|
||||
m_CurrentColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
100
PROMS/DotNetBar Source Code/ColorPickers/CombCell.cs
Normal file
100
PROMS/DotNetBar Source Code/ColorPickers/CombCell.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace DevComponents.DotNetBar.ColorPickers
|
||||
{
|
||||
internal class CombCell
|
||||
{
|
||||
#region Private Variables
|
||||
private Color m_Color = Color.Empty;
|
||||
private Point[] m_HexagonPoints=new Point[6];
|
||||
private const float Tan30 = 0.57735026918962F;
|
||||
private bool m_MouseOver = false;
|
||||
private bool m_Selected = false;
|
||||
private Rectangle m_Bounds = Rectangle.Empty;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public Color Color
|
||||
{
|
||||
get { return m_Color; }
|
||||
set { m_Color=value; }
|
||||
}
|
||||
|
||||
public void SetPosition(float x, float y, int nWidth)
|
||||
{
|
||||
float nSideLength = (float)((float)nWidth * Tan30);
|
||||
m_HexagonPoints[0] = new Point((int)Math.Floor(x - (float)(nWidth / 2)), (int)Math.Floor(y - (nSideLength / 2))-1);
|
||||
m_HexagonPoints[1] = new Point((int)Math.Floor((float)x), (int)Math.Floor(y - (float)(nWidth / 2))-1);
|
||||
m_HexagonPoints[2] = new Point((int)Math.Floor(x + (float)(nWidth / 2)), (int)Math.Floor(y - (nSideLength / 2))-1);
|
||||
m_HexagonPoints[3] = new Point((int)Math.Floor(x + (float)(nWidth / 2)), (int)Math.Floor(y + (nSideLength / 2)) + 1);
|
||||
m_HexagonPoints[4] = new Point((int)Math.Floor((float)x), (int)Math.Floor(y + (float)(nWidth / 2)) + 1);
|
||||
m_HexagonPoints[5] = new Point((int)Math.Floor(x - (float)(nWidth / 2)), (int)Math.Floor(y + (nSideLength / 2)) + 1);
|
||||
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
path.AddPolygon(m_HexagonPoints);
|
||||
m_Bounds = Rectangle.Round(path.GetBounds());
|
||||
m_Bounds.Inflate(2, 2);
|
||||
}
|
||||
|
||||
public void Draw(Graphics g)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
path.AddPolygon(m_HexagonPoints);
|
||||
path.CloseAllFigures();
|
||||
|
||||
using (SolidBrush brush = new SolidBrush(m_Color))
|
||||
{
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
|
||||
if (m_MouseOver || m_Selected)
|
||||
{
|
||||
SmoothingMode sm = g.SmoothingMode;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
using (Pen pen = new Pen(Color.FromArgb(41, 92, 150), 2))
|
||||
g.DrawPath(pen, path);
|
||||
using (Pen pen = new Pen(Color.FromArgb(149, 178, 239), 1))
|
||||
g.DrawPath(pen, path);
|
||||
g.SmoothingMode = sm;
|
||||
}
|
||||
|
||||
path.Dispose();
|
||||
}
|
||||
|
||||
public void Draw(Graphics g, Color c)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
path.AddPolygon(m_HexagonPoints);
|
||||
using (SolidBrush brush = new SolidBrush(c))
|
||||
{
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
path.Dispose();
|
||||
}
|
||||
|
||||
public Rectangle Bounds
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Bounds;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MouseOver
|
||||
{
|
||||
get { return m_MouseOver; }
|
||||
set { m_MouseOver = value; }
|
||||
}
|
||||
|
||||
public bool Selected
|
||||
{
|
||||
get { return m_Selected; }
|
||||
set { m_Selected = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
340
PROMS/DotNetBar Source Code/ColorPickers/CustomColorBlender.cs
Normal file
340
PROMS/DotNetBar Source Code/ColorPickers/CustomColorBlender.cs
Normal file
@@ -0,0 +1,340 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing.Imaging;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DevComponents.DotNetBar.ColorPickers
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents custom color blend selection control.
|
||||
/// </summary>
|
||||
[ToolboxItem(true), DefaultEvent("SelectedColorChanged"), DefaultProperty("SelectedColor"), ToolboxBitmap(typeof(CustomColorBlender), "ColorPickerItem.CustomColorBlender.ico")]
|
||||
public class CustomColorBlender : System.Windows.Forms.Control
|
||||
{
|
||||
#region Events
|
||||
/// <summary>
|
||||
/// Occurs when SelectedColor has changed.
|
||||
/// </summary>
|
||||
public event EventHandler SelectedColorChanged;
|
||||
/// <summary>
|
||||
/// Raises SelectedColorChanged event.
|
||||
/// </summary>
|
||||
/// <param name="e">Provides event arguments.</param>
|
||||
protected virtual void OnSelectedColorChanged(EventArgs e)
|
||||
{
|
||||
EventHandler handler = SelectedColorChanged;
|
||||
if (handler != null)
|
||||
handler(this, e);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
private Bitmap m_ColorBlendBitmap = null;
|
||||
private Point m_SelectedPoint = new Point(-1, -1);
|
||||
#endregion
|
||||
|
||||
#region Constructor, Dispose
|
||||
public CustomColorBlender()
|
||||
{
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.SetStyle(ControlStyles.Opaque, true);
|
||||
this.SetStyle(DisplayHelp.DoubleBufferFlag, true);
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (m_ColorBlendBitmap != null)
|
||||
{
|
||||
m_ColorBlendBitmap.Dispose();
|
||||
m_ColorBlendBitmap = null;
|
||||
}
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void CreateBlendBitmap()
|
||||
{
|
||||
int stripeCount = 6;
|
||||
Rectangle clientRect = this.ClientRectangle;
|
||||
|
||||
int stripeWidth = clientRect.Width / stripeCount;
|
||||
int ySteps=127;
|
||||
int xStart = clientRect.X;
|
||||
Bitmap bmp = new Bitmap(clientRect.Width, clientRect.Height, PixelFormat.Format24bppRgb);
|
||||
using (Graphics graph = Graphics.FromImage(bmp))
|
||||
{
|
||||
graph.FillRectangle(SystemBrushes.Control, clientRect);
|
||||
|
||||
for (int stripe = 0; stripe < stripeCount; stripe++)
|
||||
{
|
||||
// Calculate X steps and point Width
|
||||
int pointWidth = 4;
|
||||
int colorStepX = 255 / (stripeWidth / pointWidth);
|
||||
|
||||
if (colorStepX<1)
|
||||
{
|
||||
pointWidth = stripeWidth / 255;
|
||||
colorStepX = 1;
|
||||
}
|
||||
|
||||
int pointHeight = 4;
|
||||
int colorStepY = ySteps / (clientRect.Height / pointHeight);
|
||||
|
||||
if (colorStepY<1)
|
||||
{
|
||||
pointHeight = clientRect.Height / ySteps;
|
||||
colorStepY = 1;
|
||||
}
|
||||
|
||||
int x = xStart;
|
||||
int y = clientRect.Y;
|
||||
int r = 0, g = 0, b = 0;
|
||||
int rXInc = 0, gXInc = 0, bXInc = 0;
|
||||
int rYInc = 0, gYInc = 0, bYInc = 0;
|
||||
|
||||
if (stripe == 0)
|
||||
{
|
||||
r = 255;
|
||||
g = 0;
|
||||
b = 0;
|
||||
gXInc = colorStepX;
|
||||
}
|
||||
else if (stripe == 1)
|
||||
{
|
||||
r = 255;
|
||||
g = 255;
|
||||
b = 0;
|
||||
rXInc = - colorStepX;
|
||||
}
|
||||
else if (stripe == 2)
|
||||
{
|
||||
r = 0;
|
||||
g = 255;
|
||||
b = 0;
|
||||
bXInc = colorStepX;
|
||||
}
|
||||
else if (stripe == 3)
|
||||
{
|
||||
r = 0;
|
||||
g = 255;
|
||||
b = 255;
|
||||
gXInc = -colorStepX;
|
||||
}
|
||||
else if (stripe == 4)
|
||||
{
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 255;
|
||||
rXInc = colorStepX;
|
||||
}
|
||||
else if (stripe == 5)
|
||||
{
|
||||
r = 255;
|
||||
g = 0;
|
||||
b = 255;
|
||||
bXInc = -colorStepX;
|
||||
}
|
||||
|
||||
for (int i = 0; i < stripeWidth; i += pointWidth)
|
||||
{
|
||||
int ry = r, gy = g, by = b;
|
||||
rYInc = 127-r;
|
||||
gYInc = 127-g;
|
||||
bYInc = 127-b;
|
||||
|
||||
for (int j = clientRect.Y; j < clientRect.Height; j += pointHeight)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(Color.FromArgb(ry, gy, by)))
|
||||
graph.FillRectangle(brush, new Rectangle(x, y, pointWidth, pointHeight));
|
||||
y += pointHeight;
|
||||
|
||||
ry = r + (int)(rYInc * ((float)j / (float)clientRect.Height));
|
||||
gy = g + (int)(gYInc * ((float)j / (float)clientRect.Height));
|
||||
by = b + (int)(bYInc * ((float)j / (float)clientRect.Height));
|
||||
}
|
||||
|
||||
x += pointWidth;
|
||||
y = clientRect.Y;
|
||||
r += rXInc;
|
||||
g += gXInc;
|
||||
b += bXInc;
|
||||
|
||||
}
|
||||
xStart = x;
|
||||
if (stripe == 5)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_ColorBlendBitmap != null)
|
||||
m_ColorBlendBitmap.Dispose();
|
||||
m_ColorBlendBitmap = bmp;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
if (!this.BackColor.IsEmpty && this.BackColor != Color.Transparent)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(this.BackColor))
|
||||
g.FillRectangle(brush, -1, -1, this.Width + 1, this.Height + 1);
|
||||
}
|
||||
|
||||
if (this.BackColor == Color.Transparent || this.BackgroundImage != null)
|
||||
{
|
||||
base.OnPaintBackground(e);
|
||||
}
|
||||
|
||||
if (m_ColorBlendBitmap == null) return;
|
||||
|
||||
g.DrawImageUnscaled(m_ColorBlendBitmap, 0, 0);
|
||||
|
||||
if (m_SelectedPoint.X >= 0 && m_SelectedPoint.Y >= 0)
|
||||
{
|
||||
Color clr = Color.White;
|
||||
using (SolidBrush brush = new SolidBrush(clr))
|
||||
{
|
||||
Rectangle r = new Rectangle(m_SelectedPoint.X - 2, m_SelectedPoint.Y - 9, 3, 5);
|
||||
g.FillRectangle(brush, r);
|
||||
r.Offset(0, 10);
|
||||
g.FillRectangle(brush, r);
|
||||
r = new Rectangle(m_SelectedPoint.X - 8, m_SelectedPoint.Y - 3, 5, 3);
|
||||
g.FillRectangle(brush, r);
|
||||
r.Offset(10, 0);
|
||||
g.FillRectangle(brush, r);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
base.OnPaint(e);
|
||||
}
|
||||
|
||||
private void SetSelectedPoint(Point p)
|
||||
{
|
||||
Rectangle r = this.ClientRectangle;
|
||||
|
||||
if (m_ColorBlendBitmap != null)
|
||||
{
|
||||
r.Width = m_ColorBlendBitmap.Width;
|
||||
r.Height = m_ColorBlendBitmap.Height;
|
||||
}
|
||||
|
||||
if (p.X < 0)
|
||||
p.X = 0;
|
||||
if (p.Y < 0)
|
||||
p.Y = 0;
|
||||
if (p.X > r.Right)
|
||||
p.X = r.Right - 1;
|
||||
if (p.Y > r.Bottom)
|
||||
p.Y = r.Bottom - 1;
|
||||
|
||||
if (p != m_SelectedPoint)
|
||||
{
|
||||
if (m_SelectedPoint.X >= 0 && m_SelectedPoint.Y >= 0)
|
||||
{
|
||||
Rectangle inv = new Rectangle(m_SelectedPoint, Size.Empty);
|
||||
inv.Inflate(10, 10);
|
||||
this.Invalidate(inv);
|
||||
}
|
||||
m_SelectedPoint = p;
|
||||
if (m_SelectedPoint.X >= 0 && m_SelectedPoint.Y >= 0)
|
||||
{
|
||||
Rectangle inv = new Rectangle(m_SelectedPoint, Size.Empty);
|
||||
inv.Inflate(10, 10);
|
||||
this.Invalidate(inv);
|
||||
}
|
||||
OnSelectedColorChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
SetSelectedPoint(new Point(e.X, e.Y));
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
int x = e.X;
|
||||
int y = e.Y;
|
||||
if(x<0)
|
||||
x = 0;
|
||||
if(x>=this.ClientRectangle.Width)
|
||||
x = this.ClientRectangle.Width - 1;
|
||||
if(y<0)
|
||||
y = 0;
|
||||
if(y>=this.ClientRectangle.Height)
|
||||
y = this.ClientRectangle.Height - 1;
|
||||
SetSelectedPoint(new Point(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
CreateBlendBitmap();
|
||||
base.OnResize(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color selected by the control. Color that is assigned must be visible on the face of the control otherwise the SelectedColor will be set to Color.Empty
|
||||
/// </summary>
|
||||
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public Color SelectedColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_SelectedPoint.X < 0 || m_SelectedPoint.Y < 0 || m_ColorBlendBitmap==null)
|
||||
return Color.Empty;
|
||||
return m_ColorBlendBitmap.GetPixel(m_SelectedPoint.X, m_SelectedPoint.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value.Equals(Color.Transparent) || value.IsEmpty)
|
||||
{
|
||||
if (!m_SelectedPoint.IsEmpty)
|
||||
{
|
||||
m_SelectedPoint = new Point(-1, -1);
|
||||
this.Invalidate();
|
||||
OnSelectedColorChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Point colorPoint = FindColorPoint(value);
|
||||
if (m_SelectedPoint != colorPoint)
|
||||
{
|
||||
m_SelectedPoint = colorPoint;
|
||||
this.Invalidate();
|
||||
OnSelectedColorChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private Point FindColorPoint(Color value)
|
||||
{
|
||||
if (m_ColorBlendBitmap == null || value.IsEmpty || value == Color.Transparent) return new Point(-1, -1);
|
||||
for (int x = 0; x < m_ColorBlendBitmap.Width; x++)
|
||||
{
|
||||
for (int y = 0; y < m_ColorBlendBitmap.Height; y++)
|
||||
{
|
||||
Color color = m_ColorBlendBitmap.GetPixel(x, y);
|
||||
if (Math.Abs(color.R-value.R)<=30 && Math.Abs(color.G-value.G)<=30 && Math.Abs(color.B-value.B)<=30)
|
||||
return new Point(x, y);
|
||||
}
|
||||
}
|
||||
return new Point(-1, -1);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
BIN
PROMS/DotNetBar Source Code/ColorPickers/CustomColorBlender.ico
Normal file
BIN
PROMS/DotNetBar Source Code/ColorPickers/CustomColorBlender.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
1079
PROMS/DotNetBar Source Code/ColorPickers/CustomColorDialog.cs
Normal file
1079
PROMS/DotNetBar Source Code/ColorPickers/CustomColorDialog.cs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user