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
|
/*
* Copyright (C) 2017-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "DialogGameVolume.h"
#include "ServiceBroker.h"
#include "application/ApplicationComponents.h"
#include "application/ApplicationVolumeHandling.h"
#include "dialogs/GUIDialogVolumeBar.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIDialog.h"
#include "guilib/GUIMessage.h"
#include "guilib/GUISliderControl.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
#include "guilib/WindowIDs.h"
#include "interfaces/AnnouncementManager.h"
#include "utils/Variant.h"
#include <cmath>
using namespace KODI;
using namespace GAME;
#define CONTROL_LABEL 12 //! @todo Remove me
CDialogGameVolume::CDialogGameVolume()
{
// Initialize CGUIWindow
SetID(WINDOW_DIALOG_GAME_VOLUME);
m_loadType = KEEP_IN_MEMORY;
}
bool CDialogGameVolume::OnMessage(CGUIMessage& message)
{
switch (message.GetMessage())
{
case GUI_MSG_STATE_CHANGED:
{
int controlId = message.GetControlId();
if (controlId == GetID())
{
OnStateChanged();
return true;
}
break;
}
default:
break;
}
return CGUIDialogSlider::OnMessage(message);
}
void CDialogGameVolume::OnInitWindow()
{
m_volumePercent = m_oldVolumePercent = GetVolumePercent();
CGUIDialogSlider::OnInitWindow();
// Set slider parameters
SetModalityType(DialogModalityType::MODAL);
SetSlider(GetLabel(), GetVolumePercent(), VOLUME_MIN, VOLUME_DELTA, VOLUME_MAX, this, nullptr);
SET_CONTROL_HIDDEN(CONTROL_LABEL);
CGUIDialogVolumeBar* dialogVolumeBar = dynamic_cast<CGUIDialogVolumeBar*>(
CServiceBroker::GetGUI()->GetWindowManager().GetWindow(WINDOW_DIALOG_VOLUME_BAR));
if (dialogVolumeBar != nullptr)
dialogVolumeBar->RegisterCallback(this);
CServiceBroker::GetAnnouncementManager()->AddAnnouncer(this);
}
void CDialogGameVolume::OnDeinitWindow(int nextWindowID)
{
CServiceBroker::GetAnnouncementManager()->RemoveAnnouncer(this);
CGUIDialogVolumeBar* dialogVolumeBar = dynamic_cast<CGUIDialogVolumeBar*>(
CServiceBroker::GetGUI()->GetWindowManager().GetWindow(WINDOW_DIALOG_VOLUME_BAR));
if (dialogVolumeBar != nullptr)
dialogVolumeBar->UnregisterCallback(this);
CGUIDialogSlider::OnDeinitWindow(nextWindowID);
}
void CDialogGameVolume::OnSliderChange(void* data, CGUISliderControl* slider)
{
const float volumePercent = slider->GetFloatValue();
if (std::fabs(volumePercent - m_volumePercent) > 0.1f)
{
m_volumePercent = volumePercent;
auto& components = CServiceBroker::GetAppComponents();
const auto appVolume = components.GetComponent<CApplicationVolumeHandling>();
appVolume->SetVolume(volumePercent, true);
}
}
bool CDialogGameVolume::IsShown() const
{
return m_active;
}
void CDialogGameVolume::Announce(ANNOUNCEMENT::AnnouncementFlag flag,
const std::string& sender,
const std::string& message,
const CVariant& data)
{
if (flag == ANNOUNCEMENT::Application && message == "OnVolumeChanged")
{
const float volumePercent = static_cast<float>(data["volume"].asDouble());
if (std::fabs(volumePercent - m_volumePercent) > 0.1f)
{
m_volumePercent = volumePercent;
CGUIMessage msg(GUI_MSG_STATE_CHANGED, GetID(), GetID());
CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg);
}
}
}
void CDialogGameVolume::OnStateChanged()
{
if (m_volumePercent != m_oldVolumePercent)
{
m_oldVolumePercent = m_volumePercent;
SetSlider(GetLabel(), m_volumePercent, VOLUME_MIN, VOLUME_DELTA, VOLUME_MAX, this, nullptr);
}
}
float CDialogGameVolume::GetVolumePercent() const
{
const auto& components = CServiceBroker::GetAppComponents();
const auto appVolume = components.GetComponent<CApplicationVolumeHandling>();
return appVolume->GetVolumePercent();
}
std::string CDialogGameVolume::GetLabel()
{
return g_localizeStrings.Get(13376); // "Volume"
}
|