| 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 "GUIWindowPointer.h" |
| 10 |
|
| 11 |
#include "ServiceBroker.h" |
| 12 |
#include "input/InputManager.h" |
| 13 |
#include "input/mouse/MouseStat.h" |
| 14 |
#include "windowing/WinSystem.h" |
| 15 |
|
| 16 |
#define ID_POINTER 10 |
| 17 |
|
| 18 |
CGUIWindowPointer::CGUIWindowPointer(void) |
| 19 |
: CGUIDialog(WINDOW_DIALOG_POINTER, "Pointer.xml", DialogModalityType::MODELESS) |
| 20 |
{ |
| 21 |
m_pointer = 0; |
| 22 |
m_loadType = LOAD_ON_GUI_INIT; |
| 23 |
m_needsScaling = false; |
| 24 |
m_active = false; |
| 25 |
m_renderOrder = RENDER_ORDER_WINDOW_POINTER; |
| 26 |
} |
| 27 |
|
| 28 |
CGUIWindowPointer::~CGUIWindowPointer(void) = default; |
| 29 |
|
| 30 |
void CGUIWindowPointer::SetPointer(int pointer) |
| 31 |
{ |
| 32 |
if (m_pointer == pointer) return; |
| 33 |
// set the new pointer visible |
| 34 |
CGUIControl *pControl = GetControl(pointer); |
| 35 |
if (pControl) |
| 36 |
{ |
| 37 |
pControl->SetVisible(true); |
| 38 |
// disable the old pointer |
| 39 |
pControl = GetControl(m_pointer); |
| 40 |
if (pControl) pControl->SetVisible(false); |
| 41 |
// set pointer to the new one |
| 42 |
m_pointer = pointer; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
void CGUIWindowPointer::UpdateVisibility() |
| 47 |
{ |
| 48 |
if(CServiceBroker::GetWinSystem()->HasCursor()) |
| 49 |
{ |
| 50 |
if (CServiceBroker::GetInputManager().IsMouseActive()) |
| 51 |
Open(); |
| 52 |
else |
| 53 |
Close(); |
| 54 |
} |
| 55 |
else |
| 56 |
{ |
| 57 |
Close(); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
void CGUIWindowPointer::OnWindowLoaded() |
| 62 |
{ // set all our pointer images invisible |
| 63 |
for (iControls i = m_children.begin();i != m_children.end(); ++i) |
| 64 |
{ |
| 65 |
CGUIControl* pControl = *i; |
| 66 |
pControl->SetVisible(false); |
| 67 |
} |
| 68 |
CGUIWindow::OnWindowLoaded(); |
| 69 |
DynamicResourceAlloc(false); |
| 70 |
m_pointer = 0; |
| 71 |
m_renderOrder = RENDER_ORDER_WINDOW_POINTER; |
| 72 |
} |
| 73 |
|
| 74 |
void CGUIWindowPointer::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) |
| 75 |
{ |
| 76 |
bool active = CServiceBroker::GetInputManager().IsMouseActive(); |
| 77 |
if (active != m_active) |
| 78 |
{ |
| 79 |
MarkDirtyRegion(); |
| 80 |
m_active = active; |
| 81 |
} |
| 82 |
MousePosition pos = CServiceBroker::GetInputManager().GetMousePosition(); |
| 83 |
SetPosition((float)pos.x, (float)pos.y); |
| 84 |
SetPointer(CServiceBroker::GetInputManager().GetMouseState()); |
| 85 |
return CGUIWindow::Process(currentTime, dirtyregions); |
| 86 |
} |