This commit is contained in:
Paul 2000-10-31 16:20:53 +00:00
parent bd07373b05
commit d94c447c19
6 changed files with 909 additions and 0 deletions

184
source/gui/greadout.cpp Normal file
View File

@ -0,0 +1,184 @@
/*=========================================================================
gui.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "gui\greadout.h"
#ifndef __GFX_FONT_H__
#include "gfx\font.h"
#endif
#ifndef __LOCALE_TEXTDBASE_H__
#include "locale\textdbase.h"
#endif
/* Std Lib
------- */
/* Data
---- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextReadout::init(GUIId _id)
{
CGUIObject::init(_id);
m_target=0;
m_data=0;
m_textId=TranslationDatabase::NO_STRING;
m_fontBank=new ("TextBox-Font") FontBank();
m_fontBank->initialise(&standardFont);
m_fontBank->setJustification(FontBank::JUST_CENTRE);
m_fontBank->setOt(CGUIObject::DEFAULT_OT);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextReadout::setReadoutTarget(int *_target)
{
m_target=_target;
recalc();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextReadout::setReadoutData(TextReadoutData *_data)
{
m_data=_data;
recalc();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextReadout::render()
{
FontBank *fb;
if(!isHidden())
{
getFontBank()->print((getW()-(BORDERWIDTH*2))/2,m_textY,m_textId);
}
CGUIObject::render();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextReadout::think(int _frames)
{
CGUIObject::think(_frames);
if(*m_target!=m_lastValue)
{
recalc();
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextReadout::recalc()
{
CGUIObject::recalc();
if(m_data)
{
FontBank *fb;
char *string;
TextReadoutData *data;
int tmp;
m_lastValue=*m_target;
m_textId=4;
fb=getFontBank();
fb->setPrintArea(getX()+BORDERWIDTH,getY()+BORDERHEIGHT,getW()-(BORDERWIDTH*2),getH()-(BORDERHEIGHT*2));
m_textId=STR__DUMMY;
data=m_data;
do
{
if(m_lastValue==data->m_value)
{
m_textId=data->m_textId;
break;
}
tmp=data->m_value;
data++;
}
while(tmp<data->m_value);
string=(char*)TranslationDatabase::getString(m_textId);
#ifdef __VERSION_DEBUG__
if(fb->getStringWidth(string)>getW()-(BORDERWIDTH*2)||
fb->getStringHeight(string)>getH()-(BORDERHEIGHT*2))
{
GUI_DBGMSG("Text overflow in CGUITextReadout!");
}
#endif
m_textY=(getH()-(BORDERHEIGHT*2)-fb->getStringHeight(string))/2;
}
}
/*===========================================================================
end */

89
source/gui/greadout.h Normal file
View File

@ -0,0 +1,89 @@
/*=========================================================================
greadout.h
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __GUI_GREADOUT_H__
#define __GUI_GREADOUT_H__
/*----------------------------------------------------------------------
Includes
-------- */
#ifndef __GUI_GUI_H__
#include "gui\gui.h"
#endif
/* Std Lib
------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
class CGUITextReadout : public CGUIObject
{
public:
typedef struct
{
int m_value;
int m_textId;
} TextReadoutData;
virtual void init(GUIId _id);
virtual void setReadoutTarget(int *_target);
virtual void setReadoutData(TextReadoutData *_data);
virtual void render();
virtual void think(int _frames);
protected:
void recalc();
class FontBank *getFontBank() {return m_fontBank;}
private:
int *m_target;
TextReadoutData *m_data;
int m_lastValue;
class FontBank *m_fontBank;
unsigned int m_textId;
int m_textY;
};
/*----------------------------------------------------------------------
Globals
------- */
/*----------------------------------------------------------------------
Functions
--------- */
/*---------------------------------------------------------------------- */
#endif /* __GUI_GREADOUT_H__ */
/*===========================================================================
end */

152
source/gui/gtextbox.cpp Normal file
View File

