File: sdlgen.h

package info (click to toggle)
tworld 1.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,620 kB
  • ctags: 1,407
  • sloc: ansic: 12,442; perl: 2,465; makefile: 191; sh: 16
file content (175 lines) | stat: -rw-r--r-- 6,990 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* sdlgen.h: The internal shared definitions of the SDL OS/hardware layer.
 * 
 * Copyright (C) 2001-2006 by Brian Raiter, under the GNU General Public
 * License. No warranty. See COPYING for details.
 */

#ifndef	_sdlgen_h_
#define	_sdlgen_h_

#include	"SDL.h"
#include	"../gen.h"
#include	"../oshw.h"

/* Structure to hold the definition of a font.
 */
typedef	struct fontinfo {
    signed char		h;		/* height of each character */
    signed char		w[256];		/* width of each character */
    void	       *memory;		/* memory allocated for the font */
    unsigned char      *bits[256];	/* pointers to each glyph */
} fontinfo;

/* Structure to hold a font's colors.
 */
typedef	struct fontcolors { Uint32 c[3]; } fontcolors;

#define	bkgndcolor(fc)	((fc).c[0])	/* the background color */
#define	halfcolor(fc)	((fc).c[1])	/* the antialiasing color */
#define	textcolor(fc)	((fc).c[2])	/* the main color of the glyphs */

/* Flags to the puttext function.
 */
#define	PT_CENTER	0x0001		/* center the text horizontally */
#define	PT_RIGHT	0x0002		/* right-align the text */
#define	PT_MULTILINE	0x0004		/* span lines & break at whitespace */
#define	PT_UPDATERECT	0x0008		/* return the unused area in rect */
#define	PT_CALCSIZE	0x0010		/* determine area needed for text */
#define	PT_DIM		0x0020		/* draw using the dim text color */
#define	PT_HILIGHT	0x0040		/* draw using the bold text color */

/*
 * Values global to this module. All the globals are placed in here,
 * in order to minimize pollution of the main module's namespace.
 */

typedef	struct oshwglobals
{
    /* 
     * Shared variables.
     */

    short		wtile;		/* width of one tile in pixels */
    short		htile;		/* height of one tile in pixels */
    short		cptile;		/* size of one tile in pixels */
    fontcolors		textclr;	/* color triplet for normal text */
    fontcolors		dimtextclr;	/* color triplet for dim text */
    fontcolors		hilightclr;	/* color triplet for bold text */
    SDL_Surface	       *screen;		/* the display */
    fontinfo		font;		/* the font */

    /* 
     * Shared functions.
     */

    /* Process all pending events. If wait is TRUE and no events are
     * currently pending, the function blocks until an event arrives.
     */
    void (*eventupdatefunc)(int wait);

    /* A callback function, to be called every time a keyboard key is
     * pressed or released. scancode is an SDL key symbol. down is
     * TRUE if the key was pressed or FALSE if it was released.
     */
    void (*keyeventcallbackfunc)(int scancode, int down);

    /* A callback function, to be called when a mouse button is
     * pressed or released. xpos and ypos give the mouse's location.
     * button is the number of the mouse button. down is TRUE if the
     * button was pressed or FALSE if it was released.
     */
    void (*mouseeventcallbackfunc)(int xpos, int ypos, int button, int down);

    /* Given a pixel's coordinates, return an integer identifying the
     * tile on the map view display under that pixel, or -1 if the
     * pixel is not within the map view.
     */
    int (*windowmapposfunc)(int x, int y);

    /* Return a pointer to an image of a cell with the two given
     * tiles. If the top image is transparent, the composite image is
     * created using the overlay buffer. (Thus the caller should be
     * done using the image returned before calling this function
     * again.) timerval should hold the time of the game, for
     * rendering animated cell tiles, or -1 if the game has not
     * started.
     */
    SDL_Surface* (*getcellimagefunc)(SDL_Rect *rect,
				     int top, int bot, int timerval);

    /* Return a pointer to a tile image for the given creature or
     * animation sequence with the specified direction, sub-position,
     * and animation frame.
     */
    SDL_Surface* (*getcreatureimagefunc)(SDL_Rect *rect, int id, int dir,
					 int moving, int frame);

    /* Display a line (or more) of text in the program's font. The
     * text is clipped to area if necessary. If area is taller than
     * the font, the topmost line is used. len specifies the number of
     * characters to render; -1 can be used if text is NUL-terminated.
     * flags is some combination of PT_* flags defined above. When the
     * PT_CALCSIZE flag is set, no drawing is done; instead the w and
     * h fields of area area changed to define the smallest rectangle
     * that encloses the text that would have been rendered. (If
     * PT_MULTILINE is also set, only the h field is changed.) If
     * PT_UPDATERECT is set instead, then the h field is changed, so
     * as to exclude the rectangle that was drawn in.
     */
    void (*puttextfunc)(SDL_Rect *area, char const *text, int len, int flags);

    /* Determine the widths necessary to display the columns of the
     * given table. area specifies an enclosing rectangle for the
     * complete table. The return value is an array of rectangles, one
     * for each column of the table. The rectangles y-coordinates and
     * heights are taken from area, and the x-coordinates and widths
     * are calculated so as to best render the columns of the table in
     * the given space. The caller has the responsibility of freeing
     * the returned array.
     */
    SDL_Rect *(*measuretablefunc)(SDL_Rect const *area,
				  tablespec const *table);

    /* Draw a single row of the given table. cols is an array of
     * rectangles, one for each column. Each rectangle is altered by
     * the function as per puttext's PT_UPDATERECT behavior. row
     * points to an integer indicating the first table entry of the
     * row to display; upon return, this value is updated to point to
     * the first entry following the row. flags can be set to PT_DIM
     * and/or PT_HIGHLIGHT; the values will be applied to every entry
     * in the row.
     */
    int (*drawtablerowfunc)(tablespec const *table, SDL_Rect *cols,
			    int *row, int flags);

} oshwglobals;

/* oshw's structure of globals.
 */
extern oshwglobals sdlg;

/* Some convenience macros for the above functions.
 */
#define eventupdate		(*sdlg.eventupdatefunc)
#define	keyeventcallback	(*sdlg.keyeventcallbackfunc)
#define	mouseeventcallback	(*sdlg.mouseeventcallbackfunc)
#define	windowmappos		(*sdlg.windowmapposfunc)
#define	puttext			(*sdlg.puttextfunc)
#define	measuretable		(*sdlg.measuretablefunc)
#define	drawtablerow		(*sdlg.drawtablerowfunc)
#define	createscroll		(*sdlg.createscrollfunc)
#define	scrollmove		(*sdlg.scrollmovefunc)
#define	getcreatureimage	(*sdlg.getcreatureimagefunc)
#define	getcellimage		(*sdlg.getcellimagefunc)

/* The initialization functions for the various modules.
 */
extern int _sdltimerinitialize(int showhistogram);
extern int _sdlresourceinitialize(void);
extern int _sdltextinitialize(void);
extern int _sdltileinitialize(void);
extern int _sdlinputinitialize(void);
extern int _sdloutputinitialize(int fullscreen);
extern int _sdlsfxinitialize(int silence, int soundbufsize);

#endif