SBSPSS/source/gui/gbutton.cpp

378 lines
6.9 KiB
C++
Raw Normal View History

2000-11-02 18:19:06 +01:00
/*=========================================================================
gbutton.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "gui\gbutton.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 18:19:06 +01:00
/* Std Lib
------- */
/* Data
---- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2000-11-03 22:22:27 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIToggleButton::init(CGUIObject *_parent,GUIId _id)
{
CGUIObject::init(_parent,_id);
m_target=0;
}
2000-11-03 17:41:57 +01:00
2000-11-02 18:19:06 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2000-11-03 17:41:57 +01:00
void CGUIToggleButton::setButtonTarget(int *_target)
2000-11-02 18:19:06 +01:00
{
m_target=_target;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2000-11-03 17:41:57 +01:00
void CGUIToggleButton::think(int _frames)
{
ASSERT(getTarget());
CGUIObject::think(_frames);
if(isSelected())
{
int pad;
pad=PadGetRepeat(0);
if(pad&PAD_CROSS)
{
int *target;
target=getTarget();
if(*target==true)
{
*target=false;
}
else
{
*target=true;
}
2001-01-31 17:11:42 +01:00
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__SELECT);
2000-11-03 17:41:57 +01:00
}
}
}
2000-11-22 23:52:08 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIValueButton::init(CGUIObject *_parent,GUIId _id)
{
CGUIToggleButton::init(_parent,_id);
m_value=-1;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIValueButton::setButtonValue(int _value)
{
m_value=_value;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIValueButton::think(int _frames)
{
ASSERT(getTarget());
CGUIObject::think(_frames);
if(isSelected())
{
2001-01-31 17:11:42 +01:00
if(PadGetDown(0)&PAD_CROSS)
2000-11-22 23:52:08 +01:00
{
*getTarget()=m_value;
2001-01-31 17:11:42 +01:00
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__SELECT);
2000-11-22 23:52:08 +01:00
}
}
}
2000-11-03 22:22:27 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUICycleButton::init(CGUIObject *_parent,GUIId _id)
{
CGUIToggleButton::init(_parent,_id);
m_data=0;
}
2000-11-03 17:41:57 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUICycleButton::setButtonData(int *_data)
2000-11-02 18:19:06 +01:00
{
m_data=_data;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2000-11-03 17:41:57 +01:00
void CGUICycleButton::think(int _frames)
2000-11-02 18:19:06 +01:00
{
2000-11-03 17:41:57 +01:00
ASSERT(getTarget());
ASSERT(getData());
2000-11-02 18:19:06 +01:00
2000-11-23 17:46:29 +01:00
CGUIObject::think(_frames);
2000-11-02 18:19:06 +01:00
if(isSelected())
{
int pad;
pad=PadGetRepeat(0);
2001-02-12 17:27:03 +01:00
if(pad&(PAD_CROSS|PAD_RIGHT))
2000-11-02 18:19:06 +01:00
{
2000-11-03 17:41:57 +01:00
int *target;
2000-11-02 18:19:06 +01:00
int *data;
int tmp;
2000-11-03 01:07:42 +01:00
2000-11-03 17:41:57 +01:00
target=getTarget();
data=getData();
2000-11-02 18:19:06 +01:00
do
{
tmp=*data;
2000-11-23 17:46:29 +01:00
data++;
if(*target==tmp)
2000-11-02 18:19:06 +01:00
{
break;
}
}
while(tmp<*data);
if(tmp>*data)
{
2000-11-03 17:41:57 +01:00
data=getData();
2000-11-02 18:19:06 +01:00
}
2000-11-03 17:41:57 +01:00
*target=*data;
2001-01-31 17:11:42 +01:00
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__SELECT);
2000-11-02 18:19:06 +01:00
}
2001-02-12 17:27:03 +01:00
else if(pad&PAD_LEFT)
{
int *target;
int *data;
int tmp;
target=getTarget();
data=getData();
do
{
tmp=*data;
if(*target==tmp)
{
break;
}
data++;
}
while(tmp<*data);
if(data==getData())
{
do
{
tmp=*data;
data++;
}
while(tmp<*data);
data--;
}
else
{
data--;
}
*target=*data;
CSoundMediator::playSfx(CSoundMediator::SFX_FRONT_END__SELECT);
}
2000-11-02 18:19:06 +01:00
}
}
2000-11-03 17:41:57 +01:00
2000-11-03 22:22:27 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUISliderButton::init(CGUIObject *_parent,GUIId _id)
{
CGUIToggleButton::init(_parent,_id);
m_min=m_max=0;
m_scrollSpeed=DEFAULT_SCROLL_SPEED;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUISliderButton::setButtonRange(int _min,int _max)
{
m_min=_min;
m_max=_max;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUISliderButton::setScrollSpeed(int _scrollSpeed)
{
m_scrollSpeed=_scrollSpeed;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUISliderButton::think(int _frames)
{
ASSERT(getTarget());
ASSERT(m_min!=m_max);
CGUIObject::think(_frames);
if(isSelected())
{
int padRepeat,padDown;
int *target=getTarget();
2001-01-31 17:11:42 +01:00
int makeNoise=false;
CSoundMediator::SFXID noise=CSoundMediator::SFX_FRONT_END__SELECT;
2000-11-03 22:22:27 +01:00
padRepeat=PadGetRepeat(0);
padDown=PadGetDown(0);
if(padDown&PAD_LEFT)
{
*target-=1;
2001-01-31 17:11:42 +01:00
makeNoise=true;
noise=CSoundMediator::SFX_FRONT_END__SELECT;
2000-11-03 22:22:27 +01:00
}
else if(padDown&PAD_RIGHT)
{
*target+=1;
2001-01-31 17:11:42 +01:00
makeNoise=true;
2000-11-03 22:22:27 +01:00
}
else if(padRepeat&PAD_LEFT)
{
*target-=(_frames*m_scrollSpeed);
2001-01-31 17:11:42 +01:00
makeNoise=true;
2000-11-03 22:22:27 +01:00
}
else if(padRepeat&PAD_RIGHT)
{
*target+=(_frames*m_scrollSpeed);
2001-01-31 17:11:42 +01:00
makeNoise=true;
2000-11-03 22:22:27 +01:00
}
2001-01-31 17:11:42 +01:00
if(*target<m_min)
{
*target=m_min;
noise=CSoundMediator::SFX_FRONT_END__ERROR;
}
else if(*target>m_max)
{
*target=m_max;
noise=CSoundMediator::SFX_FRONT_END__ERROR;
}
if(makeNoise)
{
CSoundMediator::playSfx(noise);
}
2000-11-03 22:22:27 +01:00
}
}
2000-11-02 18:19:06 +01:00
/*===========================================================================
end */