Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

font_renderer Class Reference

renderer implementation specifically designed for font files. More...

#include <frenderer.h>

Inheritance diagram for font_renderer:

Inheritance graph
[legend]
Collaboration diagram for font_renderer:

Collaboration graph
[legend]
List of all members.

Public Methods

 font_renderer (bool use_original_colors=false) throw ()
 font_renderer constructor

virtual ~font_renderer () throw ()
virtual bool wait (int ms) throw ()
 wait for some time

bool set_color (int c) throw ()
 change the programmable color of the font.

bool draw_string_centered (const std::string &str, char *buffer, const point &size, int y, int xmin, int width, int offset) const throw (std::exception)
 draw a centered and possibly using multiple lines string.

bool draw_string_absolute (const std::string &str, char *buffer, const point &size, int x, int y) const throw (std::exception)
 draw a string at an absolute position.

int get_frame () const throw ()
virtual bool init_frame (const point &size) throw (std::exception)
 start of animation output

virtual char * lock_frame (int frame) throw (std::exception)
 lock a frame buffer

virtual bool unlock_frame () throw ()
 unlock a frame buffer

virtual bool flip_frame () throw ()
 flip a frame buffer

virtual bool set_palette (const palette &pal) throw ()
 set a new palette

virtual bool start_decode (const std::string &fname, int version, int nbframes) throw ()
 start of animation output

virtual sound_rendererget_sound_renderer () throw (std::exception)
 request for a sound_renderer

virtual bool save_current () throw ()
 debugging function : do not use


Protected Methods

virtual void save (int frame=-1)
int char_width (int c) const throw (std::exception)
 get the width of a character.

int string_width (const std::string &str) const throw (std::exception)
 get the width of a string.

int char_height (int c) const throw (std::exception)
 get the height of a character.

int string_height (const std::string &str) const throw (std::exception)
 get the height of a string.

int draw_char (char *buffer, const point &size, int x, int y, int c) const throw (std::exception)
 draw a character in the given frame buffer.

void draw_substring (const std::string &str, char *buffer, const point &size, int x, int y) const throw (std::exception)
 draw a string in the given frame buffer.

const std::string & get_filename () const throw ()
int get_nbframes () const throw ()
int get_width () const throw ()
int get_height () const throw ()
const palettepal () const throw ()
const char * data () const throw ()
void clean () throw ()
 memory cleanup (deletes frame buffer)

void set_frame (int f) throw ()

Private Attributes

int _nb_frames
 The number of frames in the font.

int _color
 A color parameter used for font printing.

bool _original
 flag for color selection

std::vector< std::pair< int,
int > > 
_sizes
 array that contains the size of the different frames (i.e. characters) of the font.

std::vector< char * > _chars
 array of the font data.


Detailed Description

renderer implementation specifically designed for font files.

This class is a valid renderer implementation. The frames are kept in memory, as bitmap representing characters, so that they can be rendered again in another frame as strings.

This class also contains some functions useful for printing strings. This is used to show subtitles and more generally texts in animations.

Todo:
update the mehod to use the blitter class, instead of direct pointers.

Definition at line 54 of file frenderer.h.


Constructor & Destructor Documentation

font_renderer::font_renderer bool    use_original_colors = false throw ()
 

font_renderer constructor

Parameters:
use_original_colors  flag to indicate if the font use it's own color, or if the base color are set at runtime.

Definition at line 29 of file frenderer.cpp.

font_renderer::~font_renderer   throw () [virtual]
 

Definition at line 33 of file frenderer.cpp.


Member Function Documentation

int font_renderer::char_height int    c const throw (std::exception) [protected]
 

get the height of a character.

Parameters:
c  the character we want the height from.
Returns:
the height of the character

Definition at line 53 of file frenderer.cpp.

int font_renderer::char_width int    c const throw (std::exception) [protected]
 

get the width of a character.

Parameters:
c  the character we want the width from.
Returns:
the width of the character

Definition at line 48 of file frenderer.cpp.

void base_renderer::clean   throw () [protected, inherited]
 

memory cleanup (deletes frame buffer)

Reimplemented in window_renderer.

Definition at line 25 of file brenderer.cpp.

const char* base_renderer::data   const throw () [inline, protected, inherited]
 

Definition at line 54 of file brenderer.h.

References base_renderer::_data.

Referenced by save().

