GroupList tweening

This commit is contained in:
Glenn Maynard
2003-06-18 00:10:52 +00:00
parent 2d64af7a93
commit 352dc15d49
3 changed files with 129 additions and 66 deletions
+5
View File
@@ -491,6 +491,11 @@ SpacingX=0
SpacingY=28
GainFocusCommand=stoptweening;glowshift;effectperiod,0.5;linear,0.2;x,-40
LoseFocusCommand=stoptweening;stopeffect;linear,0.2;x,0
HideItemCommand=stoptweening;linear,0.2;diffusealpha,0
ShowItemCommand=stoptweening;linear,0.2;diffusealpha,1;zoom,1.0;
# This just selects the type of tweening used for scrolling the list; it shouldn't actually
# queue any commands.
ScrollTweenCommand=stoptweening;linear,0.2;
[MusicList]
NumColumns=4
+113 -59
View File
@@ -2,6 +2,7 @@
#include "GroupList.h"
#include "ThemeManager.h"
#include "SongManager.h"
#include "RageLog.h"
/* If this actor is used anywhere other than SelectGroup, we
* can add a setting that changes which metric group we pull
@@ -10,75 +11,122 @@
#define START_Y THEME->GetMetricF("GroupList","StartY")
#define SPACING_X THEME->GetMetricF("GroupList","SpacingX")
#define SPACING_Y THEME->GetMetricF("GroupList","SpacingY")
#define SCROLL_TWEEN_COMMAND THEME->GetMetric ("GroupList","ScrollTweenCommand")
#define GAIN_FOCUS_COMMAND THEME->GetMetric ("GroupList","GainFocusCommand")
#define LOSE_FOCUS_COMMAND THEME->GetMetric ("GroupList","LoseFocusCommand")
#define HIDE_ITEM_COMMAND THEME->GetMetric ("GroupList","HideItemCommand")
#define SHOW_ITEM_COMMAND THEME->GetMetric ("GroupList","ShowItemCommand")
const int MAX_GROUPS_ONSCREEN = 7;
GroupList::GroupList()
{
m_iSelection = m_iTop = 0;
}
GroupList::~GroupList()
{
for( unsigned i = 0; i < m_Frames.size(); ++i )
{
delete m_Frames[i];
delete m_sprButtons[i];
delete m_screenLabels[i];
}
}
bool GroupList::ItemIsOnScreen( int n ) const
{
const int offset = n - m_iTop;
return offset >= 0 && offset < MAX_GROUPS_ONSCREEN;
}
void GroupList::Load( const CStringArray& asGroupNames )
{
m_asLabels = asGroupNames;
for( unsigned i=0; i<min(m_asLabels.size(), MAX_GROUPS_ONSCREEN); i++ )
this->AddChild( &m_Frame );
for( unsigned i=0; i < m_asLabels.size(); i++ )
{
float fX = START_X + i*SPACING_X;
float fY = START_Y + i*SPACING_Y;
ActorFrame *frame = new ActorFrame;
frame->SetXY( START_X + i*SPACING_X, START_Y + i*SPACING_Y );
m_Frames.push_back(frame);
m_Frame.AddChild( frame );
m_sprButton[i].Load( THEME->GetPathToG("GroupList bar") );
m_sprButton[i].SetXY( fX, fY );
this->AddChild( &m_sprButton[i] );
Sprite *spr = new Sprite;
m_sprButtons.push_back(spr);
spr->Load( THEME->GetPathToG("GroupList bar") );
frame->AddChild( spr );
m_screenLabels[i].LoadFromFont( THEME->GetPathToF("GroupList label") );
m_screenLabels[i].SetXY( fX, fY );
m_screenLabels[i].SetShadowLength( 2 );
this->AddChild( &m_screenLabels[i] );
BitmapText *text = new BitmapText;
m_screenLabels.push_back(text);
text->LoadFromFont( THEME->GetPathToF("GroupList label") );
text->SetShadowLength( 2 );
text->SetText( SONGMAN->ShortenGroupName( asGroupNames[i] ) );
frame->AddChild( text );
if( i == 0 )
text->TurnRainbowOn();
else {
text->TurnRainbowOff();
text->SetDiffuse( SONGMAN->GetGroupColor(asGroupNames[i]) );
}
m_bHidden.push_back( ItemIsOnScreen(i) );
ResetTextSize( i );
}
SetLabels();
AfterChange();
}
void GroupList::SetLabels()
void GroupList::ResetTextSize( int i )
{
for( unsigned i=0; i<min(m_asLabels.size(), MAX_GROUPS_ONSCREEN); i++ )
{
CString &label = m_asLabels[m_iTop+i];
m_screenLabels[i].SetText( SONGMAN->ShortenGroupName( label ) );
float fTextWidth = (float)m_screenLabels[i].GetWidestLineWidthInSourcePixels();
float fButtonWidth = m_sprButton[i].GetZoomedWidth();
BitmapText *text = m_screenLabels[i];
const float fTextWidth = (float)text->GetWidestLineWidthInSourcePixels();
const float fButtonWidth = m_sprButtons[i]->GetZoomedWidth();
float fZoom = fButtonWidth/fTextWidth;
fZoom = min( fZoom, 0.8f );
m_screenLabels[i].SetZoomX( fZoom );
m_screenLabels[i].SetZoomY( 0.8f );
if( m_iTop+i == 0 ) m_screenLabels[i].TurnRainbowOn();
else {
m_screenLabels[i].TurnRainbowOff();
m_screenLabels[i].SetDiffuse( SONGMAN->GetGroupColor(label) );
}
}
float fZoom = fButtonWidth/fTextWidth;
fZoom = min( fZoom, 0.8f );
text->SetZoomX( fZoom );
text->SetZoomY( 0.8f );
}
void GroupList::BeforeChange()
{
int iSel = m_iSelection-m_iTop;
m_sprButton[iSel].Command( LOSE_FOCUS_COMMAND );
m_screenLabels[iSel].Command( LOSE_FOCUS_COMMAND );
m_Frames[m_iSelection]->Command( LOSE_FOCUS_COMMAND );
}
void GroupList::AfterChange()
{
int iSel = m_iSelection-m_iTop;
m_Frame.StopTweening();
m_Frame.Command( SCROLL_TWEEN_COMMAND );
m_Frame.SetY( -m_iTop*SPACING_Y );
m_Frames[m_iSelection]->Command( GAIN_FOCUS_COMMAND );
for( int i=0; i < (int) m_asLabels.size(); i++ )
{
const bool IsHidden = !ItemIsOnScreen(i);
const bool WasHidden = m_bHidden[i];
if( IsHidden && !WasHidden )
{
m_sprButtons[i]->Command( HIDE_ITEM_COMMAND );
m_screenLabels[i]->Command( HIDE_ITEM_COMMAND );
}
else if( !IsHidden && WasHidden )
{
m_sprButtons[i]->Command( SHOW_ITEM_COMMAND );
m_screenLabels[i]->Command( SHOW_ITEM_COMMAND );
ResetTextSize( i );
}
m_bHidden[i] = IsHidden;
}
m_sprButton[iSel].Command( GAIN_FOCUS_COMMAND );
m_screenLabels[iSel].Command( GAIN_FOCUS_COMMAND );
}
void GroupList::Up()
@@ -120,45 +168,51 @@ void GroupList::SetSelection( unsigned sel )
ASSERT( m_iTop <= m_iSelection );
ASSERT( m_iTop+MAX_GROUPS_ONSCREEN > m_iSelection );
SetLabels();
AfterChange();
}
/* either tweened off screen (to come on screen),
tweened off screen (invisible),
onscreen (unselected),
or onscreen (selected)
coming on/ofscreen is internal
always invis<->unselected<->selected
*/
void GroupList::TweenOnScreen()
{
for( unsigned i=0; i<min(m_asLabels.size(), MAX_GROUPS_ONSCREEN); i++ )
for( int i=0; i < (int) m_asLabels.size(); i++ )
{
m_sprButton[i].SetX( 400 );
m_sprButton[i].BeginTweening( 0.1f*i, TWEEN_BOUNCE_END );
m_sprButton[i].BeginTweening( 0.2f, TWEEN_BOUNCE_END );
m_sprButton[i].SetX( 0 );
const int offset = max(0, i-m_iTop);
m_Frames[i]->SetX( 400 );
m_Frames[i]->BeginTweening( 0.1f*offset, TWEEN_BOUNCE_END );
m_Frames[i]->BeginTweening( 0.2f, TWEEN_BOUNCE_END );
m_Frames[i]->SetX( 0 );
m_screenLabels[i].SetX( 400 );
m_screenLabels[i].BeginTweening( 0.1f*i, TWEEN_BOUNCE_END );
m_screenLabels[i].BeginTweening( 0.2f, TWEEN_BOUNCE_END );
m_screenLabels[i].SetX( 0 );
/* If this item isn't visible, hide it and skip tweens. */
if( !ItemIsOnScreen(i) )
{
m_sprButtons[i]->Command( HIDE_ITEM_COMMAND );
m_screenLabels[i]->Command( HIDE_ITEM_COMMAND );
m_sprButtons[i]->FinishTweening();
m_screenLabels[i]->FinishTweening();
}
}
}
void GroupList::TweenOffScreen()
{
for( unsigned i=0; i<min(m_asLabels.size(), MAX_GROUPS_ONSCREEN); i++ )
for( int i=m_iTop; i < min(m_iTop+MAX_GROUPS_ONSCREEN, (int) m_asLabels.size()); i++ )
{
const int offset = max(0, i-m_iTop);
if( i == m_iSelection )
m_sprButton[i].BeginTweening( 1.0f, TWEEN_BOUNCE_BEGIN );
m_Frames[i]->BeginTweening( 1.0f, TWEEN_BOUNCE_BEGIN );
else
m_sprButton[i].BeginTweening( 0.1f*i, TWEEN_BOUNCE_BEGIN );
m_sprButton[i].BeginTweening( 0.2f, TWEEN_BOUNCE_BEGIN );
m_sprButton[i].SetX( 400 );
if( i == m_iSelection )
m_screenLabels[i].BeginTweening( 1.0f, TWEEN_BOUNCE_BEGIN );
else
m_screenLabels[i].BeginTweening( 0.1f*i, TWEEN_BOUNCE_BEGIN );
m_screenLabels[i].BeginTweening( 0.2f, TWEEN_BOUNCE_BEGIN );
m_screenLabels[i].SetX( 400 );
m_Frames[i]->BeginTweening( 0.1f*offset, TWEEN_BOUNCE_BEGIN );
m_Frames[i]->BeginTweening( 0.2f, TWEEN_BOUNCE_BEGIN );
m_Frames[i]->SetX( 400 );
}
}
+11 -7
View File
@@ -5,24 +5,28 @@
#include "Sprite.h"
#include "BitmapText.h"
const unsigned MAX_GROUPS_ONSCREEN = 7;
class GroupList: public ActorFrame {
Sprite m_sprButton[MAX_GROUPS_ONSCREEN];
BitmapText m_screenLabels[MAX_GROUPS_ONSCREEN];
ActorFrame m_Frame;
vector<Actor *> m_Frames;
vector<Sprite *> m_sprButtons;
vector<BitmapText *> m_screenLabels;
vector<CString> m_asLabels;
vector<bool> m_bHidden;
/* Currently selected label. */
unsigned m_iSelection;
int m_iSelection;
/* Label that's currently at the top of the screen. */
unsigned m_iTop;
int m_iTop;
void BeforeChange();
void AfterChange();
void SetLabels();
bool ItemIsOnScreen( int n ) const;
void ResetTextSize( int item );
public:
GroupList();
~GroupList();
void SetSelection(unsigned sel);
int GetSelection() const { return m_iSelection; }