ScummVM API documentation
text_sprites.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_INCLUDED_TEXT_SPRITES_H
28 #define ICB_INCLUDED_TEXT_SPRITES_H
29 
30 #include "engines/icb/p4_generic.h"
31 #include "engines/icb/common/px_bitmap.h"
32 #include "engines/icb/common/px_game_object.h"
33 #include "engines/icb/debug.h"
34 
35 namespace ICB {
36 
37 // PC limit
38 #define TEXT_SPRITE_SIZE (300 * 150 * 4)
39 
40 #define TS_NON_SPOKEN_LINE '&'
41 #define TS_SPOKEN_LINE '*'
42 #define TS_LINENO_OPEN '{'
43 #define TS_LINENO_CLOSE '}'
44 
45 // This pointer can be set to force a different RGB to be used for speech text. Remora uses
46 // this to do text colouring.
47 extern _rgb *psTempSpeechColour;
48 
49 // return codes for text sprite functions
50 enum _TSrtn {
51  TS_OK, // it worked
52  TS_ILLEGAL_SPACING, // line contains leading/trailing spaces or extra spaces between words
53  TS_TOO_MANY_LINES, // exceeded lineInfo array while analysing sentence
54  TS_INVALID_FONT, // the resource id passed is not a valid font resource
55  TS_OUT_OF_MEM, // couldn't allocate memory for text sprite
56  TS_ILLEGAL_PIN, // unrecognised value of '_pin_position'
57  TS_ILLEGAL_MARGIN // sprite cannot fit within given screen margin
58 };
59 
60 // "Pin position" is the point on the sprite that we want to fix to the screen coordinates.
61 // eg. Speech text traditionally uses "PIN_AT_CENTRE_OF_BASE". That is, for calculating the
62 // required render coordinates, we will specify the coordinates of a point just above the
63 // talker's head, and then whatever the width and height of the text sprite, the render
64 // coordinates will be calculated such that the centre of the text sprite's base will be
65 // exactly at the specified coordinates - ie. text is centred just above the talkers head.
66 // The other pin positions may be used for pointer text, data readouts on PPC, or alternate
67 // positions for speech text, etc.
68 enum _pin_position {
69  PIN_AT_CENTRE,
70  PIN_AT_CENTRE_OF_TOP,
71  PIN_AT_CENTRE_OF_BASE,
72  PIN_AT_CENTRE_OF_LEFT,
73  PIN_AT_CENTRE_OF_RIGHT,
74  PIN_AT_TOP_LEFT,
75  PIN_AT_TOP_RIGHT,
76  PIN_AT_BOTTOM_LEFT,
77  PIN_AT_BOTTOM_RIGHT
78 };
79 
80 // This must now be a multiple of 4!
81 #define MAX_LINES 48 // max character lines in output sprite
82 
83 typedef struct { // info for each line of words in the output text sprite
84  uint16 width; // width of line in pixels
85  uint16 length; // length of line in characters
86 } _textLine;
87 
88 typedef struct { // info describing whole set of lines used in the sprite
89  _textLine line[MAX_LINES];
90  uint8 noOfLines;
91  uint8 m_stopAtLine;
92  uint8 m_bLeftFormatted;
93  uint8 padding;
94 } _lineInfo;
95 
96 // This is the structure that must be filled in before calling MakeTextSprite()
97 // which takes a reference to a structure of this type as it's only parameter
98 typedef struct { // info for each line of words in the output text sprite
99  uint8 *textLine; // null-terminated text sprite (must not contain any leading/tailing/extra spaces
100  const char *fontResource; // name of the font
101  uint32 fontResource_hash; // hash of the font file
102  uint32 maxWidth; // maximum allowed pixel width of text sprite
103  uint32 bitDepth; // 16,24 or 32 bits per pixel (2,3 or 4 bytes)
104  int32 lineSpacing; // no. of pixels to separate lines of characters in the output sprite - negative for overlap
105  int32 charSpacing; // no. of pixels to separate characters along each line - negative for overlap
106  _rgb bodyColour; // colour required for character bodies
107  _rgb borderColour; // colour required for character borders
108  int32 errorChecking; // perform error checking during analysesetence on/off
109 } _TSparams;
110 
111 class text_sprite {
112  // created by routines:
113  uint8 sprite[TEXT_SPRITE_SIZE];
114  uint32 spriteWidth; // width of text sprite
115  uint32 spriteHeight; // height of text sprite
116  uint32 size; // in bytes (= width * height * bit_depth) NOT SURE WE NEED THIS FOR ANYTHING
117  uint32 surfaceId; // The surface we want to eventually draw this sprite on
118  _lineInfo lineInfo; // information about the lines in the text_block
119  _TSparams params;
120 
121  // private functions:
122  _TSrtn BuildTextSprite(int32 stopAtLine = -1, bool8 bRemoraLeftFormatting = FALSE8); // construct the sprite
123  uint32 CharWidth(const uint8 ch, const char *fontRes, uint32 fontRes_hash); // get width of a character
124  void CopyChar(_pxSprite *charPtr, uint8 *spritePtr, uint8 *pal); // copy character into sprite, based on params
125  _TSrtn CheckFontResource(const char *fontRes, uint32 fontRes_hash); // check that it's a valid font resource
126  _pxBitmap *LoadFont(const char *fontRes, uint32 fontRes_hash);
127 
128 public:
129  int32 renderX; // render coordinate
130  int32 renderY;
131 
132  // the usual:
133  text_sprite(); // constructor -- default constructor
134  ~text_sprite(); // destructor
135 
136  // Made this public, so Remora can work out how its formatting will be done.
137  _TSrtn AnalyseSentence(void); // fill in the lineInfo structure
138 
139  // the main routine to create the sprite (added flag to stop AnalyseSentence() getting called if you need to)
140  // Also, you can now tell it to stop short of displaying every line in the text.
141  _TSrtn MakeTextSprite(bool8 analysisAlreadyDone = FALSE8, int32 stopAtLine = -1, bool8 bRemoraLeftFormatting = FALSE8);
142 
143  // the support routine to calculate suitable render coordinates
144  _TSrtn GetRenderCoords(const int32 pinX, // screen x-coord where we want to position the pin
145  const int32 pinY, // y-coord -"-
146  const _pin_position pinPos, // position of pin on text sprite
147  const int32 margin); // margin to keep sprite within edge of screen, or -1 if allowed anywhere
148 
149  uint32 CharHeight(const char *fontRes, uint32 fontRes_hash); // get character height (all the same)
150  _pxSprite *FindChar(uint8 ch, _pxBitmap *charSet); // get pointer to header of required character data in font
151 
152  // the usual set of routines to return required values
153  uint8 *GetSprite(void) {
154  return sprite; // get pointer to text sprite in memory
155  }
156  uint32 GetWidth(void) {
157  return spriteWidth; // get dimensions of text sprite
158  }
159  uint32 GetHeight(void) {
160  return spriteHeight; // -"-
161  }
162  uint32 GetSize(void) {
163  return size; // get byte-length of text sprite data
164  }
165  _lineInfo *GetLineInfo(void) {
166  return &lineInfo; // information about the lines in the text_block
167  }
168  _TSparams *GetParams(void) {
169  return &params; // information about the lines in the text_block
170  }
171  void SetSurface(uint32 sid) { surfaceId = sid; }
172  uint32 GetSurface() const { return surfaceId; }
173 
174  // This a variable stuck way down here on it's little lonesome ?
175  bool8 please_render; // draw yes/no
176 };
177 
178 } // End of namespace ICB
179 
180 #endif // INCLUDED_TEXT_SPRITES_H
Definition: px_common.h:109
Definition: px_bitmap_pc.h:44
Definition: actor.h:32
Definition: px_bitmap_pc.h:51
Definition: text_sprites.h:83
Definition: text_sprites.h:98
Definition: text_sprites.h:111
Definition: text_sprites.h:88