[filesystem][SpecialProtocol] Removed assert from GetPath
[xbmc.git] / xbmc / windows / GUIWindowScreensaverDim.cpp
blobf617fba40504dca22d48076440c8ace932c84155
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIWindowScreensaverDim.h"
11 #include "ServiceBroker.h"
12 #include "addons/AddonManager.h"
13 #include "addons/IAddon.h"
14 #include "addons/addoninfo/AddonType.h"
15 #include "application/ApplicationComponents.h"
16 #include "application/ApplicationPowerHandling.h"
17 #include "guilib/GUITexture.h"
18 #include "utils/ColorUtils.h"
19 #include "windowing/GraphicContext.h"
21 CGUIWindowScreensaverDim::CGUIWindowScreensaverDim(void)
22 : CGUIDialog(WINDOW_SCREENSAVER_DIM, "", DialogModalityType::MODELESS)
24 m_needsScaling = false;
25 m_animations.push_back(CAnimation::CreateFader(0, 100, 0, 1000, ANIM_TYPE_WINDOW_OPEN));
26 m_animations.push_back(CAnimation::CreateFader(100, 0, 0, 1000, ANIM_TYPE_WINDOW_CLOSE));
27 m_renderOrder = RENDER_ORDER_WINDOW_SCREENSAVER;
30 void CGUIWindowScreensaverDim::UpdateVisibility()
32 auto& components = CServiceBroker::GetAppComponents();
33 const auto appPower = components.GetComponent<CApplicationPowerHandling>();
34 if (appPower->IsInScreenSaver())
36 if (m_visible)
37 return;
39 std::string usedId = appPower->ScreensaverIdInUse();
40 if (usedId == "screensaver.xbmc.builtin.dim" ||
41 usedId == "screensaver.xbmc.builtin.black")
43 m_visible = true;
44 ADDON::AddonPtr info;
45 bool success = CServiceBroker::GetAddonMgr().GetAddon(
46 usedId, info, ADDON::AddonType::SCREENSAVER, ADDON::OnlyEnabled::CHOICE_YES);
47 if (success && info && !info->GetSetting("level").empty())
48 m_newDimLevel = 100.0f - (float)atof(info->GetSetting("level").c_str());
49 else
50 m_newDimLevel = 100.0f;
51 Open();
54 else if (m_visible)
56 m_visible = false;
57 Close();
61 void CGUIWindowScreensaverDim::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
63 if (m_newDimLevel != m_dimLevel && !IsAnimating(ANIM_TYPE_WINDOW_CLOSE))
64 m_dimLevel = m_newDimLevel;
65 CGUIDialog::Process(currentTime, dirtyregions);
66 m_renderRegion.SetRect(0, 0, (float)CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth(), (float)CServiceBroker::GetWinSystem()->GetGfxContext().GetHeight());
69 void CGUIWindowScreensaverDim::Render()
71 // draw a translucent black quad - fading is handled by the window animation
72 UTILS::COLOR::Color color = (static_cast<UTILS::COLOR::Color>(m_dimLevel * 2.55f) & 0xff) << 24;
73 color = CServiceBroker::GetWinSystem()->GetGfxContext().MergeAlpha(color);
74 CRect rect(0, 0, (float)CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth(), (float)CServiceBroker::GetWinSystem()->GetGfxContext().GetHeight());
75 CGUITexture::DrawQuad(rect, color);
76 CGUIDialog::Render();