2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.Globalization;
6 using System.Runtime.InteropServices;
9 using System.Text.RegularExpressions;
14 internal class CActSelectInformation : CActivity
18 public CActSelectInformation()
26 public override void On活性化()
32 public override void On非活性化()
37 public override void OnManagedリソースの作成()
41 //Trace.TraceInformation("Information用 Pad画像生成 開始。");
45 #region [ information画像パーツの作成 ]
46 #region [ Informationに表示する文字列の取得 ]
47 string[] strInfo = new string[]
49 CDTXMania.Instance.Resources.Explanation("strSelectInfo01"),
50 CDTXMania.Instance.Resources.Explanation("strSelectInfo02"),
51 CDTXMania.Instance.Resources.Explanation("strSelectInfo03"),
52 CDTXMania.Instance.Resources.Explanation("strSelectInfo04"),
53 CDTXMania.Instance.Resources.Explanation("strSelectInfo05"),
54 CDTXMania.Instance.Resources.Explanation("strSelectInfo06"),
55 CDTXMania.Instance.Resources.Explanation("strSelectInfo07"),
56 CDTXMania.Instance.Resources.Explanation("strSelectInfo08"),
57 CDTXMania.Instance.Resources.Explanation("strSelectInfo09"),
58 CDTXMania.Instance.Resources.Explanation("strSelectInfo10"),
62 STPadValue<Rectangle> RectDrPad = new STPadValue<Rectangle>();
63 RectDrPad.LC = new Rectangle( 0, 0, 170, 130);
64 RectDrPad.HH = new Rectangle(170, 0, 170, 130);
65 RectDrPad.SD = new Rectangle(340, 0, 170, 130);
66 RectDrPad.BD = new Rectangle( 0, 130, 170, 130);
67 RectDrPad.HT = new Rectangle(170, 130, 170, 130);
68 RectDrPad.LT = new Rectangle(340, 130, 170, 130);
69 RectDrPad.FT = new Rectangle( 0, 260, 170, 130);
70 RectDrPad.CY = new Rectangle(170, 260, 170, 130);
71 RectDrPad.RD = new Rectangle(340, 260, 170, 130);
73 STPadValue<Bitmap> ImgDrPad = new STPadValue<Bitmap>();
74 STPadValue<Bitmap> ImgGtPad = new STPadValue<Bitmap>();
75 Bitmap ImgAllDrPads = new Bitmap(CSkin.Path(@"Graphics\ScreenPlayDrums pads.png"));
76 Bitmap ImgAllGtPads = new Bitmap(CSkin.Path(@"Graphics\ScreenPlayGuitar pads.png"));
78 Rectangle desRect = new Rectangle(0, 0, 170, 130);
79 float newHeight, imgScale;
83 b = new Bitmap(170, 130);
84 g = Graphics.FromImage(b);
85 g.DrawImage(ImgAllDrPads, desRect, RectDrPad.LC, GraphicsUnit.Pixel);
87 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
88 imgScale = newHeight / 130.0f * 2;
89 ImgDrPad.LC = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
91 g = Graphics.FromImage(ImgDrPad.LC);
92 g.DrawImage(b, 0, 0, ImgDrPad.LC.Width, ImgDrPad.LC.Height);
97 b = new Bitmap(170, 130);
98 g = Graphics.FromImage(b);
99 g.DrawImage(ImgAllDrPads, desRect, RectDrPad.HH, GraphicsUnit.Pixel);
101 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
102 imgScale = newHeight / 130.0f * 2;
103 ImgDrPad.HH = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
105 g = Graphics.FromImage(ImgDrPad.HH);
106 g.DrawImage(b, 0, 0, ImgDrPad.HH.Width, ImgDrPad.HH.Height);
111 b = new Bitmap(170, 130);
112 g = Graphics.FromImage(b);
113 g.DrawImage(ImgAllDrPads, desRect, RectDrPad.SD, GraphicsUnit.Pixel);
115 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
116 imgScale = newHeight / 130.0f * 2;
117 ImgDrPad.SD = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
119 g = Graphics.FromImage(ImgDrPad.SD);
120 g.DrawImage(b, 0, 0, ImgDrPad.SD.Width, ImgDrPad.SD.Height);
125 b = new Bitmap(170, 130);
126 g = Graphics.FromImage(b);
127 g.DrawImage(ImgAllDrPads, desRect, RectDrPad.BD, GraphicsUnit.Pixel);
129 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
130 imgScale = newHeight / 130.0f * 2;
131 ImgDrPad.BD = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
133 g = Graphics.FromImage(ImgDrPad.BD);
134 g.DrawImage(b, 0, 0, ImgDrPad.BD.Width, ImgDrPad.BD.Height);
139 b = new Bitmap(170, 130);
140 g = Graphics.FromImage(b);
141 g.DrawImage(ImgAllDrPads, desRect, RectDrPad.HT, GraphicsUnit.Pixel);
143 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
144 imgScale = newHeight / 130.0f * 2;
145 ImgDrPad.HT = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
147 g = Graphics.FromImage(ImgDrPad.HT);
148 g.DrawImage(b, 0, 0, ImgDrPad.HT.Width, ImgDrPad.HT.Height);
153 b = new Bitmap(170, 130);
154 g = Graphics.FromImage(b);
155 g.DrawImage(ImgAllDrPads, desRect, RectDrPad.LT, GraphicsUnit.Pixel);
157 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
158 imgScale = newHeight / 130.0f * 2;
159 ImgDrPad.LT = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
161 g = Graphics.FromImage(ImgDrPad.LT);
162 g.DrawImage(b, 0, 0, ImgDrPad.LT.Width, ImgDrPad.LT.Height);
167 b = new Bitmap(170, 130);
168 g = Graphics.FromImage(b);
169 g.DrawImage(ImgAllDrPads, desRect, RectDrPad.FT, GraphicsUnit.Pixel);
171 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
172 imgScale = newHeight / 130.0f * 2;
173 ImgDrPad.FT = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
175 g = Graphics.FromImage(ImgDrPad.FT);
176 g.DrawImage(b, 0, 0, ImgDrPad.FT.Width, ImgDrPad.FT.Height);
181 b = new Bitmap(170, 130);
182 g = Graphics.FromImage(b);
183 g.DrawImage(ImgAllDrPads, desRect, RectDrPad.CY, GraphicsUnit.Pixel);
185 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
186 imgScale = newHeight / 130.0f * 2;
187 ImgDrPad.CY = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
189 g = Graphics.FromImage(ImgDrPad.CY);
190 g.DrawImage(b, 0, 0, ImgDrPad.CY.Width, ImgDrPad.CY.Height);
195 b = new Bitmap(170, 130);
196 g = Graphics.FromImage(b);
197 g.DrawImage(ImgAllDrPads, desRect, RectDrPad.RD, GraphicsUnit.Pixel);
199 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
200 imgScale = newHeight / 130.0f * 2;
201 ImgDrPad.RD = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
203 g = Graphics.FromImage(ImgDrPad.RD);
204 g.DrawImage(b, 0, 0, ImgDrPad.RD.Width, ImgDrPad.RD.Height);
209 b = new Bitmap(170, 130);
210 g = Graphics.FromImage(b);
211 g.DrawImage(ImgAllGtPads, desRect, RectDrPad.LC, GraphicsUnit.Pixel);
213 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
214 imgScale = newHeight / 130.0f * 2;
215 ImgGtPad.LC = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
217 g = Graphics.FromImage(ImgGtPad.LC);
218 g.DrawImage(b, 0, 0, ImgGtPad.LC.Width, ImgGtPad.LC.Height);
223 b = new Bitmap(170, 130);
224 g = Graphics.FromImage(b);
225 g.DrawImage(ImgAllGtPads, desRect, RectDrPad.HH, GraphicsUnit.Pixel);
227 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
228 imgScale = newHeight / 130.0f * 2;
229 ImgGtPad.HH = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
231 g = Graphics.FromImage(ImgGtPad.HH);
232 g.DrawImage(b, 0, 0, ImgGtPad.HH.Width, ImgGtPad.HH.Height);
237 b = new Bitmap(170, 130);
238 g = Graphics.FromImage(b);
239 g.DrawImage(ImgAllGtPads, desRect, RectDrPad.SD, GraphicsUnit.Pixel);
241 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
242 imgScale = newHeight / 130.0f * 2;
243 ImgGtPad.SD = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
245 g = Graphics.FromImage(ImgGtPad.SD);
246 g.DrawImage(b, 0, 0, ImgGtPad.SD.Width, ImgGtPad.SD.Height);
251 b = new Bitmap(170, 130);
252 g = Graphics.FromImage(b);
253 g.DrawImage(ImgAllGtPads, desRect, RectDrPad.LT, GraphicsUnit.Pixel);
255 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
256 imgScale = newHeight / 130.0f * 2;
257 ImgGtPad.LT = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
259 g = Graphics.FromImage(ImgGtPad.LT);
260 g.DrawImage(b, 0, 0, ImgGtPad.LT.Width, ImgGtPad.LT.Height);
265 b = new Bitmap(170, 130);
266 g = Graphics.FromImage(b);
267 g.DrawImage(ImgAllGtPads, desRect, RectDrPad.FT, GraphicsUnit.Pixel);
269 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
270 imgScale = newHeight / 130.0f * 2;
271 ImgGtPad.FT = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
273 g = Graphics.FromImage(ImgGtPad.FT);
274 g.DrawImage(b, 0, 0, ImgGtPad.FT.Width, ImgGtPad.FT.Height);
279 b = new Bitmap(170, 130);
280 g = Graphics.FromImage(b);
281 g.DrawImage(ImgAllGtPads, desRect, RectDrPad.CY, GraphicsUnit.Pixel);
283 newHeight = fontsize * g.DpiY / 72.0f; // 1 inch = 72 points
284 imgScale = newHeight / 130.0f * 2;
285 ImgGtPad.CY = new Bitmap((int)(Math.Ceiling(b.Width * imgScale)), (int)(Math.Ceiling(b.Height * imgScale)));
287 g = Graphics.FromImage(ImgGtPad.CY);
288 g.DrawImage(b, 0, 0, ImgGtPad.CY.Width, ImgGtPad.CY.Height);
294 //Trace.TraceInformation("Information用 Pad画像生成 終了。");
297 string fontPath = CDTXMania.Instance.Resources.Explanation("strCfgSelectMusicInformationFontFileName");
298 var prvFont = new CPrivateFastFont(CSkin.Path(Path.Combine(@"Graphics\fonts\", fontPath)), fontsize);
300 for (int j = 0; j < 2; j++)
302 var bmp = new Bitmap(512, 512);
303 g = Graphics.FromImage(bmp);
305 for (int i = 0; i < 5; i++)
308 var strComments = strInfo[i + j * 5].Split(new string[] { "\n" }, StringSplitOptions.None);
310 var r = new Regex(@"(?<PAD>\[.+?])", RegexOptions.IgnoreCase);
312 foreach (var s in strComments)
315 List<string> sss = new List<string>();
316 string ss = s.Trim();
318 #region [PAD画像部と説明文字列部を分けてListに格納]
319 Match m = r.Match(ss);
322 int padStrPos = m.Groups["PAD"].Index;
323 string padName = m.Groups["PAD"].Value;
328 ss = ss.Substring(padStrPos + padName.Length);
332 sss.Add(ss.Substring(0, padStrPos));
333 ss = ss.Substring(padStrPos + padName.Length);
341 foreach (string ls in sss)
343 string l = ls; // foreach割り当て変数の書き換えはできないので
346 if ( (l != "" )&& (l[0] == '[') ) // PAD処理
351 l = ""; g.DrawImage(ImgDrPad.LC, x, y, ImgDrPad.LC.Width, ImgDrPad.LC.Height); x += ImgDrPad.LC.Width;
354 l = ""; g.DrawImage(ImgDrPad.HH, x, y, ImgDrPad.HH.Width, ImgDrPad.HH.Height); x += ImgDrPad.HH.Width;
357 l = ""; g.DrawImage(ImgDrPad.SD, x, y, ImgDrPad.SD.Width, ImgDrPad.SD.Height); x += ImgDrPad.SD.Width;
360 l = ""; g.DrawImage(ImgDrPad.BD, x, y, ImgDrPad.BD.Width, ImgDrPad.BD.Height); x += ImgDrPad.BD.Width;
363 l = ""; g.DrawImage(ImgDrPad.HT, x, y, ImgDrPad.HT.Width, ImgDrPad.HT.Height); x += ImgDrPad.HT.Width;
366 l = ""; g.DrawImage(ImgDrPad.LT, x, y, ImgDrPad.LT.Width, ImgDrPad.LT.Height); x += ImgDrPad.LT.Width;
369 l = ""; g.DrawImage(ImgDrPad.FT, x, y, ImgDrPad.FT.Width, ImgDrPad.FT.Height); x += ImgDrPad.FT.Width;
372 l = ""; g.DrawImage(ImgDrPad.CY, x, y, ImgDrPad.CY.Width, ImgDrPad.CY.Height); x += ImgDrPad.CY.Width;
375 l = ""; g.DrawImage(ImgDrPad.RD, x, y, ImgDrPad.RD.Width, ImgDrPad.RD.Height); x += ImgDrPad.RD.Width;
378 l = ""; g.DrawImage(ImgGtPad.LC, x, y, ImgGtPad.LC.Width, ImgGtPad.LC.Height); x += ImgGtPad.LC.Width;
381 l = ""; g.DrawImage(ImgGtPad.HH, x, y, ImgGtPad.LC.Width, ImgGtPad.HH.Height); x += ImgGtPad.HH.Width;
384 l = ""; g.DrawImage(ImgGtPad.SD, x, y, ImgGtPad.SD.Width, ImgGtPad.SD.Height); x += ImgGtPad.SD.Width;
387 l = ""; g.DrawImage(ImgGtPad.LT, x, y, ImgGtPad.LT.Width, ImgGtPad.LT.Height); x += ImgGtPad.LT.Width;
390 l = ""; g.DrawImage(ImgGtPad.FT, x, y, ImgGtPad.FT.Width, ImgGtPad.FT.Height); x += ImgGtPad.FT.Width;
393 l = ""; g.DrawImage(ImgGtPad.CY, x, y, ImgGtPad.CY.Width, ImgGtPad.CY.Height); x += ImgGtPad.CY.Width;
401 if (l != "") // 通常文字列、もしくはパッド名じゃない[...]で囲まれた文字列
403 var bb = prvFont.DrawPrivateFont(ls, Color.White, Color.FromArgb(0, 0, 0));
404 g.DrawImage(bb, x, y);
405 x += prvFont.RectStrings.Width;
410 y += (int)(prvFont.RectStrings.Height * 1.2f);
413 this.txInfo[j] = TextureFactory.tテクスチャの生成(bmp, false);
415 //bmp.Save("tmptmp" + j + ".png");
425 ImgDrPad.LC.Dispose(); ImgDrPad.LC = null;
426 ImgDrPad.HH.Dispose(); ImgDrPad.HH = null;
427 ImgDrPad.SD.Dispose(); ImgDrPad.SD = null;
428 ImgDrPad.BD.Dispose(); ImgDrPad.BD = null;
429 ImgDrPad.HT.Dispose(); ImgDrPad.HT = null;
430 ImgDrPad.LT.Dispose(); ImgDrPad.LT = null;
431 ImgDrPad.FT.Dispose(); ImgDrPad.FT = null;
432 ImgDrPad.CY.Dispose(); ImgDrPad.CY = null;
433 ImgDrPad.RD.Dispose(); ImgDrPad.RD = null;
439 base.OnManagedリソースの作成();
442 public override void OnManagedリソースの解放()
446 TextureFactory.tテクスチャの解放(ref this.txInfo[0]);
447 TextureFactory.tテクスチャの解放(ref this.txInfo[1]);
448 base.OnManagedリソースの解放();
451 public override int On進行描画()
457 this.ctスクロール用 = new CCounter(0, 6000, 1, CDTXMania.Instance.Timer);
458 base.b初めての進行描画 = false;
461 if (this.ctスクロール用.b終了値に達した)
463 this.n画像Index上 = this.n画像Index下;
464 this.n画像Index下 = (this.n画像Index下 + 1) % stInfo.GetLength(0); //8;
465 this.ctスクロール用.n現在の値 = 0;
467 int n現在の値 = this.ctスクロール用.n現在の値;
470 double n現在の割合 = ((double)n現在の値) / 250.0;
471 if (this.n画像Index上 >= 0)
473 STINFO stinfo = this.stInfo[this.n画像Index上];
474 Rectangle rectangle = new Rectangle(
476 stinfo.pt左上座標.Y + ((int)((int)(512.0 / 5) * n現在の割合)),
478 Convert.ToInt32((int)(512.0 / 5 * (1.0 - n現在の割合)))
480 if (this.txInfo[stinfo.nTexture番号] != null)
482 this.txInfo[stinfo.nTexture番号].t2D描画(
483 CDTXMania.Instance.Device,
490 if (this.n画像Index下 >= 0)
492 STINFO stinfo = this.stInfo[this.n画像Index下];
493 Rectangle rectangle = new Rectangle(
497 (int)(512.0 / 5 * n現在の割合)
499 if (this.txInfo[stinfo.nTexture番号] != null)
501 this.txInfo[stinfo.nTexture番号].t2D描画(
502 CDTXMania.Instance.Device,
504 6 * Scale.Y + ((int)(512.0 / 5 * (1.0 - n現在の割合))),
512 STINFO stinfo = this.stInfo[this.n画像Index下];
513 Rectangle rectangle = new Rectangle(
519 if (this.txInfo[stinfo.nTexture番号] != null)
521 this.txInfo[stinfo.nTexture番号].t2D描画(
522 CDTXMania.Instance.Device,
538 [StructLayout(LayoutKind.Sequential)]
539 private struct STINFO
541 public int nTexture番号;
543 public STINFO(int nTexture番号, int x, int y)
545 this.nTexture番号 = nTexture番号;
546 this.pt左上座標 = new Point(x, y);
550 private CCounter ctスクロール用;
551 private int n画像Index下;
552 private int n画像Index上;
553 private readonly STINFO[] stInfo = new STINFO[] {
554 new STINFO( 0, 0, 0 ),
555 new STINFO( 0, 0, (int)(512.0 / 5 * 1)),
556 new STINFO( 0, 0, (int)(512.0 / 5 * 2)),
557 new STINFO( 0, 0, (int)(512.0 / 5 * 3)),
558 new STINFO( 0, 0, (int)(512.0 / 5 * 4)),
559 new STINFO( 1, 0, (int)(512.0 / 5 * 0)),
560 new STINFO( 1, 0, (int)(512.0 / 5 * 1)),
561 new STINFO( 1, 0, (int)(512.0 / 5 * 2)),
562 new STINFO( 1, 0, (int)(512.0 / 5 * 3))
564 private CTexture[] txInfo = new CTexture[2];
569 /// 画像の周囲から画素のない部分を削除しトリミングする
570 /// (とりあえずGetPixelを使った低速バージョン)
572 /// <param name="src"></param>
573 /// <returns></returns>
574 private Bitmap tBmpTrim(Bitmap src)
576 int x0 = 0, y0 = 0, x1 = src.Width - 1, y1 = src.Height - 1;
577 int alpha_threshold = 64;
579 #region [ 左辺のトリミング(x0を求める) ]
580 for (int px = 0; px < src.Width; px++)
582 for (int py = 0; py < src.Height; py++)
584 Color c = src.GetPixel(px, py);
585 if (c.A > alpha_threshold)
588 px = src.Width; // for break;
594 #region [ 上辺のトリミング(y0を求める) ]
595 for (int py = 0; py < src.Height; py++)
597 for (int px = 0; px < src.Width; px++)
599 Color c = src.GetPixel(px, py);
600 if (c.A > alpha_threshold)
601 //if (!c.Equals(Color.FromArgb(0, 0, 0, 0)))
604 py = src.Height; // for break;
610 #region [ 右辺のトリミング(x1を求める) ]
611 for (int px = src.Width - 1; px >= 0; px--)
613 for (int py = src.Height - 1; py >= 0; py--)
615 Color c = src.GetPixel(px, py);
616 if (c.A > alpha_threshold)
619 px = -1; // for break;
625 #region [ 右辺のトリミング(y1を求める) ]
626 for (int py = src.Height- 1; py >= 0; py--)
628 for (int px = src.Width - 1; px >= 0; px--)
630 Color c = src.GetPixel(px, py);
631 if (c.A > alpha_threshold)
634 py = -1; // for break;
641 #region [ Trim後のbmpを生成 ]
644 Bitmap bmp = new Bitmap(w, h);
645 Graphics g = Graphics.FromImage(bmp);
646 g.DrawImage(src, 0, 0, new Rectangle(x0, y0, w, h), GraphicsUnit.Pixel);
647 //(src, new Rectangle(x0, y0, w, h));