| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "GUIWindowScreensaverDim.h" |
| 10 |
|
| 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" |
| 20 |
|
| 21 |
CGUIWindowScreensaverDim::CGUIWindowScreensaverDim(void) |
| 22 |
: CGUIDialog(WINDOW_SCREENSAVER_DIM, "", DialogModalityType::MODELESS) |
| 23 |
{ |
| 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; |
| 28 |
} |
| 29 |
|
| 30 |
void CGUIWindowScreensaverDim::UpdateVisibility() |
| 31 |
{ |
| 32 |
auto& components = CServiceBroker::GetAppComponents(); |
| 33 |
const auto appPower = components.GetComponent<CApplicationPowerHandling>(); |
| 34 |
if (appPower->IsInScreenSaver()) |
| 35 |
{ |
| 36 |
if (m_visible) |
| 37 |
return; |
| 38 |
|
| 39 |
std::string usedId = appPower->ScreensaverIdInUse(); |
| 40 |
if (usedId == "screensaver.xbmc.builtin.dim" || |
| 41 |
usedId == "screensaver.xbmc.builtin.black") |
| 42 |
{ |
| 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(); |
| 52 |
} |
| 53 |
} |
| 54 |
else if (m_visible) |
| 55 |
{ |
| 56 |
m_visible = false; |
| 57 |
Close(); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
void CGUIWindowScreensaverDim::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) |
| 62 |
{ |
| 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()); |
| 67 |
} |
| 68 |
|
| 69 |
void CGUIWindowScreensaverDim::Render() |
| 70 |
{ |
| 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(); |
| 77 |
} |