dev
修订版 | 9fc7fb1db7122f5aeeba3db9584dcdcab1aacb60 (tree) |
---|---|
时间 | 2013-06-18 01:11:22 |
作者 | spx <spx268@gmai...> |
Commiter | spx |
ErrorImage/InitialImageの表示にはPictureBoxSizeMode.CenterImageを使う
@@ -42,6 +42,7 @@ namespace OpenTween | ||
42 | 42 | set |
43 | 43 | { |
44 | 44 | base.Image = value; |
45 | + this.SizeMode = this._SizeMode; | |
45 | 46 | if (this.memoryImage != null) |
46 | 47 | { |
47 | 48 | this.memoryImage.Dispose(); |
@@ -67,6 +68,31 @@ namespace OpenTween | ||
67 | 68 | private string _ImageLocation; |
68 | 69 | |
69 | 70 | /// <summary> |
71 | + /// 画像に応じた SizeMode を取得・設定する | |
72 | + /// </summary> | |
73 | + /// <remarks> | |
74 | + /// ErrorImage と InitialImage は SizeMode の値に依らず中央等倍に表示する必要があるため、 | |
75 | + /// 画像に応じて SizeMode の状態を弄る | |
76 | + /// </remarks> | |
77 | + public new PictureBoxSizeMode SizeMode | |
78 | + { | |
79 | + get { return this._SizeMode; } | |
80 | + set | |
81 | + { | |
82 | + this._SizeMode = value; | |
83 | + if (base.Image == null || (base.Image != base.ErrorImage && base.Image != base.InitialImage)) | |
84 | + { | |
85 | + base.SizeMode = value; | |
86 | + } | |
87 | + else | |
88 | + { | |
89 | + base.SizeMode = PictureBoxSizeMode.CenterImage; | |
90 | + } | |
91 | + } | |
92 | + } | |
93 | + private PictureBoxSizeMode _SizeMode; | |
94 | + | |
95 | + /// <summary> | |
70 | 96 | /// ImageLocation によりロードされた画像 |
71 | 97 | /// </summary> |
72 | 98 | private MemoryImage memoryImage = null; |
@@ -81,8 +107,7 @@ namespace OpenTween | ||
81 | 107 | if (this.loadAsyncTask != null && !this.loadAsyncTask.IsCompleted) |
82 | 108 | this.CancelAsync(); |
83 | 109 | |
84 | - if (this.expandedInitialImage != null) | |
85 | - this.Image = this.expandedInitialImage; | |
110 | + this.Image = base.InitialImage; | |
86 | 111 | |
87 | 112 | Uri uri; |
88 | 113 | try |
@@ -123,7 +148,7 @@ namespace OpenTween | ||
123 | 148 | { |
124 | 149 | if (t.IsFaulted) |
125 | 150 | { |
126 | - this.Image = this.expandedErrorImage; | |
151 | + this.Image = base.ErrorImage; | |
127 | 152 | } |
128 | 153 | else |
129 | 154 | { |
@@ -162,108 +187,10 @@ namespace OpenTween | ||
162 | 187 | } |
163 | 188 | } |
164 | 189 | |
165 | - public new Image ErrorImage | |
166 | - { | |
167 | - get { return base.ErrorImage; } | |
168 | - set | |
169 | - { | |
170 | - base.ErrorImage = value; | |
171 | - this.UpdateStatusImages(); | |
172 | - } | |
173 | - } | |
174 | - | |
175 | - public new Image InitialImage | |
176 | - { | |
177 | - get { return base.InitialImage; } | |
178 | - set | |
179 | - { | |
180 | - base.InitialImage = value; | |
181 | - this.UpdateStatusImages(); | |
182 | - } | |
183 | - } | |
184 | - | |
185 | - private Image expandedErrorImage = null; | |
186 | - private Image expandedInitialImage = null; | |
187 | - | |
188 | - /// <summary> | |
189 | - /// ErrorImage と InitialImage の表示用の画像を生成する | |
190 | - /// </summary> | |
191 | - /// <remarks> | |
192 | - /// ErrorImage と InitialImage は SizeMode の値に依らず中央等倍に表示する必要があるため、 | |
193 | - /// 事前にコントロールのサイズに合わせた画像を生成しておく | |
194 | - /// </remarks> | |
195 | - private void UpdateStatusImages() | |
196 | - { | |
197 | - var isError = false; | |
198 | - var isInit = false; | |
199 | - | |
200 | - if (this.Image != null) | |
201 | - { | |
202 | - // ErrorImage か InitialImage を使用中であれば記憶しておく | |
203 | - isError = (this.Image == this.expandedErrorImage); | |
204 | - isInit = (this.Image == this.expandedInitialImage); | |
205 | - } | |
206 | - | |
207 | - if (isError || isInit) | |
208 | - this.Image = null; | |
209 | - | |
210 | - if (this.expandedErrorImage != null) | |
211 | - this.expandedErrorImage.Dispose(); | |
212 | - | |
213 | - if (this.expandedInitialImage != null) | |
214 | - this.expandedInitialImage.Dispose(); | |
215 | - | |
216 | - this.expandedErrorImage = this.ExpandImage(this.ErrorImage); | |
217 | - this.expandedInitialImage = this.ExpandImage(this.InitialImage); | |
218 | - | |
219 | - if (isError) | |
220 | - this.Image = this.expandedErrorImage; | |
221 | - | |
222 | - if (isInit) | |
223 | - this.Image = this.expandedInitialImage; | |
224 | - } | |
225 | - | |
226 | - private Image ExpandImage(Image image) | |
227 | - { | |
228 | - if (image == null) return null; | |
229 | - | |
230 | - var bitmap = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); | |
231 | - | |
232 | - using (var g = this.CreateGraphics()) | |
233 | - { | |
234 | - bitmap.SetResolution(g.DpiX, g.DpiY); | |
235 | - } | |
236 | - | |
237 | - using (var g = Graphics.FromImage(bitmap)) | |
238 | - { | |
239 | - var posx = (bitmap.Width - image.Width) / 2; | |
240 | - var posy = (bitmap.Height - image.Height) / 2; | |
241 | - | |
242 | - g.DrawImage(image, | |
243 | - new Rectangle(posx, posy, image.Width, image.Height), | |
244 | - new Rectangle(0, 0, image.Width, image.Height), | |
245 | - GraphicsUnit.Pixel); | |
246 | - } | |
247 | - | |
248 | - return bitmap; | |
249 | - } | |
250 | - | |
251 | - protected override void OnResize(EventArgs e) | |
252 | - { | |
253 | - base.OnResize(e); | |
254 | - this.UpdateStatusImages(); | |
255 | - } | |
256 | - | |
257 | 190 | protected override void Dispose(bool disposing) |
258 | 191 | { |
259 | 192 | base.Dispose(disposing); |
260 | 193 | |
261 | - if (this.expandedErrorImage != null) | |
262 | - this.expandedErrorImage.Dispose(); | |
263 | - | |
264 | - if (this.expandedInitialImage != null) | |
265 | - this.expandedInitialImage.Dispose(); | |
266 | - | |
267 | 194 | if (this.memoryImage != null) |
268 | 195 | this.memoryImage.Dispose(); |
269 | 196 |