OSDN Git Service

5ad2f7a99ae6063f0c3aebe00ce3f4d3014d1f15
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / DTXManiaプロジェクト / コード / ステージ / CActLVLNFont.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Runtime.InteropServices;
5 using System.Drawing;
6 using System.Diagnostics;
7 using SlimDX;
8 using FDK;
9
10 namespace DTXMania
11 {
12         public class CActLVLNFont : CActivity
13         {
14                 // コンストラクタ
15
16                 const int numWidth = 15;
17                 const int numHeight = 19;
18
19                 public CActLVLNFont()
20                 {
21                         string numChars = "0123456789?-";
22                         st数字 = new ST数字[12, 4];
23
24                         for (int j = 0; j < 4; j++)
25                         {
26                                 for (int i = 0; i < 12; i++)
27                                 {
28                                         this.st数字[i, j].ch = numChars[i];
29                                         this.st数字[i, j].rc = new Rectangle(
30                                                                                                 (i % 4) * numWidth + (j % 2) * 64,
31                                                                                                 (i / 4) * numHeight + (j / 2) * 64,
32                                                                                                 numWidth,
33                                                                                                 numHeight
34                                         );
35                                 }
36                         }
37                 }
38
39
40                 // メソッド
41                 public void t文字列描画(int x, int y, string str)
42                 {
43                         this.t文字列描画(x, y, str, EFontColor.White, EFontAlign.Right);
44                 }
45                 public void t文字列描画(int x, int y, string str, EFontColor efc, EFontAlign efa)
46                 {
47                         //if (!base.b活性化してない && !string.IsNullOrEmpty(str))
48                         if ( !string.IsNullOrEmpty(str))
49                         {
50                                 if (this.tx数値 != null)
51                                 {
52                                         bool bRightAlign = (efa == EFontAlign.Right);
53                     bool bCenterAlign = (efa == EFontAlign.Center);
54
55                                         if (bRightAlign)                                                        // 右詰なら文字列反転して右から描画
56                                         {
57                                                 char[] chars = str.ToCharArray();
58                                                 Array.Reverse(chars);
59                                                 str = new string(chars);
60                                         }
61                     else if( bCenterAlign )
62                     {
63                         //Centerの場合は左から。ただし開始時のX座標をマイナス方向にずらしておく。
64                         //(フォントの幅 * 文字数) / 2
65                         x -= (15 * str.Length) / 2;
66                     }
67
68                                         foreach (char ch in str)
69                                         {
70                                                 int p = (ch == '-' ? 11 : ch - '0');
71                                                 ST数字 s = st数字[p, (int)efc];
72                                                 int sw = s.rc.Width;
73                                                 int delta = bRightAlign ? 0 : -sw;
74                                                 this.tx数値.t2D描画(CDTXMania.app.Device, x + delta, y, s.rc);
75                                                 x += bRightAlign ? -sw : sw;
76                                         }
77                                 }
78                         }
79                 }
80
81
82                 // CActivity 実装
83
84                 public override void OnManagedリソースの作成()
85                 {
86                         if (!base.b活性化してない)
87                         {
88                                 this.tx数値 = CDTXMania.tテクスチャの生成(CSkin.Path(@"Graphics\ScreenSelect level numbers.png"));
89                                 base.OnManagedリソースの作成();
90                         }
91                 }
92                 public override void OnManagedリソースの解放()
93                 {
94                         if (!base.b活性化してない)
95                         {
96                                 if ( this.tx数値 != null )
97                                 {
98                                         this.tx数値.Dispose();
99                                         this.tx数値 = null;
100                                 }
101                                 base.OnManagedリソースの解放();
102                         }
103                 }
104
105
106                 // その他
107
108                 #region [ private ]
109                 //-----------------
110                 [StructLayout(LayoutKind.Sequential)]
111                 private struct ST数字
112                 {
113                         public char ch;
114                         public Rectangle rc;
115                 }
116
117                 public enum EFontColor
118                 {
119                         Red = 0,
120                         Yellow = 1,
121                         Orange = 2,
122                         White = 3
123                 }
124                 public enum EFontAlign
125                 {
126                         Left,
127                         Right,
128             Center //2017.05.20 kairera0467
129                 }
130                 private ST数字[,] st数字;
131                 private CTexture tx数値;
132                 //-----------------
133                 #endregion
134         }
135 }