• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

dev


Commit MetaInfo

修订版9fc7fb1db7122f5aeeba3db9584dcdcab1aacb60 (tree)
时间2013-06-18 01:11:22
作者spx <spx268@gmai...>
Commiterspx

Log Message

ErrorImage/InitialImageの表示にはPictureBoxSizeMode.CenterImageを使う

更改概述

差异

--- a/OpenTween/OTPictureBox.cs
+++ b/OpenTween/OTPictureBox.cs
@@ -42,6 +42,7 @@ namespace OpenTween
4242 set
4343 {
4444 base.Image = value;
45+ this.SizeMode = this._SizeMode;
4546 if (this.memoryImage != null)
4647 {
4748 this.memoryImage.Dispose();
@@ -67,6 +68,31 @@ namespace OpenTween
6768 private string _ImageLocation;
6869
6970 /// <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>
7096 /// ImageLocation によりロードされた画像
7197 /// </summary>
7298 private MemoryImage memoryImage = null;
@@ -81,8 +107,7 @@ namespace OpenTween
81107 if (this.loadAsyncTask != null && !this.loadAsyncTask.IsCompleted)
82108 this.CancelAsync();
83109
84- if (this.expandedInitialImage != null)
85- this.Image = this.expandedInitialImage;
110+ this.Image = base.InitialImage;
86111
87112 Uri uri;
88113 try
@@ -123,7 +148,7 @@ namespace OpenTween
123148 {
124149 if (t.IsFaulted)
125150 {
126- this.Image = this.expandedErrorImage;
151+ this.Image = base.ErrorImage;
127152 }
128153 else
129154 {
@@ -162,108 +187,10 @@ namespace OpenTween
162187 }
163188 }
164189
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-
257190 protected override void Dispose(bool disposing)
258191 {
259192 base.Dispose(disposing);
260193
261- if (this.expandedErrorImage != null)
262- this.expandedErrorImage.Dispose();
263-
264- if (this.expandedInitialImage != null)
265- this.expandedInitialImage.Dispose();
266-
267194 if (this.memoryImage != null)
268195 this.memoryImage.Dispose();
269196