Merge pull request #4594 from FernetMenta/paplayer
[xbmc.git] / xbmc / dialogs / GUIDialogSlider.cpp
blob9dda5cfd33f25863b3e595b439cbfe87d5c84758
1 /*
2 * Copyright (C) 2005-2013 Team XBMC
3 * http://xbmc.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "GUIDialogSlider.h"
22 #include "guilib/GUISliderControl.h"
23 #include "guilib/GUIWindowManager.h"
24 #include "guilib/Key.h"
25 #include "guilib/LocalizeStrings.h"
27 #define CONTROL_HEADING 10
28 #define CONTROL_SLIDER 11
29 #define CONTROL_LABEL 12
31 CGUIDialogSlider::CGUIDialogSlider(void)
32 : CGUIDialog(WINDOW_DIALOG_SLIDER, "DialogSlider.xml")
34 m_callback = NULL;
35 m_callbackData = NULL;
36 m_loadType = KEEP_IN_MEMORY;
39 CGUIDialogSlider::~CGUIDialogSlider(void)
43 bool CGUIDialogSlider::OnAction(const CAction &action)
45 if (action.GetID() == ACTION_SELECT_ITEM)
47 Close();
48 return true;
50 return CGUIDialog::OnAction(action);
53 bool CGUIDialogSlider::OnMessage(CGUIMessage& message)
55 switch ( message.GetMessage() )
57 case GUI_MSG_CLICKED:
58 if (message.GetSenderId() == CONTROL_SLIDER)
60 CGUISliderControl *slider = (CGUISliderControl *)GetControl(CONTROL_SLIDER);
61 if (slider && m_callback)
63 m_callback->OnSliderChange(m_callbackData, slider);
64 SET_CONTROL_LABEL(CONTROL_LABEL, slider->GetDescription());
67 break;
68 case GUI_MSG_WINDOW_DEINIT:
69 m_callback = NULL;
70 m_callbackData = NULL;
71 break;
73 return CGUIDialog::OnMessage(message);
76 void CGUIDialogSlider::SetSlider(const CStdString &label, float value, float min, float delta, float max, ISliderCallback *callback, void *callbackData)
78 SET_CONTROL_LABEL(CONTROL_HEADING, label);
79 CGUISliderControl *slider = (CGUISliderControl *)GetControl(CONTROL_SLIDER);
80 m_callback = callback;
81 m_callbackData = callbackData;
82 if (slider)
84 slider->SetType(SPIN_CONTROL_TYPE_FLOAT);
85 slider->SetFloatRange(min, max);
86 slider->SetFloatInterval(delta);
87 slider->SetFloatValue(value);
88 if (m_callback)
90 m_callback->OnSliderChange(m_callbackData, slider);
91 SET_CONTROL_LABEL(CONTROL_LABEL, slider->GetDescription());
96 void CGUIDialogSlider::OnWindowLoaded()
98 // ensure our callbacks are NULL, incase we were loaded via some non-standard means
99 m_callback = NULL;
100 m_callbackData = NULL;
101 CGUIDialog::OnWindowLoaded();
104 void CGUIDialogSlider::ShowAndGetInput(const CStdString &label, float value, float min, float delta, float max, ISliderCallback *callback, void *callbackData)
106 // grab the slider dialog
107 CGUIDialogSlider *slider = (CGUIDialogSlider *)g_windowManager.GetWindow(WINDOW_DIALOG_SLIDER);
108 if (!slider)
109 return;
111 // set the label and value
112 slider->Initialize();
113 slider->SetSlider(label, value, min, delta, max, callback, callbackData);
114 slider->DoModal();
117 void CGUIDialogSlider::Display(int label, float value, float min, float delta, float max, ISliderCallback *callback)
119 // grab the slider dialog
120 CGUIDialogSlider *slider = (CGUIDialogSlider *)g_windowManager.GetWindow(WINDOW_DIALOG_SLIDER);
121 if (!slider)
122 return;
124 // set the label and value
125 slider->Initialize();
126 slider->SetAutoClose(1000);
127 slider->SetSlider(g_localizeStrings.Get(label), value, min, delta, max, callback, NULL);
128 slider->Show();