[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / windows / GUIWindowScreensaver.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.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 "system.h"
22 #include "GUIWindowScreensaver.h"
23 #include "addons/AddonManager.h"
24 #include "Application.h"
25 #include "GUIPassword.h"
26 #include "settings/GUISettings.h"
27 #include "GUIUserMessages.h"
28 #include "guilib/GUIWindowManager.h"
29 #include "threads/SingleLock.h"
30
31 using namespace ADDON;
32
33 CGUIWindowScreensaver::CGUIWindowScreensaver(void)
34     : CGUIWindow(WINDOW_SCREENSAVER, "")
35 {
36 }
37
38 CGUIWindowScreensaver::~CGUIWindowScreensaver(void)
39 {
40 }
41
42 void CGUIWindowScreensaver::Process(unsigned int currentTime, CDirtyRegionList &regions)
43 {
44   MarkDirtyRegion();
45   CGUIWindow::Process(currentTime, regions);
46   m_renderRegion.SetRect(0, 0, (float)g_graphicsContext.GetWidth(), (float)g_graphicsContext.GetHeight());
47 }
48
49 void CGUIWindowScreensaver::Render()
50 {
51   CSingleLock lock (m_critSection);
52
53 #ifdef HAS_SCREENSAVER
54   if (m_addon)
55   {
56     if (m_bInitialized)
57     {
58       try
59       {
60         //some screensavers seem to be depending on xbmc clearing the screen
61         //       g_Windowing.Get3DDevice()->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00010001, 1.0f, 0L );
62         g_graphicsContext.CaptureStateBlock();
63         m_addon->Render();
64         g_graphicsContext.ApplyStateBlock();
65       }
66       catch (...)
67       {
68         CLog::Log(LOGERROR, "SCREENSAVER: - Exception in Render() - %s", m_addon->Name().c_str());
69       }
70       return ;
71     }
72     else
73     {
74       try
75       {
76         m_addon->Start();
77         m_bInitialized = true;
78       }
79       catch (...)
80       {
81         CLog::Log(LOGERROR, "SCREENSAVER: - Exception in Start() - %s", m_addon->Name().c_str());
82       }
83       return ;
84     }
85   }
86 #endif
87   CGUIWindow::Render();
88 }
89
90 bool CGUIWindowScreensaver::OnAction(const CAction &action)
91 {
92   // We're just a screen saver, nothing to do here
93   return false;
94 }
95
96 // called when the mouse is moved/clicked etc. etc.
97 EVENT_RESULT CGUIWindowScreensaver::OnMouseEvent(const CPoint &point, const CMouseEvent &event)
98 {
99   g_windowManager.PreviousWindow();
100   return EVENT_RESULT_HANDLED;
101 }
102
103 bool CGUIWindowScreensaver::OnMessage(CGUIMessage& message)
104 {
105   switch ( message.GetMessage() )
106   {
107   case GUI_MSG_WINDOW_DEINIT:
108     {
109       CSingleLock lock (m_critSection);
110 #ifdef HAS_SCREENSAVER
111       if (m_addon)
112       {
113         m_addon->Stop();
114         g_graphicsContext.ApplyStateBlock();
115         m_addon->Destroy();
116         m_addon.reset();
117       }
118 #endif
119       m_bInitialized = false;
120
121       // remove z-buffer
122 //      RESOLUTION res = g_graphicsContext.GetVideoResolution();
123  //     g_graphicsContext.SetVideoResolution(res, FALSE);
124
125       // enable the overlay
126       g_windowManager.ShowOverlay(OVERLAY_STATE_SHOWN);
127     }
128     break;
129
130   case GUI_MSG_WINDOW_INIT:
131     {
132       CGUIWindow::OnMessage(message);
133       CSingleLock lock (m_critSection);
134
135 #ifdef HAS_SCREENSAVER
136       assert(!m_addon);
137       m_bInitialized = false;
138
139       m_addon.reset();
140       // Setup new screensaver instance
141       AddonPtr addon;
142       if (!CAddonMgr::Get().GetAddon(g_guiSettings.GetString("screensaver.mode"), addon, ADDON_SCREENSAVER))
143         return false;
144
145       m_addon = boost::dynamic_pointer_cast<CScreenSaver>(addon);
146
147       if (!m_addon)
148         return false;
149
150       g_graphicsContext.CaptureStateBlock();
151       m_addon->CreateScreenSaver();
152 #endif
153       // setup a z-buffer
154 //      RESOLUTION res = g_graphicsContext.GetVideoResolution();
155 //      g_graphicsContext.SetVideoResolution(res, TRUE);
156
157       // disable the overlay
158       g_windowManager.ShowOverlay(OVERLAY_STATE_HIDDEN);
159       return true;
160     }
161   case GUI_MSG_CHECK_LOCK:
162     if (!g_passwordManager.IsProfileLockUnlocked())
163     {
164       g_application.m_iScreenSaveLock = -1;
165       return false;
166     }
167     g_application.m_iScreenSaveLock = 1;
168     return true;
169   }
170   return CGUIWindow::OnMessage(message);
171 }
172