Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI] New <depth> tag for stereoscopic effect for controls. #7855

Merged
merged 8 commits into from
Aug 31, 2015
14 changes: 13 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -17131,7 +17131,19 @@ msgctxt "#36549"
msgid "Use iOS8 compatible AirPlay support. If you have trouble with older iOS devices detecting this application as a valid target try switching this off. This option requires a restart to take effect!"
msgstr ""

#empty strings from id 36550 to 36599
#. Name of a setting
#: system/settings/settings.xml

This comment was marked as spam.

msgctxt "#36550"
msgid "Stereoscopic 3D effect strength"
msgstr ""

#. Description of setting "Appearance -> Skin -> Stereoscopic 3D effect strength" with label #36550
#: system/settings/settings.xml
msgctxt "#36551"
msgid "Defines the strength of the stereoscopic 3D effect in the GUI. This is done by controlling the depth of perception within the GUI, so the higher the value, the more elements will pop out of the screen. [Zero] Disables the stereoscopic 3D effect of the GUI.[CR]For a good visual experience, the value should be higher for small screens and lower for large screens. Note: this is not supported by all skins."
msgstr ""

#empty strings from id 36552 to 36599
#reserved strings 365XX

#. Description of settings category "Music -> Library" with label #14022
Expand Down
13 changes: 13 additions & 0 deletions system/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@
<show more="true" details="true">installed</show>
</control>
</setting>
<setting id="lookandfeel.stereostrength" type="integer" label="36550" help="36551">
<level>2</level>
<default>5</default>
<constraints>
<minimum>0</minimum>
<step>1</step>
<maximum>10</maximum>
</constraints>
<dependencies>
<dependency type="update" setting="lookandfeel.skin" />
</dependencies>
<control type="spinner" format="string" />
</setting>
</group>
<group id="2">
<setting id="lookandfeel.enablerssfeeds" type="boolean" label="13305" help="36111">
Expand Down
15 changes: 15 additions & 0 deletions xbmc/guilib/GUIControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ CGUIControl::CGUIControl() :
m_pushedUpdates = false;
m_pulseOnSelect = false;
m_controlIsDirty = true;
m_stereo = 0.0f;
}

CGUIControl::CGUIControl(int parentID, int controlID, float posX, float posY, float width, float height)
Expand All @@ -79,6 +80,7 @@ CGUIControl::CGUIControl(int parentID, int controlID, float posX, float posY, fl
m_pushedUpdates = false;
m_pulseOnSelect = false;
m_controlIsDirty = false;
m_stereo = 0.0f;
}


