changed: Add logic to properly handle subtitles for stacked files
[vuplus_xbmc] / xbmc / rendering / dx / GUIWindowTestPatternDX.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *      Test patterns designed by Ofer LaOr - hometheater.co.il
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include "GUIWindowTestPatternDX.h"
24 #include "windowing/WindowingFactory.h"
25 #ifndef M_PI
26   #define M_PI       3.14159265358979323846
27 #endif
28
29 #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
30
31 CGUIWindowTestPatternDX::CGUIWindowTestPatternDX(void) : CGUIWindowTestPattern()
32 {
33 }
34
35 CGUIWindowTestPatternDX::~CGUIWindowTestPatternDX(void)
36 {
37 }
38
39 void CGUIWindowTestPatternDX::DrawVerticalLines(int top, int left, int bottom, int right)
40 {
41   CUSTOMVERTEX* vert = new CUSTOMVERTEX[2+(right-left)];
42   int p = 0;
43   for (int i = left; i <= right; i += 2)
44   {
45     vert[p].x = (float)i;
46     vert[p].y = (float)top;
47     vert[p].z = 0.5f;
48     vert[p].rhw = 1.0f;
49     vert[p].color = 0xffffffff;
50     ++p;
51     vert[p].x = (float)i;
52     vert[p].y = (float)bottom;
53     vert[p].z = 0.5f;
54     vert[p].rhw = 1.0f;
55     vert[p].color = 0xffffffff;
56     ++p;
57   }
58   g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
59   g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_LINELIST, p/2, vert, sizeof(CUSTOMVERTEX));
60
61   delete [] vert;
62 }
63
64 void CGUIWindowTestPatternDX::DrawHorizontalLines(int top, int left, int bottom, int right)
65 {
66   CUSTOMVERTEX* vert = new CUSTOMVERTEX[2+(bottom-top)];
67   int p = 0;
68   for (int i = top; i <= bottom; i += 2)
69   {
70     vert[p].x = (float)left;
71     vert[p].y = (float)i;
72     vert[p].z = 0.5f;
73     vert[p].rhw = 1.0f;
74     vert[p].color = 0xffffffff;
75     ++p;
76     vert[p].x = (float)right;
77     vert[p].y = (float)i;
78     vert[p].z = 0.5f;
79     vert[p].rhw = 1.0f;
80     vert[p].color = 0xffffffff;
81     ++p;
82   }
83   g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
84   g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_LINELIST, p/2, vert, sizeof(CUSTOMVERTEX));
85
86   delete [] vert;
87 }
88
89 void CGUIWindowTestPatternDX::DrawCheckers(int top, int left, int bottom, int right)
90 {
91   int c = (bottom-top+1)*(1+(right-left)/2);
92   CUSTOMVERTEX* vert = new CUSTOMVERTEX[c];
93   int i=0;
94   for (int y = top; y <= bottom; y++)
95   {
96     for (int x = left; x <= right; x += 2)
97     {
98       if (y % 2 == 0)
99       {
100         vert[i].x = (float)x;
101         vert[i].y = (float)y;
102         vert[i].z = 0.5f;
103         vert[i].rhw = 1.0f;
104         vert[i].color = 0xffffffff;
105       }
106       else
107       {
108         vert[i].x = (float)x+1.0f;
109         vert[i].y = (float)y;
110         vert[i].z = 0.5f;
111         vert[i].rhw = 1.0f;
112         vert[i].color = 0xffffffff;
113       }
114       ++i;
115     }
116   }
117   g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
118   g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_POINTLIST, i, vert, sizeof(CUSTOMVERTEX));
119
120   delete [] vert;
121 }
122
123 void CGUIWindowTestPatternDX::DrawBouncingRectangle(int top, int left, int bottom, int right)
124 {
125   m_bounceX += m_bounceDirectionX;
126   m_bounceY += m_bounceDirectionY;
127
128   if ((m_bounceDirectionX == 1 && m_bounceX + TEST_PATTERNS_BOUNCE_SQUARE_SIZE == right) || (m_bounceDirectionX == -1 && m_bounceX == left))
129     m_bounceDirectionX = -m_bounceDirectionX;
130
131   if ((m_bounceDirectionY == 1 && m_bounceY + TEST_PATTERNS_BOUNCE_SQUARE_SIZE == bottom) || (m_bounceDirectionY == -1 && m_bounceY == top))
132     m_bounceDirectionY = -m_bounceDirectionY;
133
134   DrawRectangle((float)m_bounceX, (float)m_bounceY, (float)(m_bounceX + TEST_PATTERNS_BOUNCE_SQUARE_SIZE), (float)(m_bounceY + TEST_PATTERNS_BOUNCE_SQUARE_SIZE), 0xffffffff);
135 }
136
137 void CGUIWindowTestPatternDX::DrawContrastBrightnessPattern(int top, int left, int bottom, int right)
138 {
139   DWORD color = 0xffffffff;
140   float x5p = (float) (left + (0.05f * (right - left)));
141   float y5p = (float) (top + (0.05f * (bottom - top)));
142   float x12p = (float) (left + (0.125f * (right - left)));
143   float y12p = (float) (top + (0.125f * (bottom - top)));
144   float x25p = (float) (left + (0.25f * (right - left)));
145   float y25p = (float) (top + (0.25f * (bottom - top)));
146   float x37p = (float) (left + (0.375f * (right - left)));
147   float y37p = (float) (top + (0.375f * (bottom - top)));
148   float x50p = (float)(left + (right - left) / 2);
149   float y50p = (float)(top + (bottom - top) / 2);
150   float x62p = (float) (left + (0.625f * (right - left)));
151   float y62p = (float) (top + (0.625f * (bottom - top)));
152   float x75p = (float) (left + (0.75f * (right - left)));
153   float y75p = (float) (top + (0.75f * (bottom - top)));
154   float x87p = (float) (left + (0.875f * (right - left)));
155   float y87p = (float) (top + (0.875f * (bottom - top)));
156   float x95p = (float) (left + (0.95f * (right - left)));
157   float y95p = (float) (top + (0.95f * (bottom - top)));
158
159   m_blinkFrame = (m_blinkFrame + 1) % TEST_PATTERNS_BLINK_CYCLE;
160
161   // draw main quadrants
162   DrawRectangle(x50p, (float)top, (float)right, y50p, 0xffffffff);
163   DrawRectangle((float)left, (float)y50p, x50p, (float)bottom, 0xffffffff);
164
165   // draw border lines
166   CUSTOMVERTEX vert[] = 
167   {
168     {(float)left, y5p, 0.5f, 1.0f, 0xffffffff},
169     {x50p, y5p, 0.5f, 1.0f, 0xffffffff},
170     {x5p, (float)top, 0.5f, 1.0f, 0xffffffff},
171     {x5p, y50p, 0.5f, 1.0f, 0xffffffff},
172     {x50p, y95p, 0.5f, 1.0f, 0xffffffff},
173     {(float)right, y95p, 0.5f, 1.0f, 0xffffffff},
174     {x95p, y50p, 0.5f, 1.0f, 0xffffffff},
175     {x95p, (float)bottom, 0.5f, 1.0f, 0xffffffff},
176
177     {x50p, y5p, 0.5f, 1.0f, 0xff000000},
178     {(float)right, y5p, 0.5f, 1.0f, 0xff000000},
179     {x5p, y50p, 0.5f, 1.0f, 0xff000000},
180     {x5p, (float)bottom, 0.5f, 1.0f, 0xff000000},
181     {(float)left, y95p, 0.5f, 1.0f, 0xff000000},
182     {x50p, y95p, 0.5f, 1.0f, 0xff000000},
183     {x95p, (float)top, 0.5f, 1.0f, 0xff000000},
184     {x95p, y50p, 0.5f, 1.0f, 0xff000000}
185   };
186   g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
187   g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_LINELIST, 8, vert, sizeof(CUSTOMVERTEX));
188
189   // draw inner rectangles
190   DrawRectangle(x12p, y12p, x37p, y37p, 0xffffffff);
191   DrawRectangle(x62p, y62p, x87p, y87p, 0xffffffff);
192
193   DrawRectangle(x62p, y12p, x87p, y37p, 0xff000000);
194   DrawRectangle(x12p, y62p, x37p, y87p, 0xff000000);
195
196   // draw inner circles
197   if (m_blinkFrame < TEST_PATTERNS_BLINK_CYCLE / 2)
198     color = D3DCOLOR_COLORVALUE(0.05f, 0.05f, 0.05f, 1.0f);
199   else
200     color = D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.0f, 1.0f);
201   DrawCircleEx(x25p, y75p, (y37p - y12p) / 3, color);
202   DrawCircleEx(x75p, y25p, (y37p - y12p) / 3, color);
203
204   if (m_blinkFrame < TEST_PATTERNS_BLINK_CYCLE / 2)
205     color = D3DCOLOR_COLORVALUE(0.95f, 0.95f, 0.95f, 1.0f);
206   else
207     color = D3DCOLOR_COLORVALUE(1.0f, 1.0f, 1.0f, 1.0f);
208   DrawCircleEx(x25p, y25p, (y37p - y12p) / 3, color);
209   DrawCircleEx(x75p, y75p, (y37p - y12p) / 3, color);
210 }
211
212 void CGUIWindowTestPatternDX::DrawCircle(int originX, int originY, int radius)
213 {
214   DrawCircleEx((float)originX, (float)originY, (float)radius, 0xffffffff);
215 }
216
217 void CGUIWindowTestPatternDX::DrawCircleEx(float originX, float originY, float radius, DWORD color)
218 {
219   float angle;
220   float vectorX;
221   float vectorY;
222   float vectorY1 = originY;
223   float vectorX1 = originX;
224   CUSTOMVERTEX vert[1083]; // 361*3
225   int p = 0;
226
227   for (int i = 0; i <= 360; i++)
228   {
229     angle = (float)(((double)i)/57.29577957795135);
230     vectorX = originX + (radius*(float)sin((double)angle));
231     vectorY = originY + (radius*(float)cos((double)angle));
232     vert[p].x = originX;
233     vert[p].y = originY;
234     vert[p].z = 0.5f;
235     vert[p].rhw = 1.0f;
236     vert[p].color = color;
237     ++p;
238     vert[p].x = vectorX1;
239     vert[p].y = vectorY1;
240     vert[p].z = 0.5f;
241     vert[p].rhw = 1.0f;
242     vert[p].color = color;
243     ++p;
244     vert[p].x = vectorX;
245     vert[p].y = vectorY;
246     vert[p].z = 0.5f;
247     vert[p].rhw = 1.0f;
248     vert[p].color = color;
249     ++p;
250     vectorY1 = vectorY;
251     vectorX1 = vectorX;
252   }
253   g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
254   g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 361, vert, sizeof(CUSTOMVERTEX));
255 }
256
257 void CGUIWindowTestPatternDX::BeginRender()
258 {
259   g_Windowing.Get3DDevice()->Clear(0, NULL, D3DCLEAR_TARGET, 0, 0, 0);
260 }
261
262 void CGUIWindowTestPatternDX::EndRender()
263 {
264 }
265
266 void CGUIWindowTestPatternDX::DrawRectangle(float x, float y, float x2, float y2, DWORD color)
267 {
268   CUSTOMVERTEX vert[] = 
269   {
270     {x, y, 0.5f, 1.0f, color},
271     {x2, y, 0.5f, 1.0f, color},
272     {x2, y2, 0.5f, 1.0f, color},
273     {x, y2, 0.5f, 1.0f, color},
274     {x, y, 0.5f, 1.0f, color},
275   };
276   g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
277   g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 3, vert, sizeof(CUSTOMVERTEX));
278 }