From 5152880f7d7cd9555394722d477bcb066d8c1417 Mon Sep 17 00:00:00 2001 From: AchimTuran Date: Wed, 13 Jul 2016 17:43:22 +0200 Subject: [PATCH] [guilib] Add vertical orientation to GUISettingsSliderControl --- xbmc/guilib/GUIControlFactory.cpp | 14 +++++++-- xbmc/guilib/GUISettingsSliderControl.cpp | 38 ++++++++++++++++++++---- xbmc/guilib/GUISettingsSliderControl.h | 2 +- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/xbmc/guilib/GUIControlFactory.cpp b/xbmc/guilib/GUIControlFactory.cpp index 53f8fe1c2b8b6..05beffca38246 100644 --- a/xbmc/guilib/GUIControlFactory.cpp +++ b/xbmc/guilib/GUIControlFactory.cpp @@ -888,8 +888,6 @@ CGUIControl* CGUIControlFactory::Create(int parentID, const CRect &rect, TiXmlEl XMLUtils::GetFloat(pControlNode, "markwidth", checkWidth); XMLUtils::GetFloat(pControlNode, "markheight", checkHeight); - XMLUtils::GetFloat(pControlNode, "sliderwidth", sliderWidth); - XMLUtils::GetFloat(pControlNode, "sliderheight", sliderHeight); if (!GetTexture(pControlNode, "textureradioonfocus", textureRadioOnFocus) || !GetTexture(pControlNode, "textureradioonnofocus", textureRadioOnNoFocus)) { GetTexture(pControlNode, "textureradiofocus", textureRadioOnFocus); // backward compatibility @@ -963,8 +961,18 @@ CGUIControl* CGUIControlFactory::Create(int parentID, const CRect &rect, TiXmlEl { StringUtils::ToLower(strTmp); if (strTmp == "horizontal") + { orientation = HORIZONTAL; + // default orientation for a settings slider is vertical + // consequently it has to changed here + float tmpVal = sliderWidth; + sliderWidth = sliderHeight; + sliderHeight = tmpVal; + } } + + XMLUtils::GetFloat(pControlNode, "sliderwidth", sliderWidth); + XMLUtils::GetFloat(pControlNode, "sliderheight", sliderHeight); XMLUtils::GetFloat(pControlNode, "itemgap", buttonGap); XMLUtils::GetInt(pControlNode, "movement", iMovementRange); GetAspectRatio(pControlNode, "aspectratio", aspect); @@ -1257,7 +1265,7 @@ CGUIControl* CGUIControlFactory::Create(int parentID, const CRect &rect, TiXmlEl { control = new CGUISettingsSliderControl( parentID, id, posX, posY, width, height, sliderWidth, sliderHeight, textureFocus, textureNoFocus, - textureBar, textureNib, textureNibFocus, labelInfo, SLIDER_CONTROL_TYPE_PERCENTAGE); + textureBar, textureNib, textureNibFocus, labelInfo, SLIDER_CONTROL_TYPE_PERCENTAGE, orientation); ((CGUISettingsSliderControl *)control)->SetText(strLabel); ((CGUISettingsSliderControl *)control)->SetInfo(singleInfo); diff --git a/xbmc/guilib/GUISettingsSliderControl.cpp b/xbmc/guilib/GUISettingsSliderControl.cpp index 7cf7f0bd6102b..953d953bd5bca 100644 --- a/xbmc/guilib/GUISettingsSliderControl.cpp +++ b/xbmc/guilib/GUISettingsSliderControl.cpp @@ -20,12 +20,20 @@ #include "GUISettingsSliderControl.h" -CGUISettingsSliderControl::CGUISettingsSliderControl(int parentID, int controlID, float posX, float posY, float width, float height, float sliderWidth, float sliderHeight, const CTextureInfo &textureFocus, const CTextureInfo &textureNoFocus, const CTextureInfo& backGroundTexture, const CTextureInfo& nibTexture, const CTextureInfo& nibTextureFocus, const CLabelInfo &labelInfo, int iType) - : CGUISliderControl(parentID, controlID, posX, posY, sliderWidth, sliderHeight, backGroundTexture, nibTexture,nibTextureFocus, iType, HORIZONTAL) +CGUISettingsSliderControl::CGUISettingsSliderControl(int parentID, int controlID, float posX, float posY, float width, float height, float sliderWidth, float sliderHeight, const CTextureInfo &textureFocus, const CTextureInfo &textureNoFocus, const CTextureInfo& backGroundTexture, const CTextureInfo& nibTexture, const CTextureInfo& nibTextureFocus, const CLabelInfo &labelInfo, int iType, ORIENTATION orientation) + : CGUISliderControl(parentID, controlID, posX, posY, sliderWidth, sliderHeight, backGroundTexture, nibTexture,nibTextureFocus, iType, orientation) , m_buttonControl(parentID, controlID, posX, posY, width, height, textureFocus, textureNoFocus, labelInfo) , m_label(posX, posY, width, height, labelInfo) { - m_label.SetAlign((labelInfo.align & XBFONT_CENTER_Y) | XBFONT_RIGHT); + if (CGUISliderControl::m_orientation == HORIZONTAL) + { + m_label.SetAlign((labelInfo.align & XBFONT_CENTER_Y) | XBFONT_RIGHT); + } + else + { + m_label.SetAlign((labelInfo.align & XBFONT_CENTER_Y) | XBFONT_CENTER_X); + m_buttonControl.m_label.SetAlign((labelInfo.align & XBFONT_CENTER_Y) | XBFONT_CENTER_X); + } ControlType = GUICONTROL_SETTINGS_SLIDER; } @@ -37,8 +45,18 @@ void CGUISettingsSliderControl::Process(unsigned int currentTime, CDirtyRegionLi { if (m_bInvalidated) { - float sliderPosX = m_buttonControl.GetXPosition() + m_buttonControl.GetWidth() - m_width - m_buttonControl.GetLabelInfo().offsetX; - float sliderPosY = m_buttonControl.GetYPosition() + (m_buttonControl.GetHeight() - m_height) * 0.5f; + float sliderPosX = 0.0f; + float sliderPosY = 0.0f; + if (CGUISliderControl::m_orientation == HORIZONTAL) + { + sliderPosX = m_buttonControl.GetXPosition() + m_buttonControl.GetWidth() - CGUISliderControl::m_width - m_buttonControl.GetLabelInfo().offsetX; + sliderPosY = m_buttonControl.GetYPosition() + (m_buttonControl.GetHeight() - CGUISliderControl::m_height)*0.5f; + } + else + { + sliderPosX = m_buttonControl.GetXPosition() + m_buttonControl.GetWidth()*0.5f - CGUISliderControl::m_width*0.5f; + sliderPosY = m_buttonControl.GetYPosition() + m_buttonControl.GetHeight()*0.5f - CGUISliderControl::m_height*0.5f; + } CGUISliderControl::SetPosition(sliderPosX, sliderPosY); } m_buttonControl.SetFocus(HasFocus()); @@ -60,7 +78,15 @@ void CGUISettingsSliderControl::ProcessText() { bool changed = false; - changed |= m_label.SetMaxRect(m_buttonControl.GetXPosition(), m_buttonControl.GetYPosition(), m_posX - m_buttonControl.GetXPosition(), m_buttonControl.GetHeight()); + if (CGUISliderControl::m_orientation == HORIZONTAL) + { + changed |= m_label.SetMaxRect(m_buttonControl.GetXPosition(), m_buttonControl.GetYPosition(), m_posX - m_buttonControl.GetXPosition(), m_buttonControl.GetHeight()); + } + else + { + changed |= m_label.SetMaxRect(m_buttonControl.GetXPosition(), m_buttonControl.GetYPosition(), m_buttonControl.GetWidth(), (m_buttonControl.GetHeight() - CGUISettingsSliderControl::m_height)*0.5f); + changed |= m_buttonControl.m_label.SetMaxRect(m_buttonControl.GetXPosition(), CGUISliderControl::m_posY + CGUISettingsSliderControl::m_height, m_buttonControl.GetWidth(), (m_buttonControl.GetHeight() - CGUISettingsSliderControl::m_height)*0.5f); + } changed |= m_label.SetText(CGUISliderControl::GetDescription()); if (IsDisabled()) changed |= m_label.SetColor(CGUILabel::COLOR_DISABLED); diff --git a/xbmc/guilib/GUISettingsSliderControl.h b/xbmc/guilib/GUISettingsSliderControl.h index ae7d1169df68f..c0036750eaec3 100644 --- a/xbmc/guilib/GUISettingsSliderControl.h +++ b/xbmc/guilib/GUISettingsSliderControl.h @@ -39,7 +39,7 @@ class CGUISettingsSliderControl : public CGUISliderControl { public: - CGUISettingsSliderControl(int parentID, int controlID, float posX, float posY, float width, float height, float sliderWidth, float sliderHeight, const CTextureInfo &textureFocus, const CTextureInfo &textureNoFocus, const CTextureInfo& backGroundTexture, const CTextureInfo& nibTexture, const CTextureInfo& nibTextureFocus, const CLabelInfo &labelInfo, int iType); + CGUISettingsSliderControl(int parentID, int controlID, float posX, float posY, float width, float height, float sliderWidth, float sliderHeight, const CTextureInfo &textureFocus, const CTextureInfo &textureNoFocus, const CTextureInfo& backGroundTexture, const CTextureInfo& nibTexture, const CTextureInfo& nibTextureFocus, const CLabelInfo &labelInfo, int iType, ORIENTATION orientation); virtual ~CGUISettingsSliderControl(void); virtual CGUISettingsSliderControl *Clone() const { return new CGUISettingsSliderControl(*this); };