mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-20 19:21:46 +00:00
Move FONT_* to class.
svn-id: r14449
This commit is contained in:
parent
8585d77d34
commit
fe1ab79bee
@ -32,7 +32,7 @@
|
||||
#include "saga/script_mod.h"
|
||||
#include "saga/sndres.h"
|
||||
#include "saga/sprite_mod.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
#include "saga/text_mod.h"
|
||||
#include "saga/sound.h"
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#include "saga/saga.h"
|
||||
#include "saga/gfx.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
#include "saga/cvar_mod.h"
|
||||
#include "saga/events_mod.h"
|
||||
|
||||
@ -219,8 +219,8 @@ int CON_Draw(R_SURFACE *ds) {
|
||||
txt_fgcolor = _vm->_gfx->matchColor(R_CONSOLE_TXTCOLOR);
|
||||
txt_shcolor = _vm->_gfx->matchColor(R_CONSOLE_TXTSHADOW);
|
||||
|
||||
FONT_Draw(SMALL_FONT_ID, ds, ">", 1, 2, ConInfo.y_pos - 10, txt_fgcolor, txt_shcolor, FONT_SHADOW);
|
||||
FONT_Draw(SMALL_FONT_ID, ds, ConInfo.input_buf, strlen(ConInfo.input_buf),
|
||||
_vm->_font->draw(SMALL_FONT_ID, ds, ">", 1, 2, ConInfo.y_pos - 10, txt_fgcolor, txt_shcolor, FONT_SHADOW);
|
||||
_vm->_font->draw(SMALL_FONT_ID, ds, ConInfo.input_buf, strlen(ConInfo.input_buf),
|
||||
10, ConInfo.y_pos - 10, txt_fgcolor, txt_shcolor, FONT_SHADOW);
|
||||
|
||||
line_y = ConInfo.y_pos - (R_CON_INPUT_H + R_CON_LINE_H);
|
||||
@ -235,7 +235,7 @@ int CON_Draw(R_SURFACE *ds) {
|
||||
}
|
||||
|
||||
for (walk_ptr = start_ptr; walk_ptr; walk_ptr = walk_ptr->next) {
|
||||
FONT_Draw(SMALL_FONT_ID, ds, walk_ptr->str_p, walk_ptr->str_len, 2, line_y, txt_fgcolor, txt_shcolor, FONT_SHADOW);
|
||||
_vm->_font->draw(SMALL_FONT_ID, ds, walk_ptr->str_p, walk_ptr->str_len, 2, line_y, txt_fgcolor, txt_shcolor, FONT_SHADOW);
|
||||
line_y -= R_CON_LINE_H;
|
||||
if (line_y < -R_CON_LINE_H)
|
||||
break;
|
||||
|
137
saga/font.cpp
137
saga/font.cpp
@ -28,74 +28,61 @@
|
||||
#include "saga/rscfile_mod.h"
|
||||
#include "saga/game_mod.h"
|
||||
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
|
||||
namespace Saga {
|
||||
|
||||
static R_FONT_MODULE FontModule;
|
||||
|
||||
int FONT_Init() {
|
||||
Font::Font(SagaEngine *vm) : _vm(vm), _initialized(false) {
|
||||
R_GAME_FONTDESC *gamefonts;
|
||||
int i;
|
||||
|
||||
if (FontModule.init) {
|
||||
FontModule.err_str = "Font module already initialized.";
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
// Load font module resource context
|
||||
if (GAME_GetFileContext(&FontModule.font_ctxt,
|
||||
if (GAME_GetFileContext(&_font_ctxt,
|
||||
R_GAME_RESOURCEFILE, 0) != R_SUCCESS) {
|
||||
FontModule.err_str = "Couldn't get resource context.";
|
||||
return R_FAILURE;
|
||||
error("Font::Font(): Couldn't get resource context.");
|
||||
}
|
||||
|
||||
// Allocate font table
|
||||
GAME_GetFontInfo(&gamefonts, &FontModule.n_fonts);
|
||||
GAME_GetFontInfo(&gamefonts, &_n_fonts);
|
||||
|
||||
assert(FontModule.n_fonts > 0);
|
||||
assert(_n_fonts > 0);
|
||||
|
||||
FontModule.fonts = (R_FONT **)malloc(FontModule.n_fonts * sizeof *FontModule.fonts);
|
||||
if (FontModule.fonts == NULL) {
|
||||
FontModule.err_str = "Memory allocation failure.";
|
||||
return R_MEM;
|
||||
_fonts = (R_FONT **)malloc(_n_fonts * sizeof *_fonts);
|
||||
if (_fonts == NULL) {
|
||||
error("Font::Font(): Memory allocation failure.");
|
||||
}
|
||||
|
||||
for (i = 0; i < FontModule.n_fonts; i++) {
|
||||
FONT_Load(gamefonts[i].font_rn, gamefonts[i].font_id);
|
||||
for (i = 0; i < _n_fonts; i++) {
|
||||
loadFont(gamefonts[i].font_rn, gamefonts[i].font_id);
|
||||
}
|
||||
|
||||
FontModule.init = 1;
|
||||
|
||||
return R_SUCCESS;
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
int FONT_Shutdown() {
|
||||
Font::~Font(void) {
|
||||
// int i;
|
||||
|
||||
debug(0, "FONT_Shutdown(): Freeing fonts.");
|
||||
debug(0, "Font::~Font(): Freeing fonts.");
|
||||
/*
|
||||
for ( i = 0 ; i < R_FONT_COUNT ; i ++ ) {
|
||||
if ( FontModule.fonts[i] != NULL ) {
|
||||
if ( FontModule.fonts[i]->normal_loaded ) {
|
||||
free( FontModule.fonts[i]->normal->font_free_p );
|
||||
free( FontModule.fonts[i]->normal );
|
||||
if ( _fonts[i] != NULL ) {
|
||||
if ( _fonts[i]->normal_loaded ) {
|
||||
free( _fonts[i]->normal->font_free_p );
|
||||
free( _fonts[i]->normal );
|
||||
}
|
||||
|
||||
if ( FontModule.fonts[i]->outline_loaded ) {
|
||||
free( FontModule.fonts[i]->outline->font_free_p );
|
||||
free( FontModule.fonts[i]->outline );
|
||||
if ( _fonts[i]->outline_loaded ) {
|
||||
free( _fonts[i]->outline->font_free_p );
|
||||
free( _fonts[i]->outline );
|
||||
}
|
||||
}
|
||||
|
||||
free( FontModule.fonts[i] );
|
||||
free( _fonts[i] );
|
||||
}
|
||||
*/
|
||||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
int FONT_Load(uint32 font_rn, int font_id) {
|
||||
int Font::loadFont(uint32 font_rn, int font_id) {
|
||||
R_FONT_HEADER fh;
|
||||
R_FONT *font;
|
||||
R_FONT_STYLE *normal_font;
|
||||
@ -104,18 +91,18 @@ int FONT_Load(uint32 font_rn, int font_id) {
|
||||
int nbits;
|
||||
int c;
|
||||
|
||||
if ((font_id < 0) || (font_id >= FontModule.n_fonts)) {
|
||||
if ((font_id < 0) || (font_id >= _n_fonts)) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
// Load font resource
|
||||
if (RSC_LoadResource(FontModule.font_ctxt, font_rn, &fontres_p, &fontres_len) != R_SUCCESS) {
|
||||
FontModule.err_str = "Couldn't load font resource.";
|
||||
if (RSC_LoadResource(_font_ctxt, font_rn, &fontres_p, &fontres_len) != R_SUCCESS) {
|
||||
error("Font::loadFont(): Couldn't load font resource.");
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
if (fontres_len < R_FONT_DESCSIZE) {
|
||||
FontModule.err_str = "Invalid font length.";
|
||||
error("Font::loadFont(): Invalid font length.");
|
||||
}
|
||||
|
||||
MemoryReadStream readS(fontres_p, fontres_len);
|
||||
@ -123,7 +110,7 @@ int FONT_Load(uint32 font_rn, int font_id) {
|
||||
// Create new font structure
|
||||
font = (R_FONT *)malloc(sizeof *font);
|
||||
if (font == NULL) {
|
||||
FontModule.err_str = "Memory allocation error.";
|
||||
error("Font:loadFont(): Memory allocation error.");
|
||||
return R_MEM;
|
||||
}
|
||||
|
||||
@ -132,7 +119,7 @@ int FONT_Load(uint32 font_rn, int font_id) {
|
||||
fh.c_width = readS.readUint16LE();
|
||||
fh.row_length = readS.readUint16LE();
|
||||
|
||||
debug(1, "FONT_Load(): Reading font resource...");
|
||||
debug(1, "Font::loadFont(): Reading font resource...");
|
||||
|
||||
debug(2, "Character width:\t%d", fh.c_width);
|
||||
debug(2, "Character height:\t%d", fh.c_height);
|
||||
@ -141,7 +128,7 @@ int FONT_Load(uint32 font_rn, int font_id) {
|
||||
// Create normal font style
|
||||
normal_font = (R_FONT_STYLE *)malloc(sizeof *normal_font);
|
||||
if (normal_font == NULL) {
|
||||
FontModule.err_str = "Memory allocation error.";
|
||||
error("Font::loadFont(): Memory allocation error.");
|
||||
free(font);
|
||||
return R_MEM;
|
||||
}
|
||||
@ -157,7 +144,7 @@ int FONT_Load(uint32 font_rn, int font_id) {
|
||||
|
||||
for (c = 0; c < R_FONT_CHARCOUNT; c++) {
|
||||
nbits = normal_font->fce[c].width = readS.readByte();
|
||||
normal_font->fce[c].byte_width = GetByteLen(nbits);
|
||||
normal_font->fce[c].byte_width = getByteLen(nbits);
|
||||
}
|
||||
|
||||
for (c = 0; c < R_FONT_CHARCOUNT; c++) {
|
||||
@ -179,33 +166,33 @@ int FONT_Load(uint32 font_rn, int font_id) {
|
||||
font->normal_loaded = 1;
|
||||
|
||||
// Create outline font style
|
||||
font->outline = FONT_CreateOutline(normal_font);
|
||||
font->outline = createOutline(normal_font);
|
||||
font->outline_loaded = 1;
|
||||
|
||||
// Set font data
|
||||
FontModule.fonts[font_id] = font;
|
||||
_fonts[font_id] = font;
|
||||
|
||||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
int FONT_GetHeight(int font_id) {
|
||||
int Font::getHeight(int font_id) {
|
||||
R_FONT *font;
|
||||
|
||||
if (!FontModule.init) {
|
||||
if (!_initialized) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
if ((font_id < 0) || (font_id >= FontModule.n_fonts) || (FontModule.fonts[font_id] == NULL)) {
|
||||
FontModule.err_str = "Invalid font id.";
|
||||
if ((font_id < 0) || (font_id >= _n_fonts) || (_fonts[font_id] == NULL)) {
|
||||
error("Font::getHeight(): Invalid font id.");
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
font = FontModule.fonts[font_id];
|
||||
font = _fonts[font_id];
|
||||
|
||||
return font->normal->hdr.c_height;
|
||||
}
|
||||
|
||||
static R_FONT_STYLE *FONT_CreateOutline(R_FONT_STYLE *src_font) {
|
||||
R_FONT_STYLE *Font::createOutline(R_FONT_STYLE *src_font) {
|
||||
R_FONT_STYLE *new_font;
|
||||
unsigned char *new_font_data;
|
||||
size_t new_font_data_len;
|
||||
@ -230,7 +217,7 @@ static R_FONT_STYLE *FONT_CreateOutline(R_FONT_STYLE *src_font) {
|
||||
new_font = (R_FONT_STYLE *)malloc(sizeof *new_font);
|
||||
|
||||
if (new_font == NULL) {
|
||||
FontModule.err_str = "Memory allocation error.";
|
||||
error("Font::createOutline(): Memory allocation error.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -250,8 +237,8 @@ static R_FONT_STYLE *FONT_CreateOutline(R_FONT_STYLE *src_font) {
|
||||
new_font->fce[i].flag = src_font->fce[i].flag;
|
||||
|
||||
if (src_font->fce[i].width != 0) {
|
||||
new_byte_width = GetByteLen(src_font->fce[i].width + 2);
|
||||
old_byte_width = GetByteLen(src_font->fce[i].width);
|
||||
new_byte_width = getByteLen(src_font->fce[i].width + 2);
|
||||
old_byte_width = getByteLen(src_font->fce[i].width);
|
||||
|
||||
if (new_byte_width > old_byte_width) {
|
||||
index_offset++;
|
||||
@ -274,7 +261,7 @@ static R_FONT_STYLE *FONT_CreateOutline(R_FONT_STYLE *src_font) {
|
||||
new_font_data = (unsigned char *)malloc(new_font_data_len);
|
||||
|
||||
if (new_font_data == NULL) {
|
||||
FontModule.err_str = "Memory allocation error.";
|
||||
error("Font::createOutline(): Memory allocation error.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -335,7 +322,7 @@ static R_FONT_STYLE *FONT_CreateOutline(R_FONT_STYLE *src_font) {
|
||||
return new_font;
|
||||
}
|
||||
|
||||
static int GetByteLen(int num_bits) {
|
||||
int Font::getByteLen(int num_bits) {
|
||||
int byte_len;
|
||||
byte_len = num_bits / 8;
|
||||
|
||||
@ -350,23 +337,23 @@ static int GetByteLen(int num_bits) {
|
||||
// of at most 'test_str_ct' characters of the string 'test_str', taking
|
||||
// into account any formatting options specified by 'flags'.
|
||||
// If 'test_str_ct' is 0, all characters of 'test_str' are counted.
|
||||
int FONT_GetStringWidth(int font_id, const char *test_str, size_t test_str_ct, int flags) {
|
||||
int Font::getStringWidth(int font_id, const char *test_str, size_t test_str_ct, int flags) {
|
||||
R_FONT *font;
|
||||
size_t ct;
|
||||
int width = 0;
|
||||
int ch;
|
||||
const byte *txt_p;
|
||||
|
||||
if (!FontModule.init) {
|
||||
if (!_initialized) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
if ((font_id < 0) || (font_id >= FontModule.n_fonts) || (FontModule.fonts[font_id] == NULL)) {
|
||||
FontModule.err_str = "Invalid font id.";
|
||||
if ((font_id < 0) || (font_id >= _n_fonts) || (_fonts[font_id] == NULL)) {
|
||||
error("Font::getStringWidth(): Invalid font id.");
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
font = FontModule.fonts[font_id];
|
||||
font = _fonts[font_id];
|
||||
assert(font != NULL);
|
||||
|
||||
txt_p = (const byte *) test_str;
|
||||
@ -374,7 +361,7 @@ int FONT_GetStringWidth(int font_id, const char *test_str, size_t test_str_ct, i
|
||||
for (ct = test_str_ct; *txt_p && (!test_str_ct || ct > 0); txt_p++, ct--) {
|
||||
ch = *txt_p & 0xFFU;
|
||||
// Translate character
|
||||
ch = CharMap[ch];
|
||||
ch = _charMap[ch];
|
||||
assert(ch < R_FONT_CHARCOUNT);
|
||||
width += font->normal->fce[ch].tracking;
|
||||
}
|
||||
@ -386,37 +373,37 @@ int FONT_GetStringWidth(int font_id, const char *test_str, size_t test_str_ct, i
|
||||
return width;
|
||||
}
|
||||
|
||||
int FONT_Draw(int font_id, R_SURFACE *ds, const char *draw_str, size_t draw_str_ct,
|
||||
int Font::draw(int font_id, R_SURFACE *ds, const char *draw_str, size_t draw_str_ct,
|
||||
int text_x, int text_y, int color, int effect_color, int flags) {
|
||||
R_FONT *font;
|
||||
|
||||
if (!FontModule.init) {
|
||||
FontModule.err_str = "Font Module not initialized.";
|
||||
if (!_initialized) {
|
||||
error("Font::draw(): Font Module not initialized.");
|
||||
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
if ((font_id < 0) || (font_id >= FontModule.n_fonts) || (FontModule.fonts[font_id] == NULL)) {
|
||||
FontModule.err_str = "Invalid font id.";
|
||||
if ((font_id < 0) || (font_id >= _n_fonts) || (_fonts[font_id] == NULL)) {
|
||||
error("Font::draw(): Invalid font id.");
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
font = FontModule.fonts[font_id];
|
||||
font = _fonts[font_id];
|
||||
|
||||
if (flags & FONT_OUTLINE) {
|
||||
FONT_Out(font->outline, ds, draw_str, draw_str_ct, text_x - 1, text_y - 1, effect_color);
|
||||
FONT_Out(font->normal, ds, draw_str, draw_str_ct, text_x, text_y, color);
|
||||
outFont(font->outline, ds, draw_str, draw_str_ct, text_x - 1, text_y - 1, effect_color);
|
||||
outFont(font->normal, ds, draw_str, draw_str_ct, text_x, text_y, color);
|
||||
} else if (flags & FONT_SHADOW) {
|
||||
FONT_Out(font->normal, ds, draw_str, draw_str_ct, text_x - 1, text_y + 1, effect_color);
|
||||
FONT_Out(font->normal, ds, draw_str, draw_str_ct, text_x, text_y, color);
|
||||
outFont(font->normal, ds, draw_str, draw_str_ct, text_x - 1, text_y + 1, effect_color);
|
||||
outFont(font->normal, ds, draw_str, draw_str_ct, text_x, text_y, color);
|
||||
} else { // FONT_NORMAL
|
||||
FONT_Out(font->normal, ds, draw_str, draw_str_ct, text_x, text_y, color);
|
||||
outFont(font->normal, ds, draw_str, draw_str_ct, text_x, text_y, color);
|
||||
}
|
||||
|
||||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
int FONT_Out(R_FONT_STYLE * draw_font, R_SURFACE * ds, const char *draw_str, size_t draw_str_ct,
|
||||
int Font::outFont(R_FONT_STYLE * draw_font, R_SURFACE * ds, const char *draw_str, size_t draw_str_ct,
|
||||
int text_x, int text_y, int color) {
|
||||
const byte *draw_str_p;
|
||||
byte *c_data_ptr;
|
||||
@ -449,7 +436,7 @@ int FONT_Out(R_FONT_STYLE * draw_font, R_SURFACE * ds, const char *draw_str, siz
|
||||
c_code = *draw_str_p & 0xFFU;
|
||||
|
||||
// Translate character
|
||||
c_code = CharMap[c_code];
|
||||
c_code = _charMap[c_code];
|
||||
assert(c_code < R_FONT_CHARCOUNT);
|
||||
|
||||
// Check if character is defined
|
||||
|
53
saga/font.h
53
saga/font.h
@ -26,6 +26,8 @@
|
||||
#ifndef SAGA_FONT_H__
|
||||
#define SAGA_FONT_H__
|
||||
|
||||
#include "saga/gfx.h"
|
||||
|
||||
namespace Saga {
|
||||
|
||||
#define R_FONT_SHOWUNDEFINED 1 // Define to draw undefined characters * as ?'s
|
||||
@ -46,6 +48,20 @@ namespace Saga {
|
||||
|
||||
#define SAGA_FONT_HEADER_LEN 6
|
||||
|
||||
enum FONT_ID {
|
||||
SMALL_FONT_ID,
|
||||
MEDIUM_FONT_ID,
|
||||
BIG_FONT_ID
|
||||
};
|
||||
|
||||
enum FONT_EFFECT_FLAGS {
|
||||
FONT_NORMAL = 0x00,
|
||||
FONT_OUTLINE = 0x01,
|
||||
FONT_SHADOW = 0x02,
|
||||
FONT_BOLD = 0x04,
|
||||
FONT_CENTERED = 0x08
|
||||
};
|
||||
|
||||
struct R_FONT_HEADER {
|
||||
int c_height;
|
||||
int c_width;
|
||||
@ -80,24 +96,33 @@ struct R_FONT {
|
||||
size_t res_len;
|
||||
};
|
||||
|
||||
struct R_FONT_MODULE {
|
||||
int init;
|
||||
R_RSCFILE_CONTEXT *font_ctxt;
|
||||
class Font {
|
||||
public:
|
||||
Font(SagaEngine *vm);
|
||||
~Font(void);
|
||||
int draw(int font_id, R_SURFACE *ds, const char *draw_str, size_t draw_str_len,
|
||||
int text_x, int text_y, int color, int effect_color, int flags);
|
||||
int getStringWidth(int font_id, const char *test_str, size_t test_str_ct, int flags);
|
||||
int getHeight(int font_id);
|
||||
|
||||
int n_fonts;
|
||||
R_FONT **fonts;
|
||||
private:
|
||||
|
||||
int err_n;
|
||||
const char *err_str;
|
||||
int loadFont(uint32 font_rn, int font_id);
|
||||
R_FONT_STYLE *createOutline(R_FONT_STYLE * src_font);
|
||||
int outFont(R_FONT_STYLE *font, R_SURFACE * ds, const char *draw_str, size_t draw_str_ct,
|
||||
int text_x, int text_y, int color);
|
||||
int getByteLen(int num_bits);
|
||||
|
||||
static const int _charMap[256];
|
||||
SagaEngine *_vm;
|
||||
|
||||
bool _initialized;
|
||||
R_RSCFILE_CONTEXT *_font_ctxt;
|
||||
|
||||
int _n_fonts;
|
||||
R_FONT **_fonts;
|
||||
};
|
||||
|
||||
int FONT_Load(uint32 font_rn, int font_id);
|
||||
static R_FONT_STYLE *FONT_CreateOutline(R_FONT_STYLE * src_font);
|
||||
int FONT_Out(R_FONT_STYLE *font, R_SURFACE * ds, const char *draw_str, size_t draw_str_ct,
|
||||
int text_x, int text_y, int color);
|
||||
static int GetByteLen(int num_bits);
|
||||
extern int CharMap[];
|
||||
|
||||
} // End of namespace Saga
|
||||
|
||||
#endif
|
||||
|
@ -25,9 +25,12 @@
|
||||
|
||||
// Translation table derived from http://www.kostis.net/charsets/
|
||||
|
||||
#include "saga/saga.h"
|
||||
#include "saga/font.h"
|
||||
|
||||
namespace Saga {
|
||||
|
||||
int CharMap[] = {
|
||||
const int Font::_charMap[256] = {
|
||||
0, // 0
|
||||
1, // 1
|
||||
2, // 2
|
||||
|
@ -1,54 +0,0 @@
|
||||
/* ScummVM - Scumm Interpreter
|
||||
* Copyright (C) 2004 The ScummVM project
|
||||
*
|
||||
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
// Font management and font drawing module public header
|
||||
|
||||
#ifndef SAGA_FONT_MOD_H_
|
||||
#define SAGA_FONT_MOD_H_
|
||||
|
||||
namespace Saga {
|
||||
|
||||
enum FONT_ID {
|
||||
SMALL_FONT_ID,
|
||||
MEDIUM_FONT_ID,
|
||||
BIG_FONT_ID
|
||||
};
|
||||
|
||||
enum FONT_EFFECT_FLAGS {
|
||||
FONT_NORMAL = 0x00,
|
||||
FONT_OUTLINE = 0x01,
|
||||
FONT_SHADOW = 0x02,
|
||||
FONT_BOLD = 0x04,
|
||||
FONT_CENTERED = 0x08
|
||||
};
|
||||
|
||||
int FONT_Init();
|
||||
int FONT_Shutdown();
|
||||
int FONT_Draw(int font_id, R_SURFACE *ds, const char *draw_str, size_t draw_str_len,
|
||||
int text_x, int text_y, int color, int effect_color, int flags);
|
||||
int FONT_GetStringWidth(int font_id, const char *test_str, size_t test_str_ct, int flags);
|
||||
int FONT_GetHeight(int font_id);
|
||||
|
||||
} // End of namespace Saga
|
||||
|
||||
#endif
|
@ -30,7 +30,6 @@
|
||||
#include "saga/animation.h"
|
||||
#include "saga/cvar_mod.h"
|
||||
#include "saga/events_mod.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/rscfile_mod.h"
|
||||
#include "saga/scene_mod.h"
|
||||
#include "saga/text_mod.h"
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "saga/cvar_mod.h"
|
||||
#include "saga/actor.h"
|
||||
#include "saga/console_mod.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
#include "saga/objectmap.h"
|
||||
#include "saga/rscfile_mod.h"
|
||||
#include "saga/script_mod.h"
|
||||
@ -359,9 +359,9 @@ int DrawStatusBar(R_SURFACE *ds) {
|
||||
|
||||
_vm->_gfx->drawRect(ds, &rect, IfModule.i_desc.status_bgcol);
|
||||
|
||||
string_w = FONT_GetStringWidth(SMALL_FONT_ID, IfModule.status_txt, 0, 0);
|
||||
string_w = _vm->_font->getStringWidth(SMALL_FONT_ID, IfModule.status_txt, 0, 0);
|
||||
|
||||
FONT_Draw(SMALL_FONT_ID, ds, IfModule.status_txt, 0, (IfModule.i_desc.status_w / 2) - (string_w / 2),
|
||||
_vm->_font->draw(SMALL_FONT_ID, ds, IfModule.status_txt, 0, (IfModule.i_desc.status_w / 2) - (string_w / 2),
|
||||
IfModule.i_desc.status_y + IfModule.i_desc.status_txt_y, IfModule.i_desc.status_txt_col, 0, 0);
|
||||
|
||||
return R_SUCCESS;
|
||||
@ -448,7 +448,7 @@ int HandleCommandUpdate(R_SURFACE *ds, R_POINT *imouse_pt) {
|
||||
|
||||
verb_idx = IfModule.c_panel.buttons[i].data;
|
||||
|
||||
string_w = FONT_GetStringWidth(SMALL_FONT_ID, I_VerbData[verb_idx].verb_str, 0, 0);
|
||||
string_w = _vm->_font->getStringWidth(SMALL_FONT_ID, I_VerbData[verb_idx].verb_str, 0, 0);
|
||||
|
||||
if (i == hit_button) {
|
||||
color = IfModule.i_desc.cmd_txt_hilitecol;
|
||||
@ -459,7 +459,7 @@ int HandleCommandUpdate(R_SURFACE *ds, R_POINT *imouse_pt) {
|
||||
button_x = IfModule.c_panel.x + IfModule.c_panel.buttons[i].x1;
|
||||
button_y = IfModule.c_panel.y + IfModule.c_panel.buttons[i].y1;
|
||||
|
||||
FONT_Draw(SMALL_FONT_ID, ds, I_VerbData[verb_idx].verb_str, 0,
|
||||
_vm->_font->draw(SMALL_FONT_ID, ds, I_VerbData[verb_idx].verb_str, 0,
|
||||
button_x + ((button_w / 2) - (string_w / 2)), button_y + 1,
|
||||
color, IfModule.i_desc.cmd_txt_shadowcol, FONT_SHADOW);
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "saga/animation.h"
|
||||
#include "saga/cvar_mod.h"
|
||||
#include "saga/events_mod.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
#include "saga/game_mod.h"
|
||||
#include "saga/rscfile_mod.h"
|
||||
#include "saga/scene_mod.h"
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "saga/gfx.h"
|
||||
#include "saga/cvar_mod.h"
|
||||
#include "saga/console_mod.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
#include "saga/objectmap.h"
|
||||
|
||||
namespace Saga {
|
||||
@ -339,7 +339,7 @@ int ObjectMap::draw(R_SURFACE *ds, R_POINT *imouse_pt, int color, int color2) {
|
||||
}
|
||||
|
||||
if (draw_txt) {
|
||||
FONT_Draw(SMALL_FONT_ID, ds, txt_buf, 0, 2, 2,
|
||||
_vm->_font->draw(SMALL_FONT_ID, ds, txt_buf, 0, 2, 2,
|
||||
_gfx->getWhite(), _gfx->getBlack(), FONT_OUTLINE);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "saga/actor.h"
|
||||
#include "saga/console_mod.h"
|
||||
#include "saga/cvar_mod.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
#include "saga/game_mod.h"
|
||||
#include "saga/interface_mod.h"
|
||||
#include "saga/scene_mod.h"
|
||||
@ -155,16 +155,16 @@ int Render::drawScene() {
|
||||
// Display rendering information
|
||||
if (_flags & RF_SHOW_FPS) {
|
||||
sprintf(txt_buf, "%d", _fps);
|
||||
fps_width = FONT_GetStringWidth(SMALL_FONT_ID, txt_buf, 0, FONT_NORMAL);
|
||||
FONT_Draw(SMALL_FONT_ID, backbuf_surface, txt_buf, 0, backbuf_surface->buf_w - fps_width, 2,
|
||||
fps_width = _vm->_font->getStringWidth(SMALL_FONT_ID, txt_buf, 0, FONT_NORMAL);
|
||||
_vm->_font->draw(SMALL_FONT_ID, backbuf_surface, txt_buf, 0, backbuf_surface->buf_w - fps_width, 2,
|
||||
_gfx->getWhite(), _gfx->getBlack(), FONT_OUTLINE);
|
||||
}
|
||||
|
||||
// Display "paused game" message, if applicable
|
||||
if (_flags & RF_RENDERPAUSE) {
|
||||
int msg_len = strlen(R_PAUSEGAME_MSG);
|
||||
int msg_w = FONT_GetStringWidth(BIG_FONT_ID, R_PAUSEGAME_MSG, msg_len, FONT_OUTLINE);
|
||||
FONT_Draw(BIG_FONT_ID, backbuf_surface, R_PAUSEGAME_MSG, msg_len,
|
||||
int msg_w = _vm->_font->getStringWidth(BIG_FONT_ID, R_PAUSEGAME_MSG, msg_len, FONT_OUTLINE);
|
||||
_vm->_font->draw(BIG_FONT_ID, backbuf_surface, R_PAUSEGAME_MSG, msg_len,
|
||||
(backbuf_surface->buf_w - msg_w) / 2, 90, _gfx->getWhite(), _gfx->getBlack(), FONT_OUTLINE);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include "saga/cvar_mod.h"
|
||||
#include "saga/events_mod.h"
|
||||
#include "saga/actionmap.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
#include "saga/game_mod.h"
|
||||
#include "saga/game.h"
|
||||
#include "saga/interface_mod.h"
|
||||
@ -149,7 +149,7 @@ void SagaEngine::go() {
|
||||
// Initialize engine modules
|
||||
_sndRes = new SndRes(this);
|
||||
EVENT_Init();
|
||||
FONT_Init();
|
||||
_font = new Font(this);
|
||||
SPRITE_Init();
|
||||
_anim = new Anim(this);
|
||||
_script = new Script();
|
||||
@ -247,7 +247,7 @@ void SagaEngine::shutdown() {
|
||||
delete _actor;
|
||||
delete _script;
|
||||
SPRITE_Shutdown();
|
||||
FONT_Shutdown();
|
||||
delete _font;
|
||||
CON_Shutdown();
|
||||
CVAR_Shutdown();
|
||||
EVENT_Shutdown();
|
||||
|
@ -49,6 +49,7 @@ class Gfx;
|
||||
class SData;
|
||||
class Script;
|
||||
class Actor;
|
||||
class Font;
|
||||
|
||||
using Common::MemoryReadStream;
|
||||
|
||||
@ -103,6 +104,7 @@ public:
|
||||
SData *_sdata;
|
||||
Script *_script;
|
||||
Actor *_actor;
|
||||
Font *_font;
|
||||
|
||||
private:
|
||||
int decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len);
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "saga/console_mod.h"
|
||||
#include "saga/text_mod.h"
|
||||
#include "saga/scene_mod.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
|
||||
#include "saga/script.h"
|
||||
#include "saga/sthread.h"
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "saga/rscfile_mod.h"
|
||||
|
||||
#include "saga/text_mod.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
|
||||
#include "saga/sprite_mod.h"
|
||||
#include "saga/sprite.h"
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "saga/yslib.h"
|
||||
|
||||
#include "saga/gfx.h"
|
||||
#include "saga/font_mod.h"
|
||||
#include "saga/font.h"
|
||||
|
||||
#include "saga/text_mod.h"
|
||||
#include "saga/text.h"
|
||||
@ -69,7 +69,7 @@ int TEXT_Draw(int font_id, R_SURFACE *ds, const char *string, int text_x, int te
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
string_w = FONT_GetStringWidth(font_id, string, string_len, flags);
|
||||
string_w = _vm->_font->getStringWidth(font_id, string, string_len, flags);
|
||||
|
||||
if (text_x < (ds->buf_w / 2)) {
|
||||
// Fit to right side
|
||||
@ -82,12 +82,12 @@ int TEXT_Draw(int font_id, R_SURFACE *ds, const char *string, int text_x, int te
|
||||
if (fit_w >= string_w) {
|
||||
// Entire string fits, draw it
|
||||
text_x = text_x - (string_w / 2);
|
||||
FONT_Draw(font_id, ds, string, string_len, text_x, text_y, color, effect_color, flags);
|
||||
_vm->_font->draw(font_id, ds, string, string_len, text_x, text_y, color, effect_color, flags);
|
||||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
// String won't fit on one line
|
||||
h = FONT_GetHeight(font_id);
|
||||
h = _vm->_font->getHeight(font_id);
|
||||
w_total = 0;
|
||||
len_total = 0;
|
||||
wc = 0;
|
||||
@ -106,7 +106,7 @@ int TEXT_Draw(int font_id, R_SURFACE *ds, const char *string, int text_x, int te
|
||||
len = found_p - measure_p;
|
||||
}
|
||||
|
||||
w = FONT_GetStringWidth(font_id, measure_p, len, flags);
|
||||
w = _vm->_font->getStringWidth(font_id, measure_p, len, flags);
|
||||
measure_p = found_p;
|
||||
|
||||
if ((w_total + w) > fit_w) {
|
||||
@ -117,7 +117,7 @@ int TEXT_Draw(int font_id, R_SURFACE *ds, const char *string, int text_x, int te
|
||||
}
|
||||
|
||||
// Wrap what we've got and restart
|
||||
FONT_Draw(font_id, ds, start_p, len_total, text_x - (w_total / 2), text_y, color,
|
||||
_vm->_font->draw(font_id, ds, start_p, len_total, text_x - (w_total / 2), text_y, color,
|
||||
effect_color, flags);
|
||||
text_y += h + R_TEXT_LINESPACING;
|
||||
w_total = 0;
|
||||
@ -132,7 +132,7 @@ int TEXT_Draw(int font_id, R_SURFACE *ds, const char *string, int text_x, int te
|
||||
wc++;
|
||||
if (found_p == NULL) {
|
||||
// Since word hit NULL but fit, we are done
|
||||
FONT_Draw(font_id, ds, start_p, len_total, text_x - (w_total / 2), text_y, color,
|
||||
_vm->_font->draw(font_id, ds, start_p, len_total, text_x - (w_total / 2), text_y, color,
|
||||
effect_color, flags);
|
||||
return R_SUCCESS;
|
||||
}
|
||||
@ -141,7 +141,7 @@ int TEXT_Draw(int font_id, R_SURFACE *ds, const char *string, int text_x, int te
|
||||
}
|
||||
} else {
|
||||
// Text is not centered; No formatting required
|
||||
FONT_Draw(font_id, ds, string, string_len, text_x, text_y, color, effect_color, flags);
|
||||
_vm->_font->draw(font_id, ds, string, string_len, text_x, text_y, color, effect_color, flags);
|
||||
}
|
||||
|
||||
return R_SUCCESS;
|
||||
|
Loading…
x
Reference in New Issue
Block a user