@ -0,0 +1,152 @@
/*=========================================================================
gui.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "gui\gtextbox.h"
#ifndef __GFX_FONT_H__
#include "gfx\font.h"
#endif
#ifndef __SYSTEM_DBG_H__
#include "system\dbg.h"
#endif
#ifndef __LOCALE_TEXTDBASE_H__
#include "locale\textdbase.h"
#endif
/* Std Lib
------- */
/* Data
---- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextBox::init(GUIId _id)
{
CGUIObject::init(_id);
m_textId=TranslationDatabase::NO_STRING;
m_fontBank=new ("TextBox-Font") FontBank();
m_fontBank->initialise(&standardFont);
m_fontBank->setJustification(FontBank::JUST_CENTRE);
m_fontBank->setOt(CGUIObject::DEFAULT_OT);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextBox::shutdown()
{
CGUIObject::shutdown();
m_fontBank->dump();
m_fontBank=NULL;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextBox::setText(unsigned int _textId)
{
FontBank *fb;
m_textId=_textId;
recalc();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextBox::render()
{
FontBank *fb;
if(!isHidden())
{
getFontBank()->print((getW()-(BORDERWIDTH*2))/2,m_textY,m_textId);
}
CGUIObject::render();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUITextBox::recalc()
{
FontBank *fb;
char *string;
CGUIObject::recalc();
fb=getFontBank();
fb->setPrintArea(getX()+BORDERWIDTH,getY()+BORDERHEIGHT,getW()-(BORDERWIDTH*2),getH()-(BORDERHEIGHT*2));
string=(char*)TranslationDatabase::getString(m_textId);
#ifdef __VERSION_DEBUG__
if(fb->getStringWidth(string)>getW()-(BORDERWIDTH*2)||
fb->getStringHeight(string)>getH()-(BORDERHEIGHT*2))
{
GUI_DBGMSG("Text overflow in CGUITextBox!");
}
#endif
m_textY=(getH()-(BORDERHEIGHT*2)-fb->getStringHeight(string))/2;
}
/*===========================================================================
end */

77
source/gui/gtextbox.h Normal file
View File

@ -0,0 +1,77 @@
/*=========================================================================
gtextbox.h
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __GUI_GTEXTBOX_H__
#define __GUI_GTEXTBOX_H__
/*----------------------------------------------------------------------
Includes
-------- */
#ifndef __GUI_GUI_H__
#include "gui\gui.h"
#endif
/* Std Lib
------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
class CGUITextBox : public CGUIObject
{
public:
virtual void init(GUIId _id);
virtual void shutdown();
virtual void setText(unsigned int _textId);
virtual void render();
protected:
void recalc();
class FontBank *getFontBank() {return m_fontBank;}
private:
class FontBank *m_fontBank;
unsigned int m_textId;
int m_textY;
};
/*----------------------------------------------------------------------
Globals
------- */
/*----------------------------------------------------------------------
Functions
--------- */
/*---------------------------------------------------------------------- */
#endif /* __GUI_GTEXTBOX_H__ */
/*===========================================================================
end */

276
source/gui/gui.cpp Normal file
View File

