2 using System.Collections.Generic;
\r
3 using System.Runtime.InteropServices;
\r
5 using System.Drawing;
\r
6 using System.Drawing.Drawing2D;
\r
7 using System.Diagnostics;
\r
12 /// 高速描画版のCPrivateFontクラス。
\r
13 /// といっても、一度レンダリングした結果をキャッシュして使いまわしているだけ。
\r
15 public class CPrivateFastFont : CPrivateFont
\r
20 private const int MAXCACHESIZE = 128;
\r
22 private struct FontCache
\r
24 // public Font font;
\r
25 public string drawstr;
\r
26 public DrawMode drawmode;
\r
27 public Color fontColor;
\r
28 public Color edgeColor;
\r
29 public Color gradationTopColor;
\r
30 public Color gradationBottomColor;
\r
32 public Rectangle rectStrings;
\r
33 public Point ptOrigin;
\r
35 private List<FontCache> listFontCache;
\r
39 public CPrivateFastFont( FontFamily fontfamily, int pt, FontStyle style )
\r
41 Initialize( null, fontfamily, pt, style );
\r
43 public CPrivateFastFont( FontFamily fontfamily, int pt )
\r
45 Initialize( null, fontfamily, pt, FontStyle.Regular );
\r
47 public CPrivateFastFont( string fontpath, int pt, FontStyle style )
\r
49 Initialize( fontpath, null, pt, style );
\r
51 public CPrivateFastFont( string fontpath, int pt )
\r
53 Initialize( fontpath, null, pt, FontStyle.Regular );
\r
55 public CPrivateFastFont()
\r
57 throw new ArgumentException("CPrivateFastFont: 引数があるコンストラクタを使用してください。");
\r
60 #region [ コンストラクタから呼ばれる初期化処理 ]
\r
61 protected new void Initialize( string fontpath, FontFamily fontfamily, int pt, FontStyle style )
\r
63 this.bDispose完了済み_CPrivateFastFont = false;
\r
64 this.listFontCache = new List<FontCache>();
\r
65 base.Initialize( fontpath, fontfamily, pt, style );
\r
70 #region [ DrawPrivateFontのオーバーロード群 ]
\r
72 /// 文字列を描画したテクスチャを返す
\r
74 /// <param name="drawstr">描画文字列</param>
\r
75 /// <param name="fontColor">描画色</param>
\r
76 /// <returns>描画済テクスチャ</returns>
\r
77 public new Bitmap DrawPrivateFont( string drawstr, Color fontColor )
\r
79 return DrawPrivateFont( drawstr, DrawMode.Normal, fontColor, Color.White, Color.White, Color.White );
\r
83 /// 文字列を描画したテクスチャを返す
\r
85 /// <param name="drawstr">描画文字列</param>
\r
86 /// <param name="fontColor">描画色</param>
\r
87 /// <param name="edgeColor">縁取色</param>
\r
88 /// <returns>描画済テクスチャ</returns>
\r
89 public new Bitmap DrawPrivateFont( string drawstr, Color fontColor, Color edgeColor )
\r
91 return DrawPrivateFont( drawstr, DrawMode.Edge, fontColor, edgeColor, Color.White, Color.White );
\r
95 /// 文字列を描画したテクスチャを返す
\r
97 /// <param name="drawstr">描画文字列</param>
\r
98 /// <param name="fontColor">描画色</param>
\r
99 /// <param name="gradationTopColor">グラデーション 上側の色</param>
\r
100 /// <param name="gradationBottomColor">グラデーション 下側の色</param>
\r
101 /// <returns>描画済テクスチャ</returns>
\r
102 //public new Bitmap DrawPrivateFont( string drawstr, Color fontColor, Color gradationTopColor, Color gradataionBottomColor )
\r
104 // return DrawPrivateFont( drawstr, DrawMode.Gradation, fontColor, Color.White, gradationTopColor, gradataionBottomColor );
\r
108 /// 文字列を描画したテクスチャを返す
\r
110 /// <param name="drawstr">描画文字列</param>
\r
111 /// <param name="fontColor">描画色</param>
\r
112 /// <param name="edgeColor">縁取色</param>
\r
113 /// <param name="gradationTopColor">グラデーション 上側の色</param>
\r
114 /// <param name="gradationBottomColor">グラデーション 下側の色</param>
\r
115 /// <returns>描画済テクスチャ</returns>
\r
116 public new Bitmap DrawPrivateFont( string drawstr, Color fontColor, Color edgeColor, Color gradationTopColor, Color gradataionBottomColor )
\r
118 return DrawPrivateFont( drawstr, DrawMode.Edge | DrawMode.Gradation, fontColor, edgeColor, gradationTopColor, gradataionBottomColor );
\r
121 #if こちらは使わない // (Bitmapではなく、CTextureを返す版)
\r
123 /// 文字列を描画したテクスチャを返す
\r
125 /// <param name="drawstr">描画文字列</param>
\r
126 /// <param name="fontColor">描画色</param>
\r
127 /// <returns>描画済テクスチャ</returns>
\r
128 public CTexture DrawPrivateFont( string drawstr, Color fontColor )
\r
130 Bitmap bmp = DrawPrivateFont( drawstr, DrawMode.Normal, fontColor, Color.White, Color.White, Color.White );
\r
131 return CDTXMania.tテクスチャの生成( bmp, false );
\r
135 /// 文字列を描画したテクスチャを返す
\r
137 /// <param name="drawstr">描画文字列</param>
\r
138 /// <param name="fontColor">描画色</param>
\r
139 /// <param name="edgeColor">縁取色</param>
\r
140 /// <returns>描画済テクスチャ</returns>
\r
141 public CTexture DrawPrivateFont( string drawstr, Color fontColor, Color edgeColor )
\r
143 Bitmap bmp = DrawPrivateFont( drawstr, DrawMode.Edge, fontColor, edgeColor, Color.White, Color.White );
\r
144 return CDTXMania.tテクスチャの生成( bmp, false );
\r
148 /// 文字列を描画したテクスチャを返す
\r
150 /// <param name="drawstr">描画文字列</param>
\r
151 /// <param name="fontColor">描画色</param>
\r
152 /// <param name="gradationTopColor">グラデーション 上側の色</param>
\r
153 /// <param name="gradationBottomColor">グラデーション 下側の色</param>
\r
154 /// <returns>描画済テクスチャ</returns>
\r
155 //public CTexture DrawPrivateFont( string drawstr, Color fontColor, Color gradationTopColor, Color gradataionBottomColor )
\r
157 // Bitmap bmp = DrawPrivateFont( drawstr, DrawMode.Gradation, fontColor, Color.White, gradationTopColor, gradataionBottomColor );
\r
158 // return CDTXMania.tテクスチャの生成( bmp, false );
\r
162 /// 文字列を描画したテクスチャを返す
\r
164 /// <param name="drawstr">描画文字列</param>
\r
165 /// <param name="fontColor">描画色</param>
\r
166 /// <param name="edgeColor">縁取色</param>
\r
167 /// <param name="gradationTopColor">グラデーション 上側の色</param>
\r
168 /// <param name="gradationBottomColor">グラデーション 下側の色</param>
\r
169 /// <returns>描画済テクスチャ</returns>
\r
170 public CTexture DrawPrivateFont( string drawstr, Color fontColor, Color edgeColor, Color gradationTopColor, Color gradataionBottomColor )
\r
172 Bitmap bmp = DrawPrivateFont( drawstr, DrawMode.Edge | DrawMode.Gradation, fontColor, edgeColor, gradationTopColor, gradataionBottomColor );
\r
173 return CDTXMania.tテクスチャの生成( bmp, false );
\r
178 protected new Bitmap DrawPrivateFont( string drawstr, DrawMode drawmode, Color fontColor, Color edgeColor, Color gradationTopColor, Color gradationBottomColor )
\r
180 #region [ 以前レンダリングしたことのある文字列/フォントか? (キャッシュにヒットするか?) ]
\r
181 int index = listFontCache.FindIndex(
\r
182 delegate( FontCache fontcache )
\r
185 drawstr == fontcache.drawstr &&
\r
186 drawmode == fontcache.drawmode &&
\r
187 fontColor == fontcache.fontColor &&
\r
188 edgeColor == fontcache.edgeColor &&
\r
189 gradationTopColor == fontcache.gradationTopColor &&
\r
190 gradationBottomColor == fontcache.gradationBottomColor
\r
191 // _font == fontcache.font
\r
199 #region [ レンダリングして、キャッシュに登録 ]
\r
200 FontCache fc = new FontCache();
\r
201 fc.bmp = base.DrawPrivateFont( drawstr, drawmode, fontColor, edgeColor, gradationTopColor, gradationBottomColor );
\r
202 fc.drawstr = drawstr;
\r
203 fc.drawmode = drawmode;
\r
204 fc.fontColor = fontColor;
\r
205 fc.edgeColor = edgeColor;
\r
206 fc.gradationTopColor = gradationTopColor;
\r
207 fc.gradationBottomColor = gradationBottomColor;
\r
208 fc.rectStrings = RectStrings;
\r
209 fc.ptOrigin = PtOrigin;
\r
210 listFontCache.Add( fc );
\r
211 // Debug.WriteLine( drawstr + ": Cacheにヒットせず。(cachesize=" + listFontCache.Count + ")" );
\r
213 #region [ もしキャッシュがあふれたら、最も古いキャッシュを破棄する ]
\r
214 if ( listFontCache.Count > MAXCACHESIZE )
\r
216 // Debug.WriteLine( "Cache溢れ。" + listFontCache[ 0 ].drawstr + " を解放します。" );
\r
217 if ( listFontCache[ 0 ].bmp != null )
\r
219 listFontCache[ 0 ].bmp.Dispose();
\r
221 listFontCache.RemoveAt( 0 );
\r
225 // 呼び出し元のDispose()でキャッシュもDispose()されないように、Clone()で返す。
\r
226 return (Bitmap)listFontCache[ listFontCache.Count - 1 ].bmp.Clone();
\r
230 // Debug.WriteLine( drawstr + ": Cacheにヒット!! index=" + index );
\r
231 #region [ キャッシュにヒット。レンダリングは行わず、キャッシュ内のデータを返して終了。]
\r
232 RectStrings = listFontCache[ index ].rectStrings;
\r
233 PtOrigin = listFontCache[ index ].ptOrigin;
\r
234 // 呼び出し元のDispose()でキャッシュもDispose()されないように、Clone()で返す。
\r
235 return (Bitmap) listFontCache[ index ].bmp.Clone();
\r
240 #region [ IDisposable 実装 ]
\r
241 //-----------------
\r
242 public new void Dispose()
\r
244 if ( !this.bDispose完了済み_CPrivateFastFont )
\r
246 if ( listFontCache != null )
\r
248 //Debug.WriteLine( "Disposing CPrivateFastFont()" );
\r
249 #region [ キャッシュしている画像を破棄する ]
\r
250 foreach ( FontCache bc in listFontCache )
\r
253 if ( bc.bmp != null )
\r
259 listFontCache.Clear();
\r
260 listFontCache = null;
\r
262 this.bDispose完了済み_CPrivateFastFont = true;
\r
266 //-----------------
\r
269 #region [ private ]
\r
270 //-----------------
\r
271 protected bool bDispose完了済み_CPrivateFastFont;
\r
272 //-----------------
\r