Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / windows / GUIWindowScreensaverDim.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 "GUIWindowScreensaverDim.h"
22 #include "guilib/GraphicContext.h"
23 #include "guilib/GUITexture.h"
24 #include "Application.h"
25 #include <climits>
26
27 CGUIWindowScreensaverDim::CGUIWindowScreensaverDim(void)
28     : CGUIDialog(WINDOW_SCREENSAVER_DIM, "")
29 {
30   m_needsScaling = false;
31   m_dimLevel = 100.0f;
32   m_animations.push_back(CAnimation::CreateFader(0, 100, 0, 1000, ANIM_TYPE_WINDOW_OPEN));
33   m_animations.push_back(CAnimation::CreateFader(100, 0, 0, 1000, ANIM_TYPE_WINDOW_CLOSE));
34   m_renderOrder = INT_MAX;
35 }
36
37 CGUIWindowScreensaverDim::~CGUIWindowScreensaverDim(void)
38 {
39 }
40
41 void CGUIWindowScreensaverDim::UpdateVisibility()
42 {
43   float level = g_application.GetDimScreenSaverLevel();
44   if (level)
45   {
46     m_dimLevel = level;
47     Show();
48   }
49   else
50     Close();
51 }
52
53 void CGUIWindowScreensaverDim::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
54 {
55   CGUIDialog::Process(currentTime, dirtyregions);
56   m_renderRegion.SetRect(0, 0, (float)g_graphicsContext.GetWidth(), (float)g_graphicsContext.GetHeight());
57 }
58
59 void CGUIWindowScreensaverDim::Render()
60 {
61   // draw a translucent black quad - fading is handled by the window animation
62   color_t color = ((color_t)(m_dimLevel * 2.55f) & 0xff) << 24;
63   color = g_graphicsContext.MergeAlpha(color);
64   CRect rect(0, 0, (float)g_graphicsContext.GetWidth(), (float)g_graphicsContext.GetHeight());
65   CGUITexture::DrawQuad(rect, color);
66   CGUIDialog::Render();
67 }