source: libcaca/trunk/caca/caca_internals.h @ 548

Last change on this file since 548 was 548, checked in by Sam Hocevar, 14 years ago
  • Split event.c into the appropriate driver_*.c files.
  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1/*
2 *  libcaca       ASCII-Art library
3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  This library is free software; you can redistribute it and/or
7 *  modify it under the terms of the Do What The Fuck You Want To
8 *  Public License, Version 2, as published by Sam Hocevar. See
9 *  http://sam.zoy.org/wtfpl/COPYING for more details.
10 */
11
12/** \file caca_internals.h
13 *  \version \$Id: caca_internals.h 548 2006-03-08 09:28:41Z sam $
14 *  \author Sam Hocevar <sam@zoy.org>
15 *  \brief The \e libcaca private header.
16 *
17 *  This header contains the private types and functions used by \e libcaca.
18 */
19
20#ifndef __CACA_INTERNALS_H__
21#define __CACA_INTERNALS_H__
22
23#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
24#   include <inttypes.h>
25#elif !defined(CUSTOM_INTTYPES)
26#   define CUSTOM_INTTYPES
27typedef unsigned char uint8_t;
28typedef unsigned short uint16_t;
29typedef unsigned int uint32_t;
30#endif
31
32#if defined(USE_CONIO)
33#   include <conio.h>
34#endif
35#if defined(USE_GL)
36#   include <GL/glut.h>
37#endif
38#if defined(USE_NCURSES)
39#   if defined(HAVE_NCURSES_H)
40#       include <ncurses.h>
41#   else
42#       include <curses.h>
43#   endif
44#endif
45#if defined(USE_WIN32)
46#   include <windows.h>
47#endif
48#if defined(USE_X11)
49#   include <X11/Xlib.h>
50#endif
51
52#if !defined(_DOXYGEN_SKIP_ME)
53#   define EVENTBUF_LEN 10
54#endif
55
56/* Graphics driver */
57enum caca_driver
58{
59#if defined(USE_CONIO)
60    CACA_DRIVER_CONIO = 1,
61#endif
62#if defined(USE_NCURSES)
63    CACA_DRIVER_NCURSES = 2,
64#endif
65#if defined(USE_SLANG)
66    CACA_DRIVER_SLANG = 3,
67#endif
68#if defined(USE_X11)
69    CACA_DRIVER_X11 = 4,
70#endif
71#if defined(USE_WIN32)
72    CACA_DRIVER_WIN32 = 5,
73#endif
74#if defined(USE_GL)
75    CACA_DRIVER_GL = 6,
76#endif
77    CACA_DRIVER_NONE = 0
78};
79
80/* Available drivers */
81#if defined(USE_CONIO)
82void conio_init_driver(caca_t *);
83#endif
84#if defined(USE_GL)
85void gl_init_driver(caca_t *);
86#endif
87#if defined(USE_NCURSES)
88void ncurses_init_driver(caca_t *);
89#endif
90#if defined(USE_SLANG)
91void slang_init_driver(caca_t *);
92#endif
93#if defined(USE_WIN32)
94void win32_init_driver(caca_t *);
95#endif
96#if defined(USE_X11)
97void x11_init_driver(caca_t *);
98#endif
99
100/* Timer structure */
101struct caca_timer
102{
103    int last_sec, last_usec;
104};
105
106/* Internal caca context */
107struct caca_context
108{
109    cucul_t *qq;
110
111    struct driver
112    {
113        enum caca_driver driver;
114
115        int (* init_graphics) (caca_t *);
116        int (* end_graphics) (caca_t *);
117        int (* set_window_title) (caca_t *, char const *);
118        unsigned int (* get_window_width) (caca_t *);
119        unsigned int (* get_window_height) (caca_t *);
120        void (* display) (caca_t *);
121        void (* handle_resize) (caca_t *, unsigned int *, unsigned int *);
122        unsigned int (* get_event) (caca_t *);
123    } driver;
124
125    //unsigned int width, height;
126    unsigned int mouse_x, mouse_y;
127
128    int resize;
129    int resize_event;
130
131    unsigned int delay, rendertime;
132    struct caca_timer timer;
133    int lastticks;
134
135    struct events
136    {
137#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO)
138        unsigned int buf[EVENTBUF_LEN];
139        int queue;
140#endif
141#if defined(USE_SLANG) || defined(USE_NCURSES)
142        struct caca_timer key_timer;
143        unsigned int last_key_ticks;
144        unsigned int autorepeat_ticks;
145        unsigned int last_key;
146#endif
147    } events;
148
149    /* FIXME: maybe this should go away */
150#if defined(USE_X11) && !defined(_DOXYGEN_SKIP_ME)
151    struct x11
152    {
153        Display *dpy;
154        Window window;
155        Pixmap pixmap;
156        GC gc;
157        long int event_mask;
158        int font_width, font_height;
159        unsigned int new_width, new_height;
160        int colors[16];
161        Font font;
162        XFontStruct *font_struct;
163        int font_offset;
164#if defined(HAVE_X11_XKBLIB_H)
165        Bool autorepeat;
166#endif
167    } x11;
168#endif
169#if defined(USE_NCURSES)
170    struct ncurses
171    {
172        int attr[16*16];
173        mmask_t oldmask;
174    } ncurses;
175#endif
176#if defined(USE_CONIO)
177    struct conio
178    {
179        struct text_info ti;
180        char *screen;
181    } conio;
182#endif
183#if defined(USE_WIN32)
184    struct win32
185    {
186        HANDLE hin, hout;
187        HANDLE front, back;
188        CHAR_INFO *buffer;
189        CONSOLE_CURSOR_INFO cci;
190    } win32;
191#endif
192#if defined(USE_GL)
193    struct gl
194    {
195        int window;
196        unsigned int width, height;
197        float font_width, font_height;
198        float incx, incy;
199        int id[94];
200        unsigned char resized, bit;
201        unsigned char mouse_changed, mouse_clicked;
202        unsigned int mouse_x, mouse_y;
203        unsigned int mouse_button, mouse_state;
204
205        unsigned char key;
206        int special_key;
207        int new_width;
208        int new_height;
209
210        float sw, sh;
211    } gl;
212#endif
213};
214
215/* Timer functions */
216extern void _caca_sleep(unsigned int);
217extern unsigned int _caca_getticks(struct caca_timer *);
218
219#endif /* __CACA_INTERNALS_H__ */
Note: See TracBrowser for help on using the repository browser.