00001
00330 #ifndef _CRTXY_H
00331 #define _CRTXY_H
00332
00333 #include <SDL.h>
00334
00335 #ifdef __cplusplus
00336 extern "C" {
00337 #endif
00338
00346 typedef enum {
00347 XY_FALSE,
00348 XY_TRUE
00349 } XY_bool;
00350
00363 typedef struct XY_bitmap_s {
00364 SDL_Surface * surf;
00365 } XY_bitmap;
00366
00375 typedef Uint32 XY_color;
00376
00387 typedef Sint32 XY_fixed;
00388
00389
00390
00391 #define XY_FIXED_SHIFT 16
00392 #define XY_FIXED_SHIFT_HALF 8
00393 #define XY_FIXED_ONE (1 << XY_FIXED_SHIFT)
00394 #define XY_FIXED_HALF (1 << (XY_FIXED_SHIFT - 1))
00396
00397
00398 #define XY_FIXED_MAX 0x7FFFFFFF
00399 #define XY_FIXED_MIN -(0x80000000)
00400 #define XY_FIXED_NAN XY_FIXED_MAX
00414
00415
00416 #define XY_THIN XY_FIXED_ONE
00421 typedef struct XY_line_s {
00422 XY_fixed x1;
00423 XY_fixed y1;
00424 XY_fixed x2;
00425 XY_fixed y2;
00426 XY_color color;
00427 XY_fixed thickness;
00428 } XY_line;
00429
00433 typedef struct XY_lines_s {
00434 int count;
00435 int max;
00436 XY_line * lines;
00437 } XY_lines;
00438
00442 typedef enum {
00443 XY_INTERSECTION_NONE,
00444 XY_INTERSECTION_INTERSECTING,
00445 XY_INTERSECTION_PARALLEL,
00446 XY_INTERSECTION_COINCIDENT
00447 } XY_intersection;
00448
00459 typedef enum {
00460 XY_OPT_WINDOWED,
00461 XY_OPT_FULLSCREEN_REQUEST,
00462 XY_OPT_FULLSCREEN_REQUIRED
00463 } XY_opt_fullscreen;
00464
00468 typedef enum {
00469 XY_OPT_ALPHA_BLEND,
00470 XY_OPT_ALPHA_FAKE,
00471 XY_OPT_ALPHA_OFF
00472 } XY_opt_alpha;
00473
00477 typedef enum {
00478 XY_OPT_SCALE_BEST,
00479 XY_OPT_SCALE_FAST
00480 } XY_opt_scaling;
00481
00485 typedef struct XY_options_s {
00486 int displayw;
00487 int displayh;
00488 int displaybpp;
00489 XY_opt_fullscreen fullscreen;
00490 XY_opt_alpha alpha;
00491 XY_bool antialias;
00492 XY_bool gamma_correction;
00493 XY_bool blur;
00494 XY_bool additive;
00495 XY_bool backgrounds;
00496 XY_opt_scaling scaling;
00497 } XY_options;
00498
00503 #define XY_INIT_LIB_CONFIG_FILE_GLOBAL CONFDIR "/libcrtxy.conf"
00504
00508 #define XY_INIT_LIB_CONFIG_FILE_LOCAL ".libcrtxyrc"
00509
00516 typedef enum {
00517 XY_ERR_NONE,
00518 XY_ERR_OPTION_BAD,
00519 XY_ERR_OPTION_UNKNOWN,
00520 XY_ERR_FILE_CANT_OPEN,
00521 XY_ERR_MEM_CANT_ALLOC,
00522 XY_ERR_INIT_VIDEO,
00523 XY_ERR_INIT_DISPLAY,
00524 XY_ERR_INIT_UNSUPPORTED_BPP,
00525 XY_ERR_BITMAP_CANT_DECODE,
00526 XY_ERR_BITMAP_CANT_CONVERT,
00527 XY_ERR_BITMAP_CANT_SCALE,
00528 XY_ERR_LINES_INVALID,
00529 NUM_XY_ERRS
00530 } XY_err;
00531
00540 #define XY_POS_TOP 0x0
00541 #define XY_POS_LEFT 0x0
00542 #define XY_POS_HCENTER 0x1
00543 #define XY_POS_VCENTER 0x2
00544 #define XY_POS_RIGHT 0x4
00545 #define XY_POS_BOTTOM 0x8
00553 #define XY_SCALE_NONE 0
00554 #define XY_SCALE_STRETCH 1
00555 #define XY_SCALE_KEEP_ASPECT_WIDE 2
00556 #define XY_SCALE_KEEP_ASPECT_TALL 3
00572 void XY_default_options(XY_options * opts);
00573
00584 XY_bool XY_load_options(XY_options * opts);
00585
00604 XY_bool XY_load_options_from_file(char * fname, XY_options * opts,
00605 XY_bool ignore_unknowns);
00606
00618 int XY_parse_options(int * argc, char * argv[], XY_options * opts);
00619
00628 XY_bool XY_parse_envvars(XY_options * opts);
00629
00661 XY_bool XY_init(XY_options * opts, XY_fixed canvasw, XY_fixed canvash);
00662
00666 void XY_quit(void);
00667
00680 XY_err XY_errcode(void);
00681
00688 const char * XY_errstr(void);
00689
00697 void XY_print_options(FILE * fi, XY_options opts);
00698
00716 XY_bitmap * XY_load_bitmap(char * filename);
00717
00729 XY_bitmap * XY_load_bitmap_from_buffer(unsigned char * buffer, int size);
00730
00738 void XY_free_bitmap(XY_bitmap * bitmap);
00739
00740
00741
00742
00777 XY_bool XY_set_background(XY_color color, XY_bitmap * bitmap,
00778 XY_fixed x, XY_fixed y, int posflags, int scaling);
00779
00786 void XY_enable_background(XY_bool enable);
00787
00804 XY_color XY_setcolor(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
00805
00816 void XY_getcolor(XY_color c, Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a);
00817
00832 void XY_start_frame(int fps);
00833
00851 int XY_end_frame(XY_bool throttle);
00852
00866 XY_lines * XY_new_lines(void);
00867
00877 XY_lines * XY_duplicate_lines(XY_lines * lines);
00878
00889 XY_bool XY_free_lines(XY_lines * lines);
00890
00901 XY_bool XY_start_lines(XY_lines * lines);
00902
00920 XY_bool XY_add_line(XY_lines * lines,
00921 XY_fixed x1, XY_fixed y1, XY_fixed x2, XY_fixed y2,
00922 XY_color color, XY_fixed thickness);
00923
00937 XY_bool XY_translate_lines(XY_lines * lines,
00938 XY_fixed x, XY_fixed y);
00939
00951 XY_bool XY_scale_lines(XY_lines * lines, XY_fixed xscale, XY_fixed yscale);
00952
00964 XY_bool XY_rotate_lines(XY_lines * lines, int angle);
00965
00987 void XY_draw_line(XY_fixed x1, XY_fixed y1, XY_fixed x2, XY_fixed y2,
00988 XY_color color, XY_fixed thickness);
00989
00998 XY_bool XY_draw_lines(XY_lines * lines);
00999
01005 void XY_draw_one_line(XY_line line);
01006
01017 void XY_draw_point(XY_fixed x, XY_fixed y, XY_color color, XY_fixed thickness);
01018
01034 #define XY_mult(a,b) (((a) >> XY_FIXED_SHIFT_HALF) * \
01035 ((b) >> XY_FIXED_SHIFT_HALF))
01036
01044 #define XY_qdiv(a,b) (((a) / \
01045 ((b) >> XY_FIXED_SHIFT_HALF)) \
01046 << XY_FIXED_SHIFT_HALF)
01047
01057 #define XY_div(a,b) (((b) >> XY_FIXED_SHIFT_HALF) == 0 ? \
01058 XY_FIXED_NAN : XY_qdiv((a),(b)))
01059
01065 #define XY_FIXED_DIV_ZERO ((1 << XY_FIXED_SHIFT_HALF) - 1)
01066
01070 #define XY_fpart(a) ((a) & (XY_FIXED_ONE - 1))
01071
01075 #define XY_rfpart(a) (XY_FIXED_ONE - XY_fpart(a))
01076
01080 #define XY_ipart(a) ((a) - XY_fpart(a))
01081
01085 #define XY_round(a) (XY_ipart((a) + (1 << (XY_FIXED_SHIFT - 1))))
01086
01094 XY_fixed XY_cos(int degrees);
01095
01103 #define XY_sin(degrees) (XY_cos(90 - (degrees)))
01104
01120 XY_fixed XY_screenx_to_canvasx(int sx);
01121
01130 XY_fixed XY_screeny_to_canvasy(int sy);
01131
01143 void XY_screen_to_canvas(int sx, int sy, XY_fixed * cx, XY_fixed * cy);
01144
01152 XY_fixed XY_canvasx_to_screenx(int cx);
01153
01161 XY_fixed XY_canvasy_to_screeny(int cy);
01162
01174 void XY_canvas_to_screen(XY_fixed cx, XY_fixed cy, int * sx, int * sy);
01175
01181 int XY_get_screenw(void);
01182
01188 int XY_get_screenh(void);
01189
01215 XY_bool XY_lines_intersect(XY_line line1, XY_line line2,
01216 XY_fixed * intersect_x, XY_fixed * intersect_y,
01217 XY_intersection * result);
01218
01227 XY_bool XY_line_groups_intersect(XY_lines * lines1, XY_lines * lines2);
01228
01231 #ifdef __cplusplus
01232 }
01233 #endif
01234
01235 #endif
01236