diff --git a/source/gui/gsprite.cpp b/source/gui/gsprite.cpp new file mode 100644 index 000000000..5c0f6f619 --- /dev/null +++ b/source/gui/gsprite.cpp @@ -0,0 +1,151 @@ +/*========================================================================= + + gsprite.cpp + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2000 Climax Development Ltd + +===========================================================================*/ + + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "gui\gsprite.h" + +#ifndef __GFX_SPRBANK_H__ +#include "gfx\sprbank.h" +#endif + +#ifndef __SYSTEM_DBG_H__ +#include "system\dbg.h" +#endif + + +/* Std Lib + ------- */ + +/* Data + ---- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CGUISprite::init(CGUIObject *_parent,GUIId _id) +{ + CGUIObjectWithSpriteBank::init(_parent,_id); + m_frame=-1; +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CGUISprite::setFrame(int _frame) +{ + m_frame=_frame; + recalc(); +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CGUISprite::render() +{ + ASSERT(m_frame!=-1); + + if(!isHidden()) + { + SpriteBank *sb; + sb=getSpriteBank(); + sb->printFT4(sb->getFrameHeader(m_frame),m_x,m_y,0,0,getOt()); + } + CGUIObjectWithSpriteBank::render(); +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CGUISprite::recalc() +{ + if(m_frame!=-1) + { + sFrameHdr *fh; + + fh=getSpriteBank()->getFrameHeader(m_frame); + +#ifdef __VERSION_DEBUG__ + if(fh->W>getW()-(BORDERWIDTH*2)|| + fh->H>getH()-(BORDERHEIGHT*2)) + { + GUI_DBGMSG("Sprite overflow in CGUISprite!"); + } +#endif + m_x=getX()+((getW()-fh->W)/2); + m_y=getY()+((getH()-fh->H)/2); + } +} + + + + + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CGUISelectSprite::render() +{ + if(isSelected()) + { + CGUISprite::render(); + } + else + { + CGUIObjectWithSpriteBank::render(); + } +} + + +/*=========================================================================== + end */ \ No newline at end of file diff --git a/source/gui/gsprite.h b/source/gui/gsprite.h new file mode 100644 index 000000000..4331ba16e --- /dev/null +++ b/source/gui/gsprite.h @@ -0,0 +1,80 @@ +/*========================================================================= + + gsprite.h + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2000 Climax Development Ltd + +===========================================================================*/ + +#ifndef __GUI_GSPRITE_H__ +#define __GUI_GSPRITE_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#ifndef __GUI_GUI_H__ +#include "gui\gui.h" +#endif + + +/* Std Lib + ------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +// Sprite +class CGUISprite : public CGUIObjectWithSpriteBank +{ +public: + virtual void init(CGUIObject *_parent,GUIId _id=noId); + + virtual void setFrame(int _frame); + + virtual void render(); + + +protected: + void recalc(); + + +private: + int m_frame; + int m_x,m_y; + +}; + + +// Sprite that only appears when the object is selected +class CGUISelectSprite : public CGUISprite +{ +public: + virtual void render(); +}; + + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/*---------------------------------------------------------------------- + Functions + --------- */ + +/*---------------------------------------------------------------------- */ + +#endif /* __GUI_GSPRITE_H__ */ + +/*=========================================================================== + end */