@ -0,0 +1,276 @@
/*=========================================================================
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
---- */
CGUIObject *CGUIObject::s_llBase=NULL;
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIObject::init(GUIId _id)
{
ASSERT(this!=m_this);
m_id=_id;
m_x=m_y=m_w=m_h=0;
m_flags=INITIAL_FLAGS;
m_this=this;
// Add to the end of the linked list of GUI objects..
// Also check for duplicate IDs
if(s_llBase)
{
CGUIObject *pGUI;
pGUI=s_llBase;
while(pGUI->m_llNext)
{
ASSERT(pGUI->m_id==_id);
pGUI=pGUI->m_llNext;
}
pGUI->m_llNext=this;
}
else
{
s_llBase=this;
}
m_llNext=0;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIObject::shutdown()
{
CGUIObject *pGUI;
ASSERT(this==m_this);
m_this=0;
// Remove from linked list of GUI objects..
pGUI=s_llBase;
while(pGUI->m_llNext!=this);
{
ASSERT(pGUI); // Huh? Couldn't find this item in the list!?!?!
pGUI=pGUI->m_llNext;
}
pGUI->m_llNext=this->m_llNext;
}
/*----------------------------------------------------------------------
Function:
Purpose: NB: The chain of render functions needs to be reversed so
that the draworder is correct! Look at any subclasses
render() function to see what I mean by this.. (PKG)
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIObject::render()
{
ASSERT(this==m_this);
if(isHidden())
{
return;
}
if(getFlags(FLAG_DRAWBORDER))
{
POLY_G4 *g4;
int x,y,w,h;
int r,g,b;
x=getX();
y=getY();
w=getW();
h=getH();
r=g=b=240;
// Border
DrawLine(x ,y ,x+w,y ,r,g,b,DEFAULT_OT);
DrawLine(x ,y ,x ,y+h,r,g,b,DEFAULT_OT);
DrawLine(x+w,y ,x+w,y+h,r,g,b,DEFAULT_OT);
DrawLine(x ,y+h,x+w,y+h,r,g,b,DEFAULT_OT);
x+=3;y+=2;w-=6;h-=4;
DrawLine(x ,y ,x+w,y ,r,g,b,DEFAULT_OT);
DrawLine(x ,y ,x ,y+h,r,g,b,DEFAULT_OT);
DrawLine(x+w,y ,x+w,y+h,r,g,b,DEFAULT_OT);
DrawLine(x ,y+h,x+w,y+h,r,g,b,DEFAULT_OT);
x-=3;y-=2;w+=6;h+=4;
// Background
g4=GetPrimG4();
setXYWH(g4,x,y,w,h);
setSemiTrans(g4,true);
setRGB0(g4,250, 15,125);
setRGB1(g4,250,125, 15);
setRGB2(g4, 15,250,125);
setRGB3(g4, 15,125,250);
AddPrimToList(g4,DEFAULT_OT);
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGUIObject::think(int _frames)
{
ASSERT(this==m_this);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
extern void guiOpen()
{
ASSERT(!CGUIObject::s_llBase);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
extern void guiClose()
{
ASSERT(CGUIObject::s_llBase);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
extern void guiThink(int _frames)
{
CGUIObject *pGUI;
pGUI=CGUIObject::s_llBase;
while(pGUI)
{
pGUI->think(_frames);
pGUI=pGUI->m_llNext;
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
extern void guiRender()
{
CGUIObject *pGUI;
pGUI=CGUIObject::s_llBase;
while(pGUI)
{
pGUI->render();
pGUI=pGUI->m_llNext;
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
extern CGUIObject *guiGetItem(CGUIObject::GUIId _searchId)
{
CGUIObject *pGUI;
pGUI=CGUIObject::s_llBase;
while(pGUI)
{
if(pGUI->m_id==_searchId)
{
return pGUI;
}
pGUI=pGUI->m_llNext;
}
// Bwah!
ASSERT(0);
return NULL;
}
/*===========================================================================
end */

131
source/gui/gui.h Normal file
View File

@ -0,0 +1,131 @@
/*=========================================================================
gui.h
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __GUI_GUI_H__
#define __GUI_GUI_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
class CGUIObject
{
public:
typedef int GUIId;
typedef enum
{
FLAG_SELECTED= 1<<0,
FLAG_HIDDEN= 1<<1,
FLAG_DRAWBORDER= 1<<2,
INITIAL_FLAGS= FLAG_DRAWBORDER,
} GUI_FLAGS;
enum
{
DEFAULT_OT=20,
BORDERWIDTH=8,
BORDERHEIGHT=5,
};
virtual void init(GUIId _id);
virtual void shutdown();
virtual void setObjectX(int _x) {m_x=_x;recalc();}
virtual void setObjectY(int _y) {m_y=_y;recalc();}
virtual void setObjectW(int _w) {m_w=_w;recalc();}
virtual void setObjectH(int _h) {m_h=_h;recalc();}
void setObjectXY(int _x,int _y) {setObjectX(_x);setObjectY(_y);}
void setObjectWH(int _w,int _h) {setObjectW(_w);setObjectH(_h);}
void setObjectXYWH(int _x,int _y,int _w,int _h) {setObjectXY(_x,_y);setObjectWH(_w,_h);}
virtual void render();
virtual void think(int _frames);
virtual void recalc() {;}
void setFlags(GUI_FLAGS _flags) {m_flags|=_flags;}
void clearFlags(GUI_FLAGS _flags) {m_flags&=_flags^-1;}
int getFlags(GUI_FLAGS _flags) {return (m_flags&_flags)!=0;}
virtual void select() {setFlags(FLAG_SELECTED);}
virtual void unselect() {clearFlags(FLAG_SELECTED);}
virtual int isSelected() {return getFlags(FLAG_SELECTED);}
virtual void hide() {setFlags(FLAG_HIDDEN);}
virtual void unhide() {clearFlags(FLAG_HIDDEN);}
virtual int isHidden() {return getFlags(FLAG_HIDDEN);}
protected:
int getX() {return m_x;}
int getY() {return m_y;}
int getW() {return m_w;}
int getH() {return m_h;}
private:
GUIId m_id;
int m_x,m_y,m_w,m_h;
int m_flags;
CGUIObject *m_this;
CGUIObject *m_llNext;
static CGUIObject *s_llBase;
// ..don't like using friends for this :(
friend void guiOpen();
friend void guiClose();
friend void guiThink(int _frames);
friend void guiRender();
friend CGUIObject *guiGetItem(CGUIObject::GUIId _searchId);
};
/*----------------------------------------------------------------------
Globals
------- */
/*----------------------------------------------------------------------
Functions
--------- */
extern void guiOpen();
extern void guiClose();
extern void guiThink(int _frames);
extern void guiRender();
extern CGUIObject *guiGetItem(CGUIObject::GUIId _searchId);
/*---------------------------------------------------------------------- */
#endif /* __GUI_GUI_H__ */
/*===========================================================================
end */