aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormontellese <montellese@xbmc.org>2012-06-23 01:20:39 +0200
committermontellese <montellese@xbmc.org>2012-10-08 12:03:35 +0200
commit3476396155b314dda237dbc2abf090ddc5572afe (patch)
tree3cac2c1799fdda182df5effac65f3c2a58886b98
parentabc7773645b6136e92ca68ce397155cf787f34ed (diff)
CGUIDialogSettings: add a RANGE type for settings
-rw-r--r--xbmc/settings/GUIDialogSettings.cpp107
-rw-r--r--xbmc/settings/GUIDialogSettings.h13
2 files changed, 100 insertions, 20 deletions
diff --git a/xbmc/settings/GUIDialogSettings.cpp b/xbmc/settings/GUIDialogSettings.cpp
index 91b1e3aa61..5aa16cffd4 100644
--- a/xbmc/settings/GUIDialogSettings.cpp
+++ b/xbmc/settings/GUIDialogSettings.cpp
@@ -198,7 +198,7 @@ void CGUIDialogSettings::UpdateSetting(unsigned int id)
{
float value = *(float *)setting.data;
pControl->SetFloatValue(value);
- if (setting.formatFunction) pControl->SetTextValue(setting.formatFunction(value, setting.interval));
+ if (setting.formatFunction.standard) pControl->SetTextValue(setting.formatFunction.standard(value, setting.interval));
}
}
else if (setting.type == SettingInfo::BUTTON_DIALOG)
@@ -209,8 +209,8 @@ void CGUIDialogSettings::UpdateSetting(unsigned int id)
}
else if (setting.type == SettingInfo::EDIT)
{
- CGUIEditControl *pControl = (CGUIEditControl *)GetControl(controlID);
- if (pControl && setting.data) pControl->SetLabel2(*(CStdString *)setting.data);
+ SET_CONTROL_LABEL(controlID, setting.name);
+ if (setting.data) SET_CONTROL_LABEL2(controlID, string(*(CStdString *)setting.data));
}
else if (setting.type == SettingInfo::EDIT_NUM)
{
@@ -229,6 +229,17 @@ void CGUIDialogSettings::UpdateSetting(unsigned int id)
strNewValue = "-";
SET_CONTROL_LABEL2(controlID, strNewValue);
}
+ else if (setting.type == SettingInfo::RANGE)
+ {
+ CGUISettingsSliderControl *pControl = (CGUISettingsSliderControl *)GetControl(controlID);
+ float** value = (float **)setting.data;
+ if (pControl && setting.data)
+ {
+ pControl->SetFloatValue(*(value[0]), CGUISliderControl::RangeSelectorLower);
+ pControl->SetFloatValue(*(value[1]), CGUISliderControl::RangeSelectorUpper);
+ if (setting.formatFunction.range) pControl->SetTextValue(setting.formatFunction.range(*(value[0]), *(value[1]), setting.interval));
+ }
+ }
if (setting.enabled)
{
@@ -300,13 +311,13 @@ void CGUIDialogSettings::OnClick(int iID)
{
CGUISettingsSliderControl *pControl = (CGUISettingsSliderControl *)GetControl(iID);
if (setting.data) *(float *)setting.data = pControl->GetFloatValue();
- if (setting.formatFunction) pControl->SetTextValue(setting.formatFunction(pControl->GetFloatValue(), setting.interval));
+ if (setting.formatFunction.standard) pControl->SetTextValue(setting.formatFunction.standard(pControl->GetFloatValue(), setting.interval));
}
else if (setting.type == SettingInfo::BUTTON && m_usePopupSliders && setting.data)
{ // we're using popup sliders
CGUIDialogSlider::ShowAndGetInput(setting.name, *(float *)setting.data, setting.min, setting.interval, setting.max, this, &setting);
- if (setting.formatFunction)
- SET_CONTROL_LABEL2(iID, setting.formatFunction(*(float *)setting.data, setting.interval));
+ if (setting.formatFunction.standard)
+ SET_CONTROL_LABEL2(iID, setting.formatFunction.standard(*(float *)setting.data, setting.interval));
}
else if (setting.type == SettingInfo::STRING)
{
@@ -316,6 +327,19 @@ void CGUIDialogSettings::OnClick(int iID)
strNewValue = "-";
SET_CONTROL_LABEL2(iID, strNewValue);
}
+ else if (setting.type == SettingInfo::RANGE)
+ {
+ CGUISettingsSliderControl *pControl = (CGUISettingsSliderControl *)GetControl(iID);
+ if (setting.data)
+ {
+ *((float **)setting.data)[0] = pControl->GetFloatValue(CGUISliderControl::RangeSelectorLower);
+ *((float **)setting.data)[1] = pControl->GetFloatValue(CGUISliderControl::RangeSelectorUpper);
+ }
+ if (setting.formatFunction.range)
+ pControl->SetTextValue(setting.formatFunction.range(pControl->GetFloatValue(CGUISliderControl::RangeSelectorLower),
+ pControl->GetFloatValue(CGUISliderControl::RangeSelectorUpper),
+ setting.interval));
+ }
OnSettingChanged(setting);
}
@@ -346,8 +370,8 @@ void CGUIDialogSettings::AddSetting(SettingInfo &setting, float width, int iCont
pControl = new CGUIButtonControl(*m_pOriginalSettingsButton);
if (!pControl) return ;
((CGUIButtonControl *)pControl)->SetLabel(setting.name);
- if (setting.formatFunction)
- ((CGUIButtonControl *)pControl)->SetLabel2(setting.formatFunction(*(float *)setting.data, setting.interval));
+ if (setting.formatFunction.standard)
+ ((CGUIButtonControl *)pControl)->SetLabel2(setting.formatFunction.standard(*(float *)setting.data, setting.interval));
pControl->SetWidth(width);
}
else if (setting.type == SettingInfo::EDIT && m_pOriginalEdit)
@@ -404,14 +428,14 @@ void CGUIDialogSettings::AddSetting(SettingInfo &setting, float width, int iCont
if (!pControl) return ;
pControl->SetWidth(width);
((CGUISettingsSliderControl *)pControl)->SetText(setting.name);
- if (setting.formatFunction)
- ((CGUISettingsSliderControl *)pControl)->SetTextValue(setting.formatFunction(*(float *)setting.data, setting.interval));
+ if (setting.formatFunction.standard)
+ ((CGUISettingsSliderControl *)pControl)->SetTextValue(setting.formatFunction.standard(*(float *)setting.data, setting.interval));
((CGUISettingsSliderControl *)pControl)->SetType(SPIN_CONTROL_TYPE_FLOAT);
((CGUISettingsSliderControl *)pControl)->SetFloatRange(setting.min, setting.max);
((CGUISettingsSliderControl *)pControl)->SetFloatInterval(setting.interval);
if (setting.data) ((CGUISettingsSliderControl *)pControl)->SetFloatValue(*(float *)setting.data);
}
- if (setting.type == SettingInfo::STRING && m_pOriginalSettingsButton)
+ else if (setting.type == SettingInfo::STRING && m_pOriginalSettingsButton)
{
pControl = new CGUIButtonControl(*m_pOriginalSettingsButton);
if (!pControl) return ;
@@ -422,6 +446,25 @@ void CGUIDialogSettings::AddSetting(SettingInfo &setting, float width, int iCont
((CGUIButtonControl *)pControl)->SetLabel2(strValue);
pControl->SetWidth(width);
}
+ else if (setting.type == SettingInfo::RANGE)
+ {
+ if (!m_pOriginalSlider) return;
+ pControl = new CGUISettingsSliderControl(*m_pOriginalSlider);
+ if (!pControl) return ;
+ pControl->SetWidth(width);
+ ((CGUISettingsSliderControl *)pControl)->SetText(setting.name);
+ if (setting.formatFunction.range)
+ ((CGUISettingsSliderControl *)pControl)->SetTextValue(setting.formatFunction.range(*((float **)setting.data)[0], *((float **)setting.data)[1], setting.interval));
+ ((CGUISettingsSliderControl *)pControl)->SetType(SPIN_CONTROL_TYPE_FLOAT);
+ ((CGUISettingsSliderControl *)pControl)->SetRangeSelection(true);
+ ((CGUISettingsSliderControl *)pControl)->SetFloatRange(setting.min, setting.max);
+ ((CGUISettingsSliderControl *)pControl)->SetFloatInterval(setting.interval);
+ if (setting.data)
+ {
+ ((CGUISettingsSliderControl *)pControl)->SetFloatValue(*((float **)setting.data)[0], CGUISliderControl::RangeSelectorLower);
+ ((CGUISettingsSliderControl *)pControl)->SetFloatValue(*((float **)setting.data)[1], CGUISliderControl::RangeSelectorUpper);
+ }
+ }
if (!pControl) return;
pControl->SetID(iControlID);
@@ -469,7 +512,7 @@ void CGUIDialogSettings::AddButton(unsigned int id, int label, float *current, f
setting.min = min;
setting.max = max;
setting.interval = interval;
- setting.formatFunction = function;
+ setting.formatFunction.standard = function;
m_settings.push_back(setting);
}
@@ -583,7 +626,26 @@ void CGUIDialogSettings::AddSlider(unsigned int id, int label, float *current, f
setting.interval = interval;
setting.max = max;
setting.data = current;
- setting.formatFunction = function;
+ setting.formatFunction.standard = function;
+ m_settings.push_back(setting);
+}
+
+void CGUIDialogSettings::AddRangeSlider(unsigned int id, int label, float *currentLower, float* currentUpper, float min, float interval, float max, RANGEFORMATFUNCTION function)
+{
+ SettingInfo setting;
+ setting.id = id;
+ setting.name = g_localizeStrings.Get(label);
+ setting.type = SettingInfo::RANGE;
+ setting.min = min;
+ setting.interval = interval;
+ setting.max = max;
+
+ float** data = new float*[2];
+ data[0] = currentLower;
+ data[1] = currentUpper;
+ setting.data = data;
+
+ setting.formatFunction.range = function;
m_settings.push_back(setting);
}
@@ -612,8 +674,19 @@ void CGUIDialogSettings::OnSliderChange(void *data, CGUISliderControl *slider)
return;
SettingInfo *setting = (SettingInfo *)data;
- *(float *)setting->data = slider->GetFloatValue();
- OnSettingChanged(*setting);
- if (setting->formatFunction)
- slider->SetTextValue(setting->formatFunction(slider->GetFloatValue(), setting->interval));
+ if (setting->type == SettingInfo::SLIDER)
+ {
+ *(float *)setting->data = slider->GetFloatValue();
+ OnSettingChanged(*setting);
+ if (setting->formatFunction.standard)
+ slider->SetTextValue(setting->formatFunction.standard(slider->GetFloatValue(), setting->interval));
+ }
+ else if (setting->type == SettingInfo::RANGE)
+ {
+ *((float **)setting->data)[0] = slider->GetFloatValue(CGUISliderControl::RangeSelectorLower);
+ *((float **)setting->data)[1] = slider->GetFloatValue(CGUISliderControl::RangeSelectorUpper);
+ OnSettingChanged(*setting);
+ if (setting->formatFunction.range)
+ slider->SetTextValue(setting->formatFunction.range(slider->GetFloatValue(CGUISliderControl::RangeSelectorLower), slider->GetFloatValue(CGUISliderControl::RangeSelectorUpper), setting->interval));
+ }
}
diff --git a/xbmc/settings/GUIDialogSettings.h b/xbmc/settings/GUIDialogSettings.h
index dc6400f19f..4d89f5128f 100644
--- a/xbmc/settings/GUIDialogSettings.h
+++ b/xbmc/settings/GUIDialogSettings.h
@@ -29,14 +29,16 @@ class CGUIRadioButtonControl;
class CGUISettingsSliderControl;
class CGUIEditControl;
class CGUIImage;
+class CGUIEditControl;
typedef std::vector<CStdString> SETTINGSTRINGS;
typedef CStdString (*FORMATFUNCTION) (float value, float min);
+typedef CStdString (*RANGEFORMATFUNCTION) (float valueLower, float valueUpper, float min);
class SettingInfo
{
public:
- enum SETTING_TYPE { NONE=0, EDIT, EDIT_NUM, BUTTON, BUTTON_DIALOG, CHECK, CHECK_UCHAR, SPIN, SLIDER, SEPARATOR, STRING };
+ enum SETTING_TYPE { NONE=0, EDIT, EDIT_NUM, BUTTON, BUTTON_DIALOG, CHECK, CHECK_UCHAR, SPIN, SLIDER, SEPARATOR, STRING, RANGE };
SettingInfo()
{
id = 0;
@@ -46,7 +48,7 @@ public:
min = 0;
max = 0;
interval = 0;
- formatFunction = NULL;
+ formatFunction.standard = NULL;
};
SETTING_TYPE type;
CStdString name;
@@ -55,7 +57,11 @@ public:
float min;
float max;
float interval;
- FORMATFUNCTION formatFunction;
+ union
+ {
+ FORMATFUNCTION standard;
+ RANGEFORMATFUNCTION range;
+ } formatFunction;
std::vector<std::pair<int, CStdString> > entry;
bool enabled;
};
@@ -96,6 +102,7 @@ protected:
void AddSpin(unsigned int id, int label, int *current, std::vector<std::pair<int, CStdString> > &values);
void AddSpin(unsigned int id, int label, int *current, std::vector<std::pair<int, int> > &values);
void AddSlider(unsigned int id, int label, float *current, float min, float interval, float max, FORMATFUNCTION formatFunction, bool allowPopup = true);
+ void AddRangeSlider(unsigned int id, int label, float *currentLower, float* currentUpper, float min, float interval, float max, RANGEFORMATFUNCTION formatFunction);
void AddSeparator(unsigned int id);
CGUIEditControl *m_pOriginalEdit;