Expand Down Expand Up @@ -174,14 +176,22 @@ void CGUIControl::DoRender()
{
if (IsVisible())
{
bool hasStereo = m_stereo != 0.0
&& g_graphicsContext.GetStereoMode() != RENDER_STEREO_MODE_MONO
&& g_graphicsContext.GetStereoMode() != RENDER_STEREO_MODE_OFF;

g_graphicsContext.SetTransform(m_cachedTransform);
if (m_hasCamera)
g_graphicsContext.SetCameraPosition(m_camera);
if (hasStereo)
g_graphicsContext.SetStereoFactor(m_stereo);

GUIPROFILER_RENDER_BEGIN(this);
Render();
GUIPROFILER_RENDER_END(this);

if (hasStereo)
g_graphicsContext.RestoreStereoFactor();
if (m_hasCamera)
g_graphicsContext.RestoreCameraPosition();
g_graphicsContext.RemoveTransform();
Expand Down Expand Up @@ -920,3 +930,8 @@ CPoint CGUIControl::GetRenderPosition() const
point += m_parentControl->GetRenderPosition();
return point;
}

void CGUIControl::SetStereoFactor(const float &factor)
{
m_stereo = factor;
}
2 changes: 2 additions & 0 deletions xbmc/guilib/GUIControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class CGUIControl
virtual void SetPosition(float posX, float posY);
virtual void SetHitRect(const CRect &rect);
virtual void SetCamera(const CPoint &camera);
virtual void SetStereoFactor(const float &factor);
bool SetColorDiffuse(const CGUIInfoColor &color);
CPoint GetRenderPosition() const;
virtual float GetXPosition() const;
Expand Down Expand Up @@ -353,6 +354,7 @@ class CGUIControl
std::vector<CAnimation> m_animations;
CPoint m_camera;
bool m_hasCamera;
float m_stereo;
TransformMatrix m_transform;
TransformMatrix m_cachedTransform; // Contains the absolute transform the control

Expand Down
5 changes: 5 additions & 0 deletions xbmc/guilib/GUIControlFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ CGUIControl* CGUIControlFactory::Create(int parentID, const CRect &rect, TiXmlEl

CRect hitRect;
CPoint camera;
float stereo = 0.f;
bool hasCamera = false;
bool resetOnLabelChange = true;
bool bPassword = false;
Expand Down Expand Up @@ -1093,6 +1094,9 @@ CGUIControl* CGUIControlFactory::Create(int parentID, const CRect &rect, TiXmlEl
cam->QueryFloatAttribute("y", &camera.y);
}

if (XMLUtils::GetFloat(pControlNode, "depth", stereo))
stereo = std::max(-1.f, std::min(1.f, stereo));

XMLUtils::GetInt(pControlNode, "scrollspeed", labelInfo.scrollSpeed);
spinInfo.scrollSpeed = labelInfo.scrollSpeed;

Expand Down Expand Up @@ -1491,6 +1495,7 @@ CGUIControl* CGUIControlFactory::Create(int parentID, const CRect &rect, TiXmlEl
control->SetPulseOnSelect(bPulse);
if (hasCamera)
control->SetCamera(camera);
control->SetStereoFactor(stereo);
}
return control;
}
6 changes: 6 additions & 0 deletions xbmc/guilib/GUIWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ bool CGUIWindow::Load(TiXmlElement* pRootElement)
pChild->QueryFloatAttribute("y", &m_camera.y);
m_hasCamera = true;
}
else if (strValue == "depth" && pChild->FirstChild())
{
float stereo = (float)atof(pChild->FirstChild()->Value());;
m_stereo = std::max(-1.f, std::min(1.f, stereo));
}
else if (strValue == "controls")
{
TiXmlElement *pControl = pChild->FirstChildElement();
Expand Down Expand Up @@ -1005,6 +1010,7 @@ void CGUIWindow::SetDefaults()
m_animations.clear();
m_origins.clear();
m_hasCamera = false;
m_stereo = 0.f;
m_animationsEnabled = true;
m_clearBackground = 0xff000000; // opaque black -> clear
m_hitRect.SetRect(0, 0, (float)m_coordsRes.iWidth, (float)m_coordsRes.iHeight);
Expand Down
41 changes: 34 additions & 7 deletions xbmc/guilib/GraphicContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ bool CGraphicContext::SetViewPort(float fx, float fy, float fwidth, float fheigh
g_Windowing.SetViewPort(newviewport);


UpdateCameraPosition(m_cameras.top());
UpdateCameraPosition(m_cameras.top(), m_stereoFactors.top());
return true;
}

Expand All @@ -257,7 +257,7 @@ void CGraphicContext::RestoreViewPort()
CRect viewport = StereoCorrection(m_viewStack.top());
g_Windowing.SetViewPort(viewport);

UpdateCameraPosition(m_cameras.top());
UpdateCameraPosition(m_cameras.top(), m_stereoFactors.top());
}

