form.Text = "Color";
- form.Size = new Size (221, 332); // 300
-
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.MaximizeBox = false;
defineColoursButton.Location = new Point (5, 244);
defineColoursButton.Size = new Size (210, 22);
defineColoursButton.TabIndex = 6;
- defineColoursButton.Text = Locale.GetText ("Define Colours >>");
+ // FIXME: update resource files
+ defineColoursButton.Text = "Define Custom Colors >>";
+ //defineColoursButton.Text = Locale.GetText ("Define Custom Colors >>");
// okButton
okButton.FlatStyle = FlatStyle.System;
okButton.Location = new Point (5, 271);
addColoursButton.Location = new Point (227, 271);
addColoursButton.Size = new Size (213, 22);
addColoursButton.TabIndex = 7;
- addColoursButton.Text = Locale.GetText ("Add Colours");
+ // FIXME: update resource files
+ addColoursButton.Text = "Add To Custom Colors";
+ //addColoursButton.Text = Locale.GetText ("Add To Custom Colors");
// baseColorControl
baseColorControl.Location = new Point (3, 6);
redTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
greenTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
blueTextBox.KeyPress += new KeyPressEventHandler (OnKeyPressTextBoxes);
+
+ hueTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
+ satTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
+ briTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
+ redTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
+ greenTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
+ blueTextBox.TextChanged += new EventHandler (OnTextChangedTextBoxes);
+
+ hueTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
+ satTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
+ briTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
+ redTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
+ greenTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
+ blueTextBox.GotFocus += new EventHandler (OnGotFocusTextBoxes);
+
+ hueTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
+ satTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
+ briTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
+ redTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
+ greenTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
+ blueTextBox.LostFocus += new EventHandler (OnLostFocusTextBoxes);
+
+ ResetCustomColors ();
}
#endregion // Public Constructors
}
set {
- if (color != value) {
+ if (value.IsEmpty) {
+ color = Color.Black;
+ baseColorControl.SetColor (color);
+ } else if (color != value) {
color = value;
-
baseColorControl.SetColor (color);
}
}
if (fullOpen && allowFullOpen) {
defineColoursButton.Enabled = false;
-
colorMatrixControl.ColorToShow = baseColorControl.ColorToShow;
-
- form.Size = new Size (448, 332);
+ form.Size = GetFormSize (true);
} else {
if (allowFullOpen)
defineColoursButton.Enabled = true;
-
- form.Size = new Size (221, 332); // 300
+ form.Size = GetFormSize (false);
}
}
}
}
set {
- if (allowFullOpen) {
- customColors = value;
+ if (value == null)
+ ResetCustomColors ();
+ else {
+ int[] tmp_colors = value;
- baseColorControl.SetCustomColors ();
+ Array.Copy (tmp_colors, customColors, tmp_colors.Length);
}
+
+ baseColorControl.SetCustomColors ();
}
}
public override string ToString ()
{
- return base.ToString () + ", Color: " + Color.ToString ();
+ return base.ToString () + ", Color: " + Color.ToString ();
}
#endregion // Public Instance Methods
#region Protected Instance Methods
protected override bool RunDialog (IntPtr hwndOwner)
{
+ defineColoursButton.Enabled = (AllowFullOpen && !FullOpen);
+ defineColoursButton.Refresh ();
+
+ form.Size = GetFormSize (FullOpen && AllowFullOpen);
// currently needed, otherwise there are a lot of drawing artefacts/transparent controls if the same dialog gets opened again
form.Refresh ();
}
#endregion // Protected Instance Methods
- #region Private Methods
+ #region Private Methods
+
+ Size GetFormSize (bool fullOpen)
+ {
+ if (fullOpen)
+ return new Size (448, 332);
+ else
+ return new Size (221, 332); // 300
+ }
+
void OnClickCancelButton (object sender, EventArgs e)
{
form.DialogResult = DialogResult.Cancel;
{
if (allowFullOpen) {
defineColoursButton.Enabled = false;
-
colorMatrixControl.ColorToShow = baseColorControl.ColorToShow;
-
- form.Size = new Size (448, 332);
+ form.Size = GetFormSize (true);
}
}
OnHelpRequest (e);
}
- // not working 100 %, S.W.F.TextBox isn't finished yet
+ string textBox_text_old = "";
+
+ void OnGotFocusTextBoxes (object sender, EventArgs e)
+ {
+ TextBox textbox = sender as TextBox;
+ textBox_text_old = textbox.Text;
+ }
+
+ void OnLostFocusTextBoxes (object sender, EventArgs e)
+ {
+ TextBox textbox = sender as TextBox;
+
+ if (textbox.Text.Length == 0)
+ textbox.Text = textBox_text_old;
+ }
+
void OnKeyPressTextBoxes (object sender, KeyPressEventArgs e)
{
- if (Char.IsLetter (e.KeyChar) || Char.IsWhiteSpace (e.KeyChar) || Char.IsPunctuation (e.KeyChar)) {
+ if (Char.IsLetter (e.KeyChar) || Char.IsWhiteSpace (e.KeyChar) || Char.IsPunctuation (e.KeyChar) || e.KeyChar == ',') {
e.Handled = true;
return;
}
- TextChangedTextBoxes (sender);
+ internal_textbox_change = true;
}
- // not working 100 %, S.W.F.TextBox isn't finished yet
- // setting TextBox.Maxlength gives us weird results
- void TextChangedTextBoxes (object sender)
+ internal TextBox edit_textbox = null;
+ bool internal_textbox_change = false;
+
+ void OnTextChangedTextBoxes (object sender, EventArgs e)
{
+ if (!internal_textbox_change)
+ return;
+
+ internal_textbox_change = false;
+
TextBox tmp_box = sender as TextBox;
if (tmp_box.Text.Length == 0)
return;
- int val;
+ string text = tmp_box.Text;
+
+ int val = 0;
+
+ try {
+ val = System.Convert.ToInt32 (text);
+ } catch (Exception) {
+ // bla
+ }
if (sender == hueTextBox) {
- val = System.Convert.ToInt32 (hueTextBox.Text);
-
- if (val > 240) {
- val = 240;
+ if (val > 239) {
+ val = 239;
hueTextBox.Text = val.ToString ();
} else
if (val < 0) {
hueTextBox.Text = val.ToString ();
}
+ edit_textbox = hueTextBox;
+
UpdateFromHSBTextBoxes ();
UpdateControls (selectedColorPanel.BackColor);
} else
if (sender == satTextBox) {
- val = System.Convert.ToInt32 (satTextBox.Text);
-
- if (val > 239) {
- val = 239;
+ if (val > 240) {
+ val = 240;
satTextBox.Text = val.ToString ();
} else
if (val < 0) {
satTextBox.Text = val.ToString ();
}
+ edit_textbox = satTextBox;
+
UpdateFromHSBTextBoxes ();
UpdateControls (selectedColorPanel.BackColor);
} else
if (sender == briTextBox) {
- val = System.Convert.ToInt32 (briTextBox.Text);
-
- if (val > 239) {
- val = 239;
+ if (val > 240) {
+ val = 240;
briTextBox.Text = val.ToString ();
} else
if (val < 0) {
briTextBox.Text = val.ToString ();
}
+ edit_textbox = briTextBox;
+
UpdateFromHSBTextBoxes ();
UpdateControls (selectedColorPanel.BackColor);
} else
if (sender == redTextBox) {
- val = System.Convert.ToInt32 (redTextBox.Text);
-
if (val > 255) {
val = 255;
redTextBox.Text = val.ToString ();
redTextBox.Text = val.ToString ();
}
+ edit_textbox = redTextBox;
+
UpdateFromRGBTextBoxes ();
} else
if (sender == greenTextBox) {
- val = System.Convert.ToInt32 (greenTextBox.Text);
-
if (val > 255) {
val = 255;
greenTextBox.Text = val.ToString ();
greenTextBox.Text = val.ToString ();
}
+ edit_textbox = greenTextBox;
+
UpdateFromRGBTextBoxes ();
} else
if (sender == blueTextBox) {
- val = System.Convert.ToInt32 (blueTextBox.Text);
-
if (val > 255) {
val = 255;
blueTextBox.Text = val.ToString ();
blueTextBox.Text = val.ToString ();
}
+ edit_textbox = blueTextBox;
+
UpdateFromRGBTextBoxes ();
}
+
+ textBox_text_old = edit_textbox.Text;
+
+ edit_textbox = null;
}
internal void UpdateControls (Color acolor)
internal void UpdateRGBTextBoxes (Color acolor)
{
- redTextBox.Text = acolor.R.ToString ();
- greenTextBox.Text = acolor.G.ToString ();
- blueTextBox.Text = acolor.B.ToString ();
+ if (edit_textbox != redTextBox)
+ redTextBox.Text = acolor.R.ToString ();
+ if (edit_textbox != greenTextBox)
+ greenTextBox.Text = acolor.G.ToString ();
+ if (edit_textbox != blueTextBox)
+ blueTextBox.Text = acolor.B.ToString ();
}
internal void UpdateHSBTextBoxes (Color acolor)
{
HSB hsb = HSB.RGB2HSB (acolor);
- hueTextBox.Text = hsb.hue.ToString ();
- satTextBox.Text = hsb.sat.ToString ();
- briTextBox.Text = hsb.bri.ToString ();
+ if (edit_textbox != hueTextBox)
+ hueTextBox.Text = hsb.hue.ToString ();
+ if (edit_textbox != satTextBox)
+ satTextBox.Text = hsb.sat.ToString ();
+ if (edit_textbox != briTextBox)
+ briTextBox.Text = hsb.bri.ToString ();
}
internal void UpdateFromHSBTextBoxes ()
UpdateHSBTextBoxes (col);
- UpdateFromHSBTextBoxes ();
-
UpdateControls (col);
}
+
+ void ResetCustomColors ()
+ {
+ // check if this.customColors already exists
+ if (customColors == null)
+ customColors = new int [16];
+
+ int default_color = Color.FromArgb(0, 255, 255, 255).ToArgb ();
+
+ for (int i = 0; i < customColors.Length; i++)
+ customColors [i] = default_color;
+ }
#endregion
#region Internal structs and classes
{
HSB hsb = new HSB ();
- hsb.hue = (int)((color.GetHue () / 360.0f) * 241);
+ hsb.hue = (int)((color.GetHue () / 360.0f) * 240);
hsb.sat = (int)(color.GetSaturation () * 241);
- hsb.bri = (int)(color.GetBrightness () * 240);
+ hsb.bri = (int)(color.GetBrightness () * 241);
- if (hsb.hue > 240) hsb.hue = 240;
+ if (hsb.hue > 239) hsb.hue = 239;
if (hsb.sat > 240) hsb.sat = 240;
- if (hsb.bri > 239) hsb.bri = 239;
+ if (hsb.bri > 240) hsb.bri = 240;
return hsb;
}
// not using ControlPaint HBS2Color, this algo is more precise
public static Color HSB2RGB (int hue, int saturation, int brightness)
{
- if (hue > 240)
- hue = 240;
+ if (hue > 239)
+ hue = 239;
else
if (hue < 0)
hue = 0;
if (saturation < 0)
saturation = 0;
- if (brightness > 239)
- brightness = 239;
+ if (brightness > 240)
+ brightness = 240;
else
if (brightness < 0)
brightness = 0;
- float H = hue / 240.0f;
+ float H = hue / 239.0f;
float S = saturation / 240.0f;
- float L = brightness / 239.0f;
+ float L = brightness / 240.0f;
float r = 0, g = 0, b = 0;
float d1, d2;
public static int Brightness (Color color)
{
- return (int)(color.GetBrightness () * 240);
+ return (int)(color.GetBrightness () * 241);
}
public static void GetHueSaturation (Color color, out int hue, out int sat)
{
- hue = (int)((color.GetHue () / 360.0f) * 241);
+ hue = (int)((color.GetHue () / 360.0f) * 240);
sat = (int)(color.GetSaturation () * 241);
}
private SmallColorControl selectedSmallColorControl;
private int currentlyUsedUserSmallColorControl = 0;
- private int[] customColors = null;
private ColorDialog colorDialog = null;
baseColorLabel.Location = new Point (2, 0);
baseColorLabel.Size = new Size (200, 12);
baseColorLabel.TabIndex = 5;
- baseColorLabel.Text = Locale.GetText ("Base Colours") + ":";
+ baseColorLabel.Text = Locale.GetText ("Base Colors") + ":";
// userColorLabel
userColorLabel.FlatStyle = FlatStyle.System;
userColorLabel.Location = new Point (2, 164);
{
userSmallColorControl [currentlyUsedUserSmallColorControl].InternalColor = col;
- // check if this.customColors already exists
- if (customColors == null) {
- customColors = new int [16];
- int white = Color.White.ToArgb ();
-
- for (int i = 0; i < customColors.Length; i++)
- customColors [i] = white;
- }
-
- customColors [currentlyUsedUserSmallColorControl] = col.ToArgb ();
-
- // update ColorDialog dialog property
- colorDialog.CustomColors = customColors;
+ colorDialog.customColors [currentlyUsedUserSmallColorControl] = col.ToArgb ();
currentlyUsedUserSmallColorControl++;
if (currentlyUsedUserSmallColorControl > 15)
public void SetCustomColors ()
{
- int[] customColors = colorDialog.CustomColors;
-
- if (customColors != null) {
- for (int i = 0; i < customColors.Length; i++) {
- userSmallColorControl [i].InternalColor = Color.FromArgb (customColors [i]);
- }
- } else {
- for (int i = 0; i < userSmallColorControl.Length; i++) {
- userSmallColorControl [i].InternalColor = Color.White;
- }
+ for (int i = 0; i < colorDialog.customColors.Length; i++) {
+ userSmallColorControl [i].InternalColor = Color.FromArgb (colorDialog.customColors [i]);
}
}
}
{
bitmap = new Bitmap (size.Width, size.Height);
- float hueadd = 241.0f / (size.Width - 1);
+ float hueadd = 240.0f / (size.Width - 1);
float satsub = 241.0f / (size.Height - 1);
float satpos = 240.0f;
ResumeLayout (false);
- xstep = 241.0f / (ClientSize.Width - 1);
+ xstep = 240.0f / (ClientSize.Width - 1);
ystep = 241.0f / (ClientSize.Height - 1);
SetStyle (ControlStyles.DoubleBuffer, true);
}
UpdateControls ();
+ XplatUI.GrabWindow (Handle, Handle);
base.OnMouseDown (e);
}
protected override void OnMouseUp (MouseEventArgs e)
{
+ XplatUI.UngrabWindow (Handle);
mouseButtonDown = false;
drawCross = true;
Invalidate ();
colorDialog.satTextBox.Text = satvalue.ToString ();
// update hue text box
- colorDialog.hueTextBox.Text = ((int)((float)currentXPos * xstep)).ToString ();
+ int huevalue = (int)((float)currentXPos * xstep);
+ if (huevalue > 239)
+ huevalue = 239;
+ colorDialog.hueTextBox.Text = huevalue.ToString ();
// update the main selected color panel
colorDialog.selectedColorPanel.BackColor = tmpColor;
// color will be computed with an iteration
public void Draw (int hue, int sat)
{
- float brisub = 240.0f / 190.0f;
- float bri = 240.0f;
+ float brisub = 241.0f / 190.0f;
+ float bri = 241.0f;
for (int height = 0; height < 190; height++) {
for (int width = 0; width < 14; width++) {
}
}
- private const float step = 240.0f/189.0f;
+ private const float step = 241.0f/189.0f;
private DrawingBitmap bitmap;
private int currentTrianglePosition = 195;
// private Rectangle clipRectangle;
- private const float briStep = 239.0f/186.0f;
+ private const float briStep = 241.0f/186.0f;
private static int currentBrightness = 0;
float tmp = (float)(currentTrianglePosition - 9);
tmp = tmp * briStep;
- int retval = 239 - (int)tmp;
+ int retval = 240 - (int)tmp;
TriangleControl.CurrentBrightness = retval;
float tmp = (float)pos_raw / briStep;
currentTrianglePosition = 186 - (int)tmp + 9;
- colorDialog.briTextBox.Text = TrianglePosition.ToString ();
+ if (colorDialog.edit_textbox == null)
+ colorDialog.briTextBox.Text = TrianglePosition.ToString ();
Invalidate ();
}