CraftSynth.ImageEditor – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
2 | using System.Globalization; |
||
3 | using System.Windows.Forms; |
||
4 | |||
5 | namespace CraftSynth.ImageEditor |
||
6 | { |
||
7 | internal partial class PropertiesDialog : Form |
||
8 | { |
||
9 | public PropertiesDialog() |
||
10 | { |
||
11 | InitializeComponent(); |
||
12 | } |
||
13 | |||
14 | private GraphicsProperties properties; |
||
15 | private const string undefined = "??"; |
||
16 | private const int maxWidth = 5; |
||
17 | |||
18 | public GraphicsProperties Properties |
||
19 | { |
||
20 | get { return properties; } |
||
21 | set { properties = value; } |
||
22 | } |
||
23 | |||
24 | private void PropertiesDialog_Load(object sender, EventArgs e) |
||
25 | { |
||
26 | InitControls(); |
||
27 | SetColor(); |
||
28 | SetPenWidth(); |
||
29 | } |
||
30 | |||
31 | private void InitControls() |
||
32 | { |
||
33 | for (int i = 1; i <= maxWidth; i++) |
||
34 | { |
||
35 | cmbPenWidth.Items.Add(i.ToString(CultureInfo.InvariantCulture)); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | private void SetColor() |
||
40 | { |
||
41 | if (properties.Color.HasValue) |
||
42 | lblColor.BackColor = properties.Color.Value; |
||
43 | else |
||
44 | lblColor.Text = undefined; |
||
45 | } |
||
46 | |||
47 | private void SetPenWidth() |
||
48 | { |
||
49 | if (properties.PenWidth.HasValue) |
||
50 | { |
||
51 | int penWidth = properties.PenWidth.Value; |
||
52 | |||
53 | if (penWidth < 1) |
||
54 | penWidth = 1; |
||
55 | |||
56 | if (penWidth > maxWidth) |
||
57 | penWidth = maxWidth; |
||
58 | |||
59 | label2.Text = penWidth.ToString(CultureInfo.InvariantCulture); |
||
60 | cmbPenWidth.SelectedIndex = penWidth - 1; |
||
61 | } |
||
62 | else |
||
63 | { |
||
64 | label2.Text = undefined; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | private void ReadValues() |
||
69 | { |
||
70 | if (cmbPenWidth.Text != undefined) |
||
71 | { |
||
72 | properties.PenWidth = cmbPenWidth.SelectedIndex + 1; |
||
73 | } |
||
74 | |||
75 | if (lblColor.Text.Length == 0) |
||
76 | { |
||
77 | properties.Color = lblColor.BackColor; |
||
78 | } |
||
79 | } |
||
80 | |||
81 | private void cmbPenWidth_SelectedIndexChanged(object sender, EventArgs e) |
||
82 | { |
||
83 | int width = cmbPenWidth.SelectedIndex + 1; |
||
84 | lblPenWidth.Text = width.ToString(CultureInfo.InvariantCulture); |
||
85 | } |
||
86 | |||
87 | private void btnSelectColor_Click(object sender, EventArgs e) |
||
88 | { |
||
89 | ColorDialog dlg = new ColorDialog(); |
||
90 | dlg.Color = lblColor.BackColor; |
||
91 | |||
92 | if (dlg.ShowDialog(this) == |
||
93 | DialogResult.OK) |
||
94 | { |
||
95 | lblColor.BackColor = dlg.Color; |
||
96 | lblColor.Text = ""; |
||
97 | } |
||
98 | } |
||
99 | |||
100 | private void btnOK_Click(object sender, EventArgs e) |
||
101 | { |
||
102 | ReadValues(); |
||
103 | DialogResult = DialogResult.OK; |
||
104 | } |
||
105 | } |
||
106 | } |