-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ColorSampleBox and ColorPicker controls.
- Loading branch information
Pavel Kovalenko
committed
Oct 18, 2014
1 parent
bc0bd11
commit 145a7ba
Showing
8 changed files
with
864 additions
and
0 deletions.
There are no files selected for viewing
315 changes: 315 additions & 0 deletions
315
src/editors/xrSdkControls/Controls/ColorPicker/ColorPicker.Designer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
src/editors/xrSdkControls/Controls/ColorPicker/ColorPicker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
|
||
namespace XRay.SdkControls | ||
{ | ||
// XXX nitrocaster: implement hex color TextBox (NumericBox) | ||
public sealed partial class ColorPicker : UserControl | ||
{ | ||
public delegate void ColorChangedEventHandler(object sender, Color color); | ||
|
||
private Color color; | ||
private bool hexademical; | ||
|
||
public ColorPicker() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public event ColorChangedEventHandler ColorChanged; | ||
|
||
public Color Value | ||
{ | ||
get { return color; } | ||
set | ||
{ | ||
color = value; | ||
UpdateColor(); | ||
} | ||
} | ||
|
||
public byte Red { get; private set; } | ||
public byte Green { get; private set; } | ||
public byte Blue { get; private set; } | ||
public byte Alpha { get; private set; } | ||
|
||
public bool Hexademical | ||
{ | ||
get { return hexademical; } | ||
set | ||
{ | ||
if (hexademical == value) | ||
return; | ||
hexademical = value; | ||
chkHexademical.Checked = value; | ||
numRed.Hexadecimal = value; | ||
numGreen.Hexadecimal = value; | ||
numBlue.Hexadecimal = value; | ||
numAlpha.Hexadecimal = value; | ||
} | ||
} | ||
|
||
private void ColorPicker_Load(object sender, EventArgs e) | ||
{ | ||
numRed.ValueChanged += (obj, args) => SyncValues(tbrRed, numRed); | ||
numGreen.ValueChanged += (obj, args) => SyncValues(tbrGreen, numGreen); | ||
numBlue.ValueChanged += (obj, args) => SyncValues(tbrBlue, numBlue); | ||
numAlpha.ValueChanged += (obj, args) => SyncValues(tbrAlpha, numAlpha); | ||
tbrRed.ValueChanged += (obj, args) => SyncValues(numRed, tbrRed); | ||
tbrGreen.ValueChanged += (obj, args) => SyncValues(numGreen, tbrGreen); | ||
tbrBlue.ValueChanged += (obj, args) => SyncValues(numBlue, tbrBlue); | ||
tbrAlpha.ValueChanged += (obj, args) => SyncValues(numAlpha, tbrAlpha); | ||
chkHexademical.CheckedChanged += (obj, args) => Hexademical = chkHexademical.Checked; | ||
UpdateColor(); | ||
} | ||
|
||
private void SyncValues(TrackBar tbr, IntegerUpDown num) | ||
{ | ||
if (tbr.Value == num.Value) | ||
return; | ||
tbr.Value = num.Value; | ||
UpdateColor(); | ||
} | ||
|
||
private void SyncValues(IntegerUpDown num, TrackBar tbr) | ||
{ | ||
if (num.Value == tbr.Value) | ||
return; | ||
num.Value = tbr.Value; | ||
UpdateColor(); | ||
} | ||
|
||
private void UpdateColor() | ||
{ | ||
var newColor = Color.FromArgb(tbrAlpha.Value, tbrRed.Value, tbrGreen.Value, tbrBlue.Value); | ||
if (pbColor.ColorSample == newColor) | ||
return; | ||
pbColor.ColorSample = newColor; | ||
if (ColorChanged != null) | ||
ColorChanged(this, Value); | ||
} | ||
} | ||
} |
171 changes: 171 additions & 0 deletions
171
src/editors/xrSdkControls/Controls/ColorPicker/ColorPicker.resx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<!-- | ||
Microsoft ResX Schema | ||
Version 2.0 | ||
The primary goals of this format is to allow a simple XML format | ||
that is mostly human readable. The generation and parsing of the | ||
various data types are done through the TypeConverter classes | ||
associated with the data types. | ||
Example: | ||
... ado.net/XML headers & schema ... | ||
<resheader name="resmimetype">text/microsoft-resx</resheader> | ||
<resheader name="version">2.0</resheader> | ||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> | ||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> | ||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> | ||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> | ||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> | ||
<value>[base64 mime encoded serialized .NET Framework object]</value> | ||
</data> | ||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> | ||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> | ||
<comment>This is a comment</comment> | ||
</data> | ||
There are any number of "resheader" rows that contain simple | ||
name/value pairs. | ||
Each data row contains a name, and value. The row also contains a | ||
type or mimetype. Type corresponds to a .NET class that support | ||
text/value conversion through the TypeConverter architecture. | ||
Classes that don't support this are serialized and stored with the | ||
mimetype set. | ||
The mimetype is used for serialized objects, and tells the | ||
ResXResourceReader how to depersist the object. This is currently not | ||
extensible. For a given mimetype the value must be set accordingly: | ||
Note - application/x-microsoft.net.object.binary.base64 is the format | ||
that the ResXResourceWriter will generate, however the reader can | ||
read any of the formats listed below. | ||
mimetype: application/x-microsoft.net.object.binary.base64 | ||
value : The object must be serialized with | ||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter | ||
: and then encoded with base64 encoding. | ||
mimetype: application/x-microsoft.net.object.soap.base64 | ||
value : The object must be serialized with | ||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter | ||
: and then encoded with base64 encoding. | ||
mimetype: application/x-microsoft.net.object.bytearray.base64 | ||
value : The object must be serialized into a byte array | ||
: using a System.ComponentModel.TypeConverter | ||
: and then encoded with base64 encoding. | ||
--> | ||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | ||
<xsd:element name="root" msdata:IsDataSet="true"> | ||
<xsd:complexType> | ||
<xsd:choice maxOccurs="unbounded"> | ||
<xsd:element name="metadata"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" use="required" type="xsd:string" /> | ||
<xsd:attribute name="type" type="xsd:string" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="assembly"> | ||
<xsd:complexType> | ||
<xsd:attribute name="alias" type="xsd:string" /> | ||
<xsd:attribute name="name" type="xsd:string" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="data"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | ||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="resheader"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:choice> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:schema> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>2.0</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<metadata name="tbrRed.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="tbrGreen.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="tbrAlpha.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="tbrBlue.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="lRed.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="lGreen.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="lBlue.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="lAlpha.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="chkHexademical.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="tbHexColor.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="lHexColor.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="pbColor.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="numAlpha.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="numBlue.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="numGreen.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="numRed.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<value>True</value> | ||
</metadata> | ||
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Drawing.Drawing2D; | ||
using System.Windows.Forms; | ||
|
||
namespace XRay.SdkControls | ||
{ | ||
public class ColorSampleBox : UserControl | ||
{ | ||
private Color color; | ||
|
||
public ColorSampleBox() | ||
{ | ||
base.BackgroundImage = Properties.Resources.Background; | ||
base.BackgroundImageLayout = ImageLayout.Tile; | ||
} | ||
|
||
public Color ColorSample | ||
{ | ||
get { return color; } | ||
set | ||
{ | ||
if (color == value) | ||
return; | ||
color = value; | ||
Invalidate(); | ||
} | ||
} | ||
|
||
protected override CreateParams CreateParams | ||
{ | ||
get | ||
{ | ||
var cp = base.CreateParams; | ||
cp.ExStyle |= 0x02000000; // set WS_EX_COMPOSITED | ||
return cp; | ||
} | ||
} | ||
|
||
public override Image BackgroundImage | ||
{ | ||
get { return base.BackgroundImage; } | ||
set { } | ||
} | ||
|
||
public override ImageLayout BackgroundImageLayout | ||
{ | ||
get { return base.BackgroundImageLayout; } | ||
set { } | ||
} | ||
|
||
protected override void OnPaint(PaintEventArgs e) | ||
{ | ||
using (var backBrush = new SolidBrush(color)) | ||
{ | ||
e.Graphics.CompositingMode = CompositingMode.SourceOver; | ||
e.Graphics.FillRectangle(backBrush, ClientRectangle); | ||
} | ||
base.OnPaint(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.