2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
2009-02-10 10:01:48 -08:00
|
|
|
Copyright (C) 2005-2009 Warzone Resurrection Project
|
2007-01-15 12:09:25 -08:00
|
|
|
|
|
|
|
Warzone 2100 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.
|
|
|
|
|
|
|
|
Warzone 2100 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 Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-06-14 14:56:36 -07:00
|
|
|
|
2008-04-20 05:52:19 -07:00
|
|
|
#include "lib/ivis_opengl/GLee.h"
|
2007-11-25 13:43:16 -08:00
|
|
|
#include "lib/framework/frame.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-02-10 09:23:09 -08:00
|
|
|
#include "lib/framework/string_ext.h"
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/ivis_common/ivisdef.h"
|
|
|
|
#include "lib/ivis_common/piestate.h"
|
|
|
|
#include "lib/ivis_common/rendmode.h"
|
|
|
|
#include "lib/ivis_common/pieclip.h"
|
|
|
|
#include "lib/ivis_common/pieblitfunc.h"
|
|
|
|
#include "lib/ivis_common/piepalette.h"
|
|
|
|
#include "lib/ivis_common/ivispatch.h"
|
|
|
|
#include "lib/ivis_common/textdraw.h"
|
|
|
|
#include "lib/ivis_common/bitimage.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-12-15 15:34:51 -08:00
|
|
|
#ifdef WZ_OS_MAC
|
|
|
|
# include <QuesoGLC/glc.h>
|
|
|
|
#else
|
2007-12-17 09:22:07 -08:00
|
|
|
# include <GL/glc.h>
|
2007-12-15 15:34:51 -08:00
|
|
|
#endif
|
2007-10-01 12:45:49 -07:00
|
|
|
|
2008-08-20 14:23:58 -07:00
|
|
|
static char font_family[128];
|
|
|
|
static char font_face_regular[128];
|
|
|
|
static char font_face_bold[128];
|
2007-10-04 12:43:38 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
static float font_size = 12.f;
|
|
|
|
// Contains the font color in the following order: red, green, blue, alpha
|
|
|
|
static float font_colour[4] = {1.f, 1.f, 1.f, 1.f};
|
|
|
|
|
2008-03-04 07:03:18 -08:00
|
|
|
static GLint _glcContext = 0;
|
|
|
|
static GLint _glcFont_Regular = 0;
|
|
|
|
static GLint _glcFont_Bold = 0;
|
2007-08-03 04:57:16 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
/***************************************************************************/
|
|
|
|
/*
|
2007-10-01 12:45:49 -07:00
|
|
|
* Source
|
2007-06-28 10:47:08 -07:00
|
|
|
*/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2008-08-20 14:23:58 -07:00
|
|
|
void iV_font(const char *fontName, const char *fontFace, const char *fontFaceBold)
|
|
|
|
{
|
|
|
|
if (_glcContext)
|
|
|
|
{
|
|
|
|
debug(LOG_ERROR, "Cannot change font in running game, yet.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fontName)
|
|
|
|
{
|
|
|
|
sstrcpy(font_family, fontName);
|
|
|
|
}
|
|
|
|
if (fontFace)
|
|
|
|
{
|
|
|
|
sstrcpy(font_face_regular, fontFace);
|
|
|
|
}
|
|
|
|
if (fontFaceBold)
|
|
|
|
{
|
|
|
|
sstrcpy(font_face_bold, fontFaceBold);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-05 08:34:55 -07:00
|
|
|
static inline void iV_printFontList(void)
|
2007-10-01 12:45:49 -07:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2007-12-10 15:15:46 -08:00
|
|
|
unsigned int font_count = glcGeti(GLC_CURRENT_FONT_COUNT);
|
2007-10-04 12:43:38 -07:00
|
|
|
debug(LOG_NEVER, "GLC_CURRENT_FONT_COUNT = %d", font_count);
|
|
|
|
|
|
|
|
if (font_count == 0)
|
2007-10-05 10:06:20 -07:00
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "The required font (%s) isn't loaded", font_family);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-05 10:06:20 -07:00
|
|
|
// Fall back to unselected fonts since the requested font apparently
|
|
|
|
// isn't available.
|
|
|
|
glcEnable(GLC_AUTO_FONT);
|
|
|
|
}
|
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
for (i = 0; i < font_count; ++i)
|
|
|
|
{
|
|
|
|
GLint font = glcGetListi(GLC_CURRENT_FONT_LIST, i);
|
|
|
|
/* The output of the family name and the face is printed using 2 steps
|
|
|
|
* because glcGetFontc and glcGetFontFace return their result in the
|
|
|
|
* same buffer (according to GLC specs).
|
|
|
|
*/
|
|
|
|
char prBuffer[1024];
|
|
|
|
snprintf(prBuffer, sizeof(prBuffer), "Font #%d : %s ", font, (const char*)glcGetFontc(font, GLC_FAMILY));
|
|
|
|
prBuffer[sizeof(prBuffer) - 1] = 0;
|
2008-05-25 06:46:49 -07:00
|
|
|
sstrcat(prBuffer, glcGetFontFace(font));
|
2008-03-28 16:28:44 -07:00
|
|
|
debug(LOG_NEVER, "%s", prBuffer);
|
2007-10-01 12:45:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-05 08:34:55 -07:00
|
|
|
static void iV_initializeGLC(void)
|
2007-08-01 11:26:56 -07:00
|
|
|
{
|
2008-03-04 07:03:18 -08:00
|
|
|
if (_glcContext)
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
return;
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-03-04 07:03:18 -08:00
|
|
|
_glcContext = glcGenContext();
|
|
|
|
if (!_glcContext)
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "Failed to initialize");
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-10-01 12:45:49 -07:00
|
|
|
else
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2009-10-18 05:30:31 -07:00
|
|
|
debug(LOG_NEVER, "Successfully initialized. _glcContext = %d", _glcContext);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-03-04 07:03:18 -08:00
|
|
|
glcContext(_glcContext);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2009-11-07 20:06:23 -08:00
|
|
|
glcEnable(GLC_AUTO_FONT); // We *do* want font fall-backs
|
2007-10-27 12:20:25 -07:00
|
|
|
glcRenderStyle(GLC_TEXTURE);
|
2008-03-17 00:23:48 -07:00
|
|
|
glcStringType(GLC_UTF8_QSO); // Set GLC's string type to UTF-8 FIXME should be UCS4 to avoid conversions
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-03-04 07:03:18 -08:00
|
|
|
_glcFont_Regular = glcGenFontID();
|
|
|
|
_glcFont_Bold = glcGenFontID();
|
2007-10-01 12:45:49 -07:00
|
|
|
|
2008-03-04 07:03:18 -08:00
|
|
|
if (!glcNewFontFromFamily(_glcFont_Regular, font_family))
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "Failed to select font family %s as regular font", font_family);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_NEVER, "Successfully selected font family %s as regular font", font_family);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-10-01 12:45:49 -07:00
|
|
|
|
2008-03-04 07:03:18 -08:00
|
|
|
if (!glcFontFace(_glcFont_Regular, font_face_regular))
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_WARNING, "Failed to select the \"%s\" font face of font family %s", font_face_regular, font_family);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_NEVER, "Successfully selected the \"%s\" font face of font family %s", font_face_regular, font_family);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-03-04 07:03:18 -08:00
|
|
|
if (!glcNewFontFromFamily(_glcFont_Bold, font_family))
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2007-12-07 11:31:19 -08:00
|
|
|
debug(LOG_ERROR, "iV_initializeGLC: Failed to select font family %s for the bold font", font_family);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_NEVER, "Successfully selected font family %s for the bold font", font_family);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-10-01 12:45:49 -07:00
|
|
|
|
2008-03-04 07:03:18 -08:00
|
|
|
if (!glcFontFace(_glcFont_Bold, font_face_bold))
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_WARNING, "Failed to select the \"%s\" font face of font family %s", font_face_bold, font_family);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_NEVER, "Successfully selected the \"%s\" font face of font family %s", font_face_bold, font_family);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-10-01 12:45:49 -07:00
|
|
|
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_NEVER, "Finished initializing GLC");
|
2007-10-01 12:45:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void iV_TextInit()
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
iV_initializeGLC();
|
|
|
|
iV_SetFont(font_regular);
|
2007-10-04 12:43:38 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
iV_printFontList();
|
|
|
|
#endif
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
void iV_TextShutdown()
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2008-03-04 07:03:18 -08:00
|
|
|
if (_glcFont_Regular)
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2008-03-04 07:03:18 -08:00
|
|
|
glcDeleteFont(_glcFont_Regular);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-03-04 07:03:18 -08:00
|
|
|
if (_glcFont_Bold)
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2008-03-04 07:03:18 -08:00
|
|
|
glcDeleteFont(_glcFont_Bold);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2006-06-02 12:34:58 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
glcContext(0);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-03-04 07:03:18 -08:00
|
|
|
if (_glcContext)
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2008-03-04 07:03:18 -08:00
|
|
|
glcDeleteContext(_glcContext);
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-10-01 12:45:49 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
void iV_SetFont(enum iV_fonts FontID)
|
|
|
|
{
|
|
|
|
switch (FontID)
|
2007-08-01 11:26:56 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
case font_regular:
|
|
|
|
iV_SetTextSize(12.f);
|
2008-03-04 07:03:18 -08:00
|
|
|
glcFont(_glcFont_Regular);
|
2007-10-01 12:45:49 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case font_large:
|
|
|
|
iV_SetTextSize(21.f);
|
2008-03-04 07:03:18 -08:00
|
|
|
glcFont(_glcFont_Bold);
|
2007-10-01 12:45:49 -07:00
|
|
|
break;
|
2009-12-18 14:21:34 -08:00
|
|
|
|
|
|
|
case font_small:
|
|
|
|
iV_SetTextSize(9.f);
|
|
|
|
glcFont(_glcFont_Regular);
|
|
|
|
break;
|
2007-10-01 12:45:49 -07:00
|
|
|
}
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-04-05 08:34:55 -07:00
|
|
|
static inline float getGLCResolution(void)
|
2007-10-01 12:45:49 -07:00
|
|
|
{
|
|
|
|
float resolution = glcGetf(GLC_RESOLUTION);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
// The default resolution as used by OpenGLC is 72 dpi
|
|
|
|
if (resolution == 0.f)
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
return 72.f;
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
return resolution;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-04-05 08:34:55 -07:00
|
|
|
static inline float getGLCPixelSize(void)
|
2007-10-01 12:45:49 -07:00
|
|
|
{
|
|
|
|
float pixel_size = font_size * getGLCResolution() / 72.f;
|
|
|
|
return pixel_size;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
static inline float getGLCPointWidth(const float* boundingbox)
|
|
|
|
{
|
|
|
|
// boundingbox contains: [ xlb ylb xrb yrb xrt yrt xlt ylt ]
|
|
|
|
// l = left; r = right; b = bottom; t = top;
|
|
|
|
float rightTopX = boundingbox[4];
|
|
|
|
float leftTopX = boundingbox[6];
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
float point_width = rightTopX - leftTopX;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
return point_width;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
static inline float getGLCPointHeight(const float* boundingbox)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
// boundingbox contains: [ xlb ylb xrb yrb xrt yrt xlt ylt ]
|
|
|
|
// l = left; r = right; b = bottom; t = top;
|
|
|
|
float leftBottomY = boundingbox[1];
|
|
|
|
float leftTopY = boundingbox[7];
|
|
|
|
|
|
|
|
float point_height = fabsf(leftTopY - leftBottomY);
|
|
|
|
|
|
|
|
return point_height;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
static inline float getGLCPointToPixel(float point_width)
|
|
|
|
{
|
|
|
|
float pixel_width = point_width * getGLCPixelSize();
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
return pixel_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int iV_GetTextWidth(const char* string)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
float boundingbox[8];
|
|
|
|
float pixel_width, point_width;
|
|
|
|
|
|
|
|
glcMeasureString(GL_FALSE, string);
|
|
|
|
if (!glcGetStringMetric(GLC_BOUNDS, boundingbox))
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "Couldn't retrieve a bounding box for the string \"%s\"", string);
|
2007-10-01 12:45:49 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
point_width = getGLCPointWidth(boundingbox);
|
|
|
|
pixel_width = getGLCPointToPixel(point_width);
|
|
|
|
return (unsigned int)pixel_width;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
unsigned int iV_GetCountedTextWidth(const char* string, size_t string_length)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
float boundingbox[8];
|
|
|
|
float pixel_width, point_width;
|
|
|
|
|
|
|
|
glcMeasureCountedString(GL_FALSE, string_length, string);
|
|
|
|
if (!glcGetStringMetric(GLC_BOUNDS, boundingbox))
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "Couldn't retrieve a bounding box for the string \"%s\" of length %u",
|
|
|
|
string, (unsigned int)string_length);
|
2007-10-01 12:45:49 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
point_width = getGLCPointWidth(boundingbox);
|
|
|
|
pixel_width = getGLCPointToPixel(point_width);
|
|
|
|
return (unsigned int)pixel_width;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
unsigned int iV_GetTextHeight(const char* string)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
float boundingbox[8];
|
|
|
|
float pixel_height, point_height;
|
|
|
|
|
|
|
|
glcMeasureString(GL_FALSE, string);
|
|
|
|
if (!glcGetStringMetric(GLC_BOUNDS, boundingbox))
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "Couldn't retrieve a bounding box for the string \"%s\"", string);
|
2007-10-01 12:45:49 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
point_height = getGLCPointHeight(boundingbox);
|
|
|
|
pixel_height = getGLCPointToPixel(point_height);
|
|
|
|
return (unsigned int)pixel_height;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
unsigned int iV_GetCharWidth(uint32_t charCode)
|
|
|
|
{
|
|
|
|
float boundingbox[8];
|
|
|
|
float pixel_width, point_width;
|
|
|
|
|
|
|
|
if (!glcGetCharMetric(charCode, GLC_BOUNDS, boundingbox))
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "Couldn't retrieve a bounding box for the character code %u", charCode);
|
2007-10-01 12:45:49 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
point_width = getGLCPointWidth(boundingbox);
|
|
|
|
pixel_width = getGLCPointToPixel(point_width);
|
|
|
|
return (unsigned int)pixel_width;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
int iV_GetTextLineSize()
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
float boundingbox[8];
|
|
|
|
float pixel_height, point_height;
|
|
|
|
|
|
|
|
if (!glcGetMaxCharMetric(GLC_BOUNDS, boundingbox))
|
2007-07-30 09:42:37 -07:00
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "Couldn't retrieve a bounding box for the character");
|
2007-10-01 12:45:49 -07:00
|
|
|
return 0;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
point_height = getGLCPointHeight(boundingbox);
|
|
|
|
pixel_height = getGLCPointToPixel(point_height);
|
|
|
|
return (unsigned int)pixel_height;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2008-04-05 08:34:55 -07:00
|
|
|
static float iV_GetMaxCharBaseY(void)
|
2007-10-01 12:45:49 -07:00
|
|
|
{
|
|
|
|
float base_line[4]; // [ xl yl xr yr ]
|
|
|
|
|
|
|
|
if (!glcGetMaxCharMetric(GLC_BASELINE, base_line))
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "Couldn't retrieve the baseline for the character");
|
2007-10-01 12:45:49 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base_line[1];
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
int iV_GetTextAboveBase(void)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
float point_base_y = iV_GetMaxCharBaseY();
|
|
|
|
float point_top_y;
|
|
|
|
float boundingbox[8];
|
|
|
|
float pixel_height, point_height;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
if (!glcGetMaxCharMetric(GLC_BOUNDS, boundingbox))
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "Couldn't retrieve a bounding box for the character");
|
2007-07-30 09:42:37 -07:00
|
|
|
return 0;
|
2007-10-01 12:45:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
point_top_y = boundingbox[7];
|
|
|
|
point_height = point_base_y - point_top_y;
|
|
|
|
pixel_height = getGLCPointToPixel(point_height);
|
|
|
|
return (int)pixel_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iV_GetTextBelowBase(void)
|
|
|
|
{
|
|
|
|
float point_base_y = iV_GetMaxCharBaseY();
|
|
|
|
float point_bottom_y;
|
|
|
|
float boundingbox[8];
|
|
|
|
float pixel_height, point_height;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
if (!glcGetMaxCharMetric(GLC_BOUNDS, boundingbox))
|
|
|
|
{
|
2008-12-12 08:35:05 -08:00
|
|
|
debug(LOG_ERROR, "Couldn't retrieve a bounding box for the character");
|
2007-10-01 12:45:49 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
point_bottom_y = boundingbox[1];
|
|
|
|
point_height = point_bottom_y - point_base_y;
|
|
|
|
pixel_height = getGLCPointToPixel(point_height);
|
|
|
|
return (int)pixel_height;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-12-09 08:09:23 -08:00
|
|
|
void iV_SetTextColour(PIELIGHT colour)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-12-09 08:09:23 -08:00
|
|
|
font_colour[0] = colour.byte.r / 255.0f;
|
|
|
|
font_colour[1] = colour.byte.g / 255.0f;
|
|
|
|
font_colour[2] = colour.byte.b / 255.0f;
|
|
|
|
font_colour[3] = colour.byte.a / 255.0f;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2008-02-10 07:25:20 -08:00
|
|
|
/** Draws formatted text with word wrap, long word splitting, embedded newlines
|
|
|
|
* (uses '@' rather than '\n') and colour toggle mode ('#') which enables or
|
|
|
|
* disables font colouring.
|
|
|
|
*
|
|
|
|
* @param String the string to display.
|
|
|
|
* @param x,y X and Y coordinates of top left of formatted text.
|
|
|
|
* @param width the maximum width of the formatted text (beyond which line
|
|
|
|
* wrapping is used).
|
|
|
|
* @param justify The alignment style to use, which is one of the following:
|
|
|
|
* FTEXT_LEFTJUSTIFY, FTEXT_CENTRE or FTEXT_RIGHTJUSTIFY.
|
|
|
|
* @return the Y coordinate for the next text line.
|
|
|
|
*/
|
|
|
|
int iV_DrawFormattedText(const char* String, UDWORD x, UDWORD y, UDWORD Width, UDWORD Justify)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2009-04-30 14:42:11 -07:00
|
|
|
char FString[256];
|
|
|
|
char FWord[256];
|
2007-07-30 10:03:02 -07:00
|
|
|
int i;
|
2007-06-28 10:47:08 -07:00
|
|
|
int jx = x; // Default to left justify.
|
|
|
|
int jy = y;
|
2007-01-04 10:41:24 -08:00
|
|
|
UDWORD WWidth;
|
2007-06-28 10:47:08 -07:00
|
|
|
int TWidth;
|
2007-07-30 10:03:02 -07:00
|
|
|
const char* curChar = String;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-07-30 10:03:02 -07:00
|
|
|
while (*curChar != 0)
|
|
|
|
{
|
2007-08-01 13:50:27 -07:00
|
|
|
bool GotSpace = false;
|
|
|
|
bool NewLine = false;
|
|
|
|
|
2007-08-01 13:17:23 -07:00
|
|
|
// Reset text draw buffer
|
2007-06-28 10:47:08 -07:00
|
|
|
FString[0] = 0;
|
|
|
|
|
2007-08-01 09:57:41 -07:00
|
|
|
WWidth = 0;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// Parse through the string, adding words until width is achieved.
|
2007-08-01 13:50:27 -07:00
|
|
|
while (*curChar != 0 && WWidth < Width && !NewLine)
|
2007-07-30 10:03:02 -07:00
|
|
|
{
|
2007-08-01 13:50:27 -07:00
|
|
|
const char* startOfWord = curChar;
|
2007-10-01 12:45:49 -07:00
|
|
|
const unsigned int FStringWidth = iV_GetTextWidth(FString);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// Get the next word.
|
2007-08-01 11:26:56 -07:00
|
|
|
i = 0;
|
2007-08-01 13:50:27 -07:00
|
|
|
for (; *curChar != 0
|
|
|
|
&& *curChar != ASCII_SPACE
|
2009-05-06 13:24:40 -07:00
|
|
|
&& *curChar != ASCII_NEWLINE
|
|
|
|
&& *curChar != '\n';
|
2007-08-01 13:50:27 -07:00
|
|
|
++i, ++curChar)
|
2007-07-30 10:03:02 -07:00
|
|
|
{
|
2007-08-01 11:26:56 -07:00
|
|
|
if (*curChar == ASCII_COLOURMODE) // If it's a colour mode toggle char then just add it to the word.
|
2007-07-30 10:03:02 -07:00
|
|
|
{
|
|
|
|
FWord[i] = *curChar;
|
2007-08-01 13:17:23 -07:00
|
|
|
|
|
|
|
// this character won't be drawn so don't deal with its width
|
|
|
|
continue;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
2007-08-01 13:17:23 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
// Update this line's pixel width.
|
|
|
|
WWidth = FStringWidth + iV_GetCountedTextWidth(FWord, i + 1);
|
2007-08-01 13:17:23 -07:00
|
|
|
|
|
|
|
// If this word doesn't fit on the current line then break out
|
|
|
|
if (WWidth > Width)
|
2007-10-26 16:29:45 -07:00
|
|
|
{
|
2007-08-01 13:17:23 -07:00
|
|
|
break;
|
2007-10-26 16:29:45 -07:00
|
|
|
}
|
2007-08-01 13:17:23 -07:00
|
|
|
|
|
|
|
// If width ok then add this character to the current word.
|
|
|
|
FWord[i] = *curChar;
|
2007-08-01 11:26:56 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-08-01 11:26:56 -07:00
|
|
|
// Don't forget the space.
|
2007-08-01 13:50:27 -07:00
|
|
|
if (*curChar == ASCII_SPACE)
|
2007-07-30 10:03:02 -07:00
|
|
|
{
|
2007-10-27 12:00:55 -07:00
|
|
|
// Should be a space below, not '-', but need to work around bug in QuesoGLC
|
|
|
|
// which was fixed in CVS snapshot as of 2007/10/26, same day as I reported it :) - Per
|
|
|
|
WWidth += iV_GetCharWidth('-');
|
2007-08-01 11:26:56 -07:00
|
|
|
if (WWidth <= Width)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
FWord[i] = ' ';
|
2007-07-30 10:03:02 -07:00
|
|
|
++i;
|
|
|
|
++curChar;
|
2007-08-01 13:50:27 -07:00
|
|
|
GotSpace = true;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
2007-08-01 13:50:27 -07:00
|
|
|
// Check for new line character.
|
2009-05-06 13:24:40 -07:00
|
|
|
else if (*curChar == ASCII_NEWLINE
|
|
|
|
|| *curChar == '\n')
|
2007-08-01 13:50:27 -07:00
|
|
|
{
|
|
|
|
NewLine = true;
|
|
|
|
++curChar;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-08-01 13:50:27 -07:00
|
|
|
// If we've passed a space on this line and the word goes past the
|
|
|
|
// maximum width and this isn't caused by the appended space then
|
|
|
|
// rewind to the start of this word and finish this line.
|
2007-08-01 13:17:23 -07:00
|
|
|
if (GotSpace
|
2007-08-01 13:50:27 -07:00
|
|
|
&& WWidth > Width
|
|
|
|
&& FWord[i - 1] != ' ')
|
2007-08-01 11:26:56 -07:00
|
|
|
{
|
2007-08-01 13:50:27 -07:00
|
|
|
// Skip back to the beginning of this
|
|
|
|
// word and draw it on the next line
|
|
|
|
curChar = startOfWord;
|
|
|
|
break;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Terminate the word.
|
|
|
|
FWord[i] = 0;
|
|
|
|
|
|
|
|
// And add it to the output string.
|
2008-05-25 06:46:49 -07:00
|
|
|
sstrcat(FString, FWord);
|
2007-08-01 11:26:56 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
|
2007-08-01 09:57:41 -07:00
|
|
|
// Remove trailing spaces, useful when doing center alignment.
|
|
|
|
{
|
2007-11-25 13:43:16 -08:00
|
|
|
// Find the string length (the "minus one" part
|
|
|
|
// guarantees that we get the length of the string, not
|
|
|
|
// the buffer size required to contain it).
|
|
|
|
size_t len = strnlen1(FString, sizeof(FString)) - 1;
|
|
|
|
|
|
|
|
for (; len != 0; --len)
|
|
|
|
{
|
|
|
|
// As soon as we encounter a non-space character, break out
|
|
|
|
if (FString[len] != ASCII_SPACE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Cut off the current space character from the string
|
|
|
|
FString[len] = '\0';
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TWidth = iV_GetTextWidth(FString);
|
|
|
|
|
|
|
|
// Do justify.
|
2007-08-01 11:26:56 -07:00
|
|
|
switch (Justify)
|
2007-08-01 09:57:41 -07:00
|
|
|
{
|
|
|
|
case FTEXT_CENTRE:
|
2007-08-01 11:26:56 -07:00
|
|
|
jx = x + (Width - TWidth) / 2;
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
|
2007-08-01 09:57:41 -07:00
|
|
|
case FTEXT_RIGHTJUSTIFY:
|
2007-08-01 11:26:56 -07:00
|
|
|
jx = x + Width - TWidth;
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
|
2007-08-01 09:57:41 -07:00
|
|
|
case FTEXT_LEFTJUSTIFY:
|
2007-06-28 10:47:08 -07:00
|
|
|
jx = x;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw the text.
|
2007-10-01 12:45:49 -07:00
|
|
|
//iV_SetTextSize(12.f);
|
2007-08-03 06:14:34 -07:00
|
|
|
iV_DrawText(FString, jx, jy);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// and move down a line.
|
|
|
|
jy += iV_GetTextLineSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
return jy;
|
|
|
|
}
|
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
void iV_DrawTextRotated(const char* string, float XPos, float YPos, float rotation)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-10-27 12:20:25 -07:00
|
|
|
GLint matrix_mode = 0;
|
|
|
|
|
2008-03-21 07:34:30 -07:00
|
|
|
pie_SetTexturePage(TEXPAGE_FONT);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-27 12:20:25 -07:00
|
|
|
glGetIntegerv(GL_MATRIX_MODE, &matrix_mode);
|
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
2008-02-10 07:06:23 -08:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
2007-09-25 13:40:56 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
if (rotation != 0.f)
|
2007-10-26 16:25:32 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
rotation = 360.f - rotation;
|
2007-10-26 16:25:32 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
glTranslatef(XPos, YPos, 0.f);
|
|
|
|
glRotatef(180.f, 1.f, 0.f, 0.f);
|
|
|
|
glRotatef(rotation, 0.f, 0.f, 1.f);
|
|
|
|
glScalef(font_size, font_size, 0.f);
|
2007-08-01 11:59:51 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
glColor4fv(font_colour);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
glFrontFace(GL_CW);
|
|
|
|
glcRenderString(string);
|
|
|
|
glFrontFace(GL_CCW);
|
2007-08-01 09:57:41 -07:00
|
|
|
|
2008-02-10 07:06:23 -08:00
|
|
|
glPopMatrix();
|
2007-10-27 12:20:25 -07:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(matrix_mode);
|
2007-08-01 11:59:51 -07:00
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
// Reset the current model view matrix
|
2007-08-03 04:57:16 -07:00
|
|
|
glLoadIdentity();
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2009-04-30 14:56:04 -07:00
|
|
|
static void iV_DrawTextRotatedFv(float x, float y, float rotation, const char* format, va_list ap)
|
2007-12-16 07:47:55 -08:00
|
|
|
{
|
2008-09-05 12:38:22 -07:00
|
|
|
va_list aq;
|
|
|
|
size_t size;
|
|
|
|
char* str;
|
|
|
|
|
|
|
|
/* Required because we're using the va_list ap twice otherwise, which
|
|
|
|
* results in undefined behaviour. See stdarg(3) for details.
|
|
|
|
*/
|
|
|
|
va_copy(aq, ap);
|
2007-12-16 07:47:55 -08:00
|
|
|
|
|
|
|
// Allocate a buffer large enough to hold our string on the stack
|
2008-09-05 12:38:22 -07:00
|
|
|
size = vsnprintf(NULL, 0, format, ap);
|
|
|
|
str = alloca(size + 1);
|
2007-12-16 07:47:55 -08:00
|
|
|
|
|
|
|
// Print into our newly created string buffer
|
2008-09-05 12:38:22 -07:00
|
|
|
vsprintf(str, format, aq);
|
|
|
|
|
|
|
|
va_end(aq);
|
2007-12-16 07:47:55 -08:00
|
|
|
|
|
|
|
// Draw the produced string to the screen at the given position and rotation
|
|
|
|
iV_DrawTextRotated(str, x, y, rotation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void iV_DrawTextF(float x, float y, const char* format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2008-02-25 13:58:35 -08:00
|
|
|
|
2007-12-16 07:47:55 -08:00
|
|
|
va_start(ap, format);
|
2009-04-30 14:56:04 -07:00
|
|
|
iV_DrawTextRotatedFv(x, y, 0.f, format, ap);
|
2007-12-16 07:47:55 -08:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2007-10-01 12:45:49 -07:00
|
|
|
void iV_SetTextSize(float size)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-10-01 12:45:49 -07:00
|
|
|
font_size = size;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|