]> git.sesse.net Git - vlc/blob - plugins/sdl/intf_sdl.c
.SDL:
[vlc] / plugins / sdl / intf_sdl.c
1 /*****************************************************************************
2  * intf_sdl.c: SDL interface plugin
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "defs.h"
27
28 #include <errno.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <SDL/SDL.h>                                   /* for all the SDL stuff      */
32 #include <sys/types.h>                        /* on BSD, uio.h needs types.h */
33 #include <sys/uio.h>                                          /* for input.h */
34
35 #include "config.h"
36 #include "common.h"
37 #include "threads.h"
38 #include "mtime.h"
39 #include "plugins.h"
40
41 #include "input.h"
42 #include "video.h"
43 #include "video_output.h"
44
45 #include "interface.h"
46 #include "intf_msg.h"
47
48 #include "main.h"
49
50 /*****************************************************************************
51  * intf_sys_t: description and status of SDL interface
52  *****************************************************************************/
53 typedef struct intf_sys_s
54 {
55     /* SDL system information */
56     SDL_Surface *               p_display;                                /* display */
57         
58 } intf_sys_t;
59
60 /* local prototype */
61 void    intf_SDL_Keymap( intf_thread_t * p_intf );
62     
63
64 /*****************************************************************************
65  * intf_SDLCreate: initialize and create SDL interface
66  *****************************************************************************/
67 int intf_SDLCreate( intf_thread_t *p_intf )
68 {
69     /* Check that b_video is set */
70     if( !p_main->b_video )
71     {
72         intf_ErrMsg( "error: SDL interface requires a video output thread\n" );
73         return( 1 );
74     }
75
76     /* Allocate instance and initialize some members */
77     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
78     if( p_intf->p_sys == NULL )
79     {
80         intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
81         return( 1 );
82     }
83
84     /* Spawn video output thread */
85     p_intf->p_vout = vout_CreateThread( main_GetPszVariable( VOUT_DISPLAY_VAR,
86                                                              NULL), 0,
87                                         main_GetIntVariable( VOUT_WIDTH_VAR,
88                                                          VOUT_WIDTH_DEFAULT ),
89                                         main_GetIntVariable( VOUT_HEIGHT_VAR,
90                                                         VOUT_HEIGHT_DEFAULT ),
91                                         NULL, 0,
92                                         (void *)&p_intf->p_sys->p_display );
93
94     if( p_intf->p_vout == NULL )                                  /* error */
95     {
96         intf_ErrMsg( "error: can't create video output thread\n" );
97         free( p_intf->p_sys );
98         return( 1 );
99     }
100     intf_SDL_Keymap( p_intf );
101     return( 0 );
102 }
103
104 /*****************************************************************************
105  * intf_SDLDestroy: destroy interface
106  *****************************************************************************/
107 void intf_SDLDestroy( intf_thread_t *p_intf )
108 {
109     /* Close input thread, if any (blocking) */
110     if( p_intf->p_input )
111     {
112         input_DestroyThread( p_intf->p_input, NULL );
113     }
114
115     /* Close video output thread, if any (blocking) */
116     if( p_intf->p_vout )
117     {
118         vout_DestroyThread( p_intf->p_vout, NULL );
119     }
120
121     /* Destroy structure */
122     
123     SDL_FreeSurface( p_intf->p_sys->p_display );     /* destroy the "screen" */
124     SDL_Quit();
125     free( p_intf->p_sys );
126 }
127
128
129 /*****************************************************************************
130  * intf_SDLManage: event loop
131  *****************************************************************************/
132 void intf_SDLManage( intf_thread_t *p_intf )
133 {
134         SDL_Event event;                                                                                /*      SDL event        */
135     Uint8   i_key;
136     
137     while ( SDL_PollEvent(&event) ) 
138     {
139         
140         i_key = event.key.keysym.sym;                  /* forward it */
141         intf_ErrMsgImm("key :%c:\n",(char) i_key);
142         
143         switch (event.type) {           
144             case SDL_KEYDOWN:                         /* if a key is pressed */
145                 if( intf_ProcessKey( p_intf, (char ) i_key ) )
146                 {
147                     intf_DbgMsg( "unhandled key '%c' (%i)\n", 
148                                  (char) i_key, i_key );
149                 }
150                 break;
151             case SDL_QUIT:
152                 intf_ProcessKey( p_intf, 'Q' ); 
153                 break;
154             default:
155                 break;
156         }
157     }
158 }
159
160 void intf_SDL_Keymap(intf_thread_t * p_intf )
161
162     intf_AssignKey(p_intf, SDLK_q,      'Q');
163     intf_AssignKey(p_intf, SDLK_ESCAPE, 'Q');
164     /* intf_AssignKey(p_intf,3,'Q'); */
165     intf_AssignKey(p_intf, SDLK_0,      '0');
166     intf_AssignKey(p_intf, SDLK_1,      '1');
167     intf_AssignKey(p_intf, SDLK_2,      '2');
168     intf_AssignKey(p_intf, SDLK_3,      '3');
169     intf_AssignKey(p_intf, SDLK_4,      '4');
170     intf_AssignKey(p_intf, SDLK_5,      '5');
171     intf_AssignKey(p_intf, SDLK_6,      '6');
172     intf_AssignKey(p_intf, SDLK_7,      '7');
173     intf_AssignKey(p_intf, SDLK_8,      '8');
174     intf_AssignKey(p_intf, SDLK_9,      '9');
175     intf_AssignKey(p_intf, SDLK_PLUS,   '+');
176     intf_AssignKey(p_intf, SDLK_MINUS,  '-');
177     intf_AssignKey(p_intf, SDLK_m,      'M');
178     /* intf_AssignKey(p_intf,'M','M'); */
179     intf_AssignKey(p_intf, SDLK_g,      'g');
180     /* intf_AssignKey(p_intf,'G','G'); */
181     intf_AssignKey(p_intf, SDLK_c,      'c');
182     intf_AssignKey(p_intf, SDLK_SPACE,  ' ');
183     intf_AssignKey(p_intf, 'i',      'i');
184     intf_AssignKey(p_intf, SDLK_s,      's');
185
186 }