OSDN Git Service

2317cd7859eb1cfb8f35241213f4539979974ce9
[dtxmania/dtxmania.git] / DTXMania / コード / 全体 / CPreviewMagnifier.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Diagnostics;
5
6 namespace DTXMania
7 {
8         public class CPreviewMagnifier
9         {
10
11                 #region [ プロパティ(拡大率等の取得) ]
12                 /// <summary>
13                 /// 拡大後のwidth
14                 /// </summary>
15                 public int width;
16                 /// <summary>
17                 /// 拡大後のheight
18                 /// </summary>
19                 public int height;
20                 /// <summary>
21                 /// 拡大後のX拡大率
22                 /// </summary>
23                 public float magX;
24                 /// <summary>
25                 /// 拡大後のY拡大率
26                 /// </summary>
27                 public float magY;
28
29                 public int px;
30                 public int py;
31
32                 private int freestyle_w, freestyle_h;
33
34                 /// <summary>
35                 /// プレビュー画像向けの拡大率か(それとも、演奏画面向けの拡大率か)
36                 /// </summary>
37                 public enum EPreviewType : int
38                 {
39                         MusicSelect = 0,                        // 選曲画面
40                         PlayingFront = 1,                       // 演奏画面(ウインドウ表示の動画,サイズ固定(従来方式)
41                         PlayingBackground = 2,          // 演奏画面(背景全画面表示の動画)
42                         PlayingFrontScalable = 3        // 演奏画面(ウインドウ表示の動画,サイズ可変
43                 }
44                 public EPreviewType ePreviewType;
45                 #endregion
46
47                 #region [ 定数定義 ]
48                 // 配列の0,1要素はそれぞれ, Preview用, 演奏画面用
49                 private int[] WIDTH_VGA_SET = { 204, 278, 640 };                     // VGA版DTXManiaのプレビュー画像width値
50                 private int[] HEIGHT_VGA_SET = { 269, 355, 1920 };                      // VGA版DTXManiaのプレビュー画像height値
51                 private int[] WIDTH_HD_SET = { 400, 400, 1920 };                      // HD版DTXManiaのプレビュー画像width値
52                 private int[] HEIGHT_HD_SET = { 400, 600, 1080 }; // 600は仮                                                          // HD版DTXManiaのプレビュー画像height値
53                 private int[] WIDTH_FHD_LIMIT = { 320, 320, 640 };                     // VGA版/FullHD版どちらのプレビュー画像とみなすかのwidth閾値
54                 private int[] HEIGHT_FHD_LIMIT = { 416, 416, 480 };                      // VGA版/FullHD版どちらのプレビュー画像とみなすかのwidth閾値
55                 private int[] WIDTH_FHD_SET = { (int)(204 * Scale.X), (int)(278 * 2), 1920 }; // FHD版DTXManiaのプレビュー画像height値
56                 private int[] HEIGHT_FHD_SET = { (int)(269 * Scale.Y), (int)(355 * 2), 1080 };  // FHD版DTXManiaのプレビュー画像height値
57                                                                                                                                                                                 // #37227 2017.5.29 yyagi 105以降の新演奏画面では、BGA/AVI領域の縦横倍率はx2
58                 #endregion
59
60
61                 #region [ コンストラクタ ]
62                 /// <summary>
63                 /// コンストラクタ
64                 /// </summary>
65                 public CPreviewMagnifier()
66                 {
67                 }
68                 public CPreviewMagnifier(EPreviewType _ePreviewType)
69                 {
70                         CPreviewMagnifier_initializer(_ePreviewType, 0, 0, 1, 1);
71                 }
72                 public CPreviewMagnifier( EPreviewType _ePreviewType, int _px, int _py )
73                 {
74                         CPreviewMagnifier_initializer( _ePreviewType, _px, _py, 1, 1 );
75                 }
76                 public CPreviewMagnifier(EPreviewType _ePreviewType, int _px, int _py, int _w, int _h)
77                 {
78                         CPreviewMagnifier_initializer(_ePreviewType, _px, _py, _w, _h);
79                 }
80                 private void CPreviewMagnifier_initializer(EPreviewType _ePreviewType, int _px, int _py, int _w, int _h)
81                 {
82                         this.ePreviewType = _ePreviewType;
83                         this.px = _px;
84                         this.py = _py;
85                         this.freestyle_w = _w;
86                         this.freestyle_h = _h;
87                 }
88                 #endregion
89
90                 /// <summary>
91                 /// 拡大率の取得
92                 /// </summary>
93                 /// <param name="width_org">元の幅</param>
94                 /// <param name="height_org">元の高さ</param>
95                 /// <param name="magX_org">元の拡大率(幅)</param>
96                 /// <param name="magY_org">元の拡大率(高さ)</param>
97                 /// <remarks>出力はプロパティで得てください。</remarks>
98                 public void GetMagnifier(int width_org, int height_org, float magX_org, float magY_org)
99                 {
100                         //bool bIsPreview = ( this.ePreviewType == EPreviewType.MusicSelect );
101
102                         // #35820 画像サイズに関係なく、プレビュー領域に合わせる add ikanick 15.12.08
103                         // #36176 プレビュー画像については、前仕様(204x269)画像はアスペクト比を維持する change ikanick 16.03.20
104
105                         if ( this.ePreviewType == EPreviewType.PlayingBackground )      // フル背景動画に限り、上位指定の表示座標を無視する
106                         {
107                                 this.px = this.py = 0;
108                         }
109
110                         #region [ アスペクト比を維持した拡大縮小 ]
111                         this.width = width_org;
112                         this.height = height_org;
113                         int W = (this.ePreviewType == EPreviewType.PlayingFrontScalable)? freestyle_w : width_fhd_set;
114                         int H = (this.ePreviewType == EPreviewType.PlayingFrontScalable)? freestyle_h : height_fhd_set;
115                         this.magX = magX_org * W  / width_org;
116                         this.magY = magY_org * H / height_org;
117
118                         if ( magX > magY )
119                         {
120                                 magX = magY;
121                                 px += (int) ( ( W - ( width_org * magY ) ) / 2 );
122                         }
123                         else
124                         {
125                                 magY = magX;
126                                 py += (int) ( ( H - ( height_org * magX ) ) / 2 );
127                         }
128                         #endregion
129                 }
130
131                 #region [ bIsPreviewによる配列→定数読み替え ]
132                 private int width_vga_set
133                 {
134                         get
135                         {
136                                 return WIDTH_VGA_SET[ (int)ePreviewType ];
137                         }
138                 }
139                 private int height_vga_set
140                 {
141                         get
142                         {
143                                 return HEIGHT_VGA_SET[ (int)ePreviewType ];
144                         }
145                 }
146                 private int width_hd_set
147                 {
148                         get
149                         {
150                                 return WIDTH_HD_SET[ (int)ePreviewType ];
151                         }
152                 }
153                 private int height_hd_set
154                 {
155                         get
156                         {
157                                 return HEIGHT_HD_SET[ (int)ePreviewType ];
158                         }
159                 }
160                 private int width_fhd_limit
161                 {
162                         get
163                         {
164                                 return WIDTH_FHD_LIMIT[ (int)ePreviewType ];
165                         }
166                 }
167                 private int height_fhd_limit
168                 {
169                         get
170                         {
171                                 return HEIGHT_FHD_LIMIT[ (int)ePreviewType ];
172                         }
173                 }
174                 private int width_fhd_set
175                 {
176                         get
177                         {
178                                 return WIDTH_FHD_SET[ (int)ePreviewType ];
179                         }
180                 }
181                 private int height_fhd_set
182                 {
183                         get
184                         {
185                                 return HEIGHT_FHD_SET[ (int)ePreviewType ];
186                         }
187                 }
188                 #endregion
189         }
190 }