SBSPSS/source/gui/gframe.cpp
2001-01-31 16:11:42 +00:00

325 lines
5.8 KiB
C++

/*=========================================================================
gbutton.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "gui\gframe.h"
#ifndef __PAD_PADS_H__
#include "pad\pads.h"
#endif
#ifndef __SOUND_SOUND_H__
#include "sound\sound.h"
#endif
/* Std Lib
------- */
/* Data
---- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIGroupFrame::setFlags(GUI_FLAGS _flags)
{
CGUIObject *pGUI;
CGUIObject::setFlags(_flags);
pGUI=getChild();
while(pGUI)
{
pGUI->setFlags(_flags);
pGUI=pGUI->getNext();
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIGroupFrame::clearFlags(GUI_FLAGS _flags)
{
CGUIObject *pGUI;
CGUIObject::clearFlags(_flags);
pGUI=getChild();
while(pGUI)
{
pGUI->clearFlags(_flags);
pGUI=pGUI->getNext();
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CGUIGroupFrame::isSelectable()
{
CGUIObject *pGUI;
int selectable=false;
pGUI=getChild();
while(pGUI)
{
if(pGUI->isSelectable())
{
selectable=true;
break;
}
pGUI=pGUI->getNext();
}
return selectable;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CGUIGroupFrame::isUnselectable()
{
CGUIObject *pGUI;
int unselectable=false;
pGUI=getChild();
while(pGUI)
{
if(pGUI->isUnselectable())
{
unselectable=true;
break;
}
pGUI=pGUI->getNext();
}
return unselectable;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIControlFrame::think(int _frames)
{
int pad;
int makeNoise=false;
CGUIObject::think(_frames);
pad=PadGetRepeat(0);
if(pad&PAD_DOWN)
{
CGUIObject *pGUI;
pGUI=getChild();
if(pGUI)
{
// Get current selection and deselect it
while(!pGUI->isSelected())
{
ASSERT(pGUI);
pGUI=pGUI->getNext();
}
if(pGUI->isUnselectable())
{
pGUI->unselect();
// Find next selectable object and select it
do
{
pGUI=pGUI->getNext();
if(!pGUI)pGUI=getChild();
}
while(!pGUI->isSelectable());
pGUI->select();
}
}
makeNoise=true;
}
else if(pad&PAD_UP)
{
CGUIObject *pGUI,*prevGUI;
pGUI=getChild();
prevGUI=0;
if(pGUI)
{
// Get current selection and deselect it
while(!pGUI->isSelected())
{
ASSERT(pGUI);
if(pGUI->isSelectable())
{
prevGUI=pGUI;
}
pGUI=pGUI->getNext();
}
if(pGUI->isUnselectable())
{
pGUI->unselect();
// Find previous selectable object and select it
if(!prevGUI)
{
do
{
if(pGUI->isSelectable())
{
prevGUI=pGUI;
}
pGUI=pGUI->getNext();
}
while(pGUI);
}
prevGUI->select();
}
}
makeNoise=true;
}
if(makeNoise)
{
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__MOVE_CURSOR);
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIControlFrame::setFlags(GUI_FLAGS _flags)
{
GUI_FLAGS childFlags;
CGUIObject::setFlags(_flags);
childFlags=(GUI_FLAGS)(_flags&(-1^FLAG_SELECTED)); // Don't propogate the SELECTED flag
if(getChild())getChild()->setFlags(childFlags);
if(_flags&FLAG_SELECTED)
{
selectFrame();
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIControlFrame::clearFlags(GUI_FLAGS _flags)
{
GUI_FLAGS childFlags;
CGUIObject::clearFlags(_flags);
childFlags=(GUI_FLAGS)(_flags&(-1^FLAG_SELECTED)); // Don't propogate the SELECTED flag
if(getChild())getChild()->clearFlags(childFlags);
if(_flags&FLAG_SELECTED)
{
unselectFrame();
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIControlFrame::selectFrame()
{
CGUIObject *pGUI;
pGUI=getChild();
while(!pGUI->isSelectable())
{
ASSERT(pGUI);
pGUI=pGUI->getNext();
}
pGUI->select();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIControlFrame::unselectFrame()
{
CGUIObject *pGUI;
pGUI=getChild();
if(pGUI)
{
while(!pGUI->isSelected())
{
ASSERT(pGUI);
pGUI=pGUI->getNext();
}
pGUI->unselect();
}
}
/*===========================================================================
end */