Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
@@ -4,99 +4,96 @@
|
||||
See license in Gwen.h
|
||||
*/
|
||||
|
||||
|
||||
#include "Gwen/Controls/ScrollBar.h"
|
||||
#include "Gwen/Controls/HorizontalScrollBar.h"
|
||||
|
||||
using namespace Gwen;
|
||||
using namespace Gwen::Controls;
|
||||
|
||||
GWEN_CONTROL_CONSTRUCTOR( HorizontalScrollBar )
|
||||
GWEN_CONTROL_CONSTRUCTOR(HorizontalScrollBar)
|
||||
{
|
||||
m_Bar->SetHorizontal();
|
||||
|
||||
m_ScrollButton[SCROLL_BUTTON_LEFT]->SetDirectionLeft();
|
||||
m_ScrollButton[SCROLL_BUTTON_LEFT]->onPress.Add( this, &HorizontalScrollBar::NudgeLeft );
|
||||
m_ScrollButton[SCROLL_BUTTON_LEFT]->onPress.Add(this, &HorizontalScrollBar::NudgeLeft);
|
||||
|
||||
m_ScrollButton[SCROLL_BUTTON_RIGHT]->SetDirectionRight();
|
||||
m_ScrollButton[SCROLL_BUTTON_RIGHT]->onPress.Add( this, &HorizontalScrollBar::NudgeRight );
|
||||
m_ScrollButton[SCROLL_BUTTON_RIGHT]->onPress.Add(this, &HorizontalScrollBar::NudgeRight);
|
||||
|
||||
m_Bar->onDragged.Add( this, &HorizontalScrollBar::OnBarMoved );
|
||||
m_Bar->onDragged.Add(this, &HorizontalScrollBar::OnBarMoved);
|
||||
}
|
||||
|
||||
void HorizontalScrollBar::Layout( Skin::Base* skin )
|
||||
void HorizontalScrollBar::Layout(Skin::Base* skin)
|
||||
{
|
||||
BaseClass::Layout( skin );
|
||||
BaseClass::Layout(skin);
|
||||
|
||||
m_ScrollButton[SCROLL_BUTTON_LEFT]->SetWidth( Height() );
|
||||
m_ScrollButton[SCROLL_BUTTON_LEFT]->SetWidth(Height());
|
||||
m_ScrollButton[SCROLL_BUTTON_LEFT]->Dock(Pos::Left);
|
||||
|
||||
m_ScrollButton[SCROLL_BUTTON_RIGHT]->SetWidth( Height() );
|
||||
m_ScrollButton[SCROLL_BUTTON_RIGHT]->SetWidth(Height());
|
||||
m_ScrollButton[SCROLL_BUTTON_RIGHT]->Dock(Pos::Right);
|
||||
|
||||
m_Bar->SetHeight( GetButtonSize() );
|
||||
m_Bar->SetPadding( Padding( GetButtonSize(), 0, GetButtonSize(), 0 ) );
|
||||
m_Bar->SetHeight(GetButtonSize());
|
||||
m_Bar->SetPadding(Padding(GetButtonSize(), 0, GetButtonSize(), 0));
|
||||
|
||||
float barWidth = (m_fViewableContentSize / m_fContentSize) * (Width() - (GetButtonSize() * 2));
|
||||
|
||||
if ( barWidth < GetButtonSize() * 0.5 )
|
||||
if (barWidth < GetButtonSize() * 0.5)
|
||||
barWidth = GetButtonSize() * 0.5;
|
||||
|
||||
m_Bar->SetWidth(barWidth);
|
||||
m_Bar->SetHidden( Width() - (GetButtonSize() * 2) <= barWidth );
|
||||
m_Bar->SetHidden(Width() - (GetButtonSize() * 2) <= barWidth);
|
||||
|
||||
//Based on our last scroll amount, produce a position for the bar
|
||||
if ( !m_Bar->IsDepressed() )
|
||||
if (!m_Bar->IsDepressed())
|
||||
{
|
||||
SetScrolledAmount( GetScrolledAmount(), true );
|
||||
SetScrolledAmount(GetScrolledAmount(), true);
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalScrollBar::NudgeLeft( Base* /*control*/ )
|
||||
void HorizontalScrollBar::NudgeLeft(Base* /*control*/)
|
||||
{
|
||||
if ( !IsDisabled() )
|
||||
SetScrolledAmount( GetScrolledAmount() - GetNudgeAmount(), true);
|
||||
if (!IsDisabled())
|
||||
SetScrolledAmount(GetScrolledAmount() - GetNudgeAmount(), true);
|
||||
}
|
||||
|
||||
void HorizontalScrollBar::NudgeRight( Base* /*control*/ )
|
||||
void HorizontalScrollBar::NudgeRight(Base* /*control*/)
|
||||
{
|
||||
if ( !IsDisabled() )
|
||||
SetScrolledAmount( GetScrolledAmount() + GetNudgeAmount(), true);
|
||||
if (!IsDisabled())
|
||||
SetScrolledAmount(GetScrolledAmount() + GetNudgeAmount(), true);
|
||||
}
|
||||
|
||||
void HorizontalScrollBar::ScrollToLeft()
|
||||
{
|
||||
SetScrolledAmount( 0, true);
|
||||
SetScrolledAmount(0, true);
|
||||
}
|
||||
void HorizontalScrollBar::ScrollToRight()
|
||||
{
|
||||
SetScrolledAmount( 1, true);
|
||||
SetScrolledAmount(1, true);
|
||||
}
|
||||
|
||||
float HorizontalScrollBar::GetNudgeAmount()
|
||||
{
|
||||
if ( m_bDepressed )
|
||||
if (m_bDepressed)
|
||||
return m_fViewableContentSize / m_fContentSize;
|
||||
else
|
||||
else
|
||||
return BaseClass::GetNudgeAmount();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HorizontalScrollBar::OnMouseClickLeft( int x, int y, bool bDown )
|
||||
void HorizontalScrollBar::OnMouseClickLeft(int x, int y, bool bDown)
|
||||
{
|
||||
if ( bDown )
|
||||
if (bDown)
|
||||
{
|
||||
m_bDepressed = true;
|
||||
Gwen::MouseFocus = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Gwen::Point clickPos = CanvasPosToLocal( Gwen::Point( x, y ) );
|
||||
if ( clickPos.x < m_Bar->X() )
|
||||
NudgeLeft( this );
|
||||
else if ( clickPos.x > m_Bar->X() + m_Bar->Width() )
|
||||
NudgeRight( this );
|
||||
Gwen::Point clickPos = CanvasPosToLocal(Gwen::Point(x, y));
|
||||
if (clickPos.x < m_Bar->X())
|
||||
NudgeLeft(this);
|
||||
else if (clickPos.x > m_Bar->X() + m_Bar->Width())
|
||||
NudgeRight(this);
|
||||
|
||||
m_bDepressed = false;
|
||||
Gwen::MouseFocus = NULL;
|
||||
@@ -105,30 +102,30 @@ void HorizontalScrollBar::OnMouseClickLeft( int x, int y, bool bDown )
|
||||
|
||||
float HorizontalScrollBar::CalculateScrolledAmount()
|
||||
{
|
||||
return (float)(m_Bar->X() - GetButtonSize()) / (float)(Width() - m_Bar->Width() - (GetButtonSize() * 2 ));
|
||||
return (float)(m_Bar->X() - GetButtonSize()) / (float)(Width() - m_Bar->Width() - (GetButtonSize() * 2));
|
||||
}
|
||||
|
||||
bool HorizontalScrollBar::SetScrolledAmount( float amount, bool forceUpdate )
|
||||
bool HorizontalScrollBar::SetScrolledAmount(float amount, bool forceUpdate)
|
||||
{
|
||||
amount = Gwen::Clamp( amount, 0, 1 );
|
||||
amount = Gwen::Clamp(amount, 0, 1);
|
||||
|
||||
if ( !BaseClass::SetScrolledAmount( amount, forceUpdate ) )
|
||||
if (!BaseClass::SetScrolledAmount(amount, forceUpdate))
|
||||
return false;
|
||||
|
||||
if ( forceUpdate )
|
||||
if (forceUpdate)
|
||||
{
|
||||
int newX = GetButtonSize() + (amount * ((Width() - m_Bar->Width()) - (GetButtonSize()*2)));
|
||||
m_Bar->MoveTo( newX, m_Bar->Y() );
|
||||
int newX = GetButtonSize() + (amount * ((Width() - m_Bar->Width()) - (GetButtonSize() * 2)));
|
||||
m_Bar->MoveTo(newX, m_Bar->Y());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HorizontalScrollBar::OnBarMoved( Controls::Base* control )
|
||||
void HorizontalScrollBar::OnBarMoved(Controls::Base* control)
|
||||
{
|
||||
if ( m_Bar->IsDepressed() )
|
||||
if (m_Bar->IsDepressed())
|
||||
{
|
||||
SetScrolledAmount( CalculateScrolledAmount(), false );
|
||||
SetScrolledAmount(CalculateScrolledAmount(), false);
|
||||
BaseClass::OnBarMoved(control);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user