[video] fix selection after changing video or extra art
[xbmc.git] / xbmc / windows / GUIWindowPointer.cpp
blobca51ce34e7d80fd0b34d0393196b5e68918565bb
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 "GUIWindowPointer.h"
11 #include "ServiceBroker.h"
12 #include "input/InputManager.h"
13 #include "input/mouse/MouseStat.h"
14 #include "windowing/WinSystem.h"
16 #define ID_POINTER 10
18 CGUIWindowPointer::CGUIWindowPointer(void)
19 : CGUIDialog(WINDOW_DIALOG_POINTER, "Pointer.xml", DialogModalityType::MODELESS)
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;
28 CGUIWindowPointer::~CGUIWindowPointer(void) = default;
30 void CGUIWindowPointer::SetPointer(int pointer)
32 if (m_pointer == pointer) return;
33 // set the new pointer visible
34 CGUIControl *pControl = GetControl(pointer);
35 if (pControl)
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;
46 void CGUIWindowPointer::UpdateVisibility()
48 if(CServiceBroker::GetWinSystem()->HasCursor())
50 if (CServiceBroker::GetInputManager().IsMouseActive())
51 Open();
52 else
53 Close();
55 else
57 Close();
61 void CGUIWindowPointer::OnWindowLoaded()
62 { // set all our pointer images invisible
63 for (iControls i = m_children.begin();i != m_children.end(); ++i)
65 CGUIControl* pControl = *i;
66 pControl->SetVisible(false);
68 CGUIWindow::OnWindowLoaded();
69 DynamicResourceAlloc(false);
70 m_pointer = 0;
71 m_renderOrder = RENDER_ORDER_WINDOW_POINTER;
74 void CGUIWindowPointer::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
76 bool active = CServiceBroker::GetInputManager().IsMouseActive();
77 if (active != m_active)
79 MarkDirtyRegion();
80 m_active = active;
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);