Skip to content

Commit

Permalink
Merge pull request #9704 from ronie/slider-orientation
Browse files Browse the repository at this point in the history
[GUI] add orientation support to slider controls
  • Loading branch information
ronie committed May 20, 2016
2 parents d20f454 + ac88548 commit 578e9d5
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 28 deletions.
1 change: 1 addition & 0 deletions addons/skin.estouchy/xml/defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<texturesliderbar>-</texturesliderbar>
<textureslidernib>-</textureslidernib>
<textureslidernibfocus>-</textureslidernibfocus>
<orientation>horizontal</orientation>
</default>
<default type="sliderex">
<height>35</height>
Expand Down
1 change: 1 addition & 0 deletions addons/skin.estuary/1080i/Defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<texturesliderbar border="10">dialogs/mediasource/slider-back.png</texturesliderbar>
<textureslidernib>dialogs/mediasource/slider-nib-nf.png</textureslidernib>
<textureslidernibfocus colordiffuse="button_focus">dialogs/mediasource/slider-nib-nf.png</textureslidernibfocus>
<orientation>horizontal</orientation>
</default>
<default type="sliderex">
<height>35</height>
Expand Down
2 changes: 1 addition & 1 deletion xbmc/guilib/GUIControlFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ CGUIControl* CGUIControlFactory::Create(int parentID, const CRect &rect, TiXmlEl
{
control = new CGUISliderControl(
parentID, id, posX, posY, width, height,
textureBar, textureNib, textureNibFocus, SLIDER_CONTROL_TYPE_PERCENTAGE);
textureBar, textureNib, textureNibFocus, SLIDER_CONTROL_TYPE_PERCENTAGE, orientation);

((CGUISliderControl *)control)->SetInfo(singleInfo);
((CGUISliderControl *)control)->SetAction(action);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/guilib/GUISettingsSliderControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#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)
: CGUISliderControl(parentID, controlID, posX, posY, sliderWidth, sliderHeight, backGroundTexture, nibTexture,nibTextureFocus, iType, HORIZONTAL)
, m_buttonControl(parentID, controlID, posX, posY, width, height, textureFocus, textureNoFocus, labelInfo)
, m_label(posX, posY, width, height, labelInfo)
{
Expand Down
92 changes: 73 additions & 19 deletions xbmc/guilib/GUISliderControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static const SliderAction actions[] = {
{"volume", "SetVolume(%2f)", PLAYER_VOLUME, true}
};

CGUISliderControl::CGUISliderControl(int parentID, int controlID, float posX, float posY, float width, float height, const CTextureInfo& backGroundTexture, const CTextureInfo& nibTexture, const CTextureInfo& nibTextureFocus, int iType)
CGUISliderControl::CGUISliderControl(int parentID, int controlID, float posX, float posY, float width, float height, const CTextureInfo& backGroundTexture, const CTextureInfo& nibTexture, const CTextureInfo& nibTextureFocus, int iType, ORIENTATION orientation)
: CGUIControl(parentID, controlID, posX, posY, width, height)
, m_guiBackground(posX, posY, width, height, backGroundTexture)
, m_guiSelectorLower(posX, posY, width, height, nibTexture)
Expand All @@ -55,6 +55,7 @@ CGUISliderControl::CGUISliderControl(int parentID, int controlID, float posX, fl
m_floatValues[0] = m_fStart;
m_floatValues[1] = m_fEnd;
ControlType = GUICONTROL_SLIDER;
m_orientation = orientation;
m_iInfoCode = 0;
m_dragging = false;
m_action = NULL;
Expand All @@ -79,18 +80,22 @@ void CGUISliderControl::Process(unsigned int currentTime, CDirtyRegionList &dirt
SetIntValue(val);
}

float fScaleY = m_height == 0 ? 1.0f : m_height / m_guiBackground.GetTextureHeight();
float fScale;
if (m_orientation == HORIZONTAL)
fScale = m_height == 0 ? 1.0f : m_height / m_guiBackground.GetTextureHeight();
else
fScale = m_width == 0 ? 1.0f : m_width / m_guiBackground.GetTextureWidth();

dirty |= m_guiBackground.SetHeight(m_height);
dirty |= m_guiBackground.SetWidth(m_width);
dirty |= m_guiBackground.Process(currentTime);

CGUITexture &nibLower = (m_bHasFocus && !IsDisabled() && m_currentSelector == RangeSelectorLower) ? m_guiSelectorLowerFocus : m_guiSelectorLower;
dirty |= ProcessSelector(nibLower, currentTime, fScaleY, RangeSelectorLower);
dirty |= ProcessSelector(nibLower, currentTime, fScale, RangeSelectorLower);
if (m_rangeSelection)
{
CGUITexture &nibUpper = (m_bHasFocus && !IsDisabled() && m_currentSelector == RangeSelectorUpper) ? m_guiSelectorUpperFocus : m_guiSelectorUpper;
dirty |= ProcessSelector(nibUpper, currentTime, fScaleY, RangeSelectorUpper);
dirty |= ProcessSelector(nibUpper, currentTime, fScale, RangeSelectorUpper);
}

if (dirty)
Expand All @@ -99,25 +104,46 @@ void CGUISliderControl::Process(unsigned int currentTime, CDirtyRegionList &dirt
CGUIControl::Process(currentTime, dirtyregions);
}

bool CGUISliderControl::ProcessSelector(CGUITexture &nib, unsigned int currentTime, float fScaleY, RangeSelector selector)
bool CGUISliderControl::ProcessSelector(CGUITexture &nib, unsigned int currentTime, float fScale, RangeSelector selector)
{
bool dirty = false;
// we render the nib centered at the appropriate percentage, except where the nib
// would overflow the background image
dirty |= nib.SetHeight(nib.GetTextureHeight() * fScaleY);
dirty |= nib.SetWidth(nib.GetHeight() * 2);
if (m_orientation == HORIZONTAL)
{
dirty |= nib.SetHeight(nib.GetTextureHeight() * fScale);
dirty |= nib.SetWidth(nib.GetHeight() * 2);
}
else
{
dirty |= nib.SetWidth(nib.GetTextureWidth() * fScale);
dirty |= nib.SetHeight(nib.GetWidth() * 2);
}
CAspectRatio ratio(CAspectRatio::AR_KEEP);
ratio.align = ASPECT_ALIGN_LEFT | ASPECT_ALIGNY_CENTER;
dirty |= nib.SetAspectRatio(ratio);
dirty |= nib.Process(currentTime);
CRect rect = nib.GetRenderRect();

float offset = GetProportion(selector) * m_width - rect.Width() / 2;
if (offset > m_width - rect.Width())
offset = m_width - rect.Width();
if (offset < 0)
offset = 0;
dirty |= nib.SetPosition(m_guiBackground.GetXPosition() + offset, m_guiBackground.GetYPosition());
float offset;
if (m_orientation == HORIZONTAL)
{
offset = GetProportion(selector) * m_width - rect.Width() / 2;
if (offset > m_width - rect.Width())
offset = m_width - rect.Width();
if (offset < 0)
offset = 0;
dirty |= nib.SetPosition(m_guiBackground.GetXPosition() + offset, m_guiBackground.GetYPosition());
}
else
{
offset = GetProportion(selector) * m_height - rect.Height() / 2;
if (offset > m_height - rect.Height())
offset = m_height - rect.Height();
if (offset < 0)
offset = 0;
dirty |= nib.SetPosition(m_guiBackground.GetXPosition(), m_guiBackground.GetYPosition() + m_guiBackground.GetHeight() - offset - ((nib.GetHeight() - rect.Height()) / 2 + rect.Height()));
}
dirty |= nib.Process(currentTime); // need to process again as the position may have changed

return dirty;
Expand Down Expand Up @@ -165,12 +191,36 @@ bool CGUISliderControl::OnAction(const CAction &action)
switch ( action.GetID() )
{
case ACTION_MOVE_LEFT:
Move(-1);
return true;
if (m_orientation == HORIZONTAL)
{
Move(-1);
return true;
}
break;

case ACTION_MOVE_RIGHT:
Move(1);
return true;
if (m_orientation == HORIZONTAL)
{
Move(1);
return true;
}
break;

case ACTION_MOVE_UP:
if (m_orientation == VERTICAL)
{
Move(1);
return true;
}
break;

case ACTION_MOVE_DOWN:
if (m_orientation == VERTICAL)
{
Move(-1);
return true;
}
break;

case ACTION_SELECT_ITEM:
// switch between the two sliders
Expand All @@ -181,7 +231,6 @@ bool CGUISliderControl::OnAction(const CAction &action)
default:
break;
}

return CGUIControl::OnAction(action);
}

Expand Down Expand Up @@ -485,7 +534,12 @@ bool CGUISliderControl::HitTest(const CPoint &point) const

void CGUISliderControl::SetFromPosition(const CPoint &point, bool guessSelector /* = false */)
{
float fPercent = (point.x - m_guiBackground.GetXPosition()) / m_guiBackground.GetWidth();

float fPercent;
if (m_orientation == HORIZONTAL)
fPercent = (point.x - m_guiBackground.GetXPosition()) / m_guiBackground.GetWidth();
else
fPercent = (point.y - m_guiBackground.GetYPosition()) / m_guiBackground.GetHeight();
if (fPercent < 0) fPercent = 0;
if (fPercent > 1) fPercent = 1;

Expand Down
2 changes: 2 additions & 0 deletions xbmc/guilib/GUISliderControl.dox
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ the position, size, and look of the slider control.
<controloffsetx></controloffsetx>
<controloffsety></controloffsety>
<pulseonselect></pulseonselect>
<orientation>vertical</orientation>
<onup>2</onup>
<ondown>3</ondown>
<onleft>1</onleft>
Expand All @@ -52,6 +53,7 @@ important, as xml tags are case-sensitive.
| controloffsetx | Amount to offset the slider background texture from the left edge of the control. Only useful if a value is being rendered as well (ie in int or float mode).
| controloffsety | Amount to offset the slider background texture from the top edge of the control.
| info | Specifies the information that the slider controls. [See here for more information](http://kodi.wiki/view/InfoLabels).
| orientation | Specifies whether this scrollbar is horizontal or vertical. Defaults to vertical.
| action | Can be <b>'volume'</b> to adjust the volume or 'seek' to change the seek position.


Expand Down
5 changes: 3 additions & 2 deletions xbmc/guilib/GUISliderControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CGUISliderControl :
RangeSelectorUpper = 1
} RangeSelector;

CGUISliderControl(int parentID, int controlID, float posX, float posY, float width, float height, const CTextureInfo& backGroundTexture, const CTextureInfo& mibTexture, const CTextureInfo& nibTextureFocus, int iType);
CGUISliderControl(int parentID, int controlID, float posX, float posY, float width, float height, const CTextureInfo& backGroundTexture, const CTextureInfo& mibTexture, const CTextureInfo& nibTextureFocus, int iType, ORIENTATION orientation);
virtual ~CGUISliderControl(void);
virtual CGUISliderControl *Clone() const { return new CGUISliderControl(*this); };

Expand All @@ -70,7 +70,7 @@ class CGUISliderControl :
virtual void SetRange(int iStart, int iEnd);
virtual void SetFloatRange(float fStart, float fEnd);
virtual bool OnMessage(CGUIMessage& message);
bool ProcessSelector(CGUITexture &nib, unsigned int currentTime, float fScaleY, RangeSelector selector);
bool ProcessSelector(CGUITexture &nib, unsigned int currentTime, float fScale, RangeSelector selector);
void SetRangeSelection(bool rangeSelection);
bool GetRangeSelection() const { return m_rangeSelection; }
void SetRangeSelector(RangeSelector selector);
Expand Down Expand Up @@ -129,5 +129,6 @@ class CGUISliderControl :
std::string m_textValue; ///< Allows overriding of the text value to be displayed (parent must update when the slider updates)
const SliderAction *m_action; ///< Allows the skin to configure the action of a click on the slider \sa SendClick
bool m_dragging; ///< Whether we're in a (mouse/touch) drag operation or not - some actions are sent only on release.
ORIENTATION m_orientation;
};
#endif
5 changes: 3 additions & 2 deletions xbmc/interfaces/legacy/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,13 @@ namespace XBMCAddon
ControlSlider::ControlSlider(long x, long y, long width, long height,
const char* textureback,
const char* texture,
const char* texturefocus)
const char* texturefocus, int orientation)
{
dwPosX = x;
dwPosY = y;
dwWidth = width;
dwHeight = height;
iOrientation = orientation;

// if texture is supplied use it, else get default ones
strTextureBack = textureback ? textureback :
Expand All @@ -455,7 +456,7 @@ namespace XBMCAddon
pGUIControl = new CGUISliderControl(iParentId, iControlId,(float)dwPosX, (float)dwPosY,
(float)dwWidth,(float)dwHeight,
CTextureInfo(strTextureBack),CTextureInfo(strTexture),
CTextureInfo(strTextureFoc),0);
CTextureInfo(strTextureFoc), 0, ORIENTATION(iOrientation));

return pGUIControl;
}
Expand Down
8 changes: 5 additions & 3 deletions xbmc/interfaces/legacy/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ namespace XBMCAddon
/// @{
/// @brief **Used for a volume slider.**
///
/// \python_class{ ControlSlider(x, y, width, height[, textureback, texture, texturefocus]) }
/// \python_class{ ControlSlider(x, y, width, height[, textureback, texture, texturefocus, orientation]) }
///
/// The slider control is used for things where a sliding bar best represents
/// the operation at hand (such as a volume control or seek control). You can
Expand All @@ -2749,6 +2749,7 @@ namespace XBMCAddon
/// @param textureback [opt] string - image filename
/// @param texture [opt] string - image filename
/// @param texturefocus [opt] string - image filename
/// @param orientation [opt] integer - orientation of slider (xbmcgui.HORIZONTAL / xbmcgui.VERTICAL (default))
///
///
/// @note You can use the above as keywords for arguments and skip certain
Expand All @@ -2773,7 +2774,7 @@ namespace XBMCAddon
ControlSlider(long x, long y, long width, long height,
const char* textureback = NULL,
const char* texture = NULL,
const char* texturefocus = NULL);
const char* texturefocus = NULL, int orientation = 1);

#ifdef DOXYGEN_SHOULD_USE_THIS
///
Expand Down Expand Up @@ -2826,7 +2827,8 @@ namespace XBMCAddon
#ifndef SWIG
std::string strTextureBack;
std::string strTexture;
std::string strTextureFoc;
std::string strTextureFoc;
int iOrientation;

SWIGHIDDENVIRTUAL CGUIControl* Create();

Expand Down
3 changes: 3 additions & 0 deletions xbmc/interfaces/legacy/ModuleXbmcgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ namespace XBMCAddon
SWIG_CONSTANT(int,INPUT_IPADDRESS);
SWIG_CONSTANT(int,INPUT_PASSWORD);

SWIG_CONSTANT(int, HORIZONTAL);
SWIG_CONSTANT(int, VERTICAL);

SWIG_CONSTANT(int,PASSWORD_VERIFY);
SWIG_CONSTANT(int,ALPHANUM_HIDE_INPUT);

Expand Down

0 comments on commit 578e9d5

Please sign in to comment.