int font_renderer::draw_char char *    buffer,
const point   size,
int    x,
int    y,
int    c
const throw (std::exception) [protected]
 

draw a character in the given frame buffer.

Parameters:
buffer  the frame buffer to draw into.
size  the size of the frame buffer.
x  the horizontal position of the topleft corner of the character.
y  the vertical position of the topleft corner of the character.
c  the character to draw.

Bug:
This method does not clip. This is not really a bug, as it should always be correctly called, but some asserts would be welcome.

Returns:
the width of the character

Definition at line 76 of file frenderer.cpp.

bool font_renderer::draw_string_absolute const std::string &    str,
char *    buffer,
const point   size,
int    x,
int    y
const throw (std::exception)
 

draw a string at an absolute position.

Parameters:
str  the string to draw.
buffer  the frame buffer to draw into.
size  the size of the frame buffer.
x  the horizontal position of the topleft corner of the string.
y  the vertical position of the topleft corner of the string. This position may be changed if it is too low to be correctly drawn.
Returns:
true if everything went fine, false otherwise

Definition at line 137 of file frenderer.cpp.

Referenced by player::handleTextResource().

bool font_renderer::draw_string_centered const std::string &    str,
char *    buffer,
const point   size,
int    y,
int    xmin,
int    width,
int    offset
const throw (std::exception)
 

draw a centered and possibly using multiple lines string.

This method performs calculation of the string size before choosing where to draw it. As I still not have figured out exactly what is the meaning of the fields in the TRES chunck, the real meaning of the parameters can be quite difficult to understand.

Remarks:
The current implementation is incorrect in the sense that it does not conform to the original game.

Todo:
rewrite and rethink this to better match the original implementation.
Parameters:
str  the string to draw.
buffer  the frame buffer to draw into.
size  the size of the frame buffer.
y  the vertical position of the topleft corner of the string. This position may be changed if it is too low to be correctly drawn.
xmin  the minimum horizontal position of the topleft corner of the string.
width  the maximum width of the string. If the string is too long, it will wrap.
offset  offset to give to the horizontal position.
Returns:
true if everything went fine, false otherwise

Definition at line 142 of file frenderer.cpp.

References split().

Referenced by player::handleTextResource().

void font_renderer::draw_substring const std::string &    str,
char *    buffer,
const point   size,
int    x,
int    y
const throw (std::exception) [protected]
 

draw a string in the given frame buffer.

Parameters:
str  the string to draw.
buffer  the frame buffer to draw into.
size  the size of the frame buffer.
x  the horizontal position of the topleft corner of the string.
y  the vertical position of the topleft corner of the string.
Bug:
This method does not clip. This is not really a bug, as it should always be correctly called, but some asserts would be welcome.

Definition at line 128 of file frenderer.cpp.

bool base_renderer::flip_frame   throw () [virtual, inherited]
 

flip a frame buffer

This is called by the animation player when the current frame should be shown.

Returns:
true if everything went fine, false otherwise

Implements renderer.

Definition at line 65 of file brenderer.cpp.

const std::string& base_renderer::get_filename   const throw () [inline, protected, inherited]
 

Definition at line 49 of file brenderer.h.

References base_renderer::_fname.

int base_renderer::get_frame   const throw () [inline, inherited]
 

Definition at line 58 of file brenderer.h.

References base_renderer::_frame.

int base_renderer::get_height   const throw () [inline, protected, inherited]
 

Definition at line 52 of file brenderer.h.

References base_renderer::_height.

Referenced by save().

int base_renderer::get_nbframes   const throw () [inline, protected, inherited]
 

Definition at line 50 of file brenderer.h.

References base_renderer::_nbframes.

virtual sound_renderer* base_renderer::get_sound_renderer   throw (std::exception) [inline, virtual, inherited]
 

request for a sound_renderer

This is called by the animation player when sound output is required by the animation.

Returns:
a valid pointer to an uninitialized sound_renderer instance, or null if none is available.

Implements renderer.

Reimplemented in window_renderer.

Definition at line 68 of file brenderer.h.

int base_renderer::get_width   const throw () [inline, protected, inherited]
 

Definition at line 51 of file brenderer.h.

References base_renderer::_width.

Referenced by save().

bool base_renderer::init_frame const point   size throw (std::exception) [virtual, inherited]
 

start of animation output

This is called by the animation player when the frame size is changing.

Parameters:
size  new size of the frames.
Returns:
true if everything went fine, false otherwise

