Merge pull request #4314 from MartijnKaijser/beta1
[vuplus_xbmc] / xbmc / settings / windows / GUIWindowTestPattern.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "GUIWindowTestPattern.h"
22 #include "settings/DisplaySettings.h"
23 #include "guilib/GUIWindowManager.h"
24 #include "guilib/Key.h"
25 #include "guilib/WindowIDs.h"
26 #include "windowing/WindowingFactory.h"
27
28
29 CGUIWindowTestPattern::CGUIWindowTestPattern(void)
30     : CGUIWindow(WINDOW_TEST_PATTERN, "")
31     , m_white(1.0)
32     , m_black(0.0)
33 {
34   m_pattern = 0;
35   m_bounceX = 0;
36   m_bounceY = 0;
37   m_bounceDirectionX = 0;
38   m_bounceDirectionY = 0;
39   m_blinkFrame = 0;
40   m_needsScaling = false;
41 }
42
43 CGUIWindowTestPattern::~CGUIWindowTestPattern(void)
44 {}
45
46
47 bool CGUIWindowTestPattern::OnAction(const CAction &action)
48 {
49   switch (action.GetID())
50   {
51   case ACTION_MOVE_UP:
52   case ACTION_MOVE_LEFT:
53     m_pattern = m_pattern > 0 ? m_pattern - 1 : TEST_PATTERNS_COUNT - 1;
54     SetInvalid();
55     return true;
56
57   case ACTION_MOVE_DOWN:
58   case ACTION_MOVE_RIGHT:
59     m_pattern = (m_pattern + 1) % TEST_PATTERNS_COUNT;
60     SetInvalid();
61     return true;
62   }
63   return CGUIWindow::OnAction(action); // base class to handle basic movement etc.
64 }
65
66 bool CGUIWindowTestPattern::OnMessage(CGUIMessage& message)
67 {
68   switch (message.GetMessage())
69   {
70   case GUI_MSG_WINDOW_INIT:
71     m_pattern = 0;
72     m_bounceDirectionX = 1;
73     m_bounceDirectionY = 1;
74     m_bounceX = 0;
75     m_bounceY = 0;
76     m_blinkFrame = 0;
77     break;
78
79   }
80   return CGUIWindow::OnMessage(message);
81 }
82
83 void CGUIWindowTestPattern::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
84 {
85   if (m_pattern == 0 || m_pattern == 4)
86     MarkDirtyRegion();
87   CGUIWindow::Process(currentTime, dirtyregions);
88   m_renderRegion.SetRect(0, 0, (float)g_graphicsContext.GetWidth(), (float)g_graphicsContext.GetHeight());
89
90
91   if(g_Windowing.UseLimitedColor())
92   {
93     m_white = 235.0f / 255;
94     m_black =  16.0f / 255;
95   }
96   else
97   {
98     m_white = 1.0f;
99     m_black = 0.0f;
100   }
101 }
102
103 void CGUIWindowTestPattern::Render()
104 {
105   BeginRender();
106   const RESOLUTION_INFO info = g_graphicsContext.GetResInfo();
107
108   int top    = info.Overscan.top;
109   int bottom = info.Overscan.bottom;
110   int left   = info.Overscan.left;
111   int right  = info.Overscan.right;
112
113   switch (m_pattern)
114   {
115     case 0:
116       DrawContrastBrightnessPattern(top, left, bottom, right);
117       break;
118
119     case 1:
120       DrawVerticalLines(top, left, bottom, right);
121       break;
122
123     case 2:
124       DrawHorizontalLines(top, left, bottom, right);
125       break;
126
127     case 3:
128       DrawCheckers(top, left, bottom, right);
129       break;
130
131     case 4:
132       DrawBouncingRectangle(top, left, bottom, right);
133       break;
134   }
135
136   EndRender();
137
138   CGUIWindow::Render();
139 }
140