This repository has been archived by the owner on Apr 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
GUIWindowScreensaver.cpp
164 lines (146 loc) · 4.19 KB
/
GUIWindowScreensaver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "system.h"
#include "GUIWindowScreensaver.h"
#include "utils/AddonManager.h"
#include "Application.h"
#include "GUIPassword.h"
#include "GUISettings.h"
#include "GUIUserMessages.h"
#include "GUIWindowManager.h"
#include "utils/SingleLock.h"
CGUIWindowScreensaver::CGUIWindowScreensaver(void)
: CGUIWindow(WINDOW_SCREENSAVER, "")
{
}
CGUIWindowScreensaver::~CGUIWindowScreensaver(void)
{
}
void CGUIWindowScreensaver::Render()
{
CSingleLock lock (m_critSection);
#ifdef HAS_SCREENSAVER
if (m_addon)
{
if (m_bInitialized)
{
try
{
//some screensavers seem to be depending on xbmc clearing the screen
// g_Windowing.Get3DDevice()->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00010001, 1.0f, 0L );
g_graphicsContext.CaptureStateBlock();
m_addon->Render();
g_graphicsContext.ApplyStateBlock();
}
catch (...)
{
CLog::Log(LOGERROR, "SCREENSAVER: - Exception in Render() - %s", m_addon->Name().c_str());
}
return ;
}
else
{
try
{
m_addon->Start();
m_bInitialized = true;
}
catch (...)
{
CLog::Log(LOGERROR, "SCREENSAVER: - Exception in Start() - %s", m_addon->Name().c_str());
}
return ;
}
}
#endif
CGUIWindow::Render();
}
bool CGUIWindowScreensaver::OnAction(const CAction &action)
{
// We're just a screen saver, nothing to do here
return false;
}
// called when the mouse is moved/clicked etc. etc.
bool CGUIWindowScreensaver::OnMouseEvent(const CPoint &point, const CMouseEvent &event)
{
g_windowManager.PreviousWindow();
return true;
}
bool CGUIWindowScreensaver::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
{
case GUI_MSG_WINDOW_DEINIT:
{
CSingleLock lock (m_critSection);
#ifdef HAS_SCREENSAVER
if (m_addon)
{
m_addon->Stop();
g_graphicsContext.ApplyStateBlock();
m_addon->Destroy();
m_addon.reset();
}
#endif
m_bInitialized = false;
// remove z-buffer
// RESOLUTION res = g_graphicsContext.GetVideoResolution();
// g_graphicsContext.SetVideoResolution(res, FALSE);
// enable the overlay
g_windowManager.ShowOverlay(OVERLAY_STATE_SHOWN);
}
break;
case GUI_MSG_WINDOW_INIT:
{
CGUIWindow::OnMessage(message);
CSingleLock lock (m_critSection);
#ifdef HAS_SCREENSAVER
assert(!m_addon);
m_bInitialized = false;
m_addon.reset();
// Setup new screensaver instance
ADDON::AddonPtr addon;
if (!ADDON::CAddonMgr::Get()->GetAddon(g_guiSettings.GetString("screensaver.mode"), addon, ADDON::ADDON_SCREENSAVER))
return false;
m_addon = boost::dynamic_pointer_cast<CScreenSaver>(addon);
if (!m_addon)
return false;
g_graphicsContext.CaptureStateBlock();
m_addon->CreateScreenSaver();
#endif
// setup a z-buffer
// RESOLUTION res = g_graphicsContext.GetVideoResolution();
// g_graphicsContext.SetVideoResolution(res, TRUE);
// disable the overlay
g_windowManager.ShowOverlay(OVERLAY_STATE_HIDDEN);
return true;
}
case GUI_MSG_CHECK_LOCK:
if (!g_passwordManager.IsProfileLockUnlocked())
{
g_application.m_iScreenSaveLock = -1;
return false;
}
g_application.m_iScreenSaveLock = 1;
return true;
}
return CGUIWindow::OnMessage(message);
}