SBSPSS/source/gui/gframe.cpp

375 lines
6.7 KiB
C++
Raw Normal View History

2000-11-02 16:54:27 +01:00
/*=========================================================================
2000-11-02 18:16:10 +01:00
gbutton.cpp
2000-11-02 16:54:27 +01:00
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
2001-01-31 17:11:42 +01:00
#ifndef __SOUND_SOUND_H__
#include "sound\sound.h"
#endif
2000-11-02 16:54:27 +01:00
/* Std Lib
------- */
/* Data
---- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIGroupFrame::setFlags(GUI_FLAGS _flags)
{
CGUIObject *pGUI;
2000-11-02 18:16:10 +01:00
CGUIObject::setFlags(_flags);
2000-11-02 16:54:27 +01:00
pGUI=getChild();
2000-11-02 18:16:10 +01:00
while(pGUI)
2000-11-02 16:54:27 +01:00
{
2000-11-02 18:16:10 +01:00
pGUI->setFlags(_flags);
2000-11-02 16:54:27 +01:00
pGUI=pGUI->getNext();
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2000-11-02 18:16:10 +01:00
void CGUIGroupFrame::clearFlags(GUI_FLAGS _flags)
2000-11-02 16:54:27 +01:00
{
CGUIObject *pGUI;
2000-11-02 18:16:10 +01:00
CGUIObject::clearFlags(_flags);
2000-11-02 16:54:27 +01:00
pGUI=getChild();
2000-11-02 18:16:10 +01:00
while(pGUI)
2000-11-02 16:54:27 +01:00
{
2000-11-02 18:16:10 +01:00
pGUI->clearFlags(_flags);
2000-11-02 16:54:27 +01:00
pGUI=pGUI->getNext();
}
}
2000-11-02 18:35:44 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CGUIGroupFrame::isSelectable()
{
CGUIObject *pGUI;
int selectable=false;
2001-07-31 17:57:19 +02:00
if(!isHidden())
2000-11-02 18:35:44 +01:00
{
2001-07-31 17:57:19 +02:00
pGUI=getChild();
while(pGUI)
2000-11-02 18:35:44 +01:00
{
2001-07-31 17:57:19 +02:00
if(pGUI->isSelectable())
{
selectable=true;
break;
}
pGUI=pGUI->getNext();
2000-11-02 18:35:44 +01:00
}
}
return selectable;
}
2000-11-07 23:05:42 +01:00
/*----------------------------------------------------------------------
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;
}
2000-11-02 16:54:27 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIControlFrame::think(int _frames)
{
int pad;
2001-01-31 17:11:42 +01:00
int makeNoise=false;
2000-11-02 16:54:27 +01:00
CGUIObject::think(_frames);
pad=PadGetRepeat(0);
if(pad&PAD_DOWN)
{
2001-07-31 17:57:19 +02:00
selectNextItem();
2001-01-31 17:11:42 +01:00
makeNoise=true;
2000-11-02 16:54:27 +01:00
}
2000-11-03 01:07:42 +01:00
else if(pad&PAD_UP)
{
2001-07-31 17:57:19 +02:00
selectPreviousItem();
2001-01-31 17:11:42 +01:00
makeNoise=true;
}
if(makeNoise)
{
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__MOVE_CURSOR);
2000-11-03 01:07:42 +01:00
}
2000-11-02 16:54:27 +01:00
}
/*----------------------------------------------------------------------
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();
}
}
2001-07-31 17:57:19 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIControlFrame::selectPreviousItem()
{
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();
}
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIControlFrame::selectNextItem()
{
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();
}
}
}
2001-08-17 17:54:50 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
CGUIObject::GUIId CGUIControlFrame::getIdOfSelectedItem()
{
CGUIObject *pGUI;
pGUI=getChild();
if(pGUI)
{
while(!pGUI->isSelected())
{
ASSERT(pGUI);
pGUI=pGUI->getNext();
}
return pGUI->getId();
}
return CGUIObject::noId;
}
2000-11-02 16:54:27 +01:00
/*----------------------------------------------------------------------
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();
2000-11-02 18:35:44 +01:00
while(!pGUI->isSelectable())
2000-11-02 16:54:27 +01:00
{
2000-11-02 18:35:44 +01:00
ASSERT(pGUI);
pGUI=pGUI->getNext();
2000-11-02 16:54:27 +01:00
}
2000-11-02 18:35:44 +01:00
pGUI->select();
2000-11-02 16:54:27 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIControlFrame::unselectFrame()
{
CGUIObject *pGUI;
pGUI=getChild();
if(pGUI)
{
while(!pGUI->isSelected())
{
ASSERT(pGUI);
pGUI=pGUI->getNext();
}
pGUI->unselect();
}
}
/*===========================================================================
end */