Implements renderer.

Reimplemented in bitmap_renderer, bitmap_file_renderer, and window_renderer.

Definition at line 45 of file brenderer.cpp.

Referenced by bitmap_renderer::init_frame().

char * base_renderer::lock_frame int    frame throw (std::exception) [virtual, inherited]
 

lock a frame buffer

This is called by the animation player when a frame is going to be decoded.

Parameters:
frame  the frame number.
Returns:
a pointer to the frame buffer to output data to.

Implements renderer.

Definition at line 55 of file brenderer.cpp.

const palette& base_renderer::pal   const throw () [inline, protected, inherited]
 

Definition at line 53 of file brenderer.h.

void font_renderer::save int    frame = -1 [protected, virtual]
 

Implements base_renderer.

Definition at line 39 of file frenderer.cpp.

References _chars, _nb_frames, _sizes, base_renderer::data(), base_renderer::get_height(), and base_renderer::get_width().

virtual bool renderer::save_current   throw () [inline, virtual, inherited]
 

debugging function : do not use

Returns:
true if everything went fine, false otherwise

Reimplemented in bitmap_file_renderer.

Definition at line 151 of file renderer.h.

bool font_renderer::set_color int    c throw () [inline]
 

change the programmable color of the font.

Parameters:
c  the new color to use.
Returns:
true if everything went fine, false otherwise

Definition at line 130 of file frenderer.h.

References _color.

Referenced by player::handleTextResource().

void base_renderer::set_frame int    f throw () [inline, protected, inherited]
 

Definition at line 56 of file brenderer.h.

References base_renderer::_frame.

bool base_renderer::set_palette const palette   pal throw () [virtual, inherited]
 

set a new palette

This is called by the animation player when the palette is changing.

Parameters:
pal  new palette.
Returns:
true if everything went fine, false otherwise

Implements renderer.

Reimplemented in bitmap_renderer.

Definition at line 70 of file brenderer.cpp.

Referenced by bitmap_renderer::set_palette().

virtual bool base_renderer::start_decode const std::string &    fname,
int    version,
int    nbframes
throw () [inline, virtual, inherited]
 

start of animation output

This is called by the animation player when output is going to start.

Parameters:
fname  name of the animation being played.
version  version number of the animation
nbframes  total number of frames of the animation.
Returns:
true if initialisation was ok, false otherwise

Implements renderer.

Definition at line 67 of file brenderer.h.

References base_renderer::_fname, and base_renderer::_nbframes.

int font_renderer::string_height const std::string &    str const throw (std::exception) [protected]
 

get the height of a string.

Parameters:
str  the string we want the height from.
Returns:
the complete height of the string

Definition at line 67 of file frenderer.cpp.

int font_renderer::string_width const std::string &    str const throw (std::exception) [protected]
 

get the width of a string.

Parameters:
str  the string we want the width from.
Returns:
the complete width of the string

Definition at line 58 of file frenderer.cpp.

bool base_renderer::unlock_frame   throw () [virtual, inherited]
 

unlock a frame buffer

This is called by the animation player when a frame has been decoded.

Returns:
true if everything went fine, false otherwise

Implements renderer.

Definition at line 61 of file brenderer.cpp.

virtual bool font_renderer::wait int    ms throw () [inline, virtual]
 

wait for some time

This is called by the animation player when the animation should stay idle.

Parameters:
ms  number of millisecond to wait.
Returns:
true if everything went fine, false otherwise

Implements renderer.

Definition at line 68 of file frenderer.h.


Member Data Documentation

std::vector<char *> font_renderer::_chars [private]
 

array of the font data.

Definition at line 60 of file frenderer.h.

Referenced by save().

int font_renderer::_color [private]
 

A color parameter used for font printing.

Definition at line 57 of file frenderer.h.

Referenced by set_color().

int font_renderer::_nb_frames [private]
 

The number of frames in the font.

Definition at line 56 of file frenderer.h.

Referenced by save().

bool font_renderer::_original [private]
 

flag for color selection

Definition at line 58 of file frenderer.h.

std::vector<std::pair<int, int> > font_renderer::_sizes [private]
 

array that contains the size of the different frames (i.e. characters) of the font.

Definition at line 59 of file frenderer.h.

Referenced by save().


The documentation for this class was generated from the following files:
Generated on Fri Aug 9 22:54:32 2002 for san_player by doxygen1.2.16