1 /*****************************************************************************
2 * intf_sdl.c: SDL interface plugin
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
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.
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.
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 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
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 */
43 #include "video_output.h"
45 #include "interface.h"
50 /*****************************************************************************
51 * intf_sys_t: description and status of SDL interface
52 *****************************************************************************/
53 typedef struct intf_sys_s
55 /* SDL system information */
56 SDL_Surface * p_display; /* display */
61 void intf_SDL_Keymap( intf_thread_t * p_intf );
64 /*****************************************************************************
65 * intf_SDLCreate: initialize and create SDL interface
66 *****************************************************************************/
67 int intf_SDLCreate( intf_thread_t *p_intf )
69 /* Check that b_video is set */
70 if( !p_main->b_video )
72 intf_ErrMsg( "error: SDL interface requires a video output thread\n" );
76 /* Allocate instance and initialize some members */
77 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
78 if( p_intf->p_sys == NULL )
80 intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
84 /* Spawn video output thread */
85 p_intf->p_vout = vout_CreateThread( main_GetPszVariable( VOUT_DISPLAY_VAR,
87 main_GetIntVariable( VOUT_WIDTH_VAR,
89 main_GetIntVariable( VOUT_HEIGHT_VAR,
90 VOUT_HEIGHT_DEFAULT ),
92 (void *)&p_intf->p_sys->p_display );
94 if( p_intf->p_vout == NULL ) /* error */
96 intf_ErrMsg( "error: can't create video output thread\n" );
97 free( p_intf->p_sys );
100 intf_SDL_Keymap( p_intf );
104 /*****************************************************************************
105 * intf_SDLDestroy: destroy interface
106 *****************************************************************************/
107 void intf_SDLDestroy( intf_thread_t *p_intf )
109 /* Close input thread, if any (blocking) */
110 if( p_intf->p_input )
112 input_DestroyThread( p_intf->p_input, NULL );
115 /* Close video output thread, if any (blocking) */
118 vout_DestroyThread( p_intf->p_vout, NULL );
121 /* Destroy structure */
123 SDL_FreeSurface( p_intf->p_sys->p_display ); /* destroy the "screen" */
125 free( p_intf->p_sys );
129 /*****************************************************************************
130 * intf_SDLManage: event loop
131 *****************************************************************************/
132 void intf_SDLManage( intf_thread_t *p_intf )
134 SDL_Event event; /* SDL event */
137 while ( SDL_PollEvent(&event) )
140 i_key = event.key.keysym.sym; /* forward it */
141 intf_ErrMsgImm("key :%c:\n",(char) i_key);
143 switch (event.type) {
144 case SDL_KEYDOWN: /* if a key is pressed */
145 if( intf_ProcessKey( p_intf, (char ) i_key ) )
147 intf_DbgMsg( "unhandled key '%c' (%i)\n",
148 (char) i_key, i_key );
152 intf_ProcessKey( p_intf, 'Q' );
160 void intf_SDL_Keymap(intf_thread_t * p_intf )
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');