2000-10-31 17:20:53 +01:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
gui.cpp
|
|
|
|
|
|
|
|
Author: PKG
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2000 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Includes
|
|
|
|
-------- */
|
|
|
|
|
|
|
|
#include "gui\gui.h"
|
|
|
|
|
|
|
|
#ifndef __SYSTEM_DBG_H__
|
|
|
|
#include "system\dbg.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __GFX_FONT_H__
|
|
|
|
#include "gfx\font.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PRIM_HEADER__
|
|
|
|
#include "gfx\prim.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Std Lib
|
|
|
|
------- */
|
|
|
|
|
|
|
|
/* Data
|
|
|
|
---- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Tyepdefs && Defines
|
|
|
|
------------------- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Structure defintions
|
|
|
|
-------------------- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function Prototypes
|
|
|
|
------------------- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Vars
|
|
|
|
---- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
2000-11-02 18:16:10 +01:00
|
|
|
void CGUIObject::init(CGUIObject *_parent,GUIId _id)
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
|
|
|
ASSERT(this!=m_this);
|
|
|
|
|
|
|
|
m_id=_id;
|
|
|
|
m_x=m_y=m_w=m_h=0;
|
2000-10-31 17:53:12 +01:00
|
|
|
m_flags=getInitialFlags();
|
2000-10-31 17:20:53 +01:00
|
|
|
m_this=this;
|
2000-11-02 18:16:10 +01:00
|
|
|
m_parent=_parent;
|
|
|
|
m_child=NULL;
|
|
|
|
m_next=NULL;
|
2000-10-31 17:20:53 +01:00
|
|
|
|
2000-11-02 18:16:10 +01:00
|
|
|
// Link in with the parent
|
|
|
|
if(m_parent)
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
2000-11-02 18:16:10 +01:00
|
|
|
if(m_parent->m_child)
|
|
|
|
{
|
|
|
|
CGUIObject *pGUI;
|
|
|
|
pGUI=m_parent->m_child;
|
|
|
|
while(pGUI->m_next)
|
|
|
|
{
|
|
|
|
pGUI=pGUI->m_next;
|
|
|
|
}
|
|
|
|
pGUI->m_next=this;
|
|
|
|
}
|
|
|
|
else
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
2000-11-02 18:16:10 +01:00
|
|
|
m_parent->m_child=this;
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
2000-11-02 18:16:10 +01:00
|
|
|
setOt(m_parent->getOt()-1);
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-03 01:07:42 +01:00
|
|
|
// This object is a bastard :)
|
2000-11-02 18:16:10 +01:00
|
|
|
GUI_DBGMSG("INFO: GUI object without parent created!");
|
|
|
|
setOt(INITIAL_OT);
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CGUIObject::shutdown()
|
|
|
|
{
|
|
|
|
ASSERT(this==m_this);
|
|
|
|
|
2000-11-02 18:16:10 +01:00
|
|
|
if(m_child)m_child->shutdown(); m_child=NULL;
|
|
|
|
if(m_next)m_next->shutdown(); m_next=NULL;
|
|
|
|
m_parent=NULL;
|
2000-11-07 23:05:42 +01:00
|
|
|
m_this=NULL;
|
2000-10-31 17:20:53 +01:00
|
|
|
|
2000-11-07 23:05:42 +01:00
|
|
|
// Is this actually safe? Possibly not.. (PKG)
|
2000-11-02 18:16:10 +01:00
|
|
|
delete this;
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
2000-11-03 01:07:42 +01:00
|
|
|
Purpose:
|
2000-10-31 17:20:53 +01:00
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
2000-11-02 18:16:10 +01:00
|
|
|
#ifdef __USER_paul__
|
2000-11-03 01:07:42 +01:00
|
|
|
int forceBorderDraw=false;
|
2000-11-02 18:16:10 +01:00
|
|
|
#endif
|
2000-10-31 17:20:53 +01:00
|
|
|
void CGUIObject::render()
|
|
|
|
{
|
|
|
|
ASSERT(this==m_this);
|
|
|
|
|
2000-11-02 18:16:10 +01:00
|
|
|
if(m_child)m_child->render();
|
|
|
|
if(m_next)m_next->render();
|
|
|
|
|
2000-10-31 17:20:53 +01:00
|
|
|
if(isHidden())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-11-02 18:16:10 +01:00
|
|
|
#ifdef __USER_paul__
|
|
|
|
if(getFlags(FLAG_DRAWBORDER)||forceBorderDraw)
|
|
|
|
#else
|
2000-10-31 17:20:53 +01:00
|
|
|
if(getFlags(FLAG_DRAWBORDER))
|
2000-11-02 18:16:10 +01:00
|
|
|
#endif
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
|
|
|
POLY_G4 *g4;
|
2000-11-02 18:16:10 +01:00
|
|
|
int x,y,w,h;
|
|
|
|
int r,g,b;
|
|
|
|
int ot;
|
2000-10-31 17:20:53 +01:00
|
|
|
|
2000-11-02 18:16:10 +01:00
|
|
|
x=getX()+getParentX();
|
|
|
|
y=getY()+getParentY();
|
2000-10-31 17:20:53 +01:00
|
|
|
w=getW();
|
|
|
|
h=getH();
|
2000-11-02 18:16:10 +01:00
|
|
|
if(isSelected())
|
|
|
|
{
|
2000-11-03 22:22:27 +01:00
|
|
|
r=g=b=245;
|
2000-11-02 18:16:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-03 22:22:27 +01:00
|
|
|
r=g=b=110;
|
2000-11-02 18:16:10 +01:00
|
|
|
}
|
|
|
|
ot=getOt();
|
2000-10-31 17:20:53 +01:00
|
|
|
|
|
|
|
// Border
|
2000-11-02 18:16:10 +01:00
|
|
|
DrawLine(x ,y ,x+w,y ,r,g,b,ot);
|
|
|
|
DrawLine(x ,y ,x ,y+h,r,g,b,ot);
|
|
|
|
DrawLine(x+w,y ,x+w,y+h,r,g,b,ot);
|
|
|
|
DrawLine(x ,y+h,x+w,y+h,r,g,b,ot);
|
2000-11-03 22:22:27 +01:00
|
|
|
x+=1;y+=1;w-=2;h-=2;
|
2000-11-02 18:16:10 +01:00
|
|
|
DrawLine(x ,y ,x+w,y ,r,g,b,ot);
|
|
|
|
DrawLine(x ,y ,x ,y+h,r,g,b,ot);
|
|
|
|
DrawLine(x+w,y ,x+w,y+h,r,g,b,ot);
|
|
|
|
DrawLine(x ,y+h,x+w,y+h,r,g,b,ot);
|
2000-11-03 22:22:27 +01:00
|
|
|
x+=1;y+=1;w+=1;h+=1;
|
|
|
|
DrawLine(x ,y ,x+w,y ,0,0,0,ot);
|
|
|
|
DrawLine(x ,y ,x ,y+h,0,0,0,ot);
|
|
|
|
DrawLine(x+w,y ,x+w,y+h,0,0,0,ot);
|
|
|
|
DrawLine(x ,y+h,x+w,y+h,0,0,0,ot);
|
|
|
|
x-=2;y-=2;w+=1;h+=1;
|
2000-10-31 17:20:53 +01:00
|
|
|
|
|
|
|
// Background
|
|
|
|
g4=GetPrimG4();
|
|
|
|
setXYWH(g4,x,y,w,h);
|
2000-11-03 22:22:27 +01:00
|
|
|
// setSemiTrans(g4,true);
|
|
|
|
setRGB0(g4,107,105, 98);
|
|
|
|
setRGB1(g4,107,105, 98);
|
|
|
|
setRGB2(g4, 0, 0, 90);
|
|
|
|
setRGB3(g4, 0, 0, 90);
|
2000-11-02 18:16:10 +01:00
|
|
|
AddPrimToList(g4,ot);
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
2000-11-02 18:16:10 +01:00
|
|
|
#include "utils\utils.h"
|
|
|
|
int wob=0;
|
2000-10-31 17:20:53 +01:00
|
|
|
void CGUIObject::think(int _frames)
|
|
|
|
{
|
|
|
|
ASSERT(this==m_this);
|
2000-11-02 18:16:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
if(m_id==0&&++wob==20)
|
|
|
|
{
|
|
|
|
setObjectXYWH(16+getRndRange(10),100+getRndRange(5),512-64,120);
|
|
|
|
wob=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_child)m_child->think(_frames);
|
|
|
|
if(m_next)m_next->think(_frames);
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-31 17:43:44 +01:00
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CGUIObject::recalc()
|
|
|
|
{
|
|
|
|
ASSERT(this==m_this);
|
2000-11-02 18:16:10 +01:00
|
|
|
|
|
|
|
if(m_child)m_child->recalc();
|
|
|
|
if(m_next)m_next->recalc();
|
2000-10-31 17:43:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-31 17:20:53 +01:00
|
|
|
|
|
|
|
|
2000-11-02 18:16:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-10-31 17:20:53 +01:00
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
2000-11-02 18:16:10 +01:00
|
|
|
void CGUIObjectWithFont::init(CGUIObject *_parent,GUIId _id)
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
2000-11-02 18:16:10 +01:00
|
|
|
CGUIObject::init(_parent,_id);
|
|
|
|
m_fontBank=new ("GUIObjectWithFont:fontBank") FontBank();
|
|
|
|
m_fontBank->initialise(&standardFont);
|
|
|
|
m_fontBank->setJustification(FontBank::JUST_CENTRE);
|
|
|
|
m_fontBank->setOt(getOt());
|
|
|
|
m_fontBank->setColour(DEFAULT_FONT_R,DEFAULT_FONT_G,DEFAULT_FONT_B);
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
2000-11-02 18:16:10 +01:00
|
|
|
void CGUIObjectWithFont::shutdown()
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
2000-11-02 18:16:10 +01:00
|
|
|
CGUIObject::shutdown();
|
|
|
|
m_fontBank->dump();
|
|
|
|
delete(m_fontBank);
|
|
|
|
m_fontBank=NULL;
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
2000-11-02 18:16:10 +01:00
|
|
|
void CGUIObjectWithFont::setFlags(GUI_FLAGS _flags)
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
2000-11-02 18:16:10 +01:00
|
|
|
CGUIObject::setFlags(_flags);
|
|
|
|
if(_flags&FLAG_SELECTED)
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
2000-11-02 18:16:10 +01:00
|
|
|
getFontBank()->setColour(CGUIObjectWithFont::SELECTED_FONT_R,CGUIObjectWithFont::SELECTED_FONT_G,CGUIObjectWithFont::SELECTED_FONT_B);
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
2000-11-02 18:16:10 +01:00
|
|
|
void CGUIObjectWithFont::clearFlags(GUI_FLAGS _flags)
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
2000-11-02 18:16:10 +01:00
|
|
|
CGUIObject::clearFlags(_flags);
|
|
|
|
if(_flags&FLAG_SELECTED)
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
2000-11-02 18:16:10 +01:00
|
|
|
getFontBank()->setColour(CGUIObjectWithFont::DEFAULT_FONT_R,CGUIObjectWithFont::DEFAULT_FONT_G,CGUIObjectWithFont::DEFAULT_FONT_B);
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-07 23:05:42 +01:00
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CGUIObjectWithFont::setOt(int _ot)
|
|
|
|
{
|
|
|
|
CGUIObject::setOt(_ot);
|
|
|
|
getFontBank()->setOt(_ot);
|
|
|
|
}
|
|
|
|
|
2000-11-02 18:16:10 +01:00
|
|
|
|
2000-10-31 17:20:53 +01:00
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
2000-11-02 18:16:10 +01:00
|
|
|
void CGUIObjectWithFont::recalc()
|
2000-10-31 17:20:53 +01:00
|
|
|
{
|
2000-11-02 18:16:10 +01:00
|
|
|
int x,y,w,h;
|
|
|
|
|
|
|
|
CGUIObject::recalc();
|
|
|
|
x=getX()+getParentX()+BORDERWIDTH;
|
|
|
|
y=getY()+getParentY()+BORDERHEIGHT;
|
|
|
|
w=getW()-(BORDERWIDTH*2);
|
|
|
|
h=getH()-(BORDERHEIGHT*2);
|
|
|
|
getFontBank()->setPrintArea(x,y,w,h);
|
2000-10-31 17:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-03 22:22:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CGUIObjectWithSpriteBank::init(CGUIObject *_parent,GUIId _id)
|
|
|
|
{
|
|
|
|
CGUIObject::init(_parent,_id);
|
|
|
|
m_spriteBank=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CGUIObjectWithSpriteBank::shutdown()
|
|
|
|
{
|
|
|
|
ASSERT(m_spriteBank);
|
|
|
|
|
|
|
|
CGUIObject::shutdown();
|
|
|
|
m_spriteBank->dump();
|
|
|
|
delete m_spriteBank;
|
|
|
|
m_spriteBank=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CGUIObjectWithSpriteBank::setSpriteBank(FileEquate _fe)
|
|
|
|
{
|
|
|
|
m_spriteBank=new ("spritebank") SpriteBank();
|
|
|
|
m_spriteBank->load(_fe);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-31 17:20:53 +01:00
|
|
|
/*===========================================================================
|
2000-11-07 23:05:42 +01:00
|
|
|
end */
|