2 * Copyright (C) 2005-2013 Team XBMC
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)
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")
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
)
50 return CGUIDialog::OnAction(action
);
53 bool CGUIDialogSlider::OnMessage(CGUIMessage
& message
)
55 switch ( message
.GetMessage() )
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());
68 case GUI_MSG_WINDOW_DEINIT
:
70 m_callbackData
= NULL
;
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
;
84 slider
->SetType(SPIN_CONTROL_TYPE_FLOAT
);
85 slider
->SetFloatRange(min
, max
);
86 slider
->SetFloatInterval(delta
);
87 slider
->SetFloatValue(value
);
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
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
);
111 // set the label and value
112 slider
->Initialize();
113 slider
->SetSlider(label
, value
, min
, delta
, max
, callback
, callbackData
);
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
);
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
);