CPoint CGraphicContext::StereoCorrection(const CPoint &point) const
Expand Down Expand Up @@ -833,6 +833,9 @@ void CGraphicContext::SetScalingResolution(const RESOLUTION_INFO &res, bool need
while (!m_cameras.empty())
m_cameras.pop();
m_cameras.push(CPoint(0.5f*m_iScreenWidth, 0.5f*m_iScreenHeight));
while (!m_stereoFactors.empty())
m_stereoFactors.pop();
m_stereoFactors.push(0.0f);

// and reset the final transform
m_finalTransform = m_guiTransform;
Expand All @@ -843,7 +846,7 @@ void CGraphicContext::SetRenderingResolution(const RESOLUTION_INFO &res, bool ne
{
Lock();
SetScalingResolution(res, needsScaling);
UpdateCameraPosition(m_cameras.top());
UpdateCameraPosition(m_cameras.top(), m_stereoFactors.top());
Unlock();
}

Expand Down Expand Up @@ -888,14 +891,27 @@ void CGraphicContext::SetCameraPosition(const CPoint &camera)
cam.y *= (float)m_iScreenHeight / m_windowResolution.iHeight;

m_cameras.push(cam);
UpdateCameraPosition(m_cameras.top());
UpdateCameraPosition(m_cameras.top(), m_stereoFactors.top());
}

void CGraphicContext::RestoreCameraPosition()
{ // remove the top camera from the stack
assert(m_cameras.size());
m_cameras.pop();
UpdateCameraPosition(m_cameras.top());
UpdateCameraPosition(m_cameras.top(), m_stereoFactors.top());
}

void CGraphicContext::SetStereoFactor(float factor)
{
m_stereoFactors.push(factor);
UpdateCameraPosition(m_cameras.top(), m_stereoFactors.top());
}

void CGraphicContext::RestoreStereoFactor()
{ // remove the top factor from the stack
assert(m_stereoFactors.size());
m_stereoFactors.pop();
UpdateCameraPosition(m_cameras.top(), m_stereoFactors.top());
}

CRect CGraphicContext::generateAABB(const CRect &rect) const
Expand Down Expand Up @@ -938,9 +954,20 @@ CRect CGraphicContext::generateAABB(const CRect &rect) const
// the camera has changed, and if so, changes it. Similarly, it could set
// the world transform at that point as well (or even combine world + view
// to cut down on one setting)
void CGraphicContext::UpdateCameraPosition(const CPoint &camera)
void CGraphicContext::UpdateCameraPosition(const CPoint &camera, const float &factor)
{
g_Windowing.SetCameraPosition(camera, m_iScreenWidth, m_iScreenHeight);
float stereoFactor = 0.f;
if ( m_stereoMode != RENDER_STEREO_MODE_OFF
&& m_stereoMode != RENDER_STEREO_MODE_MONO
&& m_stereoView != RENDER_STEREO_VIEW_OFF)
{
RESOLUTION_INFO res = GetResInfo();
RESOLUTION_INFO desktop = GetResInfo(RES_DESKTOP);
float scaleRes = (static_cast<float>(res.iWidth) / static_cast<float>(desktop.iWidth));
float scaleX = static_cast<float>(CSettings::GetInstance().GetInt(CSettings::SETTING_LOOKANDFEEL_STEREOSTRENGTH)) * scaleRes;
stereoFactor = factor * (m_stereoView == RENDER_STEREO_VIEW_LEFT ? scaleX : -scaleX);
}
g_Windowing.SetCameraPosition(camera, m_iScreenWidth, m_iScreenHeight, stereoFactor);
}

bool CGraphicContext::RectIsAngled(float x1, float y1, float x2, float y2) const
Expand Down
5 changes: 4 additions & 1 deletion xbmc/guilib/GraphicContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class CGraphicContext : public CCriticalSection,
void SetStereoMode(RENDER_STEREO_MODE mode) { m_nextStereoMode = mode; }
RENDER_STEREO_MODE GetStereoMode() { return m_stereoMode; }
void RestoreCameraPosition();
void SetStereoFactor(float factor);
void RestoreStereoFactor();
/*! \brief Set a region in which to clip all rendering
Anything that is rendered after setting a clip region will be clipped so that no part renders
outside of the clip region. Successive calls to SetClipRegion intersect the clip region, which
Expand Down Expand Up @@ -269,14 +271,15 @@ class CGraphicContext : public CCriticalSection,
float scaleX;
float scaleY;
};
void UpdateCameraPosition(const CPoint &camera);
void UpdateCameraPosition(const CPoint &camera, const float &factor);
// this method is indirectly called by the public SetVideoResolution
// it only works when called from mainthread (thats what SetVideoResolution ensures)
void SetVideoResolutionInternal(RESOLUTION res, bool forceUpdate);
RESOLUTION_INFO m_windowResolution;
std::stack<CPoint> m_cameras;
std::stack<CPoint> m_origins;
std::stack<CRect> m_clipRegions;
std::stack<float> m_stereoFactors;

UITransform m_guiTransform;
UITransform m_finalTransform;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/rendering/RenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class CRenderSystemBase
virtual void CaptureStateBlock() = 0;
virtual void ApplyStateBlock() = 0;

virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight) = 0;
virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor = 0.f) = 0;
virtual void ApplyHardwareTransform(const TransformMatrix &matrix) = 0;
virtual void RestoreHardwareTransform() = 0;
virtual void SetStereoMode(RENDER_STEREO_MODE mode, RENDER_STEREO_VIEW view)
Expand Down
4 changes: 2 additions & 2 deletions xbmc/rendering/dx/RenderSystemDX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ void CRenderSystemDX::ApplyStateBlock()
m_pGUIShader->ApplyStateBlock();
}

void CRenderSystemDX::SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight)
void CRenderSystemDX::SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor)
{
if (!m_bRenderCreated)
return;
Expand All @@ -1353,7 +1353,7 @@ void CRenderSystemDX::SetCameraPosition(const CPoint &camera, int screenWidth, i
// position.
XMMATRIX flipY, translate;
flipY = XMMatrixScaling(1.0, -1.0f, 1.0f);
translate = XMMatrixTranslation(-(w + offset.x), -(h + offset.y), 2 * h);
translate = XMMatrixTranslation(-(w + offset.x - stereoFactor), -(h + offset.y), 2 * h);
m_pGUIShader->SetView(XMMatrixMultiply(translate, flipY));

// projection onto screen space
Expand Down
2 changes: 1 addition & 1 deletion xbmc/rendering/dx/RenderSystemDX.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CRenderSystemDX : public CRenderSystemBase
virtual void CaptureStateBlock();
virtual void ApplyStateBlock();

virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight);
virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor = 0.f);

virtual void ApplyHardwareTransform(const TransformMatrix &matrix);
virtual void RestoreHardwareTransform();
Expand Down
4 changes: 2 additions & 2 deletions xbmc/rendering/gl/RenderSystemGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void CRenderSystemGL::ApplyStateBlock()
glEnable(GL_SCISSOR_TEST);
}

void CRenderSystemGL::SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight)
void CRenderSystemGL::SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor)
{
if (!m_bRenderCreated)
return;
Expand All @@ -451,7 +451,7 @@ void CRenderSystemGL::SetCameraPosition(const CPoint &camera, int screenWidth, i
float h = (float)m_viewPort[3]*0.5f;

glMatrixModview->LoadIdentity();
glMatrixModview->Translatef(-(w + offset.x), +(h + offset.y), 0);
glMatrixModview->Translatef(-(w + offset.x - stereoFactor), +(h + offset.y), 0);
glMatrixModview->LookAt(0.0, 0.0, -2.0*h, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0);
glMatrixModview.Load();

Expand Down
2 changes: 1 addition & 1 deletion xbmc/rendering/gl/RenderSystemGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CRenderSystemGL : public CRenderSystemBase
virtual void CaptureStateBlock();
virtual void ApplyStateBlock();

virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight);
virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor = 0.0f);

virtual void ApplyHardwareTransform(const TransformMatrix &matrix);
virtual void RestoreHardwareTransform();
Expand Down
4 changes: 2 additions & 2 deletions xbmc/rendering/gles/RenderSystemGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void CRenderSystemGLES::ApplyStateBlock()
glClear(GL_DEPTH_BUFFER_BIT);
}

void CRenderSystemGLES::SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight)
void CRenderSystemGLES::SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor)
{
if (!m_bRenderCreated)
return;
Expand All @@ -414,7 +414,7 @@ void CRenderSystemGLES::SetCameraPosition(const CPoint &camera, int screenWidth,
float h = (float)m_viewPort[3]*0.5f;

glMatrixModview->LoadIdentity();
glMatrixModview->Translatef(-(w + offset.x), +(h + offset.y), 0);
glMatrixModview->Translatef(-(w + offset.x - stereoFactor), +(h + offset.y), 0);
glMatrixModview->LookAt(0.0, 0.0, -2.0*h, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0);
glMatrixModview.Load();

Expand Down
2 changes: 1 addition & 1 deletion xbmc/rendering/gles/RenderSystemGLES.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CRenderSystemGLES : public CRenderSystemBase
virtual void CaptureStateBlock();
virtual void ApplyStateBlock();

virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight);
virtual void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor = 0.0f);

virtual void ApplyHardwareTransform(const TransformMatrix &matrix);
virtual void RestoreHardwareTransform();
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const std::string CSettings::SETTING_LOOKANDFEEL_STARTUPWINDOW = "lookandfeel.st
const std::string CSettings::SETTING_LOOKANDFEEL_SOUNDSKIN = "lookandfeel.soundskin";
const std::string CSettings::SETTING_LOOKANDFEEL_ENABLERSSFEEDS = "lookandfeel.enablerssfeeds";
const std::string CSettings::SETTING_LOOKANDFEEL_RSSEDIT = "lookandfeel.rssedit";
const std::string CSettings::SETTING_LOOKANDFEEL_STEREOSTRENGTH = "lookandfeel.stereostrength";
const std::string CSettings::SETTING_LOCALE_LANGUAGE = "locale.language";
const std::string CSettings::SETTING_LOCALE_COUNTRY = "locale.country";
const std::string CSettings::SETTING_LOCALE_CHARSET = "locale.charset";
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CSettings : public CSettingCreator, public CSettingControlCreator
static const std::string SETTING_LOOKANDFEEL_SOUNDSKIN;
static const std::string SETTING_LOOKANDFEEL_ENABLERSSFEEDS;
static const std::string SETTING_LOOKANDFEEL_RSSEDIT;
static const std::string SETTING_LOOKANDFEEL_STEREOSTRENGTH;
static const std::string SETTING_LOCALE_LANGUAGE;
static const std::string SETTING_LOCALE_COUNTRY;
static const std::string SETTING_LOCALE_CHARSET;
Expand Down