This commit is contained in:
parent
df57fbe7b9
commit
83b1a03581
2 changed files with 231 additions and 0 deletions
151
source/gui/gsprite.cpp
Normal file
151
source/gui/gsprite.cpp
Normal file
|
@ -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 */
|
80
source/gui/gsprite.h
Normal file
80
source/gui/gsprite.h
Normal file
|
@ -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 */
|
Loading…
Add table
Add a link
Reference in a new issue