Skip to content

Commit

Permalink
Fade the current controller when mapping its buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
garbear committed Oct 23, 2016
1 parent 48f2dbd commit 5ca9830
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions xbmc/games/controllers/windows/GUIControllerList.h
Expand Up @@ -47,6 +47,7 @@ namespace GAME
virtual bool Refresh(void) override;
virtual void OnFocus(unsigned int controllerIndex) override;
virtual void OnSelect(unsigned int controllerIndex) override;
virtual int GetFocusedController() const override { return m_focusedController; }
virtual void ResetController(void) override;

private:
Expand Down
35 changes: 35 additions & 0 deletions xbmc/games/controllers/windows/GUIControllerWindow.cpp
Expand Up @@ -26,6 +26,8 @@
#include "addons/GUIWindowAddonBrowser.h"
#include "addons/IAddon.h"
#include "addons/AddonManager.h"
#include "guilib/GUIButtonControl.h"
#include "guilib/GUIControl.h"
#include "guilib/GUIMessage.h"
#include "guilib/WindowIDs.h"

Expand Down Expand Up @@ -56,6 +58,39 @@ CGUIControllerWindow::~CGUIControllerWindow(void)
delete m_featureList;
}

void CGUIControllerWindow::DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions)
{
/*
* Apply the faded focus texture to the current controller when unfocused
*/

CGUIControl* control = nullptr; // The controller button
bool bAlphaFaded = false; // True if the controller button has been focused and faded this frame

if (m_controllerList && m_controllerList->GetFocusedController() >= 0)
{
control = GetFirstFocusableControl(CONTROL_CONTROLLER_BUTTONS_START + m_controllerList->GetFocusedController());
if (control && !control->HasFocus())
{
if (control->GetControlType() == CGUIControl::GUICONTROL_BUTTON)
{
control->SetFocus(true);
static_cast<CGUIButtonControl*>(control)->SetAlpha(0x80);
bAlphaFaded = true;
}
}
}

CGUIDialog::DoProcess(currentTime, dirtyregions);

if (control && bAlphaFaded)
{
control->SetFocus(false);
if (control->GetControlType() == CGUIControl::GUICONTROL_BUTTON)
static_cast<CGUIButtonControl*>(control)->SetAlpha(0xFF);
}
}

bool CGUIControllerWindow::OnMessage(CGUIMessage& message)
{
switch (message.GetMessage())
Expand Down
1 change: 1 addition & 0 deletions xbmc/games/controllers/windows/GUIControllerWindow.h
Expand Up @@ -35,6 +35,7 @@ namespace GAME
virtual ~CGUIControllerWindow(void);

// implementation of CGUIControl via CGUIDialog
virtual void DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions) override;
virtual bool OnMessage(CGUIMessage& message) override;

protected:
Expand Down
6 changes: 6 additions & 0 deletions xbmc/games/controllers/windows/IConfigurationWindow.h
Expand Up @@ -87,6 +87,12 @@ namespace GAME
*/
virtual void OnSelect(unsigned int controllerIndex) = 0;

/*!
* \brief Get the index of the focused controller
* \return The index of the focused controller, or -1 if no controller has been focused yet
*/
virtual int GetFocusedController() const = 0;

/*!
* \brief Reset the focused controller
*/
Expand Down

0 comments on commit 5ca9830

Please sign in to comment.