2 * Copyright (C) 2005-2013 Team XBMC
5 * Test patterns designed by Ofer LaOr - hometheater.co.il
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)
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.
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/>.
23 #include "GUIWindowTestPatternDX.h"
24 #include "windowing/WindowingFactory.h"
26 #define M_PI 3.14159265358979323846
29 #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
31 CGUIWindowTestPatternDX::CGUIWindowTestPatternDX(void) : CGUIWindowTestPattern()
35 CGUIWindowTestPatternDX::~CGUIWindowTestPatternDX(void)
39 void CGUIWindowTestPatternDX::DrawVerticalLines(int top, int left, int bottom, int right)
41 CUSTOMVERTEX* vert = new CUSTOMVERTEX[2+(right-left)];
43 for (int i = left; i <= right; i += 2)
46 vert[p].y = (float)top;
49 vert[p].color = 0xffffffff;
52 vert[p].y = (float)bottom;
55 vert[p].color = 0xffffffff;
58 g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
59 g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_LINELIST, p/2, vert, sizeof(CUSTOMVERTEX));
64 void CGUIWindowTestPatternDX::DrawHorizontalLines(int top, int left, int bottom, int right)
66 CUSTOMVERTEX* vert = new CUSTOMVERTEX[2+(bottom-top)];
68 for (int i = top; i <= bottom; i += 2)
70 vert[p].x = (float)left;
74 vert[p].color = 0xffffffff;
76 vert[p].x = (float)right;
80 vert[p].color = 0xffffffff;
83 g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
84 g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_LINELIST, p/2, vert, sizeof(CUSTOMVERTEX));
89 void CGUIWindowTestPatternDX::DrawCheckers(int top, int left, int bottom, int right)
91 int c = (bottom-top+1)*(1+(right-left)/2);
92 CUSTOMVERTEX* vert = new CUSTOMVERTEX[c];
94 for (int y = top; y <= bottom; y++)
96 for (int x = left; x <= right; x += 2)
100 vert[i].x = (float)x;
101 vert[i].y = (float)y;
104 vert[i].color = 0xffffffff;
108 vert[i].x = (float)x+1.0f;
109 vert[i].y = (float)y;
112 vert[i].color = 0xffffffff;
117 g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
118 g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_POINTLIST, i, vert, sizeof(CUSTOMVERTEX));
123 void CGUIWindowTestPatternDX::DrawBouncingRectangle(int top, int left, int bottom, int right)
125 m_bounceX += m_bounceDirectionX;
126 m_bounceY += m_bounceDirectionY;
128 if ((m_bounceDirectionX == 1 && m_bounceX + TEST_PATTERNS_BOUNCE_SQUARE_SIZE == right) || (m_bounceDirectionX == -1 && m_bounceX == left))
129 m_bounceDirectionX = -m_bounceDirectionX;
131 if ((m_bounceDirectionY == 1 && m_bounceY + TEST_PATTERNS_BOUNCE_SQUARE_SIZE == bottom) || (m_bounceDirectionY == -1 && m_bounceY == top))
132 m_bounceDirectionY = -m_bounceDirectionY;
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);
137 void CGUIWindowTestPatternDX::DrawContrastBrightnessPattern(int top, int left, int bottom, int right)
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)));
159 m_blinkFrame = (m_blinkFrame + 1) % TEST_PATTERNS_BLINK_CYCLE;
161 // draw main quadrants
162 DrawRectangle(x50p, (float)top, (float)right, y50p, 0xffffffff);
163 DrawRectangle((float)left, (float)y50p, x50p, (float)bottom, 0xffffffff);
166 CUSTOMVERTEX vert[] =
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},
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}
186 g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
187 g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_LINELIST, 8, vert, sizeof(CUSTOMVERTEX));
189 // draw inner rectangles
190 DrawRectangle(x12p, y12p, x37p, y37p, 0xffffffff);
191 DrawRectangle(x62p, y62p, x87p, y87p, 0xffffffff);
193 DrawRectangle(x62p, y12p, x87p, y37p, 0xff000000);
194 DrawRectangle(x12p, y62p, x37p, y87p, 0xff000000);
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);
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);
204 if (m_blinkFrame < TEST_PATTERNS_BLINK_CYCLE / 2)
205 color = D3DCOLOR_COLORVALUE(0.95f, 0.95f, 0.95f, 1.0f);
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);
212 void CGUIWindowTestPatternDX::DrawCircle(int originX, int originY, int radius)
214 DrawCircleEx((float)originX, (float)originY, (float)radius, 0xffffffff);
217 void CGUIWindowTestPatternDX::DrawCircleEx(float originX, float originY, float radius, DWORD color)
222 float vectorY1 = originY;
223 float vectorX1 = originX;
224 CUSTOMVERTEX vert[1083]; // 361*3
227 for (int i = 0; i <= 360; i++)
229 angle = (float)(((double)i)/57.29577957795135);
230 vectorX = originX + (radius*(float)sin((double)angle));
231 vectorY = originY + (radius*(float)cos((double)angle));
236 vert[p].color = color;
238 vert[p].x = vectorX1;
239 vert[p].y = vectorY1;
242 vert[p].color = color;
248 vert[p].color = color;
253 g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
254 g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 361, vert, sizeof(CUSTOMVERTEX));
257 void CGUIWindowTestPatternDX::BeginRender()
259 g_Windowing.Get3DDevice()->Clear(0, NULL, D3DCLEAR_TARGET, 0, 0, 0);
262 void CGUIWindowTestPatternDX::EndRender()
266 void CGUIWindowTestPatternDX::DrawRectangle(float x, float y, float x2, float y2, DWORD color)
268 CUSTOMVERTEX vert[] =
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},
276 g_Windowing.Get3DDevice()->SetFVF(D3DFVF_CUSTOMVERTEX);
277 g_Windowing.Get3DDevice()->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 3, vert, sizeof(CUSTOMVERTEX));