BioGTK  6.7.0
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images. Including whole slide, pyramidal, and series.
Loading...
Searching...
No Matches
ColorTool.cs
1using AForge;
2using Gdk;
3using Gtk;
4using System;
5using System.Collections.Generic;
6using System.IO;
7using System.Linq;
8using System.Text;
9using System.Threading.Tasks;
10
11namespace BioGTK
12{
13
14 public class ColorTool : Gtk.Dialog
15 {
16 #region Properties
17
18 private Builder _builder;
19 bool color1 = false;
20
21#pragma warning disable 649
22
23 [Builder.Object]
24 private SpinButton rBox;
25 [Builder.Object]
26 private SpinButton gBox;
27 [Builder.Object]
28 private SpinButton bBox;
29 [Builder.Object]
30 private SpinButton widthBox;
31 [Builder.Object]
32 private Scale rBar;
33 [Builder.Object]
34 private Scale gBar;
35 [Builder.Object]
36 private Scale bBar;
37 [Builder.Object]
38 private Scale widthBar;
39 [Builder.Object]
40 private DrawingArea image;
41 [Builder.Object]
42 private Button cancelBut;
43 [Builder.Object]
44 private Button okBut;
45#pragma warning restore 649
46
47 #endregion
48
49 #region Constructors / Destructors
50
57 public static ColorTool Create(bool color1)
58 {
59 Builder builder = new Builder(new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/" + "Glade/ColorTool.glade", FileMode.Open));
60 return new ColorTool(builder, builder.GetObject("colorTool").Handle, color1);
61 }
62
63
64 /* The constructor for the class. */
65 protected ColorTool(Builder builder, IntPtr handle, bool color1) : base(handle)
66 {
67 _builder = builder;
68 builder.Autoconnect(this);
69 this.color1 = color1;
71 rBar.Adjustment.Upper = ushort.MaxValue;
72 gBar.Adjustment.Upper = ushort.MaxValue;
73 bBar.Adjustment.Upper = ushort.MaxValue;
74 rBox.Adjustment.Upper = ushort.MaxValue;
75 rBox.Adjustment.StepIncrement = 1;
76 rBox.Adjustment.PageIncrement = 10;
77 gBox.Adjustment.Upper = ushort.MaxValue;
78 gBox.Adjustment.StepIncrement = 1;
79 gBox.Adjustment.PageIncrement = 10;
80 bBox.Adjustment.Upper = ushort.MaxValue;
81 bBox.Adjustment.StepIncrement = 1;
82 bBox.Adjustment.PageIncrement = 10;
83 widthBar.Adjustment.Upper = 100;
84 widthBar.Adjustment.Value = Tools.StrokeWidth;
85 widthBox.Adjustment.Upper = 100;
86 widthBox.Adjustment.Value = Tools.StrokeWidth;
87 if (color1)
88 {
89 rBar.Adjustment.Value = Tools.drawColor.R;
90 gBar.Adjustment.Value = Tools.drawColor.G;
91 bBar.Adjustment.Value = Tools.drawColor.B;
92 }
93 else
94 {
95 rBar.Adjustment.Value = Tools.eraseColor.R;
96 gBar.Adjustment.Value = Tools.eraseColor.G;
97 bBar.Adjustment.Value = Tools.eraseColor.B;
98 }
99 image.QueueDraw();
100 App.ApplyStyles(this);
101 }
102
103 #endregion
104
105 #region Handlers
107 protected void SetupHandlers()
108 {
109 rBar.ChangeValue += ChangeValue;
110 gBar.ChangeValue += ChangeValue;
111 bBar.ChangeValue += ChangeValue;
112 widthBar.ChangeValue += ChangeValue;
113 rBox.ChangeValue += Box_ChangeValue;
114 gBox.ChangeValue += Box_ChangeValue;
115 bBox.ChangeValue += Box_ChangeValue;
116 widthBox.ChangeValue += Box_ChangeValue;
117 image.Drawn += Image_Drawn;
118 cancelBut.Clicked += CancelBut_Clicked;
119 okBut.Clicked += OkBut_Clicked;
120 }
121
126 private void OkBut_Clicked(object sender, EventArgs e)
127 {
128 this.DefaultResponse = ResponseType.Ok;
129 this.Destroy();
130 }
131
137 private void CancelBut_Clicked(object sender, EventArgs e)
138 {
139 this.DefaultResponse = ResponseType.Cancel;
140 this.Destroy();
141 }
142
148 private void Image_Drawn(object o, DrawnArgs args)
149 {
150 args.Cr.SetSourceRGBA(RGBA.Red, RGBA.Green, RGBA.Blue,RGBA.Alpha);
151 args.Cr.Rectangle(new Cairo.Rectangle(0,0,image.AllocatedWidth,image.AllocatedHeight));
152 args.Cr.Fill();
153 args.Cr.Scale(1, 1);
154 image.OverrideBackgroundColor(StateFlags.Normal, RGBA);
155 args.Cr.Paint();
156 }
157
163 private void Box_ChangeValue(object o, ChangeValueArgs args)
164 {
165 Gdk.RGBA col = new Gdk.RGBA();
166 col.Red = (float)rBar.Value / (float)ushort.MaxValue;
167 col.Green = (float)gBar.Value / (float)ushort.MaxValue;
168 col.Blue = (float)bBar.Value / (float)ushort.MaxValue;
169 rBox.Value = rBar.Value;
170 gBox.Value = gBar.Value;
171 bBox.Value = bBar.Value;
172 Tools.StrokeWidth = (int)widthBox.Value;
173 if (color1)
174 Tools.DrawColor = ColorS;
175 else
176 Tools.EraseColor = ColorS;
177
178 }
179
184 private void ChangeValue(object o, ChangeValueArgs args)
185 {
186 rBox.Value = rBar.Value;
187 gBox.Value = gBar.Value;
188 bBox.Value = bBar.Value;
189 if (!color1)
190 Tools.DrawColor = ColorS;
191 else
192 Tools.EraseColor = ColorS;
193 Tools.StrokeWidth = (int)widthBar.Value;
194 }
195
196 /* Returning a new ColorS object with the values of the spin buttons. */
197 public ColorS ColorS
198 {
199 get
200 {
201 return new ColorS((ushort)rBox.Value, (ushort)gBox.Value, (ushort)bBox.Value);
202 }
203 }
204 /* Returning a new RGBA object with the values of the spin buttons. */
205 public RGBA RGBA
206 {
207 get {
208 RGBA rgb = new RGBA();
209 rgb.Red = (float)rBox.Value / (float)ushort.MaxValue;
210 rgb.Green = (float)gBox.Value / (float)ushort.MaxValue;
211 rgb.Blue = (float)bBox.Value / (float)ushort.MaxValue;
212 rgb.Alpha = 1.0;
213 return rgb; }
214 }
215 #endregion
216
217 }
218}
static ColorTool Create(bool color1)
Definition ColorTool.cs:57
void SetupHandlers()
It sets up the event handlers for the sliders and text boxes.
Definition ColorTool.cs:107
Implementations for all tool types defined in Tools.cs.
Definition Tools.cs:23
Definition ML.cs:17