Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

lib.h File Reference


Detailed Description

All sorts of helper functions that don't belong anywhere else go in here.

There are functions for interfacing with bmovl, rendering text, controlling timers and a bunch of other stuff.

#include <sys/poll.h>
#include <fcntl.h>
#include "bitmap.h"

Go to the source code of this file.

Compounds

class  Readfd
 Class for doing secure, non-blocking, line-buffered reads from any file descriptor. More...


Interface to the bmovl protocol

void blit (const Bitmap &bitmap, int xpos, int ypos, int alpha=0, int clear=0)
 Send a bitmap to the screen.

void set_alpha (int width, int height, int xpos, int ypos, int alpha)
 Set the alpha value for a rectangle to a value between -255 and 255.

void clear (int width, int height, int xpos, int ypos)
 Clear an area.

void clear ()
 Clear the whole screen.


Bitmap generating functions

void text (RGBA &bitmap, int width, char *str, int size=0, char *align="left")
 The basic routine for rendering text.

void text_trimmed (RGBA &bitmap, int width, int height, char *str, int size=0, char *align="left")
 Works like text() but guarantees that the text will be no bigger than width x height, and that the width and height will be multiples of 2.

void text_constsize (RGBA &bitmap, char *str, int size=0, char *align="left")
 Works like text() but puts the text into a pre-allocated bitmap.

Bitmapload_image (const char *filename)
 Loads an image file from any format supported by SDL_image or Imlib2 (jpg, png, gif, etc.) and returns the type of Bitmap that best fits its color space.

Bitmapload_image_from_mem (const char *ptr, size_t len)
 Loads an image from a pointer to memory instead of a filename.


Timing related functions

void settimer_ms (int milliseconds)
 Starts a one-shot itimer.

int gettimer_ms ()
 Gets the value of an itimer.

void msleep (int msec)
 Sleeps for the requested number of milliseconds.

int runtime ()
 Returns the number of milliseconds that have passed since it was first called (which means that the first call will always return 0).


Misc functions

int tcp_connect (const char *host, short port)
 Establishes a tcp socket connection to the given host/port.

void msg (int level, char *format,...) __attribute__((format(printf
 Prints a message to stderr, but only if level is equal to or less than the global variable verbosity.

int scalefont (int percent)
 Returns a size in pixels representing approximately how tall the font will be if it takes up percent percent of the screen.

int center (int s, int S)
 Simple algorithm for centering something with the size s inside a larger object with the size S.

int inrange (int num, int lo, int hi)
 Bounds-checks num against the lo and hi boundaries.


Defines

#define __attribute__(x)


Function Documentation

void blit const Bitmap bitmap,
int  xpos,
int  ypos,
int  alpha = 0,
int  clear = 0
 

Send a bitmap to the screen.

It's ok to supply a bitmap that's partially or completely out out of bounds, it'll just be cropped before being shown.

int center int  s,
int  S
 

Simple algorithm for centering something with the size s inside a larger object with the size S.

Use it for the sake of clarity.

int gettimer_ms  ) 
 

Gets the value of an itimer.

See gettitimer(2) for more info.

Bitmap* load_image const char *  filename  ) 
 

Loads an image file from any format supported by SDL_image or Imlib2 (jpg, png, gif, etc.) and returns the type of Bitmap that best fits its color space.

Returns NULL and prints a warning if loading fails

void msg int  level,
char *  format,
... 
 

Prints a message to stderr, but only if level is equal to or less than the global variable verbosity.

1=normal, 2=verbose, 3=debug.

void msleep int  msec  ) 
 

Sleeps for the requested number of milliseconds.

Returns immediately if msec is 0 or negative.

int runtime  ) 
 

Returns the number of milliseconds that have passed since it was first called (which means that the first call will always return 0).

On broken hardware this timer may go backwards some times.

int scalefont int  percent  ) 
 

Returns a size in pixels representing approximately how tall the font will be if it takes up percent percent of the screen.

This of course depends on the font, so it should only be used as an approximate value.

void set_alpha int  width,
int  height,
int  xpos,
int  ypos,
int  alpha
 

Set the alpha value for a rectangle to a value between -255 and 255.

255 makes everything opaque. -255 makes everything transparent. The coordinates don't have to fit in screen boundaries

In bmovl there are two alpha channels: one for the image that can only be set with the alpha pixels in the bitmap supplied to blit() and another one that can be set with the alpha parameter to blit() or set_alpha(), mostly used to set the alpha of a large chunk. The two alpha channels will be added together and then truncated so the final result is between 0 and 255.

void settimer_ms int  milliseconds  ) 
 

Starts a one-shot itimer.

See setitimer(2) for more info.

void text RGBA bitmap,
int  width,
char *  str,
int  size = 0,
char *  align = "left"
 

The basic routine for rendering text.

The width parameter specifies in pixels where word wrapping should occur, but the resulting bitmap may be bigger if word wrapping is not possible. A positive size is taken as a percentage of screen width, a negative one is a value in points. If no size is given, the global default is used. This function is usually not used directly, but through one of the text_*() functions.


Generated on Sun Oct 19 17:34:47 2003 for rve by doxygen 1.3.3