Mercurial > mplayer.hg
annotate libvo/sdl_common.c @ 31041:42b4b532b86a
Missing space in error message.
author | reimar |
---|---|
date | Sun, 25 Apr 2010 10:12:39 +0000 |
parents | 85809d9fdc95 |
children | 91eb3b0b9b7a |
rev | line source |
---|---|
31032
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
1 /* |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
2 * common SDL routines |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
3 * |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
4 * This file is part of MPlayer. |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
5 * |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
6 * MPlayer is free software; you can redistribute it and/or modify |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
9 * (at your option) any later version. |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
10 * |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
11 * MPlayer is distributed in the hope that it will be useful, |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
15 * |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License along |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
19 */ |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
20 |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
21 #include "sdl_common.h" |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
22 #include "mp_msg.h" |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
23 #include "mp_fifo.h" |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
24 #include "osdep/keycodes.h" |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
25 #include "input/input.h" |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
26 #include "input/mouse.h" |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
27 #include "video_out.h" |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
28 |
31035 | 29 static int old_w; |
30 static int old_h; | |
31 static int mode_flags; | |
32 | |
31037 | 33 int vo_sdl_init(void) |
34 { | |
35 if (!SDL_WasInit(SDL_INIT_VIDEO) && | |
36 SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0) | |
37 return 0; | |
38 | |
39 // Setup Keyrepeats (500/30 are defaults) | |
40 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, 100 /*SDL_DEFAULT_REPEAT_INTERVAL*/); | |
41 | |
31038
3e67417271d7
Make uppercase characters and in general all ASCII characters work
reimar
parents:
31037
diff
changeset
|
42 // Easiest way to get uppercase characters |
3e67417271d7
Make uppercase characters and in general all ASCII characters work
reimar
parents:
31037
diff
changeset
|
43 SDL_EnableUNICODE(1); |
3e67417271d7
Make uppercase characters and in general all ASCII characters work
reimar
parents:
31037
diff
changeset
|
44 |
31037 | 45 // We don't want those in our event queue. |
46 SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE); | |
47 SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); | |
48 SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE); | |
49 SDL_EventState(SDL_USEREVENT, SDL_IGNORE); | |
50 | |
51 return 1; | |
52 } | |
53 | |
54 void vo_sdl_uninit(void) | |
55 { | |
56 if (SDL_WasInit(SDL_INIT_VIDEO)) | |
57 SDL_QuitSubSystem(SDL_INIT_VIDEO); | |
58 } | |
59 | |
31035 | 60 void vo_sdl_fullscreen(void) |
61 { | |
62 if (vo_fs) { | |
63 vo_dwidth = old_w; | |
64 vo_dheight = old_h; | |
65 } else { | |
66 old_w = vo_dwidth; | |
67 old_h = vo_dheight; | |
68 vo_dwidth = vo_screenwidth; | |
69 vo_dheight = vo_screenheight; | |
70 } | |
71 vo_fs = !vo_fs; | |
72 sdl_set_mode(0, mode_flags); | |
73 } | |
74 | |
31033
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
75 int sdl_set_mode(int bpp, uint32_t flags) |
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
76 { |
31035 | 77 SDL_Surface *s; |
78 mode_flags = flags; | |
79 if (vo_fs) flags |= SDL_FULLSCREEN; | |
80 // doublebuf with opengl creates flickering | |
81 if (vo_doublebuffering && !(flags & SDL_OPENGL)) | |
82 flags |= SDL_DOUBLEBUF; | |
83 s = SDL_SetVideoMode(vo_dwidth, vo_dheight, bpp, flags); | |
31033
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
84 if (!s) { |
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
85 mp_msg(MSGT_VO, MSGL_FATAL, "SDL SetVideoMode failed: %s\n", SDL_GetError()); |
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
86 return -1; |
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
87 } |
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
88 vo_dwidth = s->w; |
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
89 vo_dheight = s->h; |
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
90 return 0; |
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
91 } |
8d1080e9c92d
Window resizing support for -vo gl with SDL backend.
reimar
parents:
31032
diff
changeset
|
92 |
31040 | 93 static const struct mp_keymap keysym_map[] = { |
94 {SDLK_RETURN, KEY_ENTER}, {SDLK_ESCAPE, KEY_ESC}, | |
95 {SDLK_F1, KEY_F+1}, {SDLK_F2, KEY_F+2}, {SDLK_F3, KEY_F+3}, | |
96 {SDLK_F4, KEY_F+4}, {SDLK_F5, KEY_F+5}, {SDLK_F6, KEY_F+6}, | |
97 {SDLK_F7, KEY_F+7}, {SDLK_F8, KEY_F+8}, {SDLK_F9, KEY_F+9}, | |
98 {SDLK_F10, KEY_F+10}, {SDLK_F11, KEY_F+11}, {SDLK_F12, KEY_F+12}, | |
99 {SDLK_KP_PLUS, '+'}, {SDLK_KP_MINUS, '-'}, {SDLK_TAB, KEY_TAB}, | |
100 {SDLK_PAGEUP, KEY_PAGE_UP}, {SDLK_PAGEDOWN, KEY_PAGE_DOWN}, | |
101 {SDLK_UP, KEY_UP}, {SDLK_DOWN, KEY_DOWN}, | |
102 {SDLK_LEFT, KEY_LEFT}, {SDLK_RIGHT, KEY_RIGHT}, | |
103 {SDLK_KP_MULTIPLY, '*'}, {SDLK_KP_DIVIDE, '/'}, | |
104 {SDLK_KP0, KEY_KP0}, {SDLK_KP1, KEY_KP1}, {SDLK_KP2, KEY_KP2}, | |
105 {SDLK_KP3, KEY_KP3}, {SDLK_KP4, KEY_KP4}, {SDLK_KP5, KEY_KP5}, | |
106 {SDLK_KP6, KEY_KP6}, {SDLK_KP7, KEY_KP7}, {SDLK_KP8, KEY_KP8}, | |
107 {SDLK_KP9, KEY_KP9}, | |
108 {SDLK_KP_PERIOD, KEY_KPDEC}, {SDLK_KP_ENTER, KEY_KPENTER}, | |
109 }; | |
110 | |
31032
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
111 int sdl_default_handle_event(SDL_Event *event) |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
112 { |
31040 | 113 int mpkey; |
31032
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
114 switch (event->type) { |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
115 case SDL_VIDEORESIZE: |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
116 vo_dwidth = event->resize.w; |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
117 vo_dheight = event->resize.h; |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
118 return VO_EVENT_RESIZE; |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
119 case SDL_MOUSEBUTTONDOWN: |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
120 if(vo_nomouse_input) |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
121 break; |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
122 mplayer_put_key((MOUSE_BTN0 + event->button.button - 1) | MP_KEY_DOWN); |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
123 break; |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
124 |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
125 case SDL_MOUSEBUTTONUP: |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
126 if(vo_nomouse_input) |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
127 break; |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
128 mplayer_put_key(MOUSE_BTN0 + event->button.button - 1); |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
129 break; |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
130 |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
131 case SDL_KEYDOWN: |
31040 | 132 mpkey = lookup_keymap_table(keysym_map, event->key.keysym.sym); |
133 if (!mpkey && | |
134 event->key.keysym.unicode > 0 && | |
135 event->key.keysym.unicode < 128) | |
136 mpkey = event->key.keysym.unicode; | |
137 if (mpkey) | |
138 mplayer_put_key(mpkey); | |
31032
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
139 break; |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
140 |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
141 case SDL_QUIT: mplayer_put_key(KEY_CLOSE_WIN);break; |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
142 } |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
143 return 0; |
362425fe3de8
Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff
changeset
|
144 } |