This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
MyGameFramework/lib/gwen/controls/gwen_progressbar.cpp
Gered c5cdddbeaa initial commit
current versions of all of my basic framework sources, build configurations/scripts, and supporting assets
2013-01-31 12:53:05 -05:00

98 lines
1.7 KiB
C++

/*
GWEN
Copyright (c) 2010 Facepunch Studios
See license in Gwen.h
*/
#include "gwen_scrollcontrol.h"
#include "gwen_progressbar.h"
#include "../gwen_anim.h"
#include "../gwen_utility.h"
using namespace Gwen;
using namespace Gwen::Controls;
class ProgressBarThink : public Gwen::Anim::Animation
{
public:
ProgressBarThink()
{
m_fLastFrame = 0.0f;
}
virtual void Think()
{
float fDiff = Platform::GetTimeInSeconds() - m_fLastFrame;
gwen_cast<ProgressBar>(m_Control)->CycleThink( Gwen::Clamp( fDiff, 0, 0.3 ) );
m_fLastFrame = Platform::GetTimeInSeconds();
}
float m_fLastFrame;
};
GWEN_CONTROL_CONSTRUCTOR( ProgressBar )
{
SetMouseInputEnabled( true );
SetBounds( Gwen::Rect( 0, 0, 128, 32 ) );
SetTextPadding( Padding( 3, 3, 3, 3 ) );
SetHorizontal();
SetAlignment( Gwen::Pos::Center );
m_fProgress = 0.0f;
m_bAutoLabel = true;
m_fCycleSpeed = 0.0f;
Gwen::Anim::Add( this, new ProgressBarThink() );
}
void ProgressBar::SetValue(float val)
{
if ( val < 0 )
val = 0;
if ( val > 1 )
val = 1;
m_fProgress = val;
if ( m_bAutoLabel )
{
int displayVal = m_fProgress * 100;
SetText( Utility::ToString( displayVal ) + "%" );
}
}
void ProgressBar::CycleThink( float fDelta )
{
if ( !Visible() ) return;
if ( m_fCycleSpeed == 0.0f ) return;
m_fProgress += m_fCycleSpeed * fDelta;
if ( m_fProgress < 0.0f ) m_fProgress += 1.0f;
if ( m_fProgress > 1.0f ) m_fProgress -= 1.0f;
Redraw();
}
void ProgressBar::Render( Skin::Base* skin )
{
skin->DrawProgressBar( this, m_bHorizontal, m_fProgress);
}
float ProgressBar::GetCycleSpeed()
{
return m_fCycleSpeed;
}
void ProgressBar::SetCycleSpeed( float f )
{
m_fCycleSpeed = f;
}