HSLDialog.cs

Description du code

HSLDialog.cs est un fichier du projet BrolDev.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.

Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.

Code source ou contenu du fichier

  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Imaging;
  4. using System.Windows.Forms;
  5. using be.gaudry.model.drawing.colors.converter;
  6.  
  7.  
  8. namespace be.gaudry.view.dialogs
  9. {
  10. public partial class HSLDialog : Form
  11. {
  12. private Bitmap hue;
  13. private Bitmap saturation;
  14. private Bitmap luminance;
  15. private Bitmap RGB;
  16. private bool keyIsDown = false;
  17. private byte red, green, blue;
  18. private int initialHue = 180, initialSat = 50, initialLum = 50;
  19.  
  20. public HSLDialog()
  21. {
  22. InitializeComponent();
  23. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw |
  24. ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);
  25.  
  26. hue = new Bitmap(huePicBox.Width, huePicBox.Height, PixelFormat.Format24bppRgb);
  27. saturation = new Bitmap(satPicBox.Width, satPicBox.Height, PixelFormat.Format24bppRgb);
  28. luminance = new Bitmap(lumPicBox.Width, lumPicBox.Height, PixelFormat.Format24bppRgb);
  29. RGB = new Bitmap(RGBPicBox.Width, RGBPicBox.Height, PixelFormat.Format24bppRgb);
  30.  
  31. initBars();
  32. }
  33.  
  34. private void initBars()
  35. {
  36.  
  37. hueSlider.Value = initialHue;
  38. hueText.Text = initialHue.ToString();
  39. satSlider.Value = initialSat;
  40. satText.Text = initialSat.ToString();
  41. lumSlider.Value = initialLum;
  42. lumText.Text = initialLum.ToString();
  43.  
  44. Graphics gr = Graphics.FromImage(hue);
  45.  
  46. for (int i = 0; i < 360; ++i)
  47. {
  48. HSL hsl = new HSL(i, .5f, .5f);
  49. gr.DrawLine(new Pen(hsl.Color), i, 0, i, huePicBox.Height);
  50. }
  51.  
  52. huePicBox.Image = hue;
  53.  
  54. drawBars();
  55. }
  56.  
  57. private void drawBars()
  58. {
  59. Graphics g = Graphics.FromImage(saturation);
  60.  
  61. float h = (float)hueSlider.Value;
  62.  
  63. for (int i = 0; i < 360; ++i)
  64. {
  65. HSL hsl = new HSL(h, i / 360.0F, .5F);
  66.  
  67. g.DrawLine(new Pen(hsl.Color), i, 0, i, satPicBox.Height);
  68. }
  69.  
  70. satPicBox.Image = saturation;
  71.  
  72. Graphics gl = Graphics.FromImage(luminance);
  73.  
  74. float s = (float)satSlider.Value / 100.0f;
  75.  
  76. for (int i = 0; i < 360; ++i)
  77. {
  78. HSL hsl = new HSL(h, s, i / 360.0f);
  79.  
  80. gl.DrawLine(new Pen(hsl.Color), i, 0, i, lumPicBox.Height);
  81. }
  82.  
  83. lumPicBox.Image = luminance;
  84.  
  85. Graphics rgb = Graphics.FromImage(RGB);
  86.  
  87. float l = (float)lumSlider.Value / 100.0f;
  88.  
  89. Color rgbFinal = new HSL(h, s, l).Color;
  90. rgb.FillRectangle(new SolidBrush(rgbFinal), 0, 0, RGBPicBox.Width, RGBPicBox.Height);
  91.  
  92. RGBPicBox.Image = RGB;
  93.  
  94. redLabel.Text = String.Format("Rouge : {0}", rgbFinal.R.ToString());
  95. greenLabel.Text = String.Format("Vert : {0}", rgbFinal.G.ToString());
  96. blueLabel.Text = String.Format("Bleu : {0}", rgbFinal.B.ToString());
  97.  
  98. red = rgbFinal.R;
  99. green = rgbFinal.G;
  100. blue = rgbFinal.B;
  101. }
  102.  
  103. private void changeHueAction(object sender, System.EventArgs e)
  104. {
  105. if (!keyIsDown)
  106. {
  107. hueText.Text = (hueSlider.Value).ToString();
  108. drawBars();
  109. }
  110. }
  111.  
  112. private void hueText_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  113. {
  114. if (!Char.IsControl(e.KeyChar))
  115. {
  116. if (!Char.IsDigit(e.KeyChar))
  117. {
  118. e.Handled = true;
  119. return;
  120. }
  121.  
  122. if (hueText.Text.Length > 0)
  123. {
  124. string s = hueText.Text.Substring(0, hueText.SelectionStart);
  125. s += e.KeyChar;
  126. int sub = hueText.SelectionStart + hueText.SelectionLength;
  127. s += hueText.Text.Substring(sub, hueText.Text.Length - sub);
  128.  
  129. int n = Convert.ToInt16(s);
  130.  
  131. if (n > 359)
  132. {
  133. e.Handled = true;
  134. return;
  135. }
  136.  
  137. keyIsDown = true;
  138. hueSlider.Value = n;
  139. keyIsDown = false;
  140. }
  141. }
  142.  
  143. drawBars();
  144. }
  145.  
  146. private void changeSatAction(object sender, System.EventArgs e)
  147. {
  148. if (!keyIsDown)
  149. {
  150. satText.Text = satSlider.Value.ToString();
  151. drawBars();
  152. }
  153. }
  154.  
  155. private void satText_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  156. {
  157. if (!Char.IsControl(e.KeyChar))
  158. {
  159. if (!Char.IsDigit(e.KeyChar))
  160. {
  161. e.Handled = true;
  162. return;
  163. }
  164.  
  165. if (satText.Text.Length > 0)
  166. {
  167. string s = satText.Text.Substring(0, satText.SelectionStart);
  168. s += e.KeyChar;
  169. int sub = satText.SelectionStart + satText.SelectionLength;
  170. s += satText.Text.Substring(sub, satText.Text.Length - sub);
  171.  
  172. int n = Convert.ToInt16(s);
  173.  
  174. if (n > 100)
  175. {
  176. e.Handled = true;
  177. return;
  178. }
  179.  
  180. keyIsDown = true;
  181. satSlider.Value = n;
  182. keyIsDown = false;
  183. }
  184. }
  185.  
  186. drawBars();
  187. }
  188.  
  189. private void changeLumAction(object sender, System.EventArgs e)
  190. {
  191. if (!keyIsDown)
  192. {
  193. lumText.Text = lumSlider.Value.ToString();
  194. drawBars();
  195. }
  196. }
  197.  
  198. private void lumText_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  199. {
  200. if (!Char.IsControl(e.KeyChar))
  201. {
  202. if (!Char.IsDigit(e.KeyChar))
  203. {
  204. e.Handled = true;
  205. return;
  206. }
  207.  
  208. if (lumText.Text.Length > 0)
  209. {
  210. string s = lumText.Text.Substring(0, lumText.SelectionStart);
  211. s += e.KeyChar;
  212. int sub = lumText.SelectionStart + lumText.SelectionLength;
  213. s += lumText.Text.Substring(lumText.SelectionStart + lumText.SelectionLength, lumText.Text.Length - sub);
  214.  
  215. int n = Convert.ToInt16(s);
  216.  
  217. if (n > 100)
  218. {
  219. e.Handled = true;
  220. return;
  221. }
  222.  
  223. keyIsDown = true;
  224. lumSlider.Value = n;
  225. keyIsDown = false;
  226. }
  227. }
  228.  
  229. drawBars();
  230. }
  231.  
  232. #region properties
  233. public Color SelectedColor
  234. {
  235. get
  236. {
  237. return Color.FromArgb(red, green, blue);
  238. }
  239. set
  240. {
  241. HSL hsl = new HSL(value);
  242.  
  243. hueSlider.Value = (int)hsl.Hue;
  244. satSlider.Value = (int)(hsl.Saturation * 100);
  245. lumSlider.Value = (int)(hsl.Luminance * 100);
  246. }
  247. }
  248. /*
  249.   public int H
  250.   {
  251.   get { return initialHue; }
  252.   set
  253.   {
  254.   initialHue = value;
  255.   drawBars();
  256.   }
  257.   }
  258.  
  259.  
  260.   public int S
  261.   {
  262.   get { return initialSat; }
  263.   set
  264.   {
  265.   initialSat = value;
  266.   drawBars();
  267.   }
  268.   }
  269.  
  270.  
  271.   public int L
  272.   {
  273.   get { return initialLum; }
  274.   set
  275.   {
  276.   initialLum = value;
  277.   drawBars();
  278.   }
  279.   } */
  280. #endregion
  281.  
  282. }
  283. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/dialogs/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1720147425 05/07/2024 04:43:45
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/dialogs/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csTrackIntParameterDialog.cs4.2 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csHSLDialog.cs8.25 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csExceptionDialog.cs3.58 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csVersionForm.Designer.cs6.72 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .resx|.resxCriticalExceptionDialog.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .resx|.resxTrackFloatParameterDialog.resx5.68 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csDGVLayoutOptionsDialog.designer.cs5.12 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csExceptionDialog.Designer.cs6.2 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .resx|.resxCustomOpenResultFileDialog.resx6.06 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .resx|.resxVersionForm.resx42.91 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csAboutBrolDevlDialog.Designer.cs2.24 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .resx|.resxDGVLayoutOptionsDialog.resx5.68 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .resx|.resxInfobrolForm.resx40.95 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csTrackFloatParameterDialog.cs2.41 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .resx|.resxUpdateDialog.resx5.68 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csCustomOpenResultFileDialog.Designer.cs7.44 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csCriticalExceptionDialog.Designer.cs8.88 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csTrackIntParameterDialog.Designer.cs8.02 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csDGVLayoutOptionsDialog.cs1.05 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csUpdateDialog.Designer.cs2.02 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csUpdateDialog.cs360 octets31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csAboutBrolDevlDialog.cs230 octets31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csCustomOpenResultFileDialog.cs4.84 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .resx|.resxExceptionDialog.resx5.68 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .resx|.resxHSLDialog.resx5.68 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .resx|.resxAboutBrolDevlDialog.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csTrackFloatParameterDialog.Designer.cs6.31 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .resx|.resxResizeDialog.resx5.68 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csHSLDialog.Designer.cs14.28 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csResizeDialog.cs1.09 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csCriticalExceptionDialog.cs1.87 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csVersionForm.cs1.16 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .resx|.resxTrackIntParameterDialog.resx5.68 Ko31/10/2018 18:33:15-refusé-
Afficher le fichier .cs|.csInfobrolForm.cs198 octets31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csInfobrolForm.Designer.cs2.45 Ko31/10/2018 18:33:14-refusé-
Afficher le fichier .cs|.csResizeDialog.Designer.cs5.3 Ko31/10/2018 18:33:14-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

Document créé le 16/10/2009, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/cs-broldev-source-rf-view/dialogs/HSLDialog.cs.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.