SBSPSS/source/gui/gui.cpp

588 lines
14 KiB
C++
Raw Normal View History

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
---- */
2001-04-20 16:53:35 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
2000-11-09 17:58:22 +01:00
#endif
2000-10-31 17:20:53 +01:00
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2000-11-09 17:58:22 +01:00
static SpriteBank *s_uiSpriteBank=0;
2000-10-31 17:20:53 +01:00
/*----------------------------------------------------------------------
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
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;
}
if(getFlags(FLAG_DRAWBORDER))
{
2000-11-09 17:58:22 +01:00
POLY_F4 *f4;
int x,y,w,h;
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
ot=getOt();
2000-10-31 17:20:53 +01:00
// Border
2000-11-09 17:58:22 +01:00
drawBambooBorder(x,y,w,h,ot);
// Background
f4=GetPrimF4();
setXYWH(f4,x,y,w,h);
setRGB0(f4, 0, 0, 90);
setSemiTrans(f4,true);
AddPrimToList(f4,ot);
}
2001-05-03 03:59:46 +02:00
2000-11-09 17:58:22 +01:00
#ifdef __USER_paul__
if(forceBorderDraw)
{
int x,y,w,h;
int ot;
int r,g,b;
x=getX()+getParentX();
y=getY()+getParentY();
w=getW();
h=getH();
ot=getOt();
r=g=b=200;
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);
2000-10-31 17:20:53 +01:00
}
2000-11-09 17:58:22 +01:00
#endif
2000-10-31 17:20:53 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIObject::think(int _frames)
{
ASSERT(this==m_this);
2000-11-02 18:16:10 +01:00
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();
2000-11-16 00:41:47 +01:00
m_fontBank->initialise(&standardFont);
2000-11-02 18:16:10 +01:00
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-09 17:58:22 +01:00
FontBank *fb=getFontBank();
fb->setColour(CGUIObjectWithFont::SELECTED_FONT_R,CGUIObjectWithFont::SELECTED_FONT_G,CGUIObjectWithFont::SELECTED_FONT_B);
fb->setWobble(true);
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-09 17:58:22 +01:00
FontBank *fb=getFontBank();
fb->setColour(CGUIObjectWithFont::DEFAULT_FONT_R,CGUIObjectWithFont::DEFAULT_FONT_G,CGUIObjectWithFont::DEFAULT_FONT_B);
fb->setWobble(false);
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-11-09 17:58:22 +01:00
/*----------------------------------------------------------------------
Function:
Purpose: NB: This permenantly keeps a copy of the UI sprite bank
loaded in vram! Can be changed if necessary.. (PKG)
Params:
Returns:
---------------------------------------------------------------------- */
void initGUIStuff()
{
ASSERT(!s_uiSpriteBank);
s_uiSpriteBank=new ("UI Sprites") SpriteBank();
2001-04-20 16:53:35 +02:00
s_uiSpriteBank->load(SPRITES_SPRITES_SPR);
2000-11-09 17:58:22 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void drawBambooBorder(int _x,int _y,int _w,int _h,int _ot)
{
2001-05-02 00:40:25 +02:00
_ot=0; // Sorry again
2001-03-09 20:55:54 +01:00
sFrameHdr *vbam,*hbam,*corner;
2000-11-09 17:58:22 +01:00
int totalSize,numSprites,step;
int x1,y1,x2,y2;
2001-01-10 18:27:12 +01:00
int i,x,y;
2000-11-09 17:58:22 +01:00
2001-03-09 20:55:54 +01:00
vbam=s_uiSpriteBank->getFrameHeader(FRM__BAMBOOVERTICAL);
hbam=s_uiSpriteBank->getFrameHeader(FRM__BAMBOOHORIZONTAL);
corner=s_uiSpriteBank->getFrameHeader(FRM__BAMBOOTOPLEFT); // All corners are the same size
2000-11-09 17:58:22 +01:00
2001-03-09 20:55:54 +01:00
// Top and bottom
totalSize=_w-((corner->W+corner->W)/2)-hbam->W;
2000-11-09 17:58:22 +01:00
numSprites=(totalSize/hbam->W)+1;
if(numSprites>1)
{
step=(totalSize<<4)/(numSprites-1);
2001-03-09 20:55:54 +01:00
x1=1+(_x+(corner->W/2)+(hbam->W/2)-(hbam->W/2)+hbam->W-hbam->W-1)<<4;
2000-11-09 17:58:22 +01:00
y1=_y-(hbam->H/2);
y2=y1+_h;
for(i=0;i<numSprites;i++)
{
2001-03-09 20:55:54 +01:00
x=x1>>4;
s_uiSpriteBank->printFT4(hbam,x,y1,0,0,_ot);
s_uiSpriteBank->printFT4(hbam,x,y2,0,0,_ot);
2000-11-09 17:58:22 +01:00
x1+=step;
}
}
2001-03-09 20:55:54 +01:00
// Left and right
totalSize=_h-((corner->H+corner->H)/2)-vbam->H;
2000-11-09 17:58:22 +01:00
numSprites=(totalSize/vbam->H)+1;
if(numSprites>1)
{
step=(totalSize<<4)/(numSprites-1);
x1=_x-(vbam->W/2);
x2=x1+_w;
2001-03-09 20:55:54 +01:00
y1=1+(_y+(corner->H/2)+(vbam->H/2)-(vbam->H/2)+vbam->H-vbam->H-1)<<4;
2000-11-09 17:58:22 +01:00
for(i=0;i<numSprites;i++)
{
2001-03-09 20:55:54 +01:00
y=y1>>4;
s_uiSpriteBank->printFT4(vbam,x1,y,0,0,_ot);
s_uiSpriteBank->printFT4(vbam,x2,y,0,0,_ot);
2000-11-09 17:58:22 +01:00
y1+=step;
}
}
2001-03-09 20:55:54 +01:00
// Draw Corners
corner=s_uiSpriteBank->getFrameHeader(FRM__BAMBOOTOPLEFT);
s_uiSpriteBank->printFT4(corner,_x-(corner->W/2),_y-(corner->H/2),0,0,_ot);
corner=s_uiSpriteBank->getFrameHeader(FRM__BAMBOOTOPRIGHT);
s_uiSpriteBank->printFT4(corner,_x+_w-(corner->W/2),_y-(corner->H/2),0,0,_ot);
corner=s_uiSpriteBank->getFrameHeader(FRM__BAMBOOBOTRIGHT);
s_uiSpriteBank->printFT4(corner,_x+_w-(corner->W/2),_y+_h-(corner->H/2),0,0,_ot);
corner=s_uiSpriteBank->getFrameHeader(FRM__BAMBOOBOTLEFT);
s_uiSpriteBank->printFT4(corner,_x-(corner->W/2),_y+_h-(corner->H/2),0,0,_ot);
2000-11-09 17:58:22 +01:00
}
2001-05-03 03:59:46 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
typedef struct
{
int gapfromheadtobubble;
int speechmarkgapfromtop;
int speechmarkheight;
}_sbb;
_sbb sbb=
{
32,
5,
10,
};
void drawSpeechBubbleBorder(int _x,int _y,int _w,int _h,int _ot,int _faceFrame)
{
/*
DrawLine(_x ,_y ,_x+_w,_y ,255,0,255,0);
DrawLine(_x+_w,_y ,_x+_w,_y+_h,255,0,255,0);
DrawLine(_x+_w,_y+_h,_x ,_y+_h,255,0,255,0);
DrawLine(_x ,_y+_h,_x ,_y ,255,0,255,0);
*/
sFrameHdr *cornerFh;
POLY_FT4 *ft4;
LINE_F2 *f2;
POLY_F4 *f4;
int centreX,centreY;
sFrameHdr *faceFh;
POLY_F3 *f3;
// Squeeze in the corners a bit..
_x+=4;
_y+=5;
_w-=8;
_h-=10;
// Sprite corner pieces
cornerFh=s_uiSpriteBank->getFrameHeader(FRM__SPEECHBUBBLECORNER);
ft4=s_uiSpriteBank->printFT4(cornerFh,_x-cornerFh->W,_y-cornerFh->H,0,0,_ot);setSemiTrans(ft4,true);
ft4=s_uiSpriteBank->printFT4(cornerFh,_x+_w+cornerFh->W+1,_y-cornerFh->H,1,0,_ot);setSemiTrans(ft4,true);
ft4=s_uiSpriteBank->printFT4(cornerFh,_x-cornerFh->W,_y+_h+cornerFh->H+1,0,1,_ot);setSemiTrans(ft4,true);
ft4=s_uiSpriteBank->printFT4(cornerFh,_x+_w+cornerFh->W+1,_y+_h+cornerFh->H+1,1,1,_ot);setSemiTrans(ft4,true);
// Black edge lines
f2=DrawLine(_x,_y-cornerFh->H-1,_x+_w,_y-cornerFh->H-1,0,0,0,_ot);setSemiTrans(f2,true);
f2=DrawLine(_x+_w+cornerFh->W+1,_y,_x+_w+cornerFh->W+1,_y+_h,0,0,0,_ot);setSemiTrans(f2,true);
f2=DrawLine(_x+_w,_y+_h+cornerFh->H+1,_x,_y+_h+cornerFh->H+1,0,0,0,_ot);setSemiTrans(f2,true);
// White middle
f4=GetPrimF4();
setXYWH(f4,_x,_y-cornerFh->H,_w+1,cornerFh->H);
setRGB0(f4,255,255,255);
setSemiTrans(f4,true);
AddPrimToList(f4,_ot);
f4=GetPrimF4();
setXYWH(f4,_x-cornerFh->W,_y,_w+(cornerFh->W*2)+1,_h+1);
setRGB0(f4,255,255,255);
setSemiTrans(f4,true);
AddPrimToList(f4,_ot);
f4=GetPrimF4();
setXYWH(f4,_x,_y+_h+1,_w+1,cornerFh->H);
setRGB0(f4,255,255,255);
setSemiTrans(f4,true);
AddPrimToList(f4,_ot);
if(_faceFrame!=-1)
{
// Speaking characters head
centreX=_x-cornerFh->W-sbb.gapfromheadtobubble-(64/2);
centreY=_y+(_h/2);
faceFh=s_uiSpriteBank->getFrameHeader(_faceFrame);
ft4=s_uiSpriteBank->printFT4(faceFh,centreX-(faceFh->W/2),centreY-(faceFh->H/2),0,0,_ot);//setSemiTrans(ft4,true);
// White speech bubble triangle shaped piece with black outlines.. (!?)
int speechmarkEndX,speechmarkEndY;
speechmarkEndX=_x-cornerFh->W-sbb.gapfromheadtobubble;
speechmarkEndY=centreY;
f2=DrawLine(_x-cornerFh->W-1,_y,_x-cornerFh->W-1,_y+sbb.speechmarkgapfromtop-1,0,0,0,_ot);setSemiTrans(f2,true);
f2=DrawLine(_x-cornerFh->W-1,_y+sbb.speechmarkgapfromtop,speechmarkEndX,speechmarkEndY,0,0,0,_ot);setSemiTrans(f2,true);
f2=DrawLine(speechmarkEndX,speechmarkEndY,_x-cornerFh->W-1,_y+sbb.speechmarkgapfromtop+sbb.speechmarkheight,0,0,0,_ot);setSemiTrans(f2,true);
f2=DrawLine(_x-cornerFh->W-1,_y+sbb.speechmarkgapfromtop+sbb.speechmarkheight+1,_x-cornerFh->W-1,_y+_h,0,0,0,_ot);setSemiTrans(f2,true);
f3=GetPrimF3();
setXY3(f3,_x-cornerFh->W,_y+sbb.speechmarkgapfromtop,
speechmarkEndX,speechmarkEndY,
_x-cornerFh->W,_y+sbb.speechmarkgapfromtop+sbb.speechmarkheight);
setRGB0(f3,255,255,255);
setSemiTrans(f3,true);
AddPrimToList(f3,_ot);
}
else
{
// Fill in the left hand black edge line
f2=DrawLine(_x-cornerFh->W-1,_y,_x-cornerFh->W-1,_y+_h,0,0,0,_ot);setSemiTrans(f2,true);
}
// Background
f4=GetPrimF4();
setXYWH(f4,0,0,512,256);
setRGB0(f4, 0, 0, 90);
setSemiTrans(f4,true);
AddPrimToList(f4,_ot);
}
2000-10-31 17:20:53 +01:00
/*===========================================================================
2000-11-07 23:05:42 +01:00
end */