File: sdl.h

package info (click to toggle)
ltris 1.0.19-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 3,356 kB
  • ctags: 2,332
  • sloc: ansic: 14,224; sh: 4,211; asm: 1,332; makefile: 537; yacc: 288; sed: 16; perl: 5
file content (158 lines) | stat: -rw-r--r-- 4,647 bytes parent folder | download
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
/***************************************************************************
                          sdl.h  -  description
                             -------------------
    begin                : Thu Apr 20 2000
    copyright            : (C) 2000 by Michael Speck
    email                : kulkanie@gmx.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program 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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef SDL_H
#define SDL_H

#include <SDL.h>

#define BITDEPTH 16

#ifdef __cplusplus
extern "C" {
#endif

// draw region //
#define DEST(p, i, j, k, l) {sdl.d.s = p; sdl.d.r.x = i; sdl.d.r.y = j; sdl.d.r.w = k; sdl.d.r.h = l;}
#define SOURCE(p, i, j) {sdl.s.s = p; sdl.s.r.x = i; sdl.s.r.y = j; sdl.s.r.w = sdl.d.r.w; sdl.s.r.h = sdl.d.r.h;}
#define FULL_DEST(p) {sdl.d.s = p; sdl.d.r.x = 0; sdl.d.r.y = 0; sdl.d.r.w = (p)->w; sdl.d.r.h = (p)->h;}
#define FULL_SOURCE(p) {sdl.s.s = p; sdl.s.r.x = 0; sdl.s.r.y = 0; sdl.s.r.w = sdl.d.r.w; sdl.s.r.h = sdl.d.r.h;}
typedef struct {
    SDL_Surface *s;
    SDL_Rect    r;
} DrawRgn;

// Sdl Surface //
#define SDL_NONFATAL 0x10000000
SDL_Surface* load_surf(char *fname, int f);
SDL_Surface* create_surf(int w, int h, int f);
void free_surf( SDL_Surface **surf );
void lock_surf(SDL_Surface *sur);
void unlock_surf(SDL_Surface *sur);
void blit_surf(void);
void alpha_blit_surf(int alpha);
void fill_surf(int c);
void set_surf_clip( SDL_Surface *surf, int x, int y, int w, int h );
Uint32 set_pixel( SDL_Surface *surf, int x, int y, int pixel );
Uint32 get_pixel( SDL_Surface *surf, int x, int y );
/* draw a shadowed frame and darken contents which starts at cx,cy */
void draw_3dframe( SDL_Surface *surf, int cx, int cy, int w, int h, int border );

// Sdl Font //
enum {
    OPAQUE = 0
};
enum {
    ALIGN_X_LEFT	= (1L<<1),
    ALIGN_X_CENTER	= (1L<<2),
    ALIGN_X_RIGHT	= (1L<<3),
    ALIGN_Y_TOP	    = (1L<<4),
    ALIGN_Y_CENTER	= (1L<<5),
    ALIGN_Y_BOTTOM	= (1L<<6)
};

typedef struct {
    SDL_Surface *pic;
    int         align;
    int         color;
    int         height;
    char        char_width[256];
    int         char_offset[256];
    char        keys[256];
    char        offset;
    char        length;
    //last written rect
    int         save_last;
    int     	last_x;
    int         last_y;
    int	        last_width;
    int	        last_height;
} Font;
Font* load_font(char *fname);
Font* load_fixed_font(char *fname, int off, int len, int w);
void free_font(Font **sfnt);
int  write_text(Font *sfnt, SDL_Surface *dest, int x, int y, char *str, int alpha);
void lock_font(Font *sfnt);
void unlock_font(Font *sfnt);
SDL_Rect last_write_rect(Font *fnt);
int  text_width(Font *fnt, char *str);

/* mouse buttons */
enum {
    LEFT_BUTTON = 1,
    MIDDLE_BUTTON = 2,
    RIGHT_BUTTON = 3,
    WHEEL_UP = 4,
    WHEEL_DOWN = 5,
    BUTTON_COUNT
};

/* video modes */
typedef struct {
    int id;
    char name[64];
    int width, height, depth;
    int flags;
    int ok;
} Video_Mode;
/* Sdl */
enum {
    RECT_LIMIT = 200,
    FADE_DEF_TIME = 500,
    FADE_IN = 0,
    FADE_OUT = 1
};
typedef struct {
    SDL_Surface *screen;
    DrawRgn     d, s;
    int         rect_count;
    SDL_Rect    rect[RECT_LIMIT];
    int         fade;
} Sdl;
void init_sdl( int f );
void quit_sdl();
Video_Mode def_video_mode();
Video_Mode std_video_mode( int id );
Video_Mode video_mode( int width, int height, int depth, int flags );
Video_Mode* cur_video_mode();
char** get_mode_names( int *count );
int  set_video_mode( Video_Mode mode );
void hardware_cap();
void refresh_screen( int x, int y, int w, int h );
void refresh_rects();
void add_refresh_rect(int x, int y, int w, int h);
int  wait_for_key();
void wait_for_click();
void lock_screen();
void unlock_screen();
void flip_screen();
void fade_screen( int type, int ms );
void take_screenshot( int i );

/* cursor */
/* creates cursor */
SDL_Cursor* create_cursor( int width, int height, int hot_x, int hot_y, char *source );

/* timer */
int get_time();
void reset_timer();

#ifdef __cplusplus
};
#endif

#endif