]> git.sesse.net Git - vlc/blob - plugins/sdl/intf_sdl.c
fb077c9a39641466efddd6ce354b3aa6fc75164f
[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 #include "keystrokes.h"
48
49 #include "main.h"
50
51 /*****************************************************************************
52  * intf_sys_t: description and status of SDL interface
53  *****************************************************************************/
54 typedef struct intf_sys_s
55 {
56     /* SDL system information */
57     SDL_Surface *               p_display;                                /* display */
58         
59 } intf_sys_t;
60
61 /* local prototype */
62 void    intf_SDL_Keymap( intf_thread_t * p_intf );
63     
64
65 /*****************************************************************************
66  * intf_SDLCreate: initialize and create SDL interface
67  *****************************************************************************/
68 int intf_SDLCreate( intf_thread_t *p_intf )
69 {
70     /* Check that b_video is set */
71     if( !p_main->b_video )
72     {
73         intf_ErrMsg( "error: SDL interface requires a video output thread\n" );
74         return( 1 );
75     }
76
77     /* Allocate instance and initialize some members */
78     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
79     if( p_intf->p_sys == NULL )
80     {
81         intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
82         return( 1 );
83     }
84
85     /* Spawn video output thread */
86     p_intf->p_vout = vout_CreateThread( main_GetPszVariable( VOUT_DISPLAY_VAR,
87                                                              NULL), 0,
88                                         main_GetIntVariable( VOUT_WIDTH_VAR,
89                                                          VOUT_WIDTH_DEFAULT ),
90                                         main_GetIntVariable( VOUT_HEIGHT_VAR,
91                                                         VOUT_HEIGHT_DEFAULT ),
92                                         NULL, 0,
93                                         (void *)&p_intf->p_sys->p_display );
94
95     if( p_intf->p_vout == NULL )                                  /* error */
96     {
97         intf_ErrMsg( "error: can't create video output thread\n" );
98         free( p_intf->p_sys );
99         return( 1 );
100     }
101     intf_SDL_Keymap( p_intf );
102     return( 0 );
103 }
104
105 /*****************************************************************************
106  * intf_SDLDestroy: destroy interface
107  *****************************************************************************/
108 void intf_SDLDestroy( intf_thread_t *p_intf )
109 {
110     /* Close input thread, if any (blocking) */
111     if( p_intf->p_input )
112     {
113         input_DestroyThread( p_intf->p_input, NULL );
114     }
115
116     /* Close video output thread, if any (blocking) */
117     if( p_intf->p_vout )
118     {
119         vout_DestroyThread( p_intf->p_vout, NULL );
120     }
121
122     /* Destroy structure */
123     
124     SDL_FreeSurface( p_intf->p_sys->p_display );     /* destroy the "screen" */
125     SDL_Quit();
126     free( p_intf->p_sys );
127 }
128
129
130 /*****************************************************************************
131  * intf_SDLManage: event loop
132  *****************************************************************************/
133 void intf_SDLManage( intf_thread_t *p_intf )
134 {
135         SDL_Event event;                                                                                /*      SDL event        */
136     Uint8   i_key;
137     
138     while ( SDL_PollEvent(&event) ) 
139     {
140         i_key = event.key.keysym.sym;                  /* forward it */
141         
142         switch (event.type) {           
143             case SDL_KEYDOWN:                         /* if a key is pressed */
144                 if( intf_ProcessKey( p_intf, (char ) i_key ) )
145                 {
146                     intf_DbgMsg( "unhandled key '%c' (%i)\n", 
147                                  (char) i_key, i_key );
148                 }
149                 break;
150             case SDL_QUIT:
151                 intf_ProcessKey( p_intf, INTF_KEY_QUIT ); 
152                 break;
153             default:
154                 break;
155         }
156     }
157 }
158
159
160
161 void intf_SDL_Keymap(intf_thread_t * p_intf )
162 {
163     p_intf->p_intf_getKey = intf_getKey; 
164     intf_AssignKey(p_intf, SDLK_q,      INTF_KEY_QUIT, NULL);
165     intf_AssignKey(p_intf, SDLK_ESCAPE, INTF_KEY_QUIT, NULL);
166     /* intf_AssignKey(p_intf,3,'Q'); */
167     intf_AssignKey(p_intf, SDLK_0,      INTF_KEY_SET_CHANNEL,0);
168     intf_AssignKey(p_intf, SDLK_1,      INTF_KEY_SET_CHANNEL,1);
169     intf_AssignKey(p_intf, SDLK_2,      INTF_KEY_SET_CHANNEL,2);
170     intf_AssignKey(p_intf, SDLK_3,      INTF_KEY_SET_CHANNEL,3);
171     intf_AssignKey(p_intf, SDLK_4,      INTF_KEY_SET_CHANNEL,4);
172     intf_AssignKey(p_intf, SDLK_5,      INTF_KEY_SET_CHANNEL,5);
173     intf_AssignKey(p_intf, SDLK_6,      INTF_KEY_SET_CHANNEL,6);
174     intf_AssignKey(p_intf, SDLK_7,      INTF_KEY_SET_CHANNEL,7);
175     intf_AssignKey(p_intf, SDLK_8,      INTF_KEY_SET_CHANNEL,8);
176     intf_AssignKey(p_intf, SDLK_9,      INTF_KEY_SET_CHANNEL,9);
177     intf_AssignKey(p_intf, SDLK_PLUS,   INTF_KEY_INC_VOLUME, NULL);
178     intf_AssignKey(p_intf, SDLK_MINUS,  INTF_KEY_DEC_VOLUME, NULL);
179     intf_AssignKey(p_intf, SDLK_m,      INTF_KEY_TOGGLE_VOLUME, NULL);
180     /* intf_AssignKey(p_intf,'M','M'); */
181     intf_AssignSKey(p_intf, SDLK_g,      INTF_KEY_DEC_GAMMA, NULL);
182     /* intf_AssignKey(p_intf,'G','G'); */
183     intf_AssignSKey(p_intf, SDLK_c,      INTF_KEY_TOGGLE_GRAYSCALE, NULL);
184     intf_AssignSKey(p_intf, SDLK_SPACE,  INTF_KEY_TOGGLE_INTERFACE, NULL);
185     intf_AssignSKey(p_intf, 'i',         INTF_KEY_TOGGLE_INFO, NULL);
186     intf_AssignSKey(p_intf, SDLK_s,      INTF_KEY_TOGGLE_SCALING, NULL);
187